ITS#6056 pagedresults stacked control is not overlay-friendly, add

slap_add_ctrls() function
This commit is contained in:
Howard Chu 2009-04-15 10:34:24 +00:00
parent 9e7b5d8f19
commit cfb12f536b
4 changed files with 42 additions and 26 deletions

View File

@ -1274,7 +1274,7 @@ send_paged_response(
ID *lastid,
int tentries )
{
LDAPControl ctrl, *ctrls[2];
LDAPControl *ctrls[2];
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
PagedResultsCookie respcookie;
@ -1284,8 +1284,6 @@ send_paged_response(
"send_paged_response: lastid=0x%08lx nentries=%d\n",
lastid ? *lastid : 0, rs->sr_nentries, NULL );
BER_BVZERO( &ctrl.ldctl_value );
ctrls[0] = &ctrl;
ctrls[1] = NULL;
ber_init2( ber, NULL, LBER_USE_DER );
@ -1308,6 +1306,7 @@ send_paged_response(
/* return size of 0 -- no estimate */
ber_printf( ber, "{iO}", 0, &cookie );
ctrls[0] = op->o_tmpalloc( sizeof(LDAPControl), op->o_tmpmemctx );
if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
goto done;
}
@ -1315,10 +1314,9 @@ send_paged_response(
ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
ctrls[0]->ldctl_iscritical = 0;
rs->sr_ctrls = ctrls;
slap_add_ctrls( op, rs, ctrls );
rs->sr_err = LDAP_SUCCESS;
send_ldap_result( op, rs );
rs->sr_ctrls = NULL;
done:
(void) ber_free_buf( ber );

View File

@ -539,6 +539,37 @@ void slap_free_ctrls(
op->o_tmpfree( ctrls, op->o_tmpmemctx );
}
int slap_add_ctrls(
Operation *op,
SlapReply *rs,
LDAPControl **ctrls )
{
int i = 0, j;
LDAPControl **ctrlsp;
if ( rs->sr_ctrls ) {
for ( ; rs->sr_ctrls[ i ]; i++ ) ;
}
for ( j=0; ctrls[j]; j++ ) ;
ctrlsp = op->o_tmpalloc(( i+j+1 )*sizeof(LDAPControl *), op->o_tmpmemctx );
i = 0;
if ( rs->sr_ctrls ) {
for ( ; rs->sr_ctrls[i]; i++ )
ctrlsp[i] = rs->sr_ctrls[i];
}
for ( j=0; ctrls[j]; j++)
ctrlsp[i++] = ctrls[j];
ctrlsp[i] = NULL;
if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED )
op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
rs->sr_ctrls = ctrlsp;
rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
return i;
}
int slap_parse_ctrl(
Operation *op,
SlapReply *rs,

View File

@ -290,7 +290,7 @@ deref_response( Operation *op, SlapReply *rs )
struct berval bv = BER_BVNULL;
int nDerefRes = 0, nDerefVals = 0, nAttrs = 0, nVals = 0;
struct berval ctrlval;
LDAPControl *ctrl, **ctrlsp;
LDAPControl *ctrl, *ctrlsp[2];
AccessControlState acl_state = ACL_STATE_INIT;
static char dummy = '\0';
Entry *ebase;
@ -471,26 +471,9 @@ deref_response( Operation *op, SlapReply *rs )
ber_free_buf( ber );
i = 0;
if ( rs->sr_ctrls ) {
for ( ; rs->sr_ctrls[ i ] != NULL; i++ )
/* count'em */ ;
}
i += 2;
ctrlsp = op->o_tmpcalloc( i, sizeof(LDAPControl *), op->o_tmpmemctx );
i = 0;
if ( rs->sr_ctrls != NULL ) {
for ( ; rs->sr_ctrls[ i ] != NULL; i++ ) {
ctrlsp[ i ] = rs->sr_ctrls[ i ];
}
}
ctrlsp[ i++ ] = ctrl;
ctrlsp[ i++ ] = NULL;
if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) {
op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
}
rs->sr_ctrls = ctrlsp;
rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
ctrlsp[0] = ctrl;
ctrlsp[1] = NULL;
slap_add_ctrls( op, rs, ctrlsp );
rc = SLAP_CB_CONTINUE;

View File

@ -623,6 +623,10 @@ LDAP_SLAPD_V( struct slap_control_ids ) slap_cids;
LDAP_SLAPD_F (void) slap_free_ctrls LDAP_P((
Operation *op,
LDAPControl **ctrls ));
LDAP_SLAPD_F (int) slap_add_ctrls LDAP_P((
Operation *op,
SlapReply *rs,
LDAPControl **ctrls ));
LDAP_SLAPD_F (int) slap_parse_ctrl LDAP_P((
Operation *op,
SlapReply *rs,