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