libcli/nbt: add nbt_name_socket_handle_response_packet()
authorStefan Metzmacher <metze@sernet.de>
Wed, 16 Jan 2008 13:51:56 +0000 (14:51 +0100)
committerStefan Metzmacher <metze@sernet.de>
Wed, 16 Jan 2008 13:52:44 +0000 (14:52 +0100)
Move the last part of nbt_name_socket_recv() into
a new function nbt_name_socket_handle_response_packet()
so that it can be reused by an unexpected handler.

metze

source/libcli/nbt/nbtsocket.c

index f8adf4ed8cf200470cb9297324df3b6e5976ab96..02b94ed90de7a87ddcd524c7e997f498ea8c2350 100644 (file)
@@ -223,6 +223,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) {
@@ -258,10 +268,8 @@ 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;
        }
-       
 
        req->replies = talloc_realloc(req, req->replies, struct nbt_name_reply, req->num_replies+1);
        if (req->replies == NULL) {
@@ -280,7 +288,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;
        }
 
@@ -289,7 +296,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);
        }