Merge branch 'master' of ssh://git.samba.org/data/git/samba
authorJelmer Vernooij <jelmer@samba.org>
Sun, 18 Jan 2009 16:27:41 +0000 (17:27 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 18 Jan 2009 16:27:41 +0000 (17:27 +0100)
source3/include/async_req.h
source3/lib/async_req.c
source3/lib/async_sock.c
source3/lib/util_sock.c
source3/lib/wb_reqtrans.c
source3/lib/wbclient.c
source3/libsmb/clireadwrite.c
source3/rpc_client/cli_pipe.c

index 1b8dbf33468b0567a23651de2841c161df52e081..3907a08f67cffacab42f6c7324834a925c8c1f30 100644 (file)
@@ -150,4 +150,11 @@ bool async_req_enqueue(struct async_req_queue *queue,
                       struct async_req *req,
                       void (*trigger)(struct async_req *req));
 
+bool _async_req_setup(TALLOC_CTX *mem_ctx, struct async_req **preq,
+                     void *pstate, size_t state_size, const char *typename);
+
+#define async_req_setup(_mem_ctx, _preq, _pstate, type) \
+       _async_req_setup((_mem_ctx), (_preq), (_pstate), sizeof(type), #type)
+
+
 #endif
index 13b64ba79aa0b071247eaeb34108d7fc70607527..011948a158cc4e20333573b742c16696ae02a08b 100644 (file)
@@ -313,3 +313,28 @@ bool async_req_enqueue(struct async_req_queue *queue, struct event_context *ev,
 
        return true;
 }
+
+bool _async_req_setup(TALLOC_CTX *mem_ctx, struct async_req **preq,
+                     void *pstate, size_t state_size, const char *typename)
+{
+       struct async_req *req;
+       void **ppstate = (void **)pstate;
+       void *state;
+
+       req = async_req_new(mem_ctx);
+       if (req == NULL) {
+               return false;
+       }
+       state = talloc_size(req, state_size);
+       if (state == NULL) {
+               TALLOC_FREE(req);
+               return false;
+       }
+       talloc_set_name(state, typename);
+       req->private_data = state;
+
+       *preq = req;
+       *ppstate = state;
+
+       return true;
+}
index bb89a1353ae4b21e8b3ccacd88c93c0e93689eda..73ff6f28709b89a8fa50f2f00815b5b07c655495 100644 (file)
@@ -106,17 +106,10 @@ static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx,
        struct async_req *result;
        struct async_syscall_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
-               return NULL;
-       }
-
-       state = talloc(result, struct async_syscall_state);
-       if (state == NULL) {
-               TALLOC_FREE(result);
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct async_syscall_state)) {
                return NULL;
        }
-
        state->syscall_type = type;
 
        result->private_data = state;
@@ -569,15 +562,10 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
        struct fd_event *fde;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct async_connect_state)) {
                return NULL;
        }
-       state = talloc(result, struct async_connect_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
 
        /**
         * We have to set the socket to nonblocking for async connect(2). Keep
index 98c25c1e24f7c3cec9547bab8fccdce12308745a..3ddc4342a74eb8658fae57f60dcdf3dca65b46ac 100644 (file)
@@ -978,16 +978,10 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
        struct open_socket_out_state *state;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct open_socket_out_state)) {
                return NULL;
        }
-       state = talloc(result, struct open_socket_out_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->ss = *pss;
        state->port = port;
@@ -1170,16 +1164,10 @@ struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
        struct open_socket_out_defer_state *state;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct open_socket_out_defer_state)) {
                return NULL;
        }
-       state = talloc(result, struct open_socket_out_defer_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->ss = *pss;
        state->port = port;
index 1f5f181aa1f5f206441e9bab67cd829671a01f92..0e6e5d15c47e6008a2cf9ef17bc74dc3437ec8ed 100644 (file)
@@ -43,17 +43,10 @@ struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx,
        struct async_req *result, *subreq;
        struct req_read_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct req_read_state)) {
                return NULL;
        }
-
-       state = talloc(result, struct req_read_state);
-       if (state == NULL) {
-               goto nomem;
-       }
-       result->private_data = state;
-
        state->fd = fd;
        state->ev = ev;
        state->max_extra_data = max_extra_data;
@@ -205,17 +198,10 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
        struct async_req *result, *subreq;
        struct req_write_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct req_write_state)) {
                return NULL;
        }
-
-       state = talloc(result, struct req_write_state);
-       if (state == NULL) {
-               goto nomem;
-       }
-       result->private_data = state;
-
        state->fd = fd;
        state->ev = ev;
        state->wb_req = wb_req;
@@ -304,17 +290,10 @@ struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx,
        struct async_req *result, *subreq;
        struct resp_read_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct resp_read_state)) {
                return NULL;
        }
-
-       state = talloc(result, struct resp_read_state);
-       if (state == NULL) {
-               goto nomem;
-       }
-       result->private_data = state;
-
        state->fd = fd;
        state->ev = ev;
        state->wb_resp = talloc(state, struct winbindd_response);
@@ -458,17 +437,10 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
        struct async_req *result, *subreq;
        struct resp_write_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct resp_write_state)) {
                return NULL;
        }
-
-       state = talloc(result, struct resp_write_state);
-       if (state == NULL) {
-               goto nomem;
-       }
-       result->private_data = state;
-
        state->fd = fd;
        state->ev = ev;
        state->wb_resp = wb_resp;
index d58c934c0716a79abd5aee6cf2eec79780e9d134..ea0bcb512e936036114edbc72b420015b1f04d1d 100644 (file)
@@ -289,15 +289,10 @@ static struct async_req *wb_int_trans_send(TALLOC_CTX *mem_ctx,
        struct async_req *subreq;
        struct wb_int_trans_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct wb_int_trans_state)) {
                return NULL;
        }
-       state = talloc(result, struct wb_int_trans_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
 
        if (winbind_closed_fd(fd)) {
                if (!async_post_status(result, ev,
@@ -420,16 +415,10 @@ static struct async_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx,
        struct async_req *subreq;
        struct wb_open_pipe_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct wb_open_pipe_state)) {
                return NULL;
        }
-       state = talloc(result, struct wb_open_pipe_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->wb_ctx = wb_ctx;
        state->ev = ev;
        state->need_priv = need_priv;
@@ -617,16 +606,10 @@ struct async_req *wb_trans_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        struct async_req *result;
        struct wb_trans_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct wb_trans_state)) {
                return NULL;
        }
-       state = talloc(result, struct wb_trans_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->wb_ctx = wb_ctx;
        state->ev = ev;
        state->wb_req = winbindd_request_copy(state, wb_req);
index 1d5582e61d0e9810be779d5a24dc569a0d4467f4..1ba93d827d1a3368c7cde6b70fec137dd983c4df 100644 (file)
@@ -278,15 +278,10 @@ struct async_req *cli_pull_send(TALLOC_CTX *mem_ctx,
        struct cli_pull_state *state;
        int i;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
-               goto failed;
-       }
-       state = talloc(result, struct cli_pull_state);
-       if (state == NULL) {
-               goto failed;
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct cli_pull_state)) {
+               return NULL;
        }
-       result->private_data = state;
        result->print = cli_pull_print;
        state->req = result;
 
@@ -843,16 +838,10 @@ static struct async_req *cli_writeall_send(TALLOC_CTX *mem_ctx,
        struct async_req *subreq;
        struct cli_writeall_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
-               goto fail;
-       }
-       state = talloc(result, struct cli_writeall_state);
-       if (state == NULL) {
-               goto fail;
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct cli_writeall_state)) {
+               return NULL;
        }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->fnum = fnum;
@@ -969,15 +958,10 @@ struct async_req *cli_push_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        struct cli_push_state *state;
        int i;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
-               goto failed;
-       }
-       state = talloc(result, struct cli_push_state);
-       if (state == NULL) {
-               goto failed;
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct cli_push_state)) {
+               return NULL;
        }
-       result->private_data = state;
        state->req = result;
 
        state->cli = cli;
index f3affd1cd894f63909176e33bdc833f31c791a45..cf621343e741a02d95de22641c80028e46ded294 100644 (file)
@@ -222,16 +222,10 @@ static struct async_req *rpc_read_send(TALLOC_CTX *mem_ctx,
        struct async_req *result, *subreq;
        struct rpc_read_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct rpc_read_state)) {
                return NULL;
        }
-       state = talloc(result, struct rpc_read_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->data = data;
@@ -361,16 +355,10 @@ static struct async_req *rpc_write_send(TALLOC_CTX *mem_ctx,
        struct async_req *result, *subreq;
        struct rpc_write_state *state;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct rpc_write_state)) {
                return NULL;
        }
-       state = talloc(result, struct rpc_write_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->data = data;
@@ -523,16 +511,10 @@ static struct async_req *get_complete_frag_send(TALLOC_CTX *mem_ctx,
        uint32_t pdu_len;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct get_complete_frag_state)) {
                return NULL;
        }
-       state = talloc(result, struct get_complete_frag_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->prhdr = prhdr;
@@ -586,7 +568,6 @@ static struct async_req *get_complete_frag_send(TALLOC_CTX *mem_ctx,
        if (async_post_status(result, ev, status)) {
                return result;
        }
- fail:
        TALLOC_FREE(result);
        return NULL;
 }
@@ -1165,16 +1146,10 @@ static struct async_req *cli_api_pipe_send(TALLOC_CTX *mem_ctx,
        struct cli_api_pipe_state *state;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct cli_api_pipe_state)) {
                return NULL;
        }
-       state = talloc(result, struct cli_api_pipe_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->max_rdata_len = max_rdata_len;
@@ -1227,7 +1202,6 @@ static struct async_req *cli_api_pipe_send(TALLOC_CTX *mem_ctx,
        if (async_post_status(result, ev, status)) {
                return result;
        }
- fail:
        TALLOC_FREE(result);
        return NULL;
 }
@@ -1370,16 +1344,10 @@ static struct async_req *rpc_api_pipe_send(TALLOC_CTX *mem_ctx,
        uint16_t max_recv_frag;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct rpc_api_pipe_state)) {
                return NULL;
        }
-       state = talloc(result, struct rpc_api_pipe_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->expected_pkt_type = expected_pkt_type;
@@ -1423,7 +1391,6 @@ static struct async_req *rpc_api_pipe_send(TALLOC_CTX *mem_ctx,
        if (async_post_status(result, ev, status)) {
                return result;
        }
- fail:
        TALLOC_FREE(result);
        return NULL;
 }
@@ -2184,16 +2151,10 @@ struct async_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        bool is_last_frag;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct rpc_api_pipe_req_state)) {
                return NULL;
        }
-       state = talloc(result, struct rpc_api_pipe_req_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
-
        state->ev = ev;
        state->cli = cli;
        state->op_num = op_num;
@@ -2250,7 +2211,6 @@ struct async_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
        if (async_post_status(result, ev, status)) {
                return result;
        }
- fail:
        TALLOC_FREE(result);
        return NULL;
 }
@@ -2667,15 +2627,10 @@ struct async_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
        struct rpc_pipe_bind_state *state;
        NTSTATUS status;
 
-       result = async_req_new(mem_ctx);
-       if (result == NULL) {
+       if (!async_req_setup(mem_ctx, &result, &state,
+                            struct rpc_pipe_bind_state)) {
                return NULL;
        }
-       state = talloc(result, struct rpc_pipe_bind_state);
-       if (state == NULL) {
-               goto fail;
-       }
-       result->private_data = state;
 
        DEBUG(5,("Bind RPC Pipe: %s auth_type %u, auth_level %u\n",
                rpccli_pipe_txt(debug_ctx(), cli),
@@ -2717,7 +2672,6 @@ struct async_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
        if (async_post_status(result, ev, status)) {
                return result;
        }
- fail:
        TALLOC_FREE(result);
        return NULL;
 }