]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/backglue.c
ITS#2846 - make veryclean
[openldap] / servers / slapd / backglue.c
index 1b0769301029f45d3fab66869ee5d6c52ffd1f9e..aa3ac66e3aca57633a5518a29e85d4dae01b9f36 100644 (file)
@@ -1,8 +1,17 @@
 /* backglue.c - backend glue routines */
 /* $OpenLDAP$ */
-/*
- * Copyright 2001-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2001-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 /*
@@ -51,9 +60,6 @@ static int glueMode;
 static BackendDB *glueBack;
 
 static slap_response glue_back_response;
-static slap_sresult glue_back_sresult;
-static slap_sendentry glue_back_sendentry;
-static slap_sendreference glue_back_sendreference;
 
 /* Just like select_backend, but only for our backends */
 static BackendDB *
@@ -171,7 +177,6 @@ glue_back_db_destroy (
 
 typedef struct glue_state {
        int err;
-       int nentries;
        int matchlen;
        char *matched;
        int nrefs;
@@ -179,89 +184,62 @@ typedef struct glue_state {
        slap_callback *prevcb;
 } glue_state;
 
-static void
+static int
 glue_back_response ( Operation *op, SlapReply *rs )
 {
        glue_state *gs = op->o_callback->sc_private;
+       slap_callback *tmp = op->o_callback;
 
-       if (rs->sr_err == LDAP_SUCCESS || gs->err != LDAP_SUCCESS)
-               gs->err = rs->sr_err;
-       if (gs->err == LDAP_SUCCESS && gs->matched) {
-               ch_free (gs->matched);
-               gs->matched = NULL;
-               gs->matchlen = 0;
-       }
-       if (gs->err != LDAP_SUCCESS && rs->sr_matched) {
-               int len;
-               len = strlen (rs->sr_matched);
-               if (len > gs->matchlen) {
-                       if (gs->matched)
-                               ch_free (gs->matched);
-                       gs->matched = ch_strdup (rs->sr_matched);
-                       gs->matchlen = len;
-               }
-       }
-       if (rs->sr_ref) {
-               int i, j, k;
-               BerVarray new;
-
-               for (i=0; rs->sr_ref[i].bv_val; i++);
+       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;
 
-               j = gs->nrefs;
-               if (!j) {
-                       new = ch_malloc ((i+1)*sizeof(struct berval));
-               } else {
-                       new = ch_realloc(gs->refs,
-                               (j+i+1)*sizeof(struct berval));
+       default:
+               if (rs->sr_err == LDAP_SUCCESS || gs->err != LDAP_SUCCESS)
+                       gs->err = rs->sr_err;
+               if (gs->err == LDAP_SUCCESS && gs->matched) {
+                       ch_free (gs->matched);
+                       gs->matched = NULL;
+                       gs->matchlen = 0;
                }
-               for (k=0; k<i; j++,k++) {
-                       ber_dupbv( &new[j], &rs->sr_ref[k] );
+               if (gs->err != LDAP_SUCCESS && rs->sr_matched) {
+                       int len;
+                       len = strlen (rs->sr_matched);
+                       if (len > gs->matchlen) {
+                               if (gs->matched)
+                                       ch_free (gs->matched);
+                               gs->matched = ch_strdup (rs->sr_matched);
+                               gs->matchlen = len;
+                       }
                }
-               new[j].bv_val = NULL;
-               gs->nrefs = j;
-               gs->refs = new;
-       }
-}
+               if (rs->sr_ref) {
+                       int i, j, k;
+                       BerVarray new;
 
-static void
-glue_back_sresult ( Operation *op, SlapReply *rs )
-{
-       glue_state *gs = op->o_callback->sc_private;
-
-       gs->nentries += rs->sr_nentries;
-       glue_back_response( op, rs );
-}
+                       for (i=0; rs->sr_ref[i].bv_val; i++);
 
-static int
-glue_back_sendentry ( Operation *op, SlapReply *rs )
-{
-       slap_callback *tmp = op->o_callback;
-       glue_state *gs = tmp->sc_private;
-
-       op->o_callback = gs->prevcb;
-       if (op->o_callback && op->o_callback->sc_sendentry) {
-               rs->sr_err = op->o_callback->sc_sendentry(op, rs);
-       } else {
-               rs->sr_err = send_search_entry(op, rs);
-       }
-       op->o_callback = tmp;
-       return rs->sr_err;
-}
-
-static int
-glue_back_sendreference ( Operation *op, SlapReply *rs )
-{
-       slap_callback *tmp = op->o_callback;
-       glue_state *gs = tmp->sc_private;
-
-       op->o_callback = gs->prevcb;
-       if (op->o_callback && op->o_callback->sc_sendreference) {
-               rs->sr_err = op->o_callback->sc_sendreference( op, rs );
-       } else {
-               rs->sr_err = send_search_reference( op, rs );
+                       j = gs->nrefs;
+                       if (!j) {
+                               new = ch_malloc ((i+1)*sizeof(struct berval));
+                       } else {
+                               new = ch_realloc(gs->refs,
+                                       (j+i+1)*sizeof(struct berval));
+                       }
+                       for (k=0; k<i; j++,k++) {
+                               ber_dupbv( &new[j], &rs->sr_ref[k] );
+                       }
+                       new[j].bv_val = NULL;
+                       gs->nrefs = j;
+                       gs->refs = new;
+               }
        }
-       op->o_callback = tmp;
-       return rs->sr_err;
+       return 0;
 }
 
 static int
@@ -271,24 +249,20 @@ glue_back_search ( Operation *op, SlapReply *rs )
        glueinfo *gi = (glueinfo *) b0->bd_info;
        int i;
        long stoptime = 0;
-       glue_state gs = {0, 0, 0, NULL, 0, NULL, NULL};
-       slap_callback cb;
+       glue_state gs = {0, 0, NULL, 0, NULL, NULL};
+       slap_callback cb = { glue_back_response, NULL };
        int scope0, slimit0, tlimit0;
        struct berval dn, ndn;
 
-       cb.sc_response = glue_back_response;
-       cb.sc_sresult = glue_back_sresult;
-       cb.sc_sendentry = glue_back_sendentry;
-       cb.sc_sendreference = glue_back_sendreference;
        cb.sc_private = &gs;
 
        gs.prevcb = op->o_callback;
 
-       if (op->oq_search.rs_tlimit) {
-               stoptime = slap_get_time () + op->oq_search.rs_tlimit;
+       if (op->ors_tlimit) {
+               stoptime = slap_get_time () + op->ors_tlimit;
        }
 
-       switch (op->oq_search.rs_scope) {
+       switch (op->ors_scope) {
        case LDAP_SCOPE_BASE:
                op->o_bd = glue_back_select (b0, op->o_req_ndn.bv_val);
 
@@ -304,9 +278,9 @@ glue_back_search ( Operation *op, SlapReply *rs )
        case LDAP_SCOPE_SUBTREE:
                op->o_callback = &cb;
                rs->sr_err = gs.err = LDAP_UNWILLING_TO_PERFORM;
-               scope0 = op->oq_search.rs_scope;
-               slimit0 = op->oq_search.rs_slimit;
-               tlimit0 = op->oq_search.rs_tlimit;
+               scope0 = op->ors_scope;
+               slimit0 = op->ors_slimit;
+               tlimit0 = op->ors_tlimit;
                dn = op->o_req_dn;
                ndn = op->o_req_ndn;
 
@@ -317,15 +291,15 @@ glue_back_search ( Operation *op, SlapReply *rs )
                        if (!gi->n[i].be || !gi->n[i].be->be_search)
                                continue;
                        if (tlimit0) {
-                               op->oq_search.rs_tlimit = stoptime - slap_get_time ();
-                               if (op->oq_search.rs_tlimit <= 0) {
+                               op->ors_tlimit = stoptime - slap_get_time ();
+                               if (op->ors_tlimit <= 0) {
                                        rs->sr_err = gs.err = LDAP_TIMELIMIT_EXCEEDED;
                                        break;
                                }
                        }
                        if (slimit0) {
-                               op->oq_search.rs_slimit = slimit0 - gs.nentries;
-                               if (op->oq_search.rs_slimit <= 0) {
+                               op->ors_slimit = slimit0 - rs->sr_nentries;
+                               if (op->ors_slimit <= 0) {
                                        rs->sr_err = gs.err = LDAP_SIZELIMIT_EXCEEDED;
                                        break;
                                }
@@ -340,7 +314,7 @@ glue_back_search ( Operation *op, SlapReply *rs )
                        op->o_bd = gi->n[i].be;
                        if (scope0 == LDAP_SCOPE_ONELEVEL && 
                                dn_match(&gi->n[i].pdn, &ndn)) {
-                               op->oq_search.rs_scope = LDAP_SCOPE_BASE;
+                               op->ors_scope = LDAP_SCOPE_BASE;
                                op->o_req_dn = op->o_bd->be_suffix[0];
                                op->o_req_ndn = op->o_bd->be_nsuffix[0];
                                rs->sr_err = op->o_bd->be_search(op, rs);
@@ -371,9 +345,9 @@ glue_back_search ( Operation *op, SlapReply *rs )
                        }
                }
 end_of_loop:;
-               op->oq_search.rs_scope = scope0;
-               op->oq_search.rs_slimit = slimit0;
-               op->oq_search.rs_tlimit = tlimit0;
+               op->ors_scope = scope0;
+               op->ors_slimit = slimit0;
+               op->ors_tlimit = tlimit0;
                op->o_req_dn = dn;
                op->o_req_ndn = ndn;
 
@@ -383,9 +357,8 @@ end_of_loop:;
        rs->sr_err = gs.err;
        rs->sr_matched = gs.matched;
        rs->sr_ref = gs.refs;
-       rs->sr_nentries = gs.nentries;
 
-       send_search_result( op, rs );
+       send_ldap_result( op, rs );
 
 done:
        op->o_bd = b0;
@@ -623,6 +596,10 @@ glue_sub_init( )
                                bi->bi_tool_entry_put = glue_tool_entry_put;
                                bi->bi_tool_entry_reindex = glue_tool_entry_reindex;
                                bi->bi_tool_sync = glue_tool_sync;
+                               /* FIXME : will support later */
+                               bi->bi_tool_dn2id_get = 0;
+                               bi->bi_tool_id2entry_get = 0;
+                               bi->bi_tool_entry_modify = 0;
                        } else {
                                gi = (glueinfo *)ch_realloc(gi,
                                        sizeof(glueinfo) +
@@ -639,7 +616,7 @@ glue_sub_init( )
                        gi->n[gi->nodes].be = &gi->bd;
                        dnParent( &b1->be_nsuffix[0], &gi->n[gi->nodes].pdn );
                        gi->nodes++;
-                       b1->bd_info = bi;
+                       b1->bd_info = (BackendInfo *)gi;
                }
        }
        /* If there are any unresolved subordinates left, something is wrong */