s3: Add cli_flush
authorVolker Lendecke <vl@samba.org>
Fri, 13 Aug 2010 12:01:03 +0000 (14:01 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 18 Aug 2010 13:14:02 +0000 (15:14 +0200)
source3/include/proto.h
source3/libsmb/clifile.c

index 5c664ebe54ae9c73de87b67880c065d06c9dd8ec..631d2868ec4e1d2539ee0c6afd627156d63f7925 100644 (file)
@@ -2483,6 +2483,13 @@ NTSTATUS cli_qpathinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli,
                       uint32_t max_rdata,
                       uint8_t **rdata, uint32_t *num_rdata);
 
+struct tevent_req *cli_flush_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct cli_state *cli,
+                                 uint16_t fnum);
+NTSTATUS cli_flush_recv(struct tevent_req *req);
+NTSTATUS cli_flush(TALLOC_CTX *mem_ctx, struct cli_state *cli, uint16_t fnum);
+
 /* The following definitions come from libsmb/clirap2.c  */
 struct rap_group_info_1;
 struct rap_user_info_1;
index 48af0cc56d9e4553d238fed2233e9343c41ee516..8965f6c71fb6cc8c0fa8224d6c4fa356f21d6449 100644 (file)
@@ -5243,3 +5243,86 @@ NTSTATUS cli_qpathinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli,
        }
        return status;
 }
+
+struct cli_flush_state {
+       uint16_t vwv[1];
+};
+
+static void cli_flush_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_flush_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct cli_state *cli,
+                                 uint16_t fnum)
+{
+       struct tevent_req *req, *subreq;
+       struct cli_flush_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct cli_flush_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       SSVAL(state->vwv + 0, 0, fnum);
+
+       subreq = cli_smb_send(state, ev, cli, SMBflush, 0, 1, state->vwv,
+                             0, NULL);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_flush_done, req);
+       return req;
+}
+
+static void cli_flush_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       NTSTATUS status;
+
+       status = cli_smb_recv(subreq, NULL, NULL, 0, NULL, NULL, NULL, NULL);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS cli_flush_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_flush(TALLOC_CTX *mem_ctx, struct cli_state *cli, uint16_t fnum)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct event_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+       if (cli_has_async_calls(cli)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
+       }
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_flush_send(frame, ev, cli, fnum);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_flush_recv(req);
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
+}