Patch - error reporting with LDAP v3 API
Grahame Bowland
grahame at typhaon.ucs.uwa.edu.au
Thu Feb 8 03:24:51 CET 2001
Hi all,
The attached patch adds useful error reporting if the server supports
LDAP v3 APIs and has defined LDAP_API_VERSION correctly. This makes
the module much more useful when using it with OpenLDAP 2.x.
I hope it helps. What is the plan on adding support for LDAP v3
functionality (eg. ldap_rename, etc)? I have some of that work done
and would be willing to help with the rest.
The attached diff should apply to errors.c from python-ldap-1.10alpha3.
Cheers,
Grahame
--
Grahame Bowland
University Communications Services, The University of Western Australia
Phone: +61 8 9380 1175
-------------- next part --------------
--- errors.c Tue Aug 15 06:37:37 2000
+++ ../../python-ldap/Modules/errors.c Thu Feb 8 10:16:41 2001
@@ -2,7 +2,7 @@
/*
* errors that arise from ldap use
- * $Id: errors.c,v 1.3 2000/08/14 22:37:37 leonard Exp $
+ * $Id: errors.c,v 1.1.1.1 2001/02/07 02:56:15 grahame Exp $
*
* Most errors become their own exception
*/
@@ -31,19 +31,28 @@
return NULL;
}
#ifdef LDAP_TYPE_IS_OPAQUE
+#if !defined(LDAP_API_VERSION) || LDAP_API_VERSION <= 1823
else {
+
PyErr_SetString(LDAPexception_class,
"unknown error (C API does not expose error)");
return NULL;
}
+#endif
#else
else {
- int errnum;
+ int errnum, optval;
+ char *error;
PyObject *errobj;
PyObject *info;
PyObject *str;
+ PyObject *errornum;
+#if defined(LDAP_API_VERSION) && LDAP_API_VERSION > 1823
+ ldap_get_option(l, LDAP_OPT_ERROR_NUMBER, &errnum);
+#else
errnum = l->ld_errno;
+#endif
if (errnum<0 || errnum>=NUM_LDAP_ERRORS)
errobj = LDAPexception_class; /* unknown error XXX */
else
@@ -61,6 +70,15 @@
PyDict_SetItemString( info, "desc", str );
Py_XDECREF(str);
+ errornum = PyInt_FromLong(errnum);
+ if (errornum) {
+ PyDict_SetItemString( info, "error", errornum);
+ }
+ Py_XDECREF(errornum);
+
+#if defined(LDAP_API_VERSION) && LDAP_API_VERSION > 1823
+ /* how do you get this in LDAP v3 APIs? */
+#else
if (l->ld_matched != NULL && *l->ld_matched != '\0')
{
str = PyString_FromString(l->ld_matched);
@@ -68,7 +86,20 @@
PyDict_SetItemString( info, "matched", str );
Py_XDECREF(str);
}
+#endif
+#if defined(LDAP_API_VERSION) && LDAP_API_VERSION > 1823
+ ldap_get_option(l, LDAP_OPT_ERROR_STRING, &error);
+ if (error != NULL && *error != '\0') {
+ str = PyString_FromString(error);
+ if (str) {
+ PyDict_SetItemString(info, "info", str);
+ }
+ Py_XDECREF(str);
+ }
+ PyErr_SetObject(errobj, info);
+ Py_DECREF(info);
+#else
if (l->ld_error != NULL && *l->ld_error != '\0')
{
str = PyString_FromString(l->ld_error);
@@ -78,6 +109,7 @@
}
PyErr_SetObject( errobj, info );
Py_DECREF(info);
+#endif
return NULL;
}
#endif
More information about the python-ldap
mailing list