Mercurial > hg > nginx
annotate src/http/modules/perl/nginx.xs @ 5204:a64c8a5da336
PCRE: retain input pattern for all regular expressions.
Previously, input pattern was kept only for regular expressions
with named captures, which resulted in error log entries without
input pattern for PCRE errors that occured while processing
regular expressions without them.
Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
author | Piotr Sikora <piotr@cloudflare.com> |
---|---|
date | Thu, 02 May 2013 03:26:36 -0700 |
parents | e530b88b088b |
children | f5626ab8cb87 |
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; | |
225 u_char *p, *lowcase_key, *cookie; | |
226 STRLEN len; | |
227 ssize_t size; | |
228 ngx_uint_t i, n, hash; | |
229 ngx_list_part_t *part; | |
230 ngx_table_elt_t *h, **ph; | |
231 ngx_http_header_t *hh; | |
232 ngx_http_core_main_conf_t *cmcf; | |
629 | 233 |
633 | 234 ngx_http_perl_set_request(r); |
599 | 235 |
633 | 236 key = ST(1); |
599 | 237 |
238 if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) { | |
239 key = SvRV(key); | |
240 } | |
241 | |
242 p = (u_char *) SvPV(key, len); | |
243 | |
667 | 244 /* look up hashed headers */ |
245 | |
2049 | 246 lowcase_key = ngx_pnalloc(r->pool, len); |
667 | 247 if (lowcase_key == NULL) { |
248 XSRETURN_UNDEF; | |
249 } | |
250 | |
2136 | 251 hash = ngx_hash_strlow(lowcase_key, p, len); |
667 | 252 |
253 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
254 | |
255 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); | |
256 | |
257 if (hh) { | |
258 if (hh->offset) { | |
259 | |
260 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); | |
261 | |
262 if (*ph) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
263 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 264 |
265 goto done; | |
266 } | |
267 | |
268 XSRETURN_UNDEF; | |
269 } | |
270 | |
271 /* Cookie */ | |
272 | |
273 n = r->headers_in.cookies.nelts; | |
274 | |
275 if (n == 0) { | |
276 XSRETURN_UNDEF; | |
277 } | |
278 | |
279 ph = r->headers_in.cookies.elts; | |
280 | |
281 if (n == 1) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
282 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 283 |
284 goto done; | |
285 } | |
286 | |
287 size = - (ssize_t) (sizeof("; ") - 1); | |
288 | |
289 for (i = 0; i < n; i++) { | |
290 size += ph[i]->value.len + sizeof("; ") - 1; | |
291 } | |
292 | |
2049 | 293 cookie = ngx_pnalloc(r->pool, size); |
667 | 294 if (cookie == NULL) { |
295 XSRETURN_UNDEF; | |
296 } | |
297 | |
298 p = cookie; | |
299 | |
300 for (i = 0; /* void */ ; i++) { | |
301 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len); | |
302 | |
303 if (i == n - 1) { | |
304 break; | |
305 } | |
306 | |
307 *p++ = ';'; *p++ = ' '; | |
308 } | |
309 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
310 ngx_http_perl_set_targ(cookie, size); |
667 | 311 |
312 goto done; | |
313 } | |
314 | |
315 /* iterate over all headers */ | |
316 | |
599 | 317 part = &r->headers_in.headers.part; |
667 | 318 h = part->elts; |
599 | 319 |
320 for (i = 0; /* void */ ; i++) { | |
321 | |
322 if (i >= part->nelts) { | |
323 if (part->next == NULL) { | |
324 break; | |
325 } | |
326 | |
327 part = part->next; | |
667 | 328 h = part->elts; |
599 | 329 i = 0; |
330 } | |
331 | |
667 | 332 if (len != h[i].key.len |
333 || ngx_strcasecmp(p, h[i].key.data) != 0) | |
599 | 334 { |
335 continue; | |
336 } | |
337 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
338 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len); |
599 | 339 |
340 goto done; | |
341 } | |
342 | |
343 XSRETURN_UNDEF; | |
344 | |
345 done: | |
346 | |
633 | 347 ST(0) = TARG; |
599 | 348 |
349 | |
633 | 350 void |
681 | 351 has_request_body(r, next) |
352 CODE: | |
353 | |
354 dXSTARG; | |
355 ngx_http_request_t *r; | |
356 ngx_http_perl_ctx_t *ctx; | |
357 | |
358 ngx_http_perl_set_request(r); | |
359 | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
360 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
681 | 361 XSRETURN_UNDEF; |
362 } | |
363 | |
364 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
909 | 365 ctx->next = SvRV(ST(1)); |
681 | 366 |
367 r->request_body_in_single_buf = 1; | |
368 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
|
369 r->request_body_in_clean_file = 1; |
681 | 370 |
371 if (r->request_body_in_file_only) { | |
372 r->request_body_file_log_level = 0; | |
373 } | |
374 | |
375 ngx_http_read_client_request_body(r, ngx_http_perl_handle_request); | |
376 | |
377 sv_upgrade(TARG, SVt_IV); | |
378 sv_setiv(TARG, 1); | |
379 | |
380 ST(0) = TARG; | |
381 | |
382 | |
383 void | |
631 | 384 request_body(r) |
385 CODE: | |
386 | |
633 | 387 dXSTARG; |
388 ngx_http_request_t *r; | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
389 u_char *p, *data; |
633 | 390 size_t len; |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
391 ngx_buf_t *buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
392 ngx_chain_t *cl; |
633 | 393 |
394 ngx_http_perl_set_request(r); | |
631 | 395 |
941 | 396 if (r->request_body == NULL |
397 || r->request_body->temp_file | |
398 || r->request_body->bufs == NULL) | |
399 { | |
633 | 400 XSRETURN_UNDEF; |
401 } | |
631 | 402 |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
403 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
404 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
405 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
406 if (cl->next == NULL) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
407 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
408 data = buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
409 goto done; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
410 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
411 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
412 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
413 cl = cl->next; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
414 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
415 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
416 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
417 len += buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
418 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
419 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
420 p = ngx_pnalloc(r->pool, len); |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
421 if (p == NULL) { |
5198
e530b88b088b
Perl: extra "return" removed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5181
diff
changeset
|
422 XSRETURN_UNDEF; |
5181
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 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
425 data = p; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
426 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
427 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
428 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
429 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
430 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
|
431 } |
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 done: |
631 | 434 |
435 if (len == 0) { | |
436 XSRETURN_UNDEF; | |
437 } | |
438 | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
439 ngx_http_perl_set_targ(data, len); |
631 | 440 |
633 | 441 ST(0) = TARG; |
631 | 442 |
443 | |
633 | 444 void |
445 request_body_file(r) | |
446 CODE: | |
447 | |
448 dXSTARG; | |
449 ngx_http_request_t *r; | |
450 | |
451 ngx_http_perl_set_request(r); | |
452 | |
941 | 453 if (r->request_body == NULL || r->request_body->temp_file == NULL) { |
633 | 454 XSRETURN_UNDEF; |
455 } | |
456 | |
457 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
|
458 r->request_body->temp_file->file.name.len); |
599 | 459 |
633 | 460 ST(0) = TARG; |
461 | |
462 | |
463 void | |
1371 | 464 discard_request_body(r) |
465 CODE: | |
466 | |
467 ngx_http_request_t *r; | |
468 | |
469 ngx_http_perl_set_request(r); | |
470 | |
471 ngx_http_discard_request_body(r); | |
472 | |
473 | |
474 void | |
633 | 475 header_out(r, key, value) |
476 CODE: | |
599 | 477 |
633 | 478 ngx_http_request_t *r; |
479 SV *key; | |
480 SV *value; | |
481 ngx_table_elt_t *header; | |
599 | 482 |
633 | 483 ngx_http_perl_set_request(r); |
484 | |
485 key = ST(1); | |
486 value = ST(2); | |
599 | 487 |
488 header = ngx_list_push(&r->headers_out.headers); | |
489 if (header == NULL) { | |
633 | 490 XSRETURN_EMPTY; |
599 | 491 } |
492 | |
493 header->hash = 1; | |
494 | |
495 if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) { | |
633 | 496 XSRETURN_EMPTY; |
599 | 497 } |
498 | |
499 if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) { | |
633 | 500 XSRETURN_EMPTY; |
599 | 501 } |
502 | |
503 if (header->key.len == sizeof("Content-Length") - 1 | |
3870 | 504 && 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
|
505 sizeof("Content-Length") - 1) == 0) |
599 | 506 { |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
507 r->headers_out.content_length_n = (off_t) SvIV(value); |
599 | 508 r->headers_out.content_length = header; |
509 } | |
510 | |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
511 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
|
512 && 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
|
513 sizeof("Content-Encoding") - 1) == 0) |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
514 { |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
515 r->headers_out.content_encoding = header; |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
516 } |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
517 |
599 | 518 |
633 | 519 void |
599 | 520 filename(r) |
633 | 521 CODE: |
599 | 522 |
633 | 523 dXSTARG; |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
524 size_t root; |
633 | 525 ngx_http_request_t *r; |
599 | 526 ngx_http_perl_ctx_t *ctx; |
527 | |
633 | 528 ngx_http_perl_set_request(r); |
599 | 529 |
530 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
633 | 531 if (ctx->filename.data) { |
599 | 532 goto done; |
533 } | |
534 | |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
535 if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) { |
599 | 536 XSRETURN_UNDEF; |
537 } | |
538 | |
633 | 539 ctx->filename.len--; |
540 sv_setpv(PL_statname, (char *) ctx->filename.data); | |
599 | 541 |
542 done: | |
543 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
544 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len); |
599 | 545 |
633 | 546 ST(0) = TARG; |
599 | 547 |
548 | |
633 | 549 void |
599 | 550 print(r, ...) |
551 CODE: | |
552 | |
633 | 553 ngx_http_request_t *r; |
554 SV *sv; | |
555 int i; | |
556 u_char *p; | |
557 size_t size; | |
558 STRLEN len; | |
559 ngx_buf_t *b; | |
560 | |
561 ngx_http_perl_set_request(r); | |
599 | 562 |
563 if (items == 2) { | |
564 | |
565 /* | |
566 * do zero copy for prolate single read-only SV: | |
567 * $r->print("some text\n"); | |
568 */ | |
569 | |
570 sv = ST(1); | |
571 | |
572 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
573 sv = SvRV(sv); | |
574 } | |
575 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
576 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 577 |
578 p = (u_char *) SvPV(sv, len); | |
579 | |
580 if (len == 0) { | |
633 | 581 XSRETURN_EMPTY; |
599 | 582 } |
583 | |
584 b = ngx_calloc_buf(r->pool); | |
585 if (b == NULL) { | |
633 | 586 XSRETURN_EMPTY; |
599 | 587 } |
588 | |
589 b->memory = 1; | |
590 b->pos = p; | |
591 b->last = p + len; | |
592 b->start = p; | |
593 b->end = b->last; | |
594 | |
601 | 595 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
596 "$r->print: read-only SV: %z", len); | |
597 | |
599 | 598 goto out; |
599 } | |
600 } | |
601 | |
602 size = 0; | |
603 | |
604 for (i = 1; i < items; i++) { | |
605 | |
606 sv = ST(i); | |
607 | |
608 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
609 sv = SvRV(sv); | |
610 } | |
611 | |
601 | 612 (void) SvPV(sv, len); |
599 | 613 |
601 | 614 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
615 "$r->print: copy SV: %z", len); | |
599 | 616 |
617 size += len; | |
618 } | |
619 | |
620 if (size == 0) { | |
633 | 621 XSRETURN_EMPTY; |
599 | 622 } |
623 | |
624 b = ngx_create_temp_buf(r->pool, size); | |
625 if (b == NULL) { | |
633 | 626 XSRETURN_EMPTY; |
599 | 627 } |
628 | |
629 for (i = 1; i < items; i++) { | |
630 sv = ST(i); | |
631 | |
632 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
633 sv = SvRV(sv); | |
634 } | |
635 | |
636 p = (u_char *) SvPV(sv, len); | |
637 b->last = ngx_cpymem(b->last, p, len); | |
638 } | |
639 | |
640 out: | |
641 | |
633 | 642 (void) ngx_http_perl_output(r, b); |
599 | 643 |
644 | |
633 | 645 void |
613 | 646 sendfile(r, filename, offset = -1, bytes = 0) |
633 | 647 CODE: |
648 | |
1454 | 649 ngx_http_request_t *r; |
650 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
|
651 off_t offset; |
1454 | 652 size_t bytes; |
653 ngx_str_t path; | |
654 ngx_buf_t *b; | |
655 ngx_open_file_info_t of; | |
656 ngx_http_core_loc_conf_t *clcf; | |
599 | 657 |
633 | 658 ngx_http_perl_set_request(r); |
659 | |
660 filename = SvPV_nolen(ST(1)); | |
599 | 661 |
662 if (filename == NULL) { | |
663 croak("sendfile(): NULL filename"); | |
664 } | |
665 | |
633 | 666 offset = items < 3 ? -1 : SvIV(ST(2)); |
667 bytes = items < 4 ? 0 : SvIV(ST(3)); | |
668 | |
599 | 669 b = ngx_calloc_buf(r->pool); |
670 if (b == NULL) { | |
633 | 671 XSRETURN_EMPTY; |
599 | 672 } |
673 | |
674 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | |
675 if (b->file == NULL) { | |
633 | 676 XSRETURN_EMPTY; |
599 | 677 } |
678 | |
1454 | 679 path.len = ngx_strlen(filename); |
680 | |
2061
b0a1c84725cf
change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
681 path.data = ngx_pnalloc(r->pool, path.len + 1); |
1454 | 682 if (path.data == NULL) { |
633 | 683 XSRETURN_EMPTY; |
599 | 684 } |
685 | |
3870 | 686 (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
|
687 |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
688 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
|
689 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
690 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
|
691 |
3178 | 692 of.read_ahead = clcf->read_ahead; |
2129 | 693 of.directio = clcf->directio; |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 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
|
698 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
699 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
|
700 XSRETURN_EMPTY; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
701 } |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
702 |
1799 | 703 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
704 != NGX_OK) | |
705 { | |
1454 | 706 if (of.err == 0) { |
707 XSRETURN_EMPTY; | |
708 } | |
709 | |
599 | 710 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
|
711 "%s \"%s\" failed", of.failed, filename); |
633 | 712 XSRETURN_EMPTY; |
599 | 713 } |
714 | |
613 | 715 if (offset == -1) { |
716 offset = 0; | |
717 } | |
718 | |
719 if (bytes == 0) { | |
1454 | 720 bytes = of.size - offset; |
599 | 721 } |
722 | |
723 b->in_file = 1; | |
613 | 724 |
725 b->file_pos = offset; | |
726 b->file_last = offset + bytes; | |
599 | 727 |
1454 | 728 b->file->fd = of.fd; |
599 | 729 b->file->log = r->connection->log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
730 b->file->directio = of.is_directio; |
599 | 731 |
633 | 732 (void) ngx_http_perl_output(r, b); |
599 | 733 |
734 | |
633 | 735 void |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
736 flush(r) |
633 | 737 CODE: |
599 | 738 |
633 | 739 ngx_http_request_t *r; |
740 ngx_buf_t *b; | |
599 | 741 |
633 | 742 ngx_http_perl_set_request(r); |
599 | 743 |
744 b = ngx_calloc_buf(r->pool); | |
745 if (b == NULL) { | |
633 | 746 XSRETURN_EMPTY; |
599 | 747 } |
748 | |
749 b->flush = 1; | |
750 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
751 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush"); |
601 | 752 |
633 | 753 (void) ngx_http_perl_output(r, b); |
599 | 754 |
633 | 755 XSRETURN_EMPTY; |
599 | 756 |
757 | |
758 void | |
759 internal_redirect(r, uri) | |
633 | 760 CODE: |
599 | 761 |
633 | 762 ngx_http_request_t *r; |
763 SV *uri; | |
599 | 764 ngx_uint_t i; |
765 ngx_http_perl_ctx_t *ctx; | |
766 | |
633 | 767 ngx_http_perl_set_request(r); |
768 | |
769 uri = ST(1); | |
599 | 770 |
771 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
772 | |
773 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) { | |
774 XSRETURN_EMPTY; | |
775 } | |
776 | |
777 for (i = 0; i < ctx->redirect_uri.len; i++) { | |
778 if (ctx->redirect_uri.data[i] == '?') { | |
779 | |
780 ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1); | |
781 ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1]; | |
782 ctx->redirect_uri.len = i; | |
783 | |
784 XSRETURN_EMPTY; | |
785 } | |
786 } | |
601 | 787 |
788 | |
633 | 789 void |
811 | 790 allow_ranges(r) |
791 CODE: | |
792 | |
793 ngx_http_request_t *r; | |
794 | |
795 ngx_http_perl_set_request(r); | |
796 | |
797 r->allow_ranges = 1; | |
798 | |
799 | |
800 void | |
601 | 801 unescape(r, text, type = 0) |
802 CODE: | |
803 | |
633 | 804 dXSTARG; |
805 ngx_http_request_t *r; | |
806 SV *text; | |
807 int type; | |
808 u_char *p, *dst, *src; | |
809 STRLEN len; | |
601 | 810 |
633 | 811 ngx_http_perl_set_request(r); |
812 | |
813 text = ST(1); | |
814 | |
815 src = (u_char *) SvPV(text, len); | |
816 | |
2049 | 817 p = ngx_pnalloc(r->pool, len + 1); |
601 | 818 if (p == NULL) { |
819 XSRETURN_UNDEF; | |
820 } | |
821 | |
822 dst = p; | |
823 | |
633 | 824 type = items < 3 ? 0 : SvIV(ST(2)); |
825 | |
826 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); | |
601 | 827 *dst = '\0'; |
828 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
829 ngx_http_perl_set_targ(p, dst - p); |
601 | 830 |
633 | 831 ST(0) = TARG; |
833 | 832 |
833 | |
834 void | |
835 variable(r, name, value = NULL) | |
836 CODE: | |
837 | |
838 dXSTARG; | |
839 ngx_http_request_t *r; | |
840 SV *name, *value; | |
841 u_char *p, *lowcase; | |
842 STRLEN len; | |
843 ngx_str_t var, val; | |
844 ngx_uint_t i, hash; | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
845 ngx_http_perl_var_t *v; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
846 ngx_http_perl_ctx_t *ctx; |
833 | 847 ngx_http_variable_value_t *vv; |
848 | |
849 ngx_http_perl_set_request(r); | |
850 | |
851 name = ST(1); | |
852 | |
853 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
854 name = SvRV(name); | |
855 } | |
856 | |
857 if (items == 2) { | |
858 value = NULL; | |
859 | |
860 } else { | |
861 value = ST(2); | |
862 | |
863 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
864 value = SvRV(value); | |
865 } | |
866 | |
867 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) { | |
868 XSRETURN_UNDEF; | |
869 } | |
870 } | |
871 | |
872 p = (u_char *) SvPV(name, len); | |
873 | |
2049 | 874 lowcase = ngx_pnalloc(r->pool, len); |
833 | 875 if (lowcase == NULL) { |
876 XSRETURN_UNDEF; | |
877 } | |
878 | |
2136 | 879 hash = ngx_hash_strlow(lowcase, p, len); |
833 | 880 |
881 var.len = len; | |
882 var.data = lowcase; | |
883 | |
4188 | 884 #if (NGX_DEBUG) |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
885 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
886 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
887 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
|
888 "perl variable: \"%V\"=\"%V\"", &var, &val); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
889 } else { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
890 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
|
891 "perl variable: \"%V\"", &var); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
892 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
893 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
894 #endif |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
895 |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3447
diff
changeset
|
896 vv = ngx_http_get_variable(r, &var, hash); |
833 | 897 if (vv == NULL) { |
898 XSRETURN_UNDEF; | |
899 } | |
900 | |
901 if (vv->not_found) { | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
902 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
903 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
|
904 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
905 if (ctx->variables) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
906 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
907 v = ctx->variables->elts; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
908 for (i = 0; i < ctx->variables->nelts; i++) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
909 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
910 if (hash != v[i].hash |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
911 || len != v[i].name.len |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
912 || 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
|
913 { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
914 continue; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
915 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
916 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
917 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
918 v[i].value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
919 XSRETURN_UNDEF; |
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 |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
922 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
|
923 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
924 goto done; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
925 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
926 } |
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 (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
929 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
930 ctx->variables = ngx_array_create(r->pool, 1, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
931 sizeof(ngx_http_perl_var_t)); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
932 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
933 XSRETURN_UNDEF; |
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 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
936 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
937 v = ngx_array_push(ctx->variables); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
938 if (v == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
939 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
940 } |
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 v->hash = hash; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
943 v->name.len = len; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
944 v->name.data = lowcase; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
945 v->value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
946 |
833 | 947 XSRETURN_UNDEF; |
948 } | |
949 | |
950 XSRETURN_UNDEF; | |
951 } | |
952 | |
953 if (value) { | |
954 vv->len = val.len; | |
955 vv->valid = 1; | |
1565 | 956 vv->no_cacheable = 0; |
833 | 957 vv->not_found = 0; |
958 vv->data = val.data; | |
959 | |
960 XSRETURN_UNDEF; | |
961 } | |
962 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
963 ngx_http_perl_set_targ(vv->data, vv->len); |
833 | 964 |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
965 done: |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
966 |
833 | 967 ST(0) = TARG; |
907 | 968 |
969 | |
970 void | |
911 | 971 sleep(r, sleep, next) |
972 CODE: | |
973 | |
974 ngx_http_request_t *r; | |
1897 | 975 ngx_msec_t sleep; |
911 | 976 ngx_http_perl_ctx_t *ctx; |
977 | |
978 ngx_http_perl_set_request(r); | |
979 | |
1898 | 980 sleep = (ngx_msec_t) SvIV(ST(1)); |
1897 | 981 |
982 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
983 "perl sleep: %M", sleep); | |
984 | |
911 | 985 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); |
986 | |
987 ctx->next = SvRV(ST(2)); | |
988 | |
1897 | 989 ngx_add_timer(r->connection->write, sleep); |
990 | |
991 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
|
992 r->main->count++; |
911 | 993 |
994 | |
995 void | |
907 | 996 log_error(r, err, msg) |
997 CODE: | |
998 | |
999 ngx_http_request_t *r; | |
1000 SV *err, *msg; | |
1001 u_char *p; | |
1002 STRLEN len; | |
1003 ngx_err_t e; | |
1004 | |
1005 ngx_http_perl_set_request(r); | |
1006 | |
1007 err = ST(1); | |
1008 | |
1009 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) { | |
1010 err = SvRV(err); | |
1011 } | |
1012 | |
1013 e = SvIV(err); | |
1014 | |
1015 msg = ST(2); | |
1016 | |
1017 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) { | |
1018 msg = SvRV(msg); | |
1019 } | |
1020 | |
1021 p = (u_char *) SvPV(msg, len); | |
1022 | |
910 | 1023 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p); |