Avoid using a utility header for Python replacements included in Samba,
[kai/samba-autobuild/.git] / source4 / lib / messaging / pymessaging.c
index fb23214bca300322e54c309609edaa9423610a5f..535da4526c83230c9abd10dec733abdb1a953a98 100644 (file)
 #include "lib/events/events.h"
 #include "cluster/cluster.h"
 #include "param/param.h"
-#include "librpc/gen_ndr/py_irpc.h"
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
 
 PyAPI_DATA(PyTypeObject) messaging_Type;
 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)) {
@@ -60,7 +69,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;
@@ -80,7 +89,8 @@ PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwa
        ev = s4_event_context_init(ret->mem_ctx);
 
        if (messaging_path == NULL) {
-               messaging_path = lp_messaging_path(ret, global_loadparm);
+               messaging_path = lp_messaging_path(ret->mem_ctx, 
+                                                                  py_default_loadparm_context(ret->mem_ctx));
        } else {
                messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
        }
@@ -94,12 +104,12 @@ PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwa
                ret->msg_ctx = messaging_init(ret->mem_ctx, 
                                            messaging_path,
                                            server_id,
-                                           lp_iconv_convenience(global_loadparm),
+                                       py_iconv_convenience(ret->mem_ctx),
                                            ev);
        } else {
                ret->msg_ctx = messaging_client_init(ret->mem_ctx, 
                                            messaging_path,
-                                           lp_iconv_convenience(global_loadparm),
+                                       py_iconv_convenience(ret->mem_ctx),
                                            ev);
        }
 
@@ -146,7 +156,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, 
@@ -208,7 +218,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)
@@ -229,7 +239,7 @@ static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject
                return NULL;
        }
 
-       return Py_None;
+       Py_RETURN_NONE;
 }
 
 
@@ -246,7 +256,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[] = {
@@ -311,7 +321,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;
@@ -334,7 +344,8 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
        ev = s4_event_context_init(ret->mem_ctx);
 
        if (messaging_path == NULL) {
-               messaging_path = lp_messaging_path(ret, global_loadparm);
+               messaging_path = lp_messaging_path(ret->mem_ctx, 
+                                                                  py_default_loadparm_context(ret->mem_ctx));
        } else {
                messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
        }
@@ -536,8 +547,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;
@@ -555,8 +570,6 @@ void initmessaging(void)
        if (mod == NULL)
                return;
 
-       initirpc();
-
        Py_INCREF((PyObject *)&irpc_ClientConnectionType);
        PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_ClientConnectionType);