Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/wldap32/page.c | 46 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/dlls/wldap32/page.c b/dlls/wldap32/page.c index 2709e126ab..f2501e0498 100644 --- a/dlls/wldap32/page.c +++ b/dlls/wldap32/page.c @@ -39,6 +39,10 @@
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
+#ifdef HAVE_LDAP +static struct berval null_cookie = { 0, NULL }; +#endif + /*********************************************************************** * ldap_create_page_controlA (WLDAP32.@) * @@ -77,7 +81,7 @@ static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie, LDAPControlW *ctrl; BerElement *ber; ber_tag_t tag; - struct berval *berval, null_cookie = { 0, NULL }; + struct berval *berval; INT ret, len; char *val;
@@ -181,15 +185,43 @@ ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG CDECL ldap_get_paged_count( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG *count, WLDAP32_LDAPMessage *results ) { - ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; #ifdef HAVE_LDAP - FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results ); + ULONG ret; + LDAPControl **server_ctrls, *page_ctrl = NULL; + struct berval cookie; + + TRACE( "(%p, %p, %p, %p)\n", ld, search, count, results );
- if (!ld) return WLDAP32_LDAP_PARAM_ERROR; - /* FIXME: save the cookie from the server here */ + if (!ld || !count || !results) return WLDAP32_LDAP_PARAM_ERROR; + + *count = 0; + + server_ctrls = NULL; + ret = ldap_parse_result( ld->ld, results, NULL, NULL, NULL, NULL, &server_ctrls, 0 ); + if (ret != LDAP_SUCCESS) return map_error( ret ); + + if (server_ctrls) + page_ctrl = ldap_control_find( LDAP_CONTROL_PAGEDRESULTS, server_ctrls, NULL ); + + if (!page_ctrl) /* assume end of paged results */ + { + search->cookie = &null_cookie; + return WLDAP32_LDAP_SUCCESS; + } + + ret = ldap_parse_pageresponse_control( ld->ld, page_ctrl, (int *)count, &cookie ); + if (ret == LDAP_SUCCESS) + { + TRACE("new search->cookie: %s, count %u\n", debugstr_an(cookie.bv_val, cookie.bv_len), *count); + search->cookie = ber_bvdup( &cookie ); + } + + ldap_controls_free( server_ctrls ); + + return map_error( ret );
#endif - return ret; + return WLDAP32_LDAP_NOT_SUPPORTED; }
/*********************************************************************** @@ -272,7 +304,7 @@ ULONG CDECL ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search ) strarrayfreeU( search->attrs ); controlarrayfreeU( search->serverctrls ); controlarrayfreeU( search->clientctrls ); - if (search->cookie) + if (search->cookie && search->cookie != &null_cookie) ber_bvfree( search->cookie ); heap_free( search );