Mercurial > hg > nginx
comparison src/http/modules/perl/nginx.xs @ 833:dbc6819acfcc
$r->variable
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 31 Oct 2006 14:46:48 +0000 |
parents | 35454083769f |
children | 978a1e0fa9c1 |
comparison
equal
deleted
inserted
replaced
832:fe681917a24d | 833:dbc6819acfcc |
---|---|
761 *dst = '\0'; | 761 *dst = '\0'; |
762 | 762 |
763 ngx_http_perl_set_targ(p, dst - p, 1); | 763 ngx_http_perl_set_targ(p, dst - p, 1); |
764 | 764 |
765 ST(0) = TARG; | 765 ST(0) = TARG; |
766 | |
767 | |
768 void | |
769 variable(r, name, value = NULL) | |
770 CODE: | |
771 | |
772 dXSTARG; | |
773 ngx_http_request_t *r; | |
774 SV *name, *value; | |
775 u_char *p, *lowcase; | |
776 STRLEN len; | |
777 ngx_str_t var, val; | |
778 ngx_uint_t i, hash; | |
779 ngx_http_variable_value_t *vv; | |
780 | |
781 ngx_http_perl_set_request(r); | |
782 | |
783 name = ST(1); | |
784 | |
785 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
786 name = SvRV(name); | |
787 } | |
788 | |
789 if (items == 2) { | |
790 value = NULL; | |
791 | |
792 } else { | |
793 value = ST(2); | |
794 | |
795 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
796 value = SvRV(value); | |
797 } | |
798 | |
799 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) { | |
800 XSRETURN_UNDEF; | |
801 } | |
802 } | |
803 | |
804 p = (u_char *) SvPV(name, len); | |
805 | |
806 lowcase = ngx_palloc(r->pool, len); | |
807 if (lowcase == NULL) { | |
808 XSRETURN_UNDEF; | |
809 } | |
810 | |
811 hash = 0; | |
812 for (i = 0; i < len; i++) { | |
813 lowcase[i] = ngx_tolower(p[i]); | |
814 hash = ngx_hash(hash, lowcase[i]); | |
815 } | |
816 | |
817 var.len = len; | |
818 var.data = lowcase; | |
819 | |
820 vv = ngx_http_get_variable(r, &var, hash, 1); | |
821 if (vv == NULL) { | |
822 XSRETURN_UNDEF; | |
823 } | |
824 | |
825 if (vv->not_found) { | |
826 if (value == NULL) { | |
827 XSRETURN_UNDEF; | |
828 } | |
829 | |
830 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
831 "variable \"%V\" not found", &var); | |
832 | |
833 XSRETURN_UNDEF; | |
834 } | |
835 | |
836 if (value) { | |
837 vv->len = val.len; | |
838 vv->valid = 1; | |
839 vv->no_cachable = 0; | |
840 vv->not_found = 0; | |
841 vv->data = val.data; | |
842 | |
843 XSRETURN_UNDEF; | |
844 } | |
845 | |
846 ngx_http_perl_set_targ(vv->data, vv->len, 0); | |
847 | |
848 ST(0) = TARG; |