pymessaging: Use the server_id IDL structure rather than a tuple
authorAndrew Bartlett <abartlet@samba.org>
Mon, 29 Oct 2012 04:33:59 +0000 (15:33 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 30 Oct 2012 21:13:56 +0000 (08:13 +1100)
This will make it easier to pass this structure in and out.  The tuple is still
accepted as input.

Andrew Bartlett

librpc/wscript_build
source4/lib/messaging/pymessaging.c
source4/librpc/wscript_build
source4/scripting/python/samba/tests/messaging.py

index 0eeb01b7cf48971b3832fee997774e814a441a86..8a4c169d5af3f07ad12abe2f3c495120770547b0 100644 (file)
@@ -559,6 +559,11 @@ bld.SAMBA_SUBSYSTEM('RPC_NDR_SCERPC',
     public_deps='dcerpc-binding NDR_SCERPC'
     )
 
+bld.SAMBA_SUBSYSTEM('RPC_NDR_SERVER_ID',
+    source='gen_ndr/ndr_server_id_c.c',
+    public_deps='dcerpc-binding NDR_SERVER_ID'
+    )
+
 bld.SAMBA_SUBSYSTEM('RPC_NDR_NTSVCS',
     source='gen_ndr/ndr_ntsvcs_c.c',
     public_deps='dcerpc-binding ndr-standard'
index e8ef4a800b1859231bb89977769e615c25cd7168..fb74f3e1dbec3c6de590be1376725a043d721199 100644 (file)
 #include "librpc/rpc/pyrpc_util.h"
 #include "librpc/ndr/libndr.h"
 #include "lib/messaging/messaging.h"
+#include "lib/messaging/irpc.h"
 #include "lib/events/events.h"
 #include "cluster/cluster.h"
 #include "param/param.h"
 #include "param/pyparam.h"
 #include "librpc/rpc/dcerpc.h"
 #include "librpc/gen_ndr/server_id.h"
+#include <pytalloc.h>
 
 void initmessaging(void);
 
@@ -40,10 +42,14 @@ extern PyTypeObject imessaging_Type;
 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 (!py_check_dcerpc_type(object, "server_id", "server_id")) {
 
+                       PyErr_SetString(PyExc_ValueError, "Expected tuple or server_id");
+                       return false;
+               }
+               *server_id = *pytalloc_get_type(object, struct server_id);
+               return true;
+       }
        if (PyTuple_Size(object) == 3) {
                return PyArg_ParseTuple(object, "iii", &server_id->pid, &server_id->task_id, &server_id->vnn);
        } else {
@@ -228,10 +234,19 @@ static PyMethodDef py_imessaging_methods[] = {
 static PyObject *py_imessaging_server_id(PyObject *obj, void *closure)
 {
        imessaging_Object *iface = (imessaging_Object *)obj;
+       PyObject *py_server_id;
        struct server_id server_id = imessaging_get_server_id(iface->msg_ctx);
+       struct server_id *p_server_id = talloc(NULL, struct server_id);
+       if (!p_server_id) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+       *p_server_id = server_id;
+
+       py_server_id = py_return_ndr_struct("samba.dcerpc.server_id", "server_id", p_server_id, p_server_id);
+       talloc_unlink(NULL, p_server_id);
 
-       return Py_BuildValue("(iii)", server_id.pid, server_id.task_id,
-                            server_id.vnn);
+       return py_server_id;
 }
 
 static PyGetSetDef py_imessaging_getset[] = {
index d3b81b172134e01222d82ce217fe16db08982bd6..c53acef44d8cf0397e3230076d0b19624570318c 100755 (executable)
@@ -296,6 +296,12 @@ bld.SAMBA_PYTHON('python_irpc',
        realname='samba/dcerpc/irpc.so'
        )
 
+bld.SAMBA_PYTHON('python_server_id',
+       source='../../librpc/gen_ndr/py_server_id.c',
+       deps='RPC_NDR_SERVER_ID pytalloc-util pyrpc_util',
+       realname='samba/dcerpc/server_id.so'
+       )
+
 bld.SAMBA_PYTHON('python_winbind',
        source='gen_ndr/py_winbind.c',
        deps='RPC_NDR_WINBIND pytalloc-util pyrpc_util python_netlogon',
index fd9aa8ef82edbcbdca02fc289cc75c07b6a04454..3348ff8deb21c453e81654f8f223f484921e530f 100644 (file)
@@ -21,6 +21,7 @@
 
 from samba.messaging import Messaging
 from samba.tests import TestCase
+from samba.dcerpc.server_id import server_id
 
 class MessagingTests(TestCase):
 
@@ -36,8 +37,7 @@ class MessagingTests(TestCase):
 
     def test_assign_server_id(self):
         x = self.get_context()
-        self.assertTrue(isinstance(x.server_id, tuple))
-        self.assertEquals(3, len(x.server_id))
+        self.assertTrue(isinstance(x.server_id, server_id))
 
     def test_ping_speed(self):
         server_ctx = self.get_context((0, 1))