libcli/nbt: s/private/private_data
[kai/samba-autobuild/.git] / libcli / nbt / nbtsocket.c
index 68c5d89db673a0aba20c34b48ea619f5692d57ea..a3e295d3df0489bdf63a233e759b9a76ef786753 100644 (file)
@@ -115,9 +115,9 @@ failed:
   handle a request timeout
 */
 static void nbt_name_socket_timeout(struct tevent_context *ev, struct tevent_timer *te,
-                                   struct timeval t, void *private)
+                                   struct timeval t, void *private_data)
 {
-       struct nbt_name_request *req = talloc_get_type(private,
+       struct nbt_name_request *req = talloc_get_type(private_data,
                                                       struct nbt_name_request);
 
        if (req->num_retries != 0) {
@@ -231,6 +231,16 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
                return;
        }
 
+       talloc_steal(req, packet);
+       talloc_steal(req, src);
+       talloc_free(tmp_ctx);
+       nbt_name_socket_handle_response_packet(req, packet, src);
+}
+
+void nbt_name_socket_handle_response_packet(struct nbt_name_request *req,
+                                           struct nbt_name_packet *packet,
+                                           struct socket_address *src)
+{
        /* if this is a WACK response, this we need to go back to waiting,
           but perhaps increase the timeout */
        if ((packet->operation & NBT_OPCODE) == NBT_OPCODE_WACK) {
@@ -266,7 +276,6 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
                req->te = event_add_timed(req->nbtsock->event_ctx, req,
                                          timeval_current_ofs(req->timeout, 0),
                                          nbt_name_socket_timeout, req);
-               talloc_free(tmp_ctx);
                return;
        }
 
@@ -288,7 +297,6 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
        /* if we don't want multiple replies then we are done */
        if (req->allow_multiple_replies &&
            req->num_replies < NBT_MAX_REPLIES) {
-               talloc_free(tmp_ctx);
                return;
        }
 
@@ -297,7 +305,6 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
        req->status = NT_STATUS_OK;
 
 done:
-       talloc_free(tmp_ctx);
        if (req->async.fn) {
                req->async.fn(req);
        }
@@ -307,9 +314,9 @@ done:
   handle fd events on a nbt_name_socket
 */
 static void nbt_name_socket_handler(struct tevent_context *ev, struct tevent_fd *fde,
-                                   uint16_t flags, void *private)
+                                   uint16_t flags, void *private_data)
 {
-       struct nbt_name_socket *nbtsock = talloc_get_type(private,
+       struct nbt_name_socket *nbtsock = talloc_get_type(private_data,
                                                          struct nbt_name_socket);
        if (flags & EVENT_FD_WRITE) {
                nbt_name_socket_send(nbtsock);
@@ -501,14 +508,27 @@ NTSTATUS nbt_name_request_recv(struct nbt_name_request *req)
 _PUBLIC_ NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
                                  void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
                                                  struct socket_address *),
-                                 void *private)
+                                 void *private_data)
 {
        nbtsock->incoming.handler = handler;
-       nbtsock->incoming.private_data = private;
+       nbtsock->incoming.private_data = private_data;
        EVENT_FD_READABLE(nbtsock->fde);
        return NT_STATUS_OK;
 }
 
+/*
+  setup a handler for unexpected requests
+*/
+NTSTATUS nbt_set_unexpected_handler(struct nbt_name_socket *nbtsock,
+                                   void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
+                                                   struct socket_address *),
+                                   void *private_data)
+{
+       nbtsock->unexpected.handler = handler;
+       nbtsock->unexpected.private_data = private_data;
+       EVENT_FD_READABLE(nbtsock->fde);
+       return NT_STATUS_OK;
+}
 
 /*
   turn a NBT rcode into a NTSTATUS