[PATCH 3/5] wldap32: Implement ldap_get_paged_count.
Dmitry Timoshkov
dmitry at baikal.ru
Wed Apr 15 04:52:40 CDT 2020
Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
dlls/wldap32/page.c | 44 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/dlls/wldap32/page.c b/dlls/wldap32/page.c
index 79fdd7af16..f1244dca0d 100644
--- a/dlls/wldap32/page.c
+++ b/dlls/wldap32/page.c
@@ -39,6 +39,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
+static struct berval null_cookie = { 0, NULL };
+
/***********************************************************************
* ldap_create_page_controlA (WLDAP32.@)
*
@@ -77,7 +79,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 +183,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 || !count || !results) return WLDAP32_LDAP_PARAM_ERROR;
+
+ *count = 0;
- if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
- /* FIXME: save the cookie from the server here */
+ 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;
}
/***********************************************************************
@@ -271,7 +301,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 );
--
2.25.2
More information about the wine-devel
mailing list