Back to index

openldap  2.4.31
init.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1999-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 1999 John C. Quillan.
00006  * Portions Copyright 2002 myinternet Limited.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 
00018 #include "perl_back.h"
00019 #include "../config.h"
00020 
00021 #ifdef PERL_SYS_INIT3
00022 #include <ac/unistd.h>             /* maybe get environ */
00023 extern char **environ;
00024 #endif
00025 
00026 static void perl_back_xs_init LDAP_P((PERL_BACK_XS_INIT_PARAMS));
00027 EXT void boot_DynaLoader LDAP_P((PERL_BACK_BOOT_DYNALOADER_PARAMS));
00028 
00029 PerlInterpreter *PERL_INTERPRETER = NULL;
00030 ldap_pvt_thread_mutex_t     perl_interpreter_mutex;
00031 
00032 
00033 /**********************************************************
00034  *
00035  * Init
00036  *
00037  **********************************************************/
00038 
00039 int
00040 perl_back_initialize(
00041        BackendInfo   *bi
00042 )
00043 {
00044        char *embedding[] = { "", "-e", "0", NULL }, **argv = embedding;
00045        int argc = 3;
00046 #ifdef PERL_SYS_INIT3
00047        char **env = environ;
00048 #else
00049        char **env = NULL;
00050 #endif
00051 
00052        bi->bi_open = NULL;
00053        bi->bi_config = 0;
00054        bi->bi_close = perl_back_close;
00055        bi->bi_destroy = 0;
00056 
00057        bi->bi_db_init = perl_back_db_init;
00058        bi->bi_db_config = perl_back_db_config;
00059        bi->bi_db_open = perl_back_db_open;
00060        bi->bi_db_close = 0;
00061        bi->bi_db_destroy = perl_back_db_destroy;
00062 
00063        bi->bi_op_bind = perl_back_bind;
00064        bi->bi_op_unbind = 0;
00065        bi->bi_op_search = perl_back_search;
00066        bi->bi_op_compare = perl_back_compare;
00067        bi->bi_op_modify = perl_back_modify;
00068        bi->bi_op_modrdn = perl_back_modrdn;
00069        bi->bi_op_add = perl_back_add;
00070        bi->bi_op_delete = perl_back_delete;
00071        bi->bi_op_abandon = 0;
00072 
00073        bi->bi_extended = 0;
00074 
00075        bi->bi_chk_referrals = 0;
00076 
00077        bi->bi_connection_init = 0;
00078        bi->bi_connection_destroy = 0;
00079 
00080        /* injecting code from perl_back_open, because using fonction reference  (bi->bi_open) is not functional */
00081        Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
00082 
00083        if( PERL_INTERPRETER != NULL ) {
00084               Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
00085                      0, 0, 0 );
00086               return 1;
00087        }
00088        
00089        ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
00090 
00091 #ifdef PERL_SYS_INIT3
00092        PERL_SYS_INIT3(&argc, &argv, &env);
00093 #endif
00094        PERL_INTERPRETER = perl_alloc();
00095        perl_construct(PERL_INTERPRETER);
00096 #ifdef PERL_EXIT_DESTRUCT_END
00097        PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
00098 #endif
00099        perl_parse(PERL_INTERPRETER, perl_back_xs_init, argc, argv, env);
00100        perl_run(PERL_INTERPRETER);
00101        return perl_back_init_cf( bi );
00102 }
00103 
00104 int
00105 perl_back_db_init(
00106        BackendDB     *be,
00107        ConfigReply   *cr
00108 )
00109 {
00110        be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
00111        memset( be->be_private, '\0', sizeof(PerlBackend));
00112 
00113        ((PerlBackend *)be->be_private)->pb_filter_search_results = 0;
00114 
00115        Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
00116 
00117        be->be_cf_ocs = be->bd_info->bi_cf_ocs;
00118 
00119        return 0;
00120 }
00121 
00122 int
00123 perl_back_db_open(
00124        BackendDB     *be,
00125        ConfigReply   *cr
00126 )
00127 {
00128        int count;
00129        int return_code;
00130 
00131        PerlBackend *perl_back = (PerlBackend *) be->be_private;
00132 
00133        ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );
00134 
00135        {
00136               dSP; ENTER; SAVETMPS;
00137 
00138               PUSHMARK(sp);
00139               XPUSHs( perl_back->pb_obj_ref );
00140 
00141               PUTBACK;
00142 
00143               count = call_method("init", G_SCALAR);
00144 
00145               SPAGAIN;
00146 
00147               if (count != 1) {
00148                      croak("Big trouble in perl_back_db_open\n");
00149               }
00150 
00151               return_code = POPi;
00152 
00153               PUTBACK; FREETMPS; LEAVE;
00154        }
00155 
00156        ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );
00157 
00158        return return_code;
00159 }
00160 
00161 
00162 static void
00163 perl_back_xs_init(PERL_BACK_XS_INIT_PARAMS)
00164 {
00165        char *file = __FILE__;
00166        dXSUB_SYS;
00167        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
00168 }
00169 
00170 #if SLAPD_PERL == SLAPD_MOD_DYNAMIC
00171 
00172 /* conditionally define the init_module() function */
00173 SLAP_BACKEND_INIT_MODULE( perl )
00174 
00175 #endif /* SLAPD_PERL == SLAPD_MOD_DYNAMIC */
00176 
00177