Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/perl/ngx_http_perl_module.c @ 266:251bcd11a5b8 NGINX_0_5_3
nginx 0.5.3
*) Feature: the ngx_http_perl_module supports the $r->status,
$r->log_error, and $r->sleep methods.
*) Feature: the $r->variable method supports variables that do not
exist in nginx configuration.
*) Bugfix: the $r->has_request_body method did not work.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 13 Dec 2006 00:00:00 +0300 |
parents | 6ae1357b7b7c |
children | a0c9f21ee120 |
comparison
equal
deleted
inserted
replaced
265:3d4634b3b321 | 266:251bcd11a5b8 |
---|---|
39 #if (NGX_HTTP_SSI) | 39 #if (NGX_HTTP_SSI) |
40 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r, | 40 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r, |
41 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); | 41 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); |
42 #endif | 42 #endif |
43 | 43 |
44 static void ngx_http_perl_sleep_handler(ngx_http_request_t *r); | |
44 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, | 45 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, |
45 ngx_http_perl_main_conf_t *pmcf); | 46 ngx_http_perl_main_conf_t *pmcf); |
46 static PerlInterpreter * | 47 static PerlInterpreter * |
47 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, | 48 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, |
48 ngx_log_t *log); | 49 ngx_log_t *log); |
60 void *child); | 61 void *child); |
61 static char *ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd, | 62 static char *ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd, |
62 void *conf); | 63 void *conf); |
63 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 64 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
64 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 65 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
65 static void ngx_http_perl_cleanup_sv(void *data); | |
66 | 66 |
67 #if (NGX_HAVE_PERL_MULTIPLICITY) | 67 #if (NGX_HAVE_PERL_MULTIPLICITY) |
68 static void ngx_http_perl_cleanup_perl(void *data); | 68 static void ngx_http_perl_cleanup_perl(void *data); |
69 #endif | 69 #endif |
70 | 70 |
244 } | 244 } |
245 | 245 |
246 ctx->filename.data = NULL; | 246 ctx->filename.data = NULL; |
247 ctx->redirect_uri.len = 0; | 247 ctx->redirect_uri.len = 0; |
248 | 248 |
249 if (ctx->sleep) { | |
250 ngx_add_timer(r->connection->write, (ngx_msec_t) ctx->sleep); | |
251 r->write_event_handler = ngx_http_perl_sleep_handler; | |
252 ctx->sleep = 0; | |
253 } | |
254 | |
249 if (ctx->done || ctx->next) { | 255 if (ctx->done || ctx->next) { |
250 return; | 256 return; |
251 } | 257 } |
252 | 258 |
253 if (uri.len) { | 259 if (uri.len) { |
259 ngx_http_send_special(r, NGX_HTTP_LAST); | 265 ngx_http_send_special(r, NGX_HTTP_LAST); |
260 ctx->done = 1; | 266 ctx->done = 1; |
261 } | 267 } |
262 | 268 |
263 ngx_http_finalize_request(r, rc); | 269 ngx_http_finalize_request(r, rc); |
270 } | |
271 | |
272 | |
273 static void | |
274 ngx_http_perl_sleep_handler(ngx_http_request_t *r) | |
275 { | |
276 ngx_event_t *wev; | |
277 | |
278 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
279 "perl sleep handler"); | |
280 | |
281 wev = r->connection->write; | |
282 | |
283 if (wev->timedout) { | |
284 wev->timedout = 0; | |
285 ngx_http_perl_handle_request(r); | |
286 return; | |
287 } | |
288 | |
289 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { | |
290 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
291 } | |
264 } | 292 } |
265 | 293 |
266 | 294 |
267 static ngx_int_t | 295 static ngx_int_t |
268 ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | 296 ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
756 } | 784 } |
757 | 785 |
758 #endif | 786 #endif |
759 | 787 |
760 | 788 |
761 static void | |
762 ngx_http_perl_cleanup_sv(void *data) | |
763 { | |
764 ngx_http_perl_cleanup_t *cln = data; | |
765 | |
766 dTHXa(cln->perl); | |
767 PERL_SET_CONTEXT(cln->perl); | |
768 | |
769 SvREFCNT_dec(cln->sv); | |
770 } | |
771 | |
772 | |
773 static ngx_int_t | 789 static ngx_int_t |
774 ngx_http_perl_preconfiguration(ngx_conf_t *cf) | 790 ngx_http_perl_preconfiguration(ngx_conf_t *cf) |
775 { | 791 { |
776 #if (NGX_HTTP_SSI) | 792 #if (NGX_HTTP_SSI) |
777 ngx_int_t rc; | 793 ngx_int_t rc; |
858 ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 874 ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
859 { | 875 { |
860 ngx_http_perl_loc_conf_t *plcf = conf; | 876 ngx_http_perl_loc_conf_t *plcf = conf; |
861 | 877 |
862 ngx_str_t *value; | 878 ngx_str_t *value; |
863 ngx_pool_cleanup_t *cln; | |
864 ngx_http_perl_cleanup_t *pcln; | |
865 ngx_http_core_loc_conf_t *clcf; | 879 ngx_http_core_loc_conf_t *clcf; |
866 ngx_http_perl_main_conf_t *pmcf; | 880 ngx_http_perl_main_conf_t *pmcf; |
867 | 881 |
868 value = cf->args->elts; | 882 value = cf->args->elts; |
869 | 883 |
879 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | 893 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { |
880 return NGX_CONF_ERROR; | 894 return NGX_CONF_ERROR; |
881 } | 895 } |
882 } | 896 } |
883 | 897 |
884 cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t)); | |
885 if (cln == NULL) { | |
886 return NGX_CONF_ERROR; | |
887 } | |
888 | |
889 plcf->handler = value[1]; | 898 plcf->handler = value[1]; |
890 | 899 |
891 { | 900 { |
892 | 901 |
893 dTHXa(pmcf->perl); | 902 dTHXa(pmcf->perl); |
905 plcf->sub = newSVpvn((char *) value[1].data, value[1].len); | 914 plcf->sub = newSVpvn((char *) value[1].data, value[1].len); |
906 } | 915 } |
907 | 916 |
908 } | 917 } |
909 | 918 |
910 cln->handler = ngx_http_perl_cleanup_sv; | |
911 pcln = cln->data; | |
912 pcln->sv = plcf->sub; | |
913 pcln->perl = pmcf->perl; | |
914 | |
915 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | 919 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
916 clcf->handler = ngx_http_perl_handler; | 920 clcf->handler = ngx_http_perl_handler; |
917 | 921 |
918 return NGX_CONF_OK; | 922 return NGX_CONF_OK; |
919 } | 923 } |
922 static char * | 926 static char * |
923 ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 927 ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
924 { | 928 { |
925 ngx_int_t index; | 929 ngx_int_t index; |
926 ngx_str_t *value; | 930 ngx_str_t *value; |
927 ngx_pool_cleanup_t *cln; | |
928 ngx_http_variable_t *v; | 931 ngx_http_variable_t *v; |
929 ngx_http_perl_cleanup_t *pcln; | |
930 ngx_http_perl_variable_t *pv; | 932 ngx_http_perl_variable_t *pv; |
931 ngx_http_perl_main_conf_t *pmcf; | 933 ngx_http_perl_main_conf_t *pmcf; |
932 | 934 |
933 value = cf->args->elts; | 935 value = cf->args->elts; |
934 | 936 |
962 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { | 964 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { |
963 return NGX_CONF_ERROR; | 965 return NGX_CONF_ERROR; |
964 } | 966 } |
965 } | 967 } |
966 | 968 |
967 cln = ngx_pool_cleanup_add(cf->pool, sizeof(ngx_http_perl_cleanup_t)); | |
968 if (cln == NULL) { | |
969 return NGX_CONF_ERROR; | |
970 } | |
971 | |
972 pv->handler = value[2]; | 969 pv->handler = value[2]; |
973 | 970 |
974 { | 971 { |
975 | 972 |
976 dTHXa(pmcf->perl); | 973 dTHXa(pmcf->perl); |
988 pv->sub = newSVpvn((char *) value[2].data, value[2].len); | 985 pv->sub = newSVpvn((char *) value[2].data, value[2].len); |
989 } | 986 } |
990 | 987 |
991 } | 988 } |
992 | 989 |
993 cln->handler = ngx_http_perl_cleanup_sv; | |
994 pcln = cln->data; | |
995 pcln->sv = pv->sub; | |
996 pcln->perl = pmcf->perl; | |
997 | |
998 v->get_handler = ngx_http_perl_variable; | 990 v->get_handler = ngx_http_perl_variable; |
999 v->data = (uintptr_t) pv; | 991 v->data = (uintptr_t) pv; |
1000 | 992 |
1001 return NGX_CONF_OK; | 993 return NGX_CONF_OK; |
1002 } | 994 } |