s3:libsmb: abstract the incoming dispatch function via a function pointer
authorStefan Metzmacher <metze@samba.org>
Fri, 12 Aug 2011 12:50:09 +0000 (14:50 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 12 Aug 2011 16:06:04 +0000 (18:06 +0200)
This will allow handling of SMB2 in future.

metze

source3/include/client.h
source3/libsmb/async_smb.c

index f44e52f8f6d60e38a33d39856bf505b9acc3d732..79ce709069c5c5bbe8cfbe3891c4a5fd94172129 100644 (file)
@@ -128,6 +128,17 @@ struct cli_state {
                struct tevent_req *read_smb_req;
                struct tevent_queue *outgoing;
                struct tevent_req **pending;
+               /*
+                * The incoming dispatch function should return:
+                * - NT_STATUS_RETRY, if more incoming PDUs are expected.
+                * - NT_STATUS_OK, if no more processing is desired, e.g.
+                *                 the dispatch function called
+                *                 tevent_req_done().
+                * - All other return values disconnect the connection.
+                */
+               NTSTATUS (*dispatch_incoming)(struct cli_state *cli,
+                                             TALLOC_CTX *frame,
+                                             uint8_t *inbuf);
        } conn;
 
        struct {
index b3de5af50b0d253b6b3702427d45e5af920c9a9a..b07eee9e10e2b594456497850a7df61b730c80a9 100644 (file)
@@ -228,6 +228,9 @@ bool cli_smb_req_set_pending(struct tevent_req *req)
 }
 
 static void cli_smb_received(struct tevent_req *subreq);
+static NTSTATUS cli_state_dispatch_smb1(struct cli_state *cli,
+                                       TALLOC_CTX *frame,
+                                       uint8_t *inbuf);
 
 static bool cli_state_receive_next(struct cli_state *cli)
 {
@@ -246,6 +249,8 @@ static bool cli_state_receive_next(struct cli_state *cli)
        req = cli->conn.pending[0];
        state = tevent_req_data(req, struct cli_smb_state);
 
+       cli->conn.dispatch_incoming = cli_state_dispatch_smb1;
+
        /*
         * We're the first ones, add the read_smb request that waits for the
         * answer from the server
@@ -579,10 +584,6 @@ static void cli_smb_sent(struct tevent_req *subreq)
        }
 }
 
-static NTSTATUS cli_state_dispatch_smb1(struct cli_state *cli,
-                                       TALLOC_CTX *frame,
-                                       uint8_t *inbuf);
-
 static void cli_smb_received(struct tevent_req *subreq)
 {
        struct cli_state *cli = tevent_req_callback_data(
@@ -612,7 +613,7 @@ static void cli_smb_received(struct tevent_req *subreq)
                return;
        }
 
-       status = cli_state_dispatch_smb1(cli, frame, inbuf);
+       status = cli->conn.dispatch_incoming(cli, frame, inbuf);
        TALLOC_FREE(frame);
        if (NT_STATUS_IS_OK(status)) {
                /*