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