]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/search.c
Fix typo
[openldap] / servers / slapd / back-bdb / search.c
index 12b2bb202e38e80f3f8f57952193d6d670f0fbe1..5d2bdcec14855ac86a36ebeafd93ddb23f50d006 100644 (file)
@@ -67,10 +67,6 @@ bdb_search(
        struct slap_limits_set *limit = NULL;
        int isroot = 0;
 
-#ifdef SLAP_X_FILTER_HASSUBORDINATES
-       int             filter_hasSubordinates = 0;
-#endif /* SLAP_X_FILTER_HASSUBORDINATES */
-
        u_int32_t       locker;
        DB_LOCK         lock;
 
@@ -81,6 +77,15 @@ bdb_search(
                0, 0, 0);
 #endif
 
+#ifdef LDAP_CLIENT_UPDATE
+       if ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) {
+               bdb_add_psearch_spec( be, conn, op, base, base, scope,
+                       deref, slimit, tlimit, filter, filterstr, attrs, attrsonly );
+               return LDAP_SUCCESS;
+       }
+#endif
+
+
        manageDSAit = get_manageDSAit( op );
 
        rc = LOCK_ID (bdb->bi_dbenv, &locker );
@@ -307,7 +312,8 @@ dn2entry_retry:
 
        if ( candidates[0] == 0 ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, RESULTS, "bdb_search: no candidates\n", 0, 0, 0 );
+               LDAP_LOG ( OPERATION, RESULTS,
+                       "bdb_search: no candidates\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
                        0, 0, 0 );
@@ -332,14 +338,6 @@ dn2entry_retry:
                }
        }
 
-#ifdef SLAP_X_FILTER_HASSUBORDINATES
-       /*
-        * is hasSubordinates used in the filter ?
-        * FIXME: we may compute this directly when parsing the filter
-        */
-       filter_hasSubordinates = filter_has_subordinates( filter );
-#endif /* SLAP_X_FILTER_HASSUBORDINATES */
-
 #ifdef LDAP_CLIENT_UPDATE
        if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
                lcupf.f_choice = LDAP_FILTER_AND;
@@ -372,9 +370,6 @@ dn2entry_retry:
                id = bdb_idl_next( candidates, &cursor ) )
        {
                int             scopeok = 0;
-#ifdef SLAP_X_FILTER_HASSUBORDINATES
-               Attribute       *hasSubordinates = NULL;
-#endif /* SLAP_X_FILTER_HASSUBORDINATES */
 
                /* check for abandon */
                if ( op->o_abandon ) {
@@ -538,31 +533,6 @@ id2entry_retry:
                        goto loop_continue;
                }
 
-#ifdef SLAP_X_FILTER_HASSUBORDINATES
-               /*
-                * if hasSubordinates is used in the filter,
-                * append it to the entry's attributes
-                */
-               if ( filter_hasSubordinates ) {
-                       int     hs;
-
-                       rc = bdb_hasSubordinates( be, conn, op, e, &hs);
-                       if ( rc != LDAP_SUCCESS ) {
-                               goto loop_continue;
-                       }
-
-                       hasSubordinates = slap_operational_hasSubordinate(
-                               hs == LDAP_COMPARE_TRUE );
-
-                       if ( hasSubordinates == NULL ) {
-                               goto loop_continue;
-                       }
-
-                       hasSubordinates->a_next = e->e_attrs;
-                       e->e_attrs = hasSubordinates;
-               }
-#endif /* SLAP_X_FILTER_HASSUBORDINATES */
-
                /* if it matches the filter and scope, send it */
 #ifdef LDAP_CLIENT_UPDATE
                if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
@@ -573,21 +543,6 @@ id2entry_retry:
                        rc = test_filter( be, conn, op, e, filter );
                }
 
-#ifdef SLAP_X_FILTER_HASSUBORDINATES
-               if ( hasSubordinates ) {
-                       /*
-                        * FIXME: this is fairly inefficient, because 
-                        * if hasSubordinates is among the required
-                        * attrs, it will be added again later;
-                        * maybe we should leave it and check
-                        * check later if it's already present,
-                        * if required
-                        */
-                       e->e_attrs = e->e_attrs->a_next;
-                       attr_free( hasSubordinates );
-               }
-#endif /* SLAP_X_FILTER_HASSUBORDINATES */
-
                if ( rc == LDAP_COMPARE_TRUE ) {
                        struct berval   dn;
 
@@ -610,7 +565,8 @@ id2entry_retry:
                        if ( scopeok ) {
                                /* check size limit */
                                if ( --slimit == -1 ) {
-                                       bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
+                                       bdb_cache_return_entry_r( bdb->bi_dbenv,
+                                               &bdb->bi_cache, e, &lock );
                                        e = NULL;
                                        send_search_result( conn, op,
                                                rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
@@ -624,8 +580,9 @@ id2entry_retry:
 #if 0  /* noop is masked SLAP_CTRL_UPDATE */
                                        if( op->o_noop ) {
                                                result = 0;
-                                       } else {
+                                       } else
 #endif
+                                       {
 #ifdef LDAP_CLIENT_UPDATE
                                                if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
                                                        Attribute* a;
@@ -640,9 +597,11 @@ id2entry_retry:
                                                        if ( ber == NULL ) {
 #ifdef NEW_LOGGING
                                                                LDAP_LOG ( OPERATION, RESULTS, 
-                                                                       "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
+                                                                       "bdb_search: ber_alloc_t failed\n",
+                                                                       0, 0, 0 );
 #else
-                                                               Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
+                                                               Debug( LDAP_DEBUG_TRACE,
+                                                                       "bdb_search: ber_alloc_t failed\n",
                                                                        0, 0, 0 );
 #endif
                                                                send_ldap_result( conn, op, rc=LDAP_OTHER,
@@ -659,19 +618,24 @@ id2entry_retry:
                                                                /* Send cookie */
                                                                for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
                                                                        AttributeDescription *desc = a->a_desc;
-                                                                       if ( !strcmp( desc->ad_cname.bv_val, "entryCSN" ) ) {
+                                                                       if ( desc == slap_schema.si_ad_entryCSN ) {
                                                                                ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
                                                                                if ( latest_entrycsn_bv.bv_val == NULL ) {
                                                                                        ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
                                                                                } else {
-                                                                                       res = value_match( &ret, desc, desc->ad_type->sat_ordering, SLAP_MR_ASSERTION_SYNTAX_MATCH, &entrycsn_bv, &latest_entrycsn_bv, &text );
+                                                                                       res = value_match( &ret, desc,
+                                                                                               desc->ad_type->sat_ordering,
+                                                                                               SLAP_MR_ASSERTION_SYNTAX_MATCH,
+                                                                                               &entrycsn_bv, &latest_entrycsn_bv, &text );
                                                                                        if ( res != LDAP_SUCCESS ) {
                                                                                                ret = 0;
 #ifdef NEW_LOGGING
                                                                                                LDAP_LOG ( OPERATION, RESULTS, 
-                                                                                                       "bdb_search: value_match failed\n", 0, 0, 0 );
+                                                                                                       "bdb_search: value_match failed\n",
+                                                                                                       0, 0, 0 );
 #else
-                                                                                               Debug( LDAP_DEBUG_TRACE, "bdb_search: value_match failed\n",
+                                                                                               Debug( LDAP_DEBUG_TRACE,
+                                                                                                       "bdb_search: value_match failed\n",
                                                                                                        0, 0, 0 );
 #endif
                                                                                        }
@@ -679,23 +643,28 @@ id2entry_retry:
                                                                                        if ( ret > 0 ) {
                                                                                                ch_free( latest_entrycsn_bv.bv_val );
                                                                                                latest_entrycsn_bv.bv_val = NULL;
-                                                                                               ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
+                                                                                               ber_dupbv( &latest_entrycsn_bv,
+                                                                                                       &entrycsn_bv );
                                                                                        }
                                                                                }
                                                                        }
                                                                }
 
-                                                               ber_printf( ber, "{{b}" /*}*/, SLAP_LCUP_STATE_UPDATE_FALSE );
-                                                               ber_printf( ber, "{b}",  SLAP_LCUP_ENTRY_DELETED_FALSE );
-                                                               ber_printf( ber, "{sO" /*}*/, LCUP_COOKIE_OID, &entrycsn_bv );
-                                                               ber_printf( ber, /*{{*/ "N}N}" );
+                                                               ber_printf( ber,
+                                                                       "{bb{sON}N}",
+                                                                       SLAP_LCUP_STATE_UPDATE_FALSE,
+                                                                       SLAP_LCUP_ENTRY_DELETED_FALSE,
+                                                                       LCUP_COOKIE_OID, &entrycsn_bv );
 
                                                                ch_free( entrycsn_bv.bv_val );
                                                                entrycsn_bv.bv_val = NULL;
+
                                                        } else {
                                                                /* Do not send cookie */
-                                                               ber_printf( ber, "{{b}" /*}*/, SLAP_LCUP_STATE_UPDATE_FALSE );
-                                                               ber_printf( ber, /*{*/ "{b}N}",  SLAP_LCUP_ENTRY_DELETED_FALSE );
+                                                               ber_printf( ber,
+                                                                       "{bbN}",
+                                                                       SLAP_LCUP_STATE_UPDATE_FALSE,
+                                                                       SLAP_LCUP_ENTRY_DELETED_FALSE );
                                                        }
 
                                                        ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
@@ -705,9 +674,11 @@ id2entry_retry:
                                                        if ( ret < 0 ) {
 #ifdef NEW_LOGGING
                                                                LDAP_LOG ( OPERATION, RESULTS, 
-                                                                       "bdb_search: ber_flatten failed\n", 0, 0, 0 );
+                                                                       "bdb_search: ber_flatten failed\n",
+                                                                       0, 0, 0 );
 #else
-                                                               Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
+                                                               Debug( LDAP_DEBUG_TRACE,
+                                                                       "bdb_search: ber_flatten failed\n",
                                                                        0, 0, 0 );
 #endif
                                                                send_ldap_result( conn, op, rc=LDAP_OTHER,
@@ -724,16 +695,13 @@ id2entry_retry:
                                                        ch_free( ctrls[0] );
                                                        ber_free( ber, 1 );
                                                        ber_bvfree( bv );
-                                               } else {
+                                               } else
 #endif /* LDAP_CLIENT_UPDATE */
+                                               {
                                                        result = send_search_entry( be, conn, op,
                                                                e, attrs, attrsonly, NULL);
-#ifdef LDAP_CLIENT_UPDATE
                                                }
-#endif /* LDAP_CLIENT_UPDATE */
-#if 0
                                        }
-#endif
 
                                        switch (result) {
                                        case 0:         /* entry sent ok */
@@ -742,7 +710,8 @@ id2entry_retry:
                                        case 1:         /* entry not sent */
                                                break;
                                        case -1:        /* connection closed */
-                                               bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
+                                               bdb_cache_return_entry_r(bdb->bi_dbenv,
+                                                       &bdb->bi_cache, e, &lock);
                                                e = NULL;
                                                rc = LDAP_OTHER;
                                                goto done;
@@ -779,6 +748,7 @@ loop_continue:
 
                ldap_pvt_thread_yield();
        }
+
 #ifdef LDAP_CLIENT_UPDATE
        if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
                int ret;
@@ -834,14 +804,13 @@ loop_continue:
                ch_free( ctrls[0] );
                ber_free( ber, 1 );
                ber_bvfree( bv );
-       } else {
+       } else
 #endif /* LDAP_CLIENT_UPDATE */
+       {
                send_search_result( conn, op,
                        v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
                        NULL, NULL, v2refs, NULL, nentries );
-#ifdef LDAP_CLIENT_UPDATE
        }
-#endif /* LDAP_CLIENT_UPDATE */
 
        rc = 0;
 
@@ -851,13 +820,17 @@ done:
                bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
        }
 
-       if ( csnfeq.f_av_value.bv_val != NULL ) {
-               ch_free( csnfeq.f_av_value.bv_val );
-       }
+#ifdef LDAP_CLIENT_UPDATE
+       if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
+               if ( csnfeq.f_ava != NULL && csnfeq.f_av_value.bv_val != NULL ) {
+                       ch_free( csnfeq.f_av_value.bv_val );
+               }
        
-       if ( csnfge.f_av_value.bv_val != NULL ) {
-               ch_free( csnfge.f_av_value.bv_val );
+               if ( csnfge.f_ava != NULL && csnfge.f_av_value.bv_val != NULL ) {
+                       ch_free( csnfge.f_av_value.bv_val );
+               }
        }
+#endif /* LDAP_CLIENT_UPDATE */
 
        LOCK_ID_FREE (bdb->bi_dbenv, locker );