s3/s4 build: Fix Py_RETURN_NONE to work with python versions < 2.4
[idra/samba.git] / source4 / lib / messaging / pymessaging.c
index ad8f955466f4b396c5e62f24a32f4e950fee4fcc..3fa59bde573696defcff6cd800e1bb7d029e6ae3 100644 (file)
@@ -20,7 +20,7 @@
 */
 
 #include "includes.h"
-#include <Python.h>
+#include "../lib/util/python_util.h"
 #include "scripting/python/modules.h"
 #include "libcli/util/pyerrors.h"
 #include "librpc/rpc/pyrpc.h"
@@ -29,7 +29,6 @@
 #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;
@@ -37,6 +36,9 @@ PyAPI_DATA(PyTypeObject) irpc_ClientConnectionType;
 /* FIXME: This prototype should be in param/pyparam.h */
 struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx);
 
+/* FIXME: This prototype should be in py_irpc.h, or shared otherwise */
+extern const struct PyNdrRpcMethodDef py_ndr_irpc_methods[];
+
 static bool server_id_from_py(PyObject *object, struct server_id *server_id)
 {
        if (!PyTuple_Check(object)) {
@@ -63,7 +65,7 @@ typedef struct {
 
 PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
 {
-       struct event_context *ev;
+       struct tevent_context *ev;
        const char *kwnames[] = { "own_id", "messaging_path", NULL };
        PyObject *own_id = Py_None;
        const char *messaging_path = NULL;
@@ -150,7 +152,7 @@ static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwa
                return NULL;
        }
 
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 static void py_msg_callback_wrapper(struct messaging_context *msg, void *private, 
@@ -212,7 +214,7 @@ static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObjec
 
        Py_DECREF(callback);
 
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs)
@@ -233,7 +235,7 @@ static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject
                return NULL;
        }
 
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 
@@ -250,7 +252,7 @@ static PyObject *py_messaging_remove_name(PyObject *self, PyObject *args, PyObje
 
        irpc_remove_name(iface->msg_ctx, name);
 
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 static PyMethodDef py_messaging_methods[] = {
@@ -315,7 +317,7 @@ typedef struct {
 
 PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
 {
-       struct event_context *ev;
+       struct tevent_context *ev;
        const char *kwnames[] = { "server", "own_id", "messaging_path", NULL };
        char *server;
        const char *messaging_path = NULL;
@@ -541,8 +543,12 @@ static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpc
 
 void initmessaging(void)
 {
-       extern void initirpc(void);
        PyObject *mod;
+       PyObject *dep_irpc;
+
+       dep_irpc = PyImport_ImportModule("samba.dcerpc.irpc");
+       if (dep_irpc == NULL)
+               return;
 
        if (PyType_Ready(&irpc_ClientConnectionType) < 0)
                return;
@@ -560,8 +566,6 @@ void initmessaging(void)
        if (mod == NULL)
                return;
 
-       initirpc();
-
        Py_INCREF((PyObject *)&irpc_ClientConnectionType);
        PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_ClientConnectionType);