patrickallaert          Mon Jun 15 15:04:31 2009 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/ldap   ldap.c 
  Log:
  MFH: Refactoring that will help fixing #48441
  
http://cvs.php.net/viewvc.cgi/php-src/ext/ldap/ldap.c?r1=1.161.2.3.2.16&r2=1.161.2.3.2.17&diff_format=u
Index: php-src/ext/ldap/ldap.c
diff -u php-src/ext/ldap/ldap.c:1.161.2.3.2.16 
php-src/ext/ldap/ldap.c:1.161.2.3.2.17
--- php-src/ext/ldap/ldap.c:1.161.2.3.2.16      Sun Jun  7 21:27:42 2009
+++ php-src/ext/ldap/ldap.c     Mon Jun 15 15:04:31 2009
@@ -23,7 +23,7 @@
    +----------------------------------------------------------------------+
  */
  
-/* $Id: ldap.c,v 1.161.2.3.2.16 2009/06/07 21:27:42 patrickallaert Exp $ */
+/* $Id: ldap.c,v 1.161.2.3.2.17 2009/06/15 15:04:31 patrickallaert Exp $ */
 #define IS_EXT_MODULE
 
 #ifdef HAVE_CONFIG_H
@@ -322,7 +322,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.161.2.3.2.16 2009/06/07 21:27:42 patrickallaert Exp $");
+       php_info_print_table_row(2, "RCS Version", "$Id: ldap.c,v 
1.161.2.3.2.17 2009/06/15 15:04:31 patrickallaert Exp $");
 
        if (LDAPG(max_links) == -1) {
                snprintf(tmp, 31, "%ld/unlimited", LDAPG(num_links));
@@ -689,6 +689,7 @@
        int num_attribs = 0;
        int i, errno;
        int myargcount = ZEND_NUM_ARGS();
+       int ret = 1;
 
        if (myargcount < 3 || myargcount > 8 || 
zend_get_parameters_ex(myargcount, &link, &base_dn, &filter, &attrs, 
&attrsonly, &sizelimit, &timelimit, &deref) == FAILURE) {
                WRONG_PARAM_COUNT;
@@ -715,7 +716,8 @@
                case 4 : 
                        if (Z_TYPE_PP(attrs) != IS_ARRAY) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Expected Array as last element");
-                               RETURN_FALSE;
+                               ret = 0;
+                               goto cleanup;
                        }
 
                        num_attribs = 
zend_hash_num_elements(Z_ARRVAL_PP(attrs));
@@ -724,8 +726,8 @@
                        for (i = 0; i<num_attribs; i++) {
                                if (zend_hash_index_find(Z_ARRVAL_PP(attrs), i, 
(void **) &attr) == FAILURE) {
                                        php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Array initialization wrong");
-                                       efree(ldap_attrs);
-                                       RETURN_FALSE;
+                                       ret = 0;
+                                       goto cleanup;
                                }
 
                                SEPARATE_ZVAL(attr);
@@ -735,16 +737,7 @@
                        ldap_attrs[num_attribs] = NULL;
                
                case 3 :
-                       /* parallel search? */
-                       if (Z_TYPE_PP(link) != IS_ARRAY) {
-                               convert_to_string_ex(filter);
-                               ldap_filter = Z_STRVAL_PP(filter);
-
-                               /* If anything else than string is passed, 
ldap_base_dn = NULL */
-                               if (Z_TYPE_PP(base_dn) == IS_STRING) {
-                                       ldap_base_dn = Z_STRVAL_PP(base_dn);
-                               }
-                       }
+               
                break;
 
                default:
@@ -761,20 +754,16 @@
                nlinks = zend_hash_num_elements(Z_ARRVAL_PP(link));
                if (nlinks == 0) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No links 
in link array");
-                       if (ldap_attrs != NULL) {
-                               efree(ldap_attrs);
-                       }
-                       RETURN_FALSE;
+                       ret = 0;
+                       goto cleanup;
                }
 
                if (Z_TYPE_PP(base_dn) == IS_ARRAY) {
                        nbases = zend_hash_num_elements(Z_ARRVAL_PP(base_dn));
                        if (nbases != nlinks) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"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;
+                               ret = 0;
+                               goto cleanup;
                        }
                        zend_hash_internal_pointer_reset(Z_ARRVAL_PP(base_dn));
                } else {
@@ -791,10 +780,8 @@
                        nfilters = zend_hash_num_elements(Z_ARRVAL_PP(filter));
                        if (nfilters != nlinks) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"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;
+                               ret = 0;
+                               goto cleanup;
                        }
                        zend_hash_internal_pointer_reset(Z_ARRVAL_PP(filter));
                } else {
@@ -812,12 +799,8 @@
 
                        ld = (ldap_linkdata *) zend_fetch_resource(entry 
TSRMLS_CC, -1, "ldap link", NULL, 1, le_link);
                        if (ld == NULL) {
-                               efree(lds);
-                               efree(rcs);
-                               if (ldap_attrs != NULL) {
-                                       efree(ldap_attrs);
-                               }
-                               RETURN_FALSE;
+                               ret = 0;
+                               goto cleanup_parallel;
                        }
                        if (nbases != 0) { /* base_dn an array? */
                                
zend_hash_get_current_data(Z_ARRVAL_PP(base_dn), (void **)&entry);
@@ -845,10 +828,6 @@
                        zend_hash_move_forward(Z_ARRVAL_PP(link));
                }
                
-               if (ldap_attrs != NULL) {
-                       efree(ldap_attrs);
-               }
-               
                array_init(return_value);
 
                /* Collect results from the searches */
@@ -864,50 +843,61 @@
                                add_next_index_bool(return_value, 0);
                        }
                }
+
+cleanup_parallel:
                efree(lds);
                efree(rcs);
-               return;
-       }
+       } else {
+               convert_to_string_ex(filter);
+               ldap_filter = Z_STRVAL_PP(filter);
 
-       ld = (ldap_linkdata *) zend_fetch_resource(link TSRMLS_CC, -1, "ldap 
link", NULL, 1, le_link);
-       if (ld == NULL) {
-               if (ldap_attrs != NULL) {
-                       efree(ldap_attrs);
+               /* If anything else than string is passed, ldap_base_dn = NULL 
*/
+               if (Z_TYPE_PP(base_dn) == IS_STRING) {
+                       ldap_base_dn = Z_STRVAL_PP(base_dn);
                }
-               RETURN_FALSE;
-       }
 
-       php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref);
-
-       /* Run the actual search */     
-       errno = ldap_search_s(ld->link, ldap_base_dn, scope, ldap_filter, 
ldap_attrs, ldap_attrsonly, &ldap_res);
+               ld = (ldap_linkdata *) zend_fetch_resource(link TSRMLS_CC, -1, 
"ldap link", NULL, 1, le_link);
+               if (ld == NULL) {
+                       ret = 0;
+                       goto cleanup;
+               }
 
-       if (ldap_attrs != NULL) {
-               efree(ldap_attrs);
-       }
+               php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, 
ldap_deref);
 
-       if (errno != LDAP_SUCCESS
-               && errno != LDAP_SIZELIMIT_EXCEEDED
+               /* Run the actual search */     
+               errno = ldap_search_s(ld->link, ldap_base_dn, scope, 
ldap_filter, ldap_attrs, ldap_attrsonly, &ldap_res);
+       
+               if (errno != LDAP_SUCCESS
+                       && errno != LDAP_SIZELIMIT_EXCEEDED
 #ifdef LDAP_ADMINLIMIT_EXCEEDED
-               && errno != LDAP_ADMINLIMIT_EXCEEDED
+                       && errno != LDAP_ADMINLIMIT_EXCEEDED
 #endif
 #ifdef LDAP_REFERRAL
-               && errno != LDAP_REFERRAL
+                       && errno != LDAP_REFERRAL
 #endif
-       ) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Search: %s", 
ldap_err2string(errno));
-               RETVAL_FALSE; 
-       } else {
-               if (errno == LDAP_SIZELIMIT_EXCEEDED) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial 
search results returned: Sizelimit exceeded");
-               }
+               ) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Search: 
%s", ldap_err2string(errno));
+                       ret = 0;
+               } else {
+                       if (errno == LDAP_SIZELIMIT_EXCEEDED) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Partial search results returned: Sizelimit exceeded");
+                       }
 #ifdef LDAP_ADMINLIMIT_EXCEEDED
-               else if (errno == LDAP_ADMINLIMIT_EXCEEDED) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Partial 
search results returned: Adminlimit exceeded");
-               }
+                       else if (errno == LDAP_ADMINLIMIT_EXCEEDED) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Partial search results returned: Adminlimit exceeded");
+                       }
 #endif
-               
-               ZEND_REGISTER_RESOURCE(return_value, ldap_res, le_result);
+                       
+                       ZEND_REGISTER_RESOURCE(return_value, ldap_res, 
le_result);
+               }
+       }
+
+cleanup:
+       if (ldap_attrs != NULL) {
+               efree(ldap_attrs);
+       }
+       if (!ret) {
+               RETVAL_BOOL(ret);
        }
 }
 /* }}} */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to