Mercurial > hg > nginx
comparison src/http/modules/perl/ngx_http_perl_module.c @ 1899:d24ef26f1205
pass additional arguments in ngx_http_perl_call_handler() as SV
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 16 Feb 2008 14:29:44 +0000 |
parents | b43f244d0430 |
children | 6a4c74bea81c |
comparison
equal
deleted
inserted
replaced
1898:9a73235ce453 | 1899:d24ef26f1205 |
---|---|
46 static PerlInterpreter *ngx_http_perl_create_interpreter(ngx_conf_t *cf, | 46 static PerlInterpreter *ngx_http_perl_create_interpreter(ngx_conf_t *cf, |
47 ngx_http_perl_main_conf_t *pmcf); | 47 ngx_http_perl_main_conf_t *pmcf); |
48 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, | 48 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, |
49 ngx_log_t *log); | 49 ngx_log_t *log); |
50 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, | 50 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, |
51 HV *nginx, SV *sub, ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv); | 51 HV *nginx, SV *sub, SV **args, ngx_str_t *handler, ngx_str_t *rv); |
52 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv); | 52 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv); |
53 | 53 |
54 static ngx_int_t ngx_http_perl_preconfiguration(ngx_conf_t *cf); | 54 static ngx_int_t ngx_http_perl_preconfiguration(ngx_conf_t *cf); |
55 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf); | 55 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf); |
56 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf); | 56 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf); |
355 | 355 |
356 static ngx_int_t | 356 static ngx_int_t |
357 ngx_http_perl_ssi(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ssi_ctx, | 357 ngx_http_perl_ssi(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ssi_ctx, |
358 ngx_str_t **params) | 358 ngx_str_t **params) |
359 { | 359 { |
360 SV *sv; | 360 SV *sv, **asv; |
361 ngx_int_t rc; | 361 ngx_int_t rc; |
362 ngx_str_t *handler; | 362 ngx_str_t *handler, **args; |
363 ngx_uint_t i; | |
363 ngx_http_perl_ctx_t *ctx; | 364 ngx_http_perl_ctx_t *ctx; |
364 ngx_http_perl_main_conf_t *pmcf; | 365 ngx_http_perl_main_conf_t *pmcf; |
365 | 366 |
366 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 367 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
367 "perl ssi handler"); | 368 "perl ssi handler"); |
407 | 408 |
408 #endif | 409 #endif |
409 | 410 |
410 sv = newSVpvn((char *) handler->data, handler->len); | 411 sv = newSVpvn((char *) handler->data, handler->len); |
411 | 412 |
412 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sv, | 413 args = ¶ms[NGX_HTTP_PERL_SSI_ARG]; |
413 ¶ms[NGX_HTTP_PERL_SSI_ARG], | 414 |
414 handler, NULL); | 415 if (args) { |
416 | |
417 for (i = 0; args[i]; i++) { /* void */ } | |
418 | |
419 asv = ngx_pcalloc(r->pool, (i + 1) * sizeof(SV *)); | |
420 | |
421 if (asv == NULL) { | |
422 SvREFCNT_dec(sv); | |
423 return NGX_ERROR; | |
424 } | |
425 | |
426 asv[0] = (SV *) i; | |
427 | |
428 for (i = 0; args[i]; i++) { | |
429 asv[i + 1] = newSVpvn((char *) args[i]->data, args[i]->len); | |
430 } | |
431 | |
432 } else { | |
433 asv = NULL; | |
434 } | |
435 | |
436 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sv, asv, handler, | |
437 NULL); | |
415 | 438 |
416 SvREFCNT_dec(sv); | 439 SvREFCNT_dec(sv); |
417 | 440 |
418 } | 441 } |
419 | 442 |
620 } | 643 } |
621 | 644 |
622 | 645 |
623 static ngx_int_t | 646 static ngx_int_t |
624 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, HV *nginx, SV *sub, | 647 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, HV *nginx, SV *sub, |
625 ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv) | 648 SV **args, ngx_str_t *handler, ngx_str_t *rv) |
626 { | 649 { |
627 SV *sv; | 650 SV *sv; |
628 int n, status; | 651 int n, status; |
629 char *line; | 652 char *line; |
630 STRLEN len, n_a; | 653 STRLEN len, n_a; |
643 | 666 |
644 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx)); | 667 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx)); |
645 XPUSHs(sv); | 668 XPUSHs(sv); |
646 | 669 |
647 if (args) { | 670 if (args) { |
648 for (i = 0; args[i]; i++) { /* void */ } | 671 EXTEND(sp, (int) args[0]); |
649 | 672 |
650 EXTEND(sp, (int) i); | 673 for (i = 1; i <= (ngx_uint_t) args[0]; i++) { |
651 | 674 PUSHs(sv_2mortal(args[i])); |
652 for (i = 0; args[i]; i++) { | |
653 PUSHs(sv_2mortal(newSVpvn((char *) args[i]->data, args[i]->len))); | |
654 } | 675 } |
655 } | 676 } |
656 | 677 |
657 PUTBACK; | 678 PUTBACK; |
658 | 679 |