]> granicus.if.org Git - php/commitdiff
Making parallel search allow different filter for each link
authorStig Venaas <venaas@php.net>
Wed, 17 Jan 2001 13:43:39 +0000 (13:43 +0000)
committerStig Venaas <venaas@php.net>
Wed, 17 Jan 2001 13:43:39 +0000 (13:43 +0000)
ext/ldap/ldap.c

index 88e3c15ae4e4bb3a8a5e4b4dc18c77aba534c0d5..88c0ca9dc1ca74c5d7895e8b970c6a1118dce215 100644 (file)
@@ -671,11 +671,10 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
                        ldap_attrs[num_attribs] = NULL;
                
                case 3 :
-                       convert_to_string_ex(filter);
-                       ldap_filter = (*filter)->value.str.val;
-
                        /* parallel search? */
                        if (Z_TYPE_PP(link) != IS_ARRAY) {
+                               convert_to_string_ex(filter);
+                               ldap_filter = Z_STRVAL_PP(filter);
                                convert_to_string_ex(base_dn);
                                ldap_base_dn = Z_STRVAL_PP(base_dn);
                        }
@@ -688,7 +687,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
 
        /* parallel search? */
        if (Z_TYPE_PP(link) == IS_ARRAY) {
-               int i, nlinks, nbases, *rcs;
+               int i, nlinks, nbases, nfilters, *rcs;
                LDAP **links;
                zval **entry;
                
@@ -717,6 +716,22 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
                        ldap_base_dn = Z_STRLEN_PP(base_dn) < 1 ? NULL : Z_STRVAL_PP(base_dn);
                }
 
+               if (Z_TYPE_PP(filter) == IS_ARRAY) {
+                       nfilters = zend_hash_num_elements(Z_ARRVAL_PP(filter));
+                       if (nfilters != nlinks) {
+                               php_error(E_WARNING, "LDAP: Filter 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(filter));
+               } else {
+                       nfilters = 0; /* this means string, not array */
+                       convert_to_string_ex(filter);
+                       ldap_filter = Z_STRVAL_PP(filter);
+               }
+
                links = emalloc(nlinks * sizeof(*links));
                rcs = emalloc(nlinks * sizeof(*rcs));
                
@@ -738,6 +753,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
                                convert_to_string_ex(entry);
                                ldap_base_dn = Z_STRLEN_PP(entry) < 1 ? NULL : Z_STRVAL_PP(entry);
                        }
+                       if (nfilters != 0) { /* filter an array? */
+                               zend_hash_get_current_data(Z_ARRVAL_PP(filter), (void **)&entry);
+                               zend_hash_move_forward(Z_ARRVAL_PP(filter));
+                               convert_to_string_ex(entry);
+                               ldap_filter = Z_STRVAL_PP(entry);
+                       }
 
                        php_set_opts(ldap, ldap_sizelimit, ldap_timelimit, ldap_deref);