]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/compare.c
group rewrite/map stuff in one structure and optimize more function calls
[openldap] / servers / slapd / back-meta / compare.c
index 75a4c868e4e3cf7bc4ba6d360ef638069c625050..d272ab42dc20838b5bc06054333def8238246651 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  *
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
 #include "back-meta.h"
 
 int
-meta_back_compare(
-               Backend                 *be,
-               Connection              *conn,
-               Operation               *op,
-               struct berval           *dn,
-               struct berval           *ndn,
-               AttributeAssertion      *ava
-)
+meta_back_compare( Operation *op, SlapReply *rs )
 {
-       struct metainfo *li = ( struct metainfo * )be->be_private;
+       struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
        struct metaconn *lc;
        struct metasingleconn *lsc;
        char *match = NULL, *err = NULL, *mmatch = NULL;
@@ -93,9 +86,16 @@ meta_back_compare(
                int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
        int *msgid;
 
-       lc = meta_back_getconn( li, conn, op, META_OP_ALLOW_MULTIPLE,
-                       ndn, NULL );
-       if ( !lc || !meta_back_dobind( lc, op ) ) {
+       lc = meta_back_getconn( op, rs, META_OP_ALLOW_MULTIPLE,
+                       &op->o_req_ndn, NULL );
+       if ( !lc ) {
+               send_ldap_result( op, rs );
+               return -1;
+       }
+       
+       if ( !meta_back_dobind( lc, op ) ) {
+               rs->sr_err = LDAP_OTHER;
+               send_ldap_result( op, rs );
                return -1;
        }
 
@@ -109,10 +109,11 @@ meta_back_compare(
         */
        for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
                char *mdn = NULL;
-               struct berval mapped_attr = ava->aa_desc->ad_cname;
-               struct berval mapped_value = ava->aa_value;
+               struct berval mapped_attr = op->oq_compare.rs_ava->aa_desc->ad_cname;
+               struct berval mapped_value = op->oq_compare.rs_ava->aa_value;
 
                if ( lsc->candidate != META_CANDIDATE ) {
+                       msgid[ i ] = -1;
                        continue;
                }
 
@@ -121,44 +122,44 @@ meta_back_compare(
                 */
                switch ( rewrite_session( li->targets[ i ]->rwinfo,
                                        "compareDn", 
-                                       dn->bv_val, conn, &mdn ) ) {
+                                       op->o_req_dn.bv_val, op->o_conn, &mdn ) ) {
                case REWRITE_REGEXEC_OK:
                        if ( mdn == NULL ) {
-                               mdn = ( char * )dn->bv_val;
+                               mdn = ( char * )op->o_req_dn.bv_val;
                        }
 #ifdef NEW_LOGGING
                        LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] compareDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn, 0 );
+                               "[rw] compareDn: \"%s\" -> \"%s\"\n",
+                               op->o_req_dn.bv_val, mdn, 0 );
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS,
-                                       "rw> compareDn: \"%s\" -> \"%s\"\n%s",
-                                       dn->bv_val, mdn, "" );
+                                       "rw> compareDn: \"%s\" -> \"%s\"\n",
+                                       op->o_req_dn.bv_val, mdn, 0 );
 #endif /* !NEW_LOGGING */
                        break;
                
                case REWRITE_REGEXEC_UNWILLING:
-                       send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
-                                       NULL, "Operation not allowed",
-                                       NULL, NULL );
+                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                       rs->sr_text = "Operation not allowed";
+                       send_ldap_result( op, rs );
                        return -1;
                        
                case REWRITE_REGEXEC_ERR:
-                       send_ldap_result( conn, op,  LDAP_OTHER,
-                                       NULL, "Rewrite error",
-                                       NULL, NULL );
+                       rs->sr_err = LDAP_OTHER;
+                       rs->sr_text = "Rewrite error";
+                       send_ldap_result( op, rs );
                        return -1;
                }
 
                /*
                 * if attr is objectClass, try to remap the value
                 */
-               if ( ava->aa_desc->ad_type->sat_oid 
-                       == slap_schema.si_ad_objectClass->ad_type->sat_oid ) {
+               if ( op->oq_compare.rs_ava->aa_desc == slap_schema.si_ad_objectClass ) {
                        ldap_back_map( &li->targets[ i ]->oc_map,
-                                       &ava->aa_value, &mapped_value, 0 );
+                                       &op->oq_compare.rs_ava->aa_value,
+                                       &mapped_value, BACKLDAP_MAP );
 
-                       if ( mapped_value.bv_val == NULL ) {
-                               lsc->candidate = META_NOT_CANDIDATE;
+                       if ( mapped_value.bv_val == NULL || mapped_value.bv_val[0] == '\0' ) {
                                continue;
                        }
                /*
@@ -166,9 +167,9 @@ meta_back_compare(
                 */
                } else {
                        ldap_back_map( &li->targets[ i ]->at_map,
-                               &ava->aa_desc->ad_cname, &mapped_attr, 0 );
-                       if ( mapped_attr.bv_val == NULL ) {
-                               lsc->candidate = META_NOT_CANDIDATE;
+                               &op->oq_compare.rs_ava->aa_desc->ad_cname,
+                               &mapped_attr, BACKLDAP_MAP );
+                       if ( mapped_attr.bv_val == NULL || mapped_attr.bv_val[0] == '\0' ) {
                                continue;
                        }
                }
@@ -180,21 +181,20 @@ meta_back_compare(
                 */
                msgid[ i ] = ldap_compare( lc->conns[ i ].ld, mdn,
                                mapped_attr.bv_val, mapped_value.bv_val );
-               if ( msgid[ i ] == -1 ) {
-                       lsc->candidate = META_NOT_CANDIDATE;
-                       continue;
-               }
-
-               if ( mdn != dn->bv_val ) {
+               if ( mdn != op->o_req_dn.bv_val ) {
                        free( mdn );
                }
-               if ( mapped_attr.bv_val != ava->aa_desc->ad_cname.bv_val ) {
+               if ( mapped_attr.bv_val != op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val ) {
                        free( mapped_attr.bv_val );
                }
-               if ( mapped_value.bv_val != ava->aa_value.bv_val ) {
+               if ( mapped_value.bv_val != op->oq_compare.rs_ava->aa_value.bv_val ) {
                        free( mapped_value.bv_val );
                }
 
+               if ( msgid[ i ] == -1 ) {
+                       continue;
+               }
+
                ++candidates;
        }
 
@@ -207,10 +207,10 @@ meta_back_compare(
                 * FIXME: should we check for abandon?
                 */
                for ( i = 0, lsc = lc->conns; !META_LAST(lsc); lsc++, i++ ) {
-                       int lrc;
-                       LDAPMessage *res = NULL;
+                       int             lrc;
+                       LDAPMessage     *res = NULL;
 
-                       if ( lsc->candidate != META_CANDIDATE ) {
+                       if ( msgid[ i ] == -1 ) {
                                continue;
                        }
 
@@ -225,6 +225,7 @@ meta_back_compare(
                                        ldap_msgfree( res );
                                }
                                continue;
+
                        } else if ( lrc == LDAP_RES_COMPARE ) {
                                if ( count > 0 ) {
                                        rres = LDAP_OTHER;
@@ -232,8 +233,8 @@ meta_back_compare(
                                        goto finish;
                                }
                                
-                               cres = ldap_result2error( lsc->ld, res, 1 );
-                               switch ( cres ) {
+                               rs->sr_err = ldap_result2error( lsc->ld, res, 1 );
+                               switch ( rs->sr_err ) {
                                case LDAP_COMPARE_TRUE:
                                case LDAP_COMPARE_FALSE:
 
@@ -242,7 +243,7 @@ meta_back_compare(
                                         * sending to cache ...
                                         */
                                        if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
-                                               ( void )meta_dncache_update_entry( &li->cache, ndn, i );
+                                               ( void )meta_dncache_update_entry( &li->cache, &op->o_req_ndn, i );
                                        }
 
                                        count++;
@@ -250,7 +251,7 @@ meta_back_compare(
                                        break;
 
                                default:
-                                       rres = ldap_back_map_result( cres );
+                                       rres = ldap_back_map_result( rs );
 
                                        if ( err != NULL ) {
                                                free( err );
@@ -267,10 +268,11 @@ meta_back_compare(
                                        last = i;
                                        break;
                                }
-                               lsc->candidate = META_NOT_CANDIDATE;
+                               msgid[ i ] = -1;
                                --candidates;
+
                        } else {
-                               lsc->candidate = META_NOT_CANDIDATE;
+                               msgid[ i ] = -1;
                                --candidates;
                                if ( res ) {
                                        ldap_msgfree( res );
@@ -306,39 +308,44 @@ finish:;
                 * and none was successful
                 */
                switch ( rewrite_session( li->targets[ last ]->rwinfo,
-                                       "matchedDn", match, conn, &mmatch ) ) {
+                                       "matchedDn", match, op->o_conn,
+                                       &mmatch ) ) {
                case REWRITE_REGEXEC_OK:
                        if ( mmatch == NULL ) {
                                mmatch = ( char * )match;
                        }
 #ifdef NEW_LOGGING
                        LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] matchedDn: \"%s\" -> \"%s\"\n", match, mmatch, 0 );
+                                       "[rw] matchedDn: \"%s\" -> \"%s\"\n",
+                                       match, mmatch, 0 );
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS, "rw> matchedDn:"
-                                       " \"%s\" -> \"%s\"\n%s",
-                                       match, mmatch, "" );
+                                       " \"%s\" -> \"%s\"\n",
+                                       match, mmatch, 0 );
 #endif /* !NEW_LOGGING */
                        break;
                        
                
                case REWRITE_REGEXEC_UNWILLING:
-                       send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
-                                       NULL, "Operation not allowed",
-                                       NULL, NULL );
+                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                       rs->sr_text = "Operation not allowed";
+                       send_ldap_result( op, rs );
                        rc = -1;
                        goto cleanup;
                        
                case REWRITE_REGEXEC_ERR:
-                       send_ldap_result( conn, op, LDAP_OTHER,
-                                       NULL, "Rewrite error",
-                                       NULL, NULL );
+                       rs->sr_err = LDAP_OTHER;
+                       rs->sr_text = "Rewrite error";
+                       send_ldap_result( op, rs );
                        rc = -1;
                        goto cleanup;
                }
        }
 
-       send_ldap_result( conn, op, rres, mmatch, err, NULL, NULL );
+       rs->sr_err = rres;
+       rs->sr_matched = mmatch;
+       send_ldap_result( op, rs );
+       rs->sr_matched = NULL;
 
 cleanup:;
        if ( match != NULL ) {