Skip to content
Snippets Groups Projects
Commit b26ecba0 authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

- allow interactive pagedResults size change

- implement pagedResults abandon by setting size=0
- misc code cleanup
parent acab9b32
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
......
......@@ -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;
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment