From: Stig Venaas Date: Fri, 12 Jan 2001 22:08:26 +0000 (+0000) Subject: Added parallel search when given array of link identifiers X-Git-Tag: php-4.0.5RC1~611 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d17c57664924c177f0ff476961aca6a5f1be108;p=php Added parallel search when given array of link identifiers @- Made ldap_list(), ldap_read() and ldap_search() do parallel search when @ first parameter is an array of link identifiers (Stig Venaas) --- diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 23eeb6fa90..b360cee7f4 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -576,6 +576,37 @@ PHP_FUNCTION(ldap_unbind) /* }}} */ +static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref) +{ + /* sizelimit */ + if (sizelimit > -1) { +#if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP + ldap_set_option(ldap, LDAP_OPT_SIZELIMIT, &sizelimit); +#else + ldap->ld_sizelimit = sizelimit; +#endif + } + + /* timelimit */ + if (timelimit > -1) { +#if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP + ldap_set_option(ldap, LDAP_OPT_TIMELIMIT, &timelimit); +#else + ldap->ld_timelimit = timelimit; +#endif + } + + /* deref */ + if (deref > -1) { +#if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP + ldap_set_option(ldap, LDAP_OPT_DEREF, &deref); +#else + ldap->ld_deref = deref; +#endif + } +} + + static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) { pval **link, **base_dn, **filter, **attrs, **attr, **attrsonly, **sizelimit, **timelimit, **deref; @@ -586,7 +617,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) int ldap_sizelimit = -1; int ldap_timelimit = -1; int ldap_deref = -1; - LDAPMessage *ldap_result; + LDAPMessage *ldap_res; int num_attribs = 0; int i, errno; int myargcount = ZEND_NUM_ARGS(); @@ -639,10 +670,14 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) ldap_attrs[num_attribs] = NULL; 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; + + /* parallel search? */ + if (Z_TYPE_PP(link) != IS_ARRAY) { + convert_to_string_ex(base_dn); + ldap_base_dn = Z_STRVAL_PP(base_dn); + } break; default: @@ -650,6 +685,93 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) break; } + /* parallel search? */ + if (Z_TYPE_PP(link) == IS_ARRAY) { + int i, nlinks, nbases, *rcs; + LDAP **links; + zval **entry; + + nlinks = zend_hash_num_elements(Z_ARRVAL_PP(link)); + if (nlinks == 0) { + php_error(E_WARNING, "LDAP: No links in link array"); + if (ldap_attrs != NULL) { + efree(ldap_attrs); + } + RETURN_FALSE; + } + + if (Z_TYPE_PP(base_dn) == IS_ARRAY) { + nbases = zend_hash_num_elements(Z_ARRVAL_PP(base_dn)); + if (nbases != nlinks) { + php_error(E_WARNING, "LDAP: Base must either be a string, or an array with the same number of elements as the links array"); + if (ldap_attrs != NULL) { + efree(ldap_attrs); + } + RETURN_FALSE; + } + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(base_dn)); + } else { + nbases = 0; /* this means string, not array */ + convert_to_string_ex(base_dn); + ldap_base_dn = Z_STRLEN_PP(base_dn) < 1 ? NULL : Z_STRVAL_PP(base_dn); + } + + links = emalloc(nlinks * sizeof(*links)); + rcs = emalloc(nlinks * sizeof(*rcs)); + + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(link)); + for (i=0; i -1) { -#if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP - ldap_set_option(ldap, LDAP_OPT_SIZELIMIT, &ldap_sizelimit); -#else - ldap->ld_sizelimit = ldap_sizelimit; -#endif - } - - /* timelimit */ - if(ldap_timelimit > -1) { -#if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP - ldap_set_option(ldap, LDAP_OPT_TIMELIMIT, &ldap_timelimit); -#else - ldap->ld_timelimit = ldap_timelimit; -#endif - } - - /* deref */ - if(ldap_deref > -1) { -#if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP - ldap_set_option(ldap, LDAP_OPT_DEREF, &ldap_deref); -#else - ldap->ld_deref = ldap_deref; -#endif - } + php_set_opts(ldap, ldap_sizelimit, ldap_timelimit, ldap_deref); /* Run the actual search */ - errno = ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_result); + errno = ldap_search_s(ldap, ldap_base_dn, scope, ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res); if (ldap_attrs != NULL) { efree(ldap_attrs); @@ -712,7 +809,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) php_error(E_WARNING,"LDAP: Partial search results returned: Adminlimit exceeded."); } #endif - RETVAL_LONG(zend_list_insert(ldap_result, le_result)); + RETVAL_LONG(zend_list_insert(ldap_res, le_result)); } }