librpc/rpc: make the dcerpc_binding_handle_raw_call_send/recv() wrapper more thin
authorStefan Metzmacher <metze@samba.org>
Fri, 30 Aug 2013 09:56:18 +0000 (11:56 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 4 Jun 2019 11:14:55 +0000 (13:14 +0200)
The allows better passthrough to the ops->raw_call_send/recv functions.

The important change is that the ops->raw_call_recv() function is deferred to
the dcerpc_binding_handle_raw_call_recv() function, which means
that 'req' and 'subreq' have the same lifetime.
This will be important in the following commits, which will add
dcerpc_binding_handle_raw_call_in_send/recv and LIBNDR_FLAG_INCOMPLETE_BUFFER
support for DCERPC pipes.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
librpc/rpc/binding_handle.c

index 41675e103607b2502a8424ed794bda9f9a653fb1..bb5245772e1ca75fc578bf5d573582a44a7287c0 100644 (file)
@@ -125,9 +125,8 @@ void dcerpc_binding_handle_auth_info(struct dcerpc_binding_handle *h,
 
 struct dcerpc_binding_handle_raw_call_state {
        const struct dcerpc_binding_handle_ops *ops;
-       uint8_t *out_data;
-       size_t out_length;
-       uint32_t out_flags;
+       struct tevent_context *ev;
+       struct tevent_req *subreq;
 };
 
 static void dcerpc_binding_handle_raw_call_done(struct tevent_req *subreq);
@@ -143,7 +142,6 @@ struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
 {
        struct tevent_req *req;
        struct dcerpc_binding_handle_raw_call_state *state;
-       struct tevent_req *subreq;
 
        req = tevent_req_create(mem_ctx, &state,
                                struct dcerpc_binding_handle_raw_call_state);
@@ -151,9 +149,7 @@ struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
                return NULL;
        }
        state->ops = h->ops;
-       state->out_data = NULL;
-       state->out_length = 0;
-       state->out_flags = 0;
+       state->ev = ev;
 
        if (h->object != NULL) {
                /*
@@ -171,32 +167,27 @@ struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
                object = h->object;
        }
 
-       subreq = state->ops->raw_call_send(state, ev, h,
-                                          object, opnum,
-                                          in_flags, in_data, in_length);
-       if (tevent_req_nomem(subreq, req)) {
+       state->subreq = state->ops->raw_call_send(state, ev, h,
+                                                 object, opnum,
+                                                 in_flags, in_data, in_length);
+       if (tevent_req_nomem(state->subreq, req)) {
                return tevent_req_post(req, ev);
        }
-       tevent_req_set_callback(subreq, dcerpc_binding_handle_raw_call_done, req);
+       tevent_req_set_callback(state->subreq,
+                               dcerpc_binding_handle_raw_call_done,
+                               req);
 
        return req;
 }
 
 static void dcerpc_binding_handle_raw_call_done(struct tevent_req *subreq)
 {
-       struct tevent_req *req = tevent_req_callback_data(subreq,
-                                struct tevent_req);
-       struct dcerpc_binding_handle_raw_call_state *state =
-               tevent_req_data(req,
-               struct dcerpc_binding_handle_raw_call_state);
-       NTSTATUS error;
+       struct tevent_req *req =
+               tevent_req_callback_data(subreq,
+               struct tevent_req);
 
-       error = state->ops->raw_call_recv(subreq, state,
-                                         &state->out_data,
-                                         &state->out_length,
-                                         &state->out_flags);
-       TALLOC_FREE(subreq);
-       if (tevent_req_nterror(req, error)) {
+       if (tevent_req_is_in_progress(subreq)) {
+               tevent_req_notify_callback(req);
                return;
        }
 
@@ -214,14 +205,27 @@ NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
                struct dcerpc_binding_handle_raw_call_state);
        NTSTATUS error;
 
-       if (tevent_req_is_nterror(req, &error)) {
+       if (!tevent_req_is_in_progress(req)) {
+               if (tevent_req_is_nterror(req, &error)) {
+                       tevent_req_received(req);
+                       return error;
+               }
+       }
+
+       error = state->ops->raw_call_recv(state->subreq,
+                                         mem_ctx,
+                                         out_data,
+                                         out_length,
+                                         out_flags);
+       if (!NT_STATUS_IS_OK(error)) {
                tevent_req_received(req);
                return error;
        }
 
-       *out_data = talloc_move(mem_ctx, &state->out_data);
-       *out_length = state->out_length;
-       *out_flags = state->out_flags;
+       if (tevent_req_is_in_progress(state->subreq)) {
+               return NT_STATUS_OK;
+       }
+
        tevent_req_received(req);
        return NT_STATUS_OK;
 }