2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 1999 John C. Quillan.
6 * Portions Copyright 2002 myinternet Limited.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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"
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));
23 PerlInterpreter *PERL_INTERPRETER = NULL;
24 ldap_pvt_thread_mutex_t perl_interpreter_mutex;
27 /**********************************************************
31 **********************************************************/
38 bi->bi_open = perl_back_open;
40 bi->bi_close = perl_back_close;
43 bi->bi_db_init = perl_back_db_init;
44 bi->bi_db_config = perl_back_db_config;
45 bi->bi_db_open = perl_back_db_open;
47 bi->bi_db_destroy = perl_back_db_destroy;
49 bi->bi_op_bind = perl_back_bind;
51 bi->bi_op_search = perl_back_search;
52 bi->bi_op_compare = perl_back_compare;
53 bi->bi_op_modify = perl_back_modify;
54 bi->bi_op_modrdn = perl_back_modrdn;
55 bi->bi_op_add = perl_back_add;
56 bi->bi_op_delete = perl_back_delete;
57 bi->bi_op_abandon = 0;
61 bi->bi_chk_referrals = 0;
63 bi->bi_connection_init = 0;
64 bi->bi_connection_destroy = 0;
74 char *embedding[] = { "", "-e", "0" };
76 Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
78 if( PERL_INTERPRETER != NULL ) {
79 Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
84 ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
86 PERL_INTERPRETER = perl_alloc();
87 perl_construct(PERL_INTERPRETER);
88 perl_parse(PERL_INTERPRETER, perl_back_xs_init, 3, embedding, (char **)NULL);
89 perl_run(PERL_INTERPRETER);
98 be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
99 memset( be->be_private, '\0', sizeof(PerlBackend));
101 ((PerlBackend *)be->be_private)->pb_filter_search_results = 0;
103 Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
116 PerlBackend *perl_back = (PerlBackend *) be->be_private;
118 ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
121 dSP; ENTER; SAVETMPS;
124 XPUSHs( perl_back->pb_obj_ref );
129 count = call_method("init", G_SCALAR);
131 count = perl_call_method("init", G_SCALAR);
137 croak("Big trouble in perl_back_db_open\n");
142 PUTBACK; FREETMPS; LEAVE;
145 ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
152 perl_back_xs_init(PERL_BACK_XS_INIT_PARAMS)
154 char *file = __FILE__;
156 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
159 #if SLAPD_PERL == SLAPD_MOD_DYNAMIC
161 /* conditionally define the init_module() function */
162 SLAP_BACKEND_INIT_MODULE( perl )
164 #endif /* SLAPD_PERL == SLAPD_MOD_DYNAMIC */