Mercurial > hg > nginx-vendor-0-5
comparison src/http/modules/perl/ngx_http_perl_module.c @ 202:ca5f86d94316 NGINX_0_3_48
nginx 0.3.48
*) Change: now the ngx_http_charset_module works for subrequests, if
the response has no "Content-Type" header line.
*) Bugfix: if the "proxy_pass" directive has no URI part, then the
"proxy_redirect default" directive add the unnecessary slash in
start of the rewritten redirect.
*) Bugfix: the internal redirect always transform client's HTTP method
to GET, now the transformation is made for the "X-Accel-Redirect"
redirects only and if the method is not HEAD; bug appeared in 0.3.42.
*) Bugfix: the ngx_http_perl_module could not be built, if the perl was
built with the threads support; bug appeared in 0.3.46.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 29 May 2006 00:00:00 +0400 |
parents | d2ae1c9f1fd3 |
children | 56688ed172c8 |
comparison
equal
deleted
inserted
replaced
201:958c1992c173 | 202:ca5f86d94316 |
---|---|
30 | 30 |
31 typedef struct { | 31 typedef struct { |
32 SV *sub; | 32 SV *sub; |
33 ngx_str_t handler; | 33 ngx_str_t handler; |
34 } ngx_http_perl_variable_t; | 34 } ngx_http_perl_variable_t; |
35 | |
36 | |
37 typedef struct { | |
38 SV *sv; | |
39 PerlInterpreter *perl; | |
40 } ngx_http_perl_cleanup_t; | |
35 | 41 |
36 | 42 |
37 #if (NGX_HTTP_SSI) | 43 #if (NGX_HTTP_SSI) |
38 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, |
39 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); | 45 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); |
49 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, | 55 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, |
50 ngx_http_perl_main_conf_t *pmcf); | 56 ngx_http_perl_main_conf_t *pmcf); |
51 static PerlInterpreter * | 57 static PerlInterpreter * |
52 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, | 58 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, |
53 ngx_log_t *log); | 59 ngx_log_t *log); |
54 static ngx_int_t ngx_http_perl_run_requires(ngx_array_t *requires, | 60 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, |
55 ngx_log_t *log); | 61 ngx_log_t *log); |
56 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, | 62 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, |
57 SV *sub, ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv); | 63 SV *sub, ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv); |
58 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv); | 64 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv); |
59 | 65 |
476 | 482 |
477 static char * | 483 static char * |
478 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf) | 484 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf) |
479 { | 485 { |
480 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) | 486 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) |
481 ngx_pool_cleanup_t *cln; | 487 ngx_pool_cleanup_t *cln; |
482 | 488 |
483 cln = ngx_pool_cleanup_add(cf->pool, 0); | 489 cln = ngx_pool_cleanup_add(cf->pool, 0); |
484 if (cln == NULL) { | 490 if (cln == NULL) { |
485 return NGX_CONF_ERROR; | 491 return NGX_CONF_ERROR; |
486 } | 492 } |
502 } | 508 } |
503 | 509 |
504 #if !(NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) | 510 #if !(NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) |
505 | 511 |
506 if (perl) { | 512 if (perl) { |
507 if (ngx_http_perl_run_requires(&pmcf->requires, cf->log) != NGX_OK) { | 513 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log) |
514 != NGX_OK) | |
515 { | |
508 return NGX_CONF_ERROR; | 516 return NGX_CONF_ERROR; |
509 } | 517 } |
510 | 518 |
511 pmcf->perl = perl; | 519 pmcf->perl = perl; |
512 | 520 |
611 if (n != 0) { | 619 if (n != 0) { |
612 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_parse() failed: %d", n); | 620 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_parse() failed: %d", n); |
613 goto fail; | 621 goto fail; |
614 } | 622 } |
615 | 623 |
616 if (ngx_http_perl_run_requires(&pmcf->requires, log) != NGX_OK) { | 624 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, log) != NGX_OK) { |
617 goto fail; | 625 goto fail; |
618 } | 626 } |
619 | 627 |
620 } | 628 } |
621 | 629 |
632 return NULL; | 640 return NULL; |
633 } | 641 } |
634 | 642 |
635 | 643 |
636 static ngx_int_t | 644 static ngx_int_t |
637 ngx_http_perl_run_requires(ngx_array_t *requires, ngx_log_t *log) | 645 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log) |
638 { | 646 { |
639 char **script; | 647 char **script; |
640 STRLEN len; | 648 STRLEN len; |
641 ngx_str_t err; | 649 ngx_str_t err; |
642 ngx_uint_t i; | 650 ngx_uint_t i; |
868 | 876 |
869 | 877 |
870 static void | 878 static void |
871 ngx_http_perl_cleanup_sv(void *data) | 879 ngx_http_perl_cleanup_sv(void *data) |
872 { | 880 { |
873 SV *sv = data; | 881 ngx_http_perl_cleanup_t *cln = data; |
874 | 882 |
875 SvREFCNT_dec(sv); | 883 dTHXa(cln->perl); |
884 | |
885 SvREFCNT_dec(cln->sv); | |
876 } | 886 } |
877 | 887 |
878 | 888 |
879 static ngx_int_t | 889 static ngx_int_t |
880 ngx_http_perl_preconfiguration(ngx_conf_t *cf) | 890 ngx_http_perl_preconfiguration(ngx_conf_t *cf) |
965 { | 975 { |
966 ngx_http_perl_loc_conf_t *plcf = conf; | 976 ngx_http_perl_loc_conf_t *plcf = conf; |
967 | 977 |
968 ngx_str_t *value; | 978 ngx_str_t *value; |
969 ngx_pool_cleanup_t *cln; | 979 ngx_pool_cleanup_t *cln; |
980 ngx_http_perl_cleanup_t *pcln; | |
970 ngx_http_core_loc_conf_t *clcf; | 981 ngx_http_core_loc_conf_t *clcf; |
971 ngx_http_perl_main_conf_t *pmcf; | 982 ngx_http_perl_main_conf_t *pmcf; |
972 | 983 |
973 value = cf->args->elts; | 984 value = cf->args->elts; |
974 | 985 |
984 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | 995 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { |
985 return NGX_CONF_ERROR; | 996 return NGX_CONF_ERROR; |
986 } | 997 } |
987 } | 998 } |
988 | 999 |
989 cln = ngx_pool_cleanup_add(cf->pool, 0); | 1000 cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t)); |
990 if (cln == NULL) { | 1001 if (cln == NULL) { |
991 return NGX_CONF_ERROR; | 1002 return NGX_CONF_ERROR; |
992 } | 1003 } |
993 | 1004 |
994 plcf->handler = value[1]; | 1005 plcf->handler = value[1]; |
1010 } | 1021 } |
1011 | 1022 |
1012 } | 1023 } |
1013 | 1024 |
1014 cln->handler = ngx_http_perl_cleanup_sv; | 1025 cln->handler = ngx_http_perl_cleanup_sv; |
1015 cln->data = plcf->sub; | 1026 pcln = cln->data; |
1027 pcln->sv = plcf->sub; | |
1028 pcln->perl = pmcf->perl; | |
1016 | 1029 |
1017 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | 1030 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
1018 clcf->handler = ngx_http_perl_handler; | 1031 clcf->handler = ngx_http_perl_handler; |
1019 | 1032 |
1020 return NGX_CONF_OK; | 1033 return NGX_CONF_OK; |
1026 { | 1039 { |
1027 ngx_int_t index; | 1040 ngx_int_t index; |
1028 ngx_str_t *value; | 1041 ngx_str_t *value; |
1029 ngx_pool_cleanup_t *cln; | 1042 ngx_pool_cleanup_t *cln; |
1030 ngx_http_variable_t *v; | 1043 ngx_http_variable_t *v; |
1044 ngx_http_perl_cleanup_t *pcln; | |
1031 ngx_http_perl_variable_t *pv; | 1045 ngx_http_perl_variable_t *pv; |
1032 ngx_http_perl_main_conf_t *pmcf; | 1046 ngx_http_perl_main_conf_t *pmcf; |
1033 | 1047 |
1034 value = cf->args->elts; | 1048 value = cf->args->elts; |
1035 | 1049 |
1063 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | 1077 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { |
1064 return NGX_CONF_ERROR; | 1078 return NGX_CONF_ERROR; |
1065 } | 1079 } |
1066 } | 1080 } |
1067 | 1081 |
1068 cln = ngx_pool_cleanup_add(cf->pool, 0); | 1082 cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t)); |
1069 if (cln == NULL) { | 1083 if (cln == NULL) { |
1070 return NGX_CONF_ERROR; | 1084 return NGX_CONF_ERROR; |
1071 } | 1085 } |
1072 | 1086 |
1073 pv->handler = value[2]; | 1087 pv->handler = value[2]; |
1089 } | 1103 } |
1090 | 1104 |
1091 } | 1105 } |
1092 | 1106 |
1093 cln->handler = ngx_http_perl_cleanup_sv; | 1107 cln->handler = ngx_http_perl_cleanup_sv; |
1094 cln->data = pv->sub; | 1108 pcln = cln->data; |
1109 pcln->sv = pv->sub; | |
1110 pcln->perl = pmcf->perl; | |
1095 | 1111 |
1096 v->get_handler = ngx_http_perl_variable; | 1112 v->get_handler = ngx_http_perl_variable; |
1097 v->data = (uintptr_t) pv; | 1113 v->data = (uintptr_t) pv; |
1098 | 1114 |
1099 return NGX_CONF_OK; | 1115 return NGX_CONF_OK; |