s3: Make read_smb_send/recv public
authorVolker Lendecke <vl@samba.org>
Thu, 19 May 2011 06:23:50 +0000 (08:23 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 19 May 2011 11:46:47 +0000 (13:46 +0200)
source3/Makefile.in
source3/libsmb/async_smb.c
source3/libsmb/read_smb.c [new file with mode: 0644]
source3/libsmb/read_smb.h [new file with mode: 0644]

index 847f811e8976482b581c35dd43d4837787568571..03b427389a9a1583716cc8029d5fcd1ba7b37533 100644 (file)
@@ -595,6 +595,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
             libsmb/clistr.o libsmb/cliquota.o libsmb/clifsinfo.o libsmb/clidfs.o \
             libsmb/clioplock.o libsmb/clirap2.o \
             libsmb/smb_seal.o libsmb/async_smb.o \
+            libsmb/read_smb.o \
             libsmb/cli_np_tstream.o \
             libsmb/smbsock_connect.o \
             $(LIBSAMBA_OBJ) \
index 82dbc74e5bff286681348110745a1b4224110195..182e652f36b72337309a70d56ae3253172c4dfb3 100644 (file)
 #include "async_smb.h"
 #include "smb_crypt.h"
 #include "libsmb/nmblib.h"
-
-/*
- * Read an smb packet asynchronously, discard keepalives
- */
-
-struct read_smb_state {
-       struct tevent_context *ev;
-       int fd;
-       uint8_t *buf;
-};
-
-static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data);
-static void read_smb_done(struct tevent_req *subreq);
-
-static struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
-                                       struct tevent_context *ev,
-                                       int fd)
-{
-       struct tevent_req *result, *subreq;
-       struct read_smb_state *state;
-
-       result = tevent_req_create(mem_ctx, &state, struct read_smb_state);
-       if (result == NULL) {
-               return NULL;
-       }
-       state->ev = ev;
-       state->fd = fd;
-
-       subreq = read_packet_send(state, ev, fd, 4, read_smb_more, NULL);
-       if (subreq == NULL) {
-               goto fail;
-       }
-       tevent_req_set_callback(subreq, read_smb_done, result);
-       return result;
- fail:
-       TALLOC_FREE(result);
-       return NULL;
-}
-
-static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data)
-{
-       if (buflen > 4) {
-               return 0;       /* We've been here, we're done */
-       }
-       return smb_len_large(buf);
-}
-
-static void read_smb_done(struct tevent_req *subreq)
-{
-       struct tevent_req *req = tevent_req_callback_data(
-               subreq, struct tevent_req);
-       struct read_smb_state *state = tevent_req_data(
-               req, struct read_smb_state);
-       ssize_t len;
-       int err;
-
-       len = read_packet_recv(subreq, state, &state->buf, &err);
-       TALLOC_FREE(subreq);
-       if (len == -1) {
-               tevent_req_error(req, err);
-               return;
-       }
-
-       if (CVAL(state->buf, 0) == SMBkeepalive) {
-               subreq = read_packet_send(state, state->ev, state->fd, 4,
-                                         read_smb_more, NULL);
-               if (tevent_req_nomem(subreq, req)) {
-                       return;
-               }
-               tevent_req_set_callback(subreq, read_smb_done, req);
-               return;
-       }
-       tevent_req_done(req);
-}
-
-static ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-                            uint8_t **pbuf, int *perrno)
-{
-       struct read_smb_state *state = tevent_req_data(
-               req, struct read_smb_state);
-
-       if (tevent_req_is_unix_error(req, perrno)) {
-               return -1;
-       }
-       *pbuf = talloc_move(mem_ctx, &state->buf);
-       return talloc_get_size(*pbuf);
-}
+#include "read_smb.h"
 
 /**
  * Fetch an error out of a NBT packet
diff --git a/source3/libsmb/read_smb.c b/source3/libsmb/read_smb.c
new file mode 100644 (file)
index 0000000..5397fdb
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+   Unix SMB/CIFS implementation.
+   Infrastructure for async SMB client requests
+   Copyright (C) Volker Lendecke 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/async_req/async_sock.h"
+#include "read_smb.h"
+#include "lib/util/tevent_unix.h"
+
+/*
+ * Read an smb packet asynchronously, discard keepalives
+ */
+
+struct read_smb_state {
+       struct tevent_context *ev;
+       int fd;
+       uint8_t *buf;
+};
+
+static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data);
+static void read_smb_done(struct tevent_req *subreq);
+
+struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
+                                struct tevent_context *ev,
+                                int fd)
+{
+       struct tevent_req *result, *subreq;
+       struct read_smb_state *state;
+
+       result = tevent_req_create(mem_ctx, &state, struct read_smb_state);
+       if (result == NULL) {
+               return NULL;
+       }
+       state->ev = ev;
+       state->fd = fd;
+
+       subreq = read_packet_send(state, ev, fd, 4, read_smb_more, NULL);
+       if (subreq == NULL) {
+               goto fail;
+       }
+       tevent_req_set_callback(subreq, read_smb_done, result);
+       return result;
+ fail:
+       TALLOC_FREE(result);
+       return NULL;
+}
+
+static ssize_t read_smb_more(uint8_t *buf, size_t buflen, void *private_data)
+{
+       if (buflen > 4) {
+               return 0;       /* We've been here, we're done */
+       }
+       return smb_len_large(buf);
+}
+
+static void read_smb_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct read_smb_state *state = tevent_req_data(
+               req, struct read_smb_state);
+       ssize_t len;
+       int err;
+
+       len = read_packet_recv(subreq, state, &state->buf, &err);
+       TALLOC_FREE(subreq);
+       if (len == -1) {
+               tevent_req_error(req, err);
+               return;
+       }
+
+       if (CVAL(state->buf, 0) == SMBkeepalive) {
+               subreq = read_packet_send(state, state->ev, state->fd, 4,
+                                         read_smb_more, NULL);
+               if (tevent_req_nomem(subreq, req)) {
+                       return;
+               }
+               tevent_req_set_callback(subreq, read_smb_done, req);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                     uint8_t **pbuf, int *perrno)
+{
+       struct read_smb_state *state = tevent_req_data(
+               req, struct read_smb_state);
+
+       if (tevent_req_is_unix_error(req, perrno)) {
+               return -1;
+       }
+       *pbuf = talloc_move(mem_ctx, &state->buf);
+       return talloc_get_size(*pbuf);
+}
diff --git a/source3/libsmb/read_smb.h b/source3/libsmb/read_smb.h
new file mode 100644 (file)
index 0000000..ae4dfdd
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+   Unix SMB/CIFS implementation.
+   Infrastructure for async SMB client requests
+   Copyright (C) Volker Lendecke 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __LIBSMB_READ_SMB_H
+#define __LIBSMB_READ_SMB_H
+
+#include "lib/talloc/talloc.h"
+#include "lib/tevent/tevent.h"
+
+struct tevent_req *read_smb_send(TALLOC_CTX *mem_ctx,
+                                struct tevent_context *ev,
+                                int fd);
+
+ssize_t read_smb_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                     uint8_t **pbuf, int *perrno);
+
+#endif