]> git.sur5r.net Git - openldap/commitdiff
- allow interactive pagedResults size change
authorPierangelo Masarati <ando@openldap.org>
Thu, 21 Nov 2002 03:36:37 +0000 (03:36 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 21 Nov 2002 03:36:37 +0000 (03:36 +0000)
- implement pagedResults abandon by setting size=0
- misc code cleanup

clients/tools/ldapsearch.c
servers/slapd/back-bdb/search.c
servers/slapd/controls.c

index 241e9c8071d62fc38e4ea88fd54dd570a8b2a5f6..753a426bd603202cf214a4caa0360329620a9602 100644 (file)
@@ -181,7 +181,7 @@ static int  use_tls = 0;
 static char    *sortattr = NULL;
 static int     verbose, not, includeufn, vals2tmp, ldif;
 #ifdef LDAP_CONTROL_PAGEDRESULTS
-static int pageSize;
+static int pageSize = 0;
 static ber_int_t searchControlSize = 0;
 static ber_int_t morePagedResults = 1;
 static struct berval cookie = { 0, NULL };
@@ -222,7 +222,7 @@ main( int argc, char **argv )
 #ifdef LDAP_CONTROL_PAGEDRESULTS
        BerElement      *pageber = NULL;
        struct berval   *bvalptr = NULL;
-       int             num = 0, moreEntries, searchControlCrit = 0;
+       int             num = 0, searchControlCrit = 0;
 #endif /* LDAP_CONTROL_PAGEDRESULTS */
 
 
@@ -336,7 +336,7 @@ main( int argc, char **argv )
 #ifdef LDAP_CONTROL_PAGEDRESULTS
                } else if ( strcasecmp( control, "pr" ) == 0 ) {
                        /* PagedResults control */
-                       if ( searchControlSize !=0 ) {
+                       if ( pageSize != 0 ) {
                                fprintf( stderr, "PagedResultsControl previously specified" );
                                return EXIT_FAILURE;
                        }
@@ -1025,7 +1025,7 @@ main( int argc, char **argv )
 
 #ifdef LDAP_CONTROL_PAGEDRESULTS
 getNextPage:
-       if ( manageDSAit || noop || valuesReturnFilter || searchControlSize ) {
+       if ( manageDSAit || noop || valuesReturnFilter || pageSize ) {
                int critical = 0;
 #else /* !LDAP_CONTROL_PAGEDRESULTS */
        if ( manageDSAit || noop || valuesReturnFilter ) {
@@ -1119,7 +1119,7 @@ getNextPage:
                }
 
 #ifdef LDAP_CONTROL_PAGEDRESULTS
-               if ( searchControlSize ) {
+               if ( pageSize ) {
                        if (( pageber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
                                return EXIT_FAILURE;
                        }
@@ -1227,6 +1227,11 @@ getNextPage:
                        printf("\n# with valuesReturnFilter %scontrol: %s",
                                valuesReturnFilter > 1 ? "critical " : "", vrFilter );
                }
+               if ( pageSize ) {
+                       printf("\n# with pagedResults %scontrol: size=%d",
+                               searchControlCrit ? "critical " : "", 
+                               searchControlSize );
+               }
 
                printf( "\n#\n\n" );
        }
@@ -1254,16 +1259,35 @@ getNextPage:
        }
 
 #ifdef LDAP_CONTROL_PAGEDRESULTS
-       if ( ( searchControlSize != 0 ) && ( morePagedResults != 0 ) ) { 
+       if ( ( pageSize != 0 ) && ( morePagedResults != 0 ) ) { 
+               char    buf[6];
+               int     i, moreEntries, tmpSize;
+
                /* Loop to get the next pages when 
                 * enter is pressed on the terminal.
                 */
-               printf( "Press Enter for the next %d entries.\n",
+               printf( "Press [size] Enter for the next {%d|size} entries.\n",
                        (int)searchControlSize ); 
+               i = 0;
                moreEntries = getchar();
                while ( moreEntries != EOF && moreEntries != '\n' ) { 
+                       if ( i < sizeof(buf) - 1 ) {
+                               buf[i] = moreEntries;
+                               i++;
+                       }
                        moreEntries = getchar();
                }
+               buf[i] = '\0';
+
+               if ( i > 0 && isdigit( buf[0] ) ) {
+                       num = sscanf( buf, "%d", &tmpSize );
+                       if ( num != 1 ) {
+                               fprintf( stderr, "Invalid value for PagedResultsControl, %s.\n", buf);
+                               return EXIT_FAILURE;
+
+                       }
+                       searchControlSize = (ber_int_t)tmpSize;
+               }
 
                goto getNextPage;       
        }
@@ -1383,7 +1407,7 @@ static int dosearch(
                        case LDAP_RES_SEARCH_RESULT:
                                rc = print_result( ld, msg, 1 );
 #ifdef LDAP_CONTROL_PAGEDRESULTS
-                               if ( searchControlSize != 0 ) { 
+                               if ( pageSize != 0 ) { 
                                        rc = parse_page_control( ld, msg, &cookie );
                                }
 #endif /* LDAP_CONTROL_PAGEDRESULTS */
@@ -1401,7 +1425,7 @@ static int dosearch(
 
 done:
 #ifdef LDAP_CONTROL_PAGEDRESULTS
-       if ( searchControlSize == 0 ) { 
+       if ( pageSize == 0 ) { 
                if ( ldif < 2 ) {
                        printf( "\n# numResponses: %d\n", nresponses );
                        if( nentries ) printf( "# numEntries: %d\n", nentries );
index 3f87c6ec7b713a2028d7f3295f51f180f2d2e1b2..dddadbf45affaa82077e925695b80761fcfee89e 100644 (file)
@@ -358,6 +358,12 @@ dn2entry_retry:
                if ( op->o_pagedresults_state.ps_cookie == 0 ) {
                        id = 0;
                } else {
+                       if ( op->o_pagedresults_size == 0 ) {
+                               send_search_result( conn, op, LDAP_SUCCESS,
+                                       NULL, "search abandoned by pagedResult size=0",
+                                       NULL, NULL, 0);
+                               goto done;
+                       }
                        for ( id = bdb_idl_first( candidates, &cursor );
                                id != NOID && id <= (ID)( op->o_pagedresults_state.ps_cookie );
                                id = bdb_idl_next( candidates, &cursor ) );
@@ -1114,20 +1120,13 @@ send_pagerequest_response(
        respcookie = ( PagedResultsCookie )lastid;
        conn->c_pagedresults_state.ps_cookie = respcookie;
        cookie.bv_len = sizeof( respcookie );
-#if 0
-       cookie.bv_val = ber_memalloc( sizeof( respcookie ) );
-       AC_MEMCPY( cookie.bv_val, &respcookie, sizeof( respcookie ) );
-#else
        cookie.bv_val = (char *)&respcookie;
-#endif
-/*
-       conn->c_pagedresults_state.ps_cookie = cookie.bv_val;
-*/
 
+       /*
+        * FIXME: we should consider sending an estimate of the entries
+        * left, after appropriate security check is done
+        */
        ber_printf( ber, "{iO}", 0, &cookie ); 
-#if 0
-       ber_memfree( cookie.bv_val );
-#endif
 
        if ( ber_flatten( ber, &bvalp ) == LBER_ERROR ) {
                goto done;
index b8a2011112a7da97830faf069fd0e35f19862207..f32a4a41a01ea2be0ea2b74750a75a21f570c3e9 100644 (file)
@@ -518,7 +518,7 @@ static int parsePagedResults (
                return LDAP_PROTOCOL_ERROR;
        }
 
-       if( size <= 0 ) {
+       if( size < 0 ) {
                *text = "paged results control size invalid";
                return LDAP_PROTOCOL_ERROR;
        }