Mercurial > hg > nginx-quic
annotate src/http/modules/perl/nginx.xs @ 5565:b8e6297358b5 stable-1.4
SPDY: fixed possible segfault.
While processing a DATA frame, the link to related stream is stored in spdy
connection object as part of connection state. But this stream can be closed
between receiving parts of the frame.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 22 Jan 2014 04:58:19 +0400 |
parents | edc479bf33b1 |
children | 43900b822890 |
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 |
633 | 18 #define ngx_http_perl_set_request(r) \ |
19 r = INT2PTR(ngx_http_request_t *, SvIV((SV *) SvRV(ST(0)))) | |
20 | |
21 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
22 #define ngx_http_perl_set_targ(p, len) \ |
633 | 23 \ |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
24 SvUPGRADE(TARG, SVt_PV); \ |
633 | 25 SvPOK_on(TARG); \ |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
26 sv_setpvn(TARG, (char *) p, len) |
633 | 27 |
599 | 28 |
29 static ngx_int_t | |
30 ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv) | |
31 { | |
32 u_char *p; | |
33 STRLEN len; | |
34 | |
35 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
36 sv = SvRV(sv); | |
37 } | |
38 | |
39 p = (u_char *) SvPV(sv, len); | |
40 | |
41 s->len = len; | |
42 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
43 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 44 s->data = p; |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
45 |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
46 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
|
47 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s); |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
48 |
599 | 49 return NGX_OK; |
50 } | |
51 | |
2049 | 52 s->data = ngx_pnalloc(r->pool, len); |
599 | 53 if (s->data == NULL) { |
54 return NGX_ERROR; | |
55 } | |
56 | |
57 ngx_memcpy(s->data, p, len); | |
58 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
59 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
|
60 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s); |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
61 |
599 | 62 return NGX_OK; |
63 } | |
64 | |
65 | |
66 static ngx_int_t | |
67 ngx_http_perl_output(ngx_http_request_t *r, ngx_buf_t *b) | |
68 { | |
617 | 69 ngx_chain_t out; |
70 #if (NGX_HTTP_SSI) | |
71 ngx_chain_t *cl; | |
599 | 72 ngx_http_perl_ctx_t *ctx; |
73 | |
74 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
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 | |
633 | 101 void |
915 | 102 status(r, code) |
103 CODE: | |
104 | |
105 ngx_http_request_t *r; | |
106 | |
107 ngx_http_perl_set_request(r); | |
108 | |
109 r->headers_out.status = SvIV(ST(1)); | |
110 | |
111 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
112 "perl status: %d", r->headers_out.status); | |
113 | |
114 XSRETURN_UNDEF; | |
115 | |
116 | |
117 void | |
599 | 118 send_http_header(r, ...) |
633 | 119 CODE: |
599 | 120 |
633 | 121 ngx_http_request_t *r; |
122 SV *sv; | |
599 | 123 |
633 | 124 ngx_http_perl_set_request(r); |
599 | 125 |
126 if (r->headers_out.status == 0) { | |
127 r->headers_out.status = NGX_HTTP_OK; | |
128 } | |
129 | |
130 if (items != 1) { | |
131 sv = ST(1); | |
132 | |
133 if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv) | |
134 != NGX_OK) | |
135 { | |
633 | 136 XSRETURN_EMPTY; |
599 | 137 } |
138 | |
1444
37938e68910b
allow to append charset to the "Content-Type" header
Igor Sysoev <igor@sysoev.ru>
parents:
1372
diff
changeset
|
139 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
|
140 |
599 | 141 } else { |
673 | 142 if (ngx_http_set_content_type(r) != NGX_OK) { |
143 XSRETURN_EMPTY; | |
599 | 144 } |
145 } | |
146 | |
633 | 147 (void) ngx_http_send_header(r); |
599 | 148 |
149 | |
633 | 150 void |
151 header_only(r) | |
599 | 152 CODE: |
153 | |
633 | 154 dXSTARG; |
155 ngx_http_request_t *r; | |
156 | |
157 ngx_http_perl_set_request(r); | |
599 | 158 |
633 | 159 sv_upgrade(TARG, SVt_IV); |
160 sv_setiv(TARG, r->header_only); | |
599 | 161 |
633 | 162 ST(0) = TARG; |
599 | 163 |
164 | |
633 | 165 void |
166 uri(r) | |
167 CODE: | |
168 | |
169 dXSTARG; | |
170 ngx_http_request_t *r; | |
599 | 171 |
633 | 172 ngx_http_perl_set_request(r); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
173 ngx_http_perl_set_targ(r->uri.data, r->uri.len); |
633 | 174 |
175 ST(0) = TARG; | |
176 | |
177 | |
178 void | |
179 args(r) | |
599 | 180 CODE: |
181 | |
633 | 182 dXSTARG; |
183 ngx_http_request_t *r; | |
599 | 184 |
633 | 185 ngx_http_perl_set_request(r); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
186 ngx_http_perl_set_targ(r->args.data, r->args.len); |
599 | 187 |
633 | 188 ST(0) = TARG; |
599 | 189 |
190 | |
633 | 191 void |
629 | 192 request_method(r) |
633 | 193 CODE: |
194 | |
195 dXSTARG; | |
196 ngx_http_request_t *r; | |
629 | 197 |
633 | 198 ngx_http_perl_set_request(r); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
199 ngx_http_perl_set_targ(r->method_name.data, r->method_name.len); |
633 | 200 |
201 ST(0) = TARG; | |
202 | |
203 | |
204 void | |
205 remote_addr(r) | |
629 | 206 CODE: |
207 | |
633 | 208 dXSTARG; |
209 ngx_http_request_t *r; | |
629 | 210 |
633 | 211 ngx_http_perl_set_request(r); |
212 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
|
213 r->connection->addr_text.len); |
629 | 214 |
633 | 215 ST(0) = TARG; |
629 | 216 |
217 | |
633 | 218 void |
219 header_in(r, key) | |
629 | 220 CODE: |
221 | |
633 | 222 dXSTARG; |
667 | 223 ngx_http_request_t *r; |
224 SV *key; | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
225 u_char *p, *lowcase_key, *value, sep; |
667 | 226 STRLEN len; |
227 ssize_t size; | |
228 ngx_uint_t i, n, hash; | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
229 ngx_array_t *a; |
667 | 230 ngx_list_part_t *part; |
231 ngx_table_elt_t *h, **ph; | |
232 ngx_http_header_t *hh; | |
233 ngx_http_core_main_conf_t *cmcf; | |
629 | 234 |
633 | 235 ngx_http_perl_set_request(r); |
599 | 236 |
633 | 237 key = ST(1); |
599 | 238 |
239 if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) { | |
240 key = SvRV(key); | |
241 } | |
242 | |
243 p = (u_char *) SvPV(key, len); | |
244 | |
667 | 245 /* look up hashed headers */ |
246 | |
2049 | 247 lowcase_key = ngx_pnalloc(r->pool, len); |
667 | 248 if (lowcase_key == NULL) { |
249 XSRETURN_UNDEF; | |
250 } | |
251 | |
2136 | 252 hash = ngx_hash_strlow(lowcase_key, p, len); |
667 | 253 |
254 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
255 | |
256 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); | |
257 | |
258 if (hh) { | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
259 |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
260 if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) { |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
261 sep = ';'; |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
262 goto multi; |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
263 } |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
264 |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
265 #if (NGX_HTTP_X_FORWARDED_FOR) |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
266 if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) { |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
267 sep = ','; |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
268 goto multi; |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
269 } |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
270 #endif |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
271 |
667 | 272 if (hh->offset) { |
273 | |
274 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); | |
275 | |
276 if (*ph) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
277 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 278 |
279 goto done; | |
280 } | |
281 | |
282 XSRETURN_UNDEF; | |
283 } | |
284 | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
285 multi: |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
286 |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
287 /* Cookie, X-Forwarded-For */ |
667 | 288 |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
289 a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset); |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
290 |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
291 n = a->nelts; |
667 | 292 |
293 if (n == 0) { | |
294 XSRETURN_UNDEF; | |
295 } | |
296 | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
297 ph = a->elts; |
667 | 298 |
299 if (n == 1) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
300 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 301 |
302 goto done; | |
303 } | |
304 | |
305 size = - (ssize_t) (sizeof("; ") - 1); | |
306 | |
307 for (i = 0; i < n; i++) { | |
308 size += ph[i]->value.len + sizeof("; ") - 1; | |
309 } | |
310 | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
311 value = ngx_pnalloc(r->pool, size); |
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
312 if (value == NULL) { |
667 | 313 XSRETURN_UNDEF; |
314 } | |
315 | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
316 p = value; |
667 | 317 |
318 for (i = 0; /* void */ ; i++) { | |
319 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len); | |
320 | |
321 if (i == n - 1) { | |
322 break; | |
323 } | |
324 | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
325 *p++ = sep; *p++ = ' '; |
667 | 326 } |
327 | |
5277
edc479bf33b1
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5269
diff
changeset
|
328 ngx_http_perl_set_targ(value, size); |
667 | 329 |
330 goto done; | |
331 } | |
332 | |
333 /* iterate over all headers */ | |
334 | |
599 | 335 part = &r->headers_in.headers.part; |
667 | 336 h = part->elts; |
599 | 337 |
338 for (i = 0; /* void */ ; i++) { | |
339 | |
340 if (i >= part->nelts) { | |
341 if (part->next == NULL) { | |
342 break; | |
343 } | |
344 | |
345 part = part->next; | |
667 | 346 h = part->elts; |
599 | 347 i = 0; |
348 } | |
349 | |
667 | 350 if (len != h[i].key.len |
351 || ngx_strcasecmp(p, h[i].key.data) != 0) | |
599 | 352 { |
353 continue; | |
354 } | |
355 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
356 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len); |
599 | 357 |
358 goto done; | |
359 } | |
360 | |
361 XSRETURN_UNDEF; | |
362 | |
363 done: | |
364 | |
633 | 365 ST(0) = TARG; |
599 | 366 |
367 | |
633 | 368 void |
681 | 369 has_request_body(r, next) |
370 CODE: | |
371 | |
372 dXSTARG; | |
373 ngx_http_request_t *r; | |
374 ngx_http_perl_ctx_t *ctx; | |
375 | |
376 ngx_http_perl_set_request(r); | |
377 | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
378 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
681 | 379 XSRETURN_UNDEF; |
380 } | |
381 | |
382 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
909 | 383 ctx->next = SvRV(ST(1)); |
681 | 384 |
385 r->request_body_in_single_buf = 1; | |
386 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
|
387 r->request_body_in_clean_file = 1; |
681 | 388 |
389 if (r->request_body_in_file_only) { | |
390 r->request_body_file_log_level = 0; | |
391 } | |
392 | |
393 ngx_http_read_client_request_body(r, ngx_http_perl_handle_request); | |
394 | |
395 sv_upgrade(TARG, SVt_IV); | |
396 sv_setiv(TARG, 1); | |
397 | |
398 ST(0) = TARG; | |
399 | |
400 | |
401 void | |
631 | 402 request_body(r) |
403 CODE: | |
404 | |
633 | 405 dXSTARG; |
406 ngx_http_request_t *r; | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
407 u_char *p, *data; |
633 | 408 size_t len; |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
409 ngx_buf_t *buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
410 ngx_chain_t *cl; |
633 | 411 |
412 ngx_http_perl_set_request(r); | |
631 | 413 |
941 | 414 if (r->request_body == NULL |
415 || r->request_body->temp_file | |
416 || r->request_body->bufs == NULL) | |
417 { | |
633 | 418 XSRETURN_UNDEF; |
419 } | |
631 | 420 |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
421 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
422 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
423 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
424 if (cl->next == NULL) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
425 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
426 data = buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
427 goto done; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
428 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
429 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
430 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
431 cl = cl->next; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
432 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
433 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
434 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
435 len += buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
436 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
437 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
438 p = ngx_pnalloc(r->pool, len); |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
439 if (p == NULL) { |
5269
51f6ddbf6d09
Perl: extra "return" removed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5181
diff
changeset
|
440 XSRETURN_UNDEF; |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
441 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
442 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
443 data = p; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
444 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
445 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
446 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
447 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
448 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
|
449 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
450 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
451 done: |
631 | 452 |
453 if (len == 0) { | |
454 XSRETURN_UNDEF; | |
455 } | |
456 | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
457 ngx_http_perl_set_targ(data, len); |
631 | 458 |
633 | 459 ST(0) = TARG; |
631 | 460 |
461 | |
633 | 462 void |
463 request_body_file(r) | |
464 CODE: | |
465 | |
466 dXSTARG; | |
467 ngx_http_request_t *r; | |
468 | |
469 ngx_http_perl_set_request(r); | |
470 | |
941 | 471 if (r->request_body == NULL || r->request_body->temp_file == NULL) { |
633 | 472 XSRETURN_UNDEF; |
473 } | |
474 | |
475 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
|
476 r->request_body->temp_file->file.name.len); |
599 | 477 |
633 | 478 ST(0) = TARG; |
479 | |
480 | |
481 void | |
1371 | 482 discard_request_body(r) |
483 CODE: | |
484 | |
485 ngx_http_request_t *r; | |
486 | |
487 ngx_http_perl_set_request(r); | |
488 | |
489 ngx_http_discard_request_body(r); | |
490 | |
491 | |
492 void | |
633 | 493 header_out(r, key, value) |
494 CODE: | |
599 | 495 |
633 | 496 ngx_http_request_t *r; |
497 SV *key; | |
498 SV *value; | |
499 ngx_table_elt_t *header; | |
599 | 500 |
633 | 501 ngx_http_perl_set_request(r); |
502 | |
503 key = ST(1); | |
504 value = ST(2); | |
599 | 505 |
506 header = ngx_list_push(&r->headers_out.headers); | |
507 if (header == NULL) { | |
633 | 508 XSRETURN_EMPTY; |
599 | 509 } |
510 | |
511 header->hash = 1; | |
512 | |
513 if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) { | |
633 | 514 XSRETURN_EMPTY; |
599 | 515 } |
516 | |
517 if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) { | |
633 | 518 XSRETURN_EMPTY; |
599 | 519 } |
520 | |
521 if (header->key.len == sizeof("Content-Length") - 1 | |
3870 | 522 && 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
|
523 sizeof("Content-Length") - 1) == 0) |
599 | 524 { |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
525 r->headers_out.content_length_n = (off_t) SvIV(value); |
599 | 526 r->headers_out.content_length = header; |
527 } | |
528 | |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
529 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
|
530 && 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
|
531 sizeof("Content-Encoding") - 1) == 0) |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
532 { |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
533 r->headers_out.content_encoding = header; |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
534 } |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
535 |
599 | 536 |
633 | 537 void |
599 | 538 filename(r) |
633 | 539 CODE: |
599 | 540 |
633 | 541 dXSTARG; |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
542 size_t root; |
633 | 543 ngx_http_request_t *r; |
599 | 544 ngx_http_perl_ctx_t *ctx; |
545 | |
633 | 546 ngx_http_perl_set_request(r); |
599 | 547 |
548 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
633 | 549 if (ctx->filename.data) { |
599 | 550 goto done; |
551 } | |
552 | |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
553 if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) { |
599 | 554 XSRETURN_UNDEF; |
555 } | |
556 | |
633 | 557 ctx->filename.len--; |
558 sv_setpv(PL_statname, (char *) ctx->filename.data); | |
599 | 559 |
560 done: | |
561 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
562 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len); |
599 | 563 |
633 | 564 ST(0) = TARG; |
599 | 565 |
566 | |
633 | 567 void |
599 | 568 print(r, ...) |
569 CODE: | |
570 | |
633 | 571 ngx_http_request_t *r; |
572 SV *sv; | |
573 int i; | |
574 u_char *p; | |
575 size_t size; | |
576 STRLEN len; | |
577 ngx_buf_t *b; | |
578 | |
579 ngx_http_perl_set_request(r); | |
599 | 580 |
581 if (items == 2) { | |
582 | |
583 /* | |
584 * do zero copy for prolate single read-only SV: | |
585 * $r->print("some text\n"); | |
586 */ | |
587 | |
588 sv = ST(1); | |
589 | |
590 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
591 sv = SvRV(sv); | |
592 } | |
593 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
594 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 595 |
596 p = (u_char *) SvPV(sv, len); | |
597 | |
598 if (len == 0) { | |
633 | 599 XSRETURN_EMPTY; |
599 | 600 } |
601 | |
602 b = ngx_calloc_buf(r->pool); | |
603 if (b == NULL) { | |
633 | 604 XSRETURN_EMPTY; |
599 | 605 } |
606 | |
607 b->memory = 1; | |
608 b->pos = p; | |
609 b->last = p + len; | |
610 b->start = p; | |
611 b->end = b->last; | |
612 | |
601 | 613 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
614 "$r->print: read-only SV: %z", len); | |
615 | |
599 | 616 goto out; |
617 } | |
618 } | |
619 | |
620 size = 0; | |
621 | |
622 for (i = 1; i < items; i++) { | |
623 | |
624 sv = ST(i); | |
625 | |
626 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
627 sv = SvRV(sv); | |
628 } | |
629 | |
601 | 630 (void) SvPV(sv, len); |
599 | 631 |
601 | 632 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
633 "$r->print: copy SV: %z", len); | |
599 | 634 |
635 size += len; | |
636 } | |
637 | |
638 if (size == 0) { | |
633 | 639 XSRETURN_EMPTY; |
599 | 640 } |
641 | |
642 b = ngx_create_temp_buf(r->pool, size); | |
643 if (b == NULL) { | |
633 | 644 XSRETURN_EMPTY; |
599 | 645 } |
646 | |
647 for (i = 1; i < items; i++) { | |
648 sv = ST(i); | |
649 | |
650 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
651 sv = SvRV(sv); | |
652 } | |
653 | |
654 p = (u_char *) SvPV(sv, len); | |
655 b->last = ngx_cpymem(b->last, p, len); | |
656 } | |
657 | |
658 out: | |
659 | |
633 | 660 (void) ngx_http_perl_output(r, b); |
599 | 661 |
662 | |
633 | 663 void |
613 | 664 sendfile(r, filename, offset = -1, bytes = 0) |
633 | 665 CODE: |
666 | |
1454 | 667 ngx_http_request_t *r; |
668 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
|
669 off_t offset; |
1454 | 670 size_t bytes; |
671 ngx_str_t path; | |
672 ngx_buf_t *b; | |
673 ngx_open_file_info_t of; | |
674 ngx_http_core_loc_conf_t *clcf; | |
599 | 675 |
633 | 676 ngx_http_perl_set_request(r); |
677 | |
678 filename = SvPV_nolen(ST(1)); | |
599 | 679 |
680 if (filename == NULL) { | |
681 croak("sendfile(): NULL filename"); | |
682 } | |
683 | |
633 | 684 offset = items < 3 ? -1 : SvIV(ST(2)); |
685 bytes = items < 4 ? 0 : SvIV(ST(3)); | |
686 | |
599 | 687 b = ngx_calloc_buf(r->pool); |
688 if (b == NULL) { | |
633 | 689 XSRETURN_EMPTY; |
599 | 690 } |
691 | |
692 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | |
693 if (b->file == NULL) { | |
633 | 694 XSRETURN_EMPTY; |
599 | 695 } |
696 | |
1454 | 697 path.len = ngx_strlen(filename); |
698 | |
2061
b0a1c84725cf
change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
699 path.data = ngx_pnalloc(r->pool, path.len + 1); |
1454 | 700 if (path.data == NULL) { |
633 | 701 XSRETURN_EMPTY; |
599 | 702 } |
703 | |
3870 | 704 (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
|
705 |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
706 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
|
707 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
708 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
|
709 |
3178 | 710 of.read_ahead = clcf->read_ahead; |
2129 | 711 of.directio = clcf->directio; |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
712 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
|
713 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
|
714 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
|
715 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
|
716 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
717 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
718 XSRETURN_EMPTY; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
719 } |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
720 |
1799 | 721 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
722 != NGX_OK) | |
723 { | |
1454 | 724 if (of.err == 0) { |
725 XSRETURN_EMPTY; | |
726 } | |
727 | |
599 | 728 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
|
729 "%s \"%s\" failed", of.failed, filename); |
633 | 730 XSRETURN_EMPTY; |
599 | 731 } |
732 | |
613 | 733 if (offset == -1) { |
734 offset = 0; | |
735 } | |
736 | |
737 if (bytes == 0) { | |
1454 | 738 bytes = of.size - offset; |
599 | 739 } |
740 | |
741 b->in_file = 1; | |
613 | 742 |
743 b->file_pos = offset; | |
744 b->file_last = offset + bytes; | |
599 | 745 |
1454 | 746 b->file->fd = of.fd; |
599 | 747 b->file->log = r->connection->log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
748 b->file->directio = of.is_directio; |
599 | 749 |
633 | 750 (void) ngx_http_perl_output(r, b); |
599 | 751 |
752 | |
633 | 753 void |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
754 flush(r) |
633 | 755 CODE: |
599 | 756 |
633 | 757 ngx_http_request_t *r; |
758 ngx_buf_t *b; | |
599 | 759 |
633 | 760 ngx_http_perl_set_request(r); |
599 | 761 |
762 b = ngx_calloc_buf(r->pool); | |
763 if (b == NULL) { | |
633 | 764 XSRETURN_EMPTY; |
599 | 765 } |
766 | |
767 b->flush = 1; | |
768 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
769 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush"); |
601 | 770 |
633 | 771 (void) ngx_http_perl_output(r, b); |
599 | 772 |
633 | 773 XSRETURN_EMPTY; |
599 | 774 |
775 | |
776 void | |
777 internal_redirect(r, uri) | |
633 | 778 CODE: |
599 | 779 |
633 | 780 ngx_http_request_t *r; |
781 SV *uri; | |
599 | 782 ngx_uint_t i; |
783 ngx_http_perl_ctx_t *ctx; | |
784 | |
633 | 785 ngx_http_perl_set_request(r); |
786 | |
787 uri = ST(1); | |
599 | 788 |
789 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
790 | |
791 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) { | |
792 XSRETURN_EMPTY; | |
793 } | |
794 | |
795 for (i = 0; i < ctx->redirect_uri.len; i++) { | |
796 if (ctx->redirect_uri.data[i] == '?') { | |
797 | |
798 ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1); | |
799 ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1]; | |
800 ctx->redirect_uri.len = i; | |
801 | |
802 XSRETURN_EMPTY; | |
803 } | |
804 } | |
601 | 805 |
806 | |
633 | 807 void |
811 | 808 allow_ranges(r) |
809 CODE: | |
810 | |
811 ngx_http_request_t *r; | |
812 | |
813 ngx_http_perl_set_request(r); | |
814 | |
815 r->allow_ranges = 1; | |
816 | |
817 | |
818 void | |
601 | 819 unescape(r, text, type = 0) |
820 CODE: | |
821 | |
633 | 822 dXSTARG; |
823 ngx_http_request_t *r; | |
824 SV *text; | |
825 int type; | |
826 u_char *p, *dst, *src; | |
827 STRLEN len; | |
601 | 828 |
633 | 829 ngx_http_perl_set_request(r); |
830 | |
831 text = ST(1); | |
832 | |
833 src = (u_char *) SvPV(text, len); | |
834 | |
2049 | 835 p = ngx_pnalloc(r->pool, len + 1); |
601 | 836 if (p == NULL) { |
837 XSRETURN_UNDEF; | |
838 } | |
839 | |
840 dst = p; | |
841 | |
633 | 842 type = items < 3 ? 0 : SvIV(ST(2)); |
843 | |
844 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); | |
601 | 845 *dst = '\0'; |
846 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
847 ngx_http_perl_set_targ(p, dst - p); |
601 | 848 |
633 | 849 ST(0) = TARG; |
833 | 850 |
851 | |
852 void | |
853 variable(r, name, value = NULL) | |
854 CODE: | |
855 | |
856 dXSTARG; | |
857 ngx_http_request_t *r; | |
858 SV *name, *value; | |
859 u_char *p, *lowcase; | |
860 STRLEN len; | |
861 ngx_str_t var, val; | |
862 ngx_uint_t i, hash; | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
863 ngx_http_perl_var_t *v; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
864 ngx_http_perl_ctx_t *ctx; |
833 | 865 ngx_http_variable_value_t *vv; |
866 | |
867 ngx_http_perl_set_request(r); | |
868 | |
869 name = ST(1); | |
870 | |
871 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
872 name = SvRV(name); | |
873 } | |
874 | |
875 if (items == 2) { | |
876 value = NULL; | |
877 | |
878 } else { | |
879 value = ST(2); | |
880 | |
881 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
882 value = SvRV(value); | |
883 } | |
884 | |
885 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) { | |
886 XSRETURN_UNDEF; | |
887 } | |
888 } | |
889 | |
890 p = (u_char *) SvPV(name, len); | |
891 | |
2049 | 892 lowcase = ngx_pnalloc(r->pool, len); |
833 | 893 if (lowcase == NULL) { |
894 XSRETURN_UNDEF; | |
895 } | |
896 | |
2136 | 897 hash = ngx_hash_strlow(lowcase, p, len); |
833 | 898 |
899 var.len = len; | |
900 var.data = lowcase; | |
901 | |
4188 | 902 #if (NGX_DEBUG) |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
903 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
904 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
905 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
|
906 "perl variable: \"%V\"=\"%V\"", &var, &val); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
907 } else { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
908 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
|
909 "perl variable: \"%V\"", &var); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
910 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
911 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
912 #endif |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
913 |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3447
diff
changeset
|
914 vv = ngx_http_get_variable(r, &var, hash); |
833 | 915 if (vv == NULL) { |
916 XSRETURN_UNDEF; | |
917 } | |
918 | |
919 if (vv->not_found) { | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
920 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
921 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
922 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
923 if (ctx->variables) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
924 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
925 v = ctx->variables->elts; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
926 for (i = 0; i < ctx->variables->nelts; i++) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
927 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
928 if (hash != v[i].hash |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
929 || len != v[i].name.len |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
930 || 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
|
931 { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
932 continue; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
933 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
934 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
935 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
936 v[i].value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
937 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
938 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
939 |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
940 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
|
941 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
942 goto done; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
943 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
944 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
945 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
946 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
947 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
948 ctx->variables = ngx_array_create(r->pool, 1, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
949 sizeof(ngx_http_perl_var_t)); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
950 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
951 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
952 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
953 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
954 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
955 v = ngx_array_push(ctx->variables); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
956 if (v == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
957 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
958 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
959 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
960 v->hash = hash; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
961 v->name.len = len; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
962 v->name.data = lowcase; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
963 v->value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
964 |
833 | 965 XSRETURN_UNDEF; |
966 } | |
967 | |
968 XSRETURN_UNDEF; | |
969 } | |
970 | |
971 if (value) { | |
972 vv->len = val.len; | |
973 vv->valid = 1; | |
1565 | 974 vv->no_cacheable = 0; |
833 | 975 vv->not_found = 0; |
976 vv->data = val.data; | |
977 | |
978 XSRETURN_UNDEF; | |
979 } | |
980 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
981 ngx_http_perl_set_targ(vv->data, vv->len); |
833 | 982 |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
983 done: |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
984 |
833 | 985 ST(0) = TARG; |
907 | 986 |
987 | |
988 void | |
911 | 989 sleep(r, sleep, next) |
990 CODE: | |
991 | |
992 ngx_http_request_t *r; | |
1897 | 993 ngx_msec_t sleep; |
911 | 994 ngx_http_perl_ctx_t *ctx; |
995 | |
996 ngx_http_perl_set_request(r); | |
997 | |
1898 | 998 sleep = (ngx_msec_t) SvIV(ST(1)); |
1897 | 999 |
1000 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1001 "perl sleep: %M", sleep); | |
1002 | |
911 | 1003 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); |
1004 | |
1005 ctx->next = SvRV(ST(2)); | |
1006 | |
1897 | 1007 ngx_add_timer(r->connection->write, sleep); |
1008 | |
1009 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
|
1010 r->main->count++; |
911 | 1011 |
1012 | |
1013 void | |
907 | 1014 log_error(r, err, msg) |
1015 CODE: | |
1016 | |
1017 ngx_http_request_t *r; | |
1018 SV *err, *msg; | |
1019 u_char *p; | |
1020 STRLEN len; | |
1021 ngx_err_t e; | |
1022 | |
1023 ngx_http_perl_set_request(r); | |
1024 | |
1025 err = ST(1); | |
1026 | |
1027 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) { | |
1028 err = SvRV(err); | |
1029 } | |
1030 | |
1031 e = SvIV(err); | |
1032 | |
1033 msg = ST(2); | |
1034 | |
1035 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) { | |
1036 msg = SvRV(msg); | |
1037 } | |
1038 | |
1039 p = (u_char *) SvPV(msg, len); | |
1040 | |
910 | 1041 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p); |