]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_delete.c
5b9a60ace4e8e5b3c7971df491f1018c8353870a
[openldap] / servers / slapd / back-tcl / tcl_delete.c
1 /*
2  * delete.c - tcl delete 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 tcl_back_delete (
24         Backend * be,
25         Connection * conn,
26         Operation * op,
27         char *dn
28 )
29 {
30         char *command, *suf_tcl, *results;
31         int i, code, err = 0;
32         struct tclinfo *ti = (struct tclinfo *) be->be_private;
33
34         if (ti->ti_delete == NULL) {
35                 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
36                         "delete not implemented");
37                 return (-1);
38         }
39
40         for ( i = 0; be->be_suffix[i] != NULL; i++ )
41                 ;
42         suf_tcl = Tcl_Merge(i, be->be_suffix);
43
44         command = (char *) ch_malloc (strlen(ti->ti_delete) + strlen(suf_tcl)
45                 + strlen(dn) + 64);
46         sprintf(command, "%s DELETE {%ld} {%s} {%s}",
47                 ti->ti_delete, op->o_msgid, suf_tcl, dn);
48         Tcl_Free(suf_tcl);
49
50         ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex );
51         code = Tcl_GlobalEval(ti->ti_ii->interp, command);
52         results = (char *) 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                 err = LDAP_OPERATIONS_ERROR;
58                 Debug(LDAP_DEBUG_ANY, "tcl_delete_error: %s\n", results, 0, 0);
59         } else {
60                 interp_send_results ( be, conn, op, results, NULL, 0 );
61         }
62
63         if (err != LDAP_SUCCESS)
64                 send_ldap_result (conn, op, err, NULL, "internal backend error");
65
66         return (0);
67 }