]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/init.c
e215acd2e6640032f27be17807a95719a2c0ed42
[openldap] / servers / slapd / back-perl / init.c
1 /* $OpenLDAP$ */
2 /*
3  *       Copyright 1999, John C. Quillan, All rights reserved.
4  *
5  *       Redistribution and use in source and binary forms are permitted only
6  *       as authorized by the OpenLDAP Public License.  A copy of this
7  *       license is available at http://www.OpenLDAP.org/license.html or
8  *       in file LICENSE in the top-level directory of the distribution.
9  */
10
11 #include "portable.h"
12  /* init.c - initialize shell backend */
13         
14 #include <stdio.h>
15 /* #include <ac/types.h>
16         #include <ac/socket.h>
17 */
18
19
20
21 #include <EXTERN.h>
22 #include <perl.h>
23
24 #include "slap.h"
25 #include "perl_back.h"
26
27
28
29 PerlInterpreter *perl_interpreter = NULL;
30 ldap_pvt_thread_mutex_t perl_interpreter_mutex;
31
32 #ifdef SLAPD_PERL_DYNAMIC
33
34 int back_perl_LTX_init_module(int argc, char *argv[]) {
35     BackendInfo bi;
36
37     memset( &bi, 0, sizeof(bi) );
38     bi.bi_type = "perl";
39     bi.bi_init = perl_back_initialize;
40
41     backend_add(&bi);
42     return 0;
43 }
44
45 #endif /* SLAPD_PERL_DYNAMIC */
46
47
48 /**********************************************************
49  *
50  * Init
51  *
52  **********************************************************/
53
54 int
55 perl_back_initialize(
56         BackendInfo     *bi
57 )
58 {
59         char *embedding[] = { "", "-e", "0" };
60
61         Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
62
63         if( perl_interpreter != NULL ) {
64                 Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
65                         0, 0, 0 );
66                 return 1;
67         }
68         
69         perl_interpreter = perl_alloc();
70         perl_construct(perl_interpreter);
71         perl_parse(perl_interpreter, NULL, 3, embedding, (char **)NULL);
72         perl_run(perl_interpreter);
73
74         bi->bi_open = perl_back_open;
75         bi->bi_config = 0;
76         bi->bi_close = perl_back_close;
77         bi->bi_destroy = perl_back_destroy;
78
79         bi->bi_db_init = perl_back_db_init;
80         bi->bi_db_config = perl_back_db_config;
81         bi->bi_db_open = 0;
82         bi->bi_db_close = 0;
83         bi->bi_db_destroy = perl_back_db_destroy;
84
85         bi->bi_op_bind = perl_back_bind;
86         bi->bi_op_unbind = perl_back_unbind;
87         bi->bi_op_search = perl_back_search;
88         bi->bi_op_compare = perl_back_compare;
89         bi->bi_op_modify = perl_back_modify;
90         bi->bi_op_modrdn = perl_back_modrdn;
91         bi->bi_op_add = perl_back_add;
92         bi->bi_op_delete = perl_back_delete;
93         bi->bi_op_abandon = 0;
94
95         bi->bi_acl_group = 0;
96
97         bi->bi_connection_init = 0;
98         bi->bi_connection_destroy = 0;
99
100         return 0;
101 }
102                 
103 int
104 perl_back_open(
105         BackendInfo     *bi
106 )
107 {
108         ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
109         return 0;
110 }
111
112 int
113 perl_back_db_init(
114         Backend *be
115 )
116 {
117         be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
118         memset( be->be_private, 0, sizeof(PerlBackend));
119
120         Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
121
122         return 0;
123 }
124