fixed several places that unnecessarily take a reference to the event context
[kai/samba-autobuild/.git] / source4 / libcli / dgram / dgramsocket.c
index e7eb01b7e9cca977a21bdc92e51cb0256d3eddc8..365960edb6d084bf7bfb22d6172447776ecffdd3 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "lib/events/events.h"
-#include "dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "libcli/dgram/libdgram.h"
 #include "lib/socket/socket.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
@@ -40,6 +39,7 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock)
        size_t nread, dsize;
        struct nbt_dgram_packet *packet;
        const char *mailslot_name;
+       enum ndr_err_code ndr_err;
 
        status = socket_pending(dgmsock->sock, &dsize);
        if (!NT_STATUS_IS_OK(status)) {
@@ -71,9 +71,10 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock)
        }
 
        /* parse the request */
-       status = ndr_pull_struct_blob(&blob, packet, packet, 
+       ndr_err = ndr_pull_struct_blob(&blob, packet, dgmsock->iconv_convenience, packet,
                                      (ndr_pull_flags_fn_t)ndr_pull_nbt_dgram_packet);
-       if (!NT_STATUS_IS_OK(status)) {
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               status = ndr_map_error2ntstatus(ndr_err);
                DEBUG(2,("Failed to parse incoming NBT DGRAM packet - %s\n",
                         nt_errstr(status)));
                talloc_free(tmp_ctx);
@@ -138,10 +139,10 @@ static void dgm_socket_send(struct nbt_dgram_socket *dgmsock)
 /*
   handle fd events on a nbt_dgram_socket
 */
-static void dgm_socket_handler(struct event_context *ev, struct fd_event *fde,
-                              uint16_t flags, void *private)
+static void dgm_socket_handler(struct tevent_context *ev, struct tevent_fd *fde,
+                              uint16_t flags, void *private_data)
 {
-       struct nbt_dgram_socket *dgmsock = talloc_get_type(private
+       struct nbt_dgram_socket *dgmsock = talloc_get_type(private_data,
                                                           struct nbt_dgram_socket);
        if (flags & EVENT_FD_WRITE) {
                dgm_socket_send(dgmsock);
@@ -156,7 +157,8 @@ static void dgm_socket_handler(struct event_context *ev, struct fd_event *fde,
   then operations will use that event context
 */
 struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx, 
-                                             struct event_context *event_ctx)
+                                             struct tevent_context *event_ctx,
+                                             struct smb_iconv_convenience *iconv_convenience)
 {
        struct nbt_dgram_socket *dgmsock;
        NTSTATUS status;
@@ -164,11 +166,7 @@ struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
        dgmsock = talloc(mem_ctx, struct nbt_dgram_socket);
        if (dgmsock == NULL) goto failed;
 
-       if (event_ctx == NULL) {
-               dgmsock->event_ctx = event_context_init(dgmsock);
-       } else {
-               dgmsock->event_ctx = talloc_reference(dgmsock, event_ctx);
-       }
+       dgmsock->event_ctx = event_ctx;
        if (dgmsock->event_ctx == NULL) goto failed;
 
        status = socket_create("ip", SOCKET_TYPE_DGRAM, &dgmsock->sock, 0);
@@ -185,6 +183,7 @@ struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
        dgmsock->send_queue = NULL;
        dgmsock->incoming.handler = NULL;
        dgmsock->mailslot_handlers = NULL;
+       dgmsock->iconv_convenience = iconv_convenience;
        
        return dgmsock;
 
@@ -201,10 +200,10 @@ NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
                                    void (*handler)(struct nbt_dgram_socket *, 
                                                    struct nbt_dgram_packet *, 
                                                    struct socket_address *),
-                                   void *private)
+                                   void *private_data)
 {
        dgmsock->incoming.handler = handler;
-       dgmsock->incoming.private = private;
+       dgmsock->incoming.private_data = private_data;
        EVENT_FD_READABLE(dgmsock->fde);
        return NT_STATUS_OK;
 }
@@ -219,6 +218,7 @@ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
 {
        struct nbt_dgram_request *req;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
+       enum ndr_err_code ndr_err;
 
        req = talloc(dgmsock, struct nbt_dgram_request);
        if (req == NULL) goto failed;
@@ -226,9 +226,12 @@ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
        req->dest = dest;
        if (talloc_reference(req, dest) == NULL) goto failed;
 
-       status = ndr_push_struct_blob(&req->encoded, req, packet, 
+       ndr_err = ndr_push_struct_blob(&req->encoded, req, dgmsock->iconv_convenience, packet,
                                      (ndr_push_flags_fn_t)ndr_push_nbt_dgram_packet);
-       if (!NT_STATUS_IS_OK(status)) goto failed;
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               status = ndr_map_error2ntstatus(ndr_err);
+               goto failed;
+       }
 
        DLIST_ADD_END(dgmsock->send_queue, req, struct nbt_dgram_request *);