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