annotate src/http/modules/perl/ngx_http_perl_module.c @ 230:38e7b94d63ac NGINX_0_4_0

nginx 0.4.0 *) Change in internal API: the HTTP modules initialization was moved from the init module phase to the HTTP postconfiguration phase. *) Change: now the request body is not read beforehand for the ngx_http_perl_module: it's required to start the reading using the $r->has_request_body method. *) Feature: the ngx_http_perl_module supports the DECLINED return code. *) Feature: the ngx_http_dav_module supports the incoming "Date" header line for the PUT method. *) Feature: the "ssi" directive is available inside the "if" block. *) Bugfix: a segmentation fault occurred if there was an "index" directive with variables and the first index name was without variables; bug appeared in 0.1.29.
author Igor Sysoev <http://sysoev.ru>
date Wed, 30 Aug 2006 00:00:00 +0400
parents dd6c66b5b0e2
children acd2ec3541cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_http_perl_module.h>
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 typedef struct {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 PerlInterpreter **free_perls;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 ngx_uint_t interp;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 ngx_uint_t nalloc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 ngx_uint_t interp_max;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 PerlInterpreter *perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 ngx_str_t modules;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 ngx_array_t requires;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 } ngx_http_perl_main_conf_t;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 typedef struct {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 SV *sub;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 ngx_str_t handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 } ngx_http_perl_loc_conf_t;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 typedef struct {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 SV *sub;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 ngx_str_t handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 } ngx_http_perl_variable_t;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
37 typedef struct {
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
38 SV *sv;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
39 PerlInterpreter *perl;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
40 } ngx_http_perl_cleanup_t;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
41
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
42
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
43 #if (NGX_HTTP_SSI)
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params);
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
46 #endif
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
47
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 PerlInterpreter **perl, ngx_log_t *log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51 static ngx_inline void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 ngx_http_perl_free_interpreter(ngx_http_perl_main_conf_t *pmcf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 PerlInterpreter *perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 ngx_http_perl_main_conf_t *pmcf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 static PerlInterpreter *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 ngx_log_t *log);
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
59 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires,
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
60 ngx_log_t *log);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 SV *sub, ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 static ngx_int_t ngx_http_perl_preconfiguration(ngx_conf_t *cf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 static void *ngx_http_perl_create_loc_conf(ngx_conf_t *cf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 static char *ngx_http_perl_merge_loc_conf(ngx_conf_t *cf, void *parent,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 void *child);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 static char *ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 void *conf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 static char *ngx_http_perl_interp_max_unsupported(ngx_conf_t *cf, void *post,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 void *data);
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
77 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 static void ngx_http_perl_cleanup_perl(void *data);
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
79 #endif
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
80 static void ngx_http_perl_cleanup_sv(void *data);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 static ngx_conf_post_handler_pt ngx_http_perl_interp_max_p =
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 ngx_http_perl_interp_max_unsupported;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 static ngx_command_t ngx_http_perl_commands[] = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 { ngx_string("perl_modules"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 ngx_conf_set_str_slot,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 NGX_HTTP_MAIN_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 offsetof(ngx_http_perl_main_conf_t, modules),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 { ngx_string("perl_require"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 ngx_http_perl_require,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 NGX_HTTP_MAIN_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 { ngx_string("perl_interp_max"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 ngx_conf_set_num_slot,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 NGX_HTTP_MAIN_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107 offsetof(ngx_http_perl_main_conf_t, interp_max),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 &ngx_http_perl_interp_max_p },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 { ngx_string("perl"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 ngx_http_perl,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 NGX_HTTP_LOC_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 { ngx_string("perl_set"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 ngx_http_perl_set,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 NGX_HTTP_LOC_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 ngx_null_command
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 static ngx_http_module_t ngx_http_perl_module_ctx = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 ngx_http_perl_preconfiguration, /* preconfiguration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 NULL, /* postconfiguration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 ngx_http_perl_create_main_conf, /* create main configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 ngx_http_perl_init_main_conf, /* init main configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 NULL, /* create server configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 NULL, /* merge server configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 ngx_http_perl_create_loc_conf, /* create location configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 ngx_http_perl_merge_loc_conf /* merge location configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 ngx_module_t ngx_http_perl_module = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 NGX_MODULE_V1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 &ngx_http_perl_module_ctx, /* module context */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 ngx_http_perl_commands, /* module directives */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 NGX_HTTP_MODULE, /* module type */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 NULL, /* init master */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149 NULL, /* init module */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 NULL, /* init process */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 NULL, /* init thread */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 NULL, /* exit thread */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 NULL, /* exit process */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 NULL, /* exit master */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 NGX_MODULE_V1_PADDING
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
159 #if (NGX_HTTP_SSI)
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
160
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 #define NGX_HTTP_PERL_SSI_SUB 0
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162 #define NGX_HTTP_PERL_SSI_ARG 1
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165 static ngx_http_ssi_param_t ngx_http_perl_ssi_params[] = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166 { ngx_string("sub"), NGX_HTTP_PERL_SSI_SUB, 1, 0 },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167 { ngx_string("arg"), NGX_HTTP_PERL_SSI_ARG, 0, 1 },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 { ngx_null_string, 0, 0, 0 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 static ngx_http_ssi_command_t ngx_http_perl_ssi_command = {
216
fa32d59d9a15 nginx 0.3.55
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
172 ngx_string("perl"), ngx_http_perl_ssi, ngx_http_perl_ssi_params, 0, 0, 1
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
175 #endif
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
176
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
178 static ngx_str_t ngx_null_name = ngx_null_string;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
179
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
180
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
181 static HV *nginx_stash;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
182
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 static void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 ngx_http_perl_xs_init(pTHX)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
187
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
188 nginx_stash = gv_stashpv("nginx", TRUE);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 ngx_http_perl_handler(ngx_http_request_t *r)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194 {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
195 /* TODO: Win32 */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
196 if (r->zero_in_uri) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
197 return NGX_HTTP_NOT_FOUND;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
198 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
199
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
200 ngx_http_perl_handle_request(r);
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
201
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
202 return NGX_DONE;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
203
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
204 #if 0
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
205 r->request_body_in_single_buf = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
206 r->request_body_in_persistent_file = 1;
184
71ff1e2b484a nginx 0.3.39
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
207 r->request_body_delete_incomplete_file = 1;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
208
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
209 if (r->request_body_in_file_only) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
210 r->request_body_file_log_level = 0;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
211 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
212
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
213 rc = ngx_http_read_client_request_body(r, ngx_http_perl_handle_request);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
214
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
215 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
216 return rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
217 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
218
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
219 return NGX_DONE;
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
220 #endif
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
221 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
222
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
223
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
224 void
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
225 ngx_http_perl_handle_request(ngx_http_request_t *r)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
226 {
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
227 SV *sub;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 ngx_int_t rc;
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
229 ngx_str_t uri, args, *handler;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 ngx_http_perl_ctx_t *ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231 ngx_http_perl_loc_conf_t *plcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "perl handler");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 if (ctx == NULL) {
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
241 ngx_http_finalize_request(r, NGX_ERROR);
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
242 return;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 rc = ngx_http_perl_get_interpreter(pmcf, &ctx->perl, r->connection->log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 if (rc != NGX_OK) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
253 ngx_http_finalize_request(r, rc);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
254 return;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 dTHXa(ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
261 if (ctx->next == NULL) {
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
262 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
263 sub = plcf->sub;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
264 handler = &plcf->handler;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
266 } else {
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
267 sub = ctx->next;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
268 handler = &ngx_null_name;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
269 ctx->next = NULL;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
270 }
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
271
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
272 rc = ngx_http_perl_call_handler(aTHX_ r, sub, NULL, handler, NULL);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 if (rc > 600) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279 rc = NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 "perl handler done: %i", rc);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 if (ctx->redirect_uri.len) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 uri = ctx->redirect_uri;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 args = ctx->redirect_args;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
288
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
289 } else {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
290 uri.len = 0;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
293 ctx->filename.data = NULL;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 ctx->redirect_uri.len = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
296 if (ctx->done || ctx->next) {
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
297 return;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
298 }
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
299
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300 if (uri.len) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
301 ngx_http_internal_redirect(r, &uri, &args);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
302 return;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305 if (rc == NGX_OK || rc == NGX_HTTP_OK) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
306 ngx_http_send_special(r, NGX_HTTP_LAST);
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 222
diff changeset
307 ctx->done = 1;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
308 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
310 ngx_http_finalize_request(r, rc);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315 ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316 uintptr_t data)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
318 ngx_http_perl_variable_t *pv = (ngx_http_perl_variable_t *) data;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 ngx_str_t value;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 ngx_http_perl_ctx_t *ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
324
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326 "perl variable handler");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
336 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341 rc = ngx_http_perl_get_interpreter(pmcf, &ctx->perl, r->connection->log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
342
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 if (rc != NGX_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
345 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
347 value.data = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
350
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
351 dTHXa(ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
352
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
353 rc = ngx_http_perl_call_handler(aTHX_ r, pv->sub, NULL,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
354 &pv->handler, &value);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
355
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
356 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
357
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
358 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
359
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
360 if (value.data) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361 v->len = value.len;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 v->valid = 1;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363 v->no_cachable = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 v->not_found = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365 v->data = value.data;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 } else {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368 v->not_found = 1;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
370
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
371 ctx->filename.data = NULL;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372 ctx->redirect_uri.len = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
376
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
377
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
378 #if (NGX_HTTP_SSI)
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
379
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381 ngx_http_perl_ssi(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ssi_ctx,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
382 ngx_str_t **params)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
383 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
384 SV *sv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
385 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
386 ngx_str_t *handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387 ngx_http_perl_ctx_t *ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
390 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391 "perl ssi handler");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
394
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
395 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
396
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
405
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406 rc = ngx_http_perl_get_interpreter(pmcf, &ctx->perl, r->connection->log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 if (rc != NGX_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
411
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412 ctx->ssi = ssi_ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414 handler = params[NGX_HTTP_PERL_SSI_SUB];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415 handler->data[handler->len] = '\0';
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
416
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419 dTHXa(ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420
200
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
421 #if 0
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
422
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
423 /* the code is disabled to force the precompiled perl code using only */
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
424
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
425 ngx_http_perl_eval_anon_sub(aTHX_ handler, &sv);
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
426
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
427 if (sv == &PL_sv_undef) {
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
428 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
429 "eval_pv(\"%V\") failed", handler);
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
430 return NGX_ERROR;
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
431 }
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
432
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
433 if (sv == NULL) {
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
434 sv = newSVpvn((char *) handler->data, handler->len);
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
435 }
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
436
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
437 #endif
d2ae1c9f1fd3 nginx 0.3.47
Igor Sysoev <http://sysoev.ru>
parents: 198
diff changeset
438
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
439 sv = newSVpvn((char *) handler->data, handler->len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
440
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 rc = ngx_http_perl_call_handler(aTHX_ r, sv, &params[NGX_HTTP_PERL_SSI_ARG],
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442 handler, NULL);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
444 SvREFCNT_dec(sv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
445
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
446 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
447
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
450 ctx->filename.data = NULL;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
451 ctx->redirect_uri.len = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
452 ctx->ssi = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
453
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
455 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
456
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
457 #endif
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
458
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
459
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
460 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461 ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462 PerlInterpreter **perl, ngx_log_t *log)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
464 if (pmcf->interp) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465 pmcf->interp--;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
467 *perl = pmcf->free_perls[pmcf->interp];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
468
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
469 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
471
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
472 if (pmcf->nalloc < pmcf->interp_max) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
473 *perl = ngx_http_perl_create_interpreter(pmcf, log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
474
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
475 if (*perl) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
476 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
477 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
478
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
479 return NGX_HTTP_INTERNAL_SERVER_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
480 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
481
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
482 ngx_log_error(NGX_LOG_ALERT, log, 0, "no free perl interpreter");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
483
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
484 return NGX_HTTP_SERVICE_UNAVAILABLE;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
486
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
487
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
488 static ngx_inline void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
489 ngx_http_perl_free_interpreter(ngx_http_perl_main_conf_t *pmcf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490 PerlInterpreter *perl)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
491 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
492 pmcf->free_perls[pmcf->interp++] = perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
494
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498 {
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
499 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
500 ngx_pool_cleanup_t *cln;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
501
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
502 cln = ngx_pool_cleanup_add(cf->pool, 0);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
503 if (cln == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
504 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
505 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
506
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
507 #else
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
508 static PerlInterpreter *perl;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
509 #endif
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
510
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
511 #ifdef NGX_PERL_MODULES
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512 if (pmcf->modules.data == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
513 pmcf->modules.data = NGX_PERL_MODULES;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
514 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
515 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
516
188
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 186
diff changeset
517 if (pmcf->modules.data) {
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 186
diff changeset
518 if (ngx_conf_full_name(cf->cycle, &pmcf->modules) != NGX_OK) {
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 186
diff changeset
519 return NGX_CONF_ERROR;
af37b7cb6698 nginx 0.3.41
Igor Sysoev <http://sysoev.ru>
parents: 186
diff changeset
520 }
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
521 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
522
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
523 #if !(NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
524
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
525 if (perl) {
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
526 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log)
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
527 != NGX_OK)
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
528 {
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
529 return NGX_CONF_ERROR;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
530 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
531
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
532 pmcf->perl = perl;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
533
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
534 return NGX_CONF_OK;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
535 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
536
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
537 #endif
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
538
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
539 PERL_SYS_INIT(&ngx_argc, &ngx_argv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
540
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
541 pmcf->perl = ngx_http_perl_create_interpreter(pmcf, cf->log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
542
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
543 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
544 PERL_SYS_TERM();
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
548 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
549
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
550 cln->handler = ngx_http_perl_cleanup_perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
551 cln->data = pmcf->perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
552
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
553 #else
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
554
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
555 perl = pmcf->perl;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
556
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
557 #endif
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
558
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
559 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
560 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
561
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
562
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
563 static PerlInterpreter *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
564 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
565 ngx_log_t *log)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
566 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
567 int n;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
568 char *embedding[6];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
569 PerlInterpreter *perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
570
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
571 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "create perl interpreter");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
572
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
573 #if (NGX_HAVE_PERL_CLONE)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
574
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
575 if (pmcf->perl) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
576
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
577 perl = perl_clone(pmcf->perl, CLONEf_KEEP_PTR_TABLE);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
578 if (perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_clone() failed");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
580 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
581 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
582
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
583 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
584
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
585 dTHXa(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587 ptr_table_free(PL_ptr_table);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
588 PL_ptr_table = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
589
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
590 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
591
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
592 pmcf->nalloc++;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
593
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
594 return perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
595 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
596
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
597 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
598
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
599 perl = perl_alloc();
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
600 if (perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
601 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
602 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
603 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
604
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
605 perl_construct(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
606
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
607 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
608
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
609 dTHXa(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
610
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
611 #ifdef PERL_EXIT_DESTRUCT_END
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
612 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
613 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
614
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
615 embedding[0] = "";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
616
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
617 if (pmcf->modules.data) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
618 embedding[1] = "-I";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
619 embedding[2] = (char *) pmcf->modules.data;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
620 n = 3;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
621
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
622 } else {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
623 n = 1;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
624 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
625
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
626 embedding[n++] = "-Mnginx";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
627 embedding[n++] = "-e";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
628 embedding[n++] = "0";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
629
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630 n = perl_parse(perl, ngx_http_perl_xs_init, n, embedding, NULL);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
631
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
632 if (n != 0) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
633 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_parse() failed: %d", n);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
634 goto fail;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
635 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
637 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, log) != NGX_OK) {
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
638 goto fail;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
639 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
640
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
641 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
642
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643 pmcf->nalloc++;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
644
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
645 return perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
646
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
647 fail:
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
648
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
649 (void) perl_destruct(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
651 perl_free(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
652
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
653 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
654 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
655
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
656
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
657 static ngx_int_t
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
658 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log)
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
659 {
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
660 char **script;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
661 STRLEN len;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
662 ngx_str_t err;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
663 ngx_uint_t i;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
664
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
665 script = requires->elts;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
666 for (i = 0; i < requires->nelts; i++) {
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
667
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
668 require_pv(script[i]);
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
669
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
670 if (SvTRUE(ERRSV)) {
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
671
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
672 err.data = (u_char *) SvPV(ERRSV, len);
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
673 for (len--; err.data[len] == LF || err.data[len] == CR; len--) {
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
674 /* void */
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
675 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
676 err.len = len + 1;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
677
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
678 ngx_log_error(NGX_LOG_EMERG, log, 0,
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
679 "require_pv(\"%s\") failed: \"%V\"", script[i], &err);
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
680
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
681 return NGX_ERROR;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
682 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
683 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
684
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
685 return NGX_OK;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
686 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
687
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
688
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
689 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
690 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, SV *sub,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
691 ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
692 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
693 SV *sv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694 int n, status;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695 char *line;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 STRLEN len, n_a;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697 ngx_str_t err;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698 ngx_uint_t i;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
699
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
700 dSP;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
701
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
702 status = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
703
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
704 ENTER;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
705 SAVETMPS;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
706
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
707 PUSHMARK(sp);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
708
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
709 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx_stash));
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
710 XPUSHs(sv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
711
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
712 if (args) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
713 for (i = 0; args[i]; i++) { /* void */ }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
714
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
715 EXTEND(sp, (int) i);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
716
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
717 for (i = 0; args[i]; i++) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
718 PUSHs(sv_2mortal(newSVpvn((char *) args[i]->data, args[i]->len)));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
719 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
720 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
721
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
722 PUTBACK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
723
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
724 n = call_sv(sub, G_EVAL);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
725
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
726 SPAGAIN;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
728 if (n) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
729 if (rv == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
730 status = POPi;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
732 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
733 "call_sv: %d", status);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
734
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
735 } else {
168
3314be145cb9 nginx 0.3.31
Igor Sysoev <http://sysoev.ru>
parents: 166
diff changeset
736 line = SvPVx(POPs, n_a);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
737 rv->len = n_a;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
738
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
739 rv->data = ngx_palloc(r->pool, n_a);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
740 if (rv->data == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
741 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
742 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
743
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
744 ngx_memcpy(rv->data, line, n_a);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
745 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
746 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
747
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
748 PUTBACK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
749
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
750 FREETMPS;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
751 LEAVE;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
752
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
753 /* check $@ */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
754
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
755 if (SvTRUE(ERRSV)) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
756
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
757 err.data = (u_char *) SvPV(ERRSV, len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
758 for (len--; err.data[len] == LF || err.data[len] == CR; len--) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
759 /* void */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
761 err.len = len + 1;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
762
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
763 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
764 "call_sv(\"%V\") failed: \"%V\"",
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
765 handler, &err);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
766
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
767 if (rv) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
768 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
769 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
770
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
771 return NGX_HTTP_INTERNAL_SERVER_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
772 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
773
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
774 if (n != 1) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
775 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
776 "call_sv(\"%V\") returned %d results", handler, n);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
777 status = NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
778 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
779
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
780 if (rv) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
781 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
782 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784 return (ngx_int_t) status;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
785 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
786
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
787
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
788 static void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790 {
172
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
791 u_char *p;
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
792
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
793 for (p = handler->data; *p; p++) {
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
794 if (*p != ' ' && *p != '\t' && *p != CR && *p != LF) {
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
795 break;
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
796 }
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
797 }
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
798
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
799 if (ngx_strncmp(p, "sub ", 4) == 0 || ngx_strncmp(p, "use ", 4) == 0) {
172
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
800 *sv = eval_pv((char *) p, FALSE);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
801 return;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
803
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
804 *sv = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
805 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
806
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
808 static void *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
809 ngx_http_perl_create_main_conf(ngx_conf_t *cf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
810 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
811 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
812
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
813 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814 if (pmcf == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
816 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
817
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
818 pmcf->interp_max = NGX_CONF_UNSET_UINT;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
819
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
820 if (ngx_array_init(&pmcf->requires, cf->pool, 1, sizeof(u_char *))
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
821 != NGX_OK)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
822 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
823 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
825
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
826 return pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
827 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
828
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
829
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
830 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
831 ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
832 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
833 ngx_http_perl_main_conf_t *pmcf = conf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
835 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
212
56688ed172c8 nginx 0.3.53
Igor Sysoev <http://sysoev.ru>
parents: 202
diff changeset
836 ngx_conf_init_uint_value(pmcf->interp_max, 10);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
837 #else
212
56688ed172c8 nginx 0.3.53
Igor Sysoev <http://sysoev.ru>
parents: 202
diff changeset
838 ngx_conf_init_uint_value(pmcf->interp_max, 1);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
839 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
840
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
841 pmcf->free_perls = ngx_pcalloc(cf->pool,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
842 pmcf->interp_max * sizeof(PerlInterpreter *));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
843 if (pmcf->free_perls == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
844 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
845 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
846
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
850 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
851 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
852
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
853 #if !(NGX_HAVE_PERL_CLONE)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
854 ngx_http_perl_free_interpreter(pmcf, pmcf->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
855 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
856
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
857 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
858 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
859
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
860
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
861 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
862
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
863 static void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
864 ngx_http_perl_cleanup_perl(void *data)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
865 {
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
866 PerlInterpreter *perl = data;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
867
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
868 (void) perl_destruct(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
869
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
870 perl_free(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
871
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
872 PERL_SYS_TERM();
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
873 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
874
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
875 #endif
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
876
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
877
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
878 static void
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
879 ngx_http_perl_cleanup_sv(void *data)
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
880 {
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
881 ngx_http_perl_cleanup_t *cln = data;
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
882
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
883 dTHXa(cln->perl);
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
884
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
885 SvREFCNT_dec(cln->sv);
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
886 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
887
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
888
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
889 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
890 ngx_http_perl_preconfiguration(ngx_conf_t *cf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
891 {
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
892 #if (NGX_HTTP_SSI)
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
893 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
894 ngx_http_ssi_main_conf_t *smcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
895
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
896 smcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_ssi_filter_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
897
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
898 rc = ngx_hash_add_key(&smcf->commands, &ngx_http_perl_ssi_command.name,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
899 &ngx_http_perl_ssi_command, NGX_HASH_READONLY_KEY);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
900
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
901 if (rc != NGX_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
902 if (rc == NGX_BUSY) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
903 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
904 "conflicting SSI command \"%V\"",
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
905 &ngx_http_perl_ssi_command.name);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
906 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
907
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
908 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
909 }
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
910 #endif
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
911
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
912 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
913 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
914
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
915
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
916 static void *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
917 ngx_http_perl_create_loc_conf(ngx_conf_t *cf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
918 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
919 ngx_http_perl_loc_conf_t *plcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
920
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
921 plcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_loc_conf_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
922 if (plcf == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
923 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
924 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
925
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
926 /*
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
927 * set by ngx_pcalloc():
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
928 *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
929 * plcf->handler = { 0, NULL };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
930 */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
931
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
932 return plcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
933 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
934
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
935
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
936 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
937 ngx_http_perl_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
938 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
939 ngx_http_perl_loc_conf_t *prev = parent;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
940 ngx_http_perl_loc_conf_t *conf = child;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
941
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
942 if (conf->sub == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
943 conf->sub = prev->sub;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
944 conf->handler = prev->handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
945 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
946
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
947 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
948 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
949
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
950
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
951 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
952 ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
953 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
954 ngx_http_perl_main_conf_t *pmcf = conf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
955
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
956 u_char **p;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
957 ngx_str_t *value;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
958
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
959 value = cf->args->elts;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
960
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
961 p = ngx_array_push(&pmcf->requires);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
962
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
963 if (p == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
964 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
965 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
966
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
967 *p = value[1].data;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
968
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
969 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
970 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
971
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
972
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
973 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
974 ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
975 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
976 ngx_http_perl_loc_conf_t *plcf = conf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
977
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
978 ngx_str_t *value;
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
979 ngx_pool_cleanup_t *cln;
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
980 ngx_http_perl_cleanup_t *pcln;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
981 ngx_http_core_loc_conf_t *clcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
982 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
983
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
984 value = cf->args->elts;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
985
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
986 if (plcf->handler.data) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
987 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
988 "duplicate perl handler \"%V\"", &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
989 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
990 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
991
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
992 pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
993
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
994 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
995 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
996 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
997 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
998 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
999
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1000 cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t));
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1001 if (cln == NULL) {
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1002 return NGX_CONF_ERROR;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1003 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1004
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1005 plcf->handler = value[1];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1006
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1007 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1008
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1009 dTHXa(pmcf->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1010
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1011 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1012
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1013 if (plcf->sub == &PL_sv_undef) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1014 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1015 "eval_pv(\"%V\") failed", &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1016 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1017 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1018
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1019 if (plcf->sub == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1020 plcf->sub = newSVpvn((char *) value[1].data, value[1].len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1021 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1022
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1023 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1024
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1025 cln->handler = ngx_http_perl_cleanup_sv;
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1026 pcln = cln->data;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1027 pcln->sv = plcf->sub;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1028 pcln->perl = pmcf->perl;
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1029
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1030 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1031 clcf->handler = ngx_http_perl_handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1032
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1033 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1034 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1035
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1036
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1037 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1038 ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1039 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1040 ngx_int_t index;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1041 ngx_str_t *value;
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1042 ngx_pool_cleanup_t *cln;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1043 ngx_http_variable_t *v;
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1044 ngx_http_perl_cleanup_t *pcln;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1045 ngx_http_perl_variable_t *pv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1046 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1047
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1048 value = cf->args->elts;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1049
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1050 if (value[1].data[0] != '$') {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1051 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1052 "invalid variable name \"%V\"", &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1053 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1054 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1055
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1056 value[1].len--;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1057 value[1].data++;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1058
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1059 v = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGABLE);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1060 if (v == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1061 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1062 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1063
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1064 pv = ngx_palloc(cf->pool, sizeof(ngx_http_perl_variable_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1065 if (pv == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1066 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1067 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1068
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1069 index = ngx_http_get_variable_index(cf, &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1070 if (index == NGX_ERROR) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1071 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1072 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1073
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1074 pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1075
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1076 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1077 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1078 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1079 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1080 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1081
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1082 cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t));
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1083 if (cln == NULL) {
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1084 return NGX_CONF_ERROR;
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1085 }
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1086
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1087 pv->handler = value[2];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1088
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1089 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1090
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1091 dTHXa(pmcf->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1092
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1093 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1094
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1095 if (pv->sub == &PL_sv_undef) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1096 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1097 "eval_pv(\"%V\") failed", &value[2]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1098 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1099 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1100
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1101 if (pv->sub == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1102 pv->sub = newSVpvn((char *) value[2].data, value[2].len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1103 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1104
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1105 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1106
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1107 cln->handler = ngx_http_perl_cleanup_sv;
202
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1108 pcln = cln->data;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1109 pcln->sv = pv->sub;
ca5f86d94316 nginx 0.3.48
Igor Sysoev <http://sysoev.ru>
parents: 200
diff changeset
1110 pcln->perl = pmcf->perl;
198
e6da4931e0e0 nginx 0.3.46
Igor Sysoev <http://sysoev.ru>
parents: 188
diff changeset
1111
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
1112 v->get_handler = ngx_http_perl_variable;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1113 v->data = (uintptr_t) pv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1114
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1115 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1116 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1117
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1118
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1119 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1120 ngx_http_perl_interp_max_unsupported(ngx_conf_t *cf, void *post, void *data)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1121 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1122 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1123
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1124 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1125
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1126 #else
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1127
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1128 return "to use perl_interp_max you have to build perl with "
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1129 "-Dusemultiplicity or -Dusethreads options";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1130
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1131 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1132 }