]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/search.c
Fixes for NO_THREADS
[openldap] / servers / slapd / back-ldbm / search.c
index 87f4b9278b1676360089b3b42d5fd18445464e53..eac5f831e9cc125a7bba4b4bb83afe27462ce404 100644 (file)
@@ -57,6 +57,10 @@ ldbm_back_search(
        struct slap_limits_set *limit = NULL;
        int isroot = 0;
                
+#ifdef SLAP_X_FILTER_HASSUBORDINATES
+       int             filter_hasSubordinates = 0;
+#endif /* SLAP_X_FILTER_HASSUBORDINATES */
+
 #ifdef NEW_LOGGING
        LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_search: enter\n", 0, 0, 0 );
 #else
@@ -288,10 +292,22 @@ searchit:
        /* compute it anyway; root does not use it */
        stoptime = op->o_time + tlimit;
 
+#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 */
+
        for ( id = idl_firstid( candidates, &cursor ); id != NOID;
            id = idl_nextid( candidates, &cursor ) )
        {
                int scopeok = 0;
+               int result = 0;
+#ifdef SLAP_X_FILTER_HASSUBORDINATES
+               Attribute       *hasSubordinates = NULL;
+#endif /* SLAP_X_FILTER_HASSUBORDINATES */
 
                /* check for abandon */
                if ( op->o_abandon ) {
@@ -420,8 +436,44 @@ searchit:
                        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;
+
+                       hs = has_children( be, e );
+                       hasSubordinates = slap_operational_hasSubordinate( hs );
+                       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 */
-               if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
+               result = 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 ( result == LDAP_COMPARE_TRUE ) {
                        struct berval   dn;
 
                        /* check scope */
@@ -452,7 +504,7 @@ searchit:
                                }
 
                                if (e) {
-                                       int result = send_search_entry(be, conn, op,
+                                       result = send_search_entry(be, conn, op,
                                                e, attrs, attrsonly, NULL);
 
                                        switch (result) {