r4754: tidied up the composite function infrastructure to make it easier to
authorAndrew Tridgell <tridge@samba.org>
Sat, 15 Jan 2005 10:29:43 +0000 (10:29 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:08:50 +0000 (13:08 -0500)
have composite functions that are not made up of functions that
operate on smbcli_request structures.
(This used to be commit 4f6055b4fb7e287a29544ff1ca4e22f698efc478)

source4/libcli/composite/composite.c
source4/libcli/composite/composite.h
source4/libcli/composite/loadfile.c
source4/libcli/composite/savefile.c

index f7e23cd4bc61831999712abfabae6ec2a318ec6f..d4eb5a93233f4d5ea273047033a6e7be155f7e7e 100644 (file)
@@ -34,7 +34,7 @@ NTSTATUS smb_composite_wait(struct smbcli_composite *c)
        if (c == NULL) return NT_STATUS_NO_MEMORY;
 
        while (c->state < SMBCLI_REQUEST_DONE) {
-               if (event_loop_once(c->req->transport->event.ctx) != 0) {
+               if (event_loop_once(c->event_ctx) != 0) {
                        return NT_STATUS_UNSUCCESSFUL;
                }
        }
index 7b9477a9425da1c2650511f4412820bb8d0371d7..6bffc632115e74892140e5b2d607f795b83de2f4 100644 (file)
@@ -37,7 +37,7 @@ struct smbcli_composite {
        uint16_t stage;
 
        /* the currently running sub-request */
-       struct smbcli_request *req;
+       void *req;
 
        /* the current requests parameter block */
        void *req_parms;
@@ -51,6 +51,9 @@ struct smbcli_composite {
        /* status code when finished */
        NTSTATUS status;
 
+       /* the event context we are using */
+       struct event_context *event_ctx;
+
        /* information on what to do on completion */
        struct {
                void (*fn)(struct smbcli_composite *);
index 61260aa9637dee2935a8682fe090e7a8f49516d9..d8311e91511895edcafa0beea81e437d3ae8de1d 100644 (file)
@@ -40,6 +40,7 @@ static NTSTATUS setup_close(struct smbcli_composite *c,
                            struct smbcli_tree *tree, uint16_t fnum)
 {
        union smb_close *io_close;
+       struct smbcli_request *req;
 
        /* nothing to read, setup the close */
        io_close = talloc(c, union smb_close);
@@ -49,14 +50,15 @@ static NTSTATUS setup_close(struct smbcli_composite *c,
        io_close->close.in.fnum = fnum;
        io_close->close.in.write_time = 0;
 
-       c->req = smb_raw_close_send(tree, io_close);
-       NT_STATUS_HAVE_NO_MEMORY(c->req);
+       req = smb_raw_close_send(tree, io_close);
+       NT_STATUS_HAVE_NO_MEMORY(req);
 
        /* call the handler again when the close is done */
-       c->stage = LOADFILE_CLOSE;
-       c->req->async.fn = loadfile_handler;
-       c->req->async.private = c;
+       req->async.fn = loadfile_handler;
+       req->async.private = c;
        c->req_parms = io_close;
+       c->req = req;
+       c->stage = LOADFILE_CLOSE;
 
        return NT_STATUS_OK;
 }
@@ -69,11 +71,12 @@ static NTSTATUS loadfile_open(struct smbcli_composite *c,
                              struct smb_composite_loadfile *io)
 {
        union smb_open *io_open = c->req_parms;
-       struct smbcli_tree *tree = c->req->tree;
+       struct smbcli_request *req = c->req;
+       struct smbcli_tree *tree = req->tree;
        union smb_read *io_read;
        NTSTATUS status;
 
-       status = smb_raw_open_recv(c->req, c, io_open);
+       status = smb_raw_open_recv(req, c, io_open);
        NT_STATUS_NOT_OK_RETURN(status);
        
        /* don't allow stupidly large loads */
@@ -102,14 +105,16 @@ static NTSTATUS loadfile_open(struct smbcli_composite *c,
        io_read->readx.in.remaining = 0;
        io_read->readx.out.data     = io->out.data;
 
-       c->req = smb_raw_read_send(tree, io_read);
-       NT_STATUS_HAVE_NO_MEMORY(c->req);
+       req = smb_raw_read_send(tree, io_read);
+       NT_STATUS_HAVE_NO_MEMORY(req);
 
        /* call the handler again when the first read is done */
-       c->stage = LOADFILE_READ;
-       c->req->async.fn = loadfile_handler;
-       c->req->async.private = c;
+       req->async.fn = loadfile_handler;
+       req->async.private = c;
        c->req_parms = io_read;
+       c->req = req;
+       c->stage = LOADFILE_READ;
+
        talloc_free(io_open);
 
        return NT_STATUS_OK;
@@ -124,10 +129,11 @@ static NTSTATUS loadfile_read(struct smbcli_composite *c,
                              struct smb_composite_loadfile *io)
 {
        union smb_read *io_read = c->req_parms;
-       struct smbcli_tree *tree = c->req->tree;
+       struct smbcli_request *req = c->req;
+       struct smbcli_tree *tree = req->tree;
        NTSTATUS status;
 
-       status = smb_raw_read_recv(c->req, io_read);
+       status = smb_raw_read_recv(req, io_read);
        NT_STATUS_NOT_OK_RETURN(status);
        
        /* we might be done */
@@ -141,12 +147,13 @@ static NTSTATUS loadfile_read(struct smbcli_composite *c,
        io_read->readx.in.mincnt = MIN(32768, io->out.size - io_read->readx.in.offset);
        io_read->readx.out.data = io->out.data + io_read->readx.in.offset;
 
-       c->req = smb_raw_read_send(tree, io_read);
-       NT_STATUS_HAVE_NO_MEMORY(c->req);
+       req = smb_raw_read_send(tree, io_read);
+       NT_STATUS_HAVE_NO_MEMORY(req);
 
        /* call the handler again when the read is done */
-       c->req->async.fn = loadfile_handler;
-       c->req->async.private = c;
+       req->async.fn = loadfile_handler;
+       req->async.private = c;
+       c->req = req;
 
        return NT_STATUS_OK;
 }
@@ -158,8 +165,9 @@ static NTSTATUS loadfile_close(struct smbcli_composite *c,
                               struct smb_composite_loadfile *io)
 {
        NTSTATUS status;
+       struct smbcli_request *req = c->req;
 
-       status = smbcli_request_simple_recv(c->req);
+       status = smbcli_request_simple_recv(req);
        NT_STATUS_NOT_OK_RETURN(status);
        
        c->state = SMBCLI_REQUEST_DONE;
@@ -212,13 +220,14 @@ struct smbcli_composite *smb_composite_loadfile_send(struct smbcli_tree *tree,
 {
        struct smbcli_composite *c;
        union smb_open *io_open;
+       struct smbcli_request *req;
 
        c = talloc_zero(tree, struct smbcli_composite);
        if (c == NULL) goto failed;
 
        c->state = SMBCLI_REQUEST_SEND;
-       c->stage = LOADFILE_OPEN;
        c->composite_parms = io;
+       c->event_ctx = tree->session->transport->socket->event.ctx;
 
        /* setup for the open */
        io_open = talloc_zero(c, union smb_open);
@@ -234,13 +243,15 @@ struct smbcli_composite *smb_composite_loadfile_send(struct smbcli_tree *tree,
        io_open->ntcreatex.in.fname            = io->in.fname;
 
        /* send the open on its way */
-       c->req = smb_raw_open_send(tree, io_open);
-       if (c->req == NULL) goto failed;
+       req = smb_raw_open_send(tree, io_open);
+       if (req == NULL) goto failed;
 
        /* setup the callback handler */
-       c->req->async.fn = loadfile_handler;
-       c->req->async.private = c;
+       req->async.fn = loadfile_handler;
+       req->async.private = c;
        c->req_parms = io_open;
+       c->req = req;
+       c->stage = LOADFILE_OPEN;
 
        return c;
 
index dc9ee2f9eccbce6c57cadcd25ff4e490f79e1ff0..af9d81b16b1fc592f49819d092d41fac635c7341 100644 (file)
@@ -44,6 +44,7 @@ static NTSTATUS setup_close(struct smbcli_composite *c,
                            struct smbcli_tree *tree, uint16_t fnum)
 {
        union smb_close *io_close;
+       struct smbcli_request *req = c->req;
 
        /* nothing to write, setup the close */
        io_close = talloc(c, union smb_close);
@@ -53,14 +54,15 @@ static NTSTATUS setup_close(struct smbcli_composite *c,
        io_close->close.in.fnum = fnum;
        io_close->close.in.write_time = 0;
 
-       c->req = smb_raw_close_send(tree, io_close);
-       NT_STATUS_HAVE_NO_MEMORY(c->req);
+       req = smb_raw_close_send(tree, io_close);
+       NT_STATUS_HAVE_NO_MEMORY(req);
 
        /* call the handler again when the close is done */
        c->stage = SAVEFILE_CLOSE;
-       c->req->async.fn = savefile_handler;
-       c->req->async.private = c;
+       req->async.fn = savefile_handler;
+       req->async.private = c;
        c->req_parms = io_close;
+       c->req = req;
 
        return NT_STATUS_OK;
 }
@@ -73,7 +75,8 @@ static NTSTATUS savefile_open(struct smbcli_composite *c,
                              struct smb_composite_savefile *io)
 {
        union smb_open *io_open = c->req_parms;
-       struct smbcli_tree *tree = c->req->tree;
+       struct smbcli_request *req = c->req;
+       struct smbcli_tree *tree = req->tree;
        union smb_write *io_write;
        NTSTATUS status;
        uint32_t max_xmit = tree->session->transport->negotiate.max_xmit;
@@ -97,14 +100,15 @@ static NTSTATUS savefile_open(struct smbcli_composite *c,
        io_write->writex.in.count     = MIN(max_xmit - 100, io->in.size);
        io_write->writex.in.data      = io->in.data;
 
-       c->req = smb_raw_write_send(tree, io_write);
-       NT_STATUS_HAVE_NO_MEMORY(c->req);
+       req = smb_raw_write_send(tree, io_write);
+       NT_STATUS_HAVE_NO_MEMORY(req);
 
        /* call the handler again when the first write is done */
        c->stage = SAVEFILE_WRITE;
-       c->req->async.fn = savefile_handler;
-       c->req->async.private = c;
+       req->async.fn = savefile_handler;
+       req->async.private = c;
        c->req_parms = io_write;
+       c->req = req;
        talloc_free(io_open);
 
        return NT_STATUS_OK;
@@ -119,7 +123,8 @@ static NTSTATUS savefile_write(struct smbcli_composite *c,
                              struct smb_composite_savefile *io)
 {
        union smb_write *io_write = c->req_parms;
-       struct smbcli_tree *tree = c->req->tree;
+       struct smbcli_request *req = c->req;
+       struct smbcli_tree *tree = req->tree;
        struct savefile_state *state = c->private;
        NTSTATUS status;
        uint32_t max_xmit = tree->session->transport->negotiate.max_xmit;
@@ -140,12 +145,13 @@ static NTSTATUS savefile_write(struct smbcli_composite *c,
        io_write->writex.in.count = MIN(max_xmit - 100, io->in.size - state->total_written);
        io_write->writex.in.data = io->in.data + state->total_written;
 
-       c->req = smb_raw_write_send(tree, io_write);
-       NT_STATUS_HAVE_NO_MEMORY(c->req);
+       req = smb_raw_write_send(tree, io_write);
+       NT_STATUS_HAVE_NO_MEMORY(req);
 
        /* call the handler again when the write is done */
-       c->req->async.fn = savefile_handler;
-       c->req->async.private = c;
+       req->async.fn = savefile_handler;
+       req->async.private = c;
+       c->req = req;
 
        return NT_STATUS_OK;
 }
@@ -217,6 +223,7 @@ struct smbcli_composite *smb_composite_savefile_send(struct smbcli_tree *tree,
        struct smbcli_composite *c;
        union smb_open *io_open;
        struct savefile_state *state;
+       struct smbcli_request *req;
 
        c = talloc_zero(tree, struct smbcli_composite);
        if (c == NULL) goto failed;
@@ -224,6 +231,7 @@ struct smbcli_composite *smb_composite_savefile_send(struct smbcli_tree *tree,
        c->state = SMBCLI_REQUEST_SEND;
        c->stage = SAVEFILE_OPEN;
        c->composite_parms = io;
+       c->event_ctx = tree->session->transport->socket->event.ctx;
 
        state = talloc(c, struct savefile_state);
        if (state == NULL) goto failed;
@@ -244,14 +252,15 @@ struct smbcli_composite *smb_composite_savefile_send(struct smbcli_tree *tree,
        io_open->ntcreatex.in.fname            = io->in.fname;
 
        /* send the open on its way */
-       c->req = smb_raw_open_send(tree, io_open);
-       if (c->req == NULL) goto failed;
+       req = smb_raw_open_send(tree, io_open);
+       if (req == NULL) goto failed;
 
        /* setup the callback handler */
-       c->req->async.fn = savefile_handler;
-       c->req->async.private = c;
+       req->async.fn = savefile_handler;
+       req->async.private = c;
        c->req_parms = io_open;
        c->private = state;
+       c->req = req;
 
        return c;