]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_init.c
Free IDL_CACHE locks
[openldap] / servers / slapd / back-tcl / tcl_init.c
1 /* $OpenLDAP$ */
2 /* tcl_init.c - tcl backend initialization
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 <ac/socket.h>
17
18 #include "slap.h"
19 #include "tcl_back.h"
20
21 ldap_pvt_thread_mutex_t tcl_interpreter_mutex;
22
23 #ifdef SLAPD_TCL_DYNAMIC
24
25 void back_tcl_LTX_init_module(int argc, char *argv[]) {
26    BackendInfo bi;
27
28    memset( &bi, '\0', sizeof(bi) );
29    bi.bi_type = "tcl";
30    bi.bi_init = tcl_back_initialize;
31
32    backend_add(&bi);
33 }
34
35 #endif /* SLAPD_TCL_DYNAMIC */
36
37 int
38 tcl_back_initialize (
39         BackendInfo * bi
40 )
41 {
42         /* Initialize the global interpreter array */
43         global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
44
45         global_i->count = 0;
46         global_i->name = "default";
47         global_i->next = NULL;
48         global_i->interp = Tcl_CreateInterp ();
49         Tcl_Init (global_i->interp);
50
51         /* Initialize the global interpreter lock */
52         ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
53
54         bi->bi_open = tcl_back_open;
55         bi->bi_config = 0;
56         bi->bi_close = tcl_back_close;
57         bi->bi_destroy = tcl_back_destroy;
58
59         bi->bi_db_init = tcl_back_db_init;
60         bi->bi_db_config = tcl_back_db_config;
61         bi->bi_db_open = tcl_back_db_open;
62         bi->bi_db_close = tcl_back_db_close;
63         bi->bi_db_destroy = tcl_back_db_destroy;
64
65         bi->bi_op_bind = tcl_back_bind;
66         bi->bi_op_unbind = tcl_back_unbind;
67         bi->bi_op_search = tcl_back_search;
68         bi->bi_op_compare = tcl_back_compare;
69         bi->bi_op_modify = tcl_back_modify;
70         bi->bi_op_modrdn = tcl_back_modrdn;
71         bi->bi_op_add = tcl_back_add;
72         bi->bi_op_delete = tcl_back_delete;
73         bi->bi_op_abandon = tcl_back_abandon;
74
75         bi->bi_chk_referrals = 0;
76
77         bi->bi_connection_init = 0;
78         bi->bi_connection_destroy = 0;
79
80         return 0;
81 }
82
83 int
84 tcl_back_open (
85         BackendInfo * bi
86 )
87 {
88         /* Initialize the global interpreter array */
89         global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
90
91         global_i->count = 0;
92         global_i->name = "default";
93         global_i->next = NULL;
94         global_i->interp = Tcl_CreateInterp ();
95         Tcl_Init (global_i->interp);
96
97         /* Initialize the global interpreter lock */
98         ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
99
100         return (0);
101 }
102
103 int
104 tcl_back_db_init (
105         Backend * be
106 )
107 {
108         struct tclinfo *ti;
109
110         ti = (struct tclinfo *) ch_calloc (1, sizeof (struct tclinfo));
111
112         ti->ti_script_path.bv_len = 0;
113         ti->ti_script_path.bv_val = NULL;
114
115         /*
116          * For some reason this causes problems
117          * specifically set to NULL
118          */
119         ti->ti_bind.bv_len = 0;
120         ti->ti_bind.bv_val = NULL;
121
122         ti->ti_unbind.bv_len = 0;
123         ti->ti_unbind.bv_val = NULL;
124
125         ti->ti_search.bv_len = 0;
126         ti->ti_search.bv_val = NULL;
127
128         ti->ti_compare.bv_len = 0;
129         ti->ti_compare.bv_val = NULL;
130
131         ti->ti_modify.bv_len = 0;
132         ti->ti_modify.bv_val = NULL;
133
134         ti->ti_modrdn.bv_len = 0;
135         ti->ti_modrdn.bv_val = NULL;
136
137         ti->ti_add.bv_len = 0;
138         ti->ti_add.bv_val = NULL;
139
140         ti->ti_delete.bv_len = 0;
141         ti->ti_delete.bv_val = NULL;
142
143         ti->ti_abandon.bv_len = 0;
144         ti->ti_abandon.bv_val = NULL;
145
146         be->be_private = ti;
147
148         return ti == NULL;
149 }
150
151 int
152 tcl_back_db_open (
153         BackendDB * bd
154 )
155 {
156         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
157
158         if (ti->ti_ii->interp == NULL) {        /* we need to make a new one */
159                 ti->ti_ii->interp = Tcl_CreateInterp ();
160                 Tcl_Init (ti->ti_ii->interp);
161         }
162
163         /* raise that count for the interpreter */
164         ti->ti_ii->count++;
165
166         /* now let's (try to) load the script */
167         readtclscript (ti->ti_script_path.bv_val, ti->ti_ii->interp);
168
169         /* install the debug command */
170         Tcl_CreateCommand (ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
171                 NULL, NULL);
172
173         return 0;
174 }