]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_compare.c
#unifdef -DSLAP_NVALUES_ON_DISK
[openldap] / servers / slapd / back-tcl / tcl_compare.c
1 /* $OpenLDAP$ */
2 /* compare.c - tcl compare routines
3  *
4  * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15
16 #include "slap.h"
17 #include "tcl_back.h"
18
19 int
20 tcl_back_compare (
21         Operation * op,
22         SlapReply * rs
23 )
24 {
25         char *command, *results;
26         struct berval suf_tcl;
27         int code;
28         struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
29
30         if (ti->ti_compare.bv_len == 0) {
31                 send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
32                         "compare not implemented" );
33                 return (-1);
34         }
35
36         if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
37                 send_ldap_error (op, rs, LDAP_OTHER, NULL );
38                 return (-1);
39         }
40
41         command = (char *) ch_malloc (ti->ti_compare.bv_len +
42                 suf_tcl.bv_len + op->o_req_dn.bv_len + op->oq_compare.rs_ava->aa_desc->ad_cname.bv_len +
43                 op->oq_compare.rs_ava->aa_value.bv_len + 84);
44         sprintf (command, "%s COMPARE {%ld/%ld} {%s} {%s} {%s: %s}",
45                 ti->ti_compare.bv_val, op->o_connid, (long) op->o_msgid,
46                 suf_tcl.bv_val, op->o_req_dn.bv_val,
47                 op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val, op->oq_compare.rs_ava->aa_value.bv_val);
48         Tcl_Free (suf_tcl.bv_val);
49
50         ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
51         code = Tcl_GlobalEval (ti->ti_ii->interp, command);
52         results = (char *) ch_strdup (ti->ti_ii->interp->result);
53         ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
54         free (command);
55
56         if (code != TCL_OK) {
57                 rs->sr_err = LDAP_OTHER;
58                 Debug (LDAP_DEBUG_SHELL, "tcl_compare_error: %s\n", results,
59                         0, 0);
60         } else {
61                 interp_send_results (op, rs, results);
62         }
63
64         if (rs->sr_err != LDAP_SUCCESS) {
65                 rs->sr_text = "internal backend error";
66                 send_ldap_result (op, rs);
67         }
68
69         free (results);
70         return (rs->sr_err);
71 }