1 /*
2 * Copyright (C) 2004-2008 Christos Tsantilas
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA.
18 */
19
20 #include "common.h"
21 #include "c-icap.h"
22 #include "service.h"
23 #include "module.h"
24 #include "header.h"
25 #include "body.h"
26 #include "debug.h"
27
28 #include "EXTERN.h"
29 #include "perl.h"
30 #include "XSUB.h"
31
32
33
34 struct perl_data {
35 PerlInterpreter *perl;
36 };
37
38 int init_perl_handler(struct ci_server_conf *server_conf);
39 ci_service_module_t *load_perl_module(char *service_file);
40
41
42 CI_DECLARE_DATA service_handler_module_t module = {
43 "perl_handler",
44 ".pl,.pm,.plx",
45 init_perl_handler,
46 NULL, /*post_init .... */
47 NULL, /*release handler */
48 load_perl_module,
49 NULL
50 };
51
52
53
54 int perl_init_service(ci_service_xdata_t *srv_xdata,
55 struct ci_server_conf *server_conf);
56 void perl_close_service();
57 void *perl_init_request_data(ci_request_t *);
58 void perl_release_request_data(void *data);
59
60
61 int perl_check_preview_handler(char *preview_data, int preview_data_len,
62 ci_request_t *);
63 int perl_end_of_data_handler(ci_request_t *);
64 int perl_service_io(char *rbuf, int *rlen, char *wbuf, int *wlen, int iseof,
65 ci_request_t *req);
66
67
init_perl_handler(struct ci_server_conf * server_conf)68 int init_perl_handler(struct ci_server_conf *server_conf)
69 {
70 return 0;
71 }
72
73
load_perl_module(char * service_file)74 ci_service_module_t *load_perl_module(char *service_file)
75 {
76 ci_service_module_t *service = NULL;
77 struct perl_data *perl_data;
78 char *argv[2];
79 argv[0] = NULL;
80 argv[1] = service_file;
81 service = malloc(sizeof(ci_service_module_t));
82 perl_data = malloc(sizeof(struct perl_data));
83
84 perl_data->perl = perl_alloc(); /*Maybe it is better to allocate a perl interpreter per request */
85 perl_construct(perl_data->perl);
86 perl_parse(perl_data->perl, NULL, 2, argv, NULL);
87 perl_run(perl_data->perl);
88
89 service->mod_data = perl_data;
90
91 service->mod_init_service = perl_init_service;
92 service->mod_post_init_service = NULL;
93 service->mod_close_service = perl_close_service;
94 service->mod_init_request_data = perl_init_request_data;
95 service->mod_release_request_data = perl_release_request_data;
96 service->mod_check_preview_handler = perl_check_preview_handler;
97 service->mod_end_of_data_handler = perl_end_of_data_handler;
98 service->mod_service_io = perl_service_io;
99
100
101 service->mod_name = strdup("perl_test");
102 service->mod_type = ICAP_REQMOD | ICAP_RESPMOD;
103
104 ci_debug_printf(1, "OK service %s loaded\n", service_file);
105 return service;
106 }
107
108
109
110
perl_init_service(ci_service_xdata_t * srv_xdata,struct ci_server_conf * server_conf)111 int perl_init_service(ci_service_xdata_t *srv_xdata,
112 struct ci_server_conf *server_conf)
113 {
114 return 0;
115 }
116
perl_close_service()117 void perl_close_service()
118 {
119
120 }
121
122
perl_init_request_data(ci_request_t * req)123 void *perl_init_request_data(ci_request_t *req)
124 {
125 return NULL;
126 }
127
perl_release_request_data(void * data)128 void perl_release_request_data(void *data)
129 {
130
131 }
132
133
perl_check_preview_handler(char * preview_data,int preview_data_len,ci_request_t * req)134 int perl_check_preview_handler(char *preview_data, int preview_data_len,
135 ci_request_t *req)
136 {
137 return EC_500;
138 }
139
perl_end_of_data_handler(ci_request_t * req)140 int perl_end_of_data_handler(ci_request_t *req)
141 {
142 return 0;
143 }
144
145
perl_service_io(char * rbuf,int * rlen,char * wbuf,int * wlen,int iseof,ci_request_t * req)146 int perl_service_io(char *rbuf, int *rlen, char *wbuf, int *wlen, int iseof,
147 ci_request_t *req)
148 {
149 *rlen = 0;
150 *wlen = 0;
151 return CI_OK;
152 }
153