[PATCH 1/4] s4: ldb implement comparaison on the ldb Message

Matthieu Patou mat at matws.net
Thu May 6 18:15:28 MDT 2010


---
 source4/lib/ldb/pyldb.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index ce149cc..17b9e0c 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -5,7 +5,7 @@
 
    Copyright (C) 2005,2006 Tim Potter <tpot at samba.org>
    Copyright (C) 2006 Simo Sorce <idra at samba.org>
-   Copyright (C) 2007-2009 Jelmer Vernooij <jelmer at samba.org>
+   Copyright (C) 2007-2010 Jelmer Vernooij <jelmer at samba.org>
    Copyright (C) 2009 Matthias Dieter Wallnöfer
 
 	 ** NOTE! The following LGPL license applies to the ldb
@@ -2107,6 +2107,28 @@ 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)
+{
+  int ret, i;
+  struct ldb_message *msg1 = PyLdbMessage_AsMessage(py_msg1),
+                     *msg2 = PyLdbMessage_AsMessage(py_msg2);
+  if (msg1->dn != msg2->dn) {
+    ret = ldb_dn_compare(msg1->dn, msg2->dn);
+    if (ret != 0)
+      return ret;
+  }
+  ret = msg2->num_elements - msg1->num_elements;
+  if (ret != 0)
+    return ret;
+  for (i = 0; i < msg1->num_elements; i++) {
+    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,
@@ -2118,6 +2140,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)
-- 
1.7.0.4


--------------080302070607010006080106
Content-Type: text/x-patch;
 name="0003-s4-Add-comments-about-setup_secrets.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0003-s4-Add-comments-about-setup_secrets.patch"



More information about the samba-technical mailing list