Add the cli_wct_ofs routine to calculate the offset for write&x
authorVolker Lendecke <vl@samba.org>
Fri, 19 Dec 2008 17:12:44 +0000 (18:12 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 19 Dec 2008 17:12:44 +0000 (18:12 +0100)
source3/include/async_smb.h
source3/libsmb/async_smb.c

index ef53ee21639c8f1683bec362634c4041554b63ef..7fc4ff7d27976ae90160ff8806e1a5951bb4ac8e 100644 (file)
@@ -122,6 +122,8 @@ struct async_req *cli_request_send(TALLOC_CTX *mem_ctx,
                                   size_t bytes_alignment,
                                   uint32_t num_bytes, const uint8_t *bytes);
 
+uint16_t cli_wct_ofs(const struct cli_state *cli);
+
 bool cli_chain_cork(struct cli_state *cli, struct event_context *ev,
                    size_t size_hint);
 void cli_chain_uncork(struct cli_state *cli);
index fdcbb002061ba7ce7e23e550787515bd63e03a8c..52bfc7500926b654355b749485f8019c9bd3fcd8 100644 (file)
@@ -638,6 +638,37 @@ struct async_req *cli_request_send(TALLOC_CTX *mem_ctx,
        return result;
 }
 
+/**
+ * Calculate the current ofs to wct for requests like write&x
+ * @param[in] req      The smb request we're currently building
+ * @retval how many bytes offset have we accumulated?
+ */
+
+uint16_t cli_wct_ofs(const struct cli_state *cli)
+{
+       size_t buf_size;
+
+       if (cli->chain_accumulator == NULL) {
+               return smb_wct - 4;
+       }
+
+       buf_size = talloc_get_size(cli->chain_accumulator->outbuf);
+
+       if (buf_size == smb_wct) {
+               return smb_wct - 4;
+       }
+
+       /*
+        * Add alignment for subsequent requests
+        */
+
+       if ((buf_size % 4) != 0) {
+               buf_size += (4 - (buf_size % 4));
+       }
+
+       return buf_size - 4;
+}
+
 /**
  * Figure out if there is an andx command behind the current one
  * @param[in] buf      The smb buffer to look at