1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MODPERL_TYPES_H
18 #define MODPERL_TYPES_H
19 
20 #ifndef MP_IOBUFSIZE
21 #   ifdef AP_IOBUFSIZE
22 #      define MP_IOBUFSIZE AP_IOBUFSIZE
23 #   else
24 #      define MP_IOBUFSIZE 8192
25 #   endif
26 #endif
27 
28 /* aliases */
29 
30 typedef request_rec subrequest_rec;
31 typedef apr_array_header_t MpAV;
32 typedef apr_table_t        MpHV;
33 typedef char char_len; /* see xs/typemap */
34 
35 /* mod_perl structures */
36 
37 typedef struct {
38     request_rec *r;
39     conn_rec    *c;
40     server_rec  *s;
41 } modperl_rcs_t;
42 
43 typedef struct modperl_config_con_t modperl_config_con_t;
44 
45 #ifdef USE_ITHREADS
46 
47 typedef struct modperl_list_t modperl_list_t;
48 
49 struct modperl_list_t {
50     modperl_list_t *prev, *next;
51     void *data;
52 };
53 
54 typedef struct modperl_interp_t modperl_interp_t;
55 typedef struct modperl_interp_pool_t modperl_interp_pool_t;
56 typedef struct modperl_tipool_t modperl_tipool_t;
57 typedef struct modperl_tipool_config_t modperl_tipool_config_t;
58 
59 struct modperl_interp_t {
60     modperl_interp_pool_t *mip;
61     PerlInterpreter *perl;
62     int num_requests;
63     U8 flags;
64     modperl_config_con_t *ccfg;
65     int refcnt;
66 #ifdef MP_TRACE
67     unsigned long tid;
68 #endif
69 };
70 
71 typedef struct {
72     /* s == startup grow
73      * r == runtime grow
74      */
75     void * (*tipool_sgrow)(modperl_tipool_t *tipool, void *data);
76     void * (*tipool_rgrow)(modperl_tipool_t *tipool, void *data);
77     void (*tipool_shrink)(modperl_tipool_t *tipool, void *data,
78                           void *item);
79     void (*tipool_destroy)(modperl_tipool_t *tipool, void *data,
80                            void *item);
81     void (*tipool_dump)(modperl_tipool_t *tipool, void *data,
82                         modperl_list_t *listp);
83 } modperl_tipool_vtbl_t;
84 
85 struct modperl_tipool_config_t {
86     int start; /* number of items to create at startup */
87     int min_spare; /* minimum number of spare items */
88     int max_spare; /* maximum number of spare items */
89     int max; /* maximum number of items */
90     int max_requests; /* maximum number of requests per item */
91 };
92 
93 struct modperl_tipool_t {
94     perl_mutex tiplock;
95     perl_cond available;
96     modperl_list_t *idle, *busy;
97     int in_use; /* number of items currrently in use */
98     int size; /* current number of items */
99     void *data; /* user data */
100     modperl_tipool_config_t *cfg;
101     modperl_tipool_vtbl_t *func;
102 };
103 
104 struct modperl_interp_pool_t {
105     server_rec *server;
106     modperl_tipool_t *tipool;
107     modperl_interp_t *parent; /* from which to perl_clone() */
108 };
109 
110 #endif /* USE_ITHREADS */
111 
112 typedef U32 modperl_opts_t;
113 
114 typedef struct {
115     modperl_opts_t opts;
116     modperl_opts_t opts_add;
117     modperl_opts_t opts_remove;
118     modperl_opts_t opts_override;
119     modperl_opts_t opts_seen;
120     int unset;
121 } modperl_options_t;
122 
123 typedef struct {
124     MpHV *setvars;
125     MpHV *configvars;
126     MpHV *SetEnv;
127     MpHV *PassEnv;
128     MpAV *PerlRequire, *PerlModule, *PerlPostConfigRequire;
129     MpAV *handlers_per_srv[MP_HANDLER_NUM_PER_SRV];
130     MpAV *handlers_files[MP_HANDLER_NUM_FILES];
131     MpAV *handlers_process[MP_HANDLER_NUM_PROCESS];
132     MpAV *handlers_pre_connection[MP_HANDLER_NUM_PRE_CONNECTION];
133     MpAV *handlers_connection[MP_HANDLER_NUM_CONNECTION];
134 #ifdef USE_ITHREADS
135     modperl_interp_pool_t *mip;
136     modperl_tipool_config_t *interp_pool_cfg;
137 #else
138     PerlInterpreter *perl;
139 #endif
140 #ifdef MP_USE_GTOP
141     modperl_gtop_t *gtop;
142 #endif
143     MpAV *argv;
144     modperl_options_t *flags;
145     apr_hash_t *modules;
146     server_rec *server;
147 } modperl_config_srv_t;
148 
149 typedef struct {
150     char *location;
151     char *PerlDispatchHandler;
152     MpAV *handlers_per_dir[MP_HANDLER_NUM_PER_DIR];
153     MpHV *SetEnv;
154     MpHV *setvars;
155     MpHV *configvars;
156     modperl_options_t *flags;
157 } modperl_config_dir_t;
158 
159 typedef struct {
160     const char *file;
161     modperl_config_dir_t *dcfg;
162 } modperl_require_file_t;
163 
164 typedef struct modperl_mgv_t modperl_mgv_t;
165 
166 struct modperl_mgv_t {
167     char *name;
168     int len;
169     UV hash;
170     modperl_mgv_t *next;
171 };
172 
173 typedef struct modperl_handler_t modperl_handler_t;
174 
175 struct modperl_handler_t {
176     /* could be:
177      * - the lightweight gv for named subs
178      * - the lookup data in $PL_modperl{ANONSUB}
179      */
180     modperl_mgv_t *mgv_obj;
181     modperl_mgv_t *mgv_cv;
182     /* could be:
183      * - a subroutine name for named subs
184      * - NULL for anon subs
185      */
186     const char *name;
187     CV *cv;
188     U8 flags;
189     U16 attrs;
190     modperl_handler_t *next;
191 };
192 
193 #define MP_HANDLER_TYPE_CHAR 1
194 #define MP_HANDLER_TYPE_SV   2
195 
196 typedef struct {
197     int outcnt;
198     char outbuf[MP_IOBUFSIZE];
199     apr_pool_t *pool;
200     ap_filter_t **filters;
201     int header_parse;
202     request_rec *r;
203 } modperl_wbucket_t;
204 
205 typedef enum {
206     MP_INPUT_FILTER_MODE,
207     MP_OUTPUT_FILTER_MODE
208 } modperl_filter_mode_e;
209 
210 typedef struct {
211     int seen_eos;
212     int eos;
213     int flush;
214     ap_filter_t *f;
215     char *leftover;
216     apr_ssize_t remaining;
217     modperl_wbucket_t *wbucket;
218     apr_bucket *bucket;
219     apr_bucket_brigade *bb_in;
220     apr_bucket_brigade *bb_out;
221     ap_input_mode_t input_mode;
222     apr_read_type_e block;
223     apr_off_t readbytes;
224     apr_status_t rc;
225     modperl_filter_mode_e mode;
226     apr_pool_t *pool;
227     apr_pool_t *temp_pool;
228 } modperl_filter_t;
229 
230 typedef struct {
231     int sent_eos;
232     SV *data;
233     modperl_handler_t *handler;
234 #ifdef USE_ITHREADS
235     modperl_interp_t *interp;
236 #endif
237 } modperl_filter_ctx_t;
238 
239 typedef struct {
240     HV *pnotes;
241     apr_pool_t *pool;
242 #ifdef USE_ITHREADS
243     modperl_interp_t *interp;
244 #endif
245 } modperl_pnotes_t;
246 
247 typedef struct {
248     modperl_pnotes_t pnotes;
249     SV *global_request_obj;
250     U8 flags;
251     int status;
252     modperl_wbucket_t *wbucket;
253     MpAV *handlers_per_dir[MP_HANDLER_NUM_PER_DIR];
254     MpAV *handlers_per_srv[MP_HANDLER_NUM_PER_SRV];
255     modperl_perl_globals_t perl_globals;
256 } modperl_config_req_t;
257 
258 struct modperl_config_con_t {
259     modperl_pnotes_t pnotes;
260 #ifdef USE_ITHREADS
261     modperl_interp_t *interp;
262 #endif
263 };
264 
265 typedef struct {
266     apr_pool_t *pool;
267     void *data;
268 } modperl_cleanup_data_t;
269 
270 typedef struct {
271     module *modp;
272     const char *cmd_data;
273     const char *func_name;
274 } modperl_module_cmd_data_t;
275 
276 typedef enum {
277     MP_HOOK_RUN_ALL,
278     MP_HOOK_RUN_FIRST,
279     MP_HOOK_VOID
280 } modperl_hook_run_mode_e;
281 
282 #endif /* MODPERL_TYPES_H */
283 
284 /*
285  * Local Variables:
286  * c-basic-offset: 4
287  * indent-tabs-mode: nil
288  * End:
289  */
290