cvs: php4 /ext/ldap ldap.c

From: Date: Fri, 21 Jul 2000 19:00:22 +0000
Subject: cvs: php4 /ext/ldap ldap.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-843@lists.php.net to get a copy of this message
sniper Fri Jul 21 12:00:22 2000 EDT Modified files: /php4/ext/ldap ldap.c Log: @- Added four additional arguments: attrsonly, sizelimit, timelimit, deref which @ were missing in ldap_search(), ldap_list() and ldap_read() functions (Jani) @- Fixed a bug in ldap_search/list/read() which prevented returning the partial @ results when 'Sizelimit exceeded' error occurred. (Jani Taskinen) # And nuked some compile time warnings. Took a while to get this commit message # written..I hope I got it right. =) Index: php4/ext/ldap/ldap.c diff -u php4/ext/ldap/ldap.c:1.46 php4/ext/ldap/ldap.c:1.47 --- php4/ext/ldap/ldap.c:1.46 Tue Jun 27 02:28:05 2000 +++ php4/ext/ldap/ldap.c Fri Jul 21 12:00:21 2000 @@ -21,7 +21,7 @@ */ -/* $Id: ldap.c,v 1.46 2000/06/27 09:28:05 thies Exp $ */ +/* $Id: ldap.c,v 1.47 2000/07/21 19:00:21 sniper Exp $ */ #define IS_EXT_MODULE #include "php.h" @@ -179,7 +179,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.46 2000/06/27 09:28:05 thies Exp $" ); + php_info_print_table_row(2, "RCS Version", "$Id: ldap.c,v 1.47 2000/07/21 19:00:21 sniper Exp $" ); php_info_print_table_row(2, "Total Links", maxl ); #if HAVE_NSLDAP @@ -450,70 +450,76 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) { - pval **link, **base_dn, **filter, **attrs, **attr; + pval **link, **base_dn, **filter, **attrs, **attr, **attrsonly, **sizelimit, **timelimit, **deref; char *ldap_base_dn, *ldap_filter; LDAP *ldap; char **ldap_attrs = NULL; - int attrsonly; + int ldap_attrsonly = 0; /* 0 = types & values , 1 = only attributes types */ + int ldap_sizelimit = 0; /* LDAP_NO_LIMIT 0 */ + int ldap_timelimit = 0; /* 0 = no timelimit? */ + int ldap_deref = 0; /* LDAP_DEREF_NEVER 0, LDAP_DEREF_SEARCHING 1, LDAP_DEREF_FINDING 2, LDAP_DEREF_ALWAYS 3 */ LDAPMessage *ldap_result; - int num_attribs=0, i; + int num_attribs = 0; + int i, errno; + int myargcount = ZEND_NUM_ARGS(); LDAPLS_FETCH(); - - switch(ZEND_NUM_ARGS()) { - case 3 : - if (zend_get_parameters_ex(3, &link, &base_dn,&filter) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(base_dn); - convert_to_string_ex(filter); - - ldap_base_dn = (*base_dn)->value.str.val; - ldap_filter = (*filter)->value.str.val; + + if (myargcount < 3 || myargcount > 8 || zend_get_parameters_ex(myargcount, &link, &base_dn, &filter, &attrs, &attrsonly, &sizelimit, &timelimit, &deref) == FAILURE) { + WRONG_PARAM_COUNT; + } - break; + /* Reverse -> fall through */ + switch(myargcount) { + case 8 : + convert_to_long_ex(deref); + ldap_deref = (*deref)->value.lval; + + case 7 : + convert_to_long_ex(timelimit); + ldap_timelimit = (*timelimit)->value.lval; + + case 6 : + convert_to_long_ex(sizelimit); + ldap_sizelimit = (*sizelimit)->value.lval; + + case 5 : + convert_to_long_ex(attrsonly); + ldap_attrsonly = (*attrsonly)->value.lval; case 4 : - if (zend_get_parameters_ex(4, &link, &base_dn,&filter, &attrs) == FAILURE) { - WRONG_PARAM_COUNT; - } - if ((*attrs)->type != IS_ARRAY) { php_error(E_WARNING, "LDAP: Expected Array as last element"); RETURN_FALSE; } - convert_to_string_ex(base_dn); - convert_to_string_ex(filter); - - ldap_base_dn = (*base_dn)->value.str.val; - ldap_filter = (*filter)->value.str.val; - num_attribs = zend_hash_num_elements((*attrs)->value.ht); if ((ldap_attrs = emalloc((num_attribs+1) * sizeof(char *))) == NULL) { php_error(E_WARNING, "LDAP: Could not allocate memory"); RETURN_FALSE; - return; } for(i=0; i<num_attribs; i++) { - if(zend_hash_index_find((*attrs)->value.ht, i, (void **) &attr) == FAILURE) -{ + if(zend_hash_index_find((*attrs)->value.ht, i, (void **) &attr) == FAILURE) { php_error(E_WARNING, "LDAP: Array initialization wrong"); RETURN_FALSE; - return; } + SEPARATE_ZVAL(attr); convert_to_string_ex(attr); ldap_attrs[i] = (*attr)->value.str.val; } ldap_attrs[num_attribs] = NULL; - - break; + + case 3 : + convert_to_string_ex(base_dn); + convert_to_string_ex(filter); + ldap_base_dn = (*base_dn)->value.str.val; + ldap_filter = (*filter)->value.str.val; + break; default: WRONG_PARAM_COUNT; - break; + break; } /* fix to make null base_dn's work */ @@ -524,40 +530,56 @@ ldap = _get_ldap_link(link); if (ldap == NULL) RETURN_FALSE; - /* Is it useful to only get the attributes ? */ - attrsonly = 0; + /* sizelimit */ + if(ldap_sizelimit > 0) { + ldap->ld_sizelimit = ldap_sizelimit; + } + + /* timelimit */ + if(ldap_timelimit > 0) { + ldap->ld_timelimit = ldap_timelimit; + } - /* We can possibly add the timeout value also */ + /* deref */ + if(ldap_deref > 0) { + ldap->ld_deref = ldap_deref; + } - if (ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, attrsonly, &ldap_result) != LDAP_SUCCESS) { + /* Run the actual search */ + errno = ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_result); + + if (ldap_attrs != NULL) { + efree(ldap_attrs); + } + + 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))); + 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 #endif - RETVAL_FALSE; - } else { + RETVAL_FALSE; + } else { + if (errno == LDAP_SIZELIMIT_EXCEEDED) { + php_error(E_WARNING,"LDAP: Partial search results returned: Sizelimit exceeded."); + } RETVAL_LONG(zend_list_insert(ldap_result, le_result)); } - - if (ldap_attrs != NULL) { - /* for(i=0; i<num_attribs; i++) efree(ldap_attrs[i]); */ - efree(ldap_attrs); - } - return; } -/* {{{ proto int ldap_read(int link, string base_dn, string filter [, array attributes]) + +/* {{{ proto int ldap_read(int link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]] ) Read an entry */ PHP_FUNCTION(ldap_read) { php_ldap_do_search(INTERNAL_FUNCTION_PARAM_PASSTHRU, LDAP_SCOPE_BASE); } /* }}} */ + -/* {{{ proto int ldap_list(int link, string base_dn, string filter [, array attributes]) +/* {{{ proto int ldap_list(int link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]] ) Single-level search */ PHP_FUNCTION(ldap_list) { @@ -566,7 +588,7 @@ /* }}} */ -/* {{{ proto int ldap_search(int link, string base_dn, string filter [, array attributes]) +/* {{{ proto int ldap_search(int link, string base_dn, string filter [, array attrs [, int attrsonly [, int sizelimit [, int timelimit [, int deref]]]]] ) Search LDAP tree under base_dn */ PHP_FUNCTION(ldap_search) { @@ -574,6 +596,7 @@ } /* }}} */ + /* {{{ proto int ldap_free_result(int result) Free result memory */ PHP_FUNCTION(ldap_free_result) @@ -1292,7 +1315,6 @@ #else RETURN_LONG( ldap_get_lderrno(ldap, NULL, NULL) ); #endif - RETURN_LONG(0); } /* }}} */

« previous php.cvs (#843) next »