From e2061095b52a198fa221d190117dcebbb63058e6 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Fri, 7 May 2010 04:15:28 +0400 Subject: [PATCH] s4:ldb python bindings - implement comparison on Python LDB Message objects MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Coauthors: Jelmer Vernooij, Matthias Dieter Wallnöfer --- source4/lib/ldb/pyldb.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file 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 Copyright (C) 2006 Simo Sorce - Copyright (C) 2007-2009 Jelmer Vernooij - Copyright (C) 2009 Matthias Dieter Wallnöfer + Copyright (C) 2007-2010 Jelmer Vernooij + 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) -- 2.34.1