[SCM] Samba Shared Repository - branch master updated
Stefan Metzmacher
metze at samba.org
Sun Mar 7 08:53:08 MST 2010
The branch, master has been updated
via 8c16d5e... s4:libcli/wrepl: add wrepl_socket_is_connected()
via f1e28a0... s4:libcli/wrepl: make struct wrepl_request private to winsrepl.c
via 2450fc1... s4:libcli/wrepl: implement wrepl_request_send as a tevent_req based wrapper
via cb4f269... s4:libcli/wrepl: rename enum wrepl_request_state => enum wrepl_request_internal_state
via 311a60d... s4:libcli/wrepl: move wrepl_request_send/recv => wrepl_request_internal_send/recv
via fc41e47... s4:torture/nbt: use wrepl_associate_stop() instead of build the request by hand
via 6dfc96c... s4:torture/nbt: use wrepl_request() instead of wrepl_request_send() followed by wrepl_request_recv()
via db051f0... s4:libcli/wrepl: add my copyright
from 6870313... s4:lib/registry/ldb.c - fix trailing whitespaces
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 8c16d5e4dc9312475c7d5dcc07022dbf316500cf
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 16:03:23 2010 +0100
s4:libcli/wrepl: add wrepl_socket_is_connected()
metze
commit f1e28a0b410169d3bfc0a069bf5de50c6cc8a27c
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 15:49:27 2010 +0100
s4:libcli/wrepl: make struct wrepl_request private to winsrepl.c
metze
commit 2450fc1c271b9f944455370510062164e68a8d59
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 15:22:10 2010 +0100
s4:libcli/wrepl: implement wrepl_request_send as a tevent_req based wrapper
metze
commit cb4f2699453b8092be0c0ff42fa0f31582d38da5
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 15:03:29 2010 +0100
s4:libcli/wrepl: rename enum wrepl_request_state => enum wrepl_request_internal_state
metze
commit 311a60df9cdbbe8641e7a69ddc1dadd5a7ac7f05
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 14:44:23 2010 +0100
s4:libcli/wrepl: move wrepl_request_send/recv => wrepl_request_internal_send/recv
metze
commit fc41e4791f3a59cd391d63ebc155407ea4787bae
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 14:34:36 2010 +0100
s4:torture/nbt: use wrepl_associate_stop() instead of build the request by hand
metze
commit 6dfc96c329421979e7367ceee3a65633e4738472
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 14:29:36 2010 +0100
s4:torture/nbt: use wrepl_request() instead of wrepl_request_send() followed by wrepl_request_recv()
metze
commit db051f0db6d45d4293d58c48ae620d8945ba8c65
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Mar 5 14:17:08 2010 +0100
s4:libcli/wrepl: add my copyright
metze
-----------------------------------------------------------------------
Summary of changes:
source4/libcli/wrepl/winsrepl.c | 213 ++++++++++++++++++++++++-----
source4/libcli/wrepl/winsrepl.h | 32 +----
source4/torture/nbt/winsreplication.c | 28 ++--
source4/wrepl_server/wrepl_out_helpers.c | 30 +++--
4 files changed, 211 insertions(+), 92 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source4/libcli/wrepl/winsrepl.c b/source4/libcli/wrepl/winsrepl.c
index 4fd21aa..5a5719f 100644
--- a/source4/libcli/wrepl/winsrepl.c
+++ b/source4/libcli/wrepl/winsrepl.c
@@ -4,6 +4,7 @@
low level WINS replication client code
Copyright (C) Andrew Tridgell 2005
+ Copyright (C) Stefan Metzmacher 2005-2010
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
@@ -32,6 +33,34 @@
#include "param/param.h"
#include "lib/util/tevent_ntstatus.h"
+enum wrepl_request_internal_state {
+ WREPL_REQUEST_INIT = 0,
+ WREPL_REQUEST_RECV = 1,
+ WREPL_REQUEST_DONE = 2,
+ WREPL_REQUEST_ERROR = 3
+};
+
+/*
+ a WINS replication request
+*/
+struct wrepl_request {
+ struct wrepl_request *next, *prev;
+ struct wrepl_socket *wrepl_socket;
+
+ enum wrepl_request_internal_state state;
+ bool trigger;
+ NTSTATUS status;
+
+ struct tevent_timer *te;
+
+ struct wrepl_packet *packet;
+
+ struct {
+ void (*fn)(struct wrepl_request *);
+ void *private_data;
+ } async;
+};
+
static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status);
/*
@@ -72,6 +101,23 @@ static void wrepl_socket_dead(struct wrepl_socket *wrepl_socket, NTSTATUS status
}
}
+bool wrepl_socket_is_connected(struct wrepl_socket *wrepl_sock)
+{
+ if (!wrepl_sock) {
+ return false;
+ }
+
+ if (wrepl_sock->dead) {
+ return false;
+ }
+
+ if (!wrepl_sock->sock) {
+ return false;
+ }
+
+ return true;
+}
+
static void wrepl_request_timeout_handler(struct tevent_context *ev, struct tevent_timer *te,
struct timeval t, void *ptr)
{
@@ -498,9 +544,9 @@ static int wrepl_send_ctrl_destructor(struct wrepl_send_ctrl_state *s)
/*
send a generic wins replication request
*/
-struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
- struct wrepl_packet *packet,
- struct wrepl_send_ctrl *ctrl)
+static struct wrepl_request *wrepl_request_internal_send(struct wrepl_socket *wrepl_socket,
+ const struct wrepl_packet *packet,
+ const struct wrepl_send_ctrl *ctrl)
{
struct wrepl_request *req;
struct wrepl_wrap wrap;
@@ -563,9 +609,9 @@ struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
/*
receive a generic WINS replication reply
*/
-NTSTATUS wrepl_request_recv(struct wrepl_request *req,
- TALLOC_CTX *mem_ctx,
- struct wrepl_packet **packet)
+static NTSTATUS wrepl_request_internal_recv(struct wrepl_request *req,
+ TALLOC_CTX *mem_ctx,
+ struct wrepl_packet **packet)
{
NTSTATUS status = wrepl_request_wait(req);
if (NT_STATUS_IS_OK(status) && packet) {
@@ -575,16 +621,109 @@ NTSTATUS wrepl_request_recv(struct wrepl_request *req,
return status;
}
+struct wrepl_request_state {
+ struct wrepl_packet *packet;
+};
+
+static void wrepl_request_done(struct wrepl_request *subreq);
+
+struct tevent_req *wrepl_request_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct wrepl_socket *wrepl_socket,
+ const struct wrepl_packet *packet,
+ const struct wrepl_send_ctrl *ctrl)
+{
+ struct tevent_req *req;
+ struct wrepl_request_state *state;
+ struct wrepl_request *subreq;
+
+ if (wrepl_socket->event.ctx != ev) {
+ /* TODO: remove wrepl_socket->event.ctx !!! */
+ smb_panic("wrepl_associate_stop_send event context mismatch!");
+ return NULL;
+ }
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct wrepl_request_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ subreq = wrepl_request_internal_send(wrepl_socket, packet, ctrl);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ subreq->async.fn = wrepl_request_done;
+ subreq->async.private_data = req;
+
+ return req;
+}
+
+static void wrepl_request_done(struct wrepl_request *subreq)
+{
+ struct tevent_req *req = talloc_get_type_abort(subreq->async.private_data,
+ struct tevent_req);
+ struct wrepl_request_state *state = tevent_req_data(req,
+ struct wrepl_request_state);
+ NTSTATUS status;
+
+ status = wrepl_request_internal_recv(subreq, state, &state->packet);
+ if (!NT_STATUS_IS_OK(status)) {
+ tevent_req_nterror(req, status);
+ return;
+ }
+
+ tevent_req_done(req);
+}
+
+NTSTATUS wrepl_request_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct wrepl_packet **packet)
+{
+ struct wrepl_request_state *state = tevent_req_data(req,
+ struct wrepl_request_state);
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ tevent_req_received(req);
+ return status;
+ }
+
+ if (packet) {
+ *packet = talloc_move(mem_ctx, &state->packet);
+ }
+
+ tevent_req_received(req);
+ return NT_STATUS_OK;
+}
+
/*
a full WINS replication request/response
*/
NTSTATUS wrepl_request(struct wrepl_socket *wrepl_socket,
TALLOC_CTX *mem_ctx,
- struct wrepl_packet *req_packet,
+ const struct wrepl_packet *req_packet,
struct wrepl_packet **reply_packet)
{
- struct wrepl_request *req = wrepl_request_send(wrepl_socket, req_packet, NULL);
- return wrepl_request_recv(req, mem_ctx, reply_packet);
+ struct tevent_req *subreq;
+ bool ok;
+ NTSTATUS status;
+
+ subreq = wrepl_request_send(mem_ctx, wrepl_socket->event.ctx,
+ wrepl_socket, req_packet, NULL);
+ NT_STATUS_HAVE_NO_MEMORY(subreq);
+
+ ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
+ if (!ok) {
+ TALLOC_FREE(subreq);
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ status = wrepl_request_recv(subreq, mem_ctx, reply_packet);
+ TALLOC_FREE(subreq);
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ return NT_STATUS_OK;
}
@@ -594,7 +733,7 @@ struct wrepl_associate_state {
uint16_t major_version;
};
-static void wrepl_associate_done(struct wrepl_request *subreq);
+static void wrepl_associate_done(struct tevent_req *subreq);
struct tevent_req *wrepl_associate_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -603,7 +742,7 @@ struct tevent_req *wrepl_associate_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct wrepl_associate_state *state;
- struct wrepl_request *subreq;
+ struct tevent_req *subreq;
if (wrepl_socket->event.ctx != ev) {
/* TODO: remove wrepl_socket->event.ctx !!! */
@@ -636,19 +775,18 @@ struct tevent_req *wrepl_associate_send(TALLOC_CTX *mem_ctx,
}
memset(state->packet.padding.data, 0, state->packet.padding.length);
- subreq = wrepl_request_send(wrepl_socket, &state->packet, NULL);
+ subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, NULL);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
- subreq->async.fn = wrepl_associate_done;
- subreq->async.private_data = req;
+ tevent_req_set_callback(subreq, wrepl_associate_done, req);
return req;
}
-static void wrepl_associate_done(struct wrepl_request *subreq)
+static void wrepl_associate_done(struct tevent_req *subreq)
{
- struct tevent_req *req = talloc_get_type_abort(subreq->async.private_data,
+ struct tevent_req *req = tevent_req_callback_data(subreq,
struct tevent_req);
struct wrepl_associate_state *state = tevent_req_data(req,
struct wrepl_associate_state);
@@ -656,6 +794,7 @@ static void wrepl_associate_done(struct wrepl_request *subreq)
struct wrepl_packet *packet;
status = wrepl_request_recv(subreq, state, &packet);
+ TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
return;
@@ -726,7 +865,7 @@ struct wrepl_associate_stop_state {
struct wrepl_send_ctrl ctrl;
};
-static void wrepl_associate_stop_done(struct wrepl_request *subreq);
+static void wrepl_associate_stop_done(struct tevent_req *subreq);
struct tevent_req *wrepl_associate_stop_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -735,7 +874,7 @@ struct tevent_req *wrepl_associate_stop_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct wrepl_associate_stop_state *state;
- struct wrepl_request *subreq;
+ struct tevent_req *subreq;
if (wrepl_socket->event.ctx != ev) {
/* TODO: remove wrepl_socket->event.ctx !!! */
@@ -759,19 +898,18 @@ struct tevent_req *wrepl_associate_stop_send(TALLOC_CTX *mem_ctx,
state->ctrl.disconnect_after_send = true;
}
- subreq = wrepl_request_send(wrepl_socket, &state->packet, &state->ctrl);
+ subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, &state->ctrl);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
- subreq->async.fn = wrepl_associate_stop_done;
- subreq->async.private_data = req;
+ tevent_req_set_callback(subreq, wrepl_associate_stop_done, req);
return req;
}
-static void wrepl_associate_stop_done(struct wrepl_request *subreq)
+static void wrepl_associate_stop_done(struct tevent_req *subreq)
{
- struct tevent_req *req = talloc_get_type_abort(subreq->async.private_data,
+ struct tevent_req *req = tevent_req_callback_data(subreq,
struct tevent_req);
struct wrepl_associate_stop_state *state = tevent_req_data(req,
struct wrepl_associate_stop_state);
@@ -779,6 +917,7 @@ static void wrepl_associate_stop_done(struct wrepl_request *subreq)
/* currently we don't care about a possible response */
status = wrepl_request_recv(subreq, state, NULL);
+ TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
return;
@@ -837,7 +976,7 @@ struct wrepl_pull_table_state {
struct wrepl_wins_owner *partners;
};
-static void wrepl_pull_table_done(struct wrepl_request *subreq);
+static void wrepl_pull_table_done(struct tevent_req *subreq);
struct tevent_req *wrepl_pull_table_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -846,7 +985,7 @@ struct tevent_req *wrepl_pull_table_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct wrepl_pull_table_state *state;
- struct wrepl_request *subreq;
+ struct tevent_req *subreq;
if (wrepl_socket->event.ctx != ev) {
/* TODO: remove wrepl_socket->event.ctx !!! */
@@ -865,19 +1004,18 @@ struct tevent_req *wrepl_pull_table_send(TALLOC_CTX *mem_ctx,
state->packet.mess_type = WREPL_REPLICATION;
state->packet.message.replication.command = WREPL_REPL_TABLE_QUERY;
- subreq = wrepl_request_send(wrepl_socket, &state->packet, NULL);
+ subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, NULL);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
- subreq->async.fn = wrepl_pull_table_done;
- subreq->async.private_data = req;
+ tevent_req_set_callback(subreq, wrepl_pull_table_done, req);
return req;
}
-static void wrepl_pull_table_done(struct wrepl_request *subreq)
+static void wrepl_pull_table_done(struct tevent_req *subreq)
{
- struct tevent_req *req = talloc_get_type_abort(subreq->async.private_data,
+ struct tevent_req *req = tevent_req_callback_data(subreq,
struct tevent_req);
struct wrepl_pull_table_state *state = tevent_req_data(req,
struct wrepl_pull_table_state);
@@ -886,6 +1024,7 @@ static void wrepl_pull_table_done(struct wrepl_request *subreq)
struct wrepl_table *table;
status = wrepl_request_recv(subreq, state, &packet);
+ TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
return;
@@ -970,7 +1109,7 @@ struct wrepl_pull_names_state {
struct wrepl_name *names;
};
-static void wrepl_pull_names_done(struct wrepl_request *subreq);
+static void wrepl_pull_names_done(struct tevent_req *subreq);
struct tevent_req *wrepl_pull_names_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -979,7 +1118,7 @@ struct tevent_req *wrepl_pull_names_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct wrepl_pull_names_state *state;
- struct wrepl_request *subreq;
+ struct tevent_req *subreq;
if (wrepl_socket->event.ctx != ev) {
/* TODO: remove wrepl_socket->event.ctx !!! */
@@ -1000,19 +1139,18 @@ struct tevent_req *wrepl_pull_names_send(TALLOC_CTX *mem_ctx,
state->packet.message.replication.command = WREPL_REPL_SEND_REQUEST;
state->packet.message.replication.info.owner = io->in.partner;
- subreq = wrepl_request_send(wrepl_socket, &state->packet, NULL);
+ subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, NULL);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
- subreq->async.fn = wrepl_pull_names_done;
- subreq->async.private_data = req;
+ tevent_req_set_callback(subreq, wrepl_pull_names_done, req);
return req;
}
-static void wrepl_pull_names_done(struct wrepl_request *subreq)
+static void wrepl_pull_names_done(struct tevent_req *subreq)
{
- struct tevent_req *req = talloc_get_type_abort(subreq->async.private_data,
+ struct tevent_req *req = tevent_req_callback_data(subreq,
struct tevent_req);
struct wrepl_pull_names_state *state = tevent_req_data(req,
struct wrepl_pull_names_state);
@@ -1021,6 +1159,7 @@ static void wrepl_pull_names_done(struct wrepl_request *subreq)
uint32_t i;
status = wrepl_request_recv(subreq, state, &packet);
+ TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
return;
diff --git a/source4/libcli/wrepl/winsrepl.h b/source4/libcli/wrepl/winsrepl.h
index a69d3d8..047e5d2 100644
--- a/source4/libcli/wrepl/winsrepl.h
+++ b/source4/libcli/wrepl/winsrepl.h
@@ -4,6 +4,7 @@
structures for WINS replication client library
Copyright (C) Andrew Tridgell 2005
+ Copyright (C) Stefan Metzmacher 2005-2010
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
@@ -22,6 +23,8 @@
#include "librpc/gen_ndr/nbt.h"
#include "librpc/gen_ndr/winsrepl.h"
+struct wrepl_request;
+
/*
main context structure for the wins replication client library
*/
@@ -58,35 +61,6 @@ struct wrepl_send_ctrl {
bool disconnect_after_send;
};
-enum wrepl_request_state {
- WREPL_REQUEST_INIT = 0,
- WREPL_REQUEST_RECV = 1,
- WREPL_REQUEST_DONE = 2,
- WREPL_REQUEST_ERROR = 3
-};
-
-/*
- a WINS replication request
-*/
-struct wrepl_request {
- struct wrepl_request *next, *prev;
- struct wrepl_socket *wrepl_socket;
-
- enum wrepl_request_state state;
- bool trigger;
- NTSTATUS status;
-
- struct tevent_timer *te;
-
- struct wrepl_packet *packet;
-
- struct {
- void (*fn)(struct wrepl_request *);
- void *private_data;
- } async;
-};
-
-
/*
setup an association
*/
diff --git a/source4/torture/nbt/winsreplication.c b/source4/torture/nbt/winsreplication.c
index 14fe584..9a7be03 100644
--- a/source4/torture/nbt/winsreplication.c
+++ b/source4/torture/nbt/winsreplication.c
@@ -83,7 +83,7 @@ static const char *wrepl_name_state_string(enum wrepl_name_state state)
static bool test_assoc_ctx1(struct torture_context *tctx)
{
bool ret = true;
- struct wrepl_request *req;
+ struct tevent_req *subreq;
struct wrepl_socket *wrepl_socket1;
struct wrepl_associate associate1;
struct wrepl_socket *wrepl_socket2;
@@ -95,6 +95,7 @@ static bool test_assoc_ctx1(struct torture_context *tctx)
NTSTATUS status;
struct nbt_name name;
const char *address;
+ bool ok;
if (!torture_nbt_get_name(tctx, &name, &address))
return false;
@@ -131,8 +132,13 @@ static bool test_assoc_ctx1(struct torture_context *tctx)
packet.message.replication.command = WREPL_REPL_TABLE_QUERY;
ZERO_STRUCT(ctrl);
ctrl.send_only = true;
- req = wrepl_request_send(wrepl_socket2, &packet, &ctrl);
- status = wrepl_request_recv(req, tctx, &rep_packet);
+ subreq = wrepl_request_send(tctx, tctx->ev, wrepl_socket2, &packet, &ctrl);
+ ok = tevent_req_poll(subreq, tctx->ev);
+ if (!ok) {
+ CHECK_STATUS(tctx, NT_STATUS_INTERNAL_ERROR, NT_STATUS_OK);
+ }
+ status = wrepl_request_recv(subreq, tctx, &rep_packet);
--
Samba Shared Repository
More information about the samba-cvs
mailing list