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