php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch php-trunk_ldap-pagination.patch for *General Issues Bug #42060Patch version 2010-11-04 20:47 UTC Return to Bug #42060 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions: 2010-11-04 20:47 UTC | 2010-11-03 21:50 UTC | 2010-05-21 15:27 UTCDeveloper: jeanseb@au-fil-du.netIndex: ext/ldap/ldap.c Index: ldap.c =================================================================== --- ext/ldap/ldap.c (révision 40035) +++ ext/ldap/ldap.c (révision 40105) --- ldap.c (révision 299434) +++ ldap.c (copie de travail) @@ -19,6 +19,10 @@ | Jani Taskinen <sniper@iki.fi> | | Stig Venaas <venaas@uninett.no> | | Doug Goldstein <cardoe@cardoe.com> | + | Rémy Saissy <remy.saissy@gmail.com> | | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ @@ -2047,6 +2051,192 @@ } @@ -2185,6 +2189,193 @@ /* }}} */ #endif + +#ifdef LDAP_CONTROL_PAGEDRESULTS +/* {{{ proto bool ldap_control_paged_results(resource link, int pagesize [, bool iscritical [, string cookie]]) + Inject paged results control*/ +PHP_FUNCTION(ldap_control_paged_results) +{ + long pagesize; + zend_bool iscritical; + zval *link, *cookie; + zval *link; + struct berval lcookie = { 0, NULL }; + ldap_linkdata *ld; + LDAP *ldap; + BerElement *ber = NULL; + LDAPControl ctrl, *ctrlsp[2]; + int rc, myargcount = ZEND_NUM_ARGS(); + char *cookie = NULL; + int cookielen; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|bz", &link, &pagesize, &iscritical, &cookie) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|bz", &link, &pagesize, &iscritical, &cookie,) != SUCCESS) { + return; + } + + if (Z_TYPE_PP(&link) == IS_NULL) { Line 47 (now 48), was 37 lines, now 36 lines + ber = ber_alloc_t(LBER_USE_DER); + if (ber == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to alloc BER encoding resources for paged results control"); + RETURN_FALSE; + } + + ctrl.ldctl_iscritical = 0; + } + + ctrl.ldctl_iscritical = 0; + + switch (myargcount) { + case 4: + convert_to_string_ex(&cookie); + lcookie.bv_val = Z_STRVAL_PP(&cookie); + lcookie.bv_len = Z_STRLEN_PP(&cookie); + lcookie.bv_val = cookie; + lcookie.bv_len = cookielen; + /* fallthru */ + case 3: + ctrl.ldctl_iscritical = (int)iscritical; + /* fallthru */ + } + + if (ber_printf(ber, "{iO}", (int)pagesize, &lcookie) == LBER_ERROR) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to BER printf paged results control"); + RETVAL_BOOL(0); + goto lcpr_error_out; + } + RETVAL_BOOL(0); + goto lcpr_error_out; + } + rc = ber_flatten2(ber, &ctrl.ldctl_value, 0); + if (rc == LBER_ERROR) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to BER encode paged results control"); + RETVAL_BOOL(0); + goto lcpr_error_out; + } + + ctrl.ldctl_oid = LDAP_CONTROL_PAGEDRESULTS; + + } + + ctrl.ldctl_oid = LDAP_CONTROL_PAGEDRESULTS; + + if (ldap) { + /* directly set the option */ + ctrlsp[0] = &ctrl; + ctrlsp[1] = NULL; Line 202 (now 202), was 63 lines, now 53 lines + RETURN_TRUE; +} +/* }}} */ +#endif #endif /* (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 */ #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) @@ -2414,6 +2604,21 @@ ZEND_ARG_INFO(1, referrals) ZEND_END_ARG_INFO() #endif + /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0) ZEND_ARG_INFO(0, hostname) @@ -2364,6 +2555,22 @@ ZEND_ARG_INFO(0, sortfilter) ZEND_END_ARG_INFO() +#ifdef LDAP_CONTROL_PAGEDRESULTS +ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_control_paged_results, 0, 0, 2) + ZEND_ARG_INFO(0, link) + ZEND_ARG_INFO(0, pagesize) + ZEND_ARG_INFO(0, iscritical) + ZEND_ARG_INFO(0, cookie) +ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_control_paged_results_response, 0, 0, 2) + ZEND_ARG_INFO(0, link) + ZEND_ARG_INFO(0, result) + ZEND_ARG_INFO(1, cookie) + ZEND_ARG_INFO(1, estimated) +ZEND_END_ARG_INFO(); + #endif #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) @@ -2489,14 +2694,22 @@ #ifdef HAVE_LDAP_PARSE_REFERENCE PHP_FE(ldap_parse_reference, arginfo_ldap_parse_reference) #endif + #ifdef HAVE_LDAP_PARSE_RESULT PHP_FE(ldap_parse_result, arginfo_ldap_parse_result) #endif + #ifdef HAVE_LDAP_START_TLS_S PHP_FE(ldap_start_tls, arginfo_ldap_resource) #endif + +#ifdef LDAP_CONTROL_PAGEDRESULTS + PHP_FE(ldap_control_paged_results, arginfo_ldap_control_paged_results) + PHP_FE(ldap_control_paged_results_response, arginfo_ldap_control_paged_results_response) +#endif + #if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP_10 ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_rename, 0, 0, 5) ZEND_ARG_INFO(0, link_identifier) @@ -2506,6 +2713,10 @@ PHP_FE(ldap_8859_to_t61, arginfo_ldap_8859_to_t61) #endif +#ifdef LDAP_CONTROL_PAGEDRESULTS + PHP_FE(ldap_control_paged_results, arginfo_ldap_control_paged_results) + PHP_FE(ldap_control_paged_results_response, arginfo_ldap_control_paged_results_response) +#endif + #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) PHP_FE(ldap_set_rebind_proc, arginfo_ldap_set_rebind_proc) #endif Index: ext/ldap/tests/ldap_control_paged_results_variation1.phpt =================================================================== --- ext/ldap/tests/ldap_control_paged_results_variation1.phpt (révision 0) +++ ext/ldap/tests/ldap_control_paged_results_variation1.phpt (révision 40105) @@ -0,0 +1,56 @@ +--TEST-- +ldap_ldap_control_paged_results() test (fetching the first page) {NULL, NULL, NULL} }; /* }}} */ Index: tests/ldap_control_paged_results_variation2.phpt =================================================================== --- tests/ldap_control_paged_results_variation2.phpt (révision 0) +++ tests/ldap_control_paged_results_variation2.phpt (révision 0) @@ -0,0 +1,72 @@ +--TEST-- +ldap_ldap_control_paged_results() test (fetching the first page with a pagesize=2) +--CREDITS-- +Jean-Sebastien Hedde <jeanseb@au-fil-du.net> +--SKIPIF-- +<?php Line 266 (now 256), was 73 lines, now 12 lines +require_once('skipifbindfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +insert_dummy_data($link); + +$dn = "dc=my-domain,dc=com"; +$filter = "(cn=*)"; +var_dump( + ldap_control_paged_results($link, 1), + $result = ldap_search($link, $dn, $filter, array('cn')), + ldap_get_entries($link, $result) +); +?> +===DONE=== +--CLEAN-- +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +remove_dummy_data($link); +?> +--EXPECTF-- +bool(true) +resource(6) of type (ldap result) +array(2) { + ["count"]=> + int(1) + [0]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userA" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userA,dc=my-domain,dc=com" + } +} +===DONE=== Index: ext/ldap/tests/ldap_control_paged_results_variation2.phpt =================================================================== --- ext/ldap/tests/ldap_control_paged_results_variation2.phpt (révision 0) +++ ext/ldap/tests/ldap_control_paged_results_variation2.phpt (révision 40105) @@ -0,0 +1,72 @@ +--TEST-- +ldap_ldap_control_paged_results() test (fetching the first page with a pagesize=2) +--CREDITS-- +Jean-Sebastien Hedde <jeanseb@au-fil-du.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifbindfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +insert_dummy_data($link); +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +insert_dummy_data($link); + +$dn = "dc=my-domain,dc=com"; +$filter = "(cn=*)"; +var_dump( +?> +--EXPECTF-- +bool(true) +resource(6) of type (ldap result) +array(3) { + ["count"]=> + int(2) + [0]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userA" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userA,dc=my-domain,dc=com" + } + [1]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userB" + } + [0]=> + string(2) "cn" + ["count"]=> +array(3) { + ["count"]=> + int(2) + [0]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userA" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userA,dc=my-domain,dc=com" + } + [1]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userB" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userB,dc=my-domain,dc=com" + } +} +===DONE=== Index: ext/ldap/tests/ldap_control_paged_results_variation3.phpt Index: tests/ldap_control_paged_results_variation3.phpt =================================================================== --- ext/ldap/tests/ldap_control_paged_results_variation3.phpt (révision 0) +++ ext/ldap/tests/ldap_control_paged_results_variation3.phpt (révision 40105) --- tests/ldap_control_paged_results_variation3.phpt (révision 0) +++ tests/ldap_control_paged_results_variation3.phpt (révision 0) @@ -0,0 +1,100 @@ +--TEST-- +ldap_ldap_control_paged_results() test (fetching the first page then the next final page) +--CREDITS-- +Jean-Sebastien Hedde <jeanseb@au-fil-du.net> +--SKIPIF-- +<?php +<?php +require_once('skipif.inc'); +require_once('skipifbindfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +insert_dummy_data($link); + +$dn = "dc=my-domain,dc=com"; +resource(%d) of type (ldap result) +array(3) { + ["count"]=> + int(2) + [0]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + [0]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userA" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userA,dc=my-domain,dc=com" + } + [1]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userB" + } + [0]=> + string(2) "cn" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userB,dc=my-domain,dc=com" + } +} +bool(true) + } +} +bool(true) +bool(true) +resource(%d) of type (ldap result) +array(2) { + ["count"]=> + ["count"]=> + int(1) + ["dn"]=> + string(37) "cn=userC,cn=userB,dc=my-domain,dc=com" + } +} +===DONE=== Index: tests/ldap_control_paged_results_variation1.phpt =================================================================== --- tests/ldap_control_paged_results_variation1.phpt (révision 0) +++ tests/ldap_control_paged_results_variation1.phpt (révision 0) @@ -0,0 +1,56 @@ +--TEST-- +ldap_ldap_control_paged_results() test (fetching the first page) +--CREDITS-- +Jean-Sebastien Hedde <jeanseb@au-fil-du.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifbindfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +insert_dummy_data($link); + +$dn = "dc=my-domain,dc=com"; +$filter = "(cn=*)"; +var_dump( + ldap_control_paged_results($link, 1), + $result = ldap_search($link, $dn, $filter, array('cn')), + ldap_get_entries($link, $result) +); +?> +===DONE=== +--CLEAN-- +<?php +include "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); +remove_dummy_data($link); +?> +--EXPECTF-- +bool(true) +resource(6) of type (ldap result) +array(2) { + ["count"]=> + int(1) + [0]=> + array(4) { + ["cn"]=> + array(2) { + ["count"]=> + int(1) + [0]=> + string(5) "userA" + } + [0]=> + string(2) "cn" + ["count"]=> + int(1) + ["dn"]=> + string(28) "cn=userA,dc=my-domain,dc=com" + } +} +===DONE=== |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Tue Mar 19 12:01:31 2024 UTC |