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