Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_ssi_filter_module.c @ 5580:06c227e9edd0
Access: supplemented the obfuscated code with a comment.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 19 Feb 2014 21:45:27 +0400 |
parents | 3a8e19528b30 |
children | e491b26fa5a1 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
6 |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
11 |
553 | 12 #define NGX_HTTP_SSI_ERROR 1 |
13 | |
14 #define NGX_HTTP_SSI_DATE_LEN 2048 | |
15 | |
16 #define NGX_HTTP_SSI_ADD_PREFIX 1 | |
629 | 17 #define NGX_HTTP_SSI_ADD_ZERO 2 |
509 | 18 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
19 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
20 typedef struct { |
597 | 21 ngx_flag_t enable; |
22 ngx_flag_t silent_errors; | |
23 ngx_flag_t ignore_recycled_buffers; | |
5228
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
24 ngx_flag_t last_modified; |
597 | 25 |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
26 ngx_hash_t types; |
597 | 27 |
28 size_t min_file_chunk; | |
29 size_t value_len; | |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
30 |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
31 ngx_array_t *types_keys; |
597 | 32 } ngx_http_ssi_loc_conf_t; |
553 | 33 |
34 | |
35 typedef struct { | |
597 | 36 ngx_str_t name; |
611 | 37 ngx_uint_t key; |
597 | 38 ngx_str_t value; |
39 } ngx_http_ssi_var_t; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
40 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
41 |
667 | 42 typedef struct { |
43 ngx_str_t name; | |
44 ngx_chain_t *bufs; | |
45 ngx_uint_t count; | |
46 } ngx_http_ssi_block_t; | |
47 | |
48 | |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
49 typedef enum { |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
50 ssi_start_state = 0, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
51 ssi_tag_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
52 ssi_comment0_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
53 ssi_comment1_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
54 ssi_sharp_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
55 ssi_precommand_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
56 ssi_command_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
57 ssi_preparam_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
58 ssi_param_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
59 ssi_preequal_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
60 ssi_prevalue_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
61 ssi_double_quoted_value_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
62 ssi_quoted_value_state, |
497 | 63 ssi_quoted_symbol_state, |
64 ssi_postparam_state, | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
65 ssi_comment_end0_state, |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
66 ssi_comment_end1_state, |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
67 ssi_error_state, |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
68 ssi_error_end0_state, |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
69 ssi_error_end1_state |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
70 } ngx_http_ssi_state_e; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
509 | 73 static ngx_int_t ngx_http_ssi_output(ngx_http_request_t *r, |
74 ngx_http_ssi_ctx_t *ctx); | |
3680
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
75 static void ngx_http_ssi_buffered(ngx_http_request_t *r, |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
76 ngx_http_ssi_ctx_t *ctx); |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
77 static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, |
497 | 78 ngx_http_ssi_ctx_t *ctx); |
553 | 79 static ngx_str_t *ngx_http_ssi_get_variable(ngx_http_request_t *r, |
611 | 80 ngx_str_t *name, ngx_uint_t key); |
553 | 81 static ngx_int_t ngx_http_ssi_evaluate_string(ngx_http_request_t *r, |
82 ngx_http_ssi_ctx_t *ctx, ngx_str_t *text, ngx_uint_t flags); | |
4381
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
83 static ngx_int_t ngx_http_ssi_regex_match(ngx_http_request_t *r, |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
84 ngx_str_t *pattern, ngx_str_t *str); |
553 | 85 |
86 static ngx_int_t ngx_http_ssi_include(ngx_http_request_t *r, | |
87 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
88 static ngx_int_t ngx_http_ssi_stub_output(ngx_http_request_t *r, void *data, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
89 ngx_int_t rc); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
90 static ngx_int_t ngx_http_ssi_set_variable(ngx_http_request_t *r, void *data, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
91 ngx_int_t rc); |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
92 static ngx_int_t ngx_http_ssi_echo(ngx_http_request_t *r, |
497 | 93 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
509 | 94 static ngx_int_t ngx_http_ssi_config(ngx_http_request_t *r, |
95 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
553 | 96 static ngx_int_t ngx_http_ssi_set(ngx_http_request_t *r, |
509 | 97 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
98 static ngx_int_t ngx_http_ssi_if(ngx_http_request_t *r, | |
99 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
100 static ngx_int_t ngx_http_ssi_else(ngx_http_request_t *r, | |
101 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
102 static ngx_int_t ngx_http_ssi_endif(ngx_http_request_t *r, | |
103 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
667 | 104 static ngx_int_t ngx_http_ssi_block(ngx_http_request_t *r, |
105 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
106 static ngx_int_t ngx_http_ssi_endblock(ngx_http_request_t *r, | |
107 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
108 |
573 | 109 static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, |
2041 | 110 ngx_http_variable_value_t *v, uintptr_t gmt); |
509 | 111 |
597 | 112 static ngx_int_t ngx_http_ssi_preconfiguration(ngx_conf_t *cf); |
113 static void *ngx_http_ssi_create_main_conf(ngx_conf_t *cf); | |
114 static char *ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf); | |
1169 | 115 static void *ngx_http_ssi_create_loc_conf(ngx_conf_t *cf); |
116 static char *ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, | |
497 | 117 void *parent, void *child); |
681 | 118 static ngx_int_t ngx_http_ssi_filter_init(ngx_conf_t *cf); |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
119 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
120 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
121 static ngx_command_t ngx_http_ssi_filter_commands[] = { |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
122 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
123 { ngx_string("ssi"), |
681 | 124 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
125 |NGX_CONF_FLAG, | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
126 ngx_conf_set_flag_slot, |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
127 NGX_HTTP_LOC_CONF_OFFSET, |
597 | 128 offsetof(ngx_http_ssi_loc_conf_t, enable), |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
129 NULL }, |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
130 |
497 | 131 { ngx_string("ssi_silent_errors"), |
132 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
133 ngx_conf_set_flag_slot, | |
134 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 135 offsetof(ngx_http_ssi_loc_conf_t, silent_errors), |
497 | 136 NULL }, |
137 | |
509 | 138 { ngx_string("ssi_ignore_recycled_buffers"), |
139 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
140 ngx_conf_set_flag_slot, | |
141 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 142 offsetof(ngx_http_ssi_loc_conf_t, ignore_recycled_buffers), |
509 | 143 NULL }, |
144 | |
497 | 145 { ngx_string("ssi_min_file_chunk"), |
4273
e444e8f6538b
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse.
Sergey Budnevitch <sb@waeme.net>
parents:
3887
diff
changeset
|
146 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
497 | 147 ngx_conf_set_size_slot, |
148 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 149 offsetof(ngx_http_ssi_loc_conf_t, min_file_chunk), |
497 | 150 NULL }, |
151 | |
589 | 152 { ngx_string("ssi_value_length"), |
4273
e444e8f6538b
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse.
Sergey Budnevitch <sb@waeme.net>
parents:
3887
diff
changeset
|
153 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
589 | 154 ngx_conf_set_size_slot, |
155 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 156 offsetof(ngx_http_ssi_loc_conf_t, value_len), |
589 | 157 NULL }, |
158 | |
527 | 159 { ngx_string("ssi_types"), |
160 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
161 ngx_http_types_slot, |
527 | 162 NGX_HTTP_LOC_CONF_OFFSET, |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
163 offsetof(ngx_http_ssi_loc_conf_t, types_keys), |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
164 &ngx_http_html_default_types[0] }, |
527 | 165 |
5228
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
166 { ngx_string("ssi_last_modified"), |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
167 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
168 ngx_conf_set_flag_slot, |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
169 NGX_HTTP_LOC_CONF_OFFSET, |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
170 offsetof(ngx_http_ssi_loc_conf_t, last_modified), |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
171 NULL }, |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
172 |
497 | 173 ngx_null_command |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
174 }; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
175 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
176 |
577 | 177 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
178 static ngx_http_module_t ngx_http_ssi_filter_module_ctx = { |
597 | 179 ngx_http_ssi_preconfiguration, /* preconfiguration */ |
681 | 180 ngx_http_ssi_filter_init, /* postconfiguration */ |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
181 |
597 | 182 ngx_http_ssi_create_main_conf, /* create main configuration */ |
183 ngx_http_ssi_init_main_conf, /* init main configuration */ | |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
185 NULL, /* create server configuration */ |
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
186 NULL, /* merge server configuration */ |
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
187 |
1169 | 188 ngx_http_ssi_create_loc_conf, /* create location configuration */ |
189 ngx_http_ssi_merge_loc_conf /* merge location configuration */ | |
577 | 190 }; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
193 ngx_module_t ngx_http_ssi_filter_module = { |
509 | 194 NGX_MODULE_V1, |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
195 &ngx_http_ssi_filter_module_ctx, /* module context */ |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
196 ngx_http_ssi_filter_commands, /* module directives */ |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
197 NGX_HTTP_MODULE, /* module type */ |
541 | 198 NULL, /* init master */ |
681 | 199 NULL, /* init module */ |
541 | 200 NULL, /* init process */ |
201 NULL, /* init thread */ | |
202 NULL, /* exit thread */ | |
203 NULL, /* exit process */ | |
204 NULL, /* exit master */ | |
205 NGX_MODULE_V1_PADDING | |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 }; |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 |
569 | 209 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
210 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
497 | 211 |
212 | |
213 static u_char ngx_http_ssi_string[] = "<!--"; | |
214 | |
215 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); | |
5540
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
216 static ngx_str_t ngx_http_ssi_timefmt = ngx_string("%A, %d-%b-%Y %H:%M:%S %Z"); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
217 static ngx_str_t ngx_http_ssi_null_string = ngx_null_string; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
218 |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
219 |
553 | 220 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 |
221 #define NGX_HTTP_SSI_INCLUDE_FILE 1 | |
645 | 222 #define NGX_HTTP_SSI_INCLUDE_WAIT 2 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
223 #define NGX_HTTP_SSI_INCLUDE_SET 3 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
224 #define NGX_HTTP_SSI_INCLUDE_STUB 4 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
225 |
509 | 226 #define NGX_HTTP_SSI_ECHO_VAR 0 |
227 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 | |
1545 | 228 #define NGX_HTTP_SSI_ECHO_ENCODING 2 |
509 | 229 |
547 | 230 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 |
231 #define NGX_HTTP_SSI_CONFIG_TIMEFMT 1 | |
509 | 232 |
553 | 233 #define NGX_HTTP_SSI_SET_VAR 0 |
234 #define NGX_HTTP_SSI_SET_VALUE 1 | |
509 | 235 |
236 #define NGX_HTTP_SSI_IF_EXPR 0 | |
237 | |
667 | 238 #define NGX_HTTP_SSI_BLOCK_NAME 0 |
239 | |
497 | 240 |
553 | 241 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = { |
597 | 242 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 }, |
243 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 }, | |
645 | 244 { ngx_string("wait"), NGX_HTTP_SSI_INCLUDE_WAIT, 0, 0 }, |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
245 { ngx_string("set"), NGX_HTTP_SSI_INCLUDE_SET, 0, 0 }, |
667 | 246 { ngx_string("stub"), NGX_HTTP_SSI_INCLUDE_STUB, 0, 0 }, |
597 | 247 { ngx_null_string, 0, 0, 0 } |
553 | 248 }; |
249 | |
250 | |
497 | 251 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = { |
597 | 252 { ngx_string("var"), NGX_HTTP_SSI_ECHO_VAR, 1, 0 }, |
253 { ngx_string("default"), NGX_HTTP_SSI_ECHO_DEFAULT, 0, 0 }, | |
1545 | 254 { ngx_string("encoding"), NGX_HTTP_SSI_ECHO_ENCODING, 0, 0 }, |
597 | 255 { ngx_null_string, 0, 0, 0 } |
497 | 256 }; |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
257 |
509 | 258 |
259 static ngx_http_ssi_param_t ngx_http_ssi_config_params[] = { | |
597 | 260 { ngx_string("errmsg"), NGX_HTTP_SSI_CONFIG_ERRMSG, 0, 0 }, |
261 { ngx_string("timefmt"), NGX_HTTP_SSI_CONFIG_TIMEFMT, 0, 0 }, | |
262 { ngx_null_string, 0, 0, 0 } | |
509 | 263 }; |
264 | |
265 | |
553 | 266 static ngx_http_ssi_param_t ngx_http_ssi_set_params[] = { |
597 | 267 { ngx_string("var"), NGX_HTTP_SSI_SET_VAR, 1, 0 }, |
268 { ngx_string("value"), NGX_HTTP_SSI_SET_VALUE, 1, 0 }, | |
269 { ngx_null_string, 0, 0, 0 } | |
553 | 270 }; |
271 | |
272 | |
509 | 273 static ngx_http_ssi_param_t ngx_http_ssi_if_params[] = { |
597 | 274 { ngx_string("expr"), NGX_HTTP_SSI_IF_EXPR, 1, 0 }, |
275 { ngx_null_string, 0, 0, 0 } | |
509 | 276 }; |
277 | |
278 | |
667 | 279 static ngx_http_ssi_param_t ngx_http_ssi_block_params[] = { |
280 { ngx_string("name"), NGX_HTTP_SSI_BLOCK_NAME, 1, 0 }, | |
281 { ngx_null_string, 0, 0, 0 } | |
282 }; | |
283 | |
284 | |
509 | 285 static ngx_http_ssi_param_t ngx_http_ssi_no_params[] = { |
597 | 286 { ngx_null_string, 0, 0, 0 } |
509 | 287 }; |
288 | |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
289 |
497 | 290 static ngx_http_ssi_command_t ngx_http_ssi_commands[] = { |
553 | 291 { ngx_string("include"), ngx_http_ssi_include, |
667 | 292 ngx_http_ssi_include_params, 0, 0, 1 }, |
293 { ngx_string("echo"), ngx_http_ssi_echo, | |
294 ngx_http_ssi_echo_params, 0, 0, 0 }, | |
509 | 295 { ngx_string("config"), ngx_http_ssi_config, |
667 | 296 ngx_http_ssi_config_params, 0, 0, 0 }, |
297 { ngx_string("set"), ngx_http_ssi_set, ngx_http_ssi_set_params, 0, 0, 0 }, | |
298 | |
299 { ngx_string("if"), ngx_http_ssi_if, ngx_http_ssi_if_params, 0, 0, 0 }, | |
629 | 300 { ngx_string("elif"), ngx_http_ssi_if, ngx_http_ssi_if_params, |
667 | 301 NGX_HTTP_SSI_COND_IF, 0, 0 }, |
629 | 302 { ngx_string("else"), ngx_http_ssi_else, ngx_http_ssi_no_params, |
667 | 303 NGX_HTTP_SSI_COND_IF, 0, 0 }, |
629 | 304 { ngx_string("endif"), ngx_http_ssi_endif, ngx_http_ssi_no_params, |
667 | 305 NGX_HTTP_SSI_COND_ELSE, 0, 0 }, |
306 | |
307 { ngx_string("block"), ngx_http_ssi_block, | |
308 ngx_http_ssi_block_params, 0, 0, 0 }, | |
309 { ngx_string("endblock"), ngx_http_ssi_endblock, | |
310 ngx_http_ssi_no_params, 0, 1, 0 }, | |
311 | |
312 { ngx_null_string, NULL, NULL, 0, 0, 0 } | |
497 | 313 }; |
314 | |
315 | |
509 | 316 static ngx_http_variable_t ngx_http_ssi_vars[] = { |
317 | |
637 | 318 { ngx_string("date_local"), NULL, ngx_http_ssi_date_gmt_local_variable, 0, |
1565 | 319 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 320 |
637 | 321 { ngx_string("date_gmt"), NULL, ngx_http_ssi_date_gmt_local_variable, 1, |
1565 | 322 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 323 |
637 | 324 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
509 | 325 }; |
326 | |
327 | |
328 | |
497 | 329 static ngx_int_t |
330 ngx_http_ssi_header_filter(ngx_http_request_t *r) | |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
331 { |
597 | 332 ngx_http_ssi_ctx_t *ctx; |
333 ngx_http_ssi_loc_conf_t *slcf; | |
334 | |
335 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module); | |
336 | |
337 if (!slcf->enable | |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
338 || r->headers_out.content_length_n == 0 |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
339 || ngx_http_test_content_type(r, &slcf->types) == NULL) |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
340 { |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
341 return ngx_http_next_header_filter(r); |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
342 } |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
343 |
499 | 344 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t)); |
345 if (ctx == NULL) { | |
497 | 346 return NGX_ERROR; |
347 } | |
348 | |
349 ngx_http_set_ctx(r, ctx, ngx_http_ssi_filter_module); | |
350 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
351 |
597 | 352 ctx->value_len = slcf->value_len; |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
353 ctx->last_out = &ctx->out; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
354 |
1545 | 355 ctx->encoding = NGX_HTTP_SSI_ENTITY_ENCODING; |
509 | 356 ctx->output = 1; |
357 | |
497 | 358 ctx->params.elts = ctx->params_array; |
359 ctx->params.size = sizeof(ngx_table_elt_t); | |
360 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N; | |
361 ctx->params.pool = r->pool; | |
362 | |
5540
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
363 ctx->timefmt = ngx_http_ssi_timefmt; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
364 ngx_str_set(&ctx->errmsg, |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
365 "[an error occurred while processing the directive]"); |
547 | 366 |
497 | 367 r->filter_need_in_memory = 1; |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
368 |
597 | 369 if (r == r->main) { |
577 | 370 ngx_http_clear_content_length(r); |
3005
5bc8811728f8
clear "Accept-Ranges" for SSI responses
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
371 ngx_http_clear_accept_ranges(r); |
4746
4a18bf1833a9
Entity tags: clear on entity changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
372 ngx_http_clear_etag(r); |
5228
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
373 |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
374 if (!slcf->last_modified) { |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
375 ngx_http_clear_last_modified(r); |
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
376 } |
509 | 377 } |
378 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
379 return ngx_http_next_header_filter(r); |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
380 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
381 |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
382 |
497 | 383 static ngx_int_t |
384 ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
15
cbb38b60495c
nginx-0.0.1-2002-09-18-20:32:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
14
diff
changeset
|
385 { |
667 | 386 size_t len; |
597 | 387 ngx_int_t rc; |
388 ngx_buf_t *b; | |
389 ngx_uint_t i, index; | |
667 | 390 ngx_chain_t *cl, **ll; |
597 | 391 ngx_table_elt_t *param; |
667 | 392 ngx_http_ssi_ctx_t *ctx, *mctx; |
393 ngx_http_ssi_block_t *bl; | |
597 | 394 ngx_http_ssi_param_t *prm; |
395 ngx_http_ssi_command_t *cmd; | |
396 ngx_http_ssi_loc_conf_t *slcf; | |
397 ngx_http_ssi_main_conf_t *smcf; | |
599 | 398 ngx_str_t *params[NGX_HTTP_SSI_MAX_PARAMS + 1]; |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
399 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
400 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
401 |
645 | 402 if (ctx == NULL |
403 || (in == NULL | |
404 && ctx->buf == NULL | |
405 && ctx->in == NULL | |
406 && ctx->busy == NULL)) | |
407 { | |
243
bf2faf694c19
nginx-0.0.1-2004-01-28-23:38:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
408 return ngx_http_next_body_filter(r, in); |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
409 } |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
410 |
497 | 411 /* add the incoming chain to the chain ctx->in */ |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
412 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
413 if (in) { |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2426
diff
changeset
|
414 if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) { |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
415 return NGX_ERROR; |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
416 } |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
417 } |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
418 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
419 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
420 "http ssi filter \"%V?%V\"", &r->uri, &r->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
421 |
645 | 422 if (ctx->wait) { |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
423 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
424 if (r != r->connection->data) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
425 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
426 "http ssi filter wait \"%V?%V\" non-active", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
427 &ctx->wait->uri, &ctx->wait->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
428 |
645 | 429 return NGX_AGAIN; |
430 } | |
431 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
432 if (ctx->wait->done) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
433 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
434 "http ssi filter wait \"%V?%V\" done", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
435 &ctx->wait->uri, &ctx->wait->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
436 |
767
cad7543dc419
fix <!--#include virtual=... wait="yes" -->
Igor Sysoev <igor@sysoev.ru>
parents:
765
diff
changeset
|
437 ctx->wait = NULL; |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
438 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
439 } else { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
440 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
441 "http ssi filter wait \"%V?%V\"", |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
442 &ctx->wait->uri, &ctx->wait->args); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
443 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
444 return ngx_http_next_body_filter(r, NULL); |
767
cad7543dc419
fix <!--#include virtual=... wait="yes" -->
Igor Sysoev <igor@sysoev.ru>
parents:
765
diff
changeset
|
445 } |
645 | 446 } |
447 | |
597 | 448 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module); |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
449 |
499 | 450 while (ctx->in || ctx->buf) { |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
451 |
3642 | 452 if (ctx->buf == NULL) { |
499 | 453 ctx->buf = ctx->in->buf; |
454 ctx->in = ctx->in->next; | |
455 ctx->pos = ctx->buf->pos; | |
456 } | |
497 | 457 |
458 if (ctx->state == ssi_start_state) { | |
459 ctx->copy_start = ctx->pos; | |
460 ctx->copy_end = ctx->pos; | |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
461 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
462 |
499 | 463 b = NULL; |
464 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
465 while (ctx->pos < ctx->buf->last) { |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
466 |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
467 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
468 "saved: %d state: %d", ctx->saved, ctx->state); |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
469 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
470 rc = ngx_http_ssi_parse(r, ctx); |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
471 |
497 | 472 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
473 "parse: %d, looked: %d %p-%p", | |
474 rc, ctx->looked, ctx->copy_start, ctx->copy_end); | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
475 |
497 | 476 if (rc == NGX_ERROR) { |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
477 return rc; |
497 | 478 } |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
479 |
497 | 480 if (ctx->copy_start != ctx->copy_end) { |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
481 |
509 | 482 if (ctx->output) { |
483 | |
484 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
485 "saved: %d", ctx->saved); | |
486 | |
487 if (ctx->saved) { | |
488 | |
489 if (ctx->free) { | |
490 cl = ctx->free; | |
491 ctx->free = ctx->free->next; | |
492 b = cl->buf; | |
493 ngx_memzero(b, sizeof(ngx_buf_t)); | |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
494 |
509 | 495 } else { |
496 b = ngx_calloc_buf(r->pool); | |
497 if (b == NULL) { | |
498 return NGX_ERROR; | |
499 } | |
500 | |
501 cl = ngx_alloc_chain_link(r->pool); | |
502 if (cl == NULL) { | |
503 return NGX_ERROR; | |
504 } | |
505 | |
506 cl->buf = b; | |
507 } | |
508 | |
509 b->memory = 1; | |
510 b->pos = ngx_http_ssi_string; | |
511 b->last = ngx_http_ssi_string + ctx->saved; | |
512 | |
513 *ctx->last_out = cl; | |
514 ctx->last_out = &cl->next; | |
515 | |
516 ctx->saved = 0; | |
517 } | |
499 | 518 |
519 if (ctx->free) { | |
520 cl = ctx->free; | |
521 ctx->free = ctx->free->next; | |
522 b = cl->buf; | |
523 | |
524 } else { | |
509 | 525 b = ngx_alloc_buf(r->pool); |
499 | 526 if (b == NULL) { |
527 return NGX_ERROR; | |
528 } | |
529 | |
530 cl = ngx_alloc_chain_link(r->pool); | |
531 if (cl == NULL) { | |
532 return NGX_ERROR; | |
533 } | |
534 | |
535 cl->buf = b; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
536 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
537 |
509 | 538 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t)); |
539 | |
513 | 540 b->pos = ctx->copy_start; |
541 b->last = ctx->copy_end; | |
542 b->shadow = NULL; | |
509 | 543 b->last_buf = 0; |
544 b->recycled = 0; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
545 |
509 | 546 if (b->in_file) { |
597 | 547 if (slcf->min_file_chunk < (size_t) (b->last - b->pos)) |
509 | 548 { |
2079
333ef9e18a59
fix error when response parsed by sub filter, then by SSI filter
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
549 b->file_last = b->file_pos |
333ef9e18a59
fix error when response parsed by sub filter, then by SSI filter
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
550 + (b->last - ctx->buf->pos); |
333ef9e18a59
fix error when response parsed by sub filter, then by SSI filter
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
551 b->file_pos += b->pos - ctx->buf->pos; |
509 | 552 |
553 } else { | |
554 b->in_file = 0; | |
555 } | |
556 } | |
557 | |
558 cl->next = NULL; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
559 *ctx->last_out = cl; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
560 ctx->last_out = &cl->next; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
561 |
509 | 562 } else { |
667 | 563 if (ctx->block |
564 && ctx->saved + (ctx->copy_end - ctx->copy_start)) | |
565 { | |
566 b = ngx_create_temp_buf(r->pool, | |
567 ctx->saved + (ctx->copy_end - ctx->copy_start)); | |
568 | |
569 if (b == NULL) { | |
570 return NGX_ERROR; | |
571 } | |
572 | |
573 if (ctx->saved) { | |
574 b->last = ngx_cpymem(b->pos, ngx_http_ssi_string, | |
575 ctx->saved); | |
576 } | |
577 | |
578 b->last = ngx_cpymem(b->last, ctx->copy_start, | |
579 ctx->copy_end - ctx->copy_start); | |
580 | |
581 cl = ngx_alloc_chain_link(r->pool); | |
582 if (cl == NULL) { | |
583 return NGX_ERROR; | |
584 } | |
585 | |
586 cl->buf = b; | |
587 cl->next = NULL; | |
588 | |
589 b = NULL; | |
590 | |
591 mctx = ngx_http_get_module_ctx(r->main, | |
592 ngx_http_ssi_filter_module); | |
593 bl = mctx->blocks->elts; | |
594 for (ll = &bl[mctx->blocks->nelts - 1].bufs; | |
595 *ll; | |
596 ll = &(*ll)->next) | |
597 { | |
598 /* void */ | |
599 } | |
600 | |
601 *ll = cl; | |
602 } | |
603 | |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
604 ctx->saved = 0; |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
605 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
606 } |
497 | 607 |
608 if (ctx->state == ssi_start_state) { | |
609 ctx->copy_start = ctx->pos; | |
610 ctx->copy_end = ctx->pos; | |
240
725129fdd524
nginx-0.0.1-2004-01-26-20:22:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
239
diff
changeset
|
611 |
497 | 612 } else { |
613 ctx->copy_start = NULL; | |
614 ctx->copy_end = NULL; | |
615 } | |
616 | |
617 if (rc == NGX_AGAIN) { | |
618 continue; | |
619 } | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
620 |
497 | 621 |
573 | 622 b = NULL; |
623 | |
497 | 624 if (rc == NGX_OK) { |
625 | |
597 | 626 smcf = ngx_http_get_module_main_conf(r, |
627 ngx_http_ssi_filter_module); | |
628 | |
629 cmd = ngx_hash_find(&smcf->hash, ctx->key, ctx->command.data, | |
630 ctx->command.len); | |
631 | |
632 if (cmd == NULL) { | |
633 if (ctx->output) { | |
634 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
635 "invalid SSI command: \"%V\"", | |
636 &ctx->command); | |
637 goto ssi_error; | |
497 | 638 } |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
639 |
597 | 640 continue; |
497 | 641 } |
642 | |
667 | 643 if (!ctx->output && !cmd->block) { |
644 | |
645 if (ctx->block) { | |
646 | |
647 /* reconstruct the SSI command text */ | |
648 | |
649 len = 5 + ctx->command.len + 4; | |
650 | |
651 param = ctx->params.elts; | |
652 for (i = 0; i < ctx->params.nelts; i++) { | |
653 len += 1 + param[i].key.len + 2 | |
654 + param[i].value.len + 1; | |
655 } | |
656 | |
657 b = ngx_create_temp_buf(r->pool, len); | |
658 | |
659 if (b == NULL) { | |
660 return NGX_ERROR; | |
661 } | |
662 | |
663 cl = ngx_alloc_chain_link(r->pool); | |
664 if (cl == NULL) { | |
665 return NGX_ERROR; | |
666 } | |
667 | |
668 cl->buf = b; | |
669 cl->next = NULL; | |
670 | |
671 *b->last++ = '<'; | |
672 *b->last++ = '!'; | |
673 *b->last++ = '-'; | |
674 *b->last++ = '-'; | |
675 *b->last++ = '#'; | |
676 | |
677 b->last = ngx_cpymem(b->last, ctx->command.data, | |
678 ctx->command.len); | |
679 | |
680 for (i = 0; i < ctx->params.nelts; i++) { | |
681 *b->last++ = ' '; | |
682 b->last = ngx_cpymem(b->last, param[i].key.data, | |
683 param[i].key.len); | |
684 *b->last++ = '='; | |
685 *b->last++ = '"'; | |
686 b->last = ngx_cpymem(b->last, param[i].value.data, | |
687 param[i].value.len); | |
688 *b->last++ = '"'; | |
689 } | |
690 | |
691 *b->last++ = ' '; | |
692 *b->last++ = '-'; | |
693 *b->last++ = '-'; | |
694 *b->last++ = '>'; | |
695 | |
696 mctx = ngx_http_get_module_ctx(r->main, | |
697 ngx_http_ssi_filter_module); | |
698 bl = mctx->blocks->elts; | |
699 for (ll = &bl[mctx->blocks->nelts - 1].bufs; | |
700 *ll; | |
701 ll = &(*ll)->next) | |
702 { | |
703 /* void */ | |
704 } | |
705 | |
706 *ll = cl; | |
707 | |
708 b = NULL; | |
709 | |
710 continue; | |
711 } | |
712 | |
713 if (cmd->conditional == 0) { | |
714 continue; | |
715 } | |
509 | 716 } |
717 | |
4374
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
718 if (cmd->conditional |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
719 && (ctx->conditional == 0 |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
720 || ctx->conditional > cmd->conditional)) |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
721 { |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
722 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
723 "invalid context of SSI command: \"%V\"", |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
724 &ctx->command); |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
725 goto ssi_error; |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
726 } |
ae376a94de11
SSI bugfix: the "if" command did not work inside the "block" command and
Valentin Bartenev <vbart@nginx.com>
parents:
4273
diff
changeset
|
727 |
597 | 728 if (ctx->params.nelts > NGX_HTTP_SSI_MAX_PARAMS) { |
729 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
4567
1f0ecc900010
Corrected spelling of error message (ticket #136).
Ruslan Ermilov <ru@nginx.com>
parents:
4528
diff
changeset
|
730 "too many SSI command parameters: \"%V\"", |
597 | 731 &ctx->command); |
732 goto ssi_error; | |
733 } | |
734 | |
497 | 735 ngx_memzero(params, |
599 | 736 (NGX_HTTP_SSI_MAX_PARAMS + 1) * sizeof(ngx_str_t *)); |
497 | 737 |
738 param = ctx->params.elts; | |
739 | |
740 for (i = 0; i < ctx->params.nelts; i++) { | |
741 | |
742 for (prm = cmd->params; prm->name.len; prm++) { | |
743 | |
744 if (param[i].key.len != prm->name.len | |
745 || ngx_strncmp(param[i].key.data, prm->name.data, | |
746 prm->name.len) != 0) | |
747 { | |
748 continue; | |
749 } | |
750 | |
597 | 751 if (!prm->multiple) { |
752 if (params[prm->index]) { | |
753 ngx_log_error(NGX_LOG_ERR, | |
754 r->connection->log, 0, | |
755 "duplicate \"%V\" parameter " | |
756 "in \"%V\" SSI command", | |
757 ¶m[i].key, &ctx->command); | |
758 | |
759 goto ssi_error; | |
760 } | |
761 | |
762 params[prm->index] = ¶m[i].value; | |
763 | |
764 break; | |
497 | 765 } |
766 | |
597 | 767 for (index = prm->index; params[index]; index++) { |
768 /* void */ | |
769 } | |
770 | |
771 params[index] = ¶m[i].value; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
772 |
497 | 773 break; |
774 } | |
775 | |
776 if (prm->name.len == 0) { | |
777 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
778 "invalid parameter name: \"%V\" " | |
779 "in \"%V\" SSI command", | |
780 ¶m[i].key, &ctx->command); | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
781 |
497 | 782 goto ssi_error; |
783 } | |
784 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
785 |
497 | 786 for (prm = cmd->params; prm->name.len; prm++) { |
787 if (prm->mandatory && params[prm->index] == 0) { | |
788 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
789 "mandatory \"%V\" parameter is absent " | |
790 "in \"%V\" SSI command", | |
791 &prm->name, &ctx->command); | |
792 | |
793 goto ssi_error; | |
794 } | |
795 } | |
796 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
797 if (cmd->flush && ctx->out) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
798 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
799 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
800 "ssi flush"); |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
801 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
802 if (ngx_http_ssi_output(r, ctx) == NGX_ERROR) { |
509 | 803 return NGX_ERROR; |
804 } | |
805 } | |
806 | |
569 | 807 rc = cmd->handler(r, ctx, params); |
808 | |
809 if (rc == NGX_OK) { | |
497 | 810 continue; |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
811 } |
583 | 812 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
813 if (rc == NGX_DONE || rc == NGX_AGAIN || rc == NGX_ERROR) { |
3680
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
814 ngx_http_ssi_buffered(r, ctx); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
815 return rc; |
583 | 816 } |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
817 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
818 |
497 | 819 |
820 /* rc == NGX_HTTP_SSI_ERROR */ | |
821 | |
499 | 822 ssi_error: |
497 | 823 |
597 | 824 if (slcf->silent_errors) { |
497 | 825 continue; |
826 } | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
827 |
499 | 828 if (ctx->free) { |
829 cl = ctx->free; | |
830 ctx->free = ctx->free->next; | |
831 b = cl->buf; | |
832 ngx_memzero(b, sizeof(ngx_buf_t)); | |
833 | |
834 } else { | |
835 b = ngx_calloc_buf(r->pool); | |
836 if (b == NULL) { | |
837 return NGX_ERROR; | |
838 } | |
839 | |
840 cl = ngx_alloc_chain_link(r->pool); | |
841 if (cl == NULL) { | |
842 return NGX_ERROR; | |
843 } | |
844 | |
845 cl->buf = b; | |
497 | 846 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
847 |
497 | 848 b->memory = 1; |
547 | 849 b->pos = ctx->errmsg.data; |
850 b->last = ctx->errmsg.data + ctx->errmsg.len; | |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
851 |
497 | 852 cl->next = NULL; |
853 *ctx->last_out = cl; | |
854 ctx->last_out = &cl->next; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
855 |
497 | 856 continue; |
857 } | |
858 | |
710
6875ee9f93c7
ssi did work with memcached and nonbuffered responses
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
859 if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) { |
499 | 860 if (b == NULL) { |
861 if (ctx->free) { | |
862 cl = ctx->free; | |
863 ctx->free = ctx->free->next; | |
864 b = cl->buf; | |
865 ngx_memzero(b, sizeof(ngx_buf_t)); | |
866 | |
867 } else { | |
868 b = ngx_calloc_buf(r->pool); | |
869 if (b == NULL) { | |
870 return NGX_ERROR; | |
871 } | |
497 | 872 |
499 | 873 cl = ngx_alloc_chain_link(r->pool); |
874 if (cl == NULL) { | |
875 return NGX_ERROR; | |
876 } | |
877 | |
878 cl->buf = b; | |
879 } | |
880 | |
509 | 881 b->sync = 1; |
882 | |
499 | 883 cl->next = NULL; |
884 *ctx->last_out = cl; | |
885 ctx->last_out = &cl->next; | |
886 } | |
887 | |
888 b->last_buf = ctx->buf->last_buf; | |
889 b->shadow = ctx->buf; | |
509 | 890 |
597 | 891 if (slcf->ignore_recycled_buffers == 0) { |
509 | 892 b->recycled = ctx->buf->recycled; |
893 } | |
497 | 894 } |
895 | |
499 | 896 ctx->buf = NULL; |
897 | |
497 | 898 ctx->saved = ctx->looked; |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
899 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
900 |
499 | 901 if (ctx->out == NULL && ctx->busy == NULL) { |
497 | 902 return NGX_OK; |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
903 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
904 |
509 | 905 return ngx_http_ssi_output(r, ctx); |
906 } | |
907 | |
908 | |
909 static ngx_int_t | |
910 ngx_http_ssi_output(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx) | |
911 { | |
912 ngx_int_t rc; | |
913 ngx_buf_t *b; | |
914 ngx_chain_t *cl; | |
915 | |
641 | 916 #if 1 |
917 b = NULL; | |
918 for (cl = ctx->out; cl; cl = cl->next) { | |
643 | 919 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
920 "ssi out: %p %p", cl->buf, cl->buf->pos); | |
641 | 921 if (cl->buf == b) { |
922 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
923 "the same buf was used in ssi"); | |
924 ngx_debug_point(); | |
925 return NGX_ERROR; | |
926 } | |
927 b = cl->buf; | |
928 } | |
929 #endif | |
930 | |
497 | 931 rc = ngx_http_next_body_filter(r, ctx->out); |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
932 |
499 | 933 if (ctx->busy == NULL) { |
934 ctx->busy = ctx->out; | |
935 | |
936 } else { | |
937 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ } | |
938 cl->next = ctx->out; | |
939 } | |
940 | |
497 | 941 ctx->out = NULL; |
942 ctx->last_out = &ctx->out; | |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
943 |
499 | 944 while (ctx->busy) { |
945 | |
657 | 946 cl = ctx->busy; |
947 b = cl->buf; | |
499 | 948 |
949 if (ngx_buf_size(b) != 0) { | |
950 break; | |
951 } | |
952 | |
953 if (b->shadow) { | |
954 b->shadow->pos = b->shadow->last; | |
955 } | |
956 | |
957 ctx->busy = cl->next; | |
645 | 958 |
959 if (ngx_buf_in_memory(b) || b->in_file) { | |
960 /* add data bufs only to the free buf chain */ | |
961 | |
962 cl->next = ctx->free; | |
963 ctx->free = cl; | |
964 } | |
499 | 965 } |
966 | |
3680
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
967 ngx_http_ssi_buffered(r, ctx); |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
968 |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
969 return rc; |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
970 } |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
971 |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
972 |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
973 static void |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
974 ngx_http_ssi_buffered(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx) |
0d492ae53a57
update r->buffered after processing SSI command,
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
975 { |
829
362d156f0278
high level HTTP buffered flags should be on per-subrequest basis,
Igor Sysoev <igor@sysoev.ru>
parents:
787
diff
changeset
|
976 if (ctx->in || ctx->buf) { |
362d156f0278
high level HTTP buffered flags should be on per-subrequest basis,
Igor Sysoev <igor@sysoev.ru>
parents:
787
diff
changeset
|
977 r->buffered |= NGX_HTTP_SSI_BUFFERED; |
362d156f0278
high level HTTP buffered flags should be on per-subrequest basis,
Igor Sysoev <igor@sysoev.ru>
parents:
787
diff
changeset
|
978 |
362d156f0278
high level HTTP buffered flags should be on per-subrequest basis,
Igor Sysoev <igor@sysoev.ru>
parents:
787
diff
changeset
|
979 } else { |
362d156f0278
high level HTTP buffered flags should be on per-subrequest basis,
Igor Sysoev <igor@sysoev.ru>
parents:
787
diff
changeset
|
980 r->buffered &= ~NGX_HTTP_SSI_BUFFERED; |
362d156f0278
high level HTTP buffered flags should be on per-subrequest basis,
Igor Sysoev <igor@sysoev.ru>
parents:
787
diff
changeset
|
981 } |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
982 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
983 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
984 |
489 | 985 static ngx_int_t |
986 ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx) | |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
987 { |
609 | 988 u_char *p, *value, *last, *copy_end, ch; |
497 | 989 size_t looked; |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
990 ngx_http_ssi_state_e state; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
991 |
497 | 992 state = ctx->state; |
993 looked = ctx->looked; | |
994 last = ctx->buf->last; | |
995 copy_end = ctx->copy_end; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
996 |
497 | 997 for (p = ctx->pos; p < last; p++) { |
489 | 998 |
999 ch = *p; | |
1000 | |
1001 if (state == ssi_start_state) { | |
1002 | |
1003 /* the tight loop */ | |
1004 | |
499 | 1005 for ( ;; ) { |
1006 if (ch == '<') { | |
1007 copy_end = p; | |
1008 looked = 1; | |
1009 state = ssi_tag_state; | |
1010 | |
1011 goto tag_started; | |
489 | 1012 } |
1013 | |
499 | 1014 if (++p == last) { |
1015 break; | |
1016 } | |
497 | 1017 |
499 | 1018 ch = *p; |
489 | 1019 } |
1020 | |
1260
c3541b8973de
if "<!--" was on edge of buf, then ssi_sharp_state was saved in ctx->saved
Igor Sysoev <igor@sysoev.ru>
parents:
1190
diff
changeset
|
1021 ctx->state = state; |
497 | 1022 ctx->pos = p; |
1023 ctx->looked = looked; | |
1024 ctx->copy_end = p; | |
489 | 1025 |
497 | 1026 if (ctx->copy_start == NULL) { |
1027 ctx->copy_start = ctx->buf->pos; | |
489 | 1028 } |
497 | 1029 |
1030 return NGX_AGAIN; | |
1031 | |
499 | 1032 tag_started: |
1033 | |
497 | 1034 continue; |
489 | 1035 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1036 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
1037 switch (state) { |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1038 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
1039 case ssi_start_state: |
4821
f1867c1d4c63
Mark logically dead code with corresponding comment.
Andrey Belov <defan@nginx.com>
parents:
4746
diff
changeset
|
1040 /* not reached */ |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1041 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1042 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1043 case ssi_tag_state: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1044 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1045 case '!': |
497 | 1046 looked = 2; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1047 state = ssi_comment0_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1048 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1049 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1050 case '<': |
497 | 1051 copy_end = p; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1052 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1053 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1054 default: |
497 | 1055 copy_end = p; |
1056 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1057 state = ssi_start_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1058 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1059 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1060 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1061 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1062 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1063 case ssi_comment0_state: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1064 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1065 case '-': |
497 | 1066 looked = 3; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1067 state = ssi_comment1_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1068 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1069 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1070 case '<': |
497 | 1071 copy_end = p; |
1072 looked = 1; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1073 state = ssi_tag_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1074 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1075 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1076 default: |
497 | 1077 copy_end = p; |
1078 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1079 state = ssi_start_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1080 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1081 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1082 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1083 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1084 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1085 case ssi_comment1_state: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1086 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1087 case '-': |
497 | 1088 looked = 4; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1089 state = ssi_sharp_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1090 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1091 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1092 case '<': |
497 | 1093 copy_end = p; |
1094 looked = 1; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1095 state = ssi_tag_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1096 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1097 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1098 default: |
497 | 1099 copy_end = p; |
1100 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1101 state = ssi_start_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1102 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1103 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1104 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1105 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1106 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1107 case ssi_sharp_state: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1108 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1109 case '#': |
659 | 1110 if (p - ctx->pos < 4) { |
1111 ctx->saved = 0; | |
1112 } | |
497 | 1113 looked = 0; |
1114 state = ssi_precommand_state; | |
489 | 1115 break; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1116 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1117 case '<': |
497 | 1118 copy_end = p; |
1119 looked = 1; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1120 state = ssi_tag_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1121 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1122 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1123 default: |
497 | 1124 copy_end = p; |
1125 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1126 state = ssi_start_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1127 break; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1128 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
1129 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1130 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1131 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1132 case ssi_precommand_state: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1133 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1134 case ' ': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1135 case CR: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1136 case LF: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1137 case '\t': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1138 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1139 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1140 default: |
489 | 1141 ctx->command.len = 1; |
2049 | 1142 ctx->command.data = ngx_pnalloc(r->pool, |
1143 NGX_HTTP_SSI_COMMAND_LEN); | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1144 if (ctx->command.data == NULL) { |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1145 return NGX_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1146 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1147 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1148 ctx->command.data[0] = ch; |
609 | 1149 |
597 | 1150 ctx->key = 0; |
1151 ctx->key = ngx_hash(ctx->key, ch); | |
1152 | |
497 | 1153 ctx->params.nelts = 0; |
629 | 1154 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1155 state = ssi_command_state; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1156 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1157 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
1158 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1159 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1160 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1161 case ssi_command_state: |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1162 switch (ch) { |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1163 case ' ': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1164 case CR: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1165 case LF: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1166 case '\t': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1167 state = ssi_preparam_state; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1168 break; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1169 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1170 case '-': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1171 state = ssi_comment_end0_state; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1172 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1173 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1174 default: |
497 | 1175 if (ctx->command.len == NGX_HTTP_SSI_COMMAND_LEN) { |
1176 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1177 "the \"%V%c...\" SSI command is too long", |
1178 &ctx->command, ch); | |
497 | 1179 |
1180 state = ssi_error_state; | |
1181 break; | |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1182 } |
609 | 1183 |
1184 ctx->command.data[ctx->command.len++] = ch; | |
1185 ctx->key = ngx_hash(ctx->key, ch); | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1186 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1187 |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1188 break; |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1189 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1190 case ssi_preparam_state: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1191 switch (ch) { |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1192 case ' ': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1193 case CR: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1194 case LF: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1195 case '\t': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1196 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1197 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1198 case '-': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1199 state = ssi_comment_end0_state; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1200 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1201 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1202 default: |
499 | 1203 ctx->param = ngx_array_push(&ctx->params); |
1204 if (ctx->param == NULL) { | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1205 return NGX_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1206 } |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1207 |
489 | 1208 ctx->param->key.len = 1; |
2049 | 1209 ctx->param->key.data = ngx_pnalloc(r->pool, |
1210 NGX_HTTP_SSI_PARAM_LEN); | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1211 if (ctx->param->key.data == NULL) { |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1212 return NGX_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1213 } |
497 | 1214 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1215 ctx->param->key.data[0] = ch; |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1216 |
489 | 1217 ctx->param->value.len = 0; |
609 | 1218 |
1219 if (ctx->value_buf == NULL) { | |
2049 | 1220 ctx->param->value.data = ngx_pnalloc(r->pool, |
4528
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1221 ctx->value_len + 1); |
609 | 1222 if (ctx->param->value.data == NULL) { |
1223 return NGX_ERROR; | |
1224 } | |
1225 | |
1226 } else { | |
1227 ctx->param->value.data = ctx->value_buf; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1228 } |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1229 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1230 state = ssi_param_state; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1231 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1232 } |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1233 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1234 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1235 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1236 case ssi_param_state: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1237 switch (ch) { |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1238 case ' ': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1239 case CR: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1240 case LF: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1241 case '\t': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1242 state = ssi_preequal_state; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1243 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1244 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1245 case '=': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1246 state = ssi_prevalue_state; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1247 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1248 |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1249 case '-': |
497 | 1250 state = ssi_error_end0_state; |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1251 |
497 | 1252 ctx->param->key.data[ctx->param->key.len++] = ch; |
1253 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1254 "invalid \"%V\" parameter in \"%V\" SSI command", | |
1255 &ctx->param->key, &ctx->command); | |
1256 break; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1257 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1258 default: |
497 | 1259 if (ctx->param->key.len == NGX_HTTP_SSI_PARAM_LEN) { |
1260 state = ssi_error_state; | |
1261 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1262 "too long \"%V%c...\" parameter in " |
497 | 1263 "\"%V\" SSI command", |
609 | 1264 &ctx->param->key, ch, &ctx->command); |
497 | 1265 break; |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1266 } |
609 | 1267 |
1268 ctx->param->key.data[ctx->param->key.len++] = ch; | |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1269 } |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1270 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1271 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1272 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1273 case ssi_preequal_state: |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1274 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1275 case ' ': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1276 case CR: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1277 case LF: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1278 case '\t': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1279 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1280 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1281 case '=': |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1282 state = ssi_prevalue_state; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1283 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1284 |
497 | 1285 default: |
1286 if (ch == '-') { | |
1287 state = ssi_error_end0_state; | |
1288 } else { | |
1289 state = ssi_error_state; | |
1290 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1291 |
497 | 1292 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1293 "unexpected \"%c\" symbol after \"%V\" " | |
1294 "parameter in \"%V\" SSI command", | |
1295 ch, &ctx->param->key, &ctx->command); | |
1296 break; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1297 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1298 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1299 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1300 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1301 case ssi_prevalue_state: |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1302 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1303 case ' ': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1304 case CR: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1305 case LF: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1306 case '\t': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1307 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1308 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1309 case '"': |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1310 state = ssi_double_quoted_value_state; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1311 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1312 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1313 case '\'': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1314 state = ssi_quoted_value_state; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1315 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1316 |
497 | 1317 default: |
1318 if (ch == '-') { | |
1319 state = ssi_error_end0_state; | |
1320 } else { | |
1321 state = ssi_error_state; | |
1322 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1323 |
497 | 1324 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1325 "unexpected \"%c\" symbol before value of " | |
1326 "\"%V\" parameter in \"%V\" SSI command", | |
1327 ch, &ctx->param->key, &ctx->command); | |
1328 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1329 } |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1330 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1331 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1332 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1333 case ssi_double_quoted_value_state: |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1334 switch (ch) { |
559 | 1335 case '"': |
1336 state = ssi_postparam_state; | |
1337 break; | |
1338 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1339 case '\\': |
497 | 1340 ctx->saved_state = ssi_double_quoted_value_state; |
1341 state = ssi_quoted_symbol_state; | |
559 | 1342 |
1343 /* fall through */ | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1344 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1345 default: |
497 | 1346 if (ctx->param->value.len == ctx->value_len) { |
1347 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1348 "too long \"%V%c...\" value of \"%V\" " |
1349 "parameter in \"%V\" SSI command", | |
1350 &ctx->param->value, ch, &ctx->param->key, | |
497 | 1351 &ctx->command); |
1352 state = ssi_error_state; | |
1353 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1354 } |
609 | 1355 |
1356 ctx->param->value.data[ctx->param->value.len++] = ch; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1357 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1358 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1359 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1360 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1361 case ssi_quoted_value_state: |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1362 switch (ch) { |
559 | 1363 case '\'': |
1364 state = ssi_postparam_state; | |
1365 break; | |
1366 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1367 case '\\': |
497 | 1368 ctx->saved_state = ssi_quoted_value_state; |
1369 state = ssi_quoted_symbol_state; | |
559 | 1370 |
1371 /* fall through */ | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1372 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1373 default: |
497 | 1374 if (ctx->param->value.len == ctx->value_len) { |
1375 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1376 "too long \"%V%c...\" value of \"%V\" " |
1377 "parameter in \"%V\" SSI command", | |
1378 &ctx->param->value, ch, &ctx->param->key, | |
497 | 1379 &ctx->command); |
1380 state = ssi_error_state; | |
1381 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1382 } |
609 | 1383 |
1384 ctx->param->value.data[ctx->param->value.len++] = ch; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1385 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1386 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1387 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1388 |
497 | 1389 case ssi_quoted_symbol_state: |
559 | 1390 state = ctx->saved_state; |
1391 | |
4528
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1392 if (ctx->param->value.len == ctx->value_len) { |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1393 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1394 "too long \"%V%c...\" value of \"%V\" " |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1395 "parameter in \"%V\" SSI command", |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1396 &ctx->param->value, ch, &ctx->param->key, |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1397 &ctx->command); |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1398 state = ssi_error_state; |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1399 break; |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1400 } |
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
1401 |
497 | 1402 ctx->param->value.data[ctx->param->value.len++] = ch; |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1403 |
497 | 1404 break; |
1405 | |
1406 case ssi_postparam_state: | |
609 | 1407 |
651 | 1408 if (ctx->param->value.len + 1 < ctx->value_len / 2) { |
2049 | 1409 value = ngx_pnalloc(r->pool, ctx->param->value.len + 1); |
609 | 1410 if (value == NULL) { |
1411 return NGX_ERROR; | |
1412 } | |
1413 | |
1414 ngx_memcpy(value, ctx->param->value.data, | |
1415 ctx->param->value.len); | |
1416 | |
1417 ctx->value_buf = ctx->param->value.data; | |
1418 ctx->param->value.data = value; | |
1419 | |
1420 } else { | |
1421 ctx->value_buf = NULL; | |
1422 } | |
1423 | |
497 | 1424 switch (ch) { |
1425 case ' ': | |
1426 case CR: | |
1427 case LF: | |
1428 case '\t': | |
1429 state = ssi_preparam_state; | |
1430 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1431 |
497 | 1432 case '-': |
1433 state = ssi_comment_end0_state; | |
1434 break; | |
1435 | |
1436 default: | |
1437 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1438 "unexpected \"%c\" symbol after \"%V\" value " | |
1439 "of \"%V\" parameter in \"%V\" SSI command", | |
1440 ch, &ctx->param->value, &ctx->param->key, | |
1441 &ctx->command); | |
1442 state = ssi_error_state; | |
1443 break; | |
1444 } | |
1445 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1446 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1447 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1448 case ssi_comment_end0_state: |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1449 switch (ch) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1450 case '-': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1451 state = ssi_comment_end1_state; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1452 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1453 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1454 default: |
497 | 1455 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1456 "unexpected \"%c\" symbol in \"%V\" SSI command", | |
1457 ch, &ctx->command); | |
1458 state = ssi_error_state; | |
1459 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1460 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1461 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1462 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1463 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1464 case ssi_comment_end1_state: |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1465 switch (ch) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1466 case '>': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1467 ctx->state = ssi_start_state; |
497 | 1468 ctx->pos = p + 1; |
1469 ctx->looked = looked; | |
1470 ctx->copy_end = copy_end; | |
1471 | |
1472 if (ctx->copy_start == NULL && copy_end) { | |
1473 ctx->copy_start = ctx->buf->pos; | |
1474 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1475 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1476 return NGX_OK; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1477 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1478 default: |
497 | 1479 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1480 "unexpected \"%c\" symbol in \"%V\" SSI command", | |
1481 ch, &ctx->command); | |
1482 state = ssi_error_state; | |
1483 break; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1484 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1485 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1486 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1487 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1488 case ssi_error_state: |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1489 switch (ch) { |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1490 case '-': |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1491 state = ssi_error_end0_state; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1492 break; |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1493 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1494 default: |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1495 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1496 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1497 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1498 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1499 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1500 case ssi_error_end0_state: |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1501 switch (ch) { |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1502 case '-': |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1503 state = ssi_error_end1_state; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1504 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1505 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1506 default: |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1507 state = ssi_error_state; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1508 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1509 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1510 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1511 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1512 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1513 case ssi_error_end1_state: |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1514 switch (ch) { |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1515 case '>': |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1516 ctx->state = ssi_start_state; |
497 | 1517 ctx->pos = p + 1; |
1518 ctx->looked = looked; | |
1519 ctx->copy_end = copy_end; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1520 |
497 | 1521 if (ctx->copy_start == NULL && copy_end) { |
1522 ctx->copy_start = ctx->buf->pos; | |
1523 } | |
1524 | |
1525 return NGX_HTTP_SSI_ERROR; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1526 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1527 default: |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
1528 state = ssi_error_state; |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
1529 break; |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1530 } |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1531 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1532 break; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1533 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
1534 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1535 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1536 ctx->state = state; |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1537 ctx->pos = p; |
497 | 1538 ctx->looked = looked; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1539 |
497 | 1540 ctx->copy_end = (state == ssi_start_state) ? p : copy_end; |
1541 | |
1542 if (ctx->copy_start == NULL && ctx->copy_end) { | |
1543 ctx->copy_start = ctx->buf->pos; | |
1544 } | |
1545 | |
1546 return NGX_AGAIN; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1547 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1548 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1549 |
553 | 1550 static ngx_str_t * |
611 | 1551 ngx_http_ssi_get_variable(ngx_http_request_t *r, ngx_str_t *name, |
1552 ngx_uint_t key) | |
553 | 1553 { |
1554 ngx_uint_t i; | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1555 ngx_list_part_t *part; |
553 | 1556 ngx_http_ssi_var_t *var; |
1557 ngx_http_ssi_ctx_t *ctx; | |
1558 | |
1559 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
1560 | |
4381
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1561 #if (NGX_PCRE) |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1562 { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1563 ngx_str_t *value; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1564 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1565 if (key >= '0' && key <= '9') { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1566 i = key - '0'; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1567 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1568 if (i < ctx->ncaptures) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1569 value = ngx_palloc(r->pool, sizeof(ngx_str_t)); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1570 if (value == NULL) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1571 return NULL; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1572 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1573 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1574 i *= 2; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1575 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1576 value->data = ctx->captures_data + ctx->captures[i]; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1577 value->len = ctx->captures[i + 1] - ctx->captures[i]; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1578 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1579 return value; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1580 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1581 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1582 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1583 #endif |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1584 |
667 | 1585 if (ctx->variables == NULL) { |
1586 return NULL; | |
1587 } | |
1588 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1589 part = &ctx->variables->part; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1590 var = part->elts; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1591 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1592 for (i = 0; /* void */ ; i++) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1593 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1594 if (i >= part->nelts) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1595 if (part->next == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1596 break; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1597 } |
787
b310630d129e
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
784
diff
changeset
|
1598 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1599 part = part->next; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1600 var = part->elts; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1601 i = 0; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1602 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1603 |
553 | 1604 if (name->len != var[i].name.len) { |
1605 continue; | |
1606 } | |
1607 | |
611 | 1608 if (key != var[i].key) { |
1609 continue; | |
1610 } | |
1611 | |
1612 if (ngx_strncmp(name->data, var[i].name.data, name->len) == 0) { | |
553 | 1613 return &var[i].value; |
1614 } | |
1615 } | |
1616 | |
1617 return NULL; | |
1618 } | |
1619 | |
1620 | |
1621 static ngx_int_t | |
1622 ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
1623 ngx_str_t *text, ngx_uint_t flags) | |
1624 { | |
573 | 1625 u_char ch, *p, **value, *data, *part_data; |
1626 size_t *size, len, prefix, part_len; | |
1627 ngx_str_t var, *val; | |
611 | 1628 ngx_int_t key; |
2136 | 1629 ngx_uint_t i, n, bracket, quoted; |
553 | 1630 ngx_array_t lengths, values; |
1631 ngx_http_variable_value_t *vv; | |
1632 | |
1633 n = ngx_http_script_variables_count(text); | |
1634 | |
1635 if (n == 0) { | |
1636 | |
657 | 1637 data = text->data; |
1638 p = data; | |
1639 | |
1640 if ((flags & NGX_HTTP_SSI_ADD_PREFIX) && text->data[0] != '/') { | |
1641 | |
553 | 1642 for (prefix = r->uri.len; prefix; prefix--) { |
1643 if (r->uri.data[prefix - 1] == '/') { | |
1644 break; | |
1645 } | |
1646 } | |
1647 | |
1648 if (prefix) { | |
1649 len = prefix + text->len; | |
1650 | |
2049 | 1651 data = ngx_pnalloc(r->pool, len); |
553 | 1652 if (data == NULL) { |
1653 return NGX_ERROR; | |
1654 } | |
1655 | |
573 | 1656 p = ngx_copy(data, r->uri.data, prefix); |
553 | 1657 } |
1658 } | |
1659 | |
657 | 1660 quoted = 0; |
1661 | |
2024 | 1662 for (i = 0; i < text->len; i++) { |
657 | 1663 ch = text->data[i]; |
1664 | |
1665 if (!quoted) { | |
1666 | |
1667 if (ch == '\\') { | |
1668 quoted = 1; | |
1669 continue; | |
1670 } | |
1671 | |
1672 } else { | |
1673 quoted = 0; | |
1674 | |
1675 if (ch != '\\' && ch != '\'' && ch != '"' && ch != '$') { | |
1676 *p++ = '\\'; | |
1677 } | |
1678 } | |
1679 | |
1680 *p++ = ch; | |
1681 } | |
1682 | |
1683 text->len = p - data; | |
1684 text->data = data; | |
1685 | |
553 | 1686 return NGX_OK; |
1687 } | |
1688 | |
1689 if (ngx_array_init(&lengths, r->pool, 8, sizeof(size_t *)) != NGX_OK) { | |
1690 return NGX_ERROR; | |
1691 } | |
1692 | |
1693 if (ngx_array_init(&values, r->pool, 8, sizeof(u_char *)) != NGX_OK) { | |
1694 return NGX_ERROR; | |
1695 } | |
1696 | |
1697 len = 0; | |
1698 i = 0; | |
1699 | |
1700 while (i < text->len) { | |
1701 | |
1702 if (text->data[i] == '$') { | |
1703 | |
1704 var.len = 0; | |
1705 | |
1706 if (++i == text->len) { | |
1707 goto invalid_variable; | |
1708 } | |
1709 | |
1710 if (text->data[i] == '{') { | |
1711 bracket = 1; | |
1712 | |
1713 if (++i == text->len) { | |
1714 goto invalid_variable; | |
1715 } | |
1716 | |
1717 var.data = &text->data[i]; | |
1718 | |
1719 } else { | |
1720 bracket = 0; | |
1721 var.data = &text->data[i]; | |
1722 } | |
1723 | |
1724 for ( /* void */ ; i < text->len; i++, var.len++) { | |
1725 ch = text->data[i]; | |
1726 | |
1727 if (ch == '}' && bracket) { | |
1728 i++; | |
1729 bracket = 0; | |
1730 break; | |
1731 } | |
1732 | |
1733 if ((ch >= 'A' && ch <= 'Z') | |
1734 || (ch >= 'a' && ch <= 'z') | |
1735 || (ch >= '0' && ch <= '9') | |
1736 || ch == '_') | |
1737 { | |
1738 continue; | |
1739 } | |
1740 | |
1741 break; | |
1742 } | |
1743 | |
1744 if (bracket) { | |
1745 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1746 "the closing bracket in \"%V\" " | |
1747 "variable is missing", &var); | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1748 return NGX_HTTP_SSI_ERROR; |
553 | 1749 } |
1750 | |
577 | 1751 if (var.len == 0) { |
553 | 1752 goto invalid_variable; |
1753 } | |
1754 | |
2136 | 1755 key = ngx_hash_strlow(var.data, var.data, var.len); |
553 | 1756 |
611 | 1757 val = ngx_http_ssi_get_variable(r, &var, key); |
553 | 1758 |
1759 if (val == NULL) { | |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3495
diff
changeset
|
1760 vv = ngx_http_get_variable(r, &var, key); |
553 | 1761 if (vv == NULL) { |
1762 return NGX_ERROR; | |
1763 } | |
1764 | |
573 | 1765 if (vv->not_found) { |
553 | 1766 continue; |
1767 } | |
1768 | |
573 | 1769 part_data = vv->data; |
1770 part_len = vv->len; | |
553 | 1771 |
1772 } else { | |
573 | 1773 part_data = val->data; |
1774 part_len = val->len; | |
553 | 1775 } |
1776 | |
1777 } else { | |
573 | 1778 part_data = &text->data[i]; |
651 | 1779 quoted = 0; |
573 | 1780 |
1781 for (p = part_data; i < text->len; i++) { | |
559 | 1782 ch = text->data[i]; |
1783 | |
651 | 1784 if (!quoted) { |
1785 | |
1786 if (ch == '\\') { | |
1787 quoted = 1; | |
1788 continue; | |
1789 } | |
1790 | |
1791 if (ch == '$') { | |
559 | 1792 break; |
1793 } | |
1794 | |
651 | 1795 } else { |
1796 quoted = 0; | |
1797 | |
1798 if (ch != '\\' && ch != '\'' && ch != '"' && ch != '$') { | |
1799 *p++ = '\\'; | |
1800 } | |
559 | 1801 } |
1802 | |
1803 *p++ = ch; | |
553 | 1804 } |
559 | 1805 |
573 | 1806 part_len = p - part_data; |
553 | 1807 } |
1808 | |
573 | 1809 len += part_len; |
553 | 1810 |
1811 size = ngx_array_push(&lengths); | |
1812 if (size == NULL) { | |
1813 return NGX_ERROR; | |
1814 } | |
1815 | |
573 | 1816 *size = part_len; |
553 | 1817 |
1818 value = ngx_array_push(&values); | |
1819 if (value == NULL) { | |
1820 return NGX_ERROR; | |
1821 } | |
1822 | |
573 | 1823 *value = part_data; |
553 | 1824 } |
1825 | |
1826 prefix = 0; | |
1827 | |
1828 size = lengths.elts; | |
1829 value = values.elts; | |
1830 | |
1831 if (flags & NGX_HTTP_SSI_ADD_PREFIX) { | |
1832 for (i = 0; i < values.nelts; i++) { | |
1833 if (size[i] != 0) { | |
1834 if (*value[i] != '/') { | |
1835 for (prefix = r->uri.len; prefix; prefix--) { | |
1836 if (r->uri.data[prefix - 1] == '/') { | |
1837 len += prefix; | |
1838 break; | |
1839 } | |
1840 } | |
1841 } | |
1842 | |
1843 break; | |
1844 } | |
1845 } | |
1846 } | |
1847 | |
2049 | 1848 p = ngx_pnalloc(r->pool, len + ((flags & NGX_HTTP_SSI_ADD_ZERO) ? 1 : 0)); |
553 | 1849 if (p == NULL) { |
1850 return NGX_ERROR; | |
1851 } | |
1852 | |
1853 text->len = len; | |
1854 text->data = p; | |
1855 | |
573 | 1856 p = ngx_copy(p, r->uri.data, prefix); |
553 | 1857 |
1858 for (i = 0; i < values.nelts; i++) { | |
573 | 1859 p = ngx_copy(p, value[i], size[i]); |
553 | 1860 } |
1861 | |
1862 return NGX_OK; | |
1863 | |
1864 invalid_variable: | |
1865 | |
1866 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1867 "invalid variable name in \"%V\"", text); | |
1868 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1869 return NGX_HTTP_SSI_ERROR; |
553 | 1870 } |
1871 | |
1872 | |
1873 static ngx_int_t | |
4381
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1874 ngx_http_ssi_regex_match(ngx_http_request_t *r, ngx_str_t *pattern, |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1875 ngx_str_t *str) |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1876 { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1877 #if (NGX_PCRE) |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1878 int rc, *captures; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1879 u_char *p, errstr[NGX_MAX_CONF_ERRSTR]; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1880 size_t size; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1881 ngx_int_t key; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1882 ngx_str_t *vv, name, value; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1883 ngx_uint_t i, n; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1884 ngx_http_ssi_ctx_t *ctx; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1885 ngx_http_ssi_var_t *var; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1886 ngx_regex_compile_t rgc; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1887 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1888 ngx_memzero(&rgc, sizeof(ngx_regex_compile_t)); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1889 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1890 rgc.pattern = *pattern; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1891 rgc.pool = r->pool; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1892 rgc.err.len = NGX_MAX_CONF_ERRSTR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1893 rgc.err.data = errstr; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1894 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1895 if (ngx_regex_compile(&rgc) != NGX_OK) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1896 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%V", &rgc.err); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1897 return NGX_HTTP_SSI_ERROR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1898 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1899 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1900 n = (rgc.captures + 1) * 3; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1901 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1902 captures = ngx_palloc(r->pool, n * sizeof(int)); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1903 if (captures == NULL) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1904 return NGX_ERROR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1905 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1906 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1907 rc = ngx_regex_exec(rgc.regex, str, captures, n); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1908 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1909 if (rc < NGX_REGEX_NO_MATCHED) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1910 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1911 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1912 rc, str, pattern); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1913 return NGX_HTTP_SSI_ERROR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1914 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1915 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1916 if (rc == NGX_REGEX_NO_MATCHED) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1917 return NGX_DECLINED; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1918 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1919 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1920 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1921 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1922 ctx->ncaptures = rc; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1923 ctx->captures = captures; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1924 ctx->captures_data = str->data; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1925 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1926 if (rgc.named_captures > 0) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1927 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1928 if (ctx->variables == NULL) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1929 ctx->variables = ngx_list_create(r->pool, 4, |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1930 sizeof(ngx_http_ssi_var_t)); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1931 if (ctx->variables == NULL) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1932 return NGX_ERROR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1933 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1934 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1935 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1936 size = rgc.name_size; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1937 p = rgc.names; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1938 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1939 for (i = 0; i < (ngx_uint_t) rgc.named_captures; i++, p += size) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1940 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1941 name.data = &p[2]; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1942 name.len = ngx_strlen(name.data); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1943 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1944 n = 2 * ((p[0] << 8) + p[1]); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1945 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1946 value.data = &str->data[captures[n]]; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1947 value.len = captures[n + 1] - captures[n]; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1948 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1949 key = ngx_hash_strlow(name.data, name.data, name.len); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1950 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1951 vv = ngx_http_ssi_get_variable(r, &name, key); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1952 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1953 if (vv) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1954 *vv = value; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1955 continue; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1956 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1957 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1958 var = ngx_list_push(ctx->variables); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1959 if (var == NULL) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1960 return NGX_ERROR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1961 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1962 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1963 var->name = name; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1964 var->key = key; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1965 var->value = value; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1966 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1967 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1968 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1969 return NGX_OK; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1970 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1971 #else |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1972 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1973 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1974 "the using of the regex \"%V\" in SSI requires PCRE library", |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1975 pattern); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1976 return NGX_HTTP_SSI_ERROR; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1977 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1978 #endif |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1979 } |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1980 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1981 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
1982 static ngx_int_t |
553 | 1983 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
1984 ngx_str_t **params) | |
1985 { | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1986 ngx_int_t rc, key; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1987 ngx_str_t *uri, *file, *wait, *set, *stub, args; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1988 ngx_buf_t *b; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1989 ngx_uint_t flags, i; |
784
5a164305b960
fix building by Debian gcc-4.1.2 amd64
Igor Sysoev <igor@sysoev.ru>
parents:
777
diff
changeset
|
1990 ngx_chain_t *cl, *tl, **ll, *out; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1991 ngx_http_request_t *sr; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1992 ngx_http_ssi_var_t *var; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1993 ngx_http_ssi_ctx_t *mctx; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1994 ngx_http_ssi_block_t *bl; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
1995 ngx_http_post_subrequest_t *psr; |
553 | 1996 |
1997 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL]; | |
1998 file = params[NGX_HTTP_SSI_INCLUDE_FILE]; | |
645 | 1999 wait = params[NGX_HTTP_SSI_INCLUDE_WAIT]; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2000 set = params[NGX_HTTP_SSI_INCLUDE_SET]; |
667 | 2001 stub = params[NGX_HTTP_SSI_INCLUDE_STUB]; |
553 | 2002 |
2003 if (uri && file) { | |
2004 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2005 "inlcusion may be either virtual=\"%V\" or file=\"%V\"", | |
2006 uri, file); | |
2007 return NGX_HTTP_SSI_ERROR; | |
2008 } | |
2009 | |
2010 if (uri == NULL && file == NULL) { | |
2011 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2012 "no parameter in \"include\" SSI command"); | |
2013 return NGX_HTTP_SSI_ERROR; | |
2014 } | |
2015 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2016 if (set && stub) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2017 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
4593
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4567
diff
changeset
|
2018 "\"set\" and \"stub\" cannot be used together " |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2019 "in \"include\" SSI command"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2020 return NGX_HTTP_SSI_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2021 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2022 |
645 | 2023 if (wait) { |
2024 if (uri == NULL) { | |
2025 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
4593
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4567
diff
changeset
|
2026 "\"wait\" cannot be used with file=\"%V\"", file); |
645 | 2027 return NGX_HTTP_SSI_ERROR; |
2028 } | |
2029 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1025
diff
changeset
|
2030 if (wait->len == 2 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1025
diff
changeset
|
2031 && ngx_strncasecmp(wait->data, (u_char *) "no", 2) == 0) |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1025
diff
changeset
|
2032 { |
645 | 2033 wait = NULL; |
2034 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1025
diff
changeset
|
2035 } else if (wait->len != 3 |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1025
diff
changeset
|
2036 || ngx_strncasecmp(wait->data, (u_char *) "yes", 3) != 0) |
645 | 2037 { |
2038 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2039 "invalid value \"%V\" in the \"wait\" parameter", | |
667 | 2040 wait); |
645 | 2041 return NGX_HTTP_SSI_ERROR; |
2042 } | |
2043 } | |
2044 | |
553 | 2045 if (uri == NULL) { |
2046 uri = file; | |
2426
e5ef47ecab5d
fix r2378, file inclusion should be waited
Igor Sysoev <igor@sysoev.ru>
parents:
2414
diff
changeset
|
2047 wait = (ngx_str_t *) -1; |
553 | 2048 } |
2049 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2050 rc = ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2051 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2052 if (rc != NGX_OK) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2053 return rc; |
553 | 2054 } |
2055 | |
1593 | 2056 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2057 "ssi include: \"%V\"", uri); | |
2058 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
2059 ngx_str_null(&args); |
3161 | 2060 flags = NGX_HTTP_LOG_UNSAFE; |
573 | 2061 |
2062 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { | |
2063 return NGX_HTTP_SSI_ERROR; | |
553 | 2064 } |
2065 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2066 psr = NULL; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2067 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2068 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); |
667 | 2069 |
2070 if (stub) { | |
2071 if (mctx->blocks) { | |
2072 bl = mctx->blocks->elts; | |
2073 for (i = 0; i < mctx->blocks->nelts; i++) { | |
2074 if (stub->len == bl[i].name.len | |
2075 && ngx_strncmp(stub->data, bl[i].name.data, stub->len) == 0) | |
2076 { | |
2077 goto found; | |
2078 } | |
2079 } | |
2080 } | |
2081 | |
2082 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2083 "\"stub\"=\"%V\" for \"include\" not found", stub); | |
2084 return NGX_HTTP_SSI_ERROR; | |
2085 | |
2086 found: | |
2087 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2088 psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t)); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2089 if (psr == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2090 return NGX_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2091 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2092 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2093 psr->handler = ngx_http_ssi_stub_output; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2094 |
667 | 2095 if (bl[i].count++) { |
2096 | |
1893
685048830623
fix segfault if empty stub block is used second time
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
2097 out = NULL; |
784
5a164305b960
fix building by Debian gcc-4.1.2 amd64
Igor Sysoev <igor@sysoev.ru>
parents:
777
diff
changeset
|
2098 ll = &out; |
667 | 2099 |
2100 for (tl = bl[i].bufs; tl; tl = tl->next) { | |
2101 | |
2102 if (ctx->free) { | |
2103 cl = ctx->free; | |
2104 ctx->free = ctx->free->next; | |
2105 b = cl->buf; | |
2106 | |
2107 } else { | |
2108 b = ngx_alloc_buf(r->pool); | |
2109 if (b == NULL) { | |
2110 return NGX_ERROR; | |
2111 } | |
2112 | |
2113 cl = ngx_alloc_chain_link(r->pool); | |
2114 if (cl == NULL) { | |
2115 return NGX_ERROR; | |
2116 } | |
2117 | |
2118 cl->buf = b; | |
2119 } | |
2120 | |
2121 ngx_memcpy(b, tl->buf, sizeof(ngx_buf_t)); | |
2122 | |
2123 b->pos = b->start; | |
2124 | |
2125 *ll = cl; | |
2126 cl->next = NULL; | |
2127 ll = &cl->next; | |
2128 } | |
2129 | |
784
5a164305b960
fix building by Debian gcc-4.1.2 amd64
Igor Sysoev <igor@sysoev.ru>
parents:
777
diff
changeset
|
2130 psr->data = out; |
5a164305b960
fix building by Debian gcc-4.1.2 amd64
Igor Sysoev <igor@sysoev.ru>
parents:
777
diff
changeset
|
2131 |
667 | 2132 } else { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2133 psr->data = bl[i].bufs; |
667 | 2134 } |
2135 } | |
2136 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2137 if (wait) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2138 flags |= NGX_HTTP_SUBREQUEST_WAITED; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2139 } |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2140 |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2141 if (set) { |
2136 | 2142 key = ngx_hash_strlow(set->data, set->data, set->len); |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2143 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2144 psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t)); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2145 if (psr == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2146 return NGX_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2147 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2148 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2149 psr->handler = ngx_http_ssi_set_variable; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2150 psr->data = ngx_http_ssi_get_variable(r, set, key); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2151 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2152 if (psr->data == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2153 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2154 if (mctx->variables == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2155 mctx->variables = ngx_list_create(r->pool, 4, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2156 sizeof(ngx_http_ssi_var_t)); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2157 if (mctx->variables == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2158 return NGX_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2159 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2160 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2161 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2162 var = ngx_list_push(mctx->variables); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2163 if (var == NULL) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2164 return NGX_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2165 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2166 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2167 var->name = *set; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2168 var->key = key; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2169 var->value = ngx_http_ssi_null_string; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2170 psr->data = &var->value; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2171 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2172 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2173 flags |= NGX_HTTP_SUBREQUEST_IN_MEMORY|NGX_HTTP_SUBREQUEST_WAITED; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2174 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2175 |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2176 if (ngx_http_subrequest(r, uri, &args, &sr, psr, flags) != NGX_OK) { |
553 | 2177 return NGX_HTTP_SSI_ERROR; |
2178 } | |
2179 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2180 if (wait == NULL && set == NULL) { |
645 | 2181 return NGX_OK; |
2182 } | |
2183 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2184 if (ctx->wait == NULL) { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2185 ctx->wait = sr; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2186 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2187 return NGX_AGAIN; |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2188 |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2189 } else { |
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2190 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
4593
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4567
diff
changeset
|
2191 "can only wait for one subrequest at a time"); |
645 | 2192 } |
2193 | |
2377
87b8c44906b5
*) refactor subrequest handling, now they run as separate posted requests
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2194 return NGX_OK; |
553 | 2195 } |
2196 | |
2197 | |
497 | 2198 static ngx_int_t |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2199 ngx_http_ssi_stub_output(ngx_http_request_t *r, void *data, ngx_int_t rc) |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2200 { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2201 ngx_chain_t *out; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2202 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2203 if (rc == NGX_ERROR || r->connection->error || r->request_output) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2204 return rc; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2205 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2206 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2207 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2208 "ssi stub output: \"%V?%V\"", &r->uri, &r->args); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2209 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2210 out = data; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2211 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2212 if (!r->header_sent) { |
3453
7b68809fe8b1
use content type of the parent request in SSI stub block output
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
2213 r->headers_out.content_type_len = |
7b68809fe8b1
use content type of the parent request in SSI stub block output
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
2214 r->parent->headers_out.content_type_len; |
7b68809fe8b1
use content type of the parent request in SSI stub block output
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
2215 r->headers_out.content_type = r->parent->headers_out.content_type; |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2216 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2217 if (ngx_http_send_header(r) == NGX_ERROR) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2218 return NGX_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2219 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2220 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2221 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2222 return ngx_http_output_filter(r, out); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2223 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2224 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2225 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2226 static ngx_int_t |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2227 ngx_http_ssi_set_variable(ngx_http_request_t *r, void *data, ngx_int_t rc) |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2228 { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2229 ngx_str_t *value = data; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2230 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2231 if (r->upstream) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2232 value->len = r->upstream->buffer.last - r->upstream->buffer.pos; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2233 value->data = r->upstream->buffer.pos; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2234 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2235 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2236 return rc; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2237 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2238 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2239 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2240 static ngx_int_t |
497 | 2241 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
2242 ngx_str_t **params) | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
2243 { |
1545 | 2244 u_char *p; |
2245 uintptr_t len; | |
611 | 2246 ngx_int_t key; |
499 | 2247 ngx_buf_t *b; |
1545 | 2248 ngx_str_t *var, *value, *enc, text; |
499 | 2249 ngx_chain_t *cl; |
501 | 2250 ngx_http_variable_value_t *vv; |
497 | 2251 |
2252 var = params[NGX_HTTP_SSI_ECHO_VAR]; | |
2253 | |
643 | 2254 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2255 "ssi echo \"%V\"", var); | |
2256 | |
2136 | 2257 key = ngx_hash_strlow(var->data, var->data, var->len); |
611 | 2258 |
2259 value = ngx_http_ssi_get_variable(r, var, key); | |
553 | 2260 |
2261 if (value == NULL) { | |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3495
diff
changeset
|
2262 vv = ngx_http_get_variable(r, var, key); |
553 | 2263 |
2264 if (vv == NULL) { | |
2265 return NGX_HTTP_SSI_ERROR; | |
2266 } | |
2267 | |
573 | 2268 if (!vv->not_found) { |
2269 text.data = vv->data; | |
2270 text.len = vv->len; | |
2271 value = &text; | |
553 | 2272 } |
501 | 2273 } |
497 | 2274 |
553 | 2275 if (value == NULL) { |
499 | 2276 value = params[NGX_HTTP_SSI_ECHO_DEFAULT]; |
2277 | |
2278 if (value == NULL) { | |
2279 value = &ngx_http_ssi_none; | |
2280 | |
2281 } else if (value->len == 0) { | |
2282 return NGX_OK; | |
2283 } | |
2284 | |
2285 } else { | |
2286 if (value->len == 0) { | |
2287 return NGX_OK; | |
2288 } | |
2289 } | |
2290 | |
1545 | 2291 enc = params[NGX_HTTP_SSI_ECHO_ENCODING]; |
2292 | |
2293 if (enc) { | |
2294 if (enc->len == 4 && ngx_strncmp(enc->data, "none", 4) == 0) { | |
2295 | |
2296 ctx->encoding = NGX_HTTP_SSI_NO_ENCODING; | |
2297 | |
2298 } else if (enc->len == 3 && ngx_strncmp(enc->data, "url", 3) == 0) { | |
2299 | |
2300 ctx->encoding = NGX_HTTP_SSI_URL_ENCODING; | |
2301 | |
2302 } else if (enc->len == 6 && ngx_strncmp(enc->data, "entity", 6) == 0) { | |
2303 | |
2304 ctx->encoding = NGX_HTTP_SSI_ENTITY_ENCODING; | |
2305 | |
2306 } else { | |
2307 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2308 "unknown encoding \"%V\" in the \"echo\" command", | |
2309 enc); | |
2310 } | |
2311 } | |
2312 | |
3495
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2313 p = value->data; |
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2314 |
1545 | 2315 switch (ctx->encoding) { |
2316 | |
2317 case NGX_HTTP_SSI_URL_ENCODING: | |
2318 len = 2 * ngx_escape_uri(NULL, value->data, value->len, | |
2319 NGX_ESCAPE_HTML); | |
2320 | |
2321 if (len) { | |
2049 | 2322 p = ngx_pnalloc(r->pool, value->len + len); |
1545 | 2323 if (p == NULL) { |
2324 return NGX_HTTP_SSI_ERROR; | |
2325 } | |
2326 | |
2327 (void) ngx_escape_uri(p, value->data, value->len, NGX_ESCAPE_HTML); | |
2328 } | |
2329 | |
3495
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2330 len += value->len; |
1545 | 2331 break; |
2332 | |
2333 case NGX_HTTP_SSI_ENTITY_ENCODING: | |
2334 len = ngx_escape_html(NULL, value->data, value->len); | |
2335 | |
2336 if (len) { | |
2049 | 2337 p = ngx_pnalloc(r->pool, value->len + len); |
1545 | 2338 if (p == NULL) { |
2339 return NGX_HTTP_SSI_ERROR; | |
2340 } | |
2341 | |
2342 (void) ngx_escape_html(p, value->data, value->len); | |
2343 } | |
2344 | |
3495
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2345 len += value->len; |
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2346 break; |
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2347 |
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2348 default: /* NGX_HTTP_SSI_NO_ENCODING */ |
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2349 len = value->len; |
1545 | 2350 break; |
2351 } | |
2352 | |
499 | 2353 b = ngx_calloc_buf(r->pool); |
2354 if (b == NULL) { | |
2355 return NGX_HTTP_SSI_ERROR; | |
2356 } | |
2357 | |
2358 cl = ngx_alloc_chain_link(r->pool); | |
2359 if (cl == NULL) { | |
497 | 2360 return NGX_HTTP_SSI_ERROR; |
2361 } | |
2362 | |
2363 b->memory = 1; | |
3495
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2364 b->pos = p; |
6a5dc3803825
do not store an encoded variable value as a new cached variable value
Igor Sysoev <igor@sysoev.ru>
parents:
3454
diff
changeset
|
2365 b->last = p + len; |
497 | 2366 |
2367 cl->buf = b; | |
2368 cl->next = NULL; | |
2369 *ctx->last_out = cl; | |
2370 ctx->last_out = &cl->next; | |
2371 | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
2372 return NGX_OK; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
2373 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
2374 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
2375 |
509 | 2376 static ngx_int_t |
2377 ngx_http_ssi_config(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2378 ngx_str_t **params) | |
2379 { | |
2380 ngx_str_t *value; | |
2381 | |
2382 value = params[NGX_HTTP_SSI_CONFIG_TIMEFMT]; | |
2383 | |
2384 if (value) { | |
589 | 2385 ctx->timefmt.len = value->len; |
2049 | 2386 ctx->timefmt.data = ngx_pnalloc(r->pool, value->len + 1); |
589 | 2387 if (ctx->timefmt.data == NULL) { |
2388 return NGX_HTTP_SSI_ERROR; | |
2389 } | |
2390 | |
2391 ngx_cpystrn(ctx->timefmt.data, value->data, value->len + 1); | |
509 | 2392 } |
2393 | |
547 | 2394 value = params[NGX_HTTP_SSI_CONFIG_ERRMSG]; |
2395 | |
2396 if (value) { | |
2397 ctx->errmsg = *value; | |
2398 } | |
2399 | |
509 | 2400 return NGX_OK; |
2401 } | |
2402 | |
2403 | |
2404 static ngx_int_t | |
553 | 2405 ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
509 | 2406 ngx_str_t **params) |
2407 { | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2408 ngx_int_t key, rc; |
553 | 2409 ngx_str_t *name, *value, *vv; |
2410 ngx_http_ssi_var_t *var; | |
2411 ngx_http_ssi_ctx_t *mctx; | |
2412 | |
2413 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
2414 | |
667 | 2415 if (mctx->variables == NULL) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2416 mctx->variables = ngx_list_create(r->pool, 4, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2417 sizeof(ngx_http_ssi_var_t)); |
667 | 2418 if (mctx->variables == NULL) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2419 return NGX_ERROR; |
509 | 2420 } |
2421 } | |
2422 | |
553 | 2423 name = params[NGX_HTTP_SSI_SET_VAR]; |
2424 value = params[NGX_HTTP_SSI_SET_VALUE]; | |
2425 | |
643 | 2426 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2427 "ssi set \"%V\" \"%V\"", name, value); | |
2428 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2429 rc = ngx_http_ssi_evaluate_string(r, ctx, value, 0); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2430 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2431 if (rc != NGX_OK) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2432 return rc; |
509 | 2433 } |
2434 | |
2136 | 2435 key = ngx_hash_strlow(name->data, name->data, name->len); |
611 | 2436 |
2437 vv = ngx_http_ssi_get_variable(r, name, key); | |
553 | 2438 |
2439 if (vv) { | |
2440 *vv = *value; | |
2441 return NGX_OK; | |
2442 } | |
2443 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2444 var = ngx_list_push(mctx->variables); |
553 | 2445 if (var == NULL) { |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2446 return NGX_ERROR; |
553 | 2447 } |
2448 | |
2449 var->name = *name; | |
611 | 2450 var->key = key; |
553 | 2451 var->value = *value; |
2452 | |
2453 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2454 "set: \"%V\"=\"%V\"", name, value); | |
2455 | |
509 | 2456 return NGX_OK; |
2457 } | |
2458 | |
2459 | |
2460 static ngx_int_t | |
2461 ngx_http_ssi_if(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2462 ngx_str_t **params) | |
2463 { | |
553 | 2464 u_char *p, *last; |
2465 ngx_str_t *expr, left, right; | |
2466 ngx_int_t rc; | |
629 | 2467 ngx_uint_t negative, noregex, flags; |
509 | 2468 |
629 | 2469 if (ctx->command.len == 2) { |
2470 if (ctx->conditional) { | |
2471 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2472 "the \"if\" command inside the \"if\" command"); | |
2473 return NGX_HTTP_SSI_ERROR; | |
2474 } | |
2475 } | |
2476 | |
2477 if (ctx->output_chosen) { | |
2478 ctx->output = 0; | |
2479 return NGX_OK; | |
2480 } | |
2481 | |
509 | 2482 expr = params[NGX_HTTP_SSI_IF_EXPR]; |
2483 | |
643 | 2484 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2485 "ssi if expr=\"%V\"", expr); | |
2486 | |
553 | 2487 left.data = expr->data; |
551 | 2488 last = expr->data + expr->len; |
2489 | |
553 | 2490 for (p = left.data; p < last; p++) { |
551 | 2491 if (*p >= 'A' && *p <= 'Z') { |
2492 *p |= 0x20; | |
2493 continue; | |
2494 } | |
509 | 2495 |
553 | 2496 if ((*p >= 'a' && *p <= 'z') |
2497 || (*p >= '0' && *p <= '9') | |
573 | 2498 || *p == '$' || *p == '{' || *p == '}' || *p == '_' |
2499 || *p == '"' || *p == '\'') | |
553 | 2500 { |
551 | 2501 continue; |
2502 } | |
2503 | |
2504 break; | |
2505 } | |
2506 | |
553 | 2507 left.len = p - left.data; |
551 | 2508 |
2509 while (p < last && *p == ' ') { | |
2510 p++; | |
509 | 2511 } |
2512 | |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3495
diff
changeset
|
2513 flags = 0; |
635 | 2514 |
553 | 2515 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2516 "left: \"%V\"", &left); | |
2517 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2518 rc = ngx_http_ssi_evaluate_string(r, ctx, &left, flags); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2519 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2520 if (rc != NGX_OK) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2521 return rc; |
509 | 2522 } |
2523 | |
553 | 2524 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2525 "evaluted left: \"%V\"", &left); | |
2526 | |
551 | 2527 if (p == last) { |
553 | 2528 if (left.len) { |
551 | 2529 ctx->output = 1; |
629 | 2530 ctx->output_chosen = 1; |
551 | 2531 |
2532 } else { | |
2533 ctx->output = 0; | |
2534 } | |
2535 | |
629 | 2536 ctx->conditional = NGX_HTTP_SSI_COND_IF; |
2537 | |
551 | 2538 return NGX_OK; |
2539 } | |
2540 | |
2541 if (p < last && *p == '=') { | |
2542 negative = 0; | |
2543 p++; | |
2544 | |
2545 } else if (p + 1 < last && *p == '!' && *(p + 1) == '=') { | |
2546 negative = 1; | |
2547 p += 2; | |
2548 | |
2549 } else { | |
2550 goto invalid_expression; | |
2551 } | |
2552 | |
2553 while (p < last && *p == ' ') { | |
2554 p++; | |
2555 } | |
2556 | |
1190
99c56c0f514e
fix segfault or parsing error in '<!--# if expr="$var = /" -->'
Igor Sysoev <igor@sysoev.ru>
parents:
1169
diff
changeset
|
2557 if (p < last - 1 && *p == '/') { |
551 | 2558 if (*(last - 1) != '/') { |
2559 goto invalid_expression; | |
2560 } | |
2561 | |
2562 noregex = 0; | |
629 | 2563 flags = NGX_HTTP_SSI_ADD_ZERO; |
551 | 2564 last--; |
1025 | 2565 p++; |
551 | 2566 |
2567 } else { | |
2568 noregex = 1; | |
629 | 2569 flags = 0; |
2570 | |
2571 if (p < last - 1 && p[0] == '\\' && p[1] == '/') { | |
651 | 2572 p++; |
629 | 2573 } |
551 | 2574 } |
2575 | |
2576 right.len = last - p; | |
2577 right.data = p; | |
2578 | |
553 | 2579 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2580 "right: \"%V\"", &right); | |
2581 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2582 rc = ngx_http_ssi_evaluate_string(r, ctx, &right, flags); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2583 |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2584 if (rc != NGX_OK) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
767
diff
changeset
|
2585 return rc; |
551 | 2586 } |
2587 | |
553 | 2588 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2589 "evaluted right: \"%V\"", &right); | |
551 | 2590 |
2591 if (noregex) { | |
2592 if (left.len != right.len) { | |
2593 rc = -1; | |
2594 | |
2595 } else { | |
2596 rc = ngx_strncmp(left.data, right.data, right.len); | |
2597 } | |
2598 | |
2599 } else { | |
2600 right.data[right.len] = '\0'; | |
2601 | |
4381
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2602 rc = ngx_http_ssi_regex_match(r, &right, &left); |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2603 |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2604 if (rc == NGX_OK) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2605 rc = 0; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2606 } else if (rc == NGX_DECLINED) { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2607 rc = -1; |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2608 } else { |
e9a0427f4139
SSI: added regex captures support in the expression of the "if" command.
Valentin Bartenev <vbart@nginx.com>
parents:
4374
diff
changeset
|
2609 return rc; |
551 | 2610 } |
2611 } | |
2612 | |
2613 if ((rc == 0 && !negative) || (rc != 0 && negative)) { | |
509 | 2614 ctx->output = 1; |
629 | 2615 ctx->output_chosen = 1; |
509 | 2616 |
2617 } else { | |
2618 ctx->output = 0; | |
2619 } | |
2620 | |
629 | 2621 ctx->conditional = NGX_HTTP_SSI_COND_IF; |
2622 | |
509 | 2623 return NGX_OK; |
551 | 2624 |
2625 invalid_expression: | |
2626 | |
2627 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2628 "invalid expression in \"%V\"", expr); | |
2629 | |
2630 return NGX_HTTP_SSI_ERROR; | |
509 | 2631 } |
2632 | |
2633 | |
2634 static ngx_int_t | |
2635 ngx_http_ssi_else(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2636 ngx_str_t **params) | |
2637 { | |
643 | 2638 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2639 "ssi else"); | |
2640 | |
629 | 2641 if (ctx->output_chosen) { |
2642 ctx->output = 0; | |
2643 } else { | |
2644 ctx->output = 1; | |
2645 } | |
2646 | |
2647 ctx->conditional = NGX_HTTP_SSI_COND_ELSE; | |
509 | 2648 |
2649 return NGX_OK; | |
2650 } | |
2651 | |
2652 | |
2653 static ngx_int_t | |
2654 ngx_http_ssi_endif(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2655 ngx_str_t **params) | |
2656 { | |
643 | 2657 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2658 "ssi endif"); | |
2659 | |
509 | 2660 ctx->output = 1; |
629 | 2661 ctx->output_chosen = 0; |
2662 ctx->conditional = 0; | |
509 | 2663 |
2664 return NGX_OK; | |
2665 } | |
2666 | |
2667 | |
573 | 2668 static ngx_int_t |
667 | 2669 ngx_http_ssi_block(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
2670 ngx_str_t **params) | |
2671 { | |
2672 ngx_http_ssi_ctx_t *mctx; | |
2673 ngx_http_ssi_block_t *bl; | |
2674 | |
2675 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2676 "ssi block"); | |
2677 | |
2678 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
2679 | |
2680 if (mctx->blocks == NULL) { | |
2681 mctx->blocks = ngx_array_create(r->pool, 4, | |
2682 sizeof(ngx_http_ssi_block_t)); | |
2683 if (mctx->blocks == NULL) { | |
2684 return NGX_HTTP_SSI_ERROR; | |
2685 } | |
2686 } | |
2687 | |
2688 bl = ngx_array_push(mctx->blocks); | |
2689 if (bl == NULL) { | |
2690 return NGX_HTTP_SSI_ERROR; | |
2691 } | |
2692 | |
2693 bl->name = *params[NGX_HTTP_SSI_BLOCK_NAME]; | |
2694 bl->bufs = NULL; | |
2695 bl->count = 0; | |
2696 | |
2697 ctx->output = 0; | |
2698 ctx->block = 1; | |
2699 | |
2700 return NGX_OK; | |
2701 } | |
2702 | |
2703 | |
2704 static ngx_int_t | |
2705 ngx_http_ssi_endblock(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2706 ngx_str_t **params) | |
2707 { | |
2708 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2709 "ssi endblock"); | |
2710 | |
2711 ctx->output = 1; | |
2712 ctx->block = 0; | |
2713 | |
2714 return NGX_OK; | |
2715 } | |
2716 | |
2717 | |
2718 static ngx_int_t | |
573 | 2719 ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, |
2041 | 2720 ngx_http_variable_value_t *v, uintptr_t gmt) |
509 | 2721 { |
573 | 2722 ngx_http_ssi_ctx_t *ctx; |
2723 ngx_time_t *tp; | |
5540
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
2724 ngx_str_t *timefmt; |
573 | 2725 struct tm tm; |
2726 char buf[NGX_HTTP_SSI_DATE_LEN]; | |
2727 | |
577 | 2728 v->valid = 1; |
1565 | 2729 v->no_cacheable = 0; |
573 | 2730 v->not_found = 0; |
509 | 2731 |
563 | 2732 tp = ngx_timeofday(); |
2733 | |
509 | 2734 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); |
2735 | |
5540
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
2736 timefmt = ctx ? &ctx->timefmt : &ngx_http_ssi_timefmt; |
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
2737 |
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
2738 if (timefmt->len == sizeof("%s") - 1 |
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
2739 && timefmt->data[0] == '%' && timefmt->data[1] == 's') |
509 | 2740 { |
2049 | 2741 v->data = ngx_pnalloc(r->pool, NGX_TIME_T_LEN); |
573 | 2742 if (v->data == NULL) { |
2743 return NGX_ERROR; | |
509 | 2744 } |
2745 | |
3454
04966b3122ab
SSI %s timefmt has no timezone offset
Igor Sysoev <igor@sysoev.ru>
parents:
3453
diff
changeset
|
2746 v->len = ngx_sprintf(v->data, "%T", tp->sec) - v->data; |
657 | 2747 |
573 | 2748 return NGX_OK; |
509 | 2749 } |
2750 | |
2751 if (gmt) { | |
563 | 2752 ngx_libc_gmtime(tp->sec, &tm); |
509 | 2753 } else { |
563 | 2754 ngx_libc_localtime(tp->sec, &tm); |
509 | 2755 } |
2756 | |
573 | 2757 v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN, |
5540
3a8e19528b30
SSI: fixed $date_local and $date_gmt without SSI (ticket #230).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5491
diff
changeset
|
2758 (char *) timefmt->data, &tm); |
573 | 2759 if (v->len == 0) { |
2760 return NGX_ERROR; | |
509 | 2761 } |
2762 | |
2049 | 2763 v->data = ngx_pnalloc(r->pool, v->len); |
573 | 2764 if (v->data == NULL) { |
2765 return NGX_ERROR; | |
509 | 2766 } |
2767 | |
573 | 2768 ngx_memcpy(v->data, buf, v->len); |
2769 | |
2770 return NGX_OK; | |
509 | 2771 } |
2772 | |
2773 | |
2774 static ngx_int_t | |
597 | 2775 ngx_http_ssi_preconfiguration(ngx_conf_t *cf) |
509 | 2776 { |
597 | 2777 ngx_int_t rc; |
2778 ngx_http_variable_t *var, *v; | |
2779 ngx_http_ssi_command_t *cmd; | |
2780 ngx_http_ssi_main_conf_t *smcf; | |
509 | 2781 |
2782 for (v = ngx_http_ssi_vars; v->name.len; v++) { | |
2783 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
2784 if (var == NULL) { | |
2785 return NGX_ERROR; | |
2786 } | |
2787 | |
637 | 2788 var->get_handler = v->get_handler; |
509 | 2789 var->data = v->data; |
2790 } | |
2791 | |
597 | 2792 smcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_ssi_filter_module); |
2793 | |
2794 for (cmd = ngx_http_ssi_commands; cmd->name.len; cmd++) { | |
2795 rc = ngx_hash_add_key(&smcf->commands, &cmd->name, cmd, | |
2796 NGX_HASH_READONLY_KEY); | |
2797 | |
2798 if (rc == NGX_OK) { | |
2799 continue; | |
2800 } | |
2801 | |
2802 if (rc == NGX_BUSY) { | |
2803 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2804 "conflicting SSI command \"%V\"", &cmd->name); | |
2805 } | |
2806 | |
2807 return NGX_ERROR; | |
2808 } | |
2809 | |
577 | 2810 return NGX_OK; |
509 | 2811 } |
2812 | |
2813 | |
497 | 2814 static void * |
597 | 2815 ngx_http_ssi_create_main_conf(ngx_conf_t *cf) |
2816 { | |
2817 ngx_http_ssi_main_conf_t *smcf; | |
2818 | |
2819 smcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_main_conf_t)); | |
2820 if (smcf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2821 return NULL; |
597 | 2822 } |
2823 | |
2824 smcf->commands.pool = cf->pool; | |
2825 smcf->commands.temp_pool = cf->temp_pool; | |
2826 | |
2827 if (ngx_hash_keys_array_init(&smcf->commands, NGX_HASH_SMALL) != NGX_OK) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2828 return NULL; |
597 | 2829 } |
2830 | |
2831 return smcf; | |
2832 } | |
2833 | |
2834 | |
2835 static char * | |
2836 ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf) | |
2837 { | |
2838 ngx_http_ssi_main_conf_t *smcf = conf; | |
2839 | |
2840 ngx_hash_init_t hash; | |
2841 | |
2842 hash.hash = &smcf->hash; | |
2843 hash.key = ngx_hash_key; | |
2844 hash.max_size = 1024; | |
2845 hash.bucket_size = ngx_cacheline_size; | |
2846 hash.name = "ssi_command_hash"; | |
2847 hash.pool = cf->pool; | |
2848 hash.temp_pool = NULL; | |
2849 | |
2850 if (ngx_hash_init(&hash, smcf->commands.keys.elts, | |
2851 smcf->commands.keys.nelts) | |
2852 != NGX_OK) | |
2853 { | |
2854 return NGX_CONF_ERROR; | |
2855 } | |
2856 | |
2857 return NGX_CONF_OK; | |
2858 } | |
2859 | |
2860 | |
2861 static void * | |
1169 | 2862 ngx_http_ssi_create_loc_conf(ngx_conf_t *cf) |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2863 { |
597 | 2864 ngx_http_ssi_loc_conf_t *slcf; |
2865 | |
2866 slcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_loc_conf_t)); | |
2867 if (slcf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
2868 return NULL; |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2869 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2870 |
527 | 2871 /* |
2872 * set by ngx_pcalloc(): | |
2873 * | |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
2874 * conf->types = { NULL }; |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
2875 * conf->types_keys = NULL; |
527 | 2876 */ |
2877 | |
597 | 2878 slcf->enable = NGX_CONF_UNSET; |
2879 slcf->silent_errors = NGX_CONF_UNSET; | |
2880 slcf->ignore_recycled_buffers = NGX_CONF_UNSET; | |
5228
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
2881 slcf->last_modified = NGX_CONF_UNSET; |
597 | 2882 |
2883 slcf->min_file_chunk = NGX_CONF_UNSET_SIZE; | |
2884 slcf->value_len = NGX_CONF_UNSET_SIZE; | |
2885 | |
2886 return slcf; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2887 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2888 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2889 |
497 | 2890 static char * |
1169 | 2891 ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2892 { |
597 | 2893 ngx_http_ssi_loc_conf_t *prev = parent; |
2894 ngx_http_ssi_loc_conf_t *conf = child; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2895 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2896 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
497 | 2897 ngx_conf_merge_value(conf->silent_errors, prev->silent_errors, 0); |
509 | 2898 ngx_conf_merge_value(conf->ignore_recycled_buffers, |
2899 prev->ignore_recycled_buffers, 0); | |
5228
cbd4bbe976d4
SSI: ssi_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4821
diff
changeset
|
2900 ngx_conf_merge_value(conf->last_modified, prev->last_modified, 0); |
497 | 2901 |
2902 ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024); | |
4528
00ccad19c53d
Fixed ssi and perl interaction.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
2903 ngx_conf_merge_size_value(conf->value_len, prev->value_len, 255); |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2904 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2905 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types, |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2906 &prev->types_keys, &prev->types, |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
2907 ngx_http_html_default_types) |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
2908 != NGX_OK) |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
2909 { |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
2910 return NGX_CONF_ERROR; |
527 | 2911 } |
2912 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2913 return NGX_CONF_OK; |
15
cbb38b60495c
nginx-0.0.1-2002-09-18-20:32:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
14
diff
changeset
|
2914 } |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2915 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2916 |
497 | 2917 static ngx_int_t |
681 | 2918 ngx_http_ssi_filter_init(ngx_conf_t *cf) |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
2919 { |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2920 ngx_http_next_header_filter = ngx_http_top_header_filter; |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
2921 ngx_http_top_header_filter = ngx_http_ssi_header_filter; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2922 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2923 ngx_http_next_body_filter = ngx_http_top_body_filter; |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
2924 ngx_http_top_body_filter = ngx_http_ssi_body_filter; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2925 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
2926 return NGX_OK; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2927 } |