"optimize" sets: since the attr part must be an attribute, use the AttributeDescription

This commit is contained in:
Pierangelo Masarati 2004-10-08 00:28:16 +00:00
parent 559cf8bfb1
commit 2f6f6f6a07
3 changed files with 70 additions and 112 deletions

View file

@ -1844,7 +1844,7 @@ aci_set_cb_gather( Operation *op, SlapReply *rs )
} }
BerVarray BerVarray
aci_set_gather( SetCookie *cookie, struct berval *name, struct berval *attr ) aci_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
{ {
AciSetCookie *cp = (AciSetCookie *)cookie; AciSetCookie *cp = (AciSetCookie *)cookie;
int rc = 0; int rc = 0;
@ -1863,7 +1863,7 @@ aci_set_gather( SetCookie *cookie, struct berval *name, struct berval *attr )
* also return the syntax or some "comparison cookie". * also return the syntax or some "comparison cookie".
*/ */
if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) { if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
return aci_set_gather2( cookie, name, attr ); return aci_set_gather2( cookie, name, desc );
} }
rc = ldap_url_parse( name->bv_val, &ludp ); rc = ldap_url_parse( name->bv_val, &ludp );
@ -1935,13 +1935,8 @@ aci_set_gather( SetCookie *cookie, struct berval *name, struct berval *attr )
anlistp = anlist; anlistp = anlist;
} }
anlistp[ nattrs ].an_name = *attr; anlistp[ nattrs ].an_name = desc->ad_cname;
anlistp[ nattrs ].an_desc = NULL; anlistp[ nattrs ].an_desc = desc;
rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
&anlistp[ nattrs ].an_desc, &text );
if ( rc != LDAP_SUCCESS ) {
goto url_done;
}
BER_BVZERO( &anlistp[ nattrs + 1 ].an_name ); BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
@ -1997,7 +1992,7 @@ url_done:;
} }
BerVarray BerVarray
aci_set_gather2( SetCookie *cookie, struct berval *name, struct berval *attr ) aci_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
{ {
AciSetCookie *cp = (AciSetCookie *)cookie; AciSetCookie *cp = (AciSetCookie *)cookie;
BerVarray bvals = NULL; BerVarray bvals = NULL;
@ -2010,10 +2005,6 @@ aci_set_gather2( SetCookie *cookie, struct berval *name, struct berval *attr )
*/ */
rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx ); rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
if ( rc == LDAP_SUCCESS ) { if ( rc == LDAP_SUCCESS ) {
const char *text;
AttributeDescription *desc = NULL;
if ( slap_bv2ad( attr, &desc, &text ) == LDAP_SUCCESS ) {
if ( desc == slap_schema.si_ad_entryDN ) { if ( desc == slap_schema.si_ad_entryDN ) {
bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2, bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
cp->op->o_tmpmemctx ); cp->op->o_tmpmemctx );
@ -2025,14 +2016,13 @@ aci_set_gather2( SetCookie *cookie, struct berval *name, struct berval *attr )
backend_attribute( cp->op, backend_attribute( cp->op,
cp->e, &ndn, desc, &bvals, ACL_NONE ); cp->e, &ndn, desc, &bvals, ACL_NONE );
} }
}
if ( !BER_BVISNULL( &ndn ) ) { if ( !BER_BVISNULL( &ndn ) ) {
slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx ); slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
} }
} }
return( bvals ); return bvals;
} }
static int static int

View file

@ -21,25 +21,25 @@
#include "slap.h" #include "slap.h"
#include "sets.h" #include "sets.h"
static BerVarray set_chase (SLAP_SET_GATHER gatherer, static BerVarray set_chase( SLAP_SET_GATHER gatherer,
SetCookie *cookie, BerVarray set, struct berval *attr, int closure); SetCookie *cookie, BerVarray set, AttributeDescription *desc, int closure );
static int set_samedn (char *dn1, char *dn2);
long static long
slap_set_size (BerVarray set) slap_set_size( BerVarray set )
{ {
long i; long i;
i = 0; i = 0;
if (set != NULL) { if ( set != NULL ) {
while (set[i].bv_val) while ( !BER_BVISNULL( &set[i] ) ) {
i++; i++;
} }
}
return i; return i;
} }
void static void
slap_set_dispose (SetCookie *cp, BerVarray set) slap_set_dispose( SetCookie *cp, BerVarray set )
{ {
ber_bvarray_free_x(set, cp->op->o_tmpmemctx); ber_bvarray_free_x(set, cp->op->o_tmpmemctx);
} }
@ -80,7 +80,8 @@ slap_set_join (SetCookie *cp, BerVarray lset, int op, BerVarray rset)
cp->op->o_tmpfree(lset, cp->op->o_tmpmemctx); cp->op->o_tmpfree(lset, cp->op->o_tmpmemctx);
for (i = 0; rset[i].bv_val; i++) { for (i = 0; rset[i].bv_val; i++) {
for (j = 0; set[j].bv_val; j++) { for (j = 0; set[j].bv_val; j++) {
if (set_samedn(rset[i].bv_val, set[j].bv_val)) { if ( dn_match( &rset[i], &set[j] ) )
{
cp->op->o_tmpfree(rset[i].bv_val, cp->op->o_tmpmemctx); cp->op->o_tmpfree(rset[i].bv_val, cp->op->o_tmpmemctx);
rset[i].bv_val = NULL; rset[i].bv_val = NULL;
break; break;
@ -103,9 +104,10 @@ slap_set_join (SetCookie *cp, BerVarray lset, int op, BerVarray rset)
last = slap_set_size(set) - 1; last = slap_set_size(set) - 1;
for (i = 0; set[i].bv_val; i++) { for (i = 0; set[i].bv_val; i++) {
for (j = 0; rset[j].bv_val; j++) { for (j = 0; rset[j].bv_val; j++) {
if (set_samedn(set[i].bv_val, rset[j].bv_val)) if ( dn_match( &set[i], &rset[j] ) ) {
break; break;
} }
}
if (rset[j].bv_val == NULL) { if (rset[j].bv_val == NULL) {
cp->op->o_tmpfree(set[i].bv_val, cp->op->o_tmpmemctx); cp->op->o_tmpfree(set[i].bv_val, cp->op->o_tmpmemctx);
set[i] = set[last]; set[i] = set[last];
@ -123,90 +125,51 @@ slap_set_join (SetCookie *cp, BerVarray lset, int op, BerVarray rset)
} }
static BerVarray static BerVarray
set_chase (SLAP_SET_GATHER gatherer, set_chase( SLAP_SET_GATHER gatherer,
SetCookie *cp, BerVarray set, struct berval *attr, int closure) SetCookie *cp, BerVarray set, AttributeDescription *desc, int closure )
{ {
BerVarray vals, nset; BerVarray vals, nset;
char attrstr[32];
struct berval bv;
int i; int i;
bv.bv_len = attr->bv_len;
bv.bv_val = attrstr;
if (set == NULL) if (set == NULL)
return(cp->op->o_tmpcalloc(1, sizeof(struct berval), cp->op->o_tmpmemctx)); return cp->op->o_tmpcalloc( 1, sizeof(struct berval),
cp->op->o_tmpmemctx );
if (set->bv_val == NULL) if ( BER_BVISNULL( set ) )
return(set); return set;
if (attr->bv_len > (sizeof(attrstr) - 1)) { nset = cp->op->o_tmpcalloc( 1, sizeof(struct berval), cp->op->o_tmpmemctx );
slap_set_dispose(cp, set); if ( nset == NULL ) {
return(NULL); slap_set_dispose( cp, set );
return NULL;
} }
AC_MEMCPY(attrstr, attr->bv_val, attr->bv_len); for ( i = 0; !BER_BVISNULL( &set[i] ); i++ ) {
attrstr[attr->bv_len] = 0; vals = (gatherer)( cp, &set[i], desc );
if ( vals != NULL ) {
nset = cp->op->o_tmpcalloc(1, sizeof(struct berval), cp->op->o_tmpmemctx); nset = slap_set_join( cp, nset, '|', vals );
if (nset == NULL) {
slap_set_dispose(cp, set);
return(NULL);
} }
for (i = 0; set[i].bv_val; i++) {
vals = (gatherer)(cp, &set[i], &bv);
if (vals != NULL)
nset = slap_set_join(cp, nset, '|', vals);
} }
slap_set_dispose(cp, set); slap_set_dispose( cp, set );
if (closure) { if ( closure ) {
for (i = 0; nset[i].bv_val; i++) { for ( i = 0; !BER_BVISNULL( &nset[i] ); i++ ) {
vals = (gatherer)(cp, &nset[i], &bv); vals = (gatherer)( cp, &nset[i], desc );
if (vals != NULL) { if ( vals != NULL ) {
nset = slap_set_join(cp, nset, '|', vals); nset = slap_set_join( cp, nset, '|', vals );
if (nset == NULL) if ( nset == NULL ) {
break; break;
} }
} }
} }
return(nset);
}
static int
set_samedn (char *dn1, char *dn2)
{
char c1, c2;
while (*dn1 == ' ') dn1++;
while (*dn2 == ' ') dn2++;
while (*dn1 || *dn2) {
if (*dn1 != '=' && *dn1 != ','
&& *dn2 != '=' && *dn2 != ',')
{
c1 = *dn1++;
c2 = *dn2++;
if (c1 >= 'a' && c1 <= 'z')
c1 -= 'a' - 'A';
if (c2 >= 'a' && c2 <= 'z')
c2 -= 'a' - 'A';
if (c1 != c2)
return(0);
} else {
while (*dn1 == ' ') dn1++;
while (*dn2 == ' ') dn2++;
if (*dn1++ != *dn2++)
return(0);
while (*dn1 == ' ') dn1++;
while (*dn2 == ' ') dn2++;
} }
}
return(1); return nset;
} }
int int
slap_set_filter (SLAP_SET_GATHER gatherer, slap_set_filter( SLAP_SET_GATHER gatherer,
SetCookie *cp, struct berval *fbv, SetCookie *cp, struct berval *fbv,
struct berval *user, struct berval *this, BerVarray *results) struct berval *user, struct berval *target, BerVarray *results )
{ {
#define IS_SET(x) ( (unsigned long)(x) >= 256 ) #define IS_SET(x) ( (unsigned long)(x) >= 256 )
#define IS_OP(x) ( (unsigned long)(x) < 256 ) #define IS_OP(x) ( (unsigned long)(x) < 256 )
@ -341,7 +304,7 @@ slap_set_filter (SLAP_SET_GATHER gatherer,
set = cp->op->o_tmpcalloc(2, sizeof(struct berval), cp->op->o_tmpmemctx); set = cp->op->o_tmpcalloc(2, sizeof(struct berval), cp->op->o_tmpmemctx);
if (set == NULL) if (set == NULL)
SF_ERROR(memory); SF_ERROR(memory);
ber_dupbv_x( set, this, cp->op->o_tmpmemctx ); ber_dupbv_x( set, target, cp->op->o_tmpmemctx );
if (set->bv_val == NULL) if (set->bv_val == NULL)
SF_ERROR(memory); SF_ERROR(memory);
} else if (len == 4 } else if (len == 4
@ -359,11 +322,19 @@ slap_set_filter (SLAP_SET_GATHER gatherer,
SF_ERROR(syntax); SF_ERROR(syntax);
} else { } else {
struct berval fb2; struct berval fb2;
AttributeDescription *ad = NULL;
const char *text = NULL;
SF_POP(); SF_POP();
fb2.bv_val = filter; fb2.bv_val = filter;
fb2.bv_len = len; fb2.bv_len = len;
if ( slap_bv2ad( &fb2, &ad, &text ) != LDAP_SUCCESS ) {
SF_ERROR(syntax);
}
set = set_chase( gatherer, set = set_chase( gatherer,
cp, SF_POP(), &fb2, c == '*' ); cp, SF_POP(), ad, c == '*' );
if (set == NULL) if (set == NULL)
SF_ERROR(memory); SF_ERROR(memory);
if (c == '*') if (c == '*')

View file

@ -29,19 +29,16 @@ typedef struct slap_set_cookie {
* also return the syntax or some "comparison cookie" * also return the syntax or some "comparison cookie"
* that is used by set_filter. * that is used by set_filter.
*/ */
typedef BerVarray (SLAP_SET_GATHER)( typedef BerVarray (SLAP_SET_GATHER)( SetCookie *cookie,
SetCookie *cookie, struct berval *name, struct berval *attr); struct berval *name, AttributeDescription *ad);
LDAP_SLAPD_F (long) slap_set_size(BerVarray set);
LDAP_SLAPD_F (void) slap_set_dispose(SetCookie *cookie, BerVarray set);
LDAP_SLAPD_F (int) slap_set_filter( LDAP_SLAPD_F (int) slap_set_filter(
SLAP_SET_GATHER gatherer, SLAP_SET_GATHER gatherer,
SetCookie *cookie, struct berval *filter, SetCookie *cookie, struct berval *filter,
struct berval *user, struct berval *this, BerVarray *results); struct berval *user, struct berval *target, BerVarray *results);
LDAP_SLAPD_F (BerVarray) slap_set_join(SetCookie *cp, BerVarray lset, LDAP_SLAPD_F (BerVarray) slap_set_join(SetCookie *cp,
int op, BerVarray rset); BerVarray lset, int op, BerVarray rset);
LDAP_END_DECL LDAP_END_DECL