Mercurial > hg > nginx-quic
annotate src/http/modules/perl/nginx.xs @ 4835:a4512d7737f6
Memcached: memcached_gzip_flag directive.
This directive allows to test desired flag as returned by memcached and
sets Content-Encoding to gzip if one found.
This is reimplementation of patch by Tomash Brechko as available on
http://openhack.ru/. It should be a bit more correct though (at least
I think so). In particular, it doesn't try to detect if we are able to
gunzip data, but instead just sets correct Content-Encoding.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 10 Sep 2012 16:43:49 +0000 |
parents | 95763fce86a8 |
children | 4d0ac175f6e4 |
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 | |
360 if (r->headers_in.content_length_n <= 0) { | |
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; | |
389 size_t len; | |
390 | |
391 ngx_http_perl_set_request(r); | |
631 | 392 |
941 | 393 if (r->request_body == NULL |
394 || r->request_body->temp_file | |
395 || r->request_body->bufs == NULL) | |
396 { | |
633 | 397 XSRETURN_UNDEF; |
398 } | |
631 | 399 |
633 | 400 len = r->request_body->bufs->buf->last - r->request_body->bufs->buf->pos; |
631 | 401 |
402 if (len == 0) { | |
403 XSRETURN_UNDEF; | |
404 } | |
405 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
406 ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len); |
631 | 407 |
633 | 408 ST(0) = TARG; |
631 | 409 |
410 | |
633 | 411 void |
412 request_body_file(r) | |
413 CODE: | |
414 | |
415 dXSTARG; | |
416 ngx_http_request_t *r; | |
417 | |
418 ngx_http_perl_set_request(r); | |
419 | |
941 | 420 if (r->request_body == NULL || r->request_body->temp_file == NULL) { |
633 | 421 XSRETURN_UNDEF; |
422 } | |
423 | |
424 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
|
425 r->request_body->temp_file->file.name.len); |
599 | 426 |
633 | 427 ST(0) = TARG; |
428 | |
429 | |
430 void | |
1371 | 431 discard_request_body(r) |
432 CODE: | |
433 | |
434 ngx_http_request_t *r; | |
435 | |
436 ngx_http_perl_set_request(r); | |
437 | |
438 ngx_http_discard_request_body(r); | |
439 | |
440 | |
441 void | |
633 | 442 header_out(r, key, value) |
443 CODE: | |
599 | 444 |
633 | 445 ngx_http_request_t *r; |
446 SV *key; | |
447 SV *value; | |
448 ngx_table_elt_t *header; | |
599 | 449 |
633 | 450 ngx_http_perl_set_request(r); |
451 | |
452 key = ST(1); | |
453 value = ST(2); | |
599 | 454 |
455 header = ngx_list_push(&r->headers_out.headers); | |
456 if (header == NULL) { | |
633 | 457 XSRETURN_EMPTY; |
599 | 458 } |
459 | |
460 header->hash = 1; | |
461 | |
462 if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) { | |
633 | 463 XSRETURN_EMPTY; |
599 | 464 } |
465 | |
466 if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) { | |
633 | 467 XSRETURN_EMPTY; |
599 | 468 } |
469 | |
470 if (header->key.len == sizeof("Content-Length") - 1 | |
3870 | 471 && 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
|
472 sizeof("Content-Length") - 1) == 0) |
599 | 473 { |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
474 r->headers_out.content_length_n = (off_t) SvIV(value); |
599 | 475 r->headers_out.content_length = header; |
476 } | |
477 | |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
478 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
|
479 && 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
|
480 sizeof("Content-Encoding") - 1) == 0) |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
481 { |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
482 r->headers_out.content_encoding = header; |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
483 } |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
484 |
599 | 485 |
633 | 486 void |
599 | 487 filename(r) |
633 | 488 CODE: |
599 | 489 |
633 | 490 dXSTARG; |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
491 size_t root; |
633 | 492 ngx_http_request_t *r; |
599 | 493 ngx_http_perl_ctx_t *ctx; |
494 | |
633 | 495 ngx_http_perl_set_request(r); |
599 | 496 |
497 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
633 | 498 if (ctx->filename.data) { |
599 | 499 goto done; |
500 } | |
501 | |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
502 if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) { |
599 | 503 XSRETURN_UNDEF; |
504 } | |
505 | |
633 | 506 ctx->filename.len--; |
507 sv_setpv(PL_statname, (char *) ctx->filename.data); | |
599 | 508 |
509 done: | |
510 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
511 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len); |
599 | 512 |
633 | 513 ST(0) = TARG; |
599 | 514 |
515 | |
633 | 516 void |
599 | 517 print(r, ...) |
518 CODE: | |
519 | |
633 | 520 ngx_http_request_t *r; |
521 SV *sv; | |
522 int i; | |
523 u_char *p; | |
524 size_t size; | |
525 STRLEN len; | |
526 ngx_buf_t *b; | |
527 | |
528 ngx_http_perl_set_request(r); | |
599 | 529 |
530 if (items == 2) { | |
531 | |
532 /* | |
533 * do zero copy for prolate single read-only SV: | |
534 * $r->print("some text\n"); | |
535 */ | |
536 | |
537 sv = ST(1); | |
538 | |
539 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
540 sv = SvRV(sv); | |
541 } | |
542 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
543 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 544 |
545 p = (u_char *) SvPV(sv, len); | |
546 | |
547 if (len == 0) { | |
633 | 548 XSRETURN_EMPTY; |
599 | 549 } |
550 | |
551 b = ngx_calloc_buf(r->pool); | |
552 if (b == NULL) { | |
633 | 553 XSRETURN_EMPTY; |
599 | 554 } |
555 | |
556 b->memory = 1; | |
557 b->pos = p; | |
558 b->last = p + len; | |
559 b->start = p; | |
560 b->end = b->last; | |
561 | |
601 | 562 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
563 "$r->print: read-only SV: %z", len); | |
564 | |
599 | 565 goto out; |
566 } | |
567 } | |
568 | |
569 size = 0; | |
570 | |
571 for (i = 1; i < items; i++) { | |
572 | |
573 sv = ST(i); | |
574 | |
575 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
576 sv = SvRV(sv); | |
577 } | |
578 | |
601 | 579 (void) SvPV(sv, len); |
599 | 580 |
601 | 581 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
582 "$r->print: copy SV: %z", len); | |
599 | 583 |
584 size += len; | |
585 } | |
586 | |
587 if (size == 0) { | |
633 | 588 XSRETURN_EMPTY; |
599 | 589 } |
590 | |
591 b = ngx_create_temp_buf(r->pool, size); | |
592 if (b == NULL) { | |
633 | 593 XSRETURN_EMPTY; |
599 | 594 } |
595 | |
596 for (i = 1; i < items; i++) { | |
597 sv = ST(i); | |
598 | |
599 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
600 sv = SvRV(sv); | |
601 } | |
602 | |
603 p = (u_char *) SvPV(sv, len); | |
604 b->last = ngx_cpymem(b->last, p, len); | |
605 } | |
606 | |
607 out: | |
608 | |
633 | 609 (void) ngx_http_perl_output(r, b); |
599 | 610 |
611 | |
633 | 612 void |
613 | 613 sendfile(r, filename, offset = -1, bytes = 0) |
633 | 614 CODE: |
615 | |
1454 | 616 ngx_http_request_t *r; |
617 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
|
618 off_t offset; |
1454 | 619 size_t bytes; |
620 ngx_str_t path; | |
621 ngx_buf_t *b; | |
622 ngx_open_file_info_t of; | |
623 ngx_http_core_loc_conf_t *clcf; | |
599 | 624 |
633 | 625 ngx_http_perl_set_request(r); |
626 | |
627 filename = SvPV_nolen(ST(1)); | |
599 | 628 |
629 if (filename == NULL) { | |
630 croak("sendfile(): NULL filename"); | |
631 } | |
632 | |
633 | 633 offset = items < 3 ? -1 : SvIV(ST(2)); |
634 bytes = items < 4 ? 0 : SvIV(ST(3)); | |
635 | |
599 | 636 b = ngx_calloc_buf(r->pool); |
637 if (b == NULL) { | |
633 | 638 XSRETURN_EMPTY; |
599 | 639 } |
640 | |
641 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | |
642 if (b->file == NULL) { | |
633 | 643 XSRETURN_EMPTY; |
599 | 644 } |
645 | |
1454 | 646 path.len = ngx_strlen(filename); |
647 | |
2061
b0a1c84725cf
change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
648 path.data = ngx_pnalloc(r->pool, path.len + 1); |
1454 | 649 if (path.data == NULL) { |
633 | 650 XSRETURN_EMPTY; |
599 | 651 } |
652 | |
3870 | 653 (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
|
654 |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
655 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
|
656 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
657 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
|
658 |
3178 | 659 of.read_ahead = clcf->read_ahead; |
2129 | 660 of.directio = clcf->directio; |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
661 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
|
662 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
|
663 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
|
664 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
|
665 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
666 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
|
667 XSRETURN_EMPTY; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
668 } |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
669 |
1799 | 670 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
671 != NGX_OK) | |
672 { | |
1454 | 673 if (of.err == 0) { |
674 XSRETURN_EMPTY; | |
675 } | |
676 | |
599 | 677 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
|
678 "%s \"%s\" failed", of.failed, filename); |
633 | 679 XSRETURN_EMPTY; |
599 | 680 } |
681 | |
613 | 682 if (offset == -1) { |
683 offset = 0; | |
684 } | |
685 | |
686 if (bytes == 0) { | |
1454 | 687 bytes = of.size - offset; |
599 | 688 } |
689 | |
690 b->in_file = 1; | |
613 | 691 |
692 b->file_pos = offset; | |
693 b->file_last = offset + bytes; | |
599 | 694 |
1454 | 695 b->file->fd = of.fd; |
599 | 696 b->file->log = r->connection->log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
697 b->file->directio = of.is_directio; |
599 | 698 |
633 | 699 (void) ngx_http_perl_output(r, b); |
599 | 700 |
701 | |
633 | 702 void |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
703 flush(r) |
633 | 704 CODE: |
599 | 705 |
633 | 706 ngx_http_request_t *r; |
707 ngx_buf_t *b; | |
599 | 708 |
633 | 709 ngx_http_perl_set_request(r); |
599 | 710 |
711 b = ngx_calloc_buf(r->pool); | |
712 if (b == NULL) { | |
633 | 713 XSRETURN_EMPTY; |
599 | 714 } |
715 | |
716 b->flush = 1; | |
717 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
718 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush"); |
601 | 719 |
633 | 720 (void) ngx_http_perl_output(r, b); |
599 | 721 |
633 | 722 XSRETURN_EMPTY; |
599 | 723 |
724 | |
725 void | |
726 internal_redirect(r, uri) | |
633 | 727 CODE: |
599 | 728 |
633 | 729 ngx_http_request_t *r; |
730 SV *uri; | |
599 | 731 ngx_uint_t i; |
732 ngx_http_perl_ctx_t *ctx; | |
733 | |
633 | 734 ngx_http_perl_set_request(r); |
735 | |
736 uri = ST(1); | |
599 | 737 |
738 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
739 | |
740 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) { | |
741 XSRETURN_EMPTY; | |
742 } | |
743 | |
744 for (i = 0; i < ctx->redirect_uri.len; i++) { | |
745 if (ctx->redirect_uri.data[i] == '?') { | |
746 | |
747 ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1); | |
748 ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1]; | |
749 ctx->redirect_uri.len = i; | |
750 | |
751 XSRETURN_EMPTY; | |
752 } | |
753 } | |
601 | 754 |
755 | |
633 | 756 void |
811 | 757 allow_ranges(r) |
758 CODE: | |
759 | |
760 ngx_http_request_t *r; | |
761 | |
762 ngx_http_perl_set_request(r); | |
763 | |
764 r->allow_ranges = 1; | |
765 | |
766 | |
767 void | |
601 | 768 unescape(r, text, type = 0) |
769 CODE: | |
770 | |
633 | 771 dXSTARG; |
772 ngx_http_request_t *r; | |
773 SV *text; | |
774 int type; | |
775 u_char *p, *dst, *src; | |
776 STRLEN len; | |
601 | 777 |
633 | 778 ngx_http_perl_set_request(r); |
779 | |
780 text = ST(1); | |
781 | |
782 src = (u_char *) SvPV(text, len); | |
783 | |
2049 | 784 p = ngx_pnalloc(r->pool, len + 1); |
601 | 785 if (p == NULL) { |
786 XSRETURN_UNDEF; | |
787 } | |
788 | |
789 dst = p; | |
790 | |
633 | 791 type = items < 3 ? 0 : SvIV(ST(2)); |
792 | |
793 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); | |
601 | 794 *dst = '\0'; |
795 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
796 ngx_http_perl_set_targ(p, dst - p); |
601 | 797 |
633 | 798 ST(0) = TARG; |
833 | 799 |
800 | |
801 void | |
802 variable(r, name, value = NULL) | |
803 CODE: | |
804 | |
805 dXSTARG; | |
806 ngx_http_request_t *r; | |
807 SV *name, *value; | |
808 u_char *p, *lowcase; | |
809 STRLEN len; | |
810 ngx_str_t var, val; | |
811 ngx_uint_t i, hash; | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
812 ngx_http_perl_var_t *v; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
813 ngx_http_perl_ctx_t *ctx; |
833 | 814 ngx_http_variable_value_t *vv; |
815 | |
816 ngx_http_perl_set_request(r); | |
817 | |
818 name = ST(1); | |
819 | |
820 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
821 name = SvRV(name); | |
822 } | |
823 | |
824 if (items == 2) { | |
825 value = NULL; | |
826 | |
827 } else { | |
828 value = ST(2); | |
829 | |
830 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
831 value = SvRV(value); | |
832 } | |
833 | |
834 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) { | |
835 XSRETURN_UNDEF; | |
836 } | |
837 } | |
838 | |
839 p = (u_char *) SvPV(name, len); | |
840 | |
2049 | 841 lowcase = ngx_pnalloc(r->pool, len); |
833 | 842 if (lowcase == NULL) { |
843 XSRETURN_UNDEF; | |
844 } | |
845 | |
2136 | 846 hash = ngx_hash_strlow(lowcase, p, len); |
833 | 847 |
848 var.len = len; | |
849 var.data = lowcase; | |
850 | |
4188 | 851 #if (NGX_DEBUG) |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
852 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
853 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
854 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
|
855 "perl variable: \"%V\"=\"%V\"", &var, &val); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
856 } else { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
857 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
|
858 "perl variable: \"%V\"", &var); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
859 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
860 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
861 #endif |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
862 |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3447
diff
changeset
|
863 vv = ngx_http_get_variable(r, &var, hash); |
833 | 864 if (vv == NULL) { |
865 XSRETURN_UNDEF; | |
866 } | |
867 | |
868 if (vv->not_found) { | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
869 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
870 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
|
871 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
872 if (ctx->variables) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
873 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
874 v = ctx->variables->elts; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
875 for (i = 0; i < ctx->variables->nelts; i++) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
876 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
877 if (hash != v[i].hash |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
878 || len != v[i].name.len |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
879 || 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
|
880 { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
881 continue; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
882 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
883 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
884 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
885 v[i].value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
886 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
887 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
888 |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
889 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
|
890 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
891 goto done; |
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 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
895 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
896 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
897 ctx->variables = ngx_array_create(r->pool, 1, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
898 sizeof(ngx_http_perl_var_t)); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
899 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
900 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
901 } |
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 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
904 v = ngx_array_push(ctx->variables); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
905 if (v == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
906 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
907 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
908 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
909 v->hash = hash; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
910 v->name.len = len; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
911 v->name.data = lowcase; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
912 v->value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
913 |
833 | 914 XSRETURN_UNDEF; |
915 } | |
916 | |
917 XSRETURN_UNDEF; | |
918 } | |
919 | |
920 if (value) { | |
921 vv->len = val.len; | |
922 vv->valid = 1; | |
1565 | 923 vv->no_cacheable = 0; |
833 | 924 vv->not_found = 0; |
925 vv->data = val.data; | |
926 | |
927 XSRETURN_UNDEF; | |
928 } | |
929 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
930 ngx_http_perl_set_targ(vv->data, vv->len); |
833 | 931 |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
932 done: |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
933 |
833 | 934 ST(0) = TARG; |
907 | 935 |
936 | |
937 void | |
911 | 938 sleep(r, sleep, next) |
939 CODE: | |
940 | |
941 ngx_http_request_t *r; | |
1897 | 942 ngx_msec_t sleep; |
911 | 943 ngx_http_perl_ctx_t *ctx; |
944 | |
945 ngx_http_perl_set_request(r); | |
946 | |
1898 | 947 sleep = (ngx_msec_t) SvIV(ST(1)); |
1897 | 948 |
949 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
950 "perl sleep: %M", sleep); | |
951 | |
911 | 952 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); |
953 | |
954 ctx->next = SvRV(ST(2)); | |
955 | |
1897 | 956 ngx_add_timer(r->connection->write, sleep); |
957 | |
958 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
|
959 r->main->count++; |
911 | 960 |
961 | |
962 void | |
907 | 963 log_error(r, err, msg) |
964 CODE: | |
965 | |
966 ngx_http_request_t *r; | |
967 SV *err, *msg; | |
968 u_char *p; | |
969 STRLEN len; | |
970 ngx_err_t e; | |
971 | |
972 ngx_http_perl_set_request(r); | |
973 | |
974 err = ST(1); | |
975 | |
976 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) { | |
977 err = SvRV(err); | |
978 } | |
979 | |
980 e = SvIV(err); | |
981 | |
982 msg = ST(2); | |
983 | |
984 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) { | |
985 msg = SvRV(msg); | |
986 } | |
987 | |
988 p = (u_char *) SvPV(msg, len); | |
989 | |
910 | 990 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p); |