cvs: php4 /ext/ldap ldap.c
| From: | Stig Venaas | Date: | Sat, 26 Aug 2000 16:20:37 +0000 |
| Subject: | cvs: php4 /ext/ldap ldap.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1397@lists.php.net to get a copy of this message | ||
venaas Sat Aug 26 09:20:37 2000 EDT
Modified files:
/php4/ext/ldap ldap.c
Log:
Makes it work with OpenLDAP 2.0 and reduces number of ifdefs
Index: php4/ext/ldap/ldap.c
diff -u php4/ext/ldap/ldap.c:1.60 php4/ext/ldap/ldap.c:1.61
--- php4/ext/ldap/ldap.c:1.60 Sun Aug 20 11:47:14 2000
+++ php4/ext/ldap/ldap.c Sat Aug 26 09:20:37 2000
@@ -17,12 +17,13 @@
| Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Gerrit Thomson <334647@swin.edu.au> |
| Jani Taskinen <sniper@iki.fi> |
+ | Stig Venaas <venaas@uninett.no> |
| PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: ldap.c,v 1.60 2000/08/20 18:47:14 venaas Exp $ */
+/* $Id: ldap.c,v 1.61 2000/08/26 16:20:37 venaas Exp $ */
#define IS_EXT_MODULE
#include "php.h"
@@ -200,7 +201,7 @@
php_info_print_table_start();
php_info_print_table_row(2, "LDAP Support", "enabled" );
- php_info_print_table_row(2, "RCS Version", "$Id: ldap.c,v 1.60 2000/08/20 18:47:14
venaas Exp $" );
+ php_info_print_table_row(2, "RCS Version", "$Id: ldap.c,v 1.61 2000/08/26 16:20:37
venaas Exp $" );
php_info_print_table_row(2, "Total Links", maxl );
#ifdef LDAP_API_VERSION
snprintf(ldapapiversion, 31, "%ld", LDAP_API_VERSION);
@@ -424,6 +425,24 @@
}
+static int _get_lderrno(LDAP *ldap)
+{
+#if !HAVE_NSLDAP
+#if LDAP_API_VERSION > 2000
+ int lderr;
+
+ /* New versions of OpenLDAP do it this way */
+ ldap_get_option(ldap, LDAP_OPT_ERROR_NUMBER, &lderr);
+ return lderr;
+#else
+ return ldap->ld_errno;
+#endif
+#else
+ return ldap_get_lderrno(ldap,NULL,NULL);
+#endif
+}
+
+
#if 0
PHP_FUNCTION(ber_free)
{
@@ -481,13 +500,8 @@
if (ldap_bind_s(ldap, ldap_bind_rdn, ldap_bind_pw, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
#if !HAVE_NSLDAP
-#if LDAP_API_VERSION > 2000
- /* New versions of OpenLDAP do it this way */
- php_error(E_WARNING,"LDAP: Unable to bind to server:
%s",ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL)));
-#else
- php_error(E_WARNING,"LDAP: Unable to bind to server:
%s",ldap_err2string(ldap->ld_errno));
+ php_error(E_WARNING,"LDAP: Unable to bind to server:
%s",ldap_err2string(_get_lderrno(ldap)));
#endif
-#endif
RETURN_FALSE;
} else {
RETURN_TRUE;
@@ -636,11 +650,7 @@
if (errno != LDAP_SUCCESS && errno != LDAP_SIZELIMIT_EXCEEDED) {
#if !HAVE_NSLDAP
-#if LDAP_API_VERSION > 2000
- php_error(E_WARNING,"LDAP: Unable to perform the search:
%s",ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL)));
-#else
- php_error(E_WARNING, "LDAP: Unable to perform the search: %s",
ldap_err2string(ldap->ld_errno));
-#endif
+ php_error(E_WARNING,"LDAP: Unable to perform the search:
%s",ldap_err2string(_get_lderrno(ldap)));
#endif
RETVAL_FALSE;
} else {
@@ -1014,12 +1024,8 @@
if ((ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute)) == NULL) {
#if !HAVE_NSLDAP
-#if LDAP_API_VERSION > 2000
- php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL)));
-#else
- php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(ldap->ld_errno));
+ php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(_get_lderrno(ldap)));
#endif
-#endif
RETURN_FALSE;
}
@@ -1065,15 +1071,7 @@
attribute = (*attr)->value.str.val;
if ((ldap_value_len = ldap_get_values_len(ldap, ldap_result_entry, attribute)) == NULL) {
-#if !HAVE_NSLDAP
-#if LDAP_API_VERSION > 2000
- php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL)));
-#else
- php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(ldap->ld_errno));
-#endif
-#else
- php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL)));
-#endif
+ php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s",
ldap_err2string(_get_lderrno(ldap)));
RETURN_FALSE;
}
@@ -1396,15 +1394,7 @@
RETURN_LONG(0);
}
-#if !HAVE_NSLDAP
-#if LDAP_API_VERSION > 2000
- RETURN_LONG( ldap_get_lderrno(ldap, NULL, NULL) );
-#else
- RETURN_LONG( ldap->ld_errno );
-#endif
-#else
- RETURN_LONG( ldap_get_lderrno(ldap, NULL, NULL) );
-#endif
+ RETURN_LONG( _get_lderrno(ldap) );
}
/* }}} */
@@ -1439,15 +1429,7 @@
RETURN_FALSE;
}
-#if !HAVE_NSLDAP
-#if LDAP_API_VERSION > 2000
- ld_errno = ldap_get_lderrno(ldap, NULL, NULL);
-#else
- ld_errno = ldap->ld_errno;
-#endif
-#else
- ld_errno = ldap_get_lderrno(ldap, NULL, NULL);
-#endif
+ ld_errno = _get_lderrno(ldap);
RETURN_STRING(ldap_err2string(ld_errno), 1);
}