summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorMatthieu Patou <mat@matws.net>2010-05-07 04:15:28 +0400
committerMatthias Dieter Wallnöfer <mdw@samba.org>2010-06-07 11:58:29 +0200
commite2061095b52a198fa221d190117dcebbb63058e6 (patch)
tree612164f319079fa50ea476dbd30ce650eec3d066 /source4/lib
parent315aeef0f9fa20a4628783241f90dbeacf0b6dc4 (diff)
downloadsamba-e2061095b52a198fa221d190117dcebbb63058e6.tar.gz
samba-e2061095b52a198fa221d190117dcebbb63058e6.tar.bz2
samba-e2061095b52a198fa221d190117dcebbb63058e6.zip
s4:ldb python bindings - implement comparison on Python LDB Message objects
Coauthors: Jelmer Vernooij, Matthias Dieter Wallnöfer
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/pyldb.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index fd7584dc6c..bbb2e715b3 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -5,8 +5,8 @@
Copyright (C) 2005,2006 Tim Potter <tpot@samba.org>
Copyright (C) 2006 Simo Sorce <idra@samba.org>
- Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
- Copyright (C) 2009 Matthias Dieter Wallnöfer
+ Copyright (C) 2007-2010 Jelmer Vernooij <jelmer@samba.org>
+ Copyright (C) 2009-2010 Matthias Dieter Wallnöfer
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
@@ -2079,6 +2079,41 @@ static void py_ldb_msg_dealloc(PyLdbMessageObject *self)
self->ob_type->tp_free(self);
}
+static int py_ldb_msg_compare(PyLdbMessageObject *py_msg1,
+ PyLdbMessageObject *py_msg2)
+{
+ struct ldb_message *msg1 = PyLdbMessage_AsMessage(py_msg1),
+ *msg2 = PyLdbMessage_AsMessage(py_msg2);
+ unsigned int i;
+ int ret;
+
+ ret = ldb_dn_compare(msg1->dn, msg2->dn);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ret = msg1->num_elements - msg2->num_elements;
+ if (ret != 0) {
+ return ret;
+ }
+
+ for (i = 0; i < msg1->num_elements; i++) {
+ ret = ldb_msg_element_compare_name(&msg1->elements[i],
+ &msg2->elements[i]);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ret = ldb_msg_element_compare(&msg1->elements[i],
+ &msg2->elements[i]);
+ if (ret != 0) {
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
PyTypeObject PyLdbMessage = {
.tp_name = "ldb.Message",
.tp_methods = py_ldb_msg_methods,
@@ -2090,6 +2125,7 @@ PyTypeObject PyLdbMessage = {
.tp_repr = (reprfunc)py_ldb_msg_repr,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = (getiterfunc)py_ldb_msg_iter,
+ .tp_compare = (cmpfunc)py_ldb_msg_compare,
};
PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *tree)