From 4e4afdb94685388f56061a5cc188a5f5b8e1ae52 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Jan 2005 10:29:43 +0000 Subject: r4754: tidied up the composite function infrastructure to make it easier to 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 | 2 +- source4/libcli/composite/composite.h | 5 ++- source4/libcli/composite/loadfile.c | 59 +++++++++++++++++++++--------------- source4/libcli/composite/savefile.c | 45 ++++++++++++++++----------- 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/source4/libcli/composite/composite.c b/source4/libcli/composite/composite.c index f7e23cd4bc..d4eb5a9323 100644 --- a/source4/libcli/composite/composite.c +++ b/source4/libcli/composite/composite.c @@ -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; } } diff --git a/source4/libcli/composite/composite.h b/source4/libcli/composite/composite.h index 7b9477a942..6bffc63211 100644 --- a/source4/libcli/composite/composite.h +++ b/source4/libcli/composite/composite.h @@ -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 *); diff --git a/source4/libcli/composite/loadfile.c b/source4/libcli/composite/loadfile.c index 61260aa963..d8311e9151 100644 --- a/source4/libcli/composite/loadfile.c +++ b/source4/libcli/composite/loadfile.c @@ -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; diff --git a/source4/libcli/composite/savefile.c b/source4/libcli/composite/savefile.c index dc9ee2f9ec..af9d81b16b 100644 --- a/source4/libcli/composite/savefile.c +++ b/source4/libcli/composite/savefile.c @@ -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; -- cgit