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