mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-04-18 15:20:35 +08:00
add limits to entries count for paged results
This commit is contained in:
parent
2b639068b6
commit
415a8d325f
@ -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 };
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user