Remove more uses of global_loadparm.
[kai/samba.git] / source4 / lib / messaging / pymessaging.c
index 1c22fb431a3a531207e840d8b807576d4bb39526..c2c23b679e0cab3c9a64a614e0eb16402afa30cc 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include <Python.h>
+#include "scripting/python/modules.h"
 #include "libcli/util/pyerrors.h"
 #include "librpc/rpc/pyrpc.h"
 #include "lib/messaging/irpc.h"
@@ -76,10 +77,10 @@ PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwa
 
        ret->mem_ctx = talloc_new(NULL);
 
-       ev = event_context_init(ret->mem_ctx);
+       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, global_loadparm);
        } else {
                messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
        }
@@ -93,12 +94,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);
        }
 
@@ -127,12 +128,15 @@ static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwa
        NTSTATUS status;
        struct server_id server;
        const char *kwnames[] = { "target", "msg_type", "data", NULL };
+       int length;
 
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois#|:send", 
-               discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &data.length)) {
+               discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &length)) {
                return NULL;
        }
 
+       data.length = length;
+
        if (!server_id_from_py(target, &server)) 
                return NULL;
 
@@ -159,11 +163,11 @@ static void py_msg_callback_wrapper(struct messaging_context *msg, void *private
 static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs)
 {
        messaging_Object *iface = (messaging_Object *)self;
-       uint32_t msg_type = -1;
+       int 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;
@@ -172,8 +176,10 @@ static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject
        Py_INCREF(callback);
 
        if (msg_type == -1) {
+               uint32_t msg_type32 = msg_type;
                status = messaging_register_tmp(iface->msg_ctx, callback,
-                                               py_msg_callback_wrapper, &msg_type);
+                                               py_msg_callback_wrapper, &msg_type32);
+               msg_type = msg_type32;
        } else {
                status = messaging_register(iface->msg_ctx, callback,
                                    msg_type, py_msg_callback_wrapper);
@@ -189,7 +195,7 @@ static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject
 static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs)
 {
        messaging_Object *iface = (messaging_Object *)self;
-       uint32_t msg_type = -1;
+       int msg_type = -1;
        PyObject *callback;
        const char *kwnames[] = { "callback", "msg_type", NULL };
 
@@ -325,10 +331,10 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
 
        ret->server_name = server;
 
-       ev = event_context_init(ret->mem_ctx);
+       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, global_loadparm);
        } else {
                messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
        }
@@ -342,12 +348,12 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
                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);
        }