[SCM] Samba Shared Repository - branch v4-0-test updated - release-4-0-0alpha3-1835-ga429dc7

Jelmer Vernooij jelmer at samba.org
Mon May 26 11:47:06 GMT 2008


The branch, v4-0-test has been updated
       via  a429dc730f97388f0b4478b44522b1fe53f8569a (commit)
       via  f758553ac50d374f64a8763055dc4f12ab9b0c68 (commit)
       via  9861cae1aebdef41f098df71be4e5a33f6af9bf1 (commit)
       via  3d22b72bb780065059f45ebeb6025d1bceb1f5b6 (commit)
       via  1c179566cb39eb09e522dbce69230472a5d4e655 (commit)
       via  e1af9708c9b40edfa21862028672882797218174 (commit)
       via  17231443a0e3b0ebc4b75db3d721fe0b4e1170c6 (commit)
       via  f1a2d2bc00dac56080b2bd560074ec66d12a3129 (commit)
       via  4026493e91f8096e5d602cd42f9a83d2d75042db (commit)
       via  893119bb4c9c297966d43d37fe73faa747b7c86e (commit)
       via  988508c2d3269cc88ed38df2fc207a1c0aaccc6b (commit)
       via  6ecf81ae13dffa05356c1177c617206c120fb7d7 (commit)
       via  777dc3a2c7b5bf855344ba3ae8c8b564c48fc0c6 (commit)
       via  170d5aef80f37c26171a40e818cc8b557828d04b (commit)
       via  5f75a4f0c0343fe459f5c231f4b5ac89cea43b42 (commit)
       via  3b70a3de4aa63bd6c325fd620c71bd6111d3d2b8 (commit)
       via  f14ad6cd92227c7ed5c570b581e5db82b7d42e25 (commit)
       via  adcd87ad07abbf60a0152deae4b975a2401d701b (commit)
       via  3e7b361f5952bd2f8a417510adf218b78234ed36 (commit)
       via  f2e8f9851044506ef80811a6b6c5d31632a1f112 (commit)
       via  a75dbdec15ead785e0105dd61f980627e487fcb0 (commit)
       via  8f47157f09cbf4200f0f7c5efe8750fd5d316a3b (commit)
       via  daae053365cf6c5be7b31aa51a239c2660cfc120 (commit)
       via  717ce0b640a5c3aa62804b9869ef4dcc0f71b7ba (commit)
       via  19b46b50c982eb01909fe31d5abd304a1dd13577 (commit)
       via  5f07faf9c954229bf1cf6401eff81bdab4e242ae (commit)
       via  737059795ce150066ff775909030eebc54b595d9 (commit)
       via  1ce0632afeb94a69bf286706b3b1f9f4be7ea91f (commit)
       via  5980c7bfd727825758bda1b94ddf7a7c3f691620 (commit)
       via  0a9330ee2a38bff13bf9af48114e6eecd962680b (commit)
       via  3246258afb4f3b4a977a191f2f83c73e8ce9c65a (commit)
       via  c994fa427fdd1e9682a5ad506aafc77f942122d1 (commit)
       via  df01b040f7450c3be29f369a993955fbc4678bd9 (commit)
      from  8995c2f12174ebacc4a6b0864b6583665494a14b (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit a429dc730f97388f0b4478b44522b1fe53f8569a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 13:43:54 2008 +0200

    Revert "remove unused credentials ejs module."
    
    This reverts commit 9861cae1aebdef41f098df71be4e5a33f6af9bf1.

commit f758553ac50d374f64a8763055dc4f12ab9b0c68
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 13:40:17 2008 +0200

    Remove unused datablob and nbt ejs bindings.

commit 9861cae1aebdef41f098df71be4e5a33f6af9bf1
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 13:36:05 2008 +0200

    remove unused credentials ejs module.

commit 3d22b72bb780065059f45ebeb6025d1bceb1f5b6
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 13:34:36 2008 +0200

    Remove unused scripts.

commit 1c179566cb39eb09e522dbce69230472a5d4e655
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 13:31:57 2008 +0200

    Remove evil hack which breaks Python bindings.

commit e1af9708c9b40edfa21862028672882797218174
Merge: 17231443a0e3b0ebc4b75db3d721fe0b4e1170c6 8995c2f12174ebacc4a6b0864b6583665494a14b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 12:19:09 2008 +0200

    Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-pyirpc

commit 17231443a0e3b0ebc4b75db3d721fe0b4e1170c6
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 17:52:44 2008 +0200

    Fix import.

commit f1a2d2bc00dac56080b2bd560074ec66d12a3129
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 17:52:58 2008 +0200

    Remove obsolete ejs winreg example.

commit 4026493e91f8096e5d602cd42f9a83d2d75042db
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 17:56:49 2008 +0200

    Move some scripts to examples directory since they're not really generically useful.

commit 893119bb4c9c297966d43d37fe73faa747b7c86e
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 05:12:31 2008 +0200

    Cope with no server being active.

commit 988508c2d3269cc88ed38df2fc207a1c0aaccc6b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 05:00:45 2008 +0200

    Finish smbstatus in Python.

commit 6ecf81ae13dffa05356c1177c617206c120fb7d7
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 04:14:28 2008 +0200

    Allow using IRPC functions on the messaging bus from Python.

commit 777dc3a2c7b5bf855344ba3ae8c8b564c48fc0c6
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 03:07:18 2008 +0200

    Implement IRPC calls over the internal messaging bus.

commit 170d5aef80f37c26171a40e818cc8b557828d04b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 02:11:32 2008 +0200

    Remove unused cli ejs module.

commit 5f75a4f0c0343fe459f5c231f4b5ac89cea43b42
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 02:07:47 2008 +0200

    Remove unused nss module.

commit 3b70a3de4aa63bd6c325fd620c71bd6111d3d2b8
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 02:05:11 2008 +0200

    Remove unused EJS code.

commit f14ad6cd92227c7ed5c570b581e5db82b7d42e25
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 02:04:00 2008 +0200

    Convert smbstatus to Python.

commit adcd87ad07abbf60a0152deae4b975a2401d701b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 01:52:35 2008 +0200

    Provide access to server_id from python bindings, add more tests.

commit 3e7b361f5952bd2f8a417510adf218b78234ed36
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 01:15:15 2008 +0200

    Add bindings for deregister.

commit f2e8f9851044506ef80811a6b6c5d31632a1f112
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 01:10:24 2008 +0200

    Support messaging_client_init in the python bindings.

commit a75dbdec15ead785e0105dd61f980627e487fcb0
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 00:50:07 2008 +0200

    Add bindings for irpc_{add,remove}_name.

commit 8f47157f09cbf4200f0f7c5efe8750fd5d316a3b
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 26 00:38:12 2008 +0200

    Remove some unused cruft.

commit daae053365cf6c5be7b31aa51a239c2660cfc120
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 23:22:05 2008 +0200

    Fix compilation errors.

commit 717ce0b640a5c3aa62804b9869ef4dcc0f71b7ba
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 23:14:48 2008 +0200

    Trim the size of the Python bindings a bit.

commit 19b46b50c982eb01909fe31d5abd304a1dd13577
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 18:27:32 2008 +0200

    Fix environment generation.

commit 5f07faf9c954229bf1cf6401eff81bdab4e242ae
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 18:15:55 2008 +0200

    Move result tuple generation out of main Python function running.

commit 737059795ce150066ff775909030eebc54b595d9
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 17:53:10 2008 +0200

    Use separate function for in argument parsing.

commit 1ce0632afeb94a69bf286706b3b1f9f4be7ea91f
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 16:47:12 2008 +0200

    Add tests for irpc python bindings.

commit 5980c7bfd727825758bda1b94ddf7a7c3f691620
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 16:26:34 2008 +0200

    Start building IRPC Python support.

commit 0a9330ee2a38bff13bf9af48114e6eecd962680b
Merge: 3246258afb4f3b4a977a191f2f83c73e8ce9c65a a875e07a37568b7e51c290074d5e3834c2caa4d6
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 06:38:05 2008 +0200

    Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-pyirpc

commit 3246258afb4f3b4a977a191f2f83c73e8ce9c65a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 18:25:27 2008 +0200

    Initialize module.

commit c994fa427fdd1e9682a5ad506aafc77f942122d1
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 18:19:41 2008 +0200

    Remove remaining EJS RPC code, was unused.

commit df01b040f7450c3be29f369a993955fbc4678bd9
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat May 24 18:18:21 2008 +0200

    Initial work on IRPC Python support.

-----------------------------------------------------------------------

Summary of changes:
 source/lib/messaging/config.mk              |   14 +-
 source/lib/messaging/irpc.h                 |    1 +
 source/lib/messaging/messaging.c            |    5 +
 source/lib/messaging/pymessaging.c          |  559 +++++++++++++++++++++
 source/lib/messaging/tests/bindings.py      |   57 +++
 source/libcli/nbt/nbtname.c                 |   21 +
 source/librpc/config.mk                     |   17 +
 source/librpc/idl/nbt.idl                   |   18 +-
 source/librpc/rpc/dcerpc.h                  |    1 +
 source/librpc/rpc/pyrpc.c                   |   69 +++-
 source/librpc/rpc/pyrpc.h                   |   18 +
 source/pidl/lib/Parse/Pidl/Samba4/Python.pm |  270 ++++++-----
 source/scripting/bin/samba3dump             |    4 +-
 source/scripting/bin/samr.py                |  114 -----
 source/scripting/bin/smbstatus              |  159 +++----
 source/scripting/bin/winreg                 |  107 ----
 source/scripting/bin/winreg.py              |   87 ----
 source/scripting/ejs/config.mk              |   39 +--
 source/scripting/ejs/ejsrpc.c               |  424 ----------------
 source/scripting/ejs/ejsrpc.h               |  172 -------
 source/scripting/ejs/smbcalls.c             |    2 -
 source/scripting/ejs/smbcalls_cli.c         |  722 ---------------------------
 source/scripting/ejs/smbcalls_data.c        |  284 -----------
 source/scripting/ejs/smbcalls_nbt.c         |   93 ----
 source/scripting/ejs/smbcalls_nss.c         |  160 ------
 source/scripting/ejs/smbcalls_reg.c         |   90 ----
 source/scripting/ejs/smbcalls_rpc.c         |  385 --------------
 source/scripting/libjs/auth.js              |   18 -
 source/scripting/libjs/management.js        |  157 ------
 source/scripting/python/examples/samr.py    |  114 +++++
 source/scripting/python/examples/winreg.py  |   87 ++++
 source/selftest/samba4_tests.sh             |    1 +
 source/smb_server/smb_server.c              |    4 +-
 source/web_server/swat/__init__.py          |   27 +
 testprogs/ejs/argv.js                       |   14 -
 testprogs/ejs/nbtstats                      |   33 --
 36 files changed, 1226 insertions(+), 3121 deletions(-)
 create mode 100644 source/lib/messaging/pymessaging.c
 create mode 100644 source/lib/messaging/tests/bindings.py
 delete mode 100755 source/scripting/bin/samr.py
 delete mode 100755 source/scripting/bin/winreg
 delete mode 100755 source/scripting/bin/winreg.py
 delete mode 100644 source/scripting/ejs/ejsrpc.c
 delete mode 100644 source/scripting/ejs/ejsrpc.h
 delete mode 100644 source/scripting/ejs/smbcalls_cli.c
 delete mode 100644 source/scripting/ejs/smbcalls_data.c
 delete mode 100644 source/scripting/ejs/smbcalls_nbt.c
 delete mode 100644 source/scripting/ejs/smbcalls_nss.c
 delete mode 100644 source/scripting/ejs/smbcalls_reg.c
 delete mode 100644 source/scripting/ejs/smbcalls_rpc.c
 delete mode 100644 source/scripting/libjs/auth.js
 delete mode 100644 source/scripting/libjs/management.js
 create mode 100755 source/scripting/python/examples/samr.py
 create mode 100755 source/scripting/python/examples/winreg.py
 create mode 100644 source/web_server/swat/__init__.py
 delete mode 100644 testprogs/ejs/argv.js
 delete mode 100755 testprogs/ejs/nbtstats


Changeset truncated at 500 lines:

diff --git a/source/lib/messaging/config.mk b/source/lib/messaging/config.mk
index eaf7e35..e92f78c 100644
--- a/source/lib/messaging/config.mk
+++ b/source/lib/messaging/config.mk
@@ -1,6 +1,3 @@
-
-################################################
-# Start SUBSYSTEM MESSAGING
 [SUBSYSTEM::MESSAGING]
 PUBLIC_DEPENDENCIES = \
 		LIBSAMBA-UTIL \
@@ -9,8 +6,13 @@ PUBLIC_DEPENDENCIES = \
 		UNIX_PRIVS \
 		UTIL_TDB \
 		CLUSTER \
-		LIBNDR
-# End SUBSYSTEM MESSAGING
-################################################
+		LIBNDR \
+		samba-socket
 
 MESSAGING_OBJ_FILES = $(libmessagingsrcdir)/messaging.o
+
+[PYTHON::python_messaging]
+LIBRARY_REALNAME = samba/messaging.$(SHLIBEXT)
+PRIVATE_DEPENDENCIES = MESSAGING LIBEVENTS python_irpc
+
+python_messaging_OBJ_FILES = $(libmessagingsrcdir)/pymessaging.o
diff --git a/source/lib/messaging/irpc.h b/source/lib/messaging/irpc.h
index f44c0af..65e98dc 100644
--- a/source/lib/messaging/irpc.h
+++ b/source/lib/messaging/irpc.h
@@ -125,6 +125,7 @@ NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name);
 struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name);
 void irpc_remove_name(struct messaging_context *msg_ctx, const char *name);
 NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status);
+struct server_id messaging_get_server_id(struct messaging_context *msg_ctx);
 
 #endif
 
diff --git a/source/lib/messaging/messaging.c b/source/lib/messaging/messaging.c
index e7b6548..4b90e8c 100644
--- a/source/lib/messaging/messaging.c
+++ b/source/lib/messaging/messaging.c
@@ -1113,3 +1113,8 @@ void irpc_remove_name(struct messaging_context *msg_ctx, const char *name)
 	tdb_unlock_bystring(t->tdb, name);
 	talloc_free(t);
 }
+
+struct server_id messaging_get_server_id(struct messaging_context *msg_ctx)
+{
+	return msg_ctx->server_id;
+}
diff --git a/source/lib/messaging/pymessaging.c b/source/lib/messaging/pymessaging.c
new file mode 100644
index 0000000..1c22fb4
--- /dev/null
+++ b/source/lib/messaging/pymessaging.c
@@ -0,0 +1,559 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Copyright © Jelmer Vernooij <jelmer at samba.org> 2008
+
+   Based on the equivalent for EJS:
+   Copyright © Andrew Tridgell <tridge at samba.org> 2005
+   
+   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 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include <Python.h>
+#include "libcli/util/pyerrors.h"
+#include "librpc/rpc/pyrpc.h"
+#include "lib/messaging/irpc.h"
+#include "lib/messaging/messaging.h"
+#include "lib/events/events.h"
+#include "cluster/cluster.h"
+#include "param/param.h"
+#include "librpc/gen_ndr/py_irpc.h"
+
+PyAPI_DATA(PyTypeObject) messaging_Type;
+PyAPI_DATA(PyTypeObject) irpc_ClientConnectionType;
+
+static bool server_id_from_py(PyObject *object, struct server_id *server_id)
+{
+	if (!PyTuple_Check(object)) {
+		PyErr_SetString(PyExc_ValueError, "Expected tuple");
+		return false;
+	}
+
+	if (PyTuple_Size(object) == 3) {
+		return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node);
+	} else {
+		int id, id2;
+		if (!PyArg_ParseTuple(object, "ii", &id, &id2))
+			return false;
+		*server_id = cluster_id(id, id2);
+		return true;
+	}
+}
+
+typedef struct {
+	PyObject_HEAD
+	TALLOC_CTX *mem_ctx;
+	struct messaging_context *msg_ctx;
+} messaging_Object;
+
+PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
+{
+	struct event_context *ev;
+	const char *kwnames[] = { "own_id", "messaging_path", NULL };
+	PyObject *own_id = Py_None;
+	const char *messaging_path = NULL;
+	messaging_Object *ret;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oz:connect", 
+		discard_const_p(char *, kwnames), &own_id, &messaging_path)) {
+		return NULL;
+	}
+
+	ret = PyObject_New(messaging_Object, &messaging_Type);
+	if (ret == NULL)
+		return NULL;
+
+	ret->mem_ctx = talloc_new(NULL);
+
+	ev = event_context_init(ret->mem_ctx);
+
+	if (messaging_path == NULL) {
+		messaging_path = lp_messaging_path(ret, global_loadparm);
+	} else {
+		messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
+	}
+
+	if (own_id != Py_None) {
+		struct server_id server_id;
+
+		if (!server_id_from_py(own_id, &server_id)) 
+			return NULL;
+
+		ret->msg_ctx = messaging_init(ret->mem_ctx, 
+					    messaging_path,
+					    server_id,
+				            lp_iconv_convenience(global_loadparm),
+					    ev);
+	} else {
+		ret->msg_ctx = messaging_client_init(ret->mem_ctx, 
+					    messaging_path,
+				            lp_iconv_convenience(global_loadparm),
+					    ev);
+	}
+
+	if (ret->msg_ctx == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, "messaging_connect unable to create a messaging context");
+		talloc_free(ret->mem_ctx);
+		return NULL;
+	}
+
+	return (PyObject *)ret;
+}
+
+static void py_messaging_dealloc(PyObject *self)
+{
+	messaging_Object *iface = (messaging_Object *)self;
+	talloc_free(iface->msg_ctx);
+	PyObject_Del(self);
+}
+
+static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	messaging_Object *iface = (messaging_Object *)self;
+	uint32_t msg_type;
+	DATA_BLOB data;
+	PyObject *target;
+	NTSTATUS status;
+	struct server_id server;
+	const char *kwnames[] = { "target", "msg_type", "data", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois#|:send", 
+		discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &data.length)) {
+		return NULL;
+	}
+
+	if (!server_id_from_py(target, &server)) 
+		return NULL;
+
+	status = messaging_send(iface->msg_ctx, server, msg_type, &data);
+	if (NT_STATUS_IS_ERR(status)) {
+		PyErr_SetNTSTATUS(status);
+		return NULL;
+	}
+
+	return Py_None;
+}
+
+static void py_msg_callback_wrapper(struct messaging_context *msg, void *private, 
+			       uint32_t msg_type, 
+			       struct server_id server_id, DATA_BLOB *data)
+{
+	PyObject *callback = (PyObject *)private;
+
+	PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, 
+			      server_id.id, server_id.id2, server_id.node, 
+			      data->data, data->length);
+}
+
+static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	messaging_Object *iface = (messaging_Object *)self;
+	uint32_t msg_type = -1;
+	PyObject *callback;
+	NTSTATUS status;
+	const char *kwnames[] = { "callback", "msg_type", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", 
+		discard_const_p(char *, kwnames), &callback, &msg_type)) {
+		return NULL;
+	}
+
+	Py_INCREF(callback);
+
+	if (msg_type == -1) {
+		status = messaging_register_tmp(iface->msg_ctx, callback,
+						py_msg_callback_wrapper, &msg_type);
+	} else {
+		status = messaging_register(iface->msg_ctx, callback,
+				    msg_type, py_msg_callback_wrapper);
+	}
+	if (NT_STATUS_IS_ERR(status)) {
+		PyErr_SetNTSTATUS(status);
+		return NULL;
+	}
+
+	return PyLong_FromLong(msg_type);
+}
+
+static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	messaging_Object *iface = (messaging_Object *)self;
+	uint32_t msg_type = -1;
+	PyObject *callback;
+	const char *kwnames[] = { "callback", "msg_type", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", 
+		discard_const_p(char *, kwnames), &callback, &msg_type)) {
+		return NULL;
+	}
+
+	messaging_deregister(iface->msg_ctx, msg_type, callback);
+
+	Py_DECREF(callback);
+
+	return Py_None;
+}
+
+static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	messaging_Object *iface = (messaging_Object *)self;
+	NTSTATUS status;
+	char *name;
+	const char *kwnames[] = { "name", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", 
+		discard_const_p(char *, kwnames), &name)) {
+		return NULL;
+	}
+
+	status = irpc_add_name(iface->msg_ctx, name);
+	if (NT_STATUS_IS_ERR(status)) {
+		PyErr_SetNTSTATUS(status);
+		return NULL;
+	}
+
+	return Py_None;
+}
+
+
+static PyObject *py_messaging_remove_name(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	messaging_Object *iface = (messaging_Object *)self;
+	char *name;
+	const char *kwnames[] = { "name", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", 
+		discard_const_p(char *, kwnames), &name)) {
+		return NULL;
+	}
+
+	irpc_remove_name(iface->msg_ctx, name);
+
+	return Py_None;
+}
+
+static PyMethodDef py_messaging_methods[] = {
+	{ "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS, 
+		"S.send(target, msg_type, data) -> None\nSend a message" },
+	{ "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS,
+		"S.register(callback, msg_type=None) -> msg_type\nRegister a message handler" },
+	{ "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS,
+		"S.deregister(callback, msg_type) -> None\nDeregister a message handler" },
+	{ "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" },
+	{ "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" },
+	{ NULL, NULL, 0, NULL }
+};
+
+static PyObject *py_messaging_server_id(PyObject *obj, void *closure)
+{
+	messaging_Object *iface = (messaging_Object *)obj;
+	struct server_id server_id = messaging_get_server_id(iface->msg_ctx);
+
+	return Py_BuildValue("(iii)", server_id.id, server_id.id2, 
+			     server_id.node);
+}
+
+static PyGetSetDef py_messaging_getset[] = {
+	{ discard_const_p(char, "server_id"), py_messaging_server_id, NULL, 
+	  discard_const_p(char, "local server id") },
+	{ NULL },
+};
+
+
+PyTypeObject messaging_Type = {
+	PyObject_HEAD_INIT(NULL) 0,
+	.tp_name = "irpc.Messaging",
+	.tp_basicsize = sizeof(messaging_Object),
+	.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+	.tp_new = py_messaging_connect,
+	.tp_dealloc = py_messaging_dealloc,
+	.tp_methods = py_messaging_methods,
+	.tp_getset = py_messaging_getset,
+	.tp_doc = "Messaging(own_id=None, messaging_path=None)\n" \
+		  "Create a new object that can be used to communicate with the peers in the specified messaging path.\n" \
+		  "If no path is specified, the default path from smb.conf will be used."
+};
+
+
+/*
+  state of a irpc 'connection'
+*/
+typedef struct {
+	PyObject_HEAD
+	const char *server_name;
+	struct server_id *dest_ids;
+	struct messaging_context *msg_ctx;
+	TALLOC_CTX *mem_ctx;
+} irpc_ClientConnectionObject;
+
+/*
+  setup a context for talking to a irpc server
+     example: 
+        status = irpc.connect("smb_server");
+*/
+
+PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
+{
+	struct event_context *ev;
+	const char *kwnames[] = { "server", "own_id", "messaging_path", NULL };
+	char *server;
+	const char *messaging_path = NULL;
+	PyObject *own_id = Py_None;
+	irpc_ClientConnectionObject *ret;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Oz:connect", 
+		discard_const_p(char *, kwnames), &server, &own_id, &messaging_path)) {
+		return NULL;
+	}
+
+	ret = PyObject_New(irpc_ClientConnectionObject, &irpc_ClientConnectionType);
+	if (ret == NULL)
+		return NULL;
+
+	ret->mem_ctx = talloc_new(NULL);
+
+	ret->server_name = server;
+
+	ev = event_context_init(ret->mem_ctx);
+
+	if (messaging_path == NULL) {
+		messaging_path = lp_messaging_path(ret, global_loadparm);
+	} else {
+		messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
+	}
+
+	if (own_id != Py_None) {
+		struct server_id server_id;
+
+		if (!server_id_from_py(own_id, &server_id)) 
+			return NULL;
+
+		ret->msg_ctx = messaging_init(ret->mem_ctx, 
+					    messaging_path,
+					    server_id,
+				            lp_iconv_convenience(global_loadparm),
+					    ev);
+	} else {
+		ret->msg_ctx = messaging_client_init(ret->mem_ctx, 
+					    messaging_path,
+				            lp_iconv_convenience(global_loadparm),
+					    ev);
+	}
+
+	if (ret->msg_ctx == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, "irpc_connect unable to create a messaging context");
+		talloc_free(ret->mem_ctx);
+		return NULL;
+	}
+
+	ret->dest_ids = irpc_servers_byname(ret->msg_ctx, ret->mem_ctx, ret->server_name);
+	if (ret->dest_ids == NULL || ret->dest_ids[0].id == 0) {
+		talloc_free(ret->mem_ctx);
+		PyErr_SetNTSTATUS(NT_STATUS_OBJECT_NAME_NOT_FOUND);
+		return NULL;
+	} else {
+		return (PyObject *)ret;
+	}
+}
+
+typedef struct {
+	PyObject_HEAD
+	struct irpc_request **reqs;
+	int count;
+	int current;
+	TALLOC_CTX *mem_ctx;
+	py_data_unpack_fn unpack_fn;
+} irpc_ResultObject;
+
+	
+static PyObject *irpc_result_next(irpc_ResultObject *iterator)
+{
+	NTSTATUS status;
+
+	if (iterator->current >= iterator->count) {
+		PyErr_SetString(PyExc_StopIteration, "No more results");
+		return NULL;
+	}
+
+	status = irpc_call_recv(iterator->reqs[iterator->current]);
+	iterator->current++;
+	if (!NT_STATUS_IS_OK(status)) {
+		PyErr_SetNTSTATUS(status);
+		return NULL;
+	}
+
+	return iterator->unpack_fn(iterator->reqs[iterator->current-1]->r);
+}
+
+static PyObject *irpc_result_len(irpc_ResultObject *self)
+{
+	return PyLong_FromLong(self->count);
+}
+
+static PyMethodDef irpc_result_methods[] = {
+	{ "__len__", (PyCFunction)irpc_result_len, METH_NOARGS, 
+		"Number of elements returned"},
+	{ NULL }
+};
+
+static void irpc_result_dealloc(PyObject *self)
+{
+	talloc_free(((irpc_ResultObject *)self)->mem_ctx);
+	PyObject_Del(self);
+}
+
+PyTypeObject irpc_ResultIteratorType = {
+	PyObject_HEAD_INIT(NULL) 0,
+	.tp_name = "irpc.ResultIterator",
+	.tp_basicsize = sizeof(irpc_ResultObject),
+	.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+	.tp_iternext = (iternextfunc)irpc_result_next,
+	.tp_iter = PyObject_SelfIter,
+	.tp_methods = irpc_result_methods,
+	.tp_dealloc = irpc_result_dealloc,
+};
+
+static PyObject *py_irpc_call(irpc_ClientConnectionObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs)
+{
+	void *ptr;
+	struct irpc_request **reqs;
+	int i, count;
+	NTSTATUS status;
+	TALLOC_CTX *mem_ctx = talloc_new(NULL);
+	irpc_ResultObject *ret;
+
+	/* allocate the C structure */
+	ptr = talloc_zero_size(mem_ctx, method_def->table->calls[method_def->opnum].struct_size);
+	if (ptr == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto done;
+	}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list