comparison src/http/modules/perl/nginx.xs @ 356:b743d290eb3b NGINX_0_6_22

nginx 0.6.22 *) Change: now all ngx_http_perl_module methods return values copied to perl's allocated memory. *) Bugfix: if nginx was built with ngx_http_perl_module, the perl before 5.8.6 was used, and perl supported threads, then during reconfiguration the master process aborted; bug appeared in 0.5.9. Thanks to Boris Zhmurov. *) Bugfix: the ngx_http_perl_module methods may get invalid values of the regex captures. *) Bugfix: a segmentation fault occurred in worker process, if the $r->has_request_body() method was called for a request whose small request body was already received. *) Bugfix: large_client_header_buffers did not freed before going to keep-alive state. Thanks to Olexander Shtepa. *) Bugfix: the last address was missed in the $upstream_addr variable; bug appeared in 0.6.18. *) Bugfix: the "fastcgi_catch_stderr" directive did return error code; now it returns 502 code, that can be rerouted to a next server using the "fastcgi_next_upstream invalid_header" directive. *) Bugfix: a segmentation fault occurred in master process if the "fastcgi_catch_stderr" directive was used; bug appeared in 0.6.10. Thanks to Manlio Perillo.
author Igor Sysoev <http://sysoev.ru>
date Wed, 19 Dec 2007 00:00:00 +0300
parents 10cc350ed8a1
children 9121a0a91f47
comparison
equal deleted inserted replaced
355:3ac45897a61c 356:b743d290eb3b
11 #include <ngx_http.h> 11 #include <ngx_http.h>
12 #include <ngx_http_perl_module.h> 12 #include <ngx_http_perl_module.h>
13 13
14 #include "XSUB.h" 14 #include "XSUB.h"
15 15
16
16 #define ngx_http_perl_set_request(r) \ 17 #define ngx_http_perl_set_request(r) \
17 r = INT2PTR(ngx_http_request_t *, SvIV((SV *) SvRV(ST(0)))) 18 r = INT2PTR(ngx_http_request_t *, SvIV((SV *) SvRV(ST(0))))
18 19
19 20
20 #define ngx_http_perl_set_targ(p, len, z) \ 21 #define ngx_http_perl_set_targ(p, len) \
21 \ 22 \
22 sv_upgrade(TARG, SVt_PV); \ 23 SvUPGRADE(TARG, SVt_PV); \
23 SvPOK_on(TARG); \ 24 SvPOK_on(TARG); \
24 SvPV_set(TARG, (char *) p); \ 25 sv_setpvn(TARG, (char *) p, len)
25 SvLEN_set(TARG, len + z); \
26 SvCUR_set(TARG, len); \
27 SvFAKE_on(TARG); \
28 SvREADONLY_on(TARG); \
29 26
30 27
31 static ngx_int_t 28 static ngx_int_t
32 ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv) 29 ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv)
33 { 30 {
40 37
41 p = (u_char *) SvPV(sv, len); 38 p = (u_char *) SvPV(sv, len);
42 39
43 s->len = len; 40 s->len = len;
44 41
45 if (SvREADONLY(sv)) { 42 if (SvREADONLY(sv) && SvPOK(sv)) {
46 s->data = p; 43 s->data = p;
44
45 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
46 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s);
47
47 return NGX_OK; 48 return NGX_OK;
48 } 49 }
49 50
50 s->data = ngx_palloc(r->pool, len); 51 s->data = ngx_palloc(r->pool, len);
51 if (s->data == NULL) { 52 if (s->data == NULL) {
52 return NGX_ERROR; 53 return NGX_ERROR;
53 } 54 }
54 55
55 ngx_memcpy(s->data, p, len); 56 ngx_memcpy(s->data, p, len);
57
58 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
59 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s);
56 60
57 return NGX_OK; 61 return NGX_OK;
58 } 62 }
59 63
60 64
163 167
164 dXSTARG; 168 dXSTARG;
165 ngx_http_request_t *r; 169 ngx_http_request_t *r;
166 170
167 ngx_http_perl_set_request(r); 171 ngx_http_perl_set_request(r);
168 ngx_http_perl_set_targ(r->uri.data, r->uri.len, 0); 172 ngx_http_perl_set_targ(r->uri.data, r->uri.len);
169 173
170 ST(0) = TARG; 174 ST(0) = TARG;
171 175
172 176
173 void 177 void
176 180
177 dXSTARG; 181 dXSTARG;
178 ngx_http_request_t *r; 182 ngx_http_request_t *r;
179 183
180 ngx_http_perl_set_request(r); 184 ngx_http_perl_set_request(r);
181 ngx_http_perl_set_targ(r->args.data, r->args.len, 0); 185 ngx_http_perl_set_targ(r->args.data, r->args.len);
182 186
183 ST(0) = TARG; 187 ST(0) = TARG;
184 188
185 189
186 void 190 void
189 193
190 dXSTARG; 194 dXSTARG;
191 ngx_http_request_t *r; 195 ngx_http_request_t *r;
192 196
193 ngx_http_perl_set_request(r); 197 ngx_http_perl_set_request(r);
194 ngx_http_perl_set_targ(r->method_name.data, r->method_name.len, 0); 198 ngx_http_perl_set_targ(r->method_name.data, r->method_name.len);
195 199
196 ST(0) = TARG; 200 ST(0) = TARG;
197 201
198 202
199 void 203 void
203 dXSTARG; 207 dXSTARG;
204 ngx_http_request_t *r; 208 ngx_http_request_t *r;
205 209
206 ngx_http_perl_set_request(r); 210 ngx_http_perl_set_request(r);
207 ngx_http_perl_set_targ(r->connection->addr_text.data, 211 ngx_http_perl_set_targ(r->connection->addr_text.data,
208 r->connection->addr_text.len, 1); 212 r->connection->addr_text.len);
209 213
210 ST(0) = TARG; 214 ST(0) = TARG;
211 215
212 216
213 void 217 void
257 if (hh->offset) { 261 if (hh->offset) {
258 262
259 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); 263 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
260 264
261 if (*ph) { 265 if (*ph) {
262 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len, 0); 266 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
263 267
264 goto done; 268 goto done;
265 } 269 }
266 270
267 XSRETURN_UNDEF; 271 XSRETURN_UNDEF;
276 } 280 }
277 281
278 ph = r->headers_in.cookies.elts; 282 ph = r->headers_in.cookies.elts;
279 283
280 if (n == 1) { 284 if (n == 1) {
281 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len, 0); 285 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
282 286
283 goto done; 287 goto done;
284 } 288 }
285 289
286 size = - (ssize_t) (sizeof("; ") - 1); 290 size = - (ssize_t) (sizeof("; ") - 1);
304 } 308 }
305 309
306 *p++ = ';'; *p++ = ' '; 310 *p++ = ';'; *p++ = ' ';
307 } 311 }
308 312
309 ngx_http_perl_set_targ(cookie, size, 0); 313 ngx_http_perl_set_targ(cookie, size);
310 314
311 goto done; 315 goto done;
312 } 316 }
313 317
314 /* iterate over all headers */ 318 /* iterate over all headers */
332 || ngx_strcasecmp(p, h[i].key.data) != 0) 336 || ngx_strcasecmp(p, h[i].key.data) != 0)
333 { 337 {
334 continue; 338 continue;
335 } 339 }
336 340
337 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len, 0); 341 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len);
338 342
339 goto done; 343 goto done;
340 } 344 }
341 345
342 XSRETURN_UNDEF; 346 XSRETURN_UNDEF;
400 404
401 if (len == 0) { 405 if (len == 0) {
402 XSRETURN_UNDEF; 406 XSRETURN_UNDEF;
403 } 407 }
404 408
405 ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len, 0); 409 ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len);
406 410
407 ST(0) = TARG; 411 ST(0) = TARG;
408 412
409 413
410 void 414 void
419 if (r->request_body == NULL || r->request_body->temp_file == NULL) { 423 if (r->request_body == NULL || r->request_body->temp_file == NULL) {
420 XSRETURN_UNDEF; 424 XSRETURN_UNDEF;
421 } 425 }
422 426
423 ngx_http_perl_set_targ(r->request_body->temp_file->file.name.data, 427 ngx_http_perl_set_targ(r->request_body->temp_file->file.name.data,
424 r->request_body->temp_file->file.name.len, 1); 428 r->request_body->temp_file->file.name.len);
425 429
426 ST(0) = TARG; 430 ST(0) = TARG;
427 431
428 432
429 void 433 void
498 ctx->filename.len--; 502 ctx->filename.len--;
499 sv_setpv(PL_statname, (char *) ctx->filename.data); 503 sv_setpv(PL_statname, (char *) ctx->filename.data);
500 504
501 done: 505 done:
502 506
503 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len, 1); 507 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len);
504 508
505 ST(0) = TARG; 509 ST(0) = TARG;
506 510
507 511
508 void 512 void
530 534
531 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { 535 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
532 sv = SvRV(sv); 536 sv = SvRV(sv);
533 } 537 }
534 538
535 if (SvREADONLY(sv)) { 539 if (SvREADONLY(sv) && SvPOK(sv)) {
536 540
537 p = (u_char *) SvPV(sv, len); 541 p = (u_char *) SvPV(sv, len);
538 542
539 if (len == 0) { 543 if (len == 0) {
540 XSRETURN_EMPTY; 544 XSRETURN_EMPTY;
776 type = items < 3 ? 0 : SvIV(ST(2)); 780 type = items < 3 ? 0 : SvIV(ST(2));
777 781
778 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); 782 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type);
779 *dst = '\0'; 783 *dst = '\0';
780 784
781 ngx_http_perl_set_targ(p, dst - p, 1); 785 ngx_http_perl_set_targ(p, dst - p);
782 786
783 ST(0) = TARG; 787 ST(0) = TARG;
784 788
785 789
786 void 790 void
873 if (value) { 877 if (value) {
874 v[i].value = val; 878 v[i].value = val;
875 XSRETURN_UNDEF; 879 XSRETURN_UNDEF;
876 } 880 }
877 881
878 ngx_http_perl_set_targ(v[i].value.data, v[i].value.len, 0); 882 ngx_http_perl_set_targ(v[i].value.data, v[i].value.len);
879 883
880 goto done; 884 goto done;
881 } 885 }
882 } 886 }
883 887
917 vv->data = val.data; 921 vv->data = val.data;
918 922
919 XSRETURN_UNDEF; 923 XSRETURN_UNDEF;
920 } 924 }
921 925
922 ngx_http_perl_set_targ(vv->data, vv->len, 0); 926 ngx_http_perl_set_targ(vv->data, vv->len);
923 927
924 done: 928 done:
925 929
926 ST(0) = TARG; 930 ST(0) = TARG;
927 931