]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/config.c
Another round of minor copyright updates
[openldap] / servers / slapd / back-perl / config.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1999-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  *       Copyright 1999, John C. Quillan, All rights reserved.
8  *       Portions Copyright 2002, myinternet Limited. All rights reserved.
9  *
10  *       Redistribution and use in source and binary forms are permitted only
11  *       as authorized by the OpenLDAP Public License.  A copy of this
12  *       license is available at http://www.OpenLDAP.org/license.html or
13  *       in file LICENSE in the top-level directory of the distribution.
14  */
15
16 #include "portable.h"
17         
18 #include <stdio.h>
19
20 #include "slap.h"
21 #ifdef HAVE_WIN32_ASPERL
22 #include "asperl_undefs.h"
23 #endif
24
25 #include <EXTERN.h>
26 #include <perl.h>
27
28 #include "perl_back.h"
29
30
31 /**********************************************************
32  *
33  * Config
34  *
35  **********************************************************/
36 int
37 perl_back_db_config(
38          BackendDB *be,
39          const char *fname,
40          int lineno,
41          int argc,
42          char **argv
43 )
44 {
45         SV* loc_sv;
46         PerlBackend *perl_back = (PerlBackend *) be->be_private;
47         char eval_str[EVAL_BUF_SIZE];
48         int count ;
49         int args;
50         int return_code;
51         
52
53         if ( strcasecmp( argv[0], "perlModule" ) == 0 ) {
54                 if ( argc < 2 ) {
55                         Debug( LDAP_DEBUG_ANY,
56                                  "%s.pm: line %d: missing module in \"perlModule <module>\" line\n",
57                                 fname, lineno, 0 );
58                         return( 1 );
59                 }
60
61 #ifdef PERL_IS_5_6
62                 snprintf( eval_str, EVAL_BUF_SIZE, "use %s;", argv[1] );
63                 eval_pv( eval_str, 0 );
64
65                 if (SvTRUE(ERRSV)) {
66                         STRLEN n_a;
67
68                         fprintf(stderr , "Error %s\n", SvPV(ERRSV, n_a)) ;
69                 }
70 #else
71                 snprintf( eval_str, EVAL_BUF_SIZE, "%s.pm", argv[1] );
72                 perl_require_pv( eval_str );
73
74                 if (SvTRUE(GvSV(errgv))) {
75                         fprintf(stderr , "Error %s\n", SvPV(GvSV(errgv), na)) ;
76                 }
77 #endif /* PERL_IS_5_6 */
78                 else {
79                         dSP; ENTER; SAVETMPS;
80                         PUSHMARK(sp);
81                         XPUSHs(sv_2mortal(newSVpv(argv[1], 0)));
82                         PUTBACK;
83
84 #ifdef PERL_IS_5_6
85                         count = call_method("new", G_SCALAR);
86 #else
87                         count = perl_call_method("new", G_SCALAR);
88 #endif
89
90                         SPAGAIN;
91
92                         if (count != 1) {
93                                 croak("Big trouble in config\n") ;
94                         }
95
96                         perl_back->pb_obj_ref = newSVsv(POPs);
97
98                         PUTBACK; FREETMPS; LEAVE ;
99                 }
100
101         } else if ( strcasecmp( argv[0], "perlModulePath" ) == 0 ) {
102                 if ( argc < 2 ) {
103                         fprintf( stderr,
104                                 "%s: line %d: missing module in \"PerlModulePath <module>\" line\n",
105                                 fname, lineno );
106                         return( 1 );
107                 }
108
109                 snprintf( eval_str, EVAL_BUF_SIZE, "push @INC, '%s';", argv[1] );
110 #ifdef PERL_IS_5_6
111                 loc_sv = eval_pv( eval_str, 0 );
112 #else
113                 loc_sv = perl_eval_pv( eval_str, 0 );
114 #endif
115
116                 /* XXX loc_sv return value is ignored. */
117
118         } else if ( strcasecmp( argv[0], "filterSearchResults" ) == 0 ) {
119                 perl_back->pb_filter_search_results = 1;
120         } else {
121                 /*
122                  * Pass it to Perl module if defined
123                  */
124
125                 {
126                         dSP ;  ENTER ; SAVETMPS;
127
128                         PUSHMARK(sp) ;
129                         XPUSHs( perl_back->pb_obj_ref );
130
131                         /* Put all arguments on the perl stack */
132                         for( args = 0; args < argc; args++ ) {
133                                 XPUSHs(sv_2mortal(newSVpv(argv[args], 0)));
134                         }
135
136                         PUTBACK ;
137
138 #ifdef PERL_IS_5_6
139                         count = call_method("config", G_SCALAR);
140 #else
141                         count = perl_call_method("config", G_SCALAR);
142 #endif
143
144                         SPAGAIN ;
145
146                         if (count != 1) {
147                                 croak("Big trouble in config\n") ;
148                         }
149
150                         return_code = POPi;
151
152                         PUTBACK ; FREETMPS ;  LEAVE ;
153
154                 }
155
156                 /* if the module rejected it then we should reject it */
157                 if ( return_code != 0 ) {
158                         fprintf( stderr,
159                                  "Unknown perl backend config: %s\n", argv[0]);
160                         exit( EXIT_FAILURE );
161                 }
162         }
163
164         return 0;
165 }