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