s3:libsmb: Avoid duplicated code by making cli_read_sink() public
authorTim Beale <timbeale@catalyst.net.nz>
Thu, 3 Jan 2019 04:48:39 +0000 (17:48 +1300)
committerTim Beale <timbeale@samba.org>
Mon, 7 Jan 2019 00:23:08 +0000 (01:23 +0100)
cli_read_sink() and pull_helper() were essentially identical. By making
cli_read_sink() non-static, we can delete the latter.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source3/libsmb/clireadwrite.c
source3/libsmb/proto.h
source3/libsmb/pylibsmb.c

index e953fa5e22860af95d1456f8f94bfafcaf861f8e..da188db7c3176db8b24eb021a7487d2da0178ede 100644 (file)
@@ -822,7 +822,11 @@ NTSTATUS cli_read_recv(struct tevent_req *req, size_t *received)
        return NT_STATUS_OK;
 }
 
-static NTSTATUS cli_read_sink(char *buf, size_t n, void *priv)
+/*
+ * Helper function for cli_pull(). This takes a chunk of data (buf) read from
+ * a remote file and copies it into the return buffer (priv).
+ */
+NTSTATUS cli_read_sink(char *buf, size_t n, void *priv)
 {
        char **pbuf = (char **)priv;
        memcpy(*pbuf, buf, n);
index bfad4dcc011d24e04bcf9fc8dcd907f8ab7b6991..b0cfcb5aa90b2e0310c8c4a31cf72af2cd054175 100644 (file)
@@ -840,6 +840,7 @@ NTSTATUS cli_pull(struct cli_state *cli, uint16_t fnum,
                  off_t start_offset, off_t size, size_t window_size,
                  NTSTATUS (*sink)(char *buf, size_t n, void *priv),
                  void *priv, off_t *received);
+NTSTATUS cli_read_sink(char *buf, size_t n, void *priv);
 struct tevent_req *cli_read_send(
        TALLOC_CTX *mem_ctx,
        struct tevent_context *ev,
index 2190b7c9c4a3928e6f225f5e77c7d7b45b7a5501..08de5d0f531e9e52527410bced23943d8496f591 100644 (file)
@@ -895,14 +895,6 @@ static NTSTATUS py_smb_filesize(struct py_cli_state *self, uint16_t fnum,
        return status;
 }
 
-static NTSTATUS pull_helper(char *buf, size_t n, void *priv)
-{
-       char **dest_buf = (char **)priv;
-       memcpy(*dest_buf, buf, n);
-       *dest_buf += n;
-       return NT_STATUS_OK;
-}
-
 /*
  * Loads the specified file's contents and returns it
  */
@@ -946,7 +938,7 @@ static PyObject *py_smb_loadfile(struct py_cli_state *self, PyObject *args,
        /* read the file contents */
        buf = PyBytes_AS_STRING(result);
        req = cli_pull_send(NULL, self->ev, self->cli, fnum, 0, size,
-                           size, pull_helper, &buf);
+                           size, cli_read_sink, &buf);
        if (!py_tevent_req_wait_exc(self, req)) {
                Py_XDECREF(result);
                return NULL;