]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/compare.c
minor cleanup
[openldap] / servers / slapd / back-meta / compare.c
index 950562e1adc6c79b82ce7fe04fbdfe02f37de83a..65fdde05f01c50c9a084b29dacd6ba974f750884 100644 (file)
@@ -34,9 +34,8 @@
 int
 meta_back_compare( Operation *op, SlapReply *rs )
 {
-       struct metainfo         *li = ( struct metainfo * )op->o_bd->be_private;
-       struct metaconn         *lc;
-       struct metasingleconn   *lsc;
+       metainfo_t              *mi = ( metainfo_t * )op->o_bd->be_private;
+       metaconn_t              *mc = NULL;
        char                    *match = NULL,
                                *err = NULL;
        struct berval           mmatch = BER_BVNULL;
@@ -50,16 +49,18 @@ meta_back_compare( Operation *op, SlapReply *rs )
                                *msgid;
        dncookie                dc;
 
-       char                    *candidates = meta_back_candidates_get( op );
+       SlapReply               *candidates = meta_back_candidates_get( op );
 
-       lc = meta_back_getconn( op, rs, NULL, LDAP_BACK_SENDERR );
-       if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+       mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_SENDERR );
+       if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
                return rs->sr_err;
        }
        
-       msgid = ch_calloc( sizeof( int ), li->mi_ntargets );
+       msgid = ch_calloc( sizeof( int ), mi->mi_ntargets );
        if ( msgid == NULL ) {
-               return -1;
+               send_ldap_error( op, rs, LDAP_OTHER, NULL );
+               rc = LDAP_OTHER;
+               goto done;
        }
 
        /*
@@ -69,12 +70,12 @@ meta_back_compare( Operation *op, SlapReply *rs )
        dc.rs = rs;
        dc.ctx = "compareDN";
 
-       for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); ++i, ++lsc ) {
-               struct berval mdn = BER_BVNULL;
-               struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
-               struct berval mapped_value = op->orc_ava->aa_value;
+       for ( i = 0; i < mi->mi_ntargets; i++ ) {
+               struct berval           mdn = BER_BVNULL;
+               struct berval           mapped_attr = op->orc_ava->aa_desc->ad_cname;
+               struct berval           mapped_value = op->orc_ava->aa_value;
 
-               if ( candidates[ i ] != META_CANDIDATE ) {
+               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
                        msgid[ i ] = -1;
                        continue;
                }
@@ -82,7 +83,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                /*
                 * Rewrite the compare dn, if needed
                 */
-               dc.rwmap = &li->mi_targets[ i ]->mt_rwmap;
+               dc.target = &mi->mi_targets[ i ];
 
                switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
                case LDAP_UNWILLING_TO_PERFORM:
@@ -97,7 +98,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                 * if attr is objectClass, try to remap the value
                 */
                if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass ) {
-                       ldap_back_map( &li->mi_targets[ i ]->mt_rwmap.rwm_oc,
+                       ldap_back_map( &mi->mi_targets[ i ].mt_rwmap.rwm_oc,
                                        &op->orc_ava->aa_value,
                                        &mapped_value, BACKLDAP_MAP );
 
@@ -108,7 +109,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                 * else try to remap the attribute
                 */
                } else {
-                       ldap_back_map( &li->mi_targets[ i ]->mt_rwmap.rwm_at,
+                       ldap_back_map( &mi->mi_targets[ i ].mt_rwmap.rwm_at,
                                &op->orc_ava->aa_desc->ad_cname,
                                &mapped_attr, BACKLDAP_MAP );
                        if ( BER_BVISNULL( &mapped_attr ) || mapped_attr.bv_val[0] == '\0' ) {
@@ -136,7 +137,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                 * that returns determines the result; a constraint on unicity
                 * of the result ought to be enforced
                 */
-                rc = ldap_compare_ext( lc->mc_conns[ i ].msc_ld, mdn.bv_val,
+                rc = ldap_compare_ext( mc->mc_conns[ i ].msc_ld, mdn.bv_val,
                                mapped_attr.bv_val, &mapped_value,
                                op->o_ctrls, NULL, &msgid[ i ] );
 
@@ -171,26 +172,35 @@ meta_back_compare( Operation *op, SlapReply *rs )
                /*
                 * FIXME: should we check for abandon?
                 */
-               for ( i = 0, lsc = &lc->mc_conns[ 0 ]; !META_LAST( lsc ); lsc++, i++ ) {
-                       int             lrc;
-                       LDAPMessage     *res = NULL;
+               for ( i = 0; i < mi->mi_ntargets; i++ ) {
+                       metasingleconn_t        *msc = &mc->mc_conns[ i ];
+                       int                     lrc;
+                       LDAPMessage             *res = NULL;
+                       struct timeval          tv;
+
+                       LDAP_BACK_TV_SET( &tv );
 
                        if ( msgid[ i ] == -1 ) {
                                continue;
                        }
 
-                       lrc = ldap_result( lsc->msc_ld, msgid[ i ],
-                                       0, NULL, &res );
+                       lrc = ldap_result( msc->msc_ld, msgid[ i ],
+                                       0, &tv, &res );
 
                        if ( lrc == 0 ) {
-                               /*
-                                * FIXME: should we yield?
-                                */
-                               if ( res ) {
-                                       ldap_msgfree( res );
-                               }
+                               assert( res == NULL );
                                continue;
 
+                       } else if ( lrc == -1 ) {
+                               /* we do not retry in this case;
+                                * only for unique operations... */
+                               ldap_get_option( msc->msc_ld,
+                                       LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
+                               rres = slap_map_api2result( rs );
+                               rres = rc;
+                               rc = -1;
+                               goto finish;
+
                        } else if ( lrc == LDAP_RES_COMPARE ) {
                                if ( count > 0 ) {
                                        rres = LDAP_OTHER;
@@ -198,7 +208,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                                        goto finish;
                                }
 
-                               rc = ldap_parse_result( lsc->msc_ld, res,
+                               rc = ldap_parse_result( msc->msc_ld, res,
                                                &rs->sr_err,
                                                NULL, NULL, NULL, NULL, 1 );
                                if ( rc != LDAP_SUCCESS ) {
@@ -212,11 +222,11 @@ meta_back_compare( Operation *op, SlapReply *rs )
                                case LDAP_COMPARE_FALSE:
 
                                        /*
-                                        * true or flase, got it;
+                                        * true or false, got it;
                                         * sending to cache ...
                                         */
-                                       if ( li->mi_cache.ttl != META_DNCACHE_DISABLED ) {
-                                               ( void )meta_dncache_update_entry( &li->mi_cache, &op->o_req_ndn, i );
+                                       if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED ) {
+                                               ( void )meta_dncache_update_entry( &mi->mi_cache, &op->o_req_ndn, i );
                                        }
 
                                        count++;
@@ -229,13 +239,13 @@ meta_back_compare( Operation *op, SlapReply *rs )
                                        if ( err != NULL ) {
                                                free( err );
                                        }
-                                       ldap_get_option( lsc->msc_ld,
+                                       ldap_get_option( msc->msc_ld,
                                                LDAP_OPT_ERROR_STRING, &err );
 
                                        if ( match != NULL ) {
                                                free( match );
                                        }
-                                       ldap_get_option( lsc->msc_ld,
+                                       ldap_get_option( msc->msc_ld,
                                                LDAP_OPT_MATCHED_DN, &match );
                                        
                                        last = i;
@@ -278,13 +288,19 @@ finish:;
                 * At least one compare failed with matched portion,
                 * and none was successful
                 */
-       } else if ( match != NULL &&  match[0] != '\0' ) {
-               struct berval matched;
+       } else if ( match != NULL && match[ 0 ] != '\0' ) {
+               struct berval matched, pmatched;
 
                ber_str2bv( match, 0, 0, &matched );
 
                dc.ctx = "matchedDN";
                ldap_back_dn_massage( &dc, &matched, &mmatch );
+               if ( dnPretty( NULL, &mmatch, &pmatched, NULL ) == LDAP_SUCCESS ) {
+                       if ( mmatch.bv_val != match ) {
+                               free( mmatch.bv_val );
+                       }
+                       mmatch = pmatched;
+               }
        }
 
        if ( rres != LDAP_SUCCESS ) {
@@ -304,7 +320,10 @@ finish:;
        if ( msgid ) {
                free( msgid );
        }
-       
+
+done:;
+       meta_back_release_conn( op, mc );
+
        return rc;
 }