]> git.sur5r.net Git - openldap/commitdiff
ITS#4364 add filter_dup, don't use str2filter to dup filters.
authorHoward Chu <hyc@openldap.org>
Mon, 23 Jan 2006 20:53:52 +0000 (20:53 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 23 Jan 2006 20:53:52 +0000 (20:53 +0000)
servers/slapd/filter.c
servers/slapd/overlays/pcache.c
servers/slapd/overlays/syncprov.c
servers/slapd/proto-slap.h

index 4fb874fdc821dece9c235a88c01a716761439db4..17bc674e234a92d0707c86593c05c33f4826e2f3 100644 (file)
@@ -777,6 +777,81 @@ filter2bv( Filter *f, struct berval *fstr )
        filter2bv_x( &op, f, fstr );
 }
 
+Filter *
+filter_dup( Filter *f, void *memctx )
+{
+       BerMemoryFunctions *mf = &slap_sl_mfuncs;
+       Filter *n;
+
+       if ( !f )
+               return NULL;
+
+       n = mf->bmf_malloc( sizeof(Filter), memctx );
+       n->f_choice = f->f_choice;
+       n->f_next = NULL;
+
+       switch( f->f_choice ) {
+       case SLAPD_FILTER_COMPUTED:
+               n->f_result = f->f_result;
+               break;
+       case LDAP_FILTER_PRESENT:
+               n->f_desc = f->f_desc;
+               break;
+       case LDAP_FILTER_EQUALITY:
+       case LDAP_FILTER_GE:
+       case LDAP_FILTER_LE:
+       case LDAP_FILTER_APPROX:
+               /* Should this be ava_dup() ? */
+               n->f_ava = mf->bmf_calloc( 1, sizeof(AttributeAssertion), memctx );
+               *n->f_ava = *f->f_ava;
+               ber_dupbv_x( &n->f_av_value, &f->f_av_value, memctx );
+               break;
+       case LDAP_FILTER_SUBSTRINGS:
+               n->f_sub = mf->bmf_calloc( 1, sizeof(SubstringsAssertion), memctx );
+               n->f_sub_desc = f->f_sub_desc;
+               if ( !BER_BVISNULL( &f->f_sub_initial ))
+                       ber_dupbv_x( &n->f_sub_initial, &f->f_sub_initial, memctx );
+               if ( f->f_sub_any ) {
+                       int i;
+                       for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ );
+                       n->f_sub_any = mf->bmf_malloc(( i+1 )*sizeof( struct berval ),
+                               memctx );
+                       for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
+                               ber_dupbv_x( &n->f_sub_any[i], &f->f_sub_any[i], memctx );
+                       }
+                       BER_BVZERO( &n->f_sub_any[i] );
+               }
+               if ( !BER_BVISNULL( &f->f_sub_final ))
+                       ber_dupbv_x( &n->f_sub_final, &f->f_sub_final, memctx );
+               break;
+       case LDAP_FILTER_EXT: {
+               /* Should this be mra_dup() ? */
+               ber_len_t length;
+               length = sizeof(MatchingRuleAssertion);
+               if ( !BER_BVISNULL( &f->f_mr_rule_text ))
+                       length += f->f_mr_rule_text.bv_len + 1;
+               n->f_mra = mf->bmf_calloc( 1, length, memctx );
+               *n->f_mra = *f->f_mra;
+               ber_dupbv_x( &n->f_mr_value, &f->f_mr_value, memctx );
+               if ( !BER_BVISNULL( &f->f_mr_rule_text )) {
+                       n->f_mr_rule_text.bv_val = (char *)(n->f_mra+1);
+                       AC_MEMCPY(n->f_mr_rule_text.bv_val,
+                               f->f_mr_rule_text.bv_val, f->f_mr_rule_text.bv_len );
+               }
+               } break;
+       case LDAP_FILTER_AND:
+       case LDAP_FILTER_OR:
+       case LDAP_FILTER_NOT: {
+               Filter **p;
+               for ( p = &n->f_list, f = f->f_list; f; f = f->f_next ) {
+                       *p = filter_dup( f, memctx );
+                       p = &(*p)->f_next;
+               }
+               } break;
+       }
+       return n;
+}
+
 static int
 get_simple_vrFilter(
        Operation *op,
index 909457f4ef26e59bb8c8f3f81ae629396727fc8e..a1a5fdd7256e9c6e604ead1013fb0ddb3d891b9b 100644 (file)
@@ -1308,7 +1308,7 @@ pcache_op_search(
                struct search_info      *si;
 
                Debug( LDAP_DEBUG_TRACE, "QUERY CACHEABLE\n", 0, 0, 0 );
-               query.filter = str2filter(op->ors_filterstr.bv_val);
+               query.filter = filter_dup(op->ors_filter, NULL);
                add_filter_attrs(op, &query.attrs, &qm->attr_sets[attr_set],
                        filter_attrs, fattr_cnt, fattr_got_oc);
 
index 5eb40f4c00431902e8fa782b5ff2cf3390eabbff..8d30c204f36d4e086479458a0f43b43d7fa220bd 100644 (file)
@@ -1761,7 +1761,7 @@ syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on )
        op2->ors_filterstr.bv_val = ptr;
        strcpy( ptr, so->s_filterstr.bv_val );
        op2->ors_filterstr.bv_len = so->s_filterstr.bv_len;
-       op2->ors_filter = str2filter( ptr );
+       op2->ors_filter = filter_dup( op->ors_filter, NULL );
        so->s_op = op2;
 
        /* Copy any cached group ACLs individually */
index 82f754e5dcb1ac182c4a316b6497a82f48c6f014..5859ecad3e045b659b47ee288e5ab82797363e30 100644 (file)
@@ -898,6 +898,7 @@ LDAP_SLAPD_F (void) filter_free LDAP_P(( Filter *f ));
 LDAP_SLAPD_F (void) filter_free_x LDAP_P(( Operation *op, Filter *f ));
 LDAP_SLAPD_F (void) filter2bv LDAP_P(( Filter *f, struct berval *bv ));
 LDAP_SLAPD_F (void) filter2bv_x LDAP_P(( Operation *op, Filter *f, struct berval *bv ));
+LDAP_SLAPD_F (Filter *) filter_dup LDAP_P(( Filter *f, void *memctx ));
 
 LDAP_SLAPD_F (int) get_vrFilter LDAP_P(( Operation *op, BerElement *ber,
        ValuesReturnFilter **f,