Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-perl / init.c
blobca6f75260881fb916c8c462fab11dcf7a3e72b3f
1 /* $OpenLDAP: pkg/ldap/servers/slapd/back-perl/init.c,v 1.44.2.4 2008/02/11 23:26:47 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2008 The OpenLDAP Foundation.
5 * Portions Copyright 1999 John C. Quillan.
6 * Portions Copyright 2002 myinternet Limited.
7 * All rights reserved.
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.
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>.
18 #include "perl_back.h"
19 #include "../config.h"
21 static void perl_back_xs_init LDAP_P((PERL_BACK_XS_INIT_PARAMS));
22 EXT void boot_DynaLoader LDAP_P((PERL_BACK_BOOT_DYNALOADER_PARAMS));
24 PerlInterpreter *PERL_INTERPRETER = NULL;
25 ldap_pvt_thread_mutex_t perl_interpreter_mutex;
28 /**********************************************************
30 * Init
32 **********************************************************/
34 int
35 perl_back_initialize(
36 BackendInfo *bi
39 char *embedding[] = { "", "-e", "0" };
41 bi->bi_open = NULL;
42 bi->bi_config = 0;
43 bi->bi_close = perl_back_close;
44 bi->bi_destroy = 0;
46 bi->bi_db_init = perl_back_db_init;
47 bi->bi_db_config = perl_back_db_config;
48 bi->bi_db_open = perl_back_db_open;
49 bi->bi_db_close = 0;
50 bi->bi_db_destroy = perl_back_db_destroy;
52 bi->bi_op_bind = perl_back_bind;
53 bi->bi_op_unbind = 0;
54 bi->bi_op_search = perl_back_search;
55 bi->bi_op_compare = perl_back_compare;
56 bi->bi_op_modify = perl_back_modify;
57 bi->bi_op_modrdn = perl_back_modrdn;
58 bi->bi_op_add = perl_back_add;
59 bi->bi_op_delete = perl_back_delete;
60 bi->bi_op_abandon = 0;
62 bi->bi_extended = 0;
64 bi->bi_chk_referrals = 0;
66 bi->bi_connection_init = 0;
67 bi->bi_connection_destroy = 0;
69 /* injecting code from perl_back_open, because using fonction reference (bi->bi_open) is not functional */
70 Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
72 if( PERL_INTERPRETER != NULL ) {
73 Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
74 0, 0, 0 );
75 return 1;
78 ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
80 PERL_INTERPRETER = perl_alloc();
81 perl_construct(PERL_INTERPRETER);
82 perl_parse(PERL_INTERPRETER, perl_back_xs_init, 3, embedding, (char **)NULL);
83 perl_run(PERL_INTERPRETER);
84 return 0;
87 int
88 perl_back_db_init(
89 BackendDB *be,
90 ConfigReply *cr
93 be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
94 memset( be->be_private, '\0', sizeof(PerlBackend));
96 ((PerlBackend *)be->be_private)->pb_filter_search_results = 0;
98 Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
100 return 0;
104 perl_back_db_open(
105 BackendDB *be,
106 ConfigReply *cr
109 int count;
110 int return_code;
112 PerlBackend *perl_back = (PerlBackend *) be->be_private;
114 ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
117 dSP; ENTER; SAVETMPS;
119 PUSHMARK(sp);
120 XPUSHs( perl_back->pb_obj_ref );
122 PUTBACK;
124 #ifdef PERL_IS_5_6
125 count = call_method("init", G_SCALAR);
126 #else
127 count = perl_call_method("init", G_SCALAR);
128 #endif
130 SPAGAIN;
132 if (count != 1) {
133 croak("Big trouble in perl_back_db_open\n");
136 return_code = POPi;
138 PUTBACK; FREETMPS; LEAVE;
141 ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
143 return return_code;
147 static void
148 perl_back_xs_init(PERL_BACK_XS_INIT_PARAMS)
150 char *file = __FILE__;
151 dXSUB_SYS;
152 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
155 #if SLAPD_PERL == SLAPD_MOD_DYNAMIC
157 /* conditionally define the init_module() function */
158 SLAP_BACKEND_INIT_MODULE( perl )
160 #endif /* SLAPD_PERL == SLAPD_MOD_DYNAMIC */