]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_init.c
Completed open/close/destroy implementations
[openldap] / servers / slapd / back-tcl / tcl_init.c
1 /*
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  * $Id: tcl_init.c,v 1.2 1999/02/17 00:55:54 bcollins Exp $
12  *
13  * $Log: tcl_init.c,v $
14  * Revision 1.2  1999/02/17 00:55:54  bcollins
15  * Implemented the open, init functions correctly
16  *
17  */
18
19 #include "portable.h"
20
21 #include <stdio.h>
22
23 #include <ac/socket.h>
24
25 #include "slap.h"
26 #include "tcl_back.h"
27
28 ldap_pvt_thread_mutex_t tcl_interpreter_mutex;
29
30 int
31 tcl_back_initialize(
32         BackendInfo     *bi
33 )
34 {
35         /* Initialize the global interpreter array */
36         global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
37         global_i->count = 0;
38         global_i->name = "default";
39         global_i->next = NULL;
40         global_i->interp = Tcl_CreateInterp ();
41         Tcl_Init (global_i->interp);
42
43         /* Initialize the global interpreter lock */
44         ldap_pvt_thread_mutex_init( &tcl_interpreter_mutex );
45
46         bi->bi_open = tcl_back_open;
47         bi->bi_config = NULL;
48         bi->bi_close = tcl_back_close;
49         bi->bi_destroy = tcl_back_destroy;
50
51         bi->bi_db_init = tcl_back_db_init;
52         bi->bi_db_config = tcl_back_db_config;
53         bi->bi_db_open = tcl_back_db_open;
54         bi->bi_db_close = tcl_back_db_close;
55         bi->bi_db_destroy = tcl_back_db_destroy;
56
57         bi->bi_op_bind = tcl_back_bind;
58         bi->bi_op_unbind = tcl_back_unbind;
59         bi->bi_op_search = tcl_back_search;
60         bi->bi_op_compare = tcl_back_compare;
61         bi->bi_op_modify = tcl_back_modify;
62         bi->bi_op_modrdn = tcl_back_modrdn;
63         bi->bi_op_add = tcl_back_add;
64         bi->bi_op_delete = tcl_back_delete;
65         bi->bi_op_abandon = tcl_back_abandon;
66
67         bi->bi_acl_group = NULL;
68
69         return 0;
70 }
71
72 int
73 tcl_back_open(
74         BackendInfo     *bi
75 )
76 {
77         /* Initialize the global interpreter array */
78         global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
79         global_i->count = 0;
80         global_i->name = "default";
81         global_i->next = NULL;
82         global_i->interp = Tcl_CreateInterp ();
83         Tcl_Init (global_i->interp);
84
85         /* Initialize the global interpreter lock */
86         ldap_pvt_thread_mutex_init( &tcl_interpreter_mutex );
87
88         return( 0 );
89 }
90
91 int
92 tcl_back_db_init(
93         Backend *be
94 )
95 {
96         struct tclinfo  *ti;
97
98         ti = (struct tclinfo *) ch_calloc( 1, sizeof(struct tclinfo) );
99
100         /*
101          * For some reason this causes problems
102          * specifically set to NULL
103          */
104         ti->ti_bind = NULL;
105         ti->ti_unbind = NULL;
106         ti->ti_search = NULL;
107         ti->ti_compare = NULL;
108         ti->ti_modify = NULL;
109         ti->ti_modrdn = NULL;
110         ti->ti_add = NULL;
111         ti->ti_delete = NULL;
112         ti->ti_abandon = NULL;
113
114         be->be_private = ti;
115
116         return ti == NULL;
117 }
118
119 int tcl_back_db_open (
120         BackendDB * bd
121 )
122 {
123         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
124
125         if (ti->ti_ii->interp == NULL) { /* we need to make a new one */
126                 ti->ti_ii->interp = Tcl_CreateInterp ();
127                 Tcl_Init (ti->interp);
128         }
129
130         /* raise that count for the interpreter */
131         ti->ti_ii->count++;
132
133         /* now let's (try to) load the script */
134         readtclscript (ti->script_path, ti->ti_ii->interp);
135
136         /* Intall the debug command */
137         Tcl_CreateCommand( ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
138                 NULL, NULL);
139
140         return 0;
141 }