summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/pyldb.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-08-26 15:59:00 +1000
committerAndrew Bartlett <abartlet@samba.org>2009-08-26 15:59:00 +1000
commit425386ff6141bba2e7b1d8f3c27e96aaf1c5cb95 (patch)
tree645da53767294cab003826df87a2502505c798b5 /source4/lib/ldb/pyldb.c
parent3ed33813bb6aa1ca932372c2a2ce36152b6af50b (diff)
downloadsamba-425386ff6141bba2e7b1d8f3c27e96aaf1c5cb95.tar.gz
samba-425386ff6141bba2e7b1d8f3c27e96aaf1c5cb95.tar.bz2
samba-425386ff6141bba2e7b1d8f3c27e96aaf1c5cb95.zip
s4:ldb Add ldb_ldif_write_string() and python wrappers
This allows us to turn a python LdbMessage back into a string. Andrew Bartlett
Diffstat (limited to 'source4/lib/ldb/pyldb.c')
-rw-r--r--source4/lib/ldb/pyldb.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 94415c8c31..3f7fa2f395 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -813,6 +813,41 @@ static PyObject *ldb_ldif_to_pyobject(struct ldb_ldif *ldif)
}
+static PyObject *py_ldb_write_ldif(PyLdbMessageObject *self, PyObject *args)
+{
+ int changetype;
+ PyObject *py_msg;
+ struct ldb_ldif ldif;
+ PyObject *ret;
+ char *string;
+ TALLOC_CTX *mem_ctx;
+
+ if (!PyArg_ParseTuple(args, "Oi", &py_msg, &changetype))
+ return NULL;
+
+ if (!PyLdbMessage_Check(py_msg)) {
+ PyErr_SetString(PyExc_TypeError, "Expected Ldb Message for msg");
+ return NULL;
+ }
+
+ ldif.msg = PyLdbMessage_AsMessage(py_msg);
+ ldif.changetype = changetype;
+
+ mem_ctx = talloc_new(NULL);
+
+ string = ldb_ldif_write_string(PyLdb_AsLdbContext(self), mem_ctx, &ldif);
+ if (!string) {
+ PyErr_SetString(PyExc_KeyError, "Failed to generate LDIF");
+ return NULL;
+ }
+
+ ret = PyString_FromString(string);
+
+ talloc_free(mem_ctx);
+
+ return ret;
+}
+
static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args)
{
PyObject *list;
@@ -1116,6 +1151,9 @@ static PyMethodDef py_ldb_methods[] = {
{ "parse_ldif", (PyCFunction)py_ldb_parse_ldif, METH_VARARGS,
"S.parse_ldif(ldif) -> iter(messages)\n"
"Parse a string formatted using LDIF." },
+ { "write_ldif", (PyCFunction)py_ldb_write_ldif, METH_VARARGS,
+ "S.write_ldif(message, changetype) -> ldif\n"
+ "Print the message as a string formatted using LDIF." },
{ "msg_diff", (PyCFunction)py_ldb_msg_diff, METH_VARARGS,
"S.msg_diff(Message) -> Message\n"
"Return an LDB Message of the difference between two Message objects." },