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

nginx 0.4.0 *) Change in internal API: the HTTP modules initialization was moved from the init module phase to the HTTP postconfiguration phase. *) Change: now the request body is not read beforehand for the ngx_http_perl_module: it's required to start the reading using the $r->has_request_body method. *) Feature: the ngx_http_perl_module supports the DECLINED return code. *) Feature: the ngx_http_dav_module supports the incoming "Date" header line for the PUT method. *) Feature: the "ssi" directive is available inside the "if" block. *) Bugfix: a segmentation fault occurred if there was an "index" directive with variables and the first index name was without variables; bug appeared in 0.1.29.
author Igor Sysoev <http://sysoev.ru>
date Wed, 30 Aug 2006 00:00:00 +0400
parents dd6c66b5b0e2
children acd2ec3541cb
comparison
equal deleted inserted replaced
229:1965c8e23be7 230:38e7b94d63ac
43 #if (NGX_HTTP_SSI) 43 #if (NGX_HTTP_SSI)
44 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r, 44 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r,
45 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); 45 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params);
46 #endif 46 #endif
47 47
48 static void ngx_http_perl_handle_request(ngx_http_request_t *r);
49 static ngx_int_t 48 static ngx_int_t
50 ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf, 49 ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf,
51 PerlInterpreter **perl, ngx_log_t *log); 50 PerlInterpreter **perl, ngx_log_t *log);
52 static ngx_inline void 51 static ngx_inline void
53 ngx_http_perl_free_interpreter(ngx_http_perl_main_conf_t *pmcf, 52 ngx_http_perl_free_interpreter(ngx_http_perl_main_conf_t *pmcf,
174 }; 173 };
175 174
176 #endif 175 #endif
177 176
178 177
178 static ngx_str_t ngx_null_name = ngx_null_string;
179
180
179 static HV *nginx_stash; 181 static HV *nginx_stash;
180 182
181 static void 183 static void
182 ngx_http_perl_xs_init(pTHX) 184 ngx_http_perl_xs_init(pTHX)
183 { 185 {
188 190
189 191
190 static ngx_int_t 192 static ngx_int_t
191 ngx_http_perl_handler(ngx_http_request_t *r) 193 ngx_http_perl_handler(ngx_http_request_t *r)
192 { 194 {
193 ngx_int_t rc;
194
195 /* TODO: Win32 */ 195 /* TODO: Win32 */
196 if (r->zero_in_uri) { 196 if (r->zero_in_uri) {
197 return NGX_HTTP_NOT_FOUND; 197 return NGX_HTTP_NOT_FOUND;
198 } 198 }
199 199
200 ngx_http_perl_handle_request(r);
201
202 return NGX_DONE;
203
204 #if 0
200 r->request_body_in_single_buf = 1; 205 r->request_body_in_single_buf = 1;
201 r->request_body_in_persistent_file = 1; 206 r->request_body_in_persistent_file = 1;
202 r->request_body_delete_incomplete_file = 1; 207 r->request_body_delete_incomplete_file = 1;
203 208
204 if (r->request_body_in_file_only) { 209 if (r->request_body_in_file_only) {
210 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { 215 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
211 return rc; 216 return rc;
212 } 217 }
213 218
214 return NGX_DONE; 219 return NGX_DONE;
215 } 220 #endif
216 221 }
217 222
218 static void 223
224 void
219 ngx_http_perl_handle_request(ngx_http_request_t *r) 225 ngx_http_perl_handle_request(ngx_http_request_t *r)
220 { 226 {
227 SV *sub;
221 ngx_int_t rc; 228 ngx_int_t rc;
222 ngx_str_t uri, args; 229 ngx_str_t uri, args, *handler;
223 ngx_http_perl_ctx_t *ctx; 230 ngx_http_perl_ctx_t *ctx;
224 ngx_http_perl_loc_conf_t *plcf; 231 ngx_http_perl_loc_conf_t *plcf;
225 ngx_http_perl_main_conf_t *pmcf; 232 ngx_http_perl_main_conf_t *pmcf;
226 233
227 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "perl handler"); 234 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "perl handler");
229 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); 236 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
230 237
231 if (ctx == NULL) { 238 if (ctx == NULL) {
232 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t)); 239 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
233 if (ctx == NULL) { 240 if (ctx == NULL) {
234 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 241 ngx_http_finalize_request(r, NGX_ERROR);
235 return; 242 return;
236 } 243 }
237 244
238 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); 245 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
239 } 246 }
249 256
250 { 257 {
251 258
252 dTHXa(ctx->perl); 259 dTHXa(ctx->perl);
253 260
254 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module); 261 if (ctx->next == NULL) {
255 262 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
256 rc = ngx_http_perl_call_handler(aTHX_ r, plcf->sub, NULL, 263 sub = plcf->sub;
257 &plcf->handler, NULL); 264 handler = &plcf->handler;
265
266 } else {
267 sub = ctx->next;
268 handler = &ngx_null_name;
269 ctx->next = NULL;
270 }
271
272 rc = ngx_http_perl_call_handler(aTHX_ r, sub, NULL, handler, NULL);
258 273
259 } 274 }
260 275
261 ngx_http_perl_free_interpreter(pmcf, ctx->perl); 276 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
262 277
276 } 291 }
277 292
278 ctx->filename.data = NULL; 293 ctx->filename.data = NULL;
279 ctx->redirect_uri.len = 0; 294 ctx->redirect_uri.len = 0;
280 295
296 if (ctx->done || ctx->next) {
297 return;
298 }
299
281 if (uri.len) { 300 if (uri.len) {
282 ngx_http_internal_redirect(r, &uri, &args); 301 ngx_http_internal_redirect(r, &uri, &args);
283 return; 302 return;
284 } 303 }
285 304
286 if (rc == NGX_OK || rc == NGX_HTTP_OK) { 305 if (rc == NGX_OK || rc == NGX_HTTP_OK) {
287 ngx_http_send_special(r, NGX_HTTP_LAST); 306 ngx_http_send_special(r, NGX_HTTP_LAST);
307 ctx->done = 1;
288 } 308 }
289 309
290 ngx_http_finalize_request(r, rc); 310 ngx_http_finalize_request(r, rc);
291 } 311 }
292 312
664 684
665 return NGX_OK; 685 return NGX_OK;
666 } 686 }
667 687
668 688
669 #if (__INTEL_COMPILER)
670 /*
671 * disable 'declaration hides parameter "my_perl"' warning for ENTER and LEAVE
672 */
673 #pragma warning(disable:1599)
674 #endif
675
676
677 static ngx_int_t 689 static ngx_int_t
678 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, SV *sub, 690 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, SV *sub,
679 ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv) 691 ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv)
680 { 692 {
681 SV *sv; 693 SV *sv;
769 return NGX_OK; 781 return NGX_OK;
770 } 782 }
771 783
772 return (ngx_int_t) status; 784 return (ngx_int_t) status;
773 } 785 }
774
775
776 #if (__INTEL_COMPILER)
777 #pragma warning(default:1599)
778 #endif
779 786
780 787
781 static void 788 static void
782 ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv) 789 ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv)
783 { 790 {