Mercurial > hg > nginx-quic
comparison src/http/modules/perl/nginx.xs @ 912:7fa926a7926d
$r->variable() supports perl only variables
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 12 Dec 2006 22:06:03 +0000 |
parents | 73c66ed9a9cd |
children | 28aa941811e6 |
comparison
equal
deleted
inserted
replaced
911:73c66ed9a9cd | 912:7fa926a7926d |
---|---|
771 SV *name, *value; | 771 SV *name, *value; |
772 u_char *p, *lowcase; | 772 u_char *p, *lowcase; |
773 STRLEN len; | 773 STRLEN len; |
774 ngx_str_t var, val; | 774 ngx_str_t var, val; |
775 ngx_uint_t i, hash; | 775 ngx_uint_t i, hash; |
776 ngx_http_perl_var_t *v; | |
777 ngx_http_perl_ctx_t *ctx; | |
776 ngx_http_variable_value_t *vv; | 778 ngx_http_variable_value_t *vv; |
777 | 779 |
778 ngx_http_perl_set_request(r); | 780 ngx_http_perl_set_request(r); |
779 | 781 |
780 name = ST(1); | 782 name = ST(1); |
812 } | 814 } |
813 | 815 |
814 var.len = len; | 816 var.len = len; |
815 var.data = lowcase; | 817 var.data = lowcase; |
816 | 818 |
819 #if (NGX_LOG_DEBUG) | |
820 | |
821 if (value) { | |
822 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
823 "perl variable: \"%V\"=\"%V\"", &var, &val); | |
824 } else { | |
825 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
826 "perl variable: \"%V\"", &var); | |
827 } | |
828 | |
829 #endif | |
830 | |
817 vv = ngx_http_get_variable(r, &var, hash, 1); | 831 vv = ngx_http_get_variable(r, &var, hash, 1); |
818 if (vv == NULL) { | 832 if (vv == NULL) { |
819 XSRETURN_UNDEF; | 833 XSRETURN_UNDEF; |
820 } | 834 } |
821 | 835 |
822 if (vv->not_found) { | 836 if (vv->not_found) { |
823 if (value == NULL) { | 837 |
838 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
839 | |
840 if (ctx->variables) { | |
841 | |
842 v = ctx->variables->elts; | |
843 for (i = 0; i < ctx->variables->nelts; i++) { | |
844 | |
845 if (hash != v[i].hash | |
846 || len != v[i].name.len | |
847 || ngx_strncmp(lowcase, v[i].name.data, len) != 0) | |
848 { | |
849 continue; | |
850 } | |
851 | |
852 if (value) { | |
853 v[i].value = val; | |
854 XSRETURN_UNDEF; | |
855 } | |
856 | |
857 ngx_http_perl_set_targ(v[i].value.data, v[i].value.len, 0); | |
858 | |
859 goto done; | |
860 } | |
861 } | |
862 | |
863 if (value) { | |
864 if (ctx->variables == NULL) { | |
865 ctx->variables = ngx_array_create(r->pool, 1, | |
866 sizeof(ngx_http_perl_var_t)); | |
867 if (ctx->variables == NULL) { | |
868 XSRETURN_UNDEF; | |
869 } | |
870 } | |
871 | |
872 v = ngx_array_push(ctx->variables); | |
873 if (v == NULL) { | |
874 XSRETURN_UNDEF; | |
875 } | |
876 | |
877 v->hash = hash; | |
878 v->name.len = len; | |
879 v->name.data = lowcase; | |
880 v->value = val; | |
881 | |
824 XSRETURN_UNDEF; | 882 XSRETURN_UNDEF; |
825 } | 883 } |
826 | 884 |
827 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 885 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
828 "variable \"%V\" not found", &var); | 886 "variable \"%V\" not found", &var); |
840 XSRETURN_UNDEF; | 898 XSRETURN_UNDEF; |
841 } | 899 } |
842 | 900 |
843 ngx_http_perl_set_targ(vv->data, vv->len, 0); | 901 ngx_http_perl_set_targ(vv->data, vv->len, 0); |
844 | 902 |
903 done: | |
904 | |
845 ST(0) = TARG; | 905 ST(0) = TARG; |
846 | 906 |
847 | 907 |
848 void | 908 void |
849 sleep(r, sleep, next) | 909 sleep(r, sleep, next) |