]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_init.c
04e1b4c120ff29a5ca6747d5b3847b5c93684797
[openldap] / servers / slapd / back-tcl / tcl_init.c
1 /* tcl_init.c - tcl backend initialization
2  *
3  * $Id: tcl_init.c,v 1.7 1999/06/23 10:31:37 bastiaan Exp $
4  *
5  * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted only
8  * as authorized by the OpenLDAP Public License.  A copy of this
9  * license is available at http://www.OpenLDAP.org/license.html or
10  * in file LICENSE in the top-level directory of the distribution.
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/socket.h>
18
19 #include "slap.h"
20 #include "tcl_back.h"
21
22 ldap_pvt_thread_mutex_t tcl_interpreter_mutex;
23
24 #ifdef SLAPD_TCL_DYNAMIC
25 #include <gmodule.h>
26
27 G_MODULE_EXPORT void init_module(int argc, char *argv[]) {
28    BackendInfo bi;
29
30    bi.bi_type = "tcl";
31    bi.bi_init = tcl_back_initialize;
32
33    backend_add(&bi);
34 }
35
36 #endif /* SLAPD_TCL_DYNAMIC */
37
38 int
39 tcl_back_initialize (
40         BackendInfo * bi
41 )
42 {
43         /* Initialize the global interpreter array */
44         global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
45
46         global_i->count = 0;
47         global_i->name = "default";
48         global_i->next = NULL;
49         global_i->interp = Tcl_CreateInterp ();
50         Tcl_Init (global_i->interp);
51
52         /* Initialize the global interpreter lock */
53         ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
54
55         bi->bi_open = tcl_back_open;
56         bi->bi_config = 0;
57         bi->bi_close = tcl_back_close;
58         bi->bi_destroy = tcl_back_destroy;
59
60         bi->bi_db_init = tcl_back_db_init;
61         bi->bi_db_config = tcl_back_db_config;
62         bi->bi_db_open = tcl_back_db_open;
63         bi->bi_db_close = tcl_back_db_close;
64         bi->bi_db_destroy = tcl_back_db_destroy;
65
66         bi->bi_op_bind = tcl_back_bind;
67         bi->bi_op_unbind = tcl_back_unbind;
68         bi->bi_op_search = tcl_back_search;
69         bi->bi_op_compare = tcl_back_compare;
70         bi->bi_op_modify = tcl_back_modify;
71         bi->bi_op_modrdn = tcl_back_modrdn;
72         bi->bi_op_add = tcl_back_add;
73         bi->bi_op_delete = tcl_back_delete;
74         bi->bi_op_abandon = tcl_back_abandon;
75
76 #ifdef SLAPD_ACLGROUPS
77         bi->bi_acl_group = 0;
78 #endif
79
80         bi->bi_connection_init = 0;
81         bi->bi_connection_destroy = 0;
82
83         return 0;
84 }
85
86 int
87 tcl_back_open (
88         BackendInfo * bi
89 )
90 {
91         /* Initialize the global interpreter array */
92         global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
93
94         global_i->count = 0;
95         global_i->name = "default";
96         global_i->next = NULL;
97         global_i->interp = Tcl_CreateInterp ();
98         Tcl_Init (global_i->interp);
99
100         /* Initialize the global interpreter lock */
101         ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
102
103         return (0);
104 }
105
106 int
107 tcl_back_db_init (
108         Backend * be
109 )
110 {
111         struct tclinfo *ti;
112
113         ti = (struct tclinfo *) ch_calloc (1, sizeof (struct tclinfo));
114
115         /*
116          * For some reason this causes problems
117          * specifically set to NULL
118          */
119         ti->ti_bind = NULL;
120         ti->ti_unbind = NULL;
121         ti->ti_search = NULL;
122         ti->ti_compare = NULL;
123         ti->ti_modify = NULL;
124         ti->ti_modrdn = NULL;
125         ti->ti_add = NULL;
126         ti->ti_delete = NULL;
127         ti->ti_abandon = NULL;
128
129         be->be_private = ti;
130
131         return ti == NULL;
132 }
133
134 int
135 tcl_back_db_open (
136         BackendDB * bd
137 )
138 {
139         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
140
141         if (ti->ti_ii->interp == NULL) {        /* we need to make a new one */
142                 ti->ti_ii->interp = Tcl_CreateInterp ();
143                 Tcl_Init (ti->ti_ii->interp);
144         }
145
146         /* raise that count for the interpreter */
147         ti->ti_ii->count++;
148
149         /* now let's (try to) load the script */
150         readtclscript (ti->script_path, ti->ti_ii->interp);
151
152         /* Intall the debug command */
153         Tcl_CreateCommand (ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
154                 NULL, NULL);
155
156         return 0;
157 }