]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/init.c
Happy New Year!
[openldap] / servers / slapd / back-perl / init.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2005 The OpenLDAP Foundation.
5  * Portions Copyright 1999 John C. Quillan.
6  * Portions Copyright 2002 myinternet Limited.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17
18 #include "perl_back.h"
19
20 static void perl_back_xs_init LDAP_P((PERL_BACK_XS_INIT_PARAMS));
21 EXT void boot_DynaLoader LDAP_P((PERL_BACK_BOOT_DYNALOADER_PARAMS));
22
23 PerlInterpreter *PERL_INTERPRETER = NULL;
24 ldap_pvt_thread_mutex_t perl_interpreter_mutex;
25
26
27 /**********************************************************
28  *
29  * Init
30  *
31  **********************************************************/
32
33 int
34 perl_back_initialize(
35         BackendInfo     *bi
36 )
37 {
38         char *embedding[] = { "", "-e", "0" };
39
40         Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
41
42         if( PERL_INTERPRETER != NULL ) {
43                 Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
44                         0, 0, 0 );
45                 return 1;
46         }
47         
48         PERL_INTERPRETER = perl_alloc();
49         perl_construct(PERL_INTERPRETER);
50         perl_parse(PERL_INTERPRETER, perl_back_xs_init, 3, embedding, (char **)NULL);
51         perl_run(PERL_INTERPRETER);
52
53         bi->bi_open = perl_back_open;
54         bi->bi_config = 0;
55         bi->bi_close = perl_back_close;
56         bi->bi_destroy = perl_back_destroy;
57
58         bi->bi_db_init = perl_back_db_init;
59         bi->bi_db_config = perl_back_db_config;
60         bi->bi_db_open = perl_back_db_open;
61         bi->bi_db_close = 0;
62         bi->bi_db_destroy = perl_back_db_destroy;
63
64         bi->bi_op_bind = perl_back_bind;
65         bi->bi_op_unbind = 0;
66         bi->bi_op_search = perl_back_search;
67         bi->bi_op_compare = perl_back_compare;
68         bi->bi_op_modify = perl_back_modify;
69         bi->bi_op_modrdn = perl_back_modrdn;
70         bi->bi_op_add = perl_back_add;
71         bi->bi_op_delete = perl_back_delete;
72         bi->bi_op_abandon = 0;
73
74         bi->bi_extended = 0;
75
76         bi->bi_chk_referrals = 0;
77
78         bi->bi_connection_init = 0;
79         bi->bi_connection_destroy = 0;
80
81         return 0;
82 }
83                 
84 int
85 perl_back_open(
86         BackendInfo     *bi
87 )
88 {
89         ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
90         return 0;
91 }
92
93 int
94 perl_back_db_init(
95         BackendDB       *be
96 )
97 {
98         be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
99         memset( be->be_private, '\0', sizeof(PerlBackend));
100
101         ((PerlBackend *)be->be_private)->pb_filter_search_results = 0;
102
103         Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
104
105         return 0;
106 }
107
108 int
109 perl_back_db_open(
110         BackendDB       *be
111 )
112 {
113         int count;
114         int return_code;
115
116         PerlBackend *perl_back = (PerlBackend *) be->be_private;
117
118         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
119
120         {
121                 dSP; ENTER; SAVETMPS;
122
123                 PUSHMARK(sp);
124                 XPUSHs( perl_back->pb_obj_ref );
125
126                 PUTBACK;
127
128 #ifdef PERL_IS_5_6
129                 count = call_method("init", G_SCALAR);
130 #else
131                 count = perl_call_method("init", G_SCALAR);
132 #endif
133
134                 SPAGAIN;
135
136                 if (count != 1) {
137                         croak("Big trouble in perl_back_db_open\n");
138                 }
139
140                 return_code = POPi;
141
142                 PUTBACK; FREETMPS; LEAVE;
143         }
144
145         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
146
147         return return_code;
148 }
149
150
151 static void
152 perl_back_xs_init(PERL_BACK_XS_INIT_PARAMS)
153 {
154         char *file = __FILE__;
155         dXSUB_SYS;
156         newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
157 }
158
159 #if SLAPD_PERL == SLAPD_MOD_DYNAMIC
160
161 /* conditionally define the init_module() function */
162 SLAP_BACKEND_INIT_MODULE( perl )
163
164 #endif /* SLAPD_PERL == SLAPD_MOD_DYNAMIC */
165
166