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