]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_compare.c
Style changes, added cvs keywords
[openldap] / servers / slapd / back-tcl / tcl_compare.c
1 /*
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  * $Id$
12  *
13  * $Log$
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include "slap.h"
21 #include "tcl_back.h"
22
23 int
24 tcl_back_compare (
25         Backend * be,
26         Connection * conn,
27         Operation * op,
28         char *dn,
29         Ava * ava
30 )
31 {
32         char *command, *suf_tcl, *results;
33         int i, code, err = 0;
34         struct tclinfo *ti = (struct tclinfo *) be->be_private;
35
36         if (ti->ti_compare == NULL) {
37                 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
38                         "compare not implemented");
39                 return (-1);
40         }
41
42         for ( i = 0; be->be_suffix[i] != NULL; i++ )
43                 ;
44         suf_tcl = Tcl_Merge(i, be->be_suffix);
45
46         command = (char *) ch_malloc (strlen(ti->ti_compare) +
47                 strlen(suf_tcl) + strlen(dn) + strlen(ava->ava_type) +
48                 strlen(ava->ava_value.bv_val) + 64);
49         sprintf(command, "%s COMPARE {%ld} {%s} {%s} {%s: %s}",
50                 ti->ti_compare, op->o_msgid, suf_tcl, dn, ava->ava_type,
51         ava->ava_value.bv_val);
52         Tcl_Free(suf_tcl);
53
54         ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex );
55         code = Tcl_GlobalEval(ti->ti_ii->interp, command);
56         results = (char *) strdup(ti->ti_ii->interp->result);
57         ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex );
58         free(command);
59
60         if (code != TCL_OK) {
61                 err = LDAP_OPERATIONS_ERROR;
62                 Debug(LDAP_DEBUG_ANY, "tcl_compare_error: %s\n", results, 0, 0);
63         } else {
64                 interp_send_results ( be, conn, op, results, NULL, 0 );
65         }
66
67         if (err != LDAP_SUCCESS)
68                 send_ldap_result (conn, op, err, NULL, "internal backend error");
69         return (0);
70
71 }