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