From: Pierangelo Masarati Date: Thu, 21 Nov 2002 20:49:02 +0000 (+0000) Subject: add limits to entries count for paged results X-Git-Tag: NO_SLAP_OP_BLOCKS~783 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=415a8d325f5249aaeb8be0b8e7c9433f3936eca4;p=openldap add limits to entries count for paged results --- diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 753a426bd6..9c9a8224a3 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -183,6 +183,7 @@ static int verbose, not, includeufn, vals2tmp, ldif; #ifdef LDAP_CONTROL_PAGEDRESULTS static int pageSize = 0; static ber_int_t searchControlSize = 0; +static ber_int_t entriesLeft = 0; static ber_int_t morePagedResults = 1; static struct berval cookie = { 0, NULL }; static int npagedresponses; @@ -1266,6 +1267,9 @@ getNextPage: /* Loop to get the next pages when * enter is pressed on the terminal. */ + if ( entriesLeft > 0 ) { + printf( "Estimate entries: %d\n", entriesLeft ); + } printf( "Press [size] Enter for the next {%d|size} entries.\n", (int)searchControlSize ); i = 0; @@ -1948,7 +1952,6 @@ parse_page_control( LDAPControl *ctrlp = NULL; BerElement *ber; ber_tag_t tag; - ber_int_t entriesLeft; struct berval servercookie = { 0, NULL }; diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 3083981d2b..7964b98ee4 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -31,7 +31,8 @@ static void send_pagerequest_response( Connection *conn, Operation *op, ID lastid, - int nentries ); + int nentries, + int tentries ); #endif /* LDAP_CONTROL_PAGEDRESULTS */ int @@ -64,6 +65,7 @@ bdb_search( int manageDSAit; #ifdef LDAP_CONTROL_PAGEDRESULTS int pagedresults; + int tentries = 0; ID lastid = NOID; #endif /* LDAP_CONTROL_PAGEDRESULTS */ @@ -281,7 +283,15 @@ dn2entry_retry: /* if no limit is required, use soft limit */ if ( slimit <= 0 ) { - slimit = limit->lms_s_soft; +#ifdef LDAP_CONTROL_PAGEDRESULTS + if ( pagedresults && limit->lms_s_pr != 0 ) { + slimit = limit->lms_s_pr; + } else { +#endif /* LDAP_CONTROL_PAGEDRESULTS */ + slimit = limit->lms_s_soft; +#ifdef LDAP_CONTROL_PAGEDRESULTS + } +#endif /* LDAP_CONTROL_PAGEDRESULTS */ /* if requested limit higher than hard limit, abort */ } else if ( slimit > limit->lms_s_hard ) { @@ -357,6 +367,12 @@ dn2entry_retry: } } +#ifdef LDAP_CONTROL_PAGEDRESULTS + if ( isroot || !limit->lms_s_pr_hide ) { + tentries = BDB_IDL_N(candidates); + } +#endif /* LDAP_CONTROL_PAGEDRESULTS */ + #ifdef LDAP_CONTROL_PAGEDRESULTS if ( pagedresults ) { if ( op->o_pagedresults_state.ps_cookie == 0 ) { @@ -382,7 +398,7 @@ dn2entry_retry: "bdb_search: no paged results candidates\n", 0, 0, 0 ); #endif - send_pagerequest_response( conn, op, lastid, 0 ); + send_pagerequest_response( conn, op, lastid, 0, 0 ); rc = 1; goto done; @@ -634,7 +650,7 @@ id2entry_retry: #ifdef LDAP_CONTROL_PAGEDRESULTS if ( pagedresults ) { if ( nentries >= op->o_pagedresults_size ) { - send_pagerequest_response( conn, op, lastid, nentries ); + send_pagerequest_response( conn, op, lastid, nentries, tentries ); goto done; } lastid = id; @@ -1096,7 +1112,8 @@ send_pagerequest_response( Connection *conn, Operation *op, ID lastid, - int nentries ) + int nentries, + int tentries ) { LDAPControl ctrl, *ctrls[2]; BerElement *ber; @@ -1130,7 +1147,7 @@ send_pagerequest_response( * FIXME: we should consider sending an estimate of the entries * left, after appropriate security check is done */ - ber_printf( ber, "{iO}", 0, &cookie ); + ber_printf( ber, "{iO}", tentries, &cookie ); if ( ber_flatten( ber, &bvalp ) == LBER_ERROR ) { goto done; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 37d3f2d1cc..bd777a81c4 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -31,6 +31,11 @@ struct slap_limits_set deflimit = { SLAPD_DEFAULT_SIZELIMIT, /* backward compatible limits */ 0, -1 /* no limit on unchecked size */ +#ifdef LDAP_CONTROL_PAGEDRESULTS + , + 0, /* page limit */ + 0 /* hide number of entries left */ +#endif /* LDAP_CONTROL_PAGEDRESULTS */ }; AccessControl *global_acl = NULL; diff --git a/servers/slapd/limits.c b/servers/slapd/limits.c index 52e6910407..ec7b2e1506 100644 --- a/servers/slapd/limits.c +++ b/servers/slapd/limits.c @@ -562,6 +562,26 @@ parse_limit( return( 1 ); } } + +#ifdef LDAP_CONTROL_PAGEDRESULTS + } else if ( strncasecmp( arg, "pr", sizeof( "pr" ) - 1 ) == 0 ) { + arg += sizeof( "pr" ) - 1; + if ( arg[0] != '=' ) { + return( 1 ); + } + arg++; + if ( strcasecmp( arg, "noEntriesLeft" ) == 0 ) { + limit->lms_s_pr_hide = 1; + } else { + char *next = NULL; + + limit->lms_s_pr = + strtol( arg, &next, 10 ); + if ( next == arg || limit->lms_s_pr < -1 ) { + return( 1 ); + } + } +#endif /* LDAP_CONTROL_PAGEDRESULTS */ } else { return( 1 ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 4510edfa3b..e81a0289fd 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1154,6 +1154,10 @@ struct slap_limits_set { int lms_s_soft; int lms_s_hard; int lms_s_unchecked; +#ifdef LDAP_CONTROL_PAGEDRESULTS + int lms_s_pr; + int lms_s_pr_hide; +#endif /* LDAP_CONTROL_PAGEDRESULTS */ }; struct slap_limits {