annotate src/http/modules/perl/ngx_http_perl_module.c @ 186:54aabf2b0bc6 NGINX_0_3_40

nginx 0.3.40 *) Feature: the ngx_http_dav_module supports the MKCOL method. *) Feature: the "create_full_put_path" directive. *) Feature: the "$limit_rate" variable.
author Igor Sysoev <http://sysoev.ru>
date Wed, 19 Apr 2006 00:00:00 +0400
parents 71ff1e2b484a
children af37b7cb6698
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
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
37 #if (NGX_HTTP_SSI)
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 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
39 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
40 #endif
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
41
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
42 static void ngx_http_perl_handle_request(ngx_http_request_t *r);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 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
45 PerlInterpreter **perl, ngx_log_t *log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 static ngx_inline void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 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
48 PerlInterpreter *perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 ngx_http_perl_main_conf_t *pmcf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51 static PerlInterpreter *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 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
53 ngx_log_t *log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 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
55 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
56 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
57
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 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
59 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
60 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
61 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
62 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
63 void *child);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 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
65 void *conf);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 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
67 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
68 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
69 void *data);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 static void ngx_http_perl_cleanup_perl(void *data);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 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
74 ngx_http_perl_interp_max_unsupported;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 static ngx_command_t ngx_http_perl_commands[] = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 { ngx_string("perl_modules"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 ngx_conf_set_str_slot,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 NGX_HTTP_MAIN_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 offsetof(ngx_http_perl_main_conf_t, modules),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 NULL },
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 { ngx_string("perl_require"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 ngx_http_perl_require,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 NGX_HTTP_MAIN_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 { ngx_string("perl_interp_max"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 ngx_conf_set_num_slot,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 NGX_HTTP_MAIN_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 offsetof(ngx_http_perl_main_conf_t, interp_max),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 &ngx_http_perl_interp_max_p },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 { ngx_string("perl"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 ngx_http_perl,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 NGX_HTTP_LOC_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107 { ngx_string("perl_set"),
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 ngx_http_perl_set,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 NGX_HTTP_LOC_CONF_OFFSET,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 NULL },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 ngx_null_command
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 };
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 static ngx_http_module_t ngx_http_perl_module_ctx = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 ngx_http_perl_preconfiguration, /* preconfiguration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 NULL, /* postconfiguration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 ngx_http_perl_create_main_conf, /* create main configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 ngx_http_perl_init_main_conf, /* init main configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 NULL, /* create server configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 NULL, /* merge server configuration */
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 ngx_http_perl_create_loc_conf, /* create location configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 ngx_http_perl_merge_loc_conf /* merge location configuration */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 };
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 ngx_module_t ngx_http_perl_module = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 NGX_MODULE_V1,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 &ngx_http_perl_module_ctx, /* module context */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 ngx_http_perl_commands, /* module directives */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 NGX_HTTP_MODULE, /* module type */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 NULL, /* init master */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 NULL, /* init module */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 NULL, /* init process */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 NULL, /* init thread */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142 NULL, /* exit thread */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 NULL, /* exit process */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 NULL, /* exit master */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 NGX_MODULE_V1_PADDING
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
149 #if (NGX_HTTP_SSI)
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
150
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 #define NGX_HTTP_PERL_SSI_SUB 0
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 #define NGX_HTTP_PERL_SSI_ARG 1
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 static ngx_http_ssi_param_t ngx_http_perl_ssi_params[] = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 { ngx_string("sub"), NGX_HTTP_PERL_SSI_SUB, 1, 0 },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157 { ngx_string("arg"), NGX_HTTP_PERL_SSI_ARG, 0, 1 },
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 { ngx_null_string, 0, 0, 0 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159 };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 static ngx_http_ssi_command_t ngx_http_perl_ssi_command = {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162 ngx_string("perl"), ngx_http_perl_ssi, ngx_http_perl_ssi_params, 0, 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
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
165 #endif
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
166
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
168 static HV *nginx_stash;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
169
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 static void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 ngx_http_perl_xs_init(pTHX)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
174
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
175 nginx_stash = gv_stashpv("nginx", TRUE);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180 ngx_http_perl_handler(ngx_http_request_t *r)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
182 ngx_int_t rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
183
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
184 /* TODO: Win32 */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
185 if (r->zero_in_uri) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
186 return NGX_HTTP_NOT_FOUND;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
187 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
188
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
189 r->request_body_in_single_buf = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
190 r->request_body_in_persistent_file = 1;
184
71ff1e2b484a nginx 0.3.39
Igor Sysoev <http://sysoev.ru>
parents: 182
diff changeset
191 r->request_body_delete_incomplete_file = 1;
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
192
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
193 if (r->request_body_in_file_only) {
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
194 r->request_body_file_log_level = 0;
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
195 }
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
196
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
197 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
198
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
199 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
200 return rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
201 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
202
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
203 return NGX_DONE;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
204 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
205
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
206
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
207 static void
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
208 ngx_http_perl_handle_request(ngx_http_request_t *r)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
209 {
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 ngx_str_t uri, args;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 ngx_http_perl_ctx_t *ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 ngx_http_perl_loc_conf_t *plcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216 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
217
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218 /* mod_perl's content handler assumes that content type was already set */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220 if (ngx_http_set_content_type(r) != NGX_OK) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
221 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
222 return;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 if (ctx == NULL) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
230 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
231 return;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 }
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_http_set_ctx(r, ctx, ngx_http_perl_module);
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 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
238
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 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
240
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241 if (rc != NGX_OK) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
242 ngx_http_finalize_request(r, rc);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
243 return;
148
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
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 dTHXa(ctx->perl);
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 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
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 rc = ngx_http_perl_call_handler(aTHX_ r, plcf->sub, NULL,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 &plcf->handler, NULL);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254
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 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
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 if (rc > 600) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 rc = NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264 "perl handler done: %i", rc);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266 if (ctx->redirect_uri.len) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 uri = ctx->redirect_uri;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 args = ctx->redirect_args;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
269
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
270 } else {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
271 uri.len = 0;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
274 ctx->filename.data = NULL;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 ctx->redirect_uri.len = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 if (uri.len) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
278 ngx_http_internal_redirect(r, &uri, &args);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
279 return;
148
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 if (rc == NGX_OK || rc == NGX_HTTP_OK) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
283 ngx_http_send_special(r, NGX_HTTP_LAST);
148
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
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
286 ngx_http_finalize_request(r, rc);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291 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
292 uintptr_t data)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 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
295
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 ngx_str_t value;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 ngx_http_perl_ctx_t *ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
301 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 "perl variable handler");
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 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
308 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
310 }
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 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315 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
316
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 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
318
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319 if (rc != NGX_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323 value.data = NULL;
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 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 dTHXa(ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329 rc = ngx_http_perl_call_handler(aTHX_ r, pv->sub, NULL,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330 &pv->handler, &value);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
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 if (value.data) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337 v->len = value.len;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338 v->valid = 1;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 v->no_cachable = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340 v->not_found = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341 v->data = value.data;
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 } else {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344 v->not_found = 1;
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
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
347 ctx->filename.data = NULL;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348 ctx->redirect_uri.len = 0;
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 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
351 }
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
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
354 #if (NGX_HTTP_SSI)
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
355
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
356 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
357 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
358 ngx_str_t **params)
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 SV *sv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 ngx_str_t *handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363 ngx_http_perl_ctx_t *ctx;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 "perl ssi handler");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 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
370
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
371 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375 if (ctx == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
376 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
377 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
378
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
379 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
382 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
383
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
384 if (rc != NGX_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
385 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
386 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 ctx->ssi = ssi_ctx;
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 handler = params[NGX_HTTP_PERL_SSI_SUB];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391 handler->data[handler->len] = '\0';
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 {
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 dTHXa(ctx->perl);
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 0
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399 ngx_http_perl_eval_anon_sub(aTHX_ handler, &sv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401 if (sv == &PL_sv_undef) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403 "eval_pv(\"%V\") failed", handler);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 return NGX_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407 if (sv == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 sv = newSVpvn((char *) handler->data, handler->len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409 }
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 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413 sv = newSVpvn((char *) handler->data, handler->len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415 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
416 handler, NULL);
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 SvREFCNT_dec(sv);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
424 ctx->filename.data = NULL;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425 ctx->redirect_uri.len = 0;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426 ctx->ssi = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
427
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428 return rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
431 #endif
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
432
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435 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
436 PerlInterpreter **perl, ngx_log_t *log)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438 if (pmcf->interp) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
439 pmcf->interp--;
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 *perl = pmcf->free_perls[pmcf->interp];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
444 }
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 if (pmcf->nalloc < pmcf->interp_max) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
447 *perl = ngx_http_perl_create_interpreter(pmcf, log);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 if (*perl) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
451 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
452
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
453 return NGX_HTTP_INTERNAL_SERVER_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454 }
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 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
457
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
458 return NGX_HTTP_SERVICE_UNAVAILABLE;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462 static ngx_inline void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 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
464 PerlInterpreter *perl)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466 pmcf->free_perls[pmcf->interp++] = perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
467 }
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
471 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
472 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
473 ngx_pool_cleanup_t *cln;
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 cln = ngx_pool_cleanup_add(cf->pool, 0);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
476 if (cln == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
477 return NGX_CONF_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
480 #ifdef NGX_PERL_MODULES
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
481 if (pmcf->modules.data == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
482 pmcf->modules.data = NGX_PERL_MODULES;
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 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
486 if (ngx_conf_full_name(cf->cycle, &pmcf->modules) != NGX_OK) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
487 return NGX_CONF_ERROR;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
488 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents: 172
diff changeset
489
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490 PERL_SYS_INIT(&ngx_argc, &ngx_argv);
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->perl = ngx_http_perl_create_interpreter(pmcf, cf->log);
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 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495 PERL_SYS_TERM();
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499 cln->handler = ngx_http_perl_cleanup_perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500 cln->data = pmcf->perl;
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 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
503 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
504
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 static PerlInterpreter *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
507 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
508 ngx_log_t *log)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
509 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
510 int n;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
511 char *embedding[6];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512 char **script;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
513 STRLEN len;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
514 ngx_str_t err;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
515 ngx_uint_t i;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
516 PerlInterpreter *perl;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
517
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
518 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
519
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
520 #if (NGX_HAVE_PERL_CLONE)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
521
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
522 if (pmcf->perl) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
523
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
524 perl = perl_clone(pmcf->perl, CLONEf_KEEP_PTR_TABLE);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
525 if (perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
526 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_clone() failed");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
527 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
528 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
529
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
530 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
531
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
532 dTHXa(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
533
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
534 ptr_table_free(PL_ptr_table);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
535 PL_ptr_table = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
536
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
537 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
538
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
539 pmcf->nalloc++;
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 return perl;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
544 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546 perl = perl_alloc();
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547 if (perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
548 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed");
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
549 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
550 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
551
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
552 perl_construct(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
553
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
554 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
555
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
556 dTHXa(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
557
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
558 #ifdef PERL_EXIT_DESTRUCT_END
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
559 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
560 #endif
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 embedding[0] = "";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
563
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
564 if (pmcf->modules.data) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
565 embedding[1] = "-I";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
566 embedding[2] = (char *) pmcf->modules.data;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
567 n = 3;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
568
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
569 } else {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
570 n = 1;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
571 }
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 embedding[n++] = "-Mnginx";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
574 embedding[n++] = "-e";
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
575 embedding[n++] = "0";
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 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
578
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 if (n != 0) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
580 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
581 goto fail;
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 script = pmcf->requires.elts;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
585 for (i = 0; i < pmcf->requires.nelts; i++) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586 require_pv(script[i]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
588 if (SvTRUE(ERRSV)) {
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 err.data = (u_char *) SvPV(ERRSV, len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
591 for (len--; err.data[len] == LF || err.data[len] == CR; len--) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
592 /* void */
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 err.len = len + 1;
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 ngx_log_error(NGX_LOG_EMERG, log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
597 "require_pv(\"%s\") failed: \"%V\"", script[i], &err);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
598 goto fail;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
599 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
600 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
601
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
602 }
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 pmcf->nalloc++;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
605
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
606 return perl;
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 fail:
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
609
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
610 (void) perl_destruct(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
611
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
612 perl_free(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
613
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
614 return NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
615 }
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
618 #if (__INTEL_COMPILER)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
619 /*
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
620 * disable 'declaration hides parameter "my_perl"' warning for ENTER and LEAVE
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 #pragma warning(disable:1599)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
623 #endif
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 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
627 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
628 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
629 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630 SV *sv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
631 int n, status;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
632 char *line;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
633 STRLEN len, n_a;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
634 ngx_str_t err;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
635 ngx_uint_t i;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
637 dSP;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
638
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
639 status = 0;
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 ENTER;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
642 SAVETMPS;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
644 PUSHMARK(sp);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
645
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
646 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
647 XPUSHs(sv);
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 if (args) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650 for (i = 0; args[i]; i++) { /* void */ }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
651
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
652 EXTEND(sp, (int) i);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
653
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
654 for (i = 0; args[i]; i++) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
655 PUSHs(sv_2mortal(newSVpvn((char *) args[i]->data, args[i]->len)));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
656 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
657 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
658
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
659 PUTBACK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
660
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
661 n = call_sv(sub, G_EVAL);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
662
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
663 SPAGAIN;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
664
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
665 if (n) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
666 if (rv == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
667 status = POPi;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
668
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
669 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
670 "call_sv: %d", status);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
671
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
672 } else {
168
3314be145cb9 nginx 0.3.31
Igor Sysoev <http://sysoev.ru>
parents: 166
diff changeset
673 line = SvPVx(POPs, n_a);
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
674 rv->len = n_a;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
675
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
676 rv->data = ngx_palloc(r->pool, n_a);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
677 if (rv->data == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
678 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
679 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
680
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
681 ngx_memcpy(rv->data, line, n_a);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
682 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
683 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
684
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
685 PUTBACK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
686
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
687 FREETMPS;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
688 LEAVE;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
689
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
690 /* check $@ */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
691
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
692 if (SvTRUE(ERRSV)) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
693
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694 err.data = (u_char *) SvPV(ERRSV, len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695 for (len--; err.data[len] == LF || err.data[len] == CR; len--) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 /* void */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698 err.len = len + 1;
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 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
701 "call_sv(\"%V\") failed: \"%V\"",
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
702 handler, &err);
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 if (rv) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
705 return NGX_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
708 return NGX_HTTP_INTERNAL_SERVER_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
709 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
710
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
711 if (n != 1) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
712 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
713 "call_sv(\"%V\") returned %d results", handler, n);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
714 status = NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
715 }
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 if (rv) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
718 return NGX_OK;
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 return (ngx_int_t) status;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
722 }
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
725 #if (__INTEL_COMPILER)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
726 #pragma warning(default:1599)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
728
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
729
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
730 static void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731 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
732 {
172
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
733 u_char *p;
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
734
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
735 for (p = handler->data; *p; p++) {
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
736 if (*p != ' ' && *p != '\t' && *p != CR && *p != LF) {
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
737 break;
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
738 }
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
739 }
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
740
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
741 if (ngx_strncmp(p, "sub ", 4) == 0
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
742 || ngx_strncmp(p, "use ", 4) == 0)
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
743 {
172
1b490fc19afa nginx 0.3.33
Igor Sysoev <http://sysoev.ru>
parents: 168
diff changeset
744 *sv = eval_pv((char *) p, FALSE);
148
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 return;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
749 *sv = NULL;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
750 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
751
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 static void *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
754 ngx_http_perl_create_main_conf(ngx_conf_t *cf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
755 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
756 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
757
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
758 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
759 if (pmcf == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
761 }
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 pmcf->interp_max = NGX_CONF_UNSET_UINT;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
764
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
765 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
766 != NGX_OK)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
767 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
768 return NULL;
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 pmcf;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
775 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
776 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
777 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
778 ngx_http_perl_main_conf_t *pmcf = conf;
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 (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
781 ngx_conf_init_unsigned_value(pmcf->interp_max, 10);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
782 #else
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783 ngx_conf_init_unsigned_value(pmcf->interp_max, 1);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784 #endif
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 pmcf->free_perls = ngx_pcalloc(cf->pool,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
787 pmcf->interp_max * sizeof(PerlInterpreter *));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
788 if (pmcf->free_perls == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
791
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
792 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
793 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
794 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
795 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
796 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
797
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
798 #if !(NGX_HAVE_PERL_CLONE)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
799 ngx_http_perl_free_interpreter(pmcf, pmcf->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
800 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
801
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802 return NGX_CONF_OK;
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
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 static void
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807 ngx_http_perl_cleanup_perl(void *data)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
808 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
809 PerlInterpreter *perl = data;
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 (void) perl_destruct(perl);
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 perl_free(perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 PERL_SYS_TERM();
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
819 static ngx_int_t
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
820 ngx_http_perl_preconfiguration(ngx_conf_t *cf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
821 {
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
822 #if (NGX_HTTP_SSI)
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
823 ngx_int_t rc;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824 ngx_http_ssi_main_conf_t *smcf;
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 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
827
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
828 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
829 &ngx_http_perl_ssi_command, NGX_HASH_READONLY_KEY);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
830
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
831 if (rc != NGX_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
832 if (rc == NGX_BUSY) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
833 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834 "conflicting SSI command \"%V\"",
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
835 &ngx_http_perl_ssi_command.name);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
836 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
837
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
838 return NGX_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
839 }
166
fef68f68bcfd nginx 0.3.30
Igor Sysoev <http://sysoev.ru>
parents: 148
diff changeset
840 #endif
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
841
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
842 return NGX_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
843 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
844
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 static void *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847 ngx_http_perl_create_loc_conf(ngx_conf_t *cf)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849 ngx_http_perl_loc_conf_t *plcf;
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 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
852 if (plcf == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
853 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
854 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
855
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 * set by ngx_pcalloc():
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 * plcf->handler = { 0, NULL };
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
860 */
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
861
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
862 return plcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
863 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
864
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
865
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
866 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
867 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
868 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
869 ngx_http_perl_loc_conf_t *prev = parent;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
870 ngx_http_perl_loc_conf_t *conf = child;
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 if (conf->sub == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
873 conf->sub = prev->sub;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
874 conf->handler = prev->handler;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
875 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
876
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
877 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
878 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
879
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
880
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
881 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
882 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
883 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
884 ngx_http_perl_main_conf_t *pmcf = conf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
885
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
886 u_char **p;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
887 ngx_str_t *value;
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 value = cf->args->elts;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
890
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
891 p = ngx_array_push(&pmcf->requires);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
892
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
893 if (p == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
894 return NGX_CONF_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
897 *p = value[1].data;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
898
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
899 return NGX_CONF_OK;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
902
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
903 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
904 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
905 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
906 ngx_http_perl_loc_conf_t *plcf = conf;
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 ngx_str_t *value;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
909 ngx_http_core_loc_conf_t *clcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
910 ngx_http_perl_main_conf_t *pmcf;
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 value = cf->args->elts;
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 if (plcf->handler.data) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
915 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
916 "duplicate perl handler \"%V\"", &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
917 return NGX_CONF_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
920 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
921
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
922 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
923 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
924 return NGX_CONF_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
928 plcf->handler = value[1];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
929
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 dTHXa(pmcf->perl);
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 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub);
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 if (plcf->sub == &PL_sv_undef) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
937 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
938 "eval_pv(\"%V\") failed", &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
939 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
940 }
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 (plcf->sub == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
943 plcf->sub = newSVpvn((char *) value[1].data, value[1].len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
944 }
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
948 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
949 clcf->handler = ngx_http_perl_handler;
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 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
952 }
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
955 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
956 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
957 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
958 ngx_int_t index;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
959 ngx_str_t *value;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
960 ngx_http_variable_t *v;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
961 ngx_http_perl_variable_t *pv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
962 ngx_http_perl_main_conf_t *pmcf;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
963
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
964 value = cf->args->elts;
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 if (value[1].data[0] != '$') {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
967 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
968 "invalid variable name \"%V\"", &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
969 return NGX_CONF_ERROR;
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 value[1].len--;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
973 value[1].data++;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
974
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
975 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
976 if (v == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
977 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
978 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
979
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
980 pv = ngx_palloc(cf->pool, sizeof(ngx_http_perl_variable_t));
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
981 if (pv == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
982 return NGX_CONF_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
985 index = ngx_http_get_variable_index(cf, &value[1]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
986 if (index == NGX_ERROR) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
987 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
988 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
989
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
990 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
991
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
992 if (pmcf->perl == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
993 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
994 return NGX_CONF_ERROR;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
995 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
996 }
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 pv->handler = value[2];
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
999
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1000 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1001
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1002 dTHXa(pmcf->perl);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1003
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1004 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1005
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1006 if (pv->sub == &PL_sv_undef) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1007 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1008 "eval_pv(\"%V\") failed", &value[2]);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1009 return NGX_CONF_ERROR;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1012 if (pv->sub == NULL) {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1013 pv->sub = newSVpvn((char *) value[2].data, value[2].len);
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1014 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1015
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1016 }
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1017
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 184
diff changeset
1018 v->get_handler = ngx_http_perl_variable;
148
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1019 v->data = (uintptr_t) pv;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1020
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1021 return NGX_CONF_OK;
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
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1025 static char *
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1026 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
1027 {
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1028 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1029
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1030 return NGX_CONF_OK;
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1031
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1032 #else
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1033
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1034 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
1035 "-Dusemultiplicity or -Dusethreads options";
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 #endif
ea622d8acb38 nginx 0.3.21
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1038 }