Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_ssi_filter_module.c @ 629:65bf042c0b4f release-0.3.36
nginx-0.3.36-RELEASE import
*) Feature: the ngx_http_addition_filter_module.
*) Feature: the "proxy_pass" and "fastcgi_pass" directives may be used
inside the "if" block.
*) Feature: the "proxy_ignore_client_abort" and
"fastcgi_ignore_client_abort" directives.
*) Feature: the "$request_completion" variable.
*) Feature: the ngx_http_perl_module supports the $r->request_method
and $r->remote_addr.
*) Feature: the ngx_http_ssi_module supports the "elif" command.
*) Bugfix: the "\/" string in the expression of the "if" command of the
ngx_http_ssi_module was treated incorrectly.
*) Bugfix: in the regular expressions in the "if" command of the
ngx_http_ssi_module.
*) Bugfix: if the relative path was specified in the
"client_body_temp_path", "proxy_temp_path", "fastcgi_temp_path", and
"perl_modules" directives, then the directory was used relatively to
a current path but not to a server prefix.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 05 Apr 2006 13:40:54 +0000 |
parents | 3f8a2132b93d |
children | 18268abd340c |
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 |
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
|
4 */ |
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 |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #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
|
10 |
553 | 11 #define NGX_HTTP_SSI_ERROR 1 |
12 | |
13 #define NGX_HTTP_SSI_DATE_LEN 2048 | |
14 | |
15 #define NGX_HTTP_SSI_ADD_PREFIX 1 | |
629 | 16 #define NGX_HTTP_SSI_ADD_ZERO 2 |
509 | 17 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
18 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
19 typedef struct { |
597 | 20 ngx_flag_t enable; |
21 ngx_flag_t silent_errors; | |
22 ngx_flag_t ignore_recycled_buffers; | |
23 | |
24 ngx_array_t *types; /* array of ngx_str_t */ | |
25 | |
26 size_t min_file_chunk; | |
27 size_t value_len; | |
28 } ngx_http_ssi_loc_conf_t; | |
553 | 29 |
30 | |
31 typedef struct { | |
597 | 32 ngx_str_t name; |
611 | 33 ngx_uint_t key; |
597 | 34 ngx_str_t value; |
35 } 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
|
36 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
37 |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
38 typedef enum { |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
39 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
|
40 ssi_tag_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
41 ssi_comment0_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
42 ssi_comment1_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
43 ssi_sharp_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
44 ssi_precommand_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
45 ssi_command_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
46 ssi_preparam_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
47 ssi_param_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
48 ssi_preequal_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
49 ssi_prevalue_state, |
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
50 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
|
51 ssi_quoted_value_state, |
497 | 52 ssi_quoted_symbol_state, |
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 } 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
|
60 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
509 | 62 static ngx_int_t ngx_http_ssi_output(ngx_http_request_t *r, |
63 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
|
64 static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, |
497 | 65 ngx_http_ssi_ctx_t *ctx); |
553 | 66 static ngx_str_t *ngx_http_ssi_get_variable(ngx_http_request_t *r, |
611 | 67 ngx_str_t *name, ngx_uint_t key); |
553 | 68 static ngx_int_t ngx_http_ssi_evaluate_string(ngx_http_request_t *r, |
69 ngx_http_ssi_ctx_t *ctx, ngx_str_t *text, ngx_uint_t flags); | |
70 | |
71 static ngx_int_t ngx_http_ssi_include(ngx_http_request_t *r, | |
72 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
|
73 static ngx_int_t ngx_http_ssi_echo(ngx_http_request_t *r, |
497 | 74 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
509 | 75 static ngx_int_t ngx_http_ssi_config(ngx_http_request_t *r, |
76 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
553 | 77 static ngx_int_t ngx_http_ssi_set(ngx_http_request_t *r, |
509 | 78 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
79 static ngx_int_t ngx_http_ssi_if(ngx_http_request_t *r, | |
80 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
81 static ngx_int_t ngx_http_ssi_else(ngx_http_request_t *r, | |
82 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | |
83 static ngx_int_t ngx_http_ssi_endif(ngx_http_request_t *r, | |
84 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
|
85 |
573 | 86 static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, |
87 ngx_http_variable_value_t *v, uintptr_t gmt); | |
509 | 88 |
527 | 89 static char *ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
90 | |
597 | 91 static ngx_int_t ngx_http_ssi_preconfiguration(ngx_conf_t *cf); |
92 static void *ngx_http_ssi_create_main_conf(ngx_conf_t *cf); | |
93 static char *ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf); | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
94 static void *ngx_http_ssi_create_conf(ngx_conf_t *cf); |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
95 static char *ngx_http_ssi_merge_conf(ngx_conf_t *cf, |
497 | 96 void *parent, void *child); |
97 static ngx_int_t ngx_http_ssi_filter_init(ngx_cycle_t *cycle); | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
98 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
99 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
100 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
|
101 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
102 { ngx_string("ssi"), |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
103 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
104 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
|
105 NGX_HTTP_LOC_CONF_OFFSET, |
597 | 106 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
|
107 NULL }, |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
108 |
497 | 109 { ngx_string("ssi_silent_errors"), |
110 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
111 ngx_conf_set_flag_slot, | |
112 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 113 offsetof(ngx_http_ssi_loc_conf_t, silent_errors), |
497 | 114 NULL }, |
115 | |
509 | 116 { ngx_string("ssi_ignore_recycled_buffers"), |
117 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
118 ngx_conf_set_flag_slot, | |
119 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 120 offsetof(ngx_http_ssi_loc_conf_t, ignore_recycled_buffers), |
509 | 121 NULL }, |
122 | |
497 | 123 { ngx_string("ssi_min_file_chunk"), |
124 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
125 ngx_conf_set_size_slot, | |
126 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 127 offsetof(ngx_http_ssi_loc_conf_t, min_file_chunk), |
497 | 128 NULL }, |
129 | |
589 | 130 { ngx_string("ssi_value_length"), |
131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
132 ngx_conf_set_size_slot, | |
133 NGX_HTTP_LOC_CONF_OFFSET, | |
597 | 134 offsetof(ngx_http_ssi_loc_conf_t, value_len), |
589 | 135 NULL }, |
136 | |
527 | 137 { ngx_string("ssi_types"), |
138 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
139 ngx_http_ssi_types, | |
140 NGX_HTTP_LOC_CONF_OFFSET, | |
141 0, | |
142 NULL }, | |
143 | |
497 | 144 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
|
145 }; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
146 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
147 |
577 | 148 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
149 static ngx_http_module_t ngx_http_ssi_filter_module_ctx = { |
597 | 150 ngx_http_ssi_preconfiguration, /* preconfiguration */ |
509 | 151 NULL, /* postconfiguration */ |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
152 |
597 | 153 ngx_http_ssi_create_main_conf, /* create main configuration */ |
154 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
|
155 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
156 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
|
157 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
|
158 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
159 ngx_http_ssi_create_conf, /* create location configuration */ |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
160 ngx_http_ssi_merge_conf /* merge location configuration */ |
577 | 161 }; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
164 ngx_module_t ngx_http_ssi_filter_module = { |
509 | 165 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
|
166 &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
|
167 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
|
168 NGX_HTTP_MODULE, /* module type */ |
541 | 169 NULL, /* init master */ |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
170 ngx_http_ssi_filter_init, /* init module */ |
541 | 171 NULL, /* init process */ |
172 NULL, /* init thread */ | |
173 NULL, /* exit thread */ | |
174 NULL, /* exit process */ | |
175 NULL, /* exit master */ | |
176 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
|
177 }; |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 |
569 | 180 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
181 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
497 | 182 |
183 | |
184 static u_char ngx_http_ssi_string[] = "<!--"; | |
185 | |
186 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); | |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
187 |
553 | 188 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 |
189 #define NGX_HTTP_SSI_INCLUDE_FILE 1 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
190 |
509 | 191 #define NGX_HTTP_SSI_ECHO_VAR 0 |
192 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 | |
193 | |
547 | 194 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 |
195 #define NGX_HTTP_SSI_CONFIG_TIMEFMT 1 | |
509 | 196 |
553 | 197 #define NGX_HTTP_SSI_SET_VAR 0 |
198 #define NGX_HTTP_SSI_SET_VALUE 1 | |
509 | 199 |
200 #define NGX_HTTP_SSI_IF_EXPR 0 | |
201 | |
497 | 202 |
553 | 203 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = { |
597 | 204 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 }, |
205 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 }, | |
206 { ngx_null_string, 0, 0, 0 } | |
553 | 207 }; |
208 | |
209 | |
497 | 210 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = { |
597 | 211 { ngx_string("var"), NGX_HTTP_SSI_ECHO_VAR, 1, 0 }, |
212 { ngx_string("default"), NGX_HTTP_SSI_ECHO_DEFAULT, 0, 0 }, | |
213 { ngx_null_string, 0, 0, 0 } | |
497 | 214 }; |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
215 |
509 | 216 |
217 static ngx_http_ssi_param_t ngx_http_ssi_config_params[] = { | |
597 | 218 { ngx_string("errmsg"), NGX_HTTP_SSI_CONFIG_ERRMSG, 0, 0 }, |
219 { ngx_string("timefmt"), NGX_HTTP_SSI_CONFIG_TIMEFMT, 0, 0 }, | |
220 { ngx_null_string, 0, 0, 0 } | |
509 | 221 }; |
222 | |
223 | |
553 | 224 static ngx_http_ssi_param_t ngx_http_ssi_set_params[] = { |
597 | 225 { ngx_string("var"), NGX_HTTP_SSI_SET_VAR, 1, 0 }, |
226 { ngx_string("value"), NGX_HTTP_SSI_SET_VALUE, 1, 0 }, | |
227 { ngx_null_string, 0, 0, 0 } | |
553 | 228 }; |
229 | |
230 | |
509 | 231 static ngx_http_ssi_param_t ngx_http_ssi_if_params[] = { |
597 | 232 { ngx_string("expr"), NGX_HTTP_SSI_IF_EXPR, 1, 0 }, |
233 { ngx_null_string, 0, 0, 0 } | |
509 | 234 }; |
235 | |
236 | |
237 static ngx_http_ssi_param_t ngx_http_ssi_no_params[] = { | |
597 | 238 { ngx_null_string, 0, 0, 0 } |
509 | 239 }; |
240 | |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
241 |
497 | 242 static ngx_http_ssi_command_t ngx_http_ssi_commands[] = { |
553 | 243 { ngx_string("include"), ngx_http_ssi_include, |
244 ngx_http_ssi_include_params, 0, 1 }, | |
509 | 245 { ngx_string("echo"), ngx_http_ssi_echo, ngx_http_ssi_echo_params, 0, 0 }, |
246 { ngx_string("config"), ngx_http_ssi_config, | |
247 ngx_http_ssi_config_params, 0, 0 }, | |
553 | 248 { ngx_string("set"), ngx_http_ssi_set, ngx_http_ssi_set_params, 0, 0 }, |
509 | 249 |
250 { ngx_string("if"), ngx_http_ssi_if, ngx_http_ssi_if_params, 0, 0 }, | |
629 | 251 { ngx_string("elif"), ngx_http_ssi_if, ngx_http_ssi_if_params, |
252 NGX_HTTP_SSI_COND_IF, 0 }, | |
253 { ngx_string("else"), ngx_http_ssi_else, ngx_http_ssi_no_params, | |
254 NGX_HTTP_SSI_COND_IF, 0 }, | |
255 { ngx_string("endif"), ngx_http_ssi_endif, ngx_http_ssi_no_params, | |
256 NGX_HTTP_SSI_COND_ELSE, 0 }, | |
509 | 257 |
258 { ngx_null_string, NULL, NULL, 0, 0 } | |
497 | 259 }; |
260 | |
261 | |
509 | 262 static ngx_http_variable_t ngx_http_ssi_vars[] = { |
263 | |
264 { ngx_string("date_local"), ngx_http_ssi_date_gmt_local_variable, 0, | |
533 | 265 NGX_HTTP_VAR_NOCACHABLE, 0 }, |
509 | 266 |
267 { ngx_string("date_gmt"), ngx_http_ssi_date_gmt_local_variable, 1, | |
533 | 268 NGX_HTTP_VAR_NOCACHABLE, 0 }, |
509 | 269 |
533 | 270 { ngx_null_string, NULL, 0, 0, 0 } |
509 | 271 }; |
272 | |
273 | |
274 | |
497 | 275 static ngx_int_t |
276 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
|
277 { |
597 | 278 ngx_uint_t i; |
279 ngx_str_t *type; | |
280 ngx_http_ssi_ctx_t *ctx; | |
281 ngx_http_ssi_loc_conf_t *slcf; | |
282 | |
283 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module); | |
284 | |
285 if (!slcf->enable | |
577 | 286 || r->headers_out.content_type.len == 0 |
287 || r->headers_out.content_length_n == 0) | |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
288 { |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
289 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
|
290 } |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
291 |
497 | 292 |
597 | 293 type = slcf->types->elts; |
294 for (i = 0; i < slcf->types->nelts; i++) { | |
527 | 295 if (r->headers_out.content_type.len >= type[i].len |
296 && ngx_strncasecmp(r->headers_out.content_type.data, | |
297 type[i].data, type[i].len) == 0) | |
298 { | |
299 goto found; | |
300 } | |
301 } | |
302 | |
303 return ngx_http_next_header_filter(r); | |
304 | |
305 | |
306 found: | |
307 | |
499 | 308 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t)); |
309 if (ctx == NULL) { | |
497 | 310 return NGX_ERROR; |
311 } | |
312 | |
313 ngx_http_set_ctx(r, ctx, ngx_http_ssi_filter_module); | |
314 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
315 |
597 | 316 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
|
317 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
|
318 |
509 | 319 ctx->output = 1; |
320 | |
497 | 321 ctx->params.elts = ctx->params_array; |
322 ctx->params.size = sizeof(ngx_table_elt_t); | |
323 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N; | |
324 ctx->params.pool = r->pool; | |
325 | |
509 | 326 ctx->timefmt.len = sizeof("%A, %d-%b-%Y %H:%M:%S %Z") - 1; |
327 ctx->timefmt.data = (u_char *) "%A, %d-%b-%Y %H:%M:%S %Z"; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
328 |
547 | 329 ctx->errmsg.len = |
330 sizeof("[an error occurred while processing the directive]") - 1; | |
331 ctx->errmsg.data = (u_char *) | |
332 "[an error occurred while processing the directive]"; | |
333 | |
497 | 334 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
|
335 |
597 | 336 if (r == r->main) { |
577 | 337 ngx_http_clear_content_length(r); |
338 ngx_http_clear_last_modified(r); | |
509 | 339 } |
340 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
341 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
|
342 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
343 |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
344 |
497 | 345 static ngx_int_t |
346 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
|
347 { |
597 | 348 ngx_int_t rc; |
349 ngx_buf_t *b; | |
350 ngx_uint_t i, index; | |
351 ngx_chain_t *cl; | |
352 ngx_table_elt_t *param; | |
353 ngx_connection_t *c; | |
354 ngx_http_ssi_ctx_t *ctx; | |
355 ngx_http_ssi_param_t *prm; | |
356 ngx_http_ssi_command_t *cmd; | |
357 ngx_http_ssi_loc_conf_t *slcf; | |
358 ngx_http_ssi_main_conf_t *smcf; | |
599 | 359 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
|
360 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
361 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
|
362 |
499 | 363 if (ctx == NULL || (in == NULL && ctx->in == NULL && ctx->busy == NULL)) { |
243
bf2faf694c19
nginx-0.0.1-2004-01-28-23:38:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
364 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
|
365 } |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
366 |
497 | 367 /* 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
|
368 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
369 if (in) { |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
370 if (ngx_chain_add_copy(r->pool, &ctx->in, in) == NGX_ERROR) { |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
371 return NGX_ERROR; |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
372 } |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
373 } |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
374 |
597 | 375 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
|
376 |
509 | 377 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
378 "http ssi filter \"%V\"", &r->uri); | |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
379 |
499 | 380 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
|
381 |
499 | 382 if (ctx->buf == NULL ){ |
383 ctx->buf = ctx->in->buf; | |
384 ctx->in = ctx->in->next; | |
385 ctx->pos = ctx->buf->pos; | |
386 } | |
497 | 387 |
388 if (ctx->state == ssi_start_state) { | |
389 ctx->copy_start = ctx->pos; | |
390 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
|
391 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
392 |
499 | 393 b = NULL; |
394 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
395 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
|
396 |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
397 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
|
398 "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
|
399 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
400 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
|
401 |
497 | 402 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
403 "parse: %d, looked: %d %p-%p", | |
404 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
|
405 |
497 | 406 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
|
407 return rc; |
497 | 408 } |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
409 |
497 | 410 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
|
411 |
509 | 412 if (ctx->output) { |
413 | |
414 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
415 "saved: %d", ctx->saved); | |
416 | |
417 if (ctx->saved) { | |
418 | |
419 if (ctx->free) { | |
420 cl = ctx->free; | |
421 ctx->free = ctx->free->next; | |
422 b = cl->buf; | |
423 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
|
424 |
509 | 425 } else { |
426 b = ngx_calloc_buf(r->pool); | |
427 if (b == NULL) { | |
428 return NGX_ERROR; | |
429 } | |
430 | |
431 cl = ngx_alloc_chain_link(r->pool); | |
432 if (cl == NULL) { | |
433 return NGX_ERROR; | |
434 } | |
435 | |
436 cl->buf = b; | |
437 } | |
438 | |
439 b->memory = 1; | |
440 b->pos = ngx_http_ssi_string; | |
441 b->last = ngx_http_ssi_string + ctx->saved; | |
442 | |
443 *ctx->last_out = cl; | |
444 ctx->last_out = &cl->next; | |
445 | |
446 ctx->saved = 0; | |
447 } | |
499 | 448 |
449 if (ctx->free) { | |
450 cl = ctx->free; | |
451 ctx->free = ctx->free->next; | |
452 b = cl->buf; | |
453 | |
454 } else { | |
509 | 455 b = ngx_alloc_buf(r->pool); |
499 | 456 if (b == NULL) { |
457 return NGX_ERROR; | |
458 } | |
459 | |
460 cl = ngx_alloc_chain_link(r->pool); | |
461 if (cl == NULL) { | |
462 return NGX_ERROR; | |
463 } | |
464 | |
465 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
|
466 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
467 |
509 | 468 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t)); |
469 | |
513 | 470 b->pos = ctx->copy_start; |
471 b->last = ctx->copy_end; | |
472 b->shadow = NULL; | |
509 | 473 b->last_buf = 0; |
474 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
|
475 |
509 | 476 if (b->in_file) { |
597 | 477 if (slcf->min_file_chunk < (size_t) (b->last - b->pos)) |
509 | 478 { |
479 b->file_last = b->file_pos + (b->last - b->start); | |
480 b->file_pos += b->pos - b->start; | |
481 | |
482 } else { | |
483 b->in_file = 0; | |
484 } | |
485 } | |
486 | |
487 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
|
488 *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
|
489 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
|
490 |
509 | 491 } else { |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
492 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
|
493 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
494 } |
497 | 495 |
496 if (ctx->state == ssi_start_state) { | |
497 ctx->copy_start = ctx->pos; | |
498 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
|
499 |
497 | 500 } else { |
501 ctx->copy_start = NULL; | |
502 ctx->copy_end = NULL; | |
503 } | |
504 | |
505 if (rc == NGX_AGAIN) { | |
506 continue; | |
507 } | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
508 |
497 | 509 |
573 | 510 b = NULL; |
511 | |
497 | 512 if (rc == NGX_OK) { |
513 | |
597 | 514 smcf = ngx_http_get_module_main_conf(r, |
515 ngx_http_ssi_filter_module); | |
516 | |
517 cmd = ngx_hash_find(&smcf->hash, ctx->key, ctx->command.data, | |
518 ctx->command.len); | |
519 | |
520 if (cmd == NULL) { | |
521 if (ctx->output) { | |
522 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
523 "invalid SSI command: \"%V\"", | |
524 &ctx->command); | |
525 goto ssi_error; | |
497 | 526 } |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
527 |
597 | 528 continue; |
497 | 529 } |
530 | |
629 | 531 if (cmd->conditional |
532 && (ctx->conditional == 0 | |
533 || ctx->conditional > cmd->conditional)) | |
534 { | |
535 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
536 "invalid context of SSI command: \"%V\"", | |
537 &ctx->command); | |
538 goto ssi_error; | |
539 } | |
540 | |
541 if (!ctx->output && cmd->conditional == 0) { | |
509 | 542 continue; |
543 } | |
544 | |
597 | 545 if (ctx->params.nelts > NGX_HTTP_SSI_MAX_PARAMS) { |
546 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
547 "too many SSI command paramters: \"%V\"", | |
548 &ctx->command); | |
549 goto ssi_error; | |
550 } | |
551 | |
497 | 552 ngx_memzero(params, |
599 | 553 (NGX_HTTP_SSI_MAX_PARAMS + 1) * sizeof(ngx_str_t *)); |
497 | 554 |
555 param = ctx->params.elts; | |
556 | |
557 for (i = 0; i < ctx->params.nelts; i++) { | |
558 | |
559 for (prm = cmd->params; prm->name.len; prm++) { | |
560 | |
561 if (param[i].key.len != prm->name.len | |
562 || ngx_strncmp(param[i].key.data, prm->name.data, | |
563 prm->name.len) != 0) | |
564 { | |
565 continue; | |
566 } | |
567 | |
597 | 568 if (!prm->multiple) { |
569 if (params[prm->index]) { | |
570 ngx_log_error(NGX_LOG_ERR, | |
571 r->connection->log, 0, | |
572 "duplicate \"%V\" parameter " | |
573 "in \"%V\" SSI command", | |
574 ¶m[i].key, &ctx->command); | |
575 | |
576 goto ssi_error; | |
577 } | |
578 | |
579 params[prm->index] = ¶m[i].value; | |
580 | |
581 break; | |
497 | 582 } |
583 | |
597 | 584 for (index = prm->index; params[index]; index++) { |
585 /* void */ | |
586 } | |
587 | |
588 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
|
589 |
497 | 590 break; |
591 } | |
592 | |
593 if (prm->name.len == 0) { | |
594 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
595 "invalid parameter name: \"%V\" " | |
596 "in \"%V\" SSI command", | |
597 ¶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
|
598 |
497 | 599 goto ssi_error; |
600 } | |
601 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
602 |
497 | 603 for (prm = cmd->params; prm->name.len; prm++) { |
604 if (prm->mandatory && params[prm->index] == 0) { | |
605 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
606 "mandatory \"%V\" parameter is absent " | |
607 "in \"%V\" SSI command", | |
608 &prm->name, &ctx->command); | |
609 | |
610 goto ssi_error; | |
611 } | |
612 } | |
613 | |
509 | 614 if (cmd->flush && ctx->out) { |
615 rc = ngx_http_ssi_output(r, ctx); | |
616 | |
617 if (rc == NGX_ERROR) { | |
618 return NGX_ERROR; | |
619 } | |
620 } | |
621 | |
569 | 622 c = r->connection; |
623 | |
624 rc = cmd->handler(r, ctx, params); | |
625 | |
583 | 626 if (c->destroyed) { |
569 | 627 return NGX_DONE; |
628 } | |
629 | |
630 if (rc == NGX_OK) { | |
497 | 631 continue; |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
632 } |
583 | 633 |
634 if (rc == NGX_ERROR) { | |
635 return NGX_ERROR; | |
636 } | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
637 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
638 |
497 | 639 |
640 /* rc == NGX_HTTP_SSI_ERROR */ | |
641 | |
499 | 642 ssi_error: |
497 | 643 |
597 | 644 if (slcf->silent_errors) { |
497 | 645 continue; |
646 } | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
647 |
499 | 648 if (ctx->free) { |
649 cl = ctx->free; | |
650 ctx->free = ctx->free->next; | |
651 b = cl->buf; | |
652 ngx_memzero(b, sizeof(ngx_buf_t)); | |
653 | |
654 } else { | |
655 b = ngx_calloc_buf(r->pool); | |
656 if (b == NULL) { | |
657 return NGX_ERROR; | |
658 } | |
659 | |
660 cl = ngx_alloc_chain_link(r->pool); | |
661 if (cl == NULL) { | |
662 return NGX_ERROR; | |
663 } | |
664 | |
665 cl->buf = b; | |
497 | 666 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
667 |
497 | 668 b->memory = 1; |
547 | 669 b->pos = ctx->errmsg.data; |
670 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
|
671 |
497 | 672 cl->next = NULL; |
673 *ctx->last_out = cl; | |
674 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
|
675 |
497 | 676 continue; |
677 } | |
678 | |
509 | 679 if (ctx->buf->last_buf || ctx->buf->recycled) { |
499 | 680 if (b == NULL) { |
681 if (ctx->free) { | |
682 cl = ctx->free; | |
683 ctx->free = ctx->free->next; | |
684 b = cl->buf; | |
685 ngx_memzero(b, sizeof(ngx_buf_t)); | |
686 | |
687 } else { | |
688 b = ngx_calloc_buf(r->pool); | |
689 if (b == NULL) { | |
690 return NGX_ERROR; | |
691 } | |
497 | 692 |
499 | 693 cl = ngx_alloc_chain_link(r->pool); |
694 if (cl == NULL) { | |
695 return NGX_ERROR; | |
696 } | |
697 | |
698 cl->buf = b; | |
699 } | |
700 | |
509 | 701 b->sync = 1; |
702 | |
499 | 703 cl->next = NULL; |
704 *ctx->last_out = cl; | |
705 ctx->last_out = &cl->next; | |
706 } | |
707 | |
708 b->last_buf = ctx->buf->last_buf; | |
709 b->shadow = ctx->buf; | |
509 | 710 |
597 | 711 if (slcf->ignore_recycled_buffers == 0) { |
509 | 712 b->recycled = ctx->buf->recycled; |
713 } | |
497 | 714 } |
715 | |
499 | 716 ctx->buf = NULL; |
717 | |
497 | 718 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
|
719 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
720 |
499 | 721 if (ctx->out == NULL && ctx->busy == NULL) { |
497 | 722 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
|
723 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
724 |
509 | 725 return ngx_http_ssi_output(r, ctx); |
726 } | |
727 | |
728 | |
729 static ngx_int_t | |
730 ngx_http_ssi_output(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx) | |
731 { | |
732 ngx_int_t rc; | |
733 ngx_buf_t *b; | |
734 ngx_chain_t *cl; | |
735 | |
497 | 736 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
|
737 |
499 | 738 if (ctx->busy == NULL) { |
739 ctx->busy = ctx->out; | |
740 | |
741 } else { | |
742 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ } | |
743 cl->next = ctx->out; | |
744 } | |
745 | |
497 | 746 ctx->out = NULL; |
747 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
|
748 |
499 | 749 while (ctx->busy) { |
750 | |
751 b = ctx->busy->buf; | |
752 | |
753 if (ngx_buf_size(b) != 0) { | |
754 break; | |
755 } | |
756 | |
757 #if (NGX_HAVE_WRITE_ZEROCOPY) | |
758 if (b->zerocopy_busy) { | |
759 break; | |
760 } | |
761 #endif | |
762 | |
763 if (b->shadow) { | |
764 b->shadow->pos = b->shadow->last; | |
765 } | |
766 | |
767 cl = ctx->busy; | |
768 ctx->busy = cl->next; | |
769 cl->next = ctx->free; | |
770 ctx->free = cl; | |
771 } | |
772 | |
497 | 773 return rc; |
129
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
774 } |
7a886b9a67dc
nginx-0.0.1-2003-08-10-20:14:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
775 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
776 |
489 | 777 static ngx_int_t |
778 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
|
779 { |
609 | 780 u_char *p, *value, *last, *copy_end, ch; |
497 | 781 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
|
782 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
|
783 |
497 | 784 state = ctx->state; |
785 looked = ctx->looked; | |
786 last = ctx->buf->last; | |
787 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
|
788 |
497 | 789 for (p = ctx->pos; p < last; p++) { |
489 | 790 |
791 ch = *p; | |
792 | |
793 if (state == ssi_start_state) { | |
794 | |
795 /* the tight loop */ | |
796 | |
499 | 797 for ( ;; ) { |
798 if (ch == '<') { | |
799 copy_end = p; | |
800 looked = 1; | |
801 state = ssi_tag_state; | |
802 | |
803 goto tag_started; | |
489 | 804 } |
805 | |
499 | 806 if (++p == last) { |
807 break; | |
808 } | |
497 | 809 |
499 | 810 ch = *p; |
489 | 811 } |
812 | |
497 | 813 ctx->pos = p; |
814 ctx->looked = looked; | |
815 ctx->copy_end = p; | |
489 | 816 |
497 | 817 if (ctx->copy_start == NULL) { |
818 ctx->copy_start = ctx->buf->pos; | |
489 | 819 } |
497 | 820 |
821 return NGX_AGAIN; | |
822 | |
499 | 823 tag_started: |
824 | |
497 | 825 continue; |
489 | 826 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
827 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
828 switch (state) { |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
829 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
830 case ssi_start_state: |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
831 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
832 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
833 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
|
834 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
835 case '!': |
497 | 836 looked = 2; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
837 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
|
838 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
839 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
840 case '<': |
497 | 841 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
|
842 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
843 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
844 default: |
497 | 845 copy_end = p; |
846 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
847 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
|
848 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
849 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
850 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
851 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
852 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
853 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
|
854 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
855 case '-': |
497 | 856 looked = 3; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
857 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
|
858 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
859 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
860 case '<': |
497 | 861 copy_end = p; |
862 looked = 1; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
863 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
|
864 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
865 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
866 default: |
497 | 867 copy_end = p; |
868 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
869 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
|
870 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
871 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
872 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
873 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
874 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
875 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
|
876 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
877 case '-': |
497 | 878 looked = 4; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
879 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
|
880 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
881 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
882 case '<': |
497 | 883 copy_end = p; |
884 looked = 1; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
885 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
|
886 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
887 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
888 default: |
497 | 889 copy_end = p; |
890 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
891 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
|
892 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
893 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
894 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
895 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
896 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
897 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
|
898 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
899 case '#': |
497 | 900 if (ctx->copy_start) { |
901 ctx->saved = 0; | |
902 } | |
903 looked = 0; | |
904 state = ssi_precommand_state; | |
489 | 905 break; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
906 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
907 case '<': |
497 | 908 copy_end = p; |
909 looked = 1; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
910 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
|
911 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
912 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
913 default: |
497 | 914 copy_end = p; |
915 looked = 0; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
916 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
|
917 break; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
918 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
919 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
920 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
921 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
922 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
|
923 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
924 case ' ': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
925 case CR: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
926 case LF: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
927 case '\t': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
928 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
929 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
930 default: |
489 | 931 ctx->command.len = 1; |
497 | 932 ctx->command.data = ngx_palloc(r->pool, |
609 | 933 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
|
934 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
|
935 return NGX_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
936 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
937 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
938 ctx->command.data[0] = ch; |
609 | 939 |
597 | 940 ctx->key = 0; |
941 ctx->key = ngx_hash(ctx->key, ch); | |
942 | |
497 | 943 ctx->params.nelts = 0; |
629 | 944 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
945 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
|
946 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
947 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
948 |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
949 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
950 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
951 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
|
952 switch (ch) { |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
953 case ' ': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
954 case CR: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
955 case LF: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
956 case '\t': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
957 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
|
958 break; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
959 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
960 case '-': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
961 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
|
962 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
963 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
964 default: |
497 | 965 if (ctx->command.len == NGX_HTTP_SSI_COMMAND_LEN) { |
966 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 967 "the \"%V%c...\" SSI command is too long", |
968 &ctx->command, ch); | |
497 | 969 |
970 state = ssi_error_state; | |
971 break; | |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
972 } |
609 | 973 |
974 ctx->command.data[ctx->command.len++] = ch; | |
975 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
|
976 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
977 |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
978 break; |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
979 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
980 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
|
981 switch (ch) { |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
982 case ' ': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
983 case CR: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
984 case LF: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
985 case '\t': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
986 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
987 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
988 case '-': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
989 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
|
990 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
991 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
992 default: |
499 | 993 ctx->param = ngx_array_push(&ctx->params); |
994 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
|
995 return NGX_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
996 } |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
997 |
489 | 998 ctx->param->key.len = 1; |
497 | 999 ctx->param->key.data = ngx_palloc(r->pool, |
609 | 1000 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
|
1001 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
|
1002 return NGX_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1003 } |
497 | 1004 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1005 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
|
1006 |
489 | 1007 ctx->param->value.len = 0; |
609 | 1008 |
1009 if (ctx->value_buf == NULL) { | |
1010 ctx->param->value.data = ngx_palloc(r->pool, | |
1011 ctx->value_len); | |
1012 if (ctx->param->value.data == NULL) { | |
1013 return NGX_ERROR; | |
1014 } | |
1015 | |
1016 } else { | |
1017 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
|
1018 } |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1019 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1020 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
|
1021 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1022 } |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1023 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1024 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1025 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1026 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
|
1027 switch (ch) { |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1028 case ' ': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1029 case CR: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1030 case LF: |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1031 case '\t': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1032 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
|
1033 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1034 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1035 case '=': |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1036 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
|
1037 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1038 |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1039 case '-': |
497 | 1040 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
|
1041 |
497 | 1042 ctx->param->key.data[ctx->param->key.len++] = ch; |
1043 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1044 "invalid \"%V\" parameter in \"%V\" SSI command", | |
1045 &ctx->param->key, &ctx->command); | |
1046 break; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1047 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1048 default: |
497 | 1049 if (ctx->param->key.len == NGX_HTTP_SSI_PARAM_LEN) { |
1050 state = ssi_error_state; | |
1051 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1052 "too long \"%V%c...\" parameter in " |
497 | 1053 "\"%V\" SSI command", |
609 | 1054 &ctx->param->key, ch, &ctx->command); |
497 | 1055 break; |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1056 } |
609 | 1057 |
1058 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
|
1059 } |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1060 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1061 break; |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1062 |
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1063 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
|
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 ' ': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1066 case CR: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1067 case LF: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1068 case '\t': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1069 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1070 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1071 case '=': |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1072 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
|
1073 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1074 |
497 | 1075 default: |
1076 if (ch == '-') { | |
1077 state = ssi_error_end0_state; | |
1078 } else { | |
1079 state = ssi_error_state; | |
1080 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1081 |
497 | 1082 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1083 "unexpected \"%c\" symbol after \"%V\" " | |
1084 "parameter in \"%V\" SSI command", | |
1085 ch, &ctx->param->key, &ctx->command); | |
1086 break; | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1087 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1088 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1089 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1090 |
127
4cbe22f9907f
nginx-0.0.1-2003-08-07-10:07:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
1091 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
|
1092 switch (ch) { |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1093 case ' ': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1094 case CR: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1095 case LF: |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1096 case '\t': |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1097 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1098 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1099 case '"': |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1100 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
|
1101 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1102 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1103 case '\'': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1104 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
|
1105 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1106 |
497 | 1107 default: |
1108 if (ch == '-') { | |
1109 state = ssi_error_end0_state; | |
1110 } else { | |
1111 state = ssi_error_state; | |
1112 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1113 |
497 | 1114 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1115 "unexpected \"%c\" symbol before value of " | |
1116 "\"%V\" parameter in \"%V\" SSI command", | |
1117 ch, &ctx->param->key, &ctx->command); | |
1118 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1119 } |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1120 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1121 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1122 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1123 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
|
1124 switch (ch) { |
559 | 1125 case '"': |
1126 state = ssi_postparam_state; | |
1127 break; | |
1128 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1129 case '\\': |
497 | 1130 ctx->saved_state = ssi_double_quoted_value_state; |
1131 state = ssi_quoted_symbol_state; | |
559 | 1132 |
1133 /* fall through */ | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1134 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1135 default: |
497 | 1136 if (ctx->param->value.len == ctx->value_len) { |
1137 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1138 "too long \"%V%c...\" value of \"%V\" " |
1139 "parameter in \"%V\" SSI command", | |
1140 &ctx->param->value, ch, &ctx->param->key, | |
497 | 1141 &ctx->command); |
1142 state = ssi_error_state; | |
1143 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1144 } |
609 | 1145 |
1146 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
|
1147 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1148 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1149 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1150 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1151 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
|
1152 switch (ch) { |
559 | 1153 case '\'': |
1154 state = ssi_postparam_state; | |
1155 break; | |
1156 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1157 case '\\': |
497 | 1158 ctx->saved_state = ssi_quoted_value_state; |
1159 state = ssi_quoted_symbol_state; | |
559 | 1160 |
1161 /* fall through */ | |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1162 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1163 default: |
497 | 1164 if (ctx->param->value.len == ctx->value_len) { |
1165 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
609 | 1166 "too long \"%V%c...\" value of \"%V\" " |
1167 "parameter in \"%V\" SSI command", | |
1168 &ctx->param->value, ch, &ctx->param->key, | |
497 | 1169 &ctx->command); |
1170 state = ssi_error_state; | |
1171 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1172 } |
609 | 1173 |
1174 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
|
1175 } |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1176 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1177 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1178 |
497 | 1179 case ssi_quoted_symbol_state: |
559 | 1180 state = ctx->saved_state; |
1181 | |
1182 if (ch == '\\') { | |
1183 break; | |
1184 } | |
1185 | |
1186 if (ch == '"' && state == ssi_double_quoted_value_state) { | |
573 | 1187 ctx->param->value.data[ctx->param->value.len - 1] = ch; |
559 | 1188 break; |
1189 } | |
1190 | |
1191 if (ch == '\'' && state == ssi_quoted_value_state) { | |
573 | 1192 ctx->param->value.data[ctx->param->value.len - 1] = ch; |
559 | 1193 break; |
1194 } | |
1195 | |
609 | 1196 if (ctx->param->value.len == ctx->value_len) { |
1197 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1198 "too long \"%V%c...\" value of \"%V\" " | |
1199 "parameter in \"%V\" SSI command", | |
1200 &ctx->param->value, ch, &ctx->param->key, | |
1201 &ctx->command); | |
1202 state = ssi_error_state; | |
1203 break; | |
1204 } | |
1205 | |
497 | 1206 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
|
1207 |
497 | 1208 break; |
1209 | |
1210 case ssi_postparam_state: | |
609 | 1211 |
1212 if (ctx->param->value.len < ctx->value_len / 2) { | |
1213 value = ngx_palloc(r->pool, ctx->param->value.len); | |
1214 if (value == NULL) { | |
1215 return NGX_ERROR; | |
1216 } | |
1217 | |
1218 ngx_memcpy(value, ctx->param->value.data, | |
1219 ctx->param->value.len); | |
1220 | |
1221 ctx->value_buf = ctx->param->value.data; | |
1222 ctx->param->value.data = value; | |
1223 | |
1224 } else { | |
1225 ctx->value_buf = NULL; | |
1226 } | |
1227 | |
497 | 1228 switch (ch) { |
1229 case ' ': | |
1230 case CR: | |
1231 case LF: | |
1232 case '\t': | |
1233 state = ssi_preparam_state; | |
1234 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1235 |
497 | 1236 case '-': |
1237 state = ssi_comment_end0_state; | |
1238 break; | |
1239 | |
1240 default: | |
1241 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1242 "unexpected \"%c\" symbol after \"%V\" value " | |
1243 "of \"%V\" parameter in \"%V\" SSI command", | |
1244 ch, &ctx->param->value, &ctx->param->key, | |
1245 &ctx->command); | |
1246 state = ssi_error_state; | |
1247 break; | |
1248 } | |
1249 | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1250 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1251 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1252 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
|
1253 switch (ch) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1254 case '-': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1255 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
|
1256 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1257 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1258 default: |
497 | 1259 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1260 "unexpected \"%c\" symbol in \"%V\" SSI command", | |
1261 ch, &ctx->command); | |
1262 state = ssi_error_state; | |
1263 break; | |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1264 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1265 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1266 break; |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1267 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1268 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
|
1269 switch (ch) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1270 case '>': |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1271 ctx->state = ssi_start_state; |
497 | 1272 ctx->pos = p + 1; |
1273 ctx->looked = looked; | |
1274 ctx->copy_end = copy_end; | |
1275 | |
1276 if (ctx->copy_start == NULL && copy_end) { | |
1277 ctx->copy_start = ctx->buf->pos; | |
1278 } | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1279 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1280 return NGX_OK; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1281 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1282 default: |
497 | 1283 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1284 "unexpected \"%c\" symbol in \"%V\" SSI command", | |
1285 ch, &ctx->command); | |
1286 state = ssi_error_state; | |
1287 break; | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1288 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1289 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1290 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1291 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1292 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
|
1293 switch (ch) { |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1294 case '-': |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1295 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
|
1296 break; |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1297 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1298 default: |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1299 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1300 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1301 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1302 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1303 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1304 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
|
1305 switch (ch) { |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1306 case '-': |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1307 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
|
1308 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1309 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1310 default: |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1311 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
|
1312 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1313 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1314 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1315 break; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1316 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1317 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
|
1318 switch (ch) { |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1319 case '>': |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1320 ctx->state = ssi_start_state; |
497 | 1321 ctx->pos = p + 1; |
1322 ctx->looked = looked; | |
1323 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
|
1324 |
497 | 1325 if (ctx->copy_start == NULL && copy_end) { |
1326 ctx->copy_start = ctx->buf->pos; | |
1327 } | |
1328 | |
1329 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
|
1330 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1331 default: |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
1332 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
|
1333 break; |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1334 } |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1335 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
127
diff
changeset
|
1336 break; |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1337 } |
16
6ce4755737b4
nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
15
diff
changeset
|
1338 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1339 |
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
125
diff
changeset
|
1340 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
|
1341 ctx->pos = p; |
497 | 1342 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
|
1343 |
497 | 1344 ctx->copy_end = (state == ssi_start_state) ? p : copy_end; |
1345 | |
1346 if (ctx->copy_start == NULL && ctx->copy_end) { | |
1347 ctx->copy_start = ctx->buf->pos; | |
1348 } | |
1349 | |
1350 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
|
1351 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1352 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
1353 |
553 | 1354 static ngx_str_t * |
611 | 1355 ngx_http_ssi_get_variable(ngx_http_request_t *r, ngx_str_t *name, |
1356 ngx_uint_t key) | |
553 | 1357 { |
1358 ngx_uint_t i; | |
1359 ngx_http_ssi_var_t *var; | |
1360 ngx_http_ssi_ctx_t *ctx; | |
1361 | |
1362 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
1363 | |
1364 var = ctx->variables.elts; | |
1365 for (i = 0; i < ctx->variables.nelts; i++) { | |
1366 if (name->len != var[i].name.len) { | |
1367 continue; | |
1368 } | |
1369 | |
611 | 1370 if (key != var[i].key) { |
1371 continue; | |
1372 } | |
1373 | |
1374 if (ngx_strncmp(name->data, var[i].name.data, name->len) == 0) { | |
553 | 1375 return &var[i].value; |
1376 } | |
1377 } | |
1378 | |
1379 return NULL; | |
1380 } | |
1381 | |
1382 | |
1383 static ngx_int_t | |
1384 ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
1385 ngx_str_t *text, ngx_uint_t flags) | |
1386 { | |
573 | 1387 u_char ch, *p, **value, *data, *part_data; |
1388 size_t *size, len, prefix, part_len; | |
1389 ngx_str_t var, *val; | |
611 | 1390 ngx_int_t key; |
553 | 1391 ngx_uint_t i, j, n, bracket; |
1392 ngx_array_t lengths, values; | |
1393 ngx_http_variable_value_t *vv; | |
1394 | |
1395 n = ngx_http_script_variables_count(text); | |
1396 | |
1397 if (n == 0) { | |
1398 | |
1399 if (!(flags & NGX_HTTP_SSI_ADD_PREFIX)) { | |
1400 return NGX_OK; | |
1401 } | |
1402 | |
1403 if (text->data[0] != '/') { | |
1404 for (prefix = r->uri.len; prefix; prefix--) { | |
1405 if (r->uri.data[prefix - 1] == '/') { | |
1406 break; | |
1407 } | |
1408 } | |
1409 | |
1410 if (prefix) { | |
1411 len = prefix + text->len; | |
1412 | |
1413 data = ngx_palloc(r->pool, len); | |
1414 if (data == NULL) { | |
1415 return NGX_ERROR; | |
1416 } | |
1417 | |
573 | 1418 p = ngx_copy(data, r->uri.data, prefix); |
553 | 1419 ngx_memcpy(p, text->data, text->len); |
1420 | |
1421 text->len = len; | |
1422 text->data = data; | |
1423 } | |
1424 } | |
1425 | |
1426 return NGX_OK; | |
1427 } | |
1428 | |
1429 if (ngx_array_init(&lengths, r->pool, 8, sizeof(size_t *)) != NGX_OK) { | |
1430 return NGX_ERROR; | |
1431 } | |
1432 | |
1433 if (ngx_array_init(&values, r->pool, 8, sizeof(u_char *)) != NGX_OK) { | |
1434 return NGX_ERROR; | |
1435 } | |
1436 | |
1437 len = 0; | |
1438 i = 0; | |
1439 | |
1440 while (i < text->len) { | |
1441 | |
1442 if (text->data[i] == '$') { | |
1443 | |
1444 var.len = 0; | |
1445 | |
1446 if (++i == text->len) { | |
1447 goto invalid_variable; | |
1448 } | |
1449 | |
1450 if (text->data[i] == '{') { | |
1451 bracket = 1; | |
1452 | |
1453 if (++i == text->len) { | |
1454 goto invalid_variable; | |
1455 } | |
1456 | |
1457 var.data = &text->data[i]; | |
1458 | |
1459 } else { | |
1460 bracket = 0; | |
1461 var.data = &text->data[i]; | |
1462 } | |
1463 | |
1464 for ( /* void */ ; i < text->len; i++, var.len++) { | |
1465 ch = text->data[i]; | |
1466 | |
1467 if (ch == '}' && bracket) { | |
1468 i++; | |
1469 bracket = 0; | |
1470 break; | |
1471 } | |
1472 | |
1473 if ((ch >= 'A' && ch <= 'Z') | |
1474 || (ch >= 'a' && ch <= 'z') | |
1475 || (ch >= '0' && ch <= '9') | |
1476 || ch == '_') | |
1477 { | |
1478 continue; | |
1479 } | |
1480 | |
1481 break; | |
1482 } | |
1483 | |
1484 if (bracket) { | |
1485 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1486 "the closing bracket in \"%V\" " | |
1487 "variable is missing", &var); | |
1488 return NGX_ERROR; | |
1489 } | |
1490 | |
577 | 1491 if (var.len == 0) { |
553 | 1492 goto invalid_variable; |
1493 } | |
1494 | |
611 | 1495 key = 0; |
1496 | |
553 | 1497 for (j = 0; j < var.len; j++) { |
1498 var.data[j] = ngx_tolower(var.data[j]); | |
611 | 1499 key = ngx_hash(key, var.data[j]); |
553 | 1500 } |
1501 | |
611 | 1502 val = ngx_http_ssi_get_variable(r, &var, key); |
553 | 1503 |
1504 if (val == NULL) { | |
611 | 1505 vv = ngx_http_get_variable(r, &var, key); |
553 | 1506 |
1507 if (vv == NULL) { | |
1508 return NGX_ERROR; | |
1509 } | |
1510 | |
573 | 1511 if (vv->not_found) { |
553 | 1512 continue; |
1513 } | |
1514 | |
573 | 1515 part_data = vv->data; |
1516 part_len = vv->len; | |
553 | 1517 |
1518 } else { | |
573 | 1519 part_data = val->data; |
1520 part_len = val->len; | |
553 | 1521 } |
1522 | |
1523 } else { | |
573 | 1524 part_data = &text->data[i]; |
1525 | |
1526 for (p = part_data; i < text->len; i++) { | |
559 | 1527 ch = text->data[i]; |
1528 | |
1529 if (ch == '$') { | |
1530 if (text->data[i - 1] != '\\') { | |
1531 break; | |
1532 } | |
1533 | |
1534 *(p - 1) = ch; | |
1535 | |
1536 continue; | |
1537 } | |
1538 | |
1539 *p++ = ch; | |
553 | 1540 } |
559 | 1541 |
573 | 1542 part_len = p - part_data; |
553 | 1543 } |
1544 | |
573 | 1545 len += part_len; |
553 | 1546 |
1547 size = ngx_array_push(&lengths); | |
1548 if (size == NULL) { | |
1549 return NGX_ERROR; | |
1550 } | |
1551 | |
573 | 1552 *size = part_len; |
553 | 1553 |
1554 value = ngx_array_push(&values); | |
1555 if (value == NULL) { | |
1556 return NGX_ERROR; | |
1557 } | |
1558 | |
573 | 1559 *value = part_data; |
553 | 1560 } |
1561 | |
1562 prefix = 0; | |
1563 | |
1564 size = lengths.elts; | |
1565 value = values.elts; | |
1566 | |
1567 if (flags & NGX_HTTP_SSI_ADD_PREFIX) { | |
1568 for (i = 0; i < values.nelts; i++) { | |
1569 if (size[i] != 0) { | |
1570 if (*value[i] != '/') { | |
1571 for (prefix = r->uri.len; prefix; prefix--) { | |
1572 if (r->uri.data[prefix - 1] == '/') { | |
1573 len += prefix; | |
1574 break; | |
1575 } | |
1576 } | |
1577 } | |
1578 | |
1579 break; | |
1580 } | |
1581 } | |
1582 } | |
1583 | |
629 | 1584 p = ngx_palloc(r->pool, len + ((flags & NGX_HTTP_SSI_ADD_ZERO) ? 1 : 0)); |
553 | 1585 if (p == NULL) { |
1586 return NGX_ERROR; | |
1587 } | |
1588 | |
1589 text->len = len; | |
1590 text->data = p; | |
1591 | |
573 | 1592 p = ngx_copy(p, r->uri.data, prefix); |
553 | 1593 |
1594 for (i = 0; i < values.nelts; i++) { | |
573 | 1595 p = ngx_copy(p, value[i], size[i]); |
553 | 1596 } |
1597 | |
1598 return NGX_OK; | |
1599 | |
1600 invalid_variable: | |
1601 | |
1602 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1603 "invalid variable name in \"%V\"", text); | |
1604 | |
1605 return NGX_ERROR; | |
1606 } | |
1607 | |
1608 | |
1609 static ngx_int_t | |
1610 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
1611 ngx_str_t **params) | |
1612 { | |
1613 ngx_str_t *uri, *file, args; | |
573 | 1614 ngx_uint_t flags; |
553 | 1615 |
1616 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL]; | |
1617 file = params[NGX_HTTP_SSI_INCLUDE_FILE]; | |
1618 | |
1619 if (uri && file) { | |
1620 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1621 "inlcusion may be either virtual=\"%V\" or file=\"%V\"", | |
1622 uri, file); | |
1623 return NGX_HTTP_SSI_ERROR; | |
1624 } | |
1625 | |
1626 if (uri == NULL && file == NULL) { | |
1627 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1628 "no parameter in \"include\" SSI command"); | |
1629 return NGX_HTTP_SSI_ERROR; | |
1630 } | |
1631 | |
1632 if (uri == NULL) { | |
1633 uri = file; | |
1634 } | |
1635 | |
1636 if (ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX) | |
1637 != NGX_OK) | |
1638 { | |
1639 return NGX_HTTP_SSI_ERROR; | |
1640 } | |
1641 | |
1642 args.len = 0; | |
1643 args.data = NULL; | |
573 | 1644 flags = 0; |
1645 | |
1646 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1647 "ssi include: \"%V\"", uri); | |
1648 | |
1649 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { | |
1650 return NGX_HTTP_SSI_ERROR; | |
553 | 1651 } |
1652 | |
573 | 1653 if (ngx_http_subrequest(r, uri, &args, flags) != NGX_OK) { |
553 | 1654 return NGX_HTTP_SSI_ERROR; |
1655 } | |
1656 | |
1657 return NGX_OK; | |
1658 } | |
1659 | |
1660 | |
497 | 1661 static ngx_int_t |
1662 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
1663 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
|
1664 { |
611 | 1665 ngx_int_t key; |
501 | 1666 ngx_uint_t i; |
499 | 1667 ngx_buf_t *b; |
573 | 1668 ngx_str_t *var, *value, text; |
499 | 1669 ngx_chain_t *cl; |
501 | 1670 ngx_http_variable_value_t *vv; |
497 | 1671 |
1672 var = params[NGX_HTTP_SSI_ECHO_VAR]; | |
1673 | |
611 | 1674 key = 0; |
1675 | |
1676 for (i = 0; i < var->len; i++) { | |
1677 var->data[i] = ngx_tolower(var->data[i]); | |
1678 key = ngx_hash(key, var->data[i]); | |
1679 } | |
1680 | |
1681 value = ngx_http_ssi_get_variable(r, var, key); | |
553 | 1682 |
1683 if (value == NULL) { | |
611 | 1684 vv = ngx_http_get_variable(r, var, key); |
553 | 1685 |
1686 if (vv == NULL) { | |
1687 return NGX_HTTP_SSI_ERROR; | |
1688 } | |
1689 | |
573 | 1690 if (!vv->not_found) { |
1691 text.data = vv->data; | |
1692 text.len = vv->len; | |
1693 value = &text; | |
553 | 1694 } |
501 | 1695 } |
497 | 1696 |
553 | 1697 if (value == NULL) { |
499 | 1698 value = params[NGX_HTTP_SSI_ECHO_DEFAULT]; |
1699 | |
1700 if (value == NULL) { | |
1701 value = &ngx_http_ssi_none; | |
1702 | |
1703 } else if (value->len == 0) { | |
1704 return NGX_OK; | |
1705 } | |
1706 | |
1707 } else { | |
1708 if (value->len == 0) { | |
1709 return NGX_OK; | |
1710 } | |
1711 } | |
1712 | |
1713 b = ngx_calloc_buf(r->pool); | |
1714 if (b == NULL) { | |
1715 return NGX_HTTP_SSI_ERROR; | |
1716 } | |
1717 | |
1718 cl = ngx_alloc_chain_link(r->pool); | |
1719 if (cl == NULL) { | |
497 | 1720 return NGX_HTTP_SSI_ERROR; |
1721 } | |
1722 | |
1723 b->memory = 1; | |
1724 b->pos = value->data; | |
1725 b->last = value->data + value->len; | |
1726 | |
1727 cl->buf = b; | |
1728 cl->next = NULL; | |
1729 *ctx->last_out = cl; | |
1730 ctx->last_out = &cl->next; | |
1731 | |
242
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1732 return NGX_OK; |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1733 } |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1734 |
5d4f49dc8de5
nginx-0.0.1-2004-01-28-18:22:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
241
diff
changeset
|
1735 |
509 | 1736 static ngx_int_t |
1737 ngx_http_ssi_config(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
1738 ngx_str_t **params) | |
1739 { | |
1740 ngx_str_t *value; | |
1741 | |
1742 value = params[NGX_HTTP_SSI_CONFIG_TIMEFMT]; | |
1743 | |
1744 if (value) { | |
589 | 1745 ctx->timefmt.len = value->len; |
1746 ctx->timefmt.data = ngx_palloc(r->pool, value->len + 1); | |
1747 if (ctx->timefmt.data == NULL) { | |
1748 return NGX_HTTP_SSI_ERROR; | |
1749 } | |
1750 | |
1751 ngx_cpystrn(ctx->timefmt.data, value->data, value->len + 1); | |
509 | 1752 } |
1753 | |
547 | 1754 value = params[NGX_HTTP_SSI_CONFIG_ERRMSG]; |
1755 | |
1756 if (value) { | |
1757 ctx->errmsg = *value; | |
1758 } | |
1759 | |
509 | 1760 return NGX_OK; |
1761 } | |
1762 | |
1763 | |
1764 static ngx_int_t | |
553 | 1765 ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
509 | 1766 ngx_str_t **params) |
1767 { | |
611 | 1768 ngx_int_t key; |
1769 ngx_uint_t i; | |
553 | 1770 ngx_str_t *name, *value, *vv; |
1771 ngx_http_ssi_var_t *var; | |
1772 ngx_http_ssi_ctx_t *mctx; | |
1773 | |
1774 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
1775 | |
1776 if (mctx->variables.elts == NULL) { | |
1777 if (ngx_array_init(&mctx->variables, r->pool, 4, | |
1778 sizeof(ngx_http_ssi_var_t)) != NGX_OK) | |
1779 { | |
509 | 1780 return NGX_HTTP_SSI_ERROR; |
1781 } | |
1782 } | |
1783 | |
553 | 1784 name = params[NGX_HTTP_SSI_SET_VAR]; |
1785 value = params[NGX_HTTP_SSI_SET_VALUE]; | |
1786 | |
1787 if (ngx_http_ssi_evaluate_string(r, ctx, value, 0) != NGX_OK) { | |
509 | 1788 return NGX_HTTP_SSI_ERROR; |
1789 } | |
1790 | |
611 | 1791 key = 0; |
1792 | |
1793 for (i = 0; i < name->len; i++) { | |
1794 name->data[i] = ngx_tolower(name->data[i]); | |
1795 key = ngx_hash(key, name->data[i]); | |
1796 } | |
1797 | |
1798 vv = ngx_http_ssi_get_variable(r, name, key); | |
553 | 1799 |
1800 if (vv) { | |
1801 *vv = *value; | |
1802 return NGX_OK; | |
1803 } | |
1804 | |
1805 var = ngx_array_push(&mctx->variables); | |
1806 if (var == NULL) { | |
1807 return NGX_HTTP_SSI_ERROR; | |
1808 } | |
1809 | |
1810 var->name = *name; | |
611 | 1811 var->key = key; |
553 | 1812 var->value = *value; |
1813 | |
1814 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1815 "set: \"%V\"=\"%V\"", name, value); | |
1816 | |
509 | 1817 return NGX_OK; |
1818 } | |
1819 | |
1820 | |
1821 static ngx_int_t | |
1822 ngx_http_ssi_if(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
1823 ngx_str_t **params) | |
1824 { | |
553 | 1825 u_char *p, *last; |
1826 ngx_str_t *expr, left, right; | |
1827 ngx_int_t rc; | |
629 | 1828 ngx_uint_t negative, noregex, flags; |
551 | 1829 #if (NGX_PCRE) |
553 | 1830 ngx_str_t err; |
1831 ngx_regex_t *regex; | |
1832 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
551 | 1833 #endif |
509 | 1834 |
629 | 1835 if (ctx->command.len == 2) { |
1836 if (ctx->conditional) { | |
1837 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1838 "the \"if\" command inside the \"if\" command"); | |
1839 return NGX_HTTP_SSI_ERROR; | |
1840 } | |
1841 } | |
1842 | |
1843 if (ctx->output_chosen) { | |
1844 ctx->output = 0; | |
1845 return NGX_OK; | |
1846 } | |
1847 | |
509 | 1848 expr = params[NGX_HTTP_SSI_IF_EXPR]; |
1849 | |
553 | 1850 left.data = expr->data; |
551 | 1851 last = expr->data + expr->len; |
1852 | |
553 | 1853 for (p = left.data; p < last; p++) { |
551 | 1854 if (*p >= 'A' && *p <= 'Z') { |
1855 *p |= 0x20; | |
1856 continue; | |
1857 } | |
509 | 1858 |
553 | 1859 if ((*p >= 'a' && *p <= 'z') |
1860 || (*p >= '0' && *p <= '9') | |
573 | 1861 || *p == '$' || *p == '{' || *p == '}' || *p == '_' |
1862 || *p == '"' || *p == '\'') | |
553 | 1863 { |
551 | 1864 continue; |
1865 } | |
1866 | |
1867 break; | |
1868 } | |
1869 | |
553 | 1870 left.len = p - left.data; |
551 | 1871 |
1872 while (p < last && *p == ' ') { | |
1873 p++; | |
509 | 1874 } |
1875 | |
553 | 1876 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1877 "left: \"%V\"", &left); | |
1878 | |
1879 if (ngx_http_ssi_evaluate_string(r, ctx, &left, 0) != NGX_OK) { | |
509 | 1880 return NGX_HTTP_SSI_ERROR; |
1881 } | |
1882 | |
553 | 1883 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1884 "evaluted left: \"%V\"", &left); | |
1885 | |
551 | 1886 if (p == last) { |
553 | 1887 if (left.len) { |
551 | 1888 ctx->output = 1; |
629 | 1889 ctx->output_chosen = 1; |
551 | 1890 |
1891 } else { | |
1892 ctx->output = 0; | |
1893 } | |
1894 | |
629 | 1895 ctx->conditional = NGX_HTTP_SSI_COND_IF; |
1896 | |
551 | 1897 return NGX_OK; |
1898 } | |
1899 | |
1900 if (p < last && *p == '=') { | |
1901 negative = 0; | |
1902 p++; | |
1903 | |
1904 } else if (p + 1 < last && *p == '!' && *(p + 1) == '=') { | |
1905 negative = 1; | |
1906 p += 2; | |
1907 | |
1908 } else { | |
1909 goto invalid_expression; | |
1910 } | |
1911 | |
1912 while (p < last && *p == ' ') { | |
1913 p++; | |
1914 } | |
1915 | |
1916 if (p < last && *p == '/') { | |
1917 if (*(last - 1) != '/') { | |
1918 goto invalid_expression; | |
1919 } | |
1920 | |
1921 noregex = 0; | |
629 | 1922 flags = NGX_HTTP_SSI_ADD_ZERO; |
551 | 1923 last--; |
1924 p++; | |
1925 | |
1926 } else { | |
1927 noregex = 1; | |
629 | 1928 flags = 0; |
1929 | |
1930 if (p < last - 1 && p[0] == '\\' && p[1] == '/') { | |
1931 p++; | |
1932 } | |
551 | 1933 } |
1934 | |
1935 right.len = last - p; | |
1936 right.data = p; | |
1937 | |
553 | 1938 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1939 "right: \"%V\"", &right); | |
1940 | |
629 | 1941 if (ngx_http_ssi_evaluate_string(r, ctx, &right, flags) != NGX_OK) { |
553 | 1942 return NGX_HTTP_SSI_ERROR; |
551 | 1943 } |
1944 | |
553 | 1945 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1946 "evaluted right: \"%V\"", &right); | |
551 | 1947 |
1948 if (noregex) { | |
1949 if (left.len != right.len) { | |
1950 rc = -1; | |
1951 | |
1952 } else { | |
1953 rc = ngx_strncmp(left.data, right.data, right.len); | |
1954 } | |
1955 | |
1956 } else { | |
1957 #if (NGX_PCRE) | |
1958 err.len = NGX_MAX_CONF_ERRSTR; | |
1959 err.data = errstr; | |
1960 | |
1961 right.data[right.len] = '\0'; | |
1962 | |
1963 regex = ngx_regex_compile(&right, 0, r->pool, &err); | |
1964 | |
1965 if (regex == NULL) { | |
1966 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%s", err.data); | |
1967 return NGX_HTTP_SSI_ERROR; | |
1968 } | |
1969 | |
1970 rc = ngx_regex_exec(regex, &left, NULL, 0); | |
1971 | |
1972 if (rc != NGX_REGEX_NO_MATCHED && rc < 0) { | |
1973 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
1974 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"", | |
1975 rc, &left, &right); | |
1976 return NGX_HTTP_SSI_ERROR; | |
1977 } | |
1978 #else | |
1979 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
1980 "the using of the regex \"%V\" in SSI " | |
1981 "requires PCRE library", &right); | |
1982 | |
1983 return NGX_HTTP_SSI_ERROR; | |
1984 #endif | |
1985 } | |
1986 | |
1987 if ((rc == 0 && !negative) || (rc != 0 && negative)) { | |
509 | 1988 ctx->output = 1; |
629 | 1989 ctx->output_chosen = 1; |
509 | 1990 |
1991 } else { | |
1992 ctx->output = 0; | |
1993 } | |
1994 | |
629 | 1995 ctx->conditional = NGX_HTTP_SSI_COND_IF; |
1996 | |
509 | 1997 return NGX_OK; |
551 | 1998 |
1999 invalid_expression: | |
2000 | |
2001 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2002 "invalid expression in \"%V\"", expr); | |
2003 | |
2004 return NGX_HTTP_SSI_ERROR; | |
509 | 2005 } |
2006 | |
2007 | |
2008 static ngx_int_t | |
2009 ngx_http_ssi_else(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2010 ngx_str_t **params) | |
2011 { | |
629 | 2012 if (ctx->output_chosen) { |
2013 ctx->output = 0; | |
2014 } else { | |
2015 ctx->output = 1; | |
2016 } | |
2017 | |
2018 ctx->conditional = NGX_HTTP_SSI_COND_ELSE; | |
509 | 2019 |
2020 return NGX_OK; | |
2021 } | |
2022 | |
2023 | |
2024 static ngx_int_t | |
2025 ngx_http_ssi_endif(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | |
2026 ngx_str_t **params) | |
2027 { | |
2028 ctx->output = 1; | |
629 | 2029 ctx->output_chosen = 0; |
2030 ctx->conditional = 0; | |
509 | 2031 |
2032 return NGX_OK; | |
2033 } | |
2034 | |
2035 | |
573 | 2036 static ngx_int_t |
2037 ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, | |
2038 ngx_http_variable_value_t *v, uintptr_t gmt) | |
509 | 2039 { |
573 | 2040 ngx_http_ssi_ctx_t *ctx; |
2041 ngx_time_t *tp; | |
2042 struct tm tm; | |
2043 char buf[NGX_HTTP_SSI_DATE_LEN]; | |
2044 | |
577 | 2045 v->valid = 1; |
573 | 2046 v->no_cachable = 0; |
2047 v->not_found = 0; | |
509 | 2048 |
563 | 2049 tp = ngx_timeofday(); |
2050 | |
509 | 2051 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); |
2052 | |
2053 if (ctx->timefmt.len == sizeof("%s") - 1 | |
2054 && ctx->timefmt.data[0] == '%' && ctx->timefmt.data[1] == 's') | |
2055 { | |
573 | 2056 v->data = ngx_palloc(r->pool, NGX_TIME_T_LEN); |
2057 if (v->data == NULL) { | |
2058 return NGX_ERROR; | |
509 | 2059 } |
2060 | |
573 | 2061 v->len = ngx_sprintf(v->data, "%T", tp->sec + (gmt ? 0 : tp->gmtoff)) |
2062 - v->data; | |
2063 return NGX_OK; | |
509 | 2064 } |
2065 | |
2066 if (gmt) { | |
563 | 2067 ngx_libc_gmtime(tp->sec, &tm); |
509 | 2068 } else { |
563 | 2069 ngx_libc_localtime(tp->sec, &tm); |
509 | 2070 } |
2071 | |
573 | 2072 v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN, |
2073 (char *) ctx->timefmt.data, &tm); | |
2074 if (v->len == 0) { | |
2075 return NGX_ERROR; | |
509 | 2076 } |
2077 | |
573 | 2078 v->data = ngx_palloc(r->pool, v->len); |
2079 if (v->data == NULL) { | |
2080 return NGX_ERROR; | |
509 | 2081 } |
2082 | |
573 | 2083 ngx_memcpy(v->data, buf, v->len); |
2084 | |
2085 return NGX_OK; | |
509 | 2086 } |
2087 | |
2088 | |
527 | 2089 static char * |
2090 ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2091 { | |
597 | 2092 ngx_http_ssi_loc_conf_t *slcf = conf; |
527 | 2093 |
2094 ngx_str_t *value, *type; | |
2095 ngx_uint_t i; | |
2096 | |
597 | 2097 if (slcf->types == NULL) { |
2098 slcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t)); | |
2099 if (slcf->types == NULL) { | |
527 | 2100 return NGX_CONF_ERROR; |
2101 } | |
2102 | |
597 | 2103 type = ngx_array_push(slcf->types); |
527 | 2104 if (type == NULL) { |
2105 return NGX_CONF_ERROR; | |
2106 } | |
2107 | |
2108 type->len = sizeof("text/html") - 1; | |
2109 type->data = (u_char *) "text/html"; | |
2110 } | |
2111 | |
2112 value = cf->args->elts; | |
2113 | |
2114 for (i = 1; i < cf->args->nelts; i++) { | |
2115 | |
2116 if (ngx_strcmp(value[i].data, "text/html") == 0) { | |
2117 continue; | |
2118 } | |
2119 | |
597 | 2120 type = ngx_array_push(slcf->types); |
527 | 2121 if (type == NULL) { |
2122 return NGX_CONF_ERROR; | |
2123 } | |
2124 | |
2125 type->len = value[i].len; | |
2126 | |
2127 type->data = ngx_palloc(cf->pool, type->len + 1); | |
2128 if (type->data == NULL) { | |
2129 return NGX_CONF_ERROR; | |
2130 } | |
2131 | |
2132 ngx_cpystrn(type->data, value[i].data, type->len + 1); | |
2133 } | |
2134 | |
2135 return NGX_CONF_OK; | |
2136 } | |
2137 | |
2138 | |
509 | 2139 static ngx_int_t |
597 | 2140 ngx_http_ssi_preconfiguration(ngx_conf_t *cf) |
509 | 2141 { |
597 | 2142 ngx_int_t rc; |
2143 ngx_http_variable_t *var, *v; | |
2144 ngx_http_ssi_command_t *cmd; | |
2145 ngx_http_ssi_main_conf_t *smcf; | |
509 | 2146 |
2147 for (v = ngx_http_ssi_vars; v->name.len; v++) { | |
2148 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
2149 if (var == NULL) { | |
2150 return NGX_ERROR; | |
2151 } | |
2152 | |
2153 var->handler = v->handler; | |
2154 var->data = v->data; | |
2155 } | |
2156 | |
597 | 2157 smcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_ssi_filter_module); |
2158 | |
2159 for (cmd = ngx_http_ssi_commands; cmd->name.len; cmd++) { | |
2160 rc = ngx_hash_add_key(&smcf->commands, &cmd->name, cmd, | |
2161 NGX_HASH_READONLY_KEY); | |
2162 | |
2163 if (rc == NGX_OK) { | |
2164 continue; | |
2165 } | |
2166 | |
2167 if (rc == NGX_BUSY) { | |
2168 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2169 "conflicting SSI command \"%V\"", &cmd->name); | |
2170 } | |
2171 | |
2172 return NGX_ERROR; | |
2173 } | |
2174 | |
577 | 2175 return NGX_OK; |
509 | 2176 } |
2177 | |
2178 | |
497 | 2179 static void * |
597 | 2180 ngx_http_ssi_create_main_conf(ngx_conf_t *cf) |
2181 { | |
2182 ngx_http_ssi_main_conf_t *smcf; | |
2183 | |
2184 smcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_main_conf_t)); | |
2185 if (smcf == NULL) { | |
2186 return NGX_CONF_ERROR; | |
2187 } | |
2188 | |
2189 smcf->commands.pool = cf->pool; | |
2190 smcf->commands.temp_pool = cf->temp_pool; | |
2191 | |
2192 if (ngx_hash_keys_array_init(&smcf->commands, NGX_HASH_SMALL) != NGX_OK) { | |
2193 return NGX_CONF_ERROR; | |
2194 } | |
2195 | |
2196 return smcf; | |
2197 } | |
2198 | |
2199 | |
2200 static char * | |
2201 ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf) | |
2202 { | |
2203 ngx_http_ssi_main_conf_t *smcf = conf; | |
2204 | |
2205 ngx_hash_init_t hash; | |
2206 | |
2207 hash.hash = &smcf->hash; | |
2208 hash.key = ngx_hash_key; | |
2209 hash.max_size = 1024; | |
2210 hash.bucket_size = ngx_cacheline_size; | |
2211 hash.name = "ssi_command_hash"; | |
2212 hash.pool = cf->pool; | |
2213 hash.temp_pool = NULL; | |
2214 | |
2215 if (ngx_hash_init(&hash, smcf->commands.keys.elts, | |
2216 smcf->commands.keys.nelts) | |
2217 != NGX_OK) | |
2218 { | |
2219 return NGX_CONF_ERROR; | |
2220 } | |
2221 | |
2222 return NGX_CONF_OK; | |
2223 } | |
2224 | |
2225 | |
2226 static void * | |
497 | 2227 ngx_http_ssi_create_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
|
2228 { |
597 | 2229 ngx_http_ssi_loc_conf_t *slcf; |
2230 | |
2231 slcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_loc_conf_t)); | |
2232 if (slcf == NULL) { | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2233 return NGX_CONF_ERROR; |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2234 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2235 |
527 | 2236 /* |
2237 * set by ngx_pcalloc(): | |
2238 * | |
2239 * conf->types = NULL; | |
2240 */ | |
2241 | |
597 | 2242 slcf->enable = NGX_CONF_UNSET; |
2243 slcf->silent_errors = NGX_CONF_UNSET; | |
2244 slcf->ignore_recycled_buffers = NGX_CONF_UNSET; | |
2245 | |
2246 slcf->min_file_chunk = NGX_CONF_UNSET_SIZE; | |
2247 slcf->value_len = NGX_CONF_UNSET_SIZE; | |
2248 | |
2249 return slcf; | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2250 } |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2251 |
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2252 |
497 | 2253 static char * |
2254 ngx_http_ssi_merge_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
|
2255 { |
597 | 2256 ngx_http_ssi_loc_conf_t *prev = parent; |
2257 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
|
2258 |
527 | 2259 ngx_str_t *type; |
2260 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2261 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
497 | 2262 ngx_conf_merge_value(conf->silent_errors, prev->silent_errors, 0); |
509 | 2263 ngx_conf_merge_value(conf->ignore_recycled_buffers, |
2264 prev->ignore_recycled_buffers, 0); | |
497 | 2265 |
2266 ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024); | |
241
3bfa496bc22e
nginx-0.0.1-2004-01-27-10:08:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
240
diff
changeset
|
2267 ngx_conf_merge_size_value(conf->value_len, prev->value_len, 256); |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2268 |
527 | 2269 if (conf->types == NULL) { |
2270 if (prev->types == NULL) { | |
2271 conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t)); | |
2272 if (conf->types == NULL) { | |
2273 return NGX_CONF_ERROR; | |
2274 } | |
2275 | |
2276 type = ngx_array_push(conf->types); | |
2277 if (type == NULL) { | |
2278 return NGX_CONF_ERROR; | |
2279 } | |
2280 | |
2281 type->len = sizeof("text/html") - 1; | |
2282 type->data = (u_char *) "text/html"; | |
2283 | |
2284 } else { | |
2285 conf->types = prev->types; | |
2286 } | |
2287 } | |
2288 | |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2289 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
|
2290 } |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2291 |
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2292 |
497 | 2293 static ngx_int_t |
2294 ngx_http_ssi_filter_init(ngx_cycle_t *cycle) | |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
2295 { |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2296 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
|
2297 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
|
2298 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
131
diff
changeset
|
2299 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
|
2300 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
|
2301 |
125
885ffb8cc32a
nginx-0.0.1-2003-08-06-09:30:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
16
diff
changeset
|
2302 return NGX_OK; |
14
f8a0d0f31a24
nginx-0.0.1-2002-09-17-21:49:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2303 } |