]> git.sur5r.net Git - openldap/commitdiff
add limits to entries count for paged results
authorPierangelo Masarati <ando@openldap.org>
Thu, 21 Nov 2002 20:49:02 +0000 (20:49 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 21 Nov 2002 20:49:02 +0000 (20:49 +0000)
clients/tools/ldapsearch.c
servers/slapd/back-bdb/search.c
servers/slapd/config.c
servers/slapd/limits.c
servers/slapd/slap.h

index 753a426bd603202cf214a4caa0360329620a9602..9c9a8224a3a4e06f22db1cb66d37463f7dda8bc9 100644 (file)
@@ -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 };
 
 
index 3083981d2bdc75c4a471b28c0e2724fe795fcda1..7964b98ee4f4863613e5b5ce836d55c934a9ced7 100644 (file)
@@ -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;
index 37d3f2d1cc116c76d6bf3d327691b068d0359a14..bd777a81c40496fac43366da4849fbacb7807708 100644 (file)
@@ -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;
index 52e69104077742fe23e7b302b1b256fe977b71d5..ec7b2e150689f659411d467b7ba867f401ce35c2 100644 (file)
@@ -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 );
index 4510edfa3b0754a64a3329706823786f9f94074e..e81a0289fd28963d9bf599ea91b172637a26d538 100644 (file)
@@ -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 {