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