]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/init.c
remove dbenv->lock_put() call from transaction-protected operations
[openldap] / servers / slapd / back-perl / init.c
1 /* $OpenLDAP$ */
2 /*
3  *       Copyright 1999, John C. Quillan, All rights reserved.
4  *       Portions Copyright 2002, myinternet Limited. 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
12 #include "portable.h"
13  /* init.c - initialize shell backend */
14         
15 #include <stdio.h>
16
17 #include "slap.h"
18 #ifdef HAVE_WIN32_ASPERL
19 #include "asperl_undefs.h"
20 #endif
21
22 #include <EXTERN.h>
23 #include <XSUB.h>
24 #include <perl.h>
25
26 #include "perl_back.h"
27
28
29 static void perl_back_xs_init LDAP_P((PERL_BACK_XS_INIT_PARAMS));
30 EXT void boot_DynaLoader LDAP_P((PERL_BACK_BOOT_DYNALOADER_PARAMS));
31
32 PerlInterpreter *PERL_INTERPRETER = NULL;
33 ldap_pvt_thread_mutex_t perl_interpreter_mutex;
34
35 #ifdef SLAPD_PERL_DYNAMIC
36
37 int back_perl_LTX_init_module(int argc, char *argv[])
38 {
39         BackendInfo bi;
40
41         memset( &bi, '\0', sizeof(bi) );
42         bi.bi_type = "perl";
43         bi.bi_init = perl_back_initialize;
44
45         backend_add(&bi);
46         return 0;
47 }
48
49 #endif /* SLAPD_PERL_DYNAMIC */
50
51
52 /**********************************************************
53  *
54  * Init
55  *
56  **********************************************************/
57
58 int
59 perl_back_initialize(
60         BackendInfo     *bi
61 )
62 {
63         char *embedding[] = { "", "-e", "0" };
64
65         Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
66
67         if( PERL_INTERPRETER != NULL ) {
68                 Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
69                         0, 0, 0 );
70                 return 1;
71         }
72         
73         PERL_INTERPRETER = perl_alloc();
74         perl_construct(PERL_INTERPRETER);
75         perl_parse(PERL_INTERPRETER, perl_back_xs_init, 3, embedding, (char **)NULL);
76         perl_run(PERL_INTERPRETER);
77
78         bi->bi_open = perl_back_open;
79         bi->bi_config = 0;
80         bi->bi_close = perl_back_close;
81         bi->bi_destroy = perl_back_destroy;
82
83         bi->bi_db_init = perl_back_db_init;
84         bi->bi_db_config = perl_back_db_config;
85         bi->bi_db_open = perl_back_db_open;
86         bi->bi_db_close = 0;
87         bi->bi_db_destroy = perl_back_db_destroy;
88
89         bi->bi_op_bind = perl_back_bind;
90         bi->bi_op_unbind = 0;
91         bi->bi_op_search = perl_back_search;
92         bi->bi_op_compare = perl_back_compare;
93         bi->bi_op_modify = perl_back_modify;
94         bi->bi_op_modrdn = perl_back_modrdn;
95         bi->bi_op_add = perl_back_add;
96         bi->bi_op_delete = perl_back_delete;
97         bi->bi_op_abandon = 0;
98
99         bi->bi_extended = 0;
100
101         bi->bi_acl_group = 0;
102         bi->bi_acl_attribute = 0;
103         bi->bi_chk_referrals = 0;
104
105         bi->bi_connection_init = 0;
106         bi->bi_connection_destroy = 0;
107
108         return 0;
109 }
110                 
111 int
112 perl_back_open(
113         BackendInfo     *bi
114 )
115 {
116         ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
117         return 0;
118 }
119
120 int
121 perl_back_db_init(
122         BackendDB       *be
123 )
124 {
125         be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
126         memset( be->be_private, '\0', sizeof(PerlBackend));
127
128         ((PerlBackend *)be->be_private)->pb_filter_search_results = 0;
129
130         Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
131
132         return 0;
133 }
134
135 int
136 perl_back_db_open(
137         BackendDB       *be
138 )
139 {
140         int count;
141         int return_code;
142
143         PerlBackend *perl_back = (PerlBackend *) be->be_private;
144
145         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
146
147         {
148                 dSP; ENTER; SAVETMPS;
149
150                 PUSHMARK(sp);
151                 XPUSHs( perl_back->pb_obj_ref );
152
153                 PUTBACK;
154
155 #ifdef PERL_IS_5_6
156                 count = call_method("init", G_SCALAR);
157 #else
158                 count = perl_call_method("init", G_SCALAR);
159 #endif
160
161                 SPAGAIN;
162
163                 if (count != 1) {
164                         croak("Big trouble in perl_back_db_open\n");
165                 }
166
167                 return_code = POPi;
168
169                 PUTBACK; FREETMPS; LEAVE;
170         }
171
172         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
173
174         return return_code;
175 }
176
177
178 static void
179 perl_back_xs_init()
180 {
181         char *file = __FILE__;
182         dXSUB_SYS;
183         newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
184 }