annotate src/http/modules/perl/nginx.xs @ 7528:0cb693b4cbbb

Perl: disabled unrelated calls from variable handlers. Variable handlers are not expected to send anything to the client, cannot sleep or read body, and are not expected to modify the request. Added appropriate protection to prevent accidental foot shooting.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 12 Jul 2019 15:35:31 +0300
parents 02cd116ebe2a
children fd9252844ec1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4196
diff changeset
4 * Copyright (C) Nginx, Inc.
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
882
26c3e48b9996 the PERL_NO_GET_CONTEXT is actually required, see perlguts
Igor Sysoev <igor@sysoev.ru>
parents: 869
diff changeset
8 #define PERL_NO_GET_CONTEXT
26c3e48b9996 the PERL_NO_GET_CONTEXT is actually required, see perlguts
Igor Sysoev <igor@sysoev.ru>
parents: 869
diff changeset
9
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_config.h>
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 #include <ngx_core.h>
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 #include <ngx_http.h>
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 #include <ngx_http_perl_module.h>
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
603
858700ae46b4 nginx-0.3.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 601
diff changeset
15 #include "XSUB.h"
858700ae46b4 nginx-0.3.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 601
diff changeset
16
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
17
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
18 #define ngx_http_perl_set_request(r, ctx) \
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
19 \
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
20 ctx = INT2PTR(ngx_http_perl_ctx_t *, SvIV((SV *) SvRV(ST(0)))); \
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
21 r = ctx->request
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
22
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
23
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
24 #define ngx_http_perl_set_targ(p, len) \
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
25 \
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
26 SvUPGRADE(TARG, SVt_PV); \
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
27 SvPOK_on(TARG); \
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
28 sv_setpvn(TARG, (char *) p, len)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
29
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static ngx_int_t
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv)
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 u_char *p;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 STRLEN len;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 sv = SvRV(sv);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 p = (u_char *) SvPV(sv, len);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 s->len = len;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44
1703
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
45 if (SvREADONLY(sv) && SvPOK(sv)) {
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 s->data = p;
1703
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
47
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
48 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
49 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s);
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
50
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 return NGX_OK;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1898
diff changeset
54 s->data = ngx_pnalloc(r->pool, len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 if (s->data == NULL) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 return NGX_ERROR;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 ngx_memcpy(s->data, p, len);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60
1703
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
61 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
62 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s);
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
63
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 return NGX_OK;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 static ngx_int_t
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
69 ngx_http_perl_output(ngx_http_request_t *r, ngx_http_perl_ctx_t *ctx,
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
70 ngx_buf_t *b)
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 {
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
72 ngx_chain_t out;
617
51b27717f140 nginx-0.3.30-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 613
diff changeset
73 #if (NGX_HTTP_SSI)
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
74 ngx_chain_t *cl;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 if (ctx->ssi) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 cl = ngx_alloc_chain_link(r->pool);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 if (cl == NULL) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 return NGX_ERROR;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 cl->buf = b;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 cl->next = NULL;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 *ctx->ssi->last_out = cl;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 ctx->ssi->last_out = &cl->next;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 return NGX_OK;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 }
617
51b27717f140 nginx-0.3.30-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 613
diff changeset
89 #endif
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 out.buf = b;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 out.next = NULL;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 return ngx_http_output_filter(r, &out);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 MODULE = nginx PACKAGE = nginx
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
6233
c6cc0b79a43d Perl: prototyping behavior explicitly specified.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6232
diff changeset
101 PROTOTYPES: DISABLE
c6cc0b79a43d Perl: prototyping behavior explicitly specified.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6232
diff changeset
102
c6cc0b79a43d Perl: prototyping behavior explicitly specified.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6232
diff changeset
103
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
104 void
915
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
105 status(r, code)
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
106 CODE:
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
107
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
108 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
109 ngx_http_perl_ctx_t *ctx;
915
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
110
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
111 ngx_http_perl_set_request(r, ctx);
915
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
112
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
113 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
114 croak("status(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
115 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
116
915
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
117 r->headers_out.status = SvIV(ST(1));
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
118
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
119 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
120 "perl status: %d", r->headers_out.status);
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
121
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
122 XSRETURN_UNDEF;
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
123
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
124
28aa941811e6 $r->status
Igor Sysoev <igor@sysoev.ru>
parents: 912
diff changeset
125 void
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 send_http_header(r, ...)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
127 CODE:
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
129 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
130 ngx_http_perl_ctx_t *ctx;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
131 SV *sv;
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
132 ngx_int_t rc;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
134 ngx_http_perl_set_request(r, ctx);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
136 if (ctx->error) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
137 croak("send_http_header(): called after error");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
138 }
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
139
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
140 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
141 croak("send_http_header(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
142 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
143
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 if (r->headers_out.status == 0) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 r->headers_out.status = NGX_HTTP_OK;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 if (items != 1) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 sv = ST(1);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv)
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 != NGX_OK)
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
154 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
155 croak("ngx_http_perl_sv2str() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
1444
37938e68910b allow to append charset to the "Content-Type" header
Igor Sysoev <igor@sysoev.ru>
parents: 1372
diff changeset
158 r->headers_out.content_type_len = r->headers_out.content_type.len;
37938e68910b allow to append charset to the "Content-Type" header
Igor Sysoev <igor@sysoev.ru>
parents: 1372
diff changeset
159
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 } else {
673
b80f94fa2197 nginx-0.3.58-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
161 if (ngx_http_set_content_type(r) != NGX_OK) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
162 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
163 croak("ngx_http_set_content_type() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
7516
36c52a0f6ded Perl: disabled not_modified filter (ticket #1786).
Maxim Dounin <mdounin@mdounin.ru>
parents: 6986
diff changeset
167 r->disable_not_modified = 1;
36c52a0f6ded Perl: disabled not_modified filter (ticket #1786).
Maxim Dounin <mdounin@mdounin.ru>
parents: 6986
diff changeset
168
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
169 rc = ngx_http_send_header(r);
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
170
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
171 if (rc == NGX_ERROR || rc > NGX_OK) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
172 ctx->error = 1;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
173 ctx->status = rc;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
174 croak("ngx_http_send_header() failed");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
175 }
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
178 void
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
179 header_only(r)
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 CODE:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
182 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
183 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
184 ngx_http_perl_ctx_t *ctx;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
185
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
186 ngx_http_perl_set_request(r, ctx);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
188 sv_upgrade(TARG, SVt_IV);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
189 sv_setiv(TARG, r->header_only);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
191 ST(0) = TARG;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
194 void
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
195 uri(r)
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
196 CODE:
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
197
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
198 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
199 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
200 ngx_http_perl_ctx_t *ctx;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
202 ngx_http_perl_set_request(r, ctx);
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
203 ngx_http_perl_set_targ(r->uri.data, r->uri.len);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
204
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
205 ST(0) = TARG;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
206
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
207
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
208 void
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
209 args(r)
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 CODE:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
212 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
213 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
214 ngx_http_perl_ctx_t *ctx;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
216 ngx_http_perl_set_request(r, ctx);
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
217 ngx_http_perl_set_targ(r->args.data, r->args.len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
219 ST(0) = TARG;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
222 void
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
223 request_method(r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
224 CODE:
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
225
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
226 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
227 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
228 ngx_http_perl_ctx_t *ctx;
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
229
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
230 ngx_http_perl_set_request(r, ctx);
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
231 ngx_http_perl_set_targ(r->method_name.data, r->method_name.len);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
232
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
233 ST(0) = TARG;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
234
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
235
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
236 void
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
237 remote_addr(r)
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
238 CODE:
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
239
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
240 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
241 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
242 ngx_http_perl_ctx_t *ctx;
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
243
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
244 ngx_http_perl_set_request(r, ctx);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
245 ngx_http_perl_set_targ(r->connection->addr_text.data,
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
246 r->connection->addr_text.len);
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
247
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
248 ST(0) = TARG;
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
249
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
250
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
251 void
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
252 header_in(r, key)
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
253 CODE:
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
254
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
255 dXSTARG;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
256 ngx_http_request_t *r;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
257 ngx_http_perl_ctx_t *ctx;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
258 SV *key;
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
259 u_char *p, *lowcase_key, *value, sep;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
260 STRLEN len;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
261 ssize_t size;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
262 ngx_uint_t i, n, hash;
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
263 ngx_array_t *a;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
264 ngx_list_part_t *part;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
265 ngx_table_elt_t *h, **ph;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
266 ngx_http_header_t *hh;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
267 ngx_http_core_main_conf_t *cmcf;
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 617
diff changeset
268
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
269 ngx_http_perl_set_request(r, ctx);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
271 key = ST(1);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 key = SvRV(key);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277 p = (u_char *) SvPV(key, len);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
279 /* look up hashed headers */
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
280
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1898
diff changeset
281 lowcase_key = ngx_pnalloc(r->pool, len);
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
282 if (lowcase_key == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
283 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
284 croak("ngx_pnalloc() failed");
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
285 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
286
2136
7a7c9e9024dd ngx_hash_strlow()
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
287 hash = ngx_hash_strlow(lowcase_key, p, len);
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
288
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
289 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
290
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
291 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len);
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
292
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
293 if (hh) {
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
294
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
295 if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) {
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
296 sep = ';';
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
297 goto multi;
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
298 }
5306
43900b822890 Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5248
diff changeset
299 #if (NGX_HTTP_X_FORWARDED_FOR)
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
300 if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) {
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
301 sep = ',';
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
302 goto multi;
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
303 }
5306
43900b822890 Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5248
diff changeset
304 #endif
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
305
6232
5f2a0739da19 Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5306
diff changeset
306 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
307
6232
5f2a0739da19 Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5306
diff changeset
308 if (*ph) {
5f2a0739da19 Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5306
diff changeset
309 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
310
6232
5f2a0739da19 Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5306
diff changeset
311 goto done;
5f2a0739da19 Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5306
diff changeset
312 }
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
313
6232
5f2a0739da19 Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5306
diff changeset
314 XSRETURN_UNDEF;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
315
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
316 multi:
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
317
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
318 /* Cookie, X-Forwarded-For */
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
319
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
320 a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset);
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
321
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
322 n = a->nelts;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
323
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
324 if (n == 0) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
325 XSRETURN_UNDEF;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
326 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
327
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
328 ph = a->elts;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
329
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
330 if (n == 1) {
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
331 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
332
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
333 goto done;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
334 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
335
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
336 size = - (ssize_t) (sizeof("; ") - 1);
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
337
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
338 for (i = 0; i < n; i++) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
339 size += ph[i]->value.len + sizeof("; ") - 1;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
340 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
341
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
342 value = ngx_pnalloc(r->pool, size);
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
343 if (value == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
344 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
345 croak("ngx_pnalloc() failed");
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
346 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
347
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
348 p = value;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
349
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
350 for (i = 0; /* void */ ; i++) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
351 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
352
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
353 if (i == n - 1) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
354 break;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
355 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
356
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
357 *p++ = sep; *p++ = ' ';
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
358 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
359
5248
f5626ab8cb87 Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5198
diff changeset
360 ngx_http_perl_set_targ(value, size);
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
361
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
362 goto done;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
363 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
364
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
365 /* iterate over all headers */
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
366
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 part = &r->headers_in.headers.part;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
368 h = part->elts;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370 for (i = 0; /* void */ ; i++) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372 if (i >= part->nelts) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373 if (part->next == NULL) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 break;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377 part = part->next;
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
378 h = part->elts;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
379 i = 0;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
382 if (len != h[i].key.len
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
383 || ngx_strcasecmp(p, h[i].key.data) != 0)
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384 {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 continue;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
388 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390 goto done;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
393 XSRETURN_UNDEF;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 done:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
396
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
397 ST(0) = TARG;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
400 void
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
401 has_request_body(r, next)
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
402 CODE:
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
403
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
404 dXSTARG;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
405 ngx_http_request_t *r;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
406 ngx_http_perl_ctx_t *ctx;
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
407 ngx_int_t rc;
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
408
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
409 ngx_http_perl_set_request(r, ctx);
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
410
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
411 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
412 croak("has_request_body(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
413 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
414
7527
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
415 if (ctx->next) {
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
416 croak("has_request_body(): another handler active");
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
417 }
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
418
5181
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
419 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) {
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
420 XSRETURN_UNDEF;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
421 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
422
909
f01e6664f9be fix $r->has_request_body()
Igor Sysoev <igor@sysoev.ru>
parents: 907
diff changeset
423 ctx->next = SvRV(ST(1));
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
424
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
425 r->request_body_in_single_buf = 1;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
426 r->request_body_in_persistent_file = 1;
1075
4d203f76b757 undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents: 1056
diff changeset
427 r->request_body_in_clean_file = 1;
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
428
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
429 if (r->request_body_in_file_only) {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
430 r->request_body_file_log_level = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
431 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
432
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
433 rc = ngx_http_read_client_request_body(r, ngx_http_perl_handle_request);
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
434
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
435 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
436 ctx->error = 1;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
437 ctx->status = rc;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
438 ctx->next = NULL;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
439 croak("ngx_http_read_client_request_body() failed");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
440 }
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
441
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
442 sv_upgrade(TARG, SVt_IV);
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
443 sv_setiv(TARG, 1);
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
444
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
445 ST(0) = TARG;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
446
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
447
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 673
diff changeset
448 void
631
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
449 request_body(r)
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
450 CODE:
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
451
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
452 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
453 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
454 ngx_http_perl_ctx_t *ctx;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
455 u_char *p, *data;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
456 size_t len;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
457 ngx_buf_t *buf;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
458 ngx_chain_t *cl;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
459
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
460 ngx_http_perl_set_request(r, ctx);
631
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
461
941
97489c43e755 fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 915
diff changeset
462 if (r->request_body == NULL
97489c43e755 fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 915
diff changeset
463 || r->request_body->temp_file
97489c43e755 fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 915
diff changeset
464 || r->request_body->bufs == NULL)
97489c43e755 fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 915
diff changeset
465 {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
466 XSRETURN_UNDEF;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
467 }
631
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
468
5181
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
469 cl = r->request_body->bufs;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
470 buf = cl->buf;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
471
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
472 if (cl->next == NULL) {
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
473 len = buf->last - buf->pos;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
474 data = buf->pos;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
475 goto done;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
476 }
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
477
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
478 len = buf->last - buf->pos;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
479 cl = cl->next;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
480
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
481 for ( /* void */ ; cl; cl = cl->next) {
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
482 buf = cl->buf;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
483 len += buf->last - buf->pos;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
484 }
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
485
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
486 p = ngx_pnalloc(r->pool, len);
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
487 if (p == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
488 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
489 croak("ngx_pnalloc() failed");
5181
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
490 }
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
491
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
492 data = p;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
493 cl = r->request_body->bufs;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
494
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
495 for ( /* void */ ; cl; cl = cl->next) {
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
496 buf = cl->buf;
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
497 p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
498 }
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
499
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
500 done:
631
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
501
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
502 if (len == 0) {
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
503 XSRETURN_UNDEF;
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
504 }
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
505
5181
4d0ac175f6e4 Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4644
diff changeset
506 ngx_http_perl_set_targ(data, len);
631
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
507
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
508 ST(0) = TARG;
631
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
509
5d2b8078c1c2 nginx-0.3.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 629
diff changeset
510
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
511 void
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
512 request_body_file(r)
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
513 CODE:
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
514
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
515 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
516 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
517 ngx_http_perl_ctx_t *ctx;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
518
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
519 ngx_http_perl_set_request(r, ctx);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
520
941
97489c43e755 fix segfault
Igor Sysoev <igor@sysoev.ru>
parents: 915
diff changeset
521 if (r->request_body == NULL || r->request_body->temp_file == NULL) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
522 XSRETURN_UNDEF;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
523 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
524
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
525 ngx_http_perl_set_targ(r->request_body->temp_file->file.name.data,
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
526 r->request_body->temp_file->file.name.len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
528 ST(0) = TARG;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
529
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
530
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
531 void
1371
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
532 discard_request_body(r)
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
533 CODE:
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
534
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
535 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
536 ngx_http_perl_ctx_t *ctx;
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
537 ngx_int_t rc;
1371
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
538
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
539 ngx_http_perl_set_request(r, ctx);
1371
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
540
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
541 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
542 croak("discard_request_body(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
543 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
544
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
545 rc = ngx_http_discard_request_body(r);
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
546
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
547 if (rc != NGX_OK) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
548 ctx->error = 1;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
549 ctx->status = rc;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
550 croak("ngx_http_discard_request_body() failed");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
551 }
1371
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
552
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
553
7dbdf47cdcba $r->discard_request_body
Igor Sysoev <igor@sysoev.ru>
parents: 1178
diff changeset
554 void
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
555 header_out(r, key, value)
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
556 CODE:
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
557
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
558 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
559 ngx_http_perl_ctx_t *ctx;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
560 SV *key;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
561 SV *value;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
562 ngx_table_elt_t *header;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
563
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
564 ngx_http_perl_set_request(r, ctx);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
565
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
566 if (ctx->error) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
567 croak("header_out(): called after error");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
568 }
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
569
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
570 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
571 croak("header_out(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
572 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
573
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
574 key = ST(1);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
575 value = ST(2);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
576
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577 header = ngx_list_push(&r->headers_out.headers);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 if (header == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
579 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
580 croak("ngx_list_push() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
581 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
582
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583 header->hash = 1;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585 if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) {
6986
0cdee26605f3 Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6960
diff changeset
586 header->hash = 0;
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
587 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
588 croak("ngx_http_perl_sv2str() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
589 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
591 if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) {
6986
0cdee26605f3 Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6960
diff changeset
592 header->hash = 0;
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
593 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
594 croak("ngx_http_perl_sv2str() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
595 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
596
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597 if (header->key.len == sizeof("Content-Length") - 1
3870
8cd7594916ec fix warnings
Igor Sysoev <igor@sysoev.ru>
parents: 3500
diff changeset
598 && ngx_strncasecmp(header->key.data, (u_char *) "Content-Length",
741
63a08390a8a2 $r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
599 sizeof("Content-Length") - 1) == 0)
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600 {
741
63a08390a8a2 $r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
601 r->headers_out.content_length_n = (off_t) SvIV(value);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
602 r->headers_out.content_length = header;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604
4196
190ae1a7f917 Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4188
diff changeset
605 if (header->key.len == sizeof("Content-Encoding") - 1
4644
95763fce86a8 Fixed warning during nginx.xs compilation.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4494
diff changeset
606 && ngx_strncasecmp(header->key.data, (u_char *) "Content-Encoding",
4196
190ae1a7f917 Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4188
diff changeset
607 sizeof("Content-Encoding") - 1) == 0)
190ae1a7f917 Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4188
diff changeset
608 {
190ae1a7f917 Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4188
diff changeset
609 r->headers_out.content_encoding = header;
190ae1a7f917 Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4188
diff changeset
610 }
190ae1a7f917 Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4188
diff changeset
611
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
613 void
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
614 filename(r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
615 CODE:
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
617 dXSTARG;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
618 ngx_http_request_t *r;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 ngx_http_perl_ctx_t *ctx;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
620 size_t root;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
621
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
622 ngx_http_perl_set_request(r, ctx);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
624 if (ctx->filename.data) {
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625 goto done;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627
774
589841f06b87 previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents: 741
diff changeset
628 if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
629 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
630 croak("ngx_http_map_uri_to_path() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
631 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
633 ctx->filename.len--;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
634 sv_setpv(PL_statname, (char *) ctx->filename.data);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 done:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
638 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
640 ST(0) = TARG;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
643 void
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 print(r, ...)
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645 CODE:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
647 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
648 ngx_http_perl_ctx_t *ctx;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
649 SV *sv;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
650 int i;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
651 u_char *p;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
652 size_t size;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
653 STRLEN len;
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
654 ngx_int_t rc;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
655 ngx_buf_t *b;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
656
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
657 ngx_http_perl_set_request(r, ctx);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
659 if (ctx->error) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
660 croak("print(): called after error");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
661 }
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
662
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
663 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
664 croak("print(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
665 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
666
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667 if (items == 2) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669 /*
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670 * do zero copy for prolate single read-only SV:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671 * $r->print("some text\n");
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672 */
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674 sv = ST(1);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677 sv = SvRV(sv);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
679
1703
43747661804d *) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
680 if (SvREADONLY(sv) && SvPOK(sv)) {
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
682 p = (u_char *) SvPV(sv, len);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
683
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
684 if (len == 0) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
685 XSRETURN_EMPTY;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
686 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
687
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
688 b = ngx_calloc_buf(r->pool);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
689 if (b == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
690 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
691 croak("ngx_calloc_buf() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
692 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694 b->memory = 1;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695 b->pos = p;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 b->last = p + len;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
697 b->start = p;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698 b->end = b->last;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
699
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
700 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
701 "$r->print: read-only SV: %z", len);
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
702
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 goto out;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
705 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
706
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 size = 0;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709 for (i = 1; i < items; i++) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
711 sv = ST(i);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
712
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
713 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
714 sv = SvRV(sv);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
716
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
717 (void) SvPV(sv, len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
719 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
720 "$r->print: copy SV: %z", len);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
722 size += len;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
723 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
724
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
725 if (size == 0) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
726 XSRETURN_EMPTY;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
727 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
728
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
729 b = ngx_create_temp_buf(r->pool, size);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
730 if (b == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
731 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
732 croak("ngx_create_temp_buf() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
733 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
734
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735 for (i = 1; i < items; i++) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
736 sv = ST(i);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
737
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
739 sv = SvRV(sv);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742 p = (u_char *) SvPV(sv, len);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 b->last = ngx_cpymem(b->last, p, len);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
746 out:
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
747
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
748 rc = ngx_http_perl_output(r, ctx, b);
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
749
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
750 if (rc == NGX_ERROR) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
751 ctx->error = 1;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
752 croak("ngx_http_perl_output() failed");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
753 }
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
754
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
755
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
756 void
613
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
757 sendfile(r, filename, offset = -1, bytes = 0)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
758 CODE:
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
759
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
760 ngx_http_request_t *r;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
761 ngx_http_perl_ctx_t *ctx;
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
762 char *filename;
2794
92bd6afe8d9c use off_t in $r->sendfile(), this allows to use 64-bit off_t on platforms
Igor Sysoev <igor@sysoev.ru>
parents: 2756
diff changeset
763 off_t offset;
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
764 size_t bytes;
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
765 ngx_int_t rc;
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
766 ngx_str_t path;
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
767 ngx_buf_t *b;
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
768 ngx_open_file_info_t of;
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
769 ngx_http_core_loc_conf_t *clcf;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
770
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
771 ngx_http_perl_set_request(r, ctx);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
772
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
773 if (ctx->error) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
774 croak("sendfile(): called after error");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
775 }
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
776
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
777 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
778 croak("sendfile(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
779 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
780
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
781 filename = SvPV_nolen(ST(1));
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783 if (filename == NULL) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
784 croak("sendfile(): NULL filename");
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
785 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
786
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
787 offset = items < 3 ? -1 : SvIV(ST(2));
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
788 bytes = items < 4 ? 0 : SvIV(ST(3));
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
789
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
790 b = ngx_calloc_buf(r->pool);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
791 if (b == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
792 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
793 croak("ngx_calloc_buf() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
794 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
795
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
797 if (b->file == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
798 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
799 croak("ngx_pcalloc() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
800 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
801
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
802 path.len = ngx_strlen(filename);
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
803
2061
b0a1c84725cf change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
804 path.data = ngx_pnalloc(r->pool, path.len + 1);
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
805 if (path.data == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
806 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
807 croak("ngx_pnalloc() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
808 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
809
3870
8cd7594916ec fix warnings
Igor Sysoev <igor@sysoev.ru>
parents: 3500
diff changeset
810 (void) ngx_cpystrn(path.data, (u_char *) filename, path.len + 1);
1560
25ee6eee7573 style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents: 1457
diff changeset
811
2063
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
812 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
813
2068
75a8d34459c5 ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents: 2063
diff changeset
814 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
75a8d34459c5 ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents: 2063
diff changeset
815
3178
975f0558aab3 read_ahead
Igor Sysoev <igor@sysoev.ru>
parents: 2794
diff changeset
816 of.read_ahead = clcf->read_ahead;
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 2068
diff changeset
817 of.directio = clcf->directio;
2063
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
818 of.valid = clcf->open_file_cache_valid;
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
819 of.min_uses = clcf->open_file_cache_min_uses;
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
820 of.errors = clcf->open_file_cache_errors;
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
821 of.events = clcf->open_file_cache_events;
4494
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
822
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
823 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
824 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
825 croak("ngx_http_set_disable_symlinks() failed");
4494
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
826 }
2063
67a29af877ed initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents: 2061
diff changeset
827
1799
0b5b94805d26 optimization
Igor Sysoev <igor@sysoev.ru>
parents: 1772
diff changeset
828 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
0b5b94805d26 optimization
Igor Sysoev <igor@sysoev.ru>
parents: 1772
diff changeset
829 != NGX_OK)
0b5b94805d26 optimization
Igor Sysoev <igor@sysoev.ru>
parents: 1772
diff changeset
830 {
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
831 if (of.err == 0) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
832 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
833 croak("ngx_open_cached_file() failed");
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
834 }
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
835
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
836 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
2756
09cab3f8d92e *) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents: 2231
diff changeset
837 "%s \"%s\" failed", of.failed, filename);
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
838
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
839 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
840 croak("ngx_open_cached_file() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
841 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842
613
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
843 if (offset == -1) {
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
844 offset = 0;
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
845 }
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
846
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
847 if (bytes == 0) {
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
848 bytes = of.size - offset;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
849 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
850
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
851 b->in_file = 1;
613
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
852
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
853 b->file_pos = offset;
c73c5c58c619 nginx-0.3.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 603
diff changeset
854 b->file_last = offset + bytes;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
855
1454
f497ed7682a7 open_file_cache in HTTP
Igor Sysoev <igor@sysoev.ru>
parents: 1444
diff changeset
856 b->file->fd = of.fd;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
857 b->file->log = r->connection->log;
2231
8564129d49b6 *) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents: 2136
diff changeset
858 b->file->directio = of.is_directio;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
859
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
860 rc = ngx_http_perl_output(r, ctx, b);
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
861
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
862 if (rc == NGX_ERROR) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
863 ctx->error = 1;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
864 croak("ngx_http_perl_output() failed");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
865 }
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
866
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
867
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
868 void
1178
a77f6980de50 rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents: 1075
diff changeset
869 flush(r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
870 CODE:
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
871
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
872 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
873 ngx_http_perl_ctx_t *ctx;
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
874 ngx_int_t rc;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
875 ngx_buf_t *b;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
876
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
877 ngx_http_perl_set_request(r, ctx);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
878
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
879 if (ctx->error) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
880 croak("flush(): called after error");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
881 }
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
882
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
883 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
884 croak("flush(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
885 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
886
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
887 b = ngx_calloc_buf(r->pool);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
888 if (b == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
889 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
890 croak("ngx_calloc_buf() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
891 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
892
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
893 b->flush = 1;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
894
1178
a77f6980de50 rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents: 1075
diff changeset
895 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush");
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
896
7525
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
897 rc = ngx_http_perl_output(r, ctx, b);
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
898
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
899 if (rc == NGX_ERROR) {
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
900 ctx->error = 1;
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
901 croak("ngx_http_perl_output() failed");
575480d3fd01 Perl: propagate errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7524
diff changeset
902 }
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
903
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
904 XSRETURN_EMPTY;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
905
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
906
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
907 void
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
908 internal_redirect(r, uri)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
909 CODE:
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
910
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
911 ngx_http_request_t *r;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
912 ngx_http_perl_ctx_t *ctx;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
913 SV *uri;
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
914 ngx_uint_t i;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
915
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
916 ngx_http_perl_set_request(r, ctx);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
917
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
918 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
919 croak("internal_redirect(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
920 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
921
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
922 uri = ST(1);
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
923
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
924 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
925 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
926 croak("ngx_http_perl_sv2str() failed");
599
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 for (i = 0; i < ctx->redirect_uri.len; i++) {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
930 if (ctx->redirect_uri.data[i] == '?') {
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
931
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932 ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1);
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
933 ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1];
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
934 ctx->redirect_uri.len = i;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
935
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
936 XSRETURN_EMPTY;
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
937 }
869b6444d234 nginx-0.3.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
938 }
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
939
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
940
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
941 void
811
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
942 allow_ranges(r)
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
943 CODE:
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
944
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
945 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
946 ngx_http_perl_ctx_t *ctx;
811
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
947
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
948 ngx_http_perl_set_request(r, ctx);
811
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
949
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
950 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
951 croak("allow_ranges(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
952 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
953
811
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
954 r->allow_ranges = 1;
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
955
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
956
35454083769f $r->allow_ranges
Igor Sysoev <igor@sysoev.ru>
parents: 774
diff changeset
957 void
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
958 unescape(r, text, type = 0)
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
959 CODE:
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
960
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
961 dXSTARG;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
962 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
963 ngx_http_perl_ctx_t *ctx;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
964 SV *text;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
965 int type;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
966 u_char *p, *dst, *src;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
967 STRLEN len;
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
968
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
969 ngx_http_perl_set_request(r, ctx);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
970
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
971 text = ST(1);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
972
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
973 src = (u_char *) SvPV(text, len);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
974
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1898
diff changeset
975 p = ngx_pnalloc(r->pool, len + 1);
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
976 if (p == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
977 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
978 croak("ngx_pnalloc() failed");
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
979 }
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
980
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
981 dst = p;
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
982
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
983 type = items < 3 ? 0 : SvIV(ST(2));
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
984
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
985 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type);
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
986 *dst = '\0';
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
987
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
988 ngx_http_perl_set_targ(p, dst - p);
601
77f77f53214a nginx-0.3.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 599
diff changeset
989
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 631
diff changeset
990 ST(0) = TARG;
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
991
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
992
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
993 void
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
994 variable(r, name, value = NULL)
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
995 CODE:
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
996
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
997 dXSTARG;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
998 ngx_http_request_t *r;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
999 ngx_http_perl_ctx_t *ctx;
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1000 SV *name, *value;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1001 u_char *p, *lowcase;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1002 STRLEN len;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1003 ngx_str_t var, val;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1004 ngx_uint_t i, hash;
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1005 ngx_http_perl_var_t *v;
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1006 ngx_http_variable_value_t *vv;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1007
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1008 ngx_http_perl_set_request(r, ctx);
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1009
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1010 name = ST(1);
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1011
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1012 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) {
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1013 name = SvRV(name);
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1014 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1015
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1016 if (items == 2) {
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1017 value = NULL;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1018
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1019 } else {
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1020 value = ST(2);
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1021
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1022 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) {
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1023 value = SvRV(value);
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1024 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1025
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1026 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1027 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1028 croak("ngx_http_perl_sv2str() failed");
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1029 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1030 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1031
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1032 p = (u_char *) SvPV(name, len);
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1033
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1898
diff changeset
1034 lowcase = ngx_pnalloc(r->pool, len);
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1035 if (lowcase == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1036 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1037 croak("ngx_pnalloc() failed");
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1038 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1039
2136
7a7c9e9024dd ngx_hash_strlow()
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
1040 hash = ngx_hash_strlow(lowcase, p, len);
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1041
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1042 var.len = len;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1043 var.data = lowcase;
5306
43900b822890 Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5248
diff changeset
1044 #if (NGX_DEBUG)
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1045
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1046 if (value) {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1047 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1048 "perl variable: \"%V\"=\"%V\"", &var, &val);
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1049 } else {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1050 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1051 "perl variable: \"%V\"", &var);
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1052 }
5306
43900b822890 Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5248
diff changeset
1053 #endif
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1054
3500
0eb46e3c5c02 change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents: 3447
diff changeset
1055 vv = ngx_http_get_variable(r, &var, hash);
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1056 if (vv == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1057 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1058 croak("ngx_http_get_variable() failed");
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1059 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1060
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1061 if (vv->not_found) {
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1062
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1063 if (ctx->variables) {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1064
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1065 v = ctx->variables->elts;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1066 for (i = 0; i < ctx->variables->nelts; i++) {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1067
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1068 if (hash != v[i].hash
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1069 || len != v[i].name.len
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1070 || ngx_strncmp(lowcase, v[i].name.data, len) != 0)
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1071 {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1072 continue;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1073 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1074
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1075 if (value) {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1076 v[i].value = val;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1077 XSRETURN_UNDEF;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1078 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1079
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
1080 ngx_http_perl_set_targ(v[i].value.data, v[i].value.len);
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1081
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1082 goto done;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1083 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1084 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1085
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1086 if (value) {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1087 if (ctx->variables == NULL) {
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1088 ctx->variables = ngx_array_create(r->pool, 1,
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1089 sizeof(ngx_http_perl_var_t));
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1090 if (ctx->variables == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1091 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1092 croak("ngx_array_create() failed");
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1093 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1094 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1095
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1096 v = ngx_array_push(ctx->variables);
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1097 if (v == NULL) {
7526
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1098 ctx->error = 1;
8125552a10ca Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7525
diff changeset
1099 croak("ngx_array_push() failed");
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1100 }
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1101
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1102 v->hash = hash;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1103 v->name.len = len;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1104 v->name.data = lowcase;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1105 v->value = val;
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1106
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1107 XSRETURN_UNDEF;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1108 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1109
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1110 XSRETURN_UNDEF;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1111 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1112
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1113 if (value) {
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1114 vv->len = val.len;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1115 vv->valid = 1;
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1560
diff changeset
1116 vv->no_cacheable = 0;
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1117 vv->not_found = 0;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1118 vv->data = val.data;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1119
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1120 XSRETURN_UNDEF;
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1121 }
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1122
1739
5b7baef2e11e copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents: 1703
diff changeset
1123 ngx_http_perl_set_targ(vv->data, vv->len);
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1124
912
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1125 done:
7fa926a7926d $r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents: 911
diff changeset
1126
833
dbc6819acfcc $r->variable
Igor Sysoev <igor@sysoev.ru>
parents: 811
diff changeset
1127 ST(0) = TARG;
907
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1128
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1129
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1130 void
911
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1131 sleep(r, sleep, next)
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1132 CODE:
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1133
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1134 ngx_http_request_t *r;
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1135 ngx_http_perl_ctx_t *ctx;
1897
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1136 ngx_msec_t sleep;
911
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1137
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1138 ngx_http_perl_set_request(r, ctx);
911
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1139
7528
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
1140 if (ctx->variable) {
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
1141 croak("sleep(): cannot be used in variable handler");
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
1142 }
0cb693b4cbbb Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7527
diff changeset
1143
7527
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
1144 if (ctx->next) {
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
1145 croak("sleep(): another handler active");
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
1146 }
02cd116ebe2a Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7526
diff changeset
1147
1898
9a73235ce453 fix previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 1897
diff changeset
1148 sleep = (ngx_msec_t) SvIV(ST(1));
1897
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1149
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1150 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1151 "perl sleep: %M", sleep);
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1152
911
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1153 ctx->next = SvRV(ST(2));
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1154
6960
1c5e5e5b008d Perl: fixed delaying subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6233
diff changeset
1155 r->connection->write->delayed = 1;
1897
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1156 ngx_add_timer(r->connection->write, sleep);
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1157
b43f244d0430 optimize $r->sleep
Igor Sysoev <igor@sysoev.ru>
parents: 1895
diff changeset
1158 r->write_event_handler = ngx_http_perl_sleep_handler;
3447
de70f912ad58 fix request counter for $r->sleep(), the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents: 3317
diff changeset
1159 r->main->count++;
911
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1160
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1161
73c66ed9a9cd $r->sleep()
Igor Sysoev <igor@sysoev.ru>
parents: 910
diff changeset
1162 void
907
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1163 log_error(r, err, msg)
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1164 CODE:
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1165
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1166 ngx_http_request_t *r;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1167 ngx_http_perl_ctx_t *ctx;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1168 SV *err, *msg;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1169 u_char *p;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1170 STRLEN len;
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1171 ngx_err_t e;
907
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1172
7524
deebe988cbd7 Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7516
diff changeset
1173 ngx_http_perl_set_request(r, ctx);
907
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1174
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1175 err = ST(1);
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1176
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1177 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) {
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1178 err = SvRV(err);
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1179 }
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1180
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1181 e = SvIV(err);
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1182
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1183 msg = ST(2);
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1184
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1185 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) {
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1186 msg = SvRV(msg);
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1187 }
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1188
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1189 p = (u_char *) SvPV(msg, len);
424636f52f44 $r->log_error()
Igor Sysoev <igor@sysoev.ru>
parents: 882
diff changeset
1190
910
918e19c51a65 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 909
diff changeset
1191 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p);