Mercurial > hg > nginx
annotate src/http/modules/perl/nginx.xs @ 9322:d6f75dd66761 default tip
Mp4: added and updated sanity checks for "end" handling.
When handling incorrect data in ngx_http_mp4_crop_stsc_data(),
trak->end_chunk_samples might end up being arbitrary large, leading
to reading before the buffer in ngx_http_mp4_update_stsz_atom(). Fix
is to check that trak->end_chunk_samples corresponds to a memory within
the stsz atom data. For consistency, trak->start_chunk_samples
is checked similarly.
Similarly, trak->end_chunk might end up being smaller than trak->start_chunk,
leading to reading memory after the buffer in ngx_http_mp4_update_stco_atom()
and ngx_http_mp4_update_co64_atom(). Corresponding checks are updated
to explicitly test (trak->end_chunk - trak->start_chunk) instead of just
checking trak->end_chunk and assuming it is larger than trak->start_chunk.
This is generally in line with existing checks of
(trak->end_sample - trak->start_sample) in ngx_http_mp4_update_stsz_atom(),
where trak->end_sample might also become smaller than trak->start_sample
when handling incorrect data in ngx_http_mp4_crop_stts_data().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 25 Aug 2024 06:35:40 +0300 |
parents | 861f076eab72 |
children |
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; | |
8046
861f076eab72
Perl: removed unused variables, forgotten in ef6a3a99a81a.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8031
diff
changeset
|
272 ngx_uint_t i, hash; |
667 | 273 ngx_list_part_t *part; |
8027
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
274 ngx_table_elt_t *h, *header, **ph; |
667 | 275 ngx_http_header_t *hh; |
276 ngx_http_core_main_conf_t *cmcf; | |
629 | 277 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
278 ngx_http_perl_set_request(r, ctx); |
599 | 279 |
633 | 280 key = ST(1); |
599 | 281 |
282 if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) { | |
283 key = SvRV(key); | |
284 } | |
285 | |
286 p = (u_char *) SvPV(key, len); | |
287 | |
667 | 288 /* look up hashed headers */ |
289 | |
2049 | 290 lowcase_key = ngx_pnalloc(r->pool, len); |
667 | 291 if (lowcase_key == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
292 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
293 croak("ngx_pnalloc() failed"); |
667 | 294 } |
295 | |
2136 | 296 hash = ngx_hash_strlow(lowcase_key, p, len); |
667 | 297 |
298 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
299 | |
300 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); | |
301 | |
302 if (hh) { | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
303 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7535
diff
changeset
|
304 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
|
305 sep = ';'; |
8026
8b3860b52bb3
Perl: all known input headers are handled identically.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
306 |
8b3860b52bb3
Perl: all known input headers are handled identically.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
307 } else { |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
308 sep = ','; |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
309 } |
667 | 310 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7535
diff
changeset
|
311 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
|
312 |
8027
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
313 goto found; |
667 | 314 } |
315 | |
316 /* iterate over all headers */ | |
317 | |
8027
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
318 sep = ','; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
319 ph = &header; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
320 |
599 | 321 part = &r->headers_in.headers.part; |
667 | 322 h = part->elts; |
599 | 323 |
324 for (i = 0; /* void */ ; i++) { | |
325 | |
326 if (i >= part->nelts) { | |
327 if (part->next == NULL) { | |
328 break; | |
329 } | |
330 | |
331 part = part->next; | |
667 | 332 h = part->elts; |
599 | 333 i = 0; |
334 } | |
335 | |
667 | 336 if (len != h[i].key.len |
337 || ngx_strcasecmp(p, h[i].key.data) != 0) | |
599 | 338 { |
339 continue; | |
340 } | |
341 | |
8027
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
342 *ph = &h[i]; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
343 ph = &h[i].next; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
344 } |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
345 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
346 *ph = NULL; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
347 ph = &header; |
599 | 348 |
8027
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
349 found: |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
350 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
351 if (*ph == NULL) { |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
352 XSRETURN_UNDEF; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
353 } |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
354 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
355 if ((*ph)->next == NULL) { |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
356 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
599 | 357 goto done; |
358 } | |
359 | |
8027
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
360 size = - (ssize_t) (sizeof("; ") - 1); |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
361 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
362 for (h = *ph; h; h = h->next) { |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
363 size += h->value.len + sizeof("; ") - 1; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
364 } |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
365 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
366 value = ngx_pnalloc(r->pool, size); |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
367 if (value == NULL) { |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
368 ctx->error = 1; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
369 croak("ngx_pnalloc() failed"); |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
370 } |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
371 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
372 p = value; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
373 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
374 for (h = *ph; h; h = h->next) { |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
375 p = ngx_copy(p, h->value.data, h->value.len); |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
376 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
377 if (h->next == NULL) { |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
378 break; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
379 } |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
380 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
381 *p++ = sep; *p++ = ' '; |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
382 } |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
383 |
ca78312db071
Perl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8026
diff
changeset
|
384 ngx_http_perl_set_targ(value, size); |
599 | 385 |
386 done: | |
387 | |
633 | 388 ST(0) = TARG; |
599 | 389 |
390 | |
633 | 391 void |
681 | 392 has_request_body(r, next) |
393 CODE: | |
394 | |
395 dXSTARG; | |
396 ngx_http_request_t *r; | |
397 ngx_http_perl_ctx_t *ctx; | |
7525 | 398 ngx_int_t rc; |
681 | 399 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
400 ngx_http_perl_set_request(r, ctx); |
681 | 401 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
402 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
403 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
|
404 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
405 |
7527
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
406 if (ctx->next) { |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
407 croak("has_request_body(): another handler active"); |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
408 } |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
409 |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
410 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
681 | 411 XSRETURN_UNDEF; |
412 } | |
413 | |
909 | 414 ctx->next = SvRV(ST(1)); |
681 | 415 |
416 r->request_body_in_single_buf = 1; | |
417 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
|
418 r->request_body_in_clean_file = 1; |
681 | 419 |
420 if (r->request_body_in_file_only) { | |
421 r->request_body_file_log_level = 0; | |
422 } | |
423 | |
7525 | 424 rc = ngx_http_read_client_request_body(r, ngx_http_perl_handle_request); |
425 | |
426 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
427 ctx->error = 1; | |
428 ctx->status = rc; | |
429 ctx->next = NULL; | |
430 croak("ngx_http_read_client_request_body() failed"); | |
431 } | |
681 | 432 |
433 sv_upgrade(TARG, SVt_IV); | |
434 sv_setiv(TARG, 1); | |
435 | |
436 ST(0) = TARG; | |
437 | |
438 | |
439 void | |
631 | 440 request_body(r) |
441 CODE: | |
442 | |
633 | 443 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
444 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
|
445 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
|
446 u_char *p, *data; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
447 size_t len; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
448 ngx_buf_t *buf; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
449 ngx_chain_t *cl; |
633 | 450 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
451 ngx_http_perl_set_request(r, ctx); |
631 | 452 |
941 | 453 if (r->request_body == NULL |
454 || r->request_body->temp_file | |
455 || r->request_body->bufs == NULL) | |
456 { | |
633 | 457 XSRETURN_UNDEF; |
458 } | |
631 | 459 |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
460 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
461 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
462 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
463 if (cl->next == NULL) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
464 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
465 data = buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
466 goto done; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
467 } |
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 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
470 cl = cl->next; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
471 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
472 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
473 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
474 len += buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
475 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
476 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
477 p = ngx_pnalloc(r->pool, len); |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
478 if (p == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
479 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
480 croak("ngx_pnalloc() failed"); |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
481 } |
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 data = p; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
484 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
485 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
486 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
487 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
488 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
|
489 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
490 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
491 done: |
631 | 492 |
493 if (len == 0) { | |
494 XSRETURN_UNDEF; | |
495 } | |
496 | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
497 ngx_http_perl_set_targ(data, len); |
631 | 498 |
633 | 499 ST(0) = TARG; |
631 | 500 |
501 | |
633 | 502 void |
503 request_body_file(r) | |
504 CODE: | |
505 | |
506 dXSTARG; | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
507 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
|
508 ngx_http_perl_ctx_t *ctx; |
633 | 509 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
510 ngx_http_perl_set_request(r, ctx); |
633 | 511 |
941 | 512 if (r->request_body == NULL || r->request_body->temp_file == NULL) { |
633 | 513 XSRETURN_UNDEF; |
514 } | |
515 | |
516 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
|
517 r->request_body->temp_file->file.name.len); |
599 | 518 |
633 | 519 ST(0) = TARG; |
520 | |
521 | |
522 void | |
1371 | 523 discard_request_body(r) |
524 CODE: | |
525 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
526 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
|
527 ngx_http_perl_ctx_t *ctx; |
7525 | 528 ngx_int_t rc; |
1371 | 529 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
530 ngx_http_perl_set_request(r, ctx); |
1371 | 531 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
532 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
533 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
|
534 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
535 |
7525 | 536 rc = ngx_http_discard_request_body(r); |
537 | |
538 if (rc != NGX_OK) { | |
539 ctx->error = 1; | |
540 ctx->status = rc; | |
541 croak("ngx_http_discard_request_body() failed"); | |
542 } | |
1371 | 543 |
544 | |
545 void | |
633 | 546 header_out(r, key, value) |
547 CODE: | |
599 | 548 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
549 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
|
550 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
|
551 SV *key; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
552 SV *value; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
553 ngx_table_elt_t *header; |
599 | 554 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
555 ngx_http_perl_set_request(r, ctx); |
633 | 556 |
7525 | 557 if (ctx->error) { |
558 croak("header_out(): called after error"); | |
559 } | |
560 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
561 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
562 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
|
563 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
564 |
633 | 565 key = ST(1); |
566 value = ST(2); | |
599 | 567 |
568 header = ngx_list_push(&r->headers_out.headers); | |
569 if (header == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
570 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
571 croak("ngx_list_push() failed"); |
599 | 572 } |
573 | |
574 header->hash = 1; | |
8031
d26db4f82d7d
All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8027
diff
changeset
|
575 header->next = NULL; |
599 | 576 |
577 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
|
578 header->hash = 0; |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
579 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
580 croak("ngx_http_perl_sv2str() failed"); |
599 | 581 } |
582 | |
583 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
|
584 header->hash = 0; |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
585 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
586 croak("ngx_http_perl_sv2str() failed"); |
599 | 587 } |
588 | |
589 if (header->key.len == sizeof("Content-Length") - 1 | |
3870 | 590 && 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
|
591 sizeof("Content-Length") - 1) == 0) |
599 | 592 { |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
593 r->headers_out.content_length_n = (off_t) SvIV(value); |
599 | 594 r->headers_out.content_length = header; |
595 } | |
596 | |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
597 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
|
598 && 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
|
599 sizeof("Content-Encoding") - 1) == 0) |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
600 { |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
601 r->headers_out.content_encoding = header; |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
602 } |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
603 |
599 | 604 |
633 | 605 void |
599 | 606 filename(r) |
633 | 607 CODE: |
599 | 608 |
633 | 609 dXSTARG; |
610 ngx_http_request_t *r; | |
599 | 611 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
|
612 size_t root; |
599 | 613 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
614 ngx_http_perl_set_request(r, ctx); |
599 | 615 |
633 | 616 if (ctx->filename.data) { |
599 | 617 goto done; |
618 } | |
619 | |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
620 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
|
621 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
622 croak("ngx_http_map_uri_to_path() failed"); |
599 | 623 } |
624 | |
633 | 625 ctx->filename.len--; |
626 sv_setpv(PL_statname, (char *) ctx->filename.data); | |
599 | 627 |
628 done: | |
629 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
630 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len); |
599 | 631 |
633 | 632 ST(0) = TARG; |
599 | 633 |
634 | |
633 | 635 void |
599 | 636 print(r, ...) |
637 CODE: | |
638 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
639 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
|
640 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
|
641 SV *sv; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
642 int i; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
643 u_char *p; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
644 size_t size; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
645 STRLEN len; |
7525 | 646 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
|
647 ngx_buf_t *b; |
633 | 648 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
649 ngx_http_perl_set_request(r, ctx); |
599 | 650 |
7525 | 651 if (ctx->error) { |
652 croak("print(): called after error"); | |
653 } | |
654 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
655 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
656 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
|
657 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
658 |
7531
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
659 if (!ctx->header_sent) { |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
660 croak("print(): header not sent"); |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
661 } |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
662 |
599 | 663 if (items == 2) { |
664 | |
665 /* | |
666 * do zero copy for prolate single read-only SV: | |
667 * $r->print("some text\n"); | |
668 */ | |
669 | |
670 sv = ST(1); | |
671 | |
672 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
673 sv = SvRV(sv); | |
674 } | |
675 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
676 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 677 |
678 p = (u_char *) SvPV(sv, len); | |
679 | |
680 if (len == 0) { | |
633 | 681 XSRETURN_EMPTY; |
599 | 682 } |
683 | |
684 b = ngx_calloc_buf(r->pool); | |
685 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
686 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
687 croak("ngx_calloc_buf() failed"); |
599 | 688 } |
689 | |
690 b->memory = 1; | |
691 b->pos = p; | |
692 b->last = p + len; | |
693 b->start = p; | |
694 b->end = b->last; | |
695 | |
601 | 696 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
697 "$r->print: read-only SV: %z", len); | |
698 | |
599 | 699 goto out; |
700 } | |
701 } | |
702 | |
703 size = 0; | |
704 | |
705 for (i = 1; i < items; i++) { | |
706 | |
707 sv = ST(i); | |
708 | |
709 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
710 sv = SvRV(sv); | |
711 } | |
712 | |
601 | 713 (void) SvPV(sv, len); |
599 | 714 |
601 | 715 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
716 "$r->print: copy SV: %z", len); | |
599 | 717 |
718 size += len; | |
719 } | |
720 | |
721 if (size == 0) { | |
633 | 722 XSRETURN_EMPTY; |
599 | 723 } |
724 | |
725 b = ngx_create_temp_buf(r->pool, size); | |
726 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
727 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
728 croak("ngx_create_temp_buf() failed"); |
599 | 729 } |
730 | |
731 for (i = 1; i < items; i++) { | |
732 sv = ST(i); | |
733 | |
734 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
735 sv = SvRV(sv); | |
736 } | |
737 | |
738 p = (u_char *) SvPV(sv, len); | |
739 b->last = ngx_cpymem(b->last, p, len); | |
740 } | |
741 | |
742 out: | |
743 | |
7525 | 744 rc = ngx_http_perl_output(r, ctx, b); |
745 | |
746 if (rc == NGX_ERROR) { | |
747 ctx->error = 1; | |
748 croak("ngx_http_perl_output() failed"); | |
749 } | |
599 | 750 |
751 | |
633 | 752 void |
613 | 753 sendfile(r, filename, offset = -1, bytes = 0) |
633 | 754 CODE: |
755 | |
1454 | 756 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
|
757 ngx_http_perl_ctx_t *ctx; |
1454 | 758 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
|
759 off_t offset; |
1454 | 760 size_t bytes; |
7525 | 761 ngx_int_t rc; |
1454 | 762 ngx_str_t path; |
763 ngx_buf_t *b; | |
764 ngx_open_file_info_t of; | |
765 ngx_http_core_loc_conf_t *clcf; | |
599 | 766 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
767 ngx_http_perl_set_request(r, ctx); |
633 | 768 |
7525 | 769 if (ctx->error) { |
770 croak("sendfile(): called after error"); | |
771 } | |
772 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
773 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
774 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
|
775 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
776 |
7531
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
777 if (!ctx->header_sent) { |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
778 croak("sendfile(): header not sent"); |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
779 } |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
780 |
633 | 781 filename = SvPV_nolen(ST(1)); |
599 | 782 |
783 if (filename == NULL) { | |
784 croak("sendfile(): NULL filename"); | |
785 } | |
786 | |
633 | 787 offset = items < 3 ? -1 : SvIV(ST(2)); |
788 bytes = items < 4 ? 0 : SvIV(ST(3)); | |
789 | |
599 | 790 b = ngx_calloc_buf(r->pool); |
791 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
792 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
793 croak("ngx_calloc_buf() failed"); |
599 | 794 } |
795 | |
796 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | |
797 if (b->file == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
798 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
799 croak("ngx_pcalloc() failed"); |
599 | 800 } |
801 | |
1454 | 802 path.len = ngx_strlen(filename); |
803 | |
2061
b0a1c84725cf
change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
804 path.data = ngx_pnalloc(r->pool, path.len + 1); |
1454 | 805 if (path.data == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
806 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
807 croak("ngx_pnalloc() failed"); |
599 | 808 } |
809 | |
3870 | 810 (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
|
811 |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
812 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
|
813 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
814 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
|
815 |
3178 | 816 of.read_ahead = clcf->read_ahead; |
2129 | 817 of.directio = clcf->directio; |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
818 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
|
819 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
|
820 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
|
821 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
|
822 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
823 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
|
824 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
825 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
|
826 } |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
827 |
1799 | 828 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
829 != NGX_OK) | |
830 { | |
1454 | 831 if (of.err == 0) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
832 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
833 croak("ngx_open_cached_file() failed"); |
1454 | 834 } |
835 | |
599 | 836 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
|
837 "%s \"%s\" failed", of.failed, filename); |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
838 |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
839 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
840 croak("ngx_open_cached_file() failed"); |
599 | 841 } |
842 | |
613 | 843 if (offset == -1) { |
844 offset = 0; | |
845 } | |
846 | |
847 if (bytes == 0) { | |
1454 | 848 bytes = of.size - offset; |
599 | 849 } |
850 | |
851 b->in_file = 1; | |
613 | 852 |
853 b->file_pos = offset; | |
854 b->file_last = offset + bytes; | |
599 | 855 |
1454 | 856 b->file->fd = of.fd; |
599 | 857 b->file->log = r->connection->log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
858 b->file->directio = of.is_directio; |
599 | 859 |
7525 | 860 rc = ngx_http_perl_output(r, ctx, b); |
861 | |
862 if (rc == NGX_ERROR) { | |
863 ctx->error = 1; | |
864 croak("ngx_http_perl_output() failed"); | |
865 } | |
599 | 866 |
867 | |
633 | 868 void |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
869 flush(r) |
633 | 870 CODE: |
599 | 871 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
872 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
|
873 ngx_http_perl_ctx_t *ctx; |
7525 | 874 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
|
875 ngx_buf_t *b; |
599 | 876 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
877 ngx_http_perl_set_request(r, ctx); |
599 | 878 |
7525 | 879 if (ctx->error) { |
880 croak("flush(): called after error"); | |
881 } | |
882 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
883 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
884 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
|
885 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
886 |
7531
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
887 if (!ctx->header_sent) { |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
888 croak("flush(): header not sent"); |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
889 } |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
890 |
599 | 891 b = ngx_calloc_buf(r->pool); |
892 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
893 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
894 croak("ngx_calloc_buf() failed"); |
599 | 895 } |
896 | |
897 b->flush = 1; | |
898 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
899 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush"); |
601 | 900 |
7525 | 901 rc = ngx_http_perl_output(r, ctx, b); |
902 | |
903 if (rc == NGX_ERROR) { | |
904 ctx->error = 1; | |
905 croak("ngx_http_perl_output() failed"); | |
906 } | |
599 | 907 |
633 | 908 XSRETURN_EMPTY; |
599 | 909 |
910 | |
911 void | |
912 internal_redirect(r, uri) | |
633 | 913 CODE: |
599 | 914 |
633 | 915 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
|
916 ngx_http_perl_ctx_t *ctx; |
633 | 917 SV *uri; |
599 | 918 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
919 ngx_http_perl_set_request(r, ctx); |
633 | 920 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
921 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
922 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
|
923 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
924 |
7531
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
925 if (ctx->header_sent) { |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
926 croak("internal_redirect(): header already sent"); |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
927 } |
ede052c67512
Perl: additional ctx->header_sent checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7530
diff
changeset
|
928 |
633 | 929 uri = ST(1); |
599 | 930 |
931 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
|
932 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
933 croak("ngx_http_perl_sv2str() failed"); |
599 | 934 } |
935 | |
601 | 936 |
633 | 937 void |
811 | 938 allow_ranges(r) |
939 CODE: | |
940 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
941 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
|
942 ngx_http_perl_ctx_t *ctx; |
811 | 943 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
944 ngx_http_perl_set_request(r, ctx); |
811 | 945 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
946 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
947 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
|
948 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
949 |
811 | 950 r->allow_ranges = 1; |
951 | |
952 | |
953 void | |
601 | 954 unescape(r, text, type = 0) |
955 CODE: | |
956 | |
633 | 957 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
958 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
|
959 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
|
960 SV *text; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
961 int type; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
962 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
|
963 STRLEN len; |
601 | 964 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
965 ngx_http_perl_set_request(r, ctx); |
633 | 966 |
967 text = ST(1); | |
968 | |
969 src = (u_char *) SvPV(text, len); | |
970 | |
2049 | 971 p = ngx_pnalloc(r->pool, len + 1); |
601 | 972 if (p == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
973 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
974 croak("ngx_pnalloc() failed"); |
601 | 975 } |
976 | |
977 dst = p; | |
978 | |
633 | 979 type = items < 3 ? 0 : SvIV(ST(2)); |
980 | |
981 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); | |
601 | 982 *dst = '\0'; |
983 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
984 ngx_http_perl_set_targ(p, dst - p); |
601 | 985 |
633 | 986 ST(0) = TARG; |
833 | 987 |
988 | |
989 void | |
990 variable(r, name, value = NULL) | |
991 CODE: | |
992 | |
993 dXSTARG; | |
994 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
|
995 ngx_http_perl_ctx_t *ctx; |
833 | 996 SV *name, *value; |
997 u_char *p, *lowcase; | |
998 STRLEN len; | |
999 ngx_str_t var, val; | |
1000 ngx_uint_t i, hash; | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1001 ngx_http_perl_var_t *v; |
833 | 1002 ngx_http_variable_value_t *vv; |
1003 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1004 ngx_http_perl_set_request(r, ctx); |
833 | 1005 |
1006 name = ST(1); | |
1007 | |
1008 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
1009 name = SvRV(name); | |
1010 } | |
1011 | |
1012 if (items == 2) { | |
1013 value = NULL; | |
1014 | |
1015 } else { | |
1016 value = ST(2); | |
1017 | |
1018 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
1019 value = SvRV(value); | |
1020 } | |
1021 | |
1022 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
|
1023 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1024 croak("ngx_http_perl_sv2str() failed"); |
833 | 1025 } |
1026 } | |
1027 | |
1028 p = (u_char *) SvPV(name, len); | |
1029 | |
2049 | 1030 lowcase = ngx_pnalloc(r->pool, len); |
833 | 1031 if (lowcase == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1032 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1033 croak("ngx_pnalloc() failed"); |
833 | 1034 } |
1035 | |
2136 | 1036 hash = ngx_hash_strlow(lowcase, p, len); |
833 | 1037 |
1038 var.len = len; | |
1039 var.data = lowcase; | |
5306
43900b822890
Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5248
diff
changeset
|
1040 #if (NGX_DEBUG) |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1041 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1042 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1043 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
|
1044 "perl variable: \"%V\"=\"%V\"", &var, &val); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1045 } else { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1046 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
|
1047 "perl variable: \"%V\"", &var); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1048 } |
5306
43900b822890
Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5248
diff
changeset
|
1049 #endif |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1050 |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3447
diff
changeset
|
1051 vv = ngx_http_get_variable(r, &var, hash); |
833 | 1052 if (vv == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1053 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1054 croak("ngx_http_get_variable() failed"); |
833 | 1055 } |
1056 | |
1057 if (vv->not_found) { | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1058 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1059 if (ctx->variables) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1060 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1061 v = ctx->variables->elts; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1062 for (i = 0; i < ctx->variables->nelts; i++) { |
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 if (hash != v[i].hash |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1065 || len != v[i].name.len |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1066 || 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
|
1067 { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1068 continue; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1069 } |
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 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1072 v[i].value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1073 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1074 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1075 |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
1076 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
|
1077 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1078 goto done; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1079 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1080 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1081 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1082 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1083 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1084 ctx->variables = ngx_array_create(r->pool, 1, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1085 sizeof(ngx_http_perl_var_t)); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1086 if (ctx->variables == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1087 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1088 croak("ngx_array_create() failed"); |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1089 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1090 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1091 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1092 v = ngx_array_push(ctx->variables); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1093 if (v == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1094 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1095 croak("ngx_array_push() failed"); |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1096 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1097 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1098 v->hash = hash; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1099 v->name.len = len; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1100 v->name.data = lowcase; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1101 v->value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1102 |
833 | 1103 XSRETURN_UNDEF; |
1104 } | |
1105 | |
1106 XSRETURN_UNDEF; | |
1107 } | |
1108 | |
1109 if (value) { | |
1110 vv->len = val.len; | |
1111 vv->valid = 1; | |
1565 | 1112 vv->no_cacheable = 0; |
833 | 1113 vv->not_found = 0; |
1114 vv->data = val.data; | |
1115 | |
1116 XSRETURN_UNDEF; | |
1117 } | |
1118 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
1119 ngx_http_perl_set_targ(vv->data, vv->len); |
833 | 1120 |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1121 done: |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1122 |
833 | 1123 ST(0) = TARG; |
907 | 1124 |
1125 | |
1126 void | |
911 | 1127 sleep(r, sleep, next) |
1128 CODE: | |
1129 | |
1130 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
|
1131 ngx_http_perl_ctx_t *ctx; |
1897 | 1132 ngx_msec_t sleep; |
911 | 1133 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1134 ngx_http_perl_set_request(r, ctx); |
911 | 1135 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1136 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1137 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
|
1138 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1139 |
7527
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1140 if (ctx->next) { |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1141 croak("sleep(): another handler active"); |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1142 } |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1143 |
1898 | 1144 sleep = (ngx_msec_t) SvIV(ST(1)); |
1897 | 1145 |
1146 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1147 "perl sleep: %M", sleep); | |
1148 | |
911 | 1149 ctx->next = SvRV(ST(2)); |
1150 | |
6960
1c5e5e5b008d
Perl: fixed delaying subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6233
diff
changeset
|
1151 r->connection->write->delayed = 1; |
1897 | 1152 ngx_add_timer(r->connection->write, sleep); |
1153 | |
1154 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
|
1155 r->main->count++; |
911 | 1156 |
1157 | |
1158 void | |
907 | 1159 log_error(r, err, msg) |
1160 CODE: | |
1161 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1162 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
|
1163 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
|
1164 SV *err, *msg; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1165 u_char *p; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1166 STRLEN len; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1167 ngx_err_t e; |
907 | 1168 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1169 ngx_http_perl_set_request(r, ctx); |
907 | 1170 |
1171 err = ST(1); | |
1172 | |
1173 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) { | |
1174 err = SvRV(err); | |
1175 } | |
1176 | |
1177 e = SvIV(err); | |
1178 | |
1179 msg = ST(2); | |
1180 | |
1181 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) { | |
1182 msg = SvRV(msg); | |
1183 } | |
1184 | |
1185 p = (u_char *) SvPV(msg, len); | |
1186 | |
910 | 1187 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p); |