libcli/raw: add a recv_helper hook infrastructure
authorStefan Metzmacher <metze@samba.org>
Fri, 4 Jul 2008 17:52:23 +0000 (19:52 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 7 Jul 2008 11:43:13 +0000 (13:43 +0200)
The recv helper will be called when a response comes
and the recv helper can decide to let the request
on the SMBCLI_REQUEST_RECV when more reponse packets
are expected. It's up to the helper function
to keep a reference to the in buffers, each incoming
response overwrites req->in.

metze

source/libcli/raw/clitransport.c
source/libcli/raw/libcliraw.h

index 34fb96230d53d135715585157e0db510e09d1765..e95ae3271edf8a8017b6aca374624c056a70baea 100644 (file)
@@ -480,8 +480,22 @@ async:
        /* if this request has an async handler then call that to
           notify that the reply has been received. This might destroy
           the request so it must happen last */
-       DLIST_REMOVE(transport->pending_recv, req);
+
        req->state = SMBCLI_REQUEST_DONE;
+
+       if (req->recv_helper.fn) {
+               /*
+                * let the recv helper decide in
+                * what state the request really is
+                */
+               req->state = req->recv_helper.fn(req);
+
+               /* if more parts are needed, wait for them */
+               if (req->state <= SMBCLI_REQUEST_RECV) {
+                       return NT_STATUS_OK;
+               }
+       }
+       DLIST_REMOVE(transport->pending_recv, req);
        if (req->async.fn) {
                req->async.fn(req);
        }
index 16a98ad66e5a81e8fc2ebf6af483fc668e4d70b4..d55b4cc42c160f341913e274d391d975bcc8322b 100644 (file)
@@ -231,6 +231,14 @@ struct smbcli_request {
        struct smbcli_session *session;
        struct smbcli_tree *tree;
 
+       /* a receive helper, smbcli_transport_finish_recv will not call
+          req->async.fn callback handler unless the recv_helper returns
+          a value > SMBCLI_REQUEST_RECV. */
+       struct {
+               enum smbcli_request_state (*fn)(struct smbcli_request *);
+               void *private_data;
+       } recv_helper;
+
        /* the flags2 from the SMB request, in raw form (host byte
           order). Used to parse strings */
        uint16_t flags2;