Finish removal of iconv_convenience in public API's.
[amitay/samba.git] / libcli / cldap / cldap.c
index 561ae8037c35be04a8e0be0803915b4cc129da5f..896319e75cdba6373a7b4d06cadaaa2351242afc 100644 (file)
@@ -51,7 +51,7 @@
 */
 struct cldap_socket {
        /* the low level socket */
-       struct tsocket_context *sock;
+       struct tdgram_context *sock;
 
        /*
         * Are we in connected mode, which means
@@ -120,8 +120,6 @@ struct cldap_search_state {
 
 static int cldap_socket_destructor(struct cldap_socket *c)
 {
-       tsocket_disconnect(c->sock);
-
        while (c->searches.list) {
                struct cldap_search_state *s = c->searches.list;
                DLIST_REMOVE(c->searches.list, s);
@@ -146,7 +144,7 @@ static bool cldap_recvfrom_setup(struct cldap_socket *c)
                return true;
        }
 
-       c->recv_subreq = tsocket_recvfrom_send(c->sock, c);
+       c->recv_subreq = tdgram_recvfrom_send(c, c->event.ctx, c->sock);
        if (!c->recv_subreq) {
                return false;
        }
@@ -186,11 +184,11 @@ static void cldap_recvfrom_done(struct tevent_req *subreq)
                goto nomem;
        }
 
-       ret = tsocket_recvfrom_recv(subreq,
-                                   &in->recv_errno,
-                                   in,
-                                   &in->buf,
-                                   &in->src);
+       ret = tdgram_recvfrom_recv(subreq,
+                                  &in->recv_errno,
+                                  in,
+                                  &in->buf,
+                                  &in->src);
        talloc_free(subreq);
        subreq = NULL;
        if (ret >= 0) {
@@ -322,7 +320,7 @@ NTSTATUS cldap_socket_init(TALLOC_CTX *mem_ctx,
        c->event.ctx = ev;
 
        if (!local_addr) {
-               ret = tsocket_address_inet_from_strings(c, "ipv4",
+               ret = tsocket_address_inet_from_strings(c, "ip",
                                                        NULL, 0,
                                                        &any);
                if (ret != 0) {
@@ -337,23 +335,15 @@ NTSTATUS cldap_socket_init(TALLOC_CTX *mem_ctx,
                goto nomem;
        }
 
-       ret = tsocket_address_create_socket(local_addr,
-                                           TSOCKET_TYPE_DGRAM,
-                                           c, &c->sock);
+       ret = tdgram_inet_udp_socket(local_addr, remote_addr,
+                                    c, &c->sock);
        if (ret != 0) {
                status = map_nt_error_from_unix(errno);
                goto nterror;
        }
        talloc_free(any);
 
-       tsocket_set_event_context(c->sock, c->event.ctx);
-
        if (remote_addr) {
-               ret = tsocket_connect(c->sock, remote_addr);
-               if (ret != 0) {
-                       status = map_nt_error_from_unix(errno);
-                       goto nterror;
-               }
                c->connected = true;
        }
 
@@ -408,7 +398,7 @@ struct cldap_reply_state {
        DATA_BLOB blob;
 };
 
-static void cldap_reply_state_destroy(struct tevent_req *req);
+static void cldap_reply_state_destroy(struct tevent_req *subreq);
 
 /*
   queue a cldap reply for send
@@ -419,7 +409,7 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
        struct ldap_message *msg;
        DATA_BLOB blob1, blob2;
        NTSTATUS status;
-       struct tevent_req *req;
+       struct tevent_req *subreq;
 
        if (cldap->connected) {
                return NT_STATUS_PIPE_CONNECTED;
@@ -476,17 +466,18 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
        data_blob_free(&blob1);
        data_blob_free(&blob2);
 
-       req = tsocket_sendto_queue_send(state,
-                                       cldap->sock,
-                                       cldap->send_queue,
-                                       state->blob.data,
-                                       state->blob.length,
-                                       state->dest);
-       if (!req) {
+       subreq = tdgram_sendto_queue_send(state,
+                                         cldap->event.ctx,
+                                         cldap->sock,
+                                         cldap->send_queue,
+                                         state->blob.data,
+                                         state->blob.length,
+                                         state->dest);
+       if (!subreq) {
                goto nomem;
        }
        /* the callback will just free the state, as we don't need a result */
-       tevent_req_set_callback(req, cldap_reply_state_destroy, state);
+       tevent_req_set_callback(subreq, cldap_reply_state_destroy, state);
 
        return NT_STATUS_OK;
 
@@ -497,19 +488,23 @@ failed:
        return status;
 }
 
-static void cldap_reply_state_destroy(struct tevent_req *req)
+static void cldap_reply_state_destroy(struct tevent_req *subreq)
 {
-       struct cldap_reply_state *state = tevent_req_callback_data(req,
+       struct cldap_reply_state *state = tevent_req_callback_data(subreq,
                                          struct cldap_reply_state);
 
        /* we don't want to know the result here, we just free the state */
-       talloc_free(req);
+       talloc_free(subreq);
        talloc_free(state);
 }
 
 static int cldap_search_state_destructor(struct cldap_search_state *s)
 {
        if (s->caller.cldap) {
+               if (s->message_id != -1) {
+                       idr_remove(s->caller.cldap->searches.idr, s->message_id);
+                       s->message_id = -1;
+               }
                DLIST_REMOVE(s->caller.cldap->searches.list, s);
                cldap_recvfrom_stop(s->caller.cldap);
                ZERO_STRUCT(s->caller);
@@ -542,8 +537,12 @@ struct tevent_req *cldap_search_send(TALLOC_CTX *mem_ctx,
        if (!req) {
                return NULL;
        }
+       ZERO_STRUCTP(state);
        state->req = req;
        state->caller.cldap = cldap;
+       state->message_id = -1;
+
+       talloc_set_destructor(state, cldap_search_state_destructor);
 
        if (io->in.dest_address) {
                if (cldap->connected) {
@@ -551,7 +550,7 @@ struct tevent_req *cldap_search_send(TALLOC_CTX *mem_ctx,
                        goto post;
                }
                ret = tsocket_address_inet_from_strings(state,
-                                                       "ipv4",
+                                                       "ip",
                                                        io->in.dest_address,
                                                        io->in.dest_port,
                                                        &state->request.dest);
@@ -622,19 +621,19 @@ struct tevent_req *cldap_search_send(TALLOC_CTX *mem_ctx,
                goto post;
        }
 
-       subreq = tsocket_sendto_queue_send(state,
-                                          state->caller.cldap->sock,
-                                          state->caller.cldap->send_queue,
-                                          state->request.blob.data,
-                                          state->request.blob.length,
-                                          state->request.dest);
+       subreq = tdgram_sendto_queue_send(state,
+                                         state->caller.cldap->event.ctx,
+                                         state->caller.cldap->sock,
+                                         state->caller.cldap->send_queue,
+                                         state->request.blob.data,
+                                         state->request.blob.length,
+                                         state->request.dest);
        if (tevent_req_nomem(subreq, req)) {
                goto post;
        }
        tevent_req_set_callback(subreq, cldap_search_state_queue_done, req);
 
        DLIST_ADD_END(cldap->searches.list, state, struct cldap_search_state *);
-       talloc_set_destructor(state, cldap_search_state_destructor);
 
        return req;
 
@@ -652,7 +651,7 @@ static void cldap_search_state_queue_done(struct tevent_req *subreq)
        int sys_errno = 0;
        struct timeval next;
 
-       ret = tsocket_sendto_queue_recv(subreq, &sys_errno);
+       ret = tdgram_sendto_queue_recv(subreq, &sys_errno);
        talloc_free(subreq);
        if (ret == -1) {
                NTSTATUS status;
@@ -701,12 +700,13 @@ static void cldap_search_state_wakeup_done(struct tevent_req *subreq)
                return;
        }
 
-       subreq = tsocket_sendto_queue_send(state,
-                                          state->caller.cldap->sock,
-                                          state->caller.cldap->send_queue,
-                                          state->request.blob.data,
-                                          state->request.blob.length,
-                                          state->request.dest);
+       subreq = tdgram_sendto_queue_send(state,
+                                         state->caller.cldap->event.ctx,
+                                         state->caller.cldap->sock,
+                                         state->caller.cldap->send_queue,
+                                         state->request.blob.data,
+                                         state->request.blob.length,
+                                         state->request.dest);
        if (tevent_req_nomem(subreq, req)) {
                return;
        }
@@ -946,7 +946,6 @@ static void cldap_netlogon_state_done(struct tevent_req *subreq)
   receive a cldap netlogon reply
 */
 NTSTATUS cldap_netlogon_recv(struct tevent_req *req,
-                            struct smb_iconv_convenience *iconv_convenience,
                             TALLOC_CTX *mem_ctx,
                             struct cldap_netlogon *io)
 {
@@ -974,7 +973,6 @@ NTSTATUS cldap_netlogon_recv(struct tevent_req *req,
        data = state->search.out.response->attributes[0].values;
 
        status = pull_netlogon_samlogon_response(data, mem_ctx,
-                                                iconv_convenience,
                                                 &io->out.netlogon);
        if (!NT_STATUS_IS_OK(status)) {
                goto failed;
@@ -994,7 +992,6 @@ failed:
   sync cldap netlogon search
 */
 NTSTATUS cldap_netlogon(struct cldap_socket *cldap,
-                       struct smb_iconv_convenience *iconv_convenience,
                        TALLOC_CTX *mem_ctx,
                        struct cldap_netlogon *io)
 {
@@ -1017,7 +1014,7 @@ NTSTATUS cldap_netlogon(struct cldap_socket *cldap,
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       status = cldap_netlogon_recv(req, iconv_convenience, mem_ctx, io);
+       status = cldap_netlogon_recv(req, mem_ctx, io);
        talloc_free(req);
 
        return status;
@@ -1081,7 +1078,6 @@ NTSTATUS cldap_error_reply(struct cldap_socket *cldap,
   send a netlogon reply 
 */
 NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
-                             struct smb_iconv_convenience *iconv_convenience,
                              uint32_t message_id,
                              struct tsocket_address *dest,
                              uint32_t version,
@@ -1095,7 +1091,6 @@ NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
        DATA_BLOB blob;
 
        status = push_netlogon_samlogon_response(&blob, tmp_ctx,
-                                                iconv_convenience,
                                                 netlogon);
        if (!NT_STATUS_IS_OK(status)) {
                talloc_free(tmp_ctx);