s4:misc: remove last usage of legacy event_ fn names
[idra/samba.git] / source4 / nbt_server / wins / winsclient.c
index f6f6ff48ec3447a496bfe674a160460f0307a4e8..b047b2b4118c2efe29ce9189d6203b3f056387aa 100644 (file)
@@ -60,7 +60,7 @@ static void nbtd_wins_start_refresh_timer(struct nbtd_iface_name *iname)
 
        refresh_time = MIN(max_refresh_time, iname->ttl/2);
        
-       event_add_timed(iname->iface->nbtsrv->task->event_ctx, 
+       tevent_add_timer(iname->iface->nbtsrv->task->event_ctx,
                        iname, 
                        timeval_add(&iname->registration_time, refresh_time, 0),
                        nbtd_wins_refresh, iname);
@@ -74,15 +74,16 @@ struct nbtd_wins_refresh_state {
 /*
   called when a wins name refresh has completed
 */
-static void nbtd_wins_refresh_handler(struct composite_context *subreq)
+static void nbtd_wins_refresh_handler(struct tevent_req *subreq)
 {
        NTSTATUS status;
        struct nbtd_wins_refresh_state *state =
-               talloc_get_type_abort(subreq->async.private_data,
+               tevent_req_callback_data(subreq,
                struct nbtd_wins_refresh_state);
        struct nbtd_iface_name *iname = state->iname;
 
        status = nbt_name_refresh_wins_recv(subreq, state, &state->io);
+       TALLOC_FREE(subreq);
        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
                /* our WINS server is dead - start registration over
                   from scratch */
@@ -139,7 +140,7 @@ static void nbtd_wins_refresh(struct tevent_context *ev, struct tevent_timer *te
        struct nbtd_iface_name *iname = talloc_get_type(private_data, struct nbtd_iface_name);
        struct nbtd_interface *iface = iname->iface;
        struct nbt_name_socket *nbtsock = wins_socket(iface);
-       struct composite_context *subreq;
+       struct tevent_req *subreq;
        struct nbtd_wins_refresh_state *state;
 
        state = talloc_zero(iname, struct nbtd_wins_refresh_state);
@@ -162,55 +163,60 @@ static void nbtd_wins_refresh(struct tevent_context *ev, struct tevent_timer *te
                return;
        }
 
-       subreq = nbt_name_refresh_wins_send(nbtsock, &state->io);
+       subreq = nbt_name_refresh_wins_send(state, ev, nbtsock, &state->io);
        if (subreq == NULL) {
                talloc_free(state);
                return;
        }
 
-       subreq->async.fn = nbtd_wins_refresh_handler;
-       subreq->async.private_data = state;
+       tevent_req_set_callback(subreq, nbtd_wins_refresh_handler, state);
 }
 
+struct nbtd_wins_register_state {
+       struct nbtd_iface_name *iname;
+       struct nbt_name_register_wins io;
+};
 
 /*
   called when a wins name register has completed
 */
-static void nbtd_wins_register_handler(struct composite_context *c)
+static void nbtd_wins_register_handler(struct tevent_req *subreq)
 {
        NTSTATUS status;
-       struct nbt_name_register_wins io;
-       struct nbtd_iface_name *iname = talloc_get_type(c->async.private_data, 
-                                                       struct nbtd_iface_name);
-       TALLOC_CTX *tmp_ctx = talloc_new(iname);
+       struct nbtd_wins_register_state *state =
+               tevent_req_callback_data(subreq,
+               struct nbtd_wins_register_state);
+       struct nbtd_iface_name *iname = state->iname;
 
-       status = nbt_name_register_wins_recv(c, tmp_ctx, &io);
+       status = nbt_name_register_wins_recv(subreq, state, &state->io);
+       TALLOC_FREE(subreq);
        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
                /* none of the WINS servers responded - try again 
                   periodically */
                int wins_retry_time = lpcfg_parm_int(iname->iface->nbtsrv->task->lp_ctx, NULL, "nbtd", "wins_retry", 300);
-               event_add_timed(iname->iface->nbtsrv->task->event_ctx, 
+               tevent_add_timer(iname->iface->nbtsrv->task->event_ctx,
                                iname,
                                timeval_current_ofs(wins_retry_time, 0),
                                nbtd_wins_register_retry,
                                iname);
-               talloc_free(tmp_ctx);
+               talloc_free(state);
                return;
        }
 
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1,("Name register failure with WINS for %s - %s\n", 
-                        nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
-               talloc_free(tmp_ctx);
+                        nbt_name_string(state, &iname->name), nt_errstr(status)));
+               talloc_free(state);
                return;
        }       
 
-       if (io.out.rcode != 0) {
+       if (state->io.out.rcode != 0) {
                DEBUG(1,("WINS server %s rejected name register of %s - %s\n", 
-                        io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name), 
-                        nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
+                        state->io.out.wins_server,
+                        nbt_name_string(state, &iname->name),
+                        nt_errstr(nbt_rcode_to_ntstatus(state->io.out.rcode))));
                iname->nb_flags |= NBT_NM_CONFLICT;
-               talloc_free(tmp_ctx);
+               talloc_free(state);
                return;
        }       
 
@@ -221,17 +227,18 @@ static void nbtd_wins_register_handler(struct composite_context *c)
                 * talloc_free() would generate a warning,
                 * so steal it into the tmp context
                 */
-               talloc_steal(tmp_ctx, iname->wins_server);
+               talloc_steal(state, iname->wins_server);
        }
-       iname->wins_server = talloc_steal(iname, io.out.wins_server);
+       iname->wins_server = talloc_move(iname, &state->io.out.wins_server);
 
        iname->registration_time = timeval_current();
-       nbtd_wins_start_refresh_timer(iname);
 
        DEBUG(3,("Registered %s with WINS server %s\n",
-                nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
+                nbt_name_string(state, &iname->name), iname->wins_server));
+
+       talloc_free(state);
 
-       talloc_free(tmp_ctx);
+       nbtd_wins_start_refresh_timer(iname);
 }
 
 /*
@@ -240,28 +247,36 @@ static void nbtd_wins_register_handler(struct composite_context *c)
 void nbtd_winsclient_register(struct nbtd_iface_name *iname)
 {
        struct nbtd_interface *iface = iname->iface;
-       struct nbt_name_register_wins io;
-       struct composite_context *c;
+       struct nbt_name_socket *nbtsock = wins_socket(iface);
+       struct nbtd_wins_register_state *state;
+       struct tevent_req *subreq;
+
+       state = talloc_zero(iname, struct nbtd_wins_register_state);
+       if (state == NULL) {
+               return;
+       }
+
+       state->iname = iname;
 
        /* setup a wins name register request */
-       io.in.name            = iname->name;
-       io.in.wins_port       = lpcfg_nbt_port(iname->iface->nbtsrv->task->lp_ctx);
-       io.in.wins_servers    = lpcfg_wins_server_list(iname->iface->nbtsrv->task->lp_ctx);
-       io.in.addresses       = nbtd_address_list(iface, iname);
-       io.in.nb_flags        = iname->nb_flags;
-       io.in.ttl             = iname->ttl;
-
-       if (!io.in.addresses) {
+       state->io.in.name         = iname->name;
+       state->io.in.wins_port    = lpcfg_nbt_port(iface->nbtsrv->task->lp_ctx);
+       state->io.in.wins_servers = lpcfg_wins_server_list(iface->nbtsrv->task->lp_ctx);
+       state->io.in.addresses    = nbtd_address_list(iface, state);
+       state->io.in.nb_flags     = iname->nb_flags;
+       state->io.in.ttl          = iname->ttl;
+
+       if (state->io.in.addresses == NULL) {
+               talloc_free(state);
                return;
        }
 
-       c = nbt_name_register_wins_send(wins_socket(iface), &io);
-       if (c == NULL) {
-               talloc_free(io.in.addresses);
+       subreq = nbt_name_register_wins_send(state, iface->nbtsrv->task->event_ctx,
+                                            nbtsock, &state->io);
+       if (subreq == NULL) {
+               talloc_free(state);
                return;
        }
-       talloc_steal(c, io.in.addresses);
 
-       c->async.fn = nbtd_wins_register_handler;
-       c->async.private_data = iname;
+       tevent_req_set_callback(subreq, nbtd_wins_register_handler, state);
 }