continue the effort to simplify and generalise the composite
authortridge <tridge@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Sat, 22 Jan 2005 02:51:39 +0000 (02:51 +0000)
committertridge <tridge@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Sat, 22 Jan 2005 02:51:39 +0000 (02:51 +0000)
interface. This patch removes the "stage" variable, which is really
better suited to the backend state structures

git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@4924 0c0555d6-39d7-0310-84fc-f1cc0bd64818

source/libcli/composite/composite.h
source/libcli/composite/connect.c
source/libcli/composite/loadfile.c
source/libcli/composite/savefile.c
source/libcli/raw/clisocket.c

index fba458795c798afca3bbbb3e341746e460b6464f..35d6d94878f1323fe35eb339626dd6908ac1b8f7 100644 (file)
@@ -33,9 +33,6 @@ struct smbcli_composite {
        /* the external state - will be queried by the caller */
        enum smbcli_request_state state;
 
-       /* the internal stage */
-       uint16_t stage;
-
        /* a private pointer for use by the composite function
           implementation */
        void *private;
index 4f6df154a7f2a41b5befa65ed5275932cb82c3f5..2663c789e497bbb513d20f746d7dcb672fe6c94e 100644 (file)
@@ -34,6 +34,7 @@ enum connect_stage {CONNECT_RESOLVE,
                    CONNECT_TCON};
 
 struct connect_state {
+       enum connect_stage stage;
        struct smbcli_socket *sock;
        struct smbcli_transport *transport;
        struct smbcli_session *session;
@@ -61,7 +62,7 @@ static NTSTATUS connect_send_negprot(struct smbcli_composite *c,
 
        state->req->async.fn = request_handler;
        state->req->async.private = c;
-       c->stage = CONNECT_NEGPROT;
+       state->stage = CONNECT_NEGPROT;
        
        return NT_STATUS_OK;
 }
@@ -141,7 +142,7 @@ static NTSTATUS connect_session_setup(struct smbcli_composite *c,
 
        state->req->async.fn = request_handler;
        state->req->async.private = c;
-       c->stage = CONNECT_TCON;
+       state->stage = CONNECT_TCON;
 
        return NT_STATUS_OK;
 }
@@ -180,7 +181,7 @@ static NTSTATUS connect_negprot(struct smbcli_composite *c,
 
        state->creq->async.fn = composite_handler;
        state->creq->async.private = c;
-       c->stage = CONNECT_SESSION_SETUP;
+       state->stage = CONNECT_SESSION_SETUP;
        
        return NT_STATUS_OK;
 }
@@ -240,7 +241,7 @@ static NTSTATUS connect_socket(struct smbcli_composite *c,
 
        state->req->async.fn = request_handler;
        state->req->async.private = c;
-       c->stage = CONNECT_SESSION_REQUEST;
+       state->stage = CONNECT_SESSION_REQUEST;
 
        return NT_STATUS_OK;
 }
@@ -262,7 +263,7 @@ static NTSTATUS connect_resolve(struct smbcli_composite *c,
        state->creq = smbcli_sock_connect_send(state->sock, address, state->io->in.port);
        NT_STATUS_HAVE_NO_MEMORY(state->creq);
 
-       c->stage = CONNECT_SOCKET;
+       state->stage = CONNECT_SOCKET;
        state->creq->async.private = c;
        state->creq->async.fn = composite_handler;
 
@@ -277,7 +278,7 @@ static void state_handler(struct smbcli_composite *c)
 {
        struct connect_state *state = talloc_get_type(c->private, struct connect_state);
 
-       switch (c->stage) {
+       switch (state->stage) {
        case CONNECT_RESOLVE:
                c->status = connect_resolve(c, state->io);
                break;
@@ -346,9 +347,9 @@ struct smbcli_composite *smb_composite_connect_send(struct smb_composite_connect
        if (state->sock == NULL) goto failed;
 
        state->io = io;
+       state->stage = CONNECT_RESOLVE;
 
        c->state = SMBCLI_REQUEST_SEND;
-       c->stage = CONNECT_RESOLVE;
        c->event_ctx = state->sock->event.ctx;
        c->private = state;
 
index 82908762243274db6987db38bd7ebc976195091f..b95f43149e7caf5b8b5bfa593df1fbe26213ccad 100644 (file)
@@ -33,6 +33,7 @@ enum loadfile_stage {LOADFILE_OPEN, LOADFILE_READ, LOADFILE_CLOSE};
 static void loadfile_handler(struct smbcli_request *req);
 
 struct loadfile_state {
+       enum loadfile_stage stage;
        struct smb_composite_loadfile *io;
        struct smbcli_request *req;
        union smb_open *io_open;
@@ -62,7 +63,7 @@ static NTSTATUS setup_close(struct smbcli_composite *c,
        /* call the handler again when the close is done */
        state->req->async.fn = loadfile_handler;
        state->req->async.private = c;
-       c->stage = LOADFILE_CLOSE;
+       state->stage = LOADFILE_CLOSE;
 
        return NT_STATUS_OK;
 }
@@ -113,7 +114,7 @@ static NTSTATUS loadfile_open(struct smbcli_composite *c,
        /* call the handler again when the first read is done */
        state->req->async.fn = loadfile_handler;
        state->req->async.private = c;
-       c->stage = LOADFILE_READ;
+       state->stage = LOADFILE_READ;
 
        talloc_free(state->io_open);
 
@@ -187,7 +188,7 @@ static void loadfile_handler(struct smbcli_request *req)
 
        /* when this handler is called, the stage indicates what
           call has just finished */
-       switch (c->stage) {
+       switch (state->stage) {
        case LOADFILE_OPEN:
                c->status = loadfile_open(c, state->io);
                break;
@@ -251,7 +252,7 @@ struct smbcli_composite *smb_composite_loadfile_send(struct smbcli_tree *tree,
        /* setup the callback handler */
        state->req->async.fn = loadfile_handler;
        state->req->async.private = c;
-       c->stage = LOADFILE_OPEN;
+       state->stage = LOADFILE_OPEN;
 
        return c;
 
index 06eb13bb017a95473ed662c7042fe9107403c221..29d26c7eba4134d6e523d10bd8d1d58c9e0a2327 100644 (file)
 /* the stages of this call */
 enum savefile_stage {SAVEFILE_OPEN, SAVEFILE_WRITE, SAVEFILE_CLOSE};
 
-
 static void savefile_handler(struct smbcli_request *req);
 
 struct savefile_state {
+       enum savefile_stage stage;
        off_t total_written;
        struct smb_composite_savefile *io;
        union smb_open *io_open;
@@ -62,7 +62,7 @@ static NTSTATUS setup_close(struct smbcli_composite *c,
        NT_STATUS_HAVE_NO_MEMORY(state->req);
 
        /* call the handler again when the close is done */
-       c->stage = SAVEFILE_CLOSE;
+       state->stage = SAVEFILE_CLOSE;
        state->req->async.fn = savefile_handler;
        state->req->async.private = c;
 
@@ -106,7 +106,7 @@ static NTSTATUS savefile_open(struct smbcli_composite *c,
        NT_STATUS_HAVE_NO_MEMORY(state->req);
 
        /* call the handler again when the first write is done */
-       c->stage = SAVEFILE_WRITE;
+       state->stage = SAVEFILE_WRITE;
        state->req->async.fn = savefile_handler;
        state->req->async.private = c;
        talloc_free(state->io_open);
@@ -189,7 +189,7 @@ static void savefile_handler(struct smbcli_request *req)
 
        /* when this handler is called, the stage indicates what
           call has just finished */
-       switch (c->stage) {
+       switch (state->stage) {
        case SAVEFILE_OPEN:
                c->status = savefile_open(c, state->io);
                break;
@@ -226,12 +226,12 @@ struct smbcli_composite *smb_composite_savefile_send(struct smbcli_tree *tree,
        if (c == NULL) goto failed;
 
        c->state = SMBCLI_REQUEST_SEND;
-       c->stage = SAVEFILE_OPEN;
        c->event_ctx = tree->session->transport->socket->event.ctx;
 
        state = talloc(c, struct savefile_state);
        if (state == NULL) goto failed;
 
+       state->stage = SAVEFILE_OPEN;
        state->total_written = 0;
        state->io = io;
 
index e9810495355f46259c15b1bfecd26de50bea4aed..cbbd6490bdc5f388a44fb41c54e3f4d1e9305ea9 100644 (file)
@@ -30,6 +30,7 @@
   this private structure is used during async connection handling
 */
 struct clisocket_connect {
+       int port_num;
        int *iports;
        struct smbcli_socket *sock;
        const char *dest_host;
@@ -95,8 +96,8 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even
        }
 
        /* that port failed - try the next port */
-       for (i=c->stage+1;conn->iports[i];i++) {
-               c->stage = i;
+       for (i=conn->port_num+1;conn->iports[i];i++) {
+               conn->port_num = i;
                c->status = smbcli_sock_connect_one(conn->sock, 
                                                    conn->dest_host, 
                                                    conn->iports[i]);
@@ -204,7 +205,7 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock,
        /* startup the connect process for each port in turn until one
           succeeds or tells us that it is pending */
        for (i=0;conn->iports[i];i++) {
-               c->stage = i;
+               conn->port_num = i;
                conn->sock->port = conn->iports[i];
                c->status = smbcli_sock_connect_one(sock, 
                                                    conn->dest_host,