3 * Copyright 1999, John C. Quillan, All rights reserved.
4 * Portions Copyright 2002, myinternet pty ltd. All rights reserved.
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.
13 /* init.c - initialize shell backend */
16 /* #include <ac/types.h>
17 #include <ac/socket.h>
24 #include "perl_back.h"
27 /**********************************************************
31 **********************************************************/
42 PerlBackend *perl_back = (PerlBackend *) be->be_private;
43 char eval_str[EVAL_BUF_SIZE];
49 if ( strcasecmp( argv[0], "perlModule" ) == 0 ) {
51 Debug( LDAP_DEBUG_ANY,
52 "%s.pm: line %d: missing module in \"perlModule <module>\" line\n",
58 snprintf( eval_str, EVAL_BUF_SIZE, "use %s;", argv[1] );
59 eval_pv( eval_str, 0 );
62 fprintf(stderr , "Error %s\n", SvPV(ERRSV, n_a)) ;
65 snprintf( eval_str, EVAL_BUF_SIZE, "%s.pm", argv[1] );
66 perl_require_pv( eval_str );
68 if (SvTRUE(GvSV(errgv))) {
69 fprintf(stderr , "Error %s\n", SvPV(GvSV(errgv), na)) ;
71 #endif /* PERL_IS_5_6 */
75 XPUSHs(sv_2mortal(newSVpv(argv[1], 0)));
79 count = call_method("new", G_SCALAR);
81 count = perl_call_method("new", G_SCALAR);
87 croak("Big trouble in config\n") ;
90 perl_back->pb_obj_ref = newSVsv(POPs);
92 PUTBACK; FREETMPS; LEAVE ;
95 } else if ( strcasecmp( argv[0], "perlModulePath" ) == 0 ) {
98 "%s: line %d: missing module in \"PerlModulePath <module>\" line\n",
103 snprintf( eval_str, EVAL_BUF_SIZE, "push @INC, '%s';", argv[1] );
105 loc_sv = eval_pv( eval_str, 0 );
107 loc_sv = perl_eval_pv( eval_str, 0 );
110 /* XXX loc_sv return value is ignored. */
112 } else if ( strcasecmp( argv[0], "filterSearchResults" ) == 0 ) {
113 perl_back->pb_filter_search_results = 1;
116 * Pass it to Perl module if defined
120 dSP ; ENTER ; SAVETMPS;
123 XPUSHs( perl_back->pb_obj_ref );
125 /* Put all arguments on the perl stack */
126 for( args = 0; args < argc; args++ ) {
127 XPUSHs(sv_2mortal(newSVpv(argv[args], 0)));
133 count = call_method("config", G_SCALAR);
135 count = perl_call_method("config", G_SCALAR);
141 croak("Big trouble in config\n") ;
146 PUTBACK ; FREETMPS ; LEAVE ;
150 /* if the module rejected it then we should reject it */
151 if ( return_code != 0 ) {
153 "Unknown perl backend config: %s\n", argv[0]);
154 exit( EXIT_FAILURE );