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