summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2010-10-11 21:18:15 +0200
committerStefan Metzmacher <metze@samba.org>2010-10-18 15:36:16 +0000
commit820ae3d9a36e031027be163d22eec468a6da8603 (patch)
tree412a63a9ba3944f8be305271cc2b06f16cf0da3e
parent0b8056d580e2d2475b208c73ffb698b0bcd487eb (diff)
downloadsamba-820ae3d9a36e031027be163d22eec468a6da8603.tar.gz
samba-820ae3d9a36e031027be163d22eec468a6da8603.tar.bz2
samba-820ae3d9a36e031027be163d22eec468a6da8603.zip
libcli/nbt: convert nbt_name_register_bcast_send/recv to tevent_req
metze
-rw-r--r--libcli/nbt/libnbt.h10
-rw-r--r--libcli/nbt/nameregister.c184
-rw-r--r--source4/nbt_server/register.c13
3 files changed, 114 insertions, 93 deletions
diff --git a/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h
index dfc3b92f96..21fd8597fe 100644
--- a/libcli/nbt/libnbt.h
+++ b/libcli/nbt/libnbt.h
@@ -339,13 +339,13 @@ NDR_SCALAR_PROTO(nbt_string, const char *)
NDR_BUFFER_PROTO(nbt_name, struct nbt_name)
NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode);
-struct composite_context;
-struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *nbtsock,
- struct nbt_name_register_bcast *io);
-NTSTATUS nbt_name_register_bcast_recv(struct composite_context *c);
-
struct tevent_context;
struct tevent_req;
+struct tevent_req *nbt_name_register_bcast_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct nbt_name_socket *nbtsock,
+ struct nbt_name_register_bcast *io);
+NTSTATUS nbt_name_register_bcast_recv(struct tevent_req *req);
struct tevent_req *nbt_name_register_wins_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct nbt_name_socket *nbtsock,
diff --git a/libcli/nbt/nameregister.c b/libcli/nbt/nameregister.c
index d0a652d751..204fb6f328 100644
--- a/libcli/nbt/nameregister.c
+++ b/libcli/nbt/nameregister.c
@@ -23,7 +23,6 @@
#include <tevent.h>
#include "../libcli/nbt/libnbt.h"
#include "../libcli/nbt/nbt_proto.h"
-#include "libcli/composite/composite.h"
#include "lib/socket/socket.h"
#include "librpc/gen_ndr/ndr_nbt.h"
#include "../lib/util/tevent_ntstatus.h"
@@ -152,120 +151,113 @@ _PUBLIC_ NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock,
*/
struct nbt_name_register_bcast_state {
struct nbt_name_socket *nbtsock;
- struct nbt_name_register *io;
- struct nbt_name_request *req;
+ struct nbt_name_register io;
};
-static void nbt_name_register_bcast_handler(struct nbt_name_request *req);
+static void nbt_name_register_bcast_handler(struct nbt_name_request *subreq);
/*
the async send call for a 4 stage name registration
*/
-_PUBLIC_ struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *nbtsock,
- struct nbt_name_register_bcast *io)
+_PUBLIC_ struct tevent_req *nbt_name_register_bcast_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct nbt_name_socket *nbtsock,
+ struct nbt_name_register_bcast *io)
{
- struct composite_context *c;
+ struct tevent_req *req;
struct nbt_name_register_bcast_state *state;
+ struct nbt_name_request *subreq;
- c = talloc_zero(nbtsock, struct composite_context);
- if (c == NULL) goto failed;
-
- state = talloc(c, struct nbt_name_register_bcast_state);
- if (state == NULL) goto failed;
-
- state->io = talloc(state, struct nbt_name_register);
- if (state->io == NULL) goto failed;
+ req = tevent_req_create(mem_ctx, &state,
+ struct nbt_name_register_bcast_state);
+ if (req == NULL) {
+ return NULL;
+ }
- state->io->in.name = io->in.name;
- state->io->in.dest_addr = io->in.dest_addr;
- state->io->in.dest_port = io->in.dest_port;
- state->io->in.address = io->in.address;
- state->io->in.nb_flags = io->in.nb_flags;
- state->io->in.register_demand = false;
- state->io->in.broadcast = true;
- state->io->in.multi_homed = false;
- state->io->in.ttl = io->in.ttl;
- state->io->in.timeout = 1;
- state->io->in.retries = 2;
+ state->io.in.name = io->in.name;
+ state->io.in.dest_addr = io->in.dest_addr;
+ state->io.in.dest_port = io->in.dest_port;
+ state->io.in.address = io->in.address;
+ state->io.in.nb_flags = io->in.nb_flags;
+ state->io.in.register_demand = false;
+ state->io.in.broadcast = true;
+ state->io.in.multi_homed = false;
+ state->io.in.ttl = io->in.ttl;
+ state->io.in.timeout = 1;
+ state->io.in.retries = 2;
state->nbtsock = nbtsock;
- state->req = nbt_name_register_send(nbtsock, state->io);
- if (state->req == NULL) goto failed;
-
- state->req->async.fn = nbt_name_register_bcast_handler;
- state->req->async.private_data = c;
-
- c->private_data = state;
- c->state = COMPOSITE_STATE_IN_PROGRESS;
- c->event_ctx = nbtsock->event_ctx;
+ subreq = nbt_name_register_send(nbtsock, &state->io);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
- return c;
+ subreq->async.fn = nbt_name_register_bcast_handler;
+ subreq->async.private_data = req;
-failed:
- talloc_free(c);
- return NULL;
+ return req;
}
-
-/*
- state handler for 4 stage name registration
-*/
-static void nbt_name_register_bcast_handler(struct nbt_name_request *req)
+static void nbt_name_register_bcast_handler(struct nbt_name_request *subreq)
{
- struct composite_context *c = talloc_get_type(req->async.private_data, struct composite_context);
- struct nbt_name_register_bcast_state *state = talloc_get_type(c->private_data, struct nbt_name_register_bcast_state);
+ struct tevent_req *req =
+ talloc_get_type_abort(subreq->async.private_data,
+ struct tevent_req);
+ struct nbt_name_register_bcast_state *state =
+ tevent_req_data(req,
+ struct nbt_name_register_bcast_state);
NTSTATUS status;
- status = nbt_name_register_recv(state->req, state, state->io);
+ status = nbt_name_register_recv(subreq, state, &state->io);
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
- if (state->io->in.register_demand == true) {
- /* all done */
- c->state = COMPOSITE_STATE_DONE;
- c->status = NT_STATUS_OK;
- goto done;
+ if (state->io.in.register_demand == true) {
+ tevent_req_done(req);
+ return;
}
/* the registration timed out - good, send the demand */
- state->io->in.register_demand = true;
- state->io->in.retries = 0;
- state->req = nbt_name_register_send(state->nbtsock, state->io);
- if (state->req == NULL) {
- c->state = COMPOSITE_STATE_ERROR;
- c->status = NT_STATUS_NO_MEMORY;
- } else {
- state->req->async.fn = nbt_name_register_bcast_handler;
- state->req->async.private_data = c;
+ state->io.in.register_demand = true;
+ state->io.in.retries = 0;
+
+ subreq = nbt_name_register_send(state->nbtsock, &state->io);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
}
- } else if (!NT_STATUS_IS_OK(status)) {
- c->state = COMPOSITE_STATE_ERROR;
- c->status = status;
- } else {
- c->state = COMPOSITE_STATE_ERROR;
- c->status = NT_STATUS_CONFLICTING_ADDRESSES;
- DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n",
- state->io->out.reply_from,
- nbt_name_string(state, &state->io->out.name),
- state->io->out.reply_addr,
- state->io->out.rcode));
+
+ subreq->async.fn = nbt_name_register_bcast_handler;
+ subreq->async.private_data = req;
+ return;
}
-done:
- if (c->state >= COMPOSITE_STATE_DONE &&
- c->async.fn) {
- c->async.fn(c);
+ if (!NT_STATUS_IS_OK(status)) {
+ tevent_req_nterror(req, status);
+ return;
}
+
+ DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n",
+ state->io.out.reply_from,
+ nbt_name_string(state, &state->io.out.name),
+ state->io.out.reply_addr,
+ state->io.out.rcode));
+
+ tevent_req_nterror(req, NT_STATUS_CONFLICTING_ADDRESSES);
}
/*
broadcast 4 part name register - recv
*/
-_PUBLIC_ NTSTATUS nbt_name_register_bcast_recv(struct composite_context *c)
+_PUBLIC_ NTSTATUS nbt_name_register_bcast_recv(struct tevent_req *req)
{
NTSTATUS status;
- status = composite_wait(c);
- talloc_free(c);
- return status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ tevent_req_received(req);
+ return status;
+ }
+
+ tevent_req_received(req);
+ return NT_STATUS_OK;
}
/*
@@ -274,8 +266,36 @@ _PUBLIC_ NTSTATUS nbt_name_register_bcast_recv(struct composite_context *c)
NTSTATUS nbt_name_register_bcast(struct nbt_name_socket *nbtsock,
struct nbt_name_register_bcast *io)
{
- struct composite_context *c = nbt_name_register_bcast_send(nbtsock, io);
- return nbt_name_register_bcast_recv(c);
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct tevent_context *ev;
+ struct tevent_req *subreq;
+ NTSTATUS status;
+
+ /*
+ * TODO: create a temporary event context
+ */
+ ev = nbtsock->event_ctx;
+
+ subreq = nbt_name_register_bcast_send(frame, ev, nbtsock, io);
+ if (subreq == NULL) {
+ talloc_free(frame);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (!tevent_req_poll(subreq, ev)) {
+ status = map_nt_error_from_unix(errno);
+ talloc_free(frame);
+ return status;
+ }
+
+ status = nbt_name_register_bcast_recv(subreq);
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(frame);
+ return status;
+ }
+
+ TALLOC_FREE(frame);
+ return NT_STATUS_OK;
}
diff --git a/source4/nbt_server/register.c b/source4/nbt_server/register.c
index 48a6319f6e..b166d46b7f 100644
--- a/source4/nbt_server/register.c
+++ b/source4/nbt_server/register.c
@@ -136,15 +136,16 @@ struct nbtd_register_name_state {
/*
a name registration has completed
*/
-static void nbtd_register_name_handler(struct composite_context *subreq)
+static void nbtd_register_name_handler(struct tevent_req *subreq)
{
struct nbtd_register_name_state *state =
- talloc_get_type_abort(subreq->async.private_data,
+ tevent_req_callback_data(subreq,
struct nbtd_register_name_state);
struct nbtd_iface_name *iname = state->iname;
NTSTATUS status;
status = nbt_name_register_bcast_recv(subreq);
+ TALLOC_FREE(subreq);
if (NT_STATUS_IS_OK(status)) {
/* good - nobody complained about our registration */
iname->nb_flags |= NBT_NM_ACTIVE;
@@ -178,7 +179,7 @@ static void nbtd_register_name_iface(struct nbtd_interface *iface,
struct nbtd_iface_name *iname;
const char *scope = lpcfg_netbios_scope(iface->nbtsrv->task->lp_ctx);
struct nbtd_register_name_state *state;
- struct composite_context *subreq;
+ struct tevent_req *subreq;
struct nbtd_server *nbtsrv = iface->nbtsrv;
iname = talloc(iface, struct nbtd_iface_name);
@@ -230,13 +231,13 @@ static void nbtd_register_name_iface(struct nbtd_interface *iface,
nbtsrv->stats.total_sent++;
- subreq = nbt_name_register_bcast_send(iface->nbtsock, &state->io);
+ subreq = nbt_name_register_bcast_send(state, nbtsrv->task->event_ctx,
+ iface->nbtsock, &state->io);
if (subreq == NULL) {
return;
}
- subreq->async.fn = nbtd_register_name_handler;
- subreq->async.private_data = state;
+ tevent_req_set_callback(subreq, nbtd_register_name_handler, state);
}