Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / libcli / raw / clitransport.c
index 5c14e9f9b8d1f819eed9ff3afcf7ba43f15b0d15..7a3993c79bf5083ddddb3a9709e9f3266c96e02d 100644 (file)
 
 #include "includes.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
 #include "lib/socket/socket.h"
-#include "lib/util/dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "lib/events/events.h"
 #include "lib/stream/packet.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
-#include "param/param.h"
+#include "../libcli/nbt/libnbt.h"
 
 
 /*
   an event has happened on the socket
 */
-static void smbcli_transport_event_handler(struct event_context *ev, 
-                                          struct fd_event *fde, 
-                                          uint16_t flags, void *private)
+static void smbcli_transport_event_handler(struct tevent_context *ev, 
+                                          struct tevent_fd *fde, 
+                                          uint16_t flags, void *private_data)
 {
-       struct smbcli_transport *transport = talloc_get_type(private,
+       struct smbcli_transport *transport = talloc_get_type(private_data,
                                                             struct smbcli_transport);
        if (flags & EVENT_FD_READ) {
                packet_recv(transport->packet);
@@ -60,13 +61,13 @@ static int transport_destructor(struct smbcli_transport *transport)
 /*
   handle receive errors
 */
-static void smbcli_transport_error(void *private, NTSTATUS status)
+static void smbcli_transport_error(void *private_data, NTSTATUS status)
 {
-       struct smbcli_transport *transport = talloc_get_type(private, struct smbcli_transport);
+       struct smbcli_transport *transport = talloc_get_type(private_data, struct smbcli_transport);
        smbcli_transport_dead(transport, status);
 }
 
-static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob);
+static NTSTATUS smbcli_transport_finish_recv(void *private_data, DATA_BLOB blob);
 
 /*
   create a transport structure based on an established socket
@@ -103,6 +104,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock,
        packet_set_error_handler(transport->packet, smbcli_transport_error);
        packet_set_event_context(transport->packet, transport->socket->event.ctx);
        packet_set_nofree(transport->packet);
+       packet_set_initial_read(transport->packet, 4);
 
        smbcli_init_signing(transport);
 
@@ -164,15 +166,14 @@ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *tr
        DATA_BLOB calling_blob, called_blob;
        TALLOC_CTX *tmp_ctx = talloc_new(transport);
        NTSTATUS status;
-       struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm);
 
        status = nbt_name_dup(transport, called, &transport->called);
        if (!NT_STATUS_IS_OK(status)) goto failed;
        
-       status = nbt_name_to_blob(tmp_ctx, iconv_convenience, &calling_blob, calling);
+       status = nbt_name_to_blob(tmp_ctx, &calling_blob, calling);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
-       status = nbt_name_to_blob(tmp_ctx, iconv_convenience, &called_blob, called);
+       status = nbt_name_to_blob(tmp_ctx, &called_blob, called);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* allocate output buffer */
@@ -305,30 +306,30 @@ again:
        return mid;
 }
 
-static void idle_handler(struct event_context *ev, 
-                        struct timed_event *te, struct timeval t, void *private)
+static void idle_handler(struct tevent_context *ev, 
+                        struct tevent_timer *te, struct timeval t, void *private_data)
 {
-       struct smbcli_transport *transport = talloc_get_type(private,
+       struct smbcli_transport *transport = talloc_get_type(private_data,
                                                             struct smbcli_transport);
        struct timeval next = timeval_add(&t, 0, transport->idle.period);
        transport->socket->event.te = event_add_timed(transport->socket->event.ctx, 
                                                      transport,
                                                      next,
                                                      idle_handler, transport);
-       transport->idle.func(transport, transport->idle.private);
+       transport->idle.func(transport, transport->idle.private_data);
 }
 
 /*
   setup the idle handler for a transport
   the period is in microseconds
 */
-void smbcli_transport_idle_handler(struct smbcli_transport *transport, 
+_PUBLIC_ void smbcli_transport_idle_handler(struct smbcli_transport *transport, 
                                   void (*idle_func)(struct smbcli_transport *, void *),
                                   uint64_t period,
-                                  void *private)
+                                  void *private_data)
 {
        transport->idle.func = idle_func;
-       transport->idle.private = private;
+       transport->idle.private_data = private_data;
        transport->idle.period = period;
 
        if (transport->socket->event.te != NULL) {
@@ -345,9 +346,9 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport,
   we have a full request in our receive buffer - match it to a pending request
   and process
  */
-static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob)
+static NTSTATUS smbcli_transport_finish_recv(void *private_data, DATA_BLOB blob)
 {
-       struct smbcli_transport *transport = talloc_get_type(private
+       struct smbcli_transport *transport = talloc_get_type(private_data,
                                                             struct smbcli_transport);
        uint8_t *buffer, *hdr, *vwv;
        int len;
@@ -448,12 +449,12 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob)
        smb_setup_bufinfo(req);
 
        if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) {
-               int class = CVAL(req->in.hdr,HDR_RCLS);
+               int eclass = CVAL(req->in.hdr,HDR_RCLS);
                int code = SVAL(req->in.hdr,HDR_ERR);
-               if (class == 0 && code == 0) {
+               if (eclass == 0 && code == 0) {
                        transport->error.e.nt_status = NT_STATUS_OK;
                } else {
-                       transport->error.e.nt_status = NT_STATUS_DOS(class, code);
+                       transport->error.e.nt_status = NT_STATUS_DOS(eclass, code);
                }
        } else {
                transport->error.e.nt_status = NT_STATUS(IVAL(req->in.hdr, HDR_RCLS));
@@ -478,8 +479,22 @@ async:
        /* if this request has an async handler then call that to
           notify that the reply has been received. This might destroy
           the request so it must happen last */
-       DLIST_REMOVE(transport->pending_recv, req);
+
        req->state = SMBCLI_REQUEST_DONE;
+
+       if (req->recv_helper.fn) {
+               /*
+                * let the recv helper decide in
+                * what state the request really is
+                */
+               req->state = req->recv_helper.fn(req);
+
+               /* if more parts are needed, wait for them */
+               if (req->state <= SMBCLI_REQUEST_RECV) {
+                       return NT_STATUS_OK;
+               }
+       }
+       DLIST_REMOVE(transport->pending_recv, req);
        if (req->async.fn) {
                req->async.fn(req);
        }
@@ -502,7 +517,7 @@ error:
   process some read/write requests that are pending
   return false if the socket is dead
 */
-bool smbcli_transport_process(struct smbcli_transport *transport)
+_PUBLIC_ bool smbcli_transport_process(struct smbcli_transport *transport)
 {
        NTSTATUS status;
        size_t npending;
@@ -525,10 +540,10 @@ bool smbcli_transport_process(struct smbcli_transport *transport)
 /*
   handle timeouts of individual smb requests
 */
-static void smbcli_timeout_handler(struct event_context *ev, struct timed_event *te, 
-                                  struct timeval t, void *private)
+static void smbcli_timeout_handler(struct tevent_context *ev, struct tevent_timer *te, 
+                                  struct timeval t, void *private_data)
 {
-       struct smbcli_request *req = talloc_get_type(private, struct smbcli_request);
+       struct smbcli_request *req = talloc_get_type(private_data, struct smbcli_request);
 
        if (req->state == SMBCLI_REQUEST_RECV) {
                DLIST_REMOVE(req->transport->pending_recv, req);
@@ -576,6 +591,13 @@ void smbcli_transport_send(struct smbcli_request *req)
                return;
        }
 
+       packet_queue_run(req->transport->packet);
+       if (req->transport->socket->sock == NULL) {
+               req->state = SMBCLI_REQUEST_ERROR;
+               req->status = NT_STATUS_NET_WRITE_FAULT;
+               return;
+       }
+
        if (req->one_way_request) {
                req->state = SMBCLI_REQUEST_DONE;
                smbcli_request_destroy(req);
@@ -599,7 +621,7 @@ void smbcli_transport_send(struct smbcli_request *req)
 /****************************************************************************
  Send an SMBecho (async send)
 *****************************************************************************/
-struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
+_PUBLIC_ struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
                                         struct smb_echo *p)
 {
        struct smbcli_request *req;