[PATCH] RFC 3876 control (return values filter)

Andreas Hasenack ahasenack at terra.com.br
Fri Jun 1 16:27:45 CEST 2007


On Thu, May 31, 2007 at 07:23:36PM -0300, Andreas Hasenack wrote:
> I will still see about the decode part and then post what I have.

Attached is my current patch. Keep in mind I did this basically using
the current code as a template.

I ended up not implementing the decode part, I'm not sure for what it
would be needed. Just for completeness?

-------------- next part --------------
Index: Modules/constants.c
===================================================================
--- Modules/constants.c
+++ Modules/constants.c	2007-06-01 11:12:12.000000000 -0300
@@ -262,4 +262,8 @@
 	PyDict_SetItemString( d, "LDAP_CONTROL_PAGE_OID", obj );
 	Py_DECREF(obj);
 
+	obj = PyString_FromString(LDAP_CONTROL_VALUESRETURNFILTER);
+	PyDict_SetItemString( d, "LDAP_CONTROL_VALUESRETURNFILTER", obj );
+	Py_DECREF(obj);
+
 }
Index: Modules/constants.h
===================================================================
--- Modules/constants.h
+++ Modules/constants.h	2007-06-01 11:12:12.000000000 -0300
@@ -12,4 +12,8 @@
 #define LDAP_CONTROL_PAGE_OID "1.2.840.113556.1.4.319"
 #endif /* !LDAP_CONTROL_PAGE_OID */
 
+#ifndef LDAP_CONTROL_VALUESRETURNFILTER
+#define LDAP_CONTROL_VALUESRETURNFILTER "1.2.826.0.1.3344810.2.3" /* RFC 3876 */
+#endif /* !LDAP_CONTROL_VALUESRETURNFILTER */
+
 #endif /* __h_constants_ */
Index: Modules/ldapcontrol.c
===================================================================
--- Modules/ldapcontrol.c
+++ Modules/ldapcontrol.c	2007-06-01 11:12:12.000000000 -0300
@@ -201,6 +201,46 @@
 
 /* --------------- en-/decoders ------------- */
 
+/* Matched Values, aka, Values Return Filter */
+static PyObject*
+encode_rfc3876(PyObject *self, PyObject *args)
+{
+	PyObject *res = 0;
+	int err;
+	BerElement *vrber = 0;
+	char *vrFilter;
+	struct berval *ctrl_val;
+
+	if (!PyArg_ParseTuple(args, "s:encode_valuesreturnfilter_control", &vrFilter)) {
+		goto endlbl;
+	}
+
+	if (!(vrber = ber_alloc_t(LBER_USE_DER))) {
+		LDAPerr(LDAP_NO_MEMORY);
+		goto endlbl;
+	}
+
+	err = ldap_put_vrFilter(vrber, vrFilter);
+	if (err == -1) {
+		LDAPerr(LDAP_FILTER_ERROR);
+		goto endlbl;
+	}
+
+	err = ber_flatten(vrber, &ctrl_val);
+	if (err == -1) {
+		LDAPerr(LDAP_NO_MEMORY);
+		goto endlbl;
+	}
+
+	res = Py_BuildValue("s#", ctrl_val->bv_val, ctrl_val->bv_len);
+
+endlbl:
+	if (vrber)
+		ber_free(vrber, 1);
+
+	return res;
+}
+
 static PyObject*
 encode_rfc2696(PyObject *self, PyObject *args)
 {
@@ -293,6 +333,7 @@
 static PyMethodDef methods[] = {
     {"encode_page_control", encode_rfc2696, METH_VARARGS },
     {"decode_page_control", decode_rfc2696, METH_VARARGS },
+    {"encode_valuesreturnfilter_control", encode_rfc3876, METH_VARARGS },
     { NULL, NULL }
 };
 
Index: Lib/ldap/controls.py
===================================================================
--- Lib/ldap/controls.py
+++ Lib/ldap/controls.py	2007-06-01 11:18:51.000000000 -0300
@@ -82,6 +82,23 @@
     return size,cookie
 
 
+class MatchedValuesControl(LDAPControl):
+  """
+  LDAP Matched Values control, as defined in RFC 3876
+
+  from ldap.controls import MatchedValuesControl
+  control = MatchedValuesControl(criticality, filter)
+  """
+  
+  controlType = ldap.LDAP_CONTROL_VALUESRETURNFILTER
+  
+  def __init__(self, criticality, controlValue=None):
+    LDAPControl.__init__(self, self.controlType, criticality, controlValue, None) 
+
+  def encodeControlValue(self, value):
+    return _ldap.encode_valuesreturnfilter_control(value)
+
+
 def EncodeControlTuples(ldapControls):
   """
   Return list of readily encoded 3-tuples which can be directly


More information about the python-ldap mailing list