Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / libcli / raw / clitransport.c
index 502ecc18253987843d92e3356337ab1e3a5432eb..7a3993c79bf5083ddddb3a9709e9f3266c96e02d 100644 (file)
 /*
   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);
@@ -61,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
@@ -75,8 +75,7 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob);
 struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock,
                                               TALLOC_CTX *parent_ctx, 
                                               bool primary, 
-                                              struct smbcli_options *options,
-                                                  struct smb_iconv_convenience *iconv_convenience)
+                                              struct smbcli_options *options)
 {
        struct smbcli_transport *transport;
 
@@ -91,7 +90,6 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock,
        transport->negotiate.protocol = PROTOCOL_NT1;
        transport->options = *options;
        transport->negotiate.max_xmit = transport->options.max_xmit;
-       transport->iconv_convenience = iconv_convenience;
 
        /* setup the stream -> packet parser */
        transport->packet = packet_init(transport);
@@ -106,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);
 
@@ -171,10 +170,10 @@ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *tr
        status = nbt_name_dup(transport, called, &transport->called);
        if (!NT_STATUS_IS_OK(status)) goto failed;
        
-       status = nbt_name_to_blob(tmp_ctx, transport->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, transport->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 */
@@ -307,17 +306,17 @@ 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);
 }
 
 /*
@@ -327,10 +326,10 @@ static void idle_handler(struct event_context *ev,
 _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) {
@@ -347,9 +346,9 @@ _PUBLIC_ 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;
@@ -450,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));
@@ -541,10 +540,10 @@ _PUBLIC_ 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);
@@ -592,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);