]> git.sur5r.net Git - openldap/commitdiff
Added sc_next and sc_cleanup to slap_callback
authorHoward Chu <hyc@openldap.org>
Sun, 7 Dec 2003 08:51:23 +0000 (08:51 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 7 Dec 2003 08:51:23 +0000 (08:51 +0000)
servers/slapd/backglue.c
servers/slapd/backover.c
servers/slapd/overlays/pcache.c
servers/slapd/passwd.c
servers/slapd/result.c
servers/slapd/sasl.c
servers/slapd/saslauthz.c
servers/slapd/slap.h
servers/slapd/syncrepl.c

index aa3ac66e3aca57633a5518a29e85d4dae01b9f36..be2b7e93d1167615af11bd4ae922272ac4e190ce 100644 (file)
@@ -181,24 +181,17 @@ typedef struct glue_state {
        char *matched;
        int nrefs;
        BerVarray refs;
-       slap_callback *prevcb;
 } glue_state;
 
 static int
 glue_back_response ( Operation *op, SlapReply *rs )
 {
        glue_state *gs = op->o_callback->sc_private;
-       slap_callback *tmp = op->o_callback;
 
        switch(rs->sr_type) {
        case REP_SEARCH:
        case REP_SEARCHREF:
-               op->o_callback = gs->prevcb;
-               if (op->o_callback && op->o_callback->sc_response) {
-                       rs->sr_err = op->o_callback->sc_response( op, rs );
-               } else rs->sr_err = SLAP_CB_CONTINUE;
-               op->o_callback = tmp;
-               return rs->sr_err;
+               return SLAP_CB_CONTINUE;
 
        default:
                if (rs->sr_err == LDAP_SUCCESS || gs->err != LDAP_SUCCESS)
@@ -249,14 +242,14 @@ glue_back_search ( Operation *op, SlapReply *rs )
        glueinfo *gi = (glueinfo *) b0->bd_info;
        int i;
        long stoptime = 0;
-       glue_state gs = {0, 0, NULL, 0, NULL, NULL};
-       slap_callback cb = { glue_back_response, NULL };
+       glue_state gs = {0, 0, NULL, 0, NULL};
+       slap_callback cb = { NULL, glue_back_response, NULL, NULL };
        int scope0, slimit0, tlimit0;
        struct berval dn, ndn;
 
        cb.sc_private = &gs;
 
-       gs.prevcb = op->o_callback;
+       cb.sc_next = op->o_callback;
 
        if (op->ors_tlimit) {
                stoptime = slap_get_time () + op->ors_tlimit;
@@ -353,7 +346,7 @@ end_of_loop:;
 
                break;
        }
-       op->o_callback = gs.prevcb;
+       op->o_callback = cb.sc_next;
        rs->sr_err = gs.err;
        rs->sr_matched = gs.matched;
        rs->sr_ref = gs.refs;
index 6a36f7880b173092abf8e2131fb9cc59b0e233e6..46bd7a439e808a93634a997631aa1e9efe308e09 100644 (file)
@@ -134,11 +134,8 @@ over_back_response ( Operation *op, SlapReply *rs )
        slap_overinst *on = oi->oi_list;
        int rc = SLAP_CB_CONTINUE;
        BackendDB *be = op->o_bd, db = *op->o_bd;
-       slap_callback *sc = op->o_callback->sc_private;
-       slap_callback *s0 = op->o_callback;
 
        op->o_bd = &db;
-       op->o_callback = sc;
        for (; on; on=on->on_next ) {
                if ( on->on_response ) {
                        db.bd_info = (BackendInfo *)on;
@@ -146,11 +143,7 @@ over_back_response ( Operation *op, SlapReply *rs )
                        if ( rc != SLAP_CB_CONTINUE ) break;
                }
        }
-       if ( sc && (rc == SLAP_CB_CONTINUE) ) {
-               rc = sc->sc_response( op, rs );
-       }
        op->o_bd = be;
-       op->o_callback = s0;
        return rc;
 }
 
@@ -169,11 +162,11 @@ over_op_func(
        slap_overinst *on = oi->oi_list;
        BI_op_bind **func;
        BackendDB *be = op->o_bd, db = *op->o_bd;
-       slap_callback cb = {over_back_response, NULL};
+       slap_callback cb = {NULL, over_back_response, NULL, NULL};
        int rc = SLAP_CB_CONTINUE;
 
        op->o_bd = &db;
-       cb.sc_private = op->o_callback;
+       cb.sc_next = op->o_callback;
        op->o_callback = &cb;
 
        for (; on; on=on->on_next ) {
@@ -194,7 +187,7 @@ over_op_func(
        if ( rc == SLAP_CB_CONTINUE ) {
                rc = LDAP_UNWILLING_TO_PERFORM;
        }
-       op->o_callback = cb.sc_private;
+       op->o_callback = cb.sc_next;
        return rc;
 }
 
index f24ada9560a0981c9b265f9d2823c80936be2b12..f73728fa72448e71b0701813b7cc0e72349471a6 100644 (file)
@@ -153,7 +153,7 @@ merge_entry(
 
        SlapReply sreply = {REP_RESULT};
 
-       slap_callback cb = { slap_null_cb, NULL };
+       slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
 
        attr = e->e_attrs;
        e->e_attrs = NULL;
@@ -895,7 +895,7 @@ remove_query_data (
        char                    filter_str[64];
        Filter                  filter = {LDAP_FILTER_EQUALITY};
        SlapReply               sreply = {REP_RESULT};
-       slap_callback cb = { remove_func, NULL };
+       slap_callback cb = { NULL, remove_func, NULL, NULL };
 
        sreply.sr_entry = NULL;
        sreply.sr_nentries = 0;
@@ -1051,7 +1051,6 @@ filter2template(
 
 struct search_info {
        slap_overinst *on;
-       slap_callback *prev;
        Query query;
        int template_id;
        int max;
@@ -1444,11 +1443,12 @@ proxy_cache_search(
                op->o_tmpfree(op->ors_attrs, op->o_tmpmemctx);
                add_filter_attrs(op, &op->ors_attrs, query.attrs, filter_attrs);
                cb = op->o_tmpalloc( sizeof(*cb) + sizeof(*si), op->o_tmpmemctx);
+               cb->sc_next = op->o_callback;
                cb->sc_response = proxy_cache_response;
+               cb->sc_cleanup = NULL;
                cb->sc_private = (cb+1);
                si = cb->sc_private;
                si->on = on;
-               si->prev = op->o_callback;
                si->query = query;
                si->template_id = template_id;
                si->max = cm->num_entries_limit ;
index 9334adfeb48dbf6ec95afd161715e041ad9f6e69..79e9e3f0cc38c1f92776f001329b4638afa36bb1 100644 (file)
@@ -36,7 +36,7 @@ int passwd_extop(
                dn, ndn, hash, vals[2], tmpbv, *rsp = NULL;
        Modifications ml, **modtail;
        Operation op2;
-       slap_callback cb = { slap_null_cb, NULL };
+       slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
 
        assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 );
 
index 9fa857e91267f28222293a19123341e37037cd42..b134b9918d709db1af89006e2faf4e05fb26cf50 100644 (file)
@@ -252,8 +252,16 @@ send_ldap_response(
        int             rc;
        long    bytes;
 
-       if (op->o_callback && op->o_callback->sc_response) {
-               rc = op->o_callback->sc_response( op, rs );
+       if (op->o_callback) {
+               slap_callback *sc = op->o_callback;
+               for ( ; op->o_callback; ) {
+                       if ( op->o_callback->sc_response ) {
+                               rc = op->o_callback->sc_response( op, rs );
+                               if ( rc != SLAP_CB_CONTINUE ) break;
+                       }
+                       op->o_callback = op->o_callback->sc_next;
+               }
+               op->o_callback = sc;
                if ( rc != SLAP_CB_CONTINUE ) goto cleanup;
        }
                
@@ -409,10 +417,20 @@ send_ldap_response(
 
 cleanup:;
        if ( rs->sr_matched && rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
-               free( rs->sr_matched );
+               free( (char *)rs->sr_matched );
                rs->sr_matched = NULL;
        }
 
+       if (op->o_callback) {
+               slap_callback *sc = op->o_callback;
+               for ( ; op->o_callback; op->o_callback = op->o_callback->sc_next ) {
+                       if ( op->o_callback->sc_cleanup ) {
+                               op->o_callback->sc_cleanup( op, rs );
+                       }
+               }
+               op->o_callback = sc;
+       }
+
        return;
 }
 
@@ -659,8 +677,16 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
        char **e_flags = NULL;
 
        rs->sr_type = REP_SEARCH;
-       if (op->o_callback && op->o_callback->sc_response) {
-               rc = op->o_callback->sc_response( op, rs );
+       if (op->o_callback) {
+               slap_callback *sc = op->o_callback;
+               for ( ; op->o_callback; ) {
+                       if ( op->o_callback->sc_response ) {
+                               rc = op->o_callback->sc_response( op, rs );
+                               if ( rc != SLAP_CB_CONTINUE ) break;
+                       }
+                       op->o_callback = op->o_callback->sc_next;
+               }
+               op->o_callback = sc;
                if ( rc != SLAP_CB_CONTINUE ) goto error_return;
        }
 
@@ -1218,6 +1244,12 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
        rc = 0;
 
 error_return:;
+       /* FIXME: I think rs->sr_type should be explicitly set to
+        * REP_SEARCH here. That's what it was when we entered this
+        * function. send_ldap_error may have changed it, but we
+        * should set it back so that the cleanup functions know
+        * what they're doing.
+        */
        if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH 
                && rs->sr_entry 
                && (rs->sr_flags & REP_ENTRY_MUSTBEFREED) ) 
@@ -1229,6 +1261,15 @@ error_return:;
 
        if ( e_flags ) sl_free( e_flags, op->o_tmpmemctx );
 
+       if (op->o_callback) {
+               slap_callback *sc = op->o_callback;
+               for ( ; op->o_callback; op->o_callback = op->o_callback->sc_next ) {
+                       if ( op->o_callback->sc_cleanup ) {
+                               op->o_callback->sc_cleanup( op, rs );
+                       }
+               }
+               op->o_callback = sc;
+       }
        return( rc );
 }
 
@@ -1244,9 +1285,17 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
        AttributeDescription *ad_entry = slap_schema.si_ad_entry;
 
        rs->sr_type = REP_SEARCHREF;
-       if (op->o_callback && op->o_callback->sc_response) {
-               rc = op->o_callback->sc_response( op, rs );
-               if ( rc != SLAP_CB_CONTINUE ) return rc;
+       if (op->o_callback) {
+               slap_callback *sc = op->o_callback;
+               for ( ; op->o_callback; ) {
+                       if ( op->o_callback->sc_response ) {
+                               rc = op->o_callback->sc_response( op, rs );
+                               if ( rc != SLAP_CB_CONTINUE ) break;
+                       }
+                       op->o_callback = op->o_callback->sc_next;
+               }
+               op->o_callback = sc;
+               if ( rc != SLAP_CB_CONTINUE ) goto rel;
        }
 
 #ifdef NEW_LOGGING
@@ -1273,7 +1322,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
                        "send_search_reference: access to entry not allowed\n",
                    0, 0, 0 );
 #endif
-               return 1;
+               rc = 1;
+               goto rel;
        }
 
        if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
@@ -1289,7 +1339,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
                        "to reference not allowed\n",
                    0, 0, 0 );
 #endif
-               return 1;
+               rc = 1;
+               goto rel;
        }
 
 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
@@ -1303,7 +1354,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
                        "send_search_reference: domainScope control in (%s)\n", 
                        rs->sr_entry->e_dn, 0, 0 );
 #endif
-               return 0;
+               rc = 0;
+               goto rel;
        }
 #endif
 
@@ -1317,16 +1369,18 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
                        "send_search_reference: null ref in (%s)\n", 
                        rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
 #endif
-               return 1;
+               rc = 1;
+               goto rel;
        }
 
        if( op->o_protocol < LDAP_VERSION3 ) {
+               rc = 0;
                /* save the references for the result */
                if( rs->sr_ref[0].bv_val != NULL ) {
                        if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
-                               return LDAP_OTHER;
+                               rc = LDAP_OTHER;
                }
-               return 0;
+               goto rel;
        }
 
 #ifdef LDAP_CONNECTIONLESS
@@ -1365,7 +1419,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 #endif
                ber_free_buf( ber );
                send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
-               return rc;
+               goto rel;
        }
 
 #ifdef LDAP_CONNECTIONLESS
@@ -1393,6 +1447,16 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
        Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
 #endif
 
+rel:
+       if (op->o_callback) {
+               slap_callback *sc = op->o_callback;
+               for ( ; op->o_callback; op->o_callback = op->o_callback->sc_next ) {
+                       if ( op->o_callback->sc_cleanup ) {
+                               op->o_callback->sc_cleanup( op, rs );
+                       }
+               }
+               op->o_callback = sc;
+       }
        return rc;
 }
 
index f973098617c29da2d0a0d4aa90ff124528fa3492..0cbb875b55532fa1ab73f80d2095d2e66498ffa5 100644 (file)
@@ -440,7 +440,7 @@ slap_auxprop_lookup(
        }
 
        if (doit) {
-               slap_callback cb = { sasl_ap_lookup, NULL };
+               slap_callback cb = { NULL, sasl_ap_lookup, NULL, NULL };
 
                cb.sc_private = &sl;
 
@@ -487,7 +487,7 @@ slap_auxprop_store(
        Connection *conn = NULL;
        const struct propval *pr;
        Modifications *modlist = NULL, **modtail = &modlist, *mod;
-       slap_callback cb = { slap_null_cb, NULL };
+       slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
        char textbuf[SLAP_TEXT_BUFLEN];
        const char *text;
        size_t textlen = sizeof(textbuf);
@@ -675,7 +675,7 @@ slap_sasl_checkpass(
 
        op.o_bd = select_backend( &op.o_req_ndn, 0, 1 );
        if ( op.o_bd && op.o_bd->be_search ) {
-               slap_callback cb = { sasl_cb_checkpass, NULL };
+               slap_callback cb = { NULL, sasl_cb_checkpass, NULL, NULL };
                SlapReply rs = {REP_RESULT};
 
                ci.cred.bv_val = (char *)pass;
index c3d92ac4ab6779adae2bf2e46eb66ee458d46e2e..9402874f891a5385fae4e7029a49b6f9712eb6ba 100644 (file)
@@ -454,7 +454,7 @@ int slap_sasl_match( Operation *opx, struct berval *rule,
        int rc; 
        regex_t reg;
        smatch_info sm;
-       slap_callback cb = { sasl_sc_smatch, NULL };
+       slap_callback cb = { NULL, sasl_sc_smatch, NULL, NULL };
        Operation op = {0};
        SlapReply rs = {REP_RESULT};
 
@@ -641,7 +641,7 @@ void slap_sasl2dn( Operation *opx,
        struct berval *saslname, struct berval *sasldn )
 {
        int rc;
-       slap_callback cb = { sasl_sc_sasl2dn, NULL };
+       slap_callback cb = { NULL, sasl_sc_sasl2dn, NULL, NULL };
        Operation op = {0};
        SlapReply rs = {REP_RESULT};
        struct berval regout = { 0, NULL };
index 1e0c0a18bc65bf8781a985d5e5c4c8df535f0ab7..40e87db90562b64b7969d9a15bb93496fd8f4a72 100644 (file)
@@ -1805,7 +1805,9 @@ struct slap_backend_info {
 typedef int (slap_response)( struct slap_op *, struct slap_rep * );
 
 typedef struct slap_callback {
+       struct slap_callback *sc_next;
        slap_response *sc_response;
+       slap_response *sc_cleanup;
        void *sc_private;
 } slap_callback;
 
index 0b89dfb6ac65f383fe1149a4a770b416803f4642..0cd130e123de9513aa25cf56a33ee5fd6d689f70 100644 (file)
@@ -434,8 +434,6 @@ do_syncrep2(
        int     rc, err, i;
        ber_len_t       len;
 
-       slap_callback   cb;
-
        int rc_efree;
 
        struct berval   *psub;
@@ -466,8 +464,6 @@ do_syncrep2(
        Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2\n", 0, 0, 0 );
 #endif
 
-       op->o_callback = &cb;
-
        psub = &si->si_be->be_nsuffix[0];
 
        slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
@@ -1039,7 +1035,7 @@ syncrepl_entry(
 )
 {
        Backend *be = op->o_bd;
-       slap_callback   cb;
+       slap_callback   cb = { NULL };
        struct berval   *syncuuid_bv = NULL;
        struct berval   syncUUID_strrep = { 0, NULL };
 
@@ -1226,7 +1222,7 @@ syncrepl_del_nonpresent(
 )
 {
        Backend* be = op->o_bd;
-       slap_callback   cb;
+       slap_callback   cb = { NULL };
        SlapReply       rs = {REP_RESULT};
        struct nonpresent_entry *np_list, *np_prev;
 
@@ -1290,7 +1286,7 @@ syncrepl_add_glue(
 )
 {
        Backend *be = op->o_bd;
-       slap_callback cb;
+       slap_callback cb = { NULL };
        Attribute       *a;
        int     rc;
        int suffrdns;
@@ -1462,7 +1458,7 @@ syncrepl_updateCookie(
        struct berval slap_syncrepl_dn_bv = BER_BVNULL;
        struct berval slap_syncrepl_cn_bv = BER_BVNULL;
        
-       slap_callback cb;
+       slap_callback cb = { NULL };
        SlapReply       rs = {REP_RESULT};
 
        slap_sync_cookie_free( &si->si_syncCookie, 0 );