Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_xslt_filter_module.c @ 8084:eece8e35e64d quic
QUIC: allowed old DCID for initial packets until first ACK.
If a packet sent in response to an initial client packet was lost, then
successive client initial packets were dropped by nginx with the unexpected
dcid message logged. This was because the new DCID generated by the server was
not available to the client.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 09 Sep 2020 16:35:29 +0300 |
parents | 1f3bf1734a77 |
children |
rev | line source |
---|---|
2139 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
2139 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 #include <libxml/parser.h> | |
13 #include <libxml/tree.h> | |
14 #include <libxslt/xslt.h> | |
15 #include <libxslt/xsltInternals.h> | |
16 #include <libxslt/transform.h> | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
17 #include <libxslt/variables.h> |
2139 | 18 #include <libxslt/xsltutils.h> |
19 | |
2299 | 20 #if (NGX_HAVE_EXSLT) |
21 #include <libexslt/exslt.h> | |
22 #endif | |
23 | |
2139 | 24 |
25 #ifndef NGX_HTTP_XSLT_REUSE_DTD | |
26 #define NGX_HTTP_XSLT_REUSE_DTD 1 | |
27 #endif | |
28 | |
29 | |
30 typedef struct { | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
31 u_char *name; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
32 void *data; |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
33 } ngx_http_xslt_file_t; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
34 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
35 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
36 typedef struct { |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
37 ngx_array_t dtd_files; /* ngx_http_xslt_file_t */ |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
38 ngx_array_t sheet_files; /* ngx_http_xslt_file_t */ |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
39 } ngx_http_xslt_filter_main_conf_t; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
40 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
41 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
42 typedef struct { |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
43 u_char *name; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
44 ngx_http_complex_value_t value; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
45 ngx_uint_t quote; /* unsigned quote:1; */ |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
46 } ngx_http_xslt_param_t; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
47 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
48 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
49 typedef struct { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
50 xsltStylesheetPtr stylesheet; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
51 ngx_array_t params; /* ngx_http_xslt_param_t */ |
2139 | 52 } ngx_http_xslt_sheet_t; |
53 | |
54 | |
55 typedef struct { | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
56 xmlDtdPtr dtd; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
57 ngx_array_t sheets; /* ngx_http_xslt_sheet_t */ |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
58 ngx_hash_t types; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
59 ngx_array_t *types_keys; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
60 ngx_array_t *params; /* ngx_http_xslt_param_t */ |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
61 ngx_flag_t last_modified; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
62 } ngx_http_xslt_filter_loc_conf_t; |
2139 | 63 |
64 | |
65 typedef struct { | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
66 xmlDocPtr doc; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
67 xmlParserCtxtPtr ctxt; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
68 xsltTransformContextPtr transform; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
69 ngx_http_request_t *request; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
70 ngx_array_t params; |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
71 |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
72 ngx_uint_t done; /* unsigned done:1; */ |
2139 | 73 } ngx_http_xslt_filter_ctx_t; |
74 | |
75 | |
76 static ngx_int_t ngx_http_xslt_send(ngx_http_request_t *r, | |
77 ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b); | |
78 static ngx_int_t ngx_http_xslt_add_chunk(ngx_http_request_t *r, | |
79 ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b); | |
80 | |
81 | |
82 static void ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name, | |
83 const xmlChar *externalId, const xmlChar *systemId); | |
84 static void ngx_cdecl ngx_http_xslt_sax_error(void *data, const char *msg, ...); | |
85 | |
86 | |
87 static ngx_buf_t *ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r, | |
88 ngx_http_xslt_filter_ctx_t *ctx); | |
89 static ngx_int_t ngx_http_xslt_params(ngx_http_request_t *r, | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
90 ngx_http_xslt_filter_ctx_t *ctx, ngx_array_t *params, ngx_uint_t final); |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
91 static u_char *ngx_http_xslt_content_type(xsltStylesheetPtr s); |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
92 static u_char *ngx_http_xslt_encoding(xsltStylesheetPtr s); |
2139 | 93 static void ngx_http_xslt_cleanup(void *data); |
94 | |
95 static char *ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, | |
96 void *conf); | |
97 static char *ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, | |
98 void *conf); | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
99 static char *ngx_http_xslt_param(ngx_conf_t *cf, ngx_command_t *cmd, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
100 void *conf); |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
101 static void ngx_http_xslt_cleanup_dtd(void *data); |
2139 | 102 static void ngx_http_xslt_cleanup_stylesheet(void *data); |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
103 static void *ngx_http_xslt_filter_create_main_conf(ngx_conf_t *cf); |
2139 | 104 static void *ngx_http_xslt_filter_create_conf(ngx_conf_t *cf); |
105 static char *ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, | |
106 void *child); | |
5280
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
107 static ngx_int_t ngx_http_xslt_filter_preconfiguration(ngx_conf_t *cf); |
2139 | 108 static ngx_int_t ngx_http_xslt_filter_init(ngx_conf_t *cf); |
2196
fab3fa7339ff
call ngx_http_xslt_filter_exit()
Igor Sysoev <igor@sysoev.ru>
parents:
2159
diff
changeset
|
109 static void ngx_http_xslt_filter_exit(ngx_cycle_t *cycle); |
2139 | 110 |
111 | |
6922
a72886067bbb
Added missing static specifiers.
Eran Kornblau <erankor@gmail.com>
parents:
5733
diff
changeset
|
112 static ngx_str_t ngx_http_xslt_default_types[] = { |
2139 | 113 ngx_string("text/xml"), |
114 ngx_null_string | |
115 }; | |
116 | |
117 | |
118 static ngx_command_t ngx_http_xslt_filter_commands[] = { | |
119 | |
120 { ngx_string("xml_entities"), | |
2150
50cede290146
fix xslt module context levels
Igor Sysoev <igor@sysoev.ru>
parents:
2148
diff
changeset
|
121 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
2139 | 122 ngx_http_xslt_entities, |
123 NGX_HTTP_LOC_CONF_OFFSET, | |
124 0, | |
125 NULL }, | |
126 | |
127 { ngx_string("xslt_stylesheet"), | |
2151
c8331f70d799
xslt_stylesheet should be valid for location only
Igor Sysoev <igor@sysoev.ru>
parents:
2150
diff
changeset
|
128 NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
2139 | 129 ngx_http_xslt_stylesheet, |
130 NGX_HTTP_LOC_CONF_OFFSET, | |
131 0, | |
132 NULL }, | |
133 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
134 { ngx_string("xslt_param"), |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
135 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
136 ngx_http_xslt_param, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
137 NGX_HTTP_LOC_CONF_OFFSET, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
138 0, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
139 NULL }, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
140 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
141 { ngx_string("xslt_string_param"), |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
143 ngx_http_xslt_param, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
144 NGX_HTTP_LOC_CONF_OFFSET, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
145 0, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
146 (void *) 1 }, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
147 |
2139 | 148 { ngx_string("xslt_types"), |
2150
50cede290146
fix xslt module context levels
Igor Sysoev <igor@sysoev.ru>
parents:
2148
diff
changeset
|
149 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
2139 | 150 ngx_http_types_slot, |
151 NGX_HTTP_LOC_CONF_OFFSET, | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
152 offsetof(ngx_http_xslt_filter_loc_conf_t, types_keys), |
2139 | 153 &ngx_http_xslt_default_types[0] }, |
154 | |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
155 { ngx_string("xslt_last_modified"), |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
157 ngx_conf_set_flag_slot, |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
158 NGX_HTTP_LOC_CONF_OFFSET, |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
159 offsetof(ngx_http_xslt_filter_loc_conf_t, last_modified), |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
160 NULL }, |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
161 |
2139 | 162 ngx_null_command |
163 }; | |
164 | |
165 | |
166 static ngx_http_module_t ngx_http_xslt_filter_module_ctx = { | |
5280
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
167 ngx_http_xslt_filter_preconfiguration, /* preconfiguration */ |
2139 | 168 ngx_http_xslt_filter_init, /* postconfiguration */ |
169 | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
170 ngx_http_xslt_filter_create_main_conf, /* create main configuration */ |
2139 | 171 NULL, /* init main configuration */ |
172 | |
173 NULL, /* create server configuration */ | |
174 NULL, /* merge server configuration */ | |
175 | |
176 ngx_http_xslt_filter_create_conf, /* create location configuration */ | |
177 ngx_http_xslt_filter_merge_conf /* merge location configuration */ | |
178 }; | |
179 | |
180 | |
181 ngx_module_t ngx_http_xslt_filter_module = { | |
182 NGX_MODULE_V1, | |
183 &ngx_http_xslt_filter_module_ctx, /* module context */ | |
184 ngx_http_xslt_filter_commands, /* module directives */ | |
185 NGX_HTTP_MODULE, /* module type */ | |
186 NULL, /* init master */ | |
187 NULL, /* init module */ | |
188 NULL, /* init process */ | |
189 NULL, /* init thread */ | |
190 NULL, /* exit thread */ | |
2983 | 191 ngx_http_xslt_filter_exit, /* exit process */ |
2196
fab3fa7339ff
call ngx_http_xslt_filter_exit()
Igor Sysoev <igor@sysoev.ru>
parents:
2159
diff
changeset
|
192 ngx_http_xslt_filter_exit, /* exit master */ |
2139 | 193 NGX_MODULE_V1_PADDING |
194 }; | |
195 | |
196 | |
197 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | |
198 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
199 | |
200 | |
201 static ngx_int_t | |
202 ngx_http_xslt_header_filter(ngx_http_request_t *r) | |
203 { | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
204 ngx_http_xslt_filter_ctx_t *ctx; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
205 ngx_http_xslt_filter_loc_conf_t *conf; |
2139 | 206 |
207 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
208 "xslt filter header"); | |
209 | |
210 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) { | |
211 return ngx_http_next_header_filter(r); | |
212 } | |
213 | |
214 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module); | |
215 | |
216 if (conf->sheets.nelts == 0 | |
2148 | 217 || ngx_http_test_content_type(r, &conf->types) == NULL) |
2139 | 218 { |
219 return ngx_http_next_header_filter(r); | |
220 } | |
221 | |
222 ctx = ngx_http_get_module_ctx(r, ngx_http_xslt_filter_module); | |
223 | |
224 if (ctx) { | |
225 return ngx_http_next_header_filter(r); | |
226 } | |
227 | |
228 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_xslt_filter_ctx_t)); | |
229 if (ctx == NULL) { | |
230 return NGX_ERROR; | |
231 } | |
232 | |
233 ngx_http_set_ctx(r, ctx, ngx_http_xslt_filter_module); | |
234 | |
235 r->main_filter_need_in_memory = 1; | |
8031 | 236 r->allow_ranges = 0; |
2139 | 237 |
238 return NGX_OK; | |
239 } | |
240 | |
241 | |
242 static ngx_int_t | |
243 ngx_http_xslt_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
244 { | |
2984
097c1242995b
preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents:
2983
diff
changeset
|
245 int wellFormed; |
2139 | 246 ngx_chain_t *cl; |
247 ngx_http_xslt_filter_ctx_t *ctx; | |
248 | |
249 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
250 "xslt filter body"); | |
251 | |
252 if (in == NULL) { | |
253 return ngx_http_next_body_filter(r, in); | |
254 } | |
255 | |
256 ctx = ngx_http_get_module_ctx(r, ngx_http_xslt_filter_module); | |
257 | |
258 if (ctx == NULL || ctx->done) { | |
259 return ngx_http_next_body_filter(r, in); | |
260 } | |
261 | |
262 for (cl = in; cl; cl = cl->next) { | |
263 | |
264 if (ngx_http_xslt_add_chunk(r, ctx, cl->buf) != NGX_OK) { | |
265 | |
3642 | 266 if (ctx->ctxt->myDoc) { |
2139 | 267 |
268 #if (NGX_HTTP_XSLT_REUSE_DTD) | |
269 ctx->ctxt->myDoc->extSubset = NULL; | |
270 #endif | |
271 xmlFreeDoc(ctx->ctxt->myDoc); | |
272 } | |
273 | |
274 xmlFreeParserCtxt(ctx->ctxt); | |
275 | |
276 return ngx_http_xslt_send(r, ctx, NULL); | |
277 } | |
278 | |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
279 if (cl->buf->last_buf || cl->buf->last_in_chain) { |
2139 | 280 |
281 ctx->doc = ctx->ctxt->myDoc; | |
282 | |
283 #if (NGX_HTTP_XSLT_REUSE_DTD) | |
284 ctx->doc->extSubset = NULL; | |
285 #endif | |
286 | |
2984
097c1242995b
preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents:
2983
diff
changeset
|
287 wellFormed = ctx->ctxt->wellFormed; |
097c1242995b
preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents:
2983
diff
changeset
|
288 |
2139 | 289 xmlFreeParserCtxt(ctx->ctxt); |
290 | |
2984
097c1242995b
preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents:
2983
diff
changeset
|
291 if (wellFormed) { |
2139 | 292 return ngx_http_xslt_send(r, ctx, |
293 ngx_http_xslt_apply_stylesheet(r, ctx)); | |
294 } | |
295 | |
296 xmlFreeDoc(ctx->doc); | |
297 | |
298 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
299 "not well formed XML document"); | |
300 | |
301 return ngx_http_xslt_send(r, ctx, NULL); | |
302 } | |
303 } | |
304 | |
305 return NGX_OK; | |
306 } | |
307 | |
308 | |
309 static ngx_int_t | |
310 ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx, | |
311 ngx_buf_t *b) | |
312 { | |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
313 ngx_int_t rc; |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
314 ngx_chain_t out; |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
315 ngx_pool_cleanup_t *cln; |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
316 ngx_http_xslt_filter_loc_conf_t *conf; |
2139 | 317 |
318 ctx->done = 1; | |
319 | |
320 if (b == NULL) { | |
4946
2570296374b4
Xslt: prevented infinite loop.
Ruslan Ermilov <ru@nginx.com>
parents:
4746
diff
changeset
|
321 return ngx_http_filter_finalize_request(r, &ngx_http_xslt_filter_module, |
2787
3daf68f2efe3
ngx_http_filter_finalize_request() and ngx_http_clean_header()
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
322 NGX_HTTP_INTERNAL_SERVER_ERROR); |
2139 | 323 } |
324 | |
325 cln = ngx_pool_cleanup_add(r->pool, 0); | |
326 | |
327 if (cln == NULL) { | |
328 ngx_free(b->pos); | |
4946
2570296374b4
Xslt: prevented infinite loop.
Ruslan Ermilov <ru@nginx.com>
parents:
4746
diff
changeset
|
329 return ngx_http_filter_finalize_request(r, &ngx_http_xslt_filter_module, |
2139 | 330 NGX_HTTP_INTERNAL_SERVER_ERROR); |
331 } | |
332 | |
2159
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
333 if (r == r->main) { |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
334 r->headers_out.content_length_n = b->last - b->pos; |
2139 | 335 |
2159
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
336 if (r->headers_out.content_length) { |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
337 r->headers_out.content_length->hash = 0; |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
338 r->headers_out.content_length = NULL; |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
339 } |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
340 |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
341 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module); |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
342 |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
343 if (!conf->last_modified) { |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
344 ngx_http_clear_last_modified(r); |
5733
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
345 ngx_http_clear_etag(r); |
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
346 |
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
347 } else { |
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
348 ngx_http_weak_etag(r); |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
349 } |
2139 | 350 } |
351 | |
352 rc = ngx_http_next_header_filter(r); | |
353 | |
354 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
355 ngx_free(b->pos); | |
356 return rc; | |
357 } | |
358 | |
359 cln->handler = ngx_http_xslt_cleanup; | |
360 cln->data = b->pos; | |
361 | |
362 out.buf = b; | |
363 out.next = NULL; | |
364 | |
365 return ngx_http_next_body_filter(r, &out); | |
366 } | |
367 | |
368 | |
369 static ngx_int_t | |
370 ngx_http_xslt_add_chunk(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx, | |
371 ngx_buf_t *b) | |
372 { | |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
373 int err; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
374 xmlParserCtxtPtr ctxt; |
2139 | 375 |
376 if (ctx->ctxt == NULL) { | |
377 | |
378 ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL); | |
379 if (ctxt == NULL) { | |
380 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
381 "xmlCreatePushParserCtxt() failed"); | |
382 return NGX_ERROR; | |
383 } | |
4560
1a11e4a8877a
Xslt: parser options now set with xmlCtxtUseOptions().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4554
diff
changeset
|
384 xmlCtxtUseOptions(ctxt, XML_PARSE_NOENT|XML_PARSE_DTDLOAD |
1a11e4a8877a
Xslt: parser options now set with xmlCtxtUseOptions().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4554
diff
changeset
|
385 |XML_PARSE_NOWARNING); |
2139 | 386 |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
387 ctxt->sax->externalSubset = ngx_http_xslt_sax_external_subset; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
388 ctxt->sax->setDocumentLocator = NULL; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
389 ctxt->sax->error = ngx_http_xslt_sax_error; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
390 ctxt->sax->fatalError = ngx_http_xslt_sax_error; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
391 ctxt->sax->_private = ctx; |
2139 | 392 |
393 ctx->ctxt = ctxt; | |
394 ctx->request = r; | |
395 } | |
396 | |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
397 err = xmlParseChunk(ctx->ctxt, (char *) b->pos, (int) (b->last - b->pos), |
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
398 (b->last_buf) || (b->last_in_chain)); |
2139 | 399 |
400 if (err == 0) { | |
401 b->pos = b->last; | |
402 return NGX_OK; | |
403 } | |
404 | |
405 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
406 "xmlParseChunk() failed, error:%d", err); | |
407 | |
408 return NGX_ERROR; | |
409 } | |
410 | |
411 | |
412 static void | |
413 ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name, | |
414 const xmlChar *externalId, const xmlChar *systemId) | |
415 { | |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
416 xmlParserCtxtPtr ctxt = data; |
2139 | 417 |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
418 xmlDocPtr doc; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
419 xmlDtdPtr dtd; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
420 ngx_http_request_t *r; |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
421 ngx_http_xslt_filter_ctx_t *ctx; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
422 ngx_http_xslt_filter_loc_conf_t *conf; |
2139 | 423 |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
424 ctx = ctxt->sax->_private; |
2139 | 425 r = ctx->request; |
426 | |
427 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module); | |
428 | |
429 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
430 "xslt filter extSubset: \"%s\" \"%s\" \"%s\"", | |
431 name ? name : (xmlChar *) "", | |
432 externalId ? externalId : (xmlChar *) "", | |
433 systemId ? systemId : (xmlChar *) ""); | |
434 | |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
435 doc = ctxt->myDoc; |
2139 | 436 |
437 #if (NGX_HTTP_XSLT_REUSE_DTD) | |
438 | |
439 dtd = conf->dtd; | |
440 | |
441 #else | |
442 | |
443 dtd = xmlCopyDtd(conf->dtd); | |
444 if (dtd == NULL) { | |
445 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
446 "xmlCopyDtd() failed"); | |
447 return; | |
448 } | |
449 | |
450 if (doc->children == NULL) { | |
451 xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd); | |
452 | |
453 } else { | |
454 xmlAddPrevSibling(doc->children, (xmlNodePtr) dtd); | |
455 } | |
456 | |
457 #endif | |
458 | |
459 doc->extSubset = dtd; | |
460 } | |
461 | |
462 | |
463 static void ngx_cdecl | |
464 ngx_http_xslt_sax_error(void *data, const char *msg, ...) | |
465 { | |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
466 xmlParserCtxtPtr ctxt = data; |
2139 | 467 |
3686
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
468 size_t n; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
469 va_list args; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
470 ngx_http_xslt_filter_ctx_t *ctx; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
471 u_char buf[NGX_MAX_ERROR_STR]; |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
472 |
47c1a9bff989
use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
473 ctx = ctxt->sax->_private; |
2139 | 474 |
475 buf[0] = '\0'; | |
476 | |
477 va_start(args, msg); | |
478 n = (size_t) vsnprintf((char *) buf, NGX_MAX_ERROR_STR, msg, args); | |
479 va_end(args); | |
480 | |
481 while (--n && (buf[n] == CR || buf[n] == LF)) { /* void */ } | |
482 | |
483 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0, | |
2999 | 484 "libxml2 error: \"%*s\"", n + 1, buf); |
2139 | 485 } |
486 | |
487 | |
488 static ngx_buf_t * | |
489 ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r, | |
490 ngx_http_xslt_filter_ctx_t *ctx) | |
491 { | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
492 int len, rc, doc_type; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
493 u_char *type, *encoding; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
494 ngx_buf_t *b; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
495 ngx_uint_t i; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
496 xmlChar *buf; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
497 xmlDocPtr doc, res; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
498 ngx_http_xslt_sheet_t *sheet; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
499 ngx_http_xslt_filter_loc_conf_t *conf; |
2139 | 500 |
501 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module); | |
502 sheet = conf->sheets.elts; | |
503 doc = ctx->doc; | |
504 | |
505 /* preallocate array for 4 params */ | |
506 | |
507 if (ngx_array_init(&ctx->params, r->pool, 4 * 2 + 1, sizeof(char *)) | |
508 != NGX_OK) | |
509 { | |
510 xmlFreeDoc(doc); | |
511 return NULL; | |
512 } | |
513 | |
514 for (i = 0; i < conf->sheets.nelts; i++) { | |
515 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
516 ctx->transform = xsltNewTransformContext(sheet[i].stylesheet, doc); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
517 if (ctx->transform == NULL) { |
2139 | 518 xmlFreeDoc(doc); |
519 return NULL; | |
520 } | |
521 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
522 if (conf->params |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
523 && ngx_http_xslt_params(r, ctx, conf->params, 0) != NGX_OK) |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
524 { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
525 xsltFreeTransformContext(ctx->transform); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
526 xmlFreeDoc(doc); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
527 return NULL; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
528 } |
2139 | 529 |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
530 if (ngx_http_xslt_params(r, ctx, &sheet[i].params, 1) != NGX_OK) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
531 xsltFreeTransformContext(ctx->transform); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
532 xmlFreeDoc(doc); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
533 return NULL; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
534 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
535 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
536 res = xsltApplyStylesheetUser(sheet[i].stylesheet, doc, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
537 ctx->params.elts, NULL, NULL, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
538 ctx->transform); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
539 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
540 xsltFreeTransformContext(ctx->transform); |
2139 | 541 xmlFreeDoc(doc); |
542 | |
543 if (res == NULL) { | |
544 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
545 "xsltApplyStylesheet() failed"); | |
546 return NULL; | |
547 } | |
548 | |
549 doc = res; | |
550 | |
551 /* reset array elements */ | |
552 ctx->params.nelts = 0; | |
553 } | |
554 | |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
555 /* there must be at least one stylesheet */ |
2139 | 556 |
2159
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
557 if (r == r->main) { |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
558 type = ngx_http_xslt_content_type(sheet[i - 1].stylesheet); |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
559 |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
560 } else { |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
561 type = NULL; |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
562 } |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
563 |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
564 encoding = ngx_http_xslt_encoding(sheet[i - 1].stylesheet); |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
565 doc_type = doc->type; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
566 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
567 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
568 "xslt filter type: %d t:%s e:%s", |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
569 doc_type, type ? type : (u_char *) "(null)", |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
570 encoding ? encoding : (u_char *) "(null)"); |
2139 | 571 |
572 rc = xsltSaveResultToString(&buf, &len, doc, sheet[i - 1].stylesheet); | |
573 | |
574 xmlFreeDoc(doc); | |
575 | |
576 if (rc != 0) { | |
577 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
578 "xsltSaveResultToString() failed"); | |
579 return NULL; | |
580 } | |
581 | |
582 if (len == 0) { | |
583 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
584 "xsltSaveResultToString() returned zero-length result"); | |
585 return NULL; | |
586 } | |
587 | |
6973
99934aade555
Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6922
diff
changeset
|
588 b = ngx_calloc_buf(r->pool); |
2139 | 589 if (b == NULL) { |
590 ngx_free(buf); | |
591 return NULL; | |
592 } | |
593 | |
594 b->pos = buf; | |
595 b->last = buf + len; | |
596 b->memory = 1; | |
597 | |
2159
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
598 if (encoding) { |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
599 r->headers_out.charset.len = ngx_strlen(encoding); |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
600 r->headers_out.charset.data = encoding; |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
601 } |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
602 |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
603 if (r != r->main) { |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
604 return b; |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
605 } |
0ec936b0010a
clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
2158
diff
changeset
|
606 |
2899
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
607 b->last_buf = 1; |
61d5b945730a
fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
608 |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
609 if (type) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
610 len = ngx_strlen(type); |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
611 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
612 r->headers_out.content_type_len = len; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
613 r->headers_out.content_type.len = len; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
614 r->headers_out.content_type.data = type; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
615 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
616 } else if (doc_type == XML_HTML_DOCUMENT_NODE) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
617 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
618 r->headers_out.content_type_len = sizeof("text/html") - 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3508
diff
changeset
|
619 ngx_str_set(&r->headers_out.content_type, "text/html"); |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
620 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
621 |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
622 r->headers_out.content_type_lowcase = NULL; |
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
623 |
2139 | 624 return b; |
625 } | |
626 | |
627 | |
628 static ngx_int_t | |
629 ngx_http_xslt_params(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx, | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
630 ngx_array_t *params, ngx_uint_t final) |
2139 | 631 { |
7540
9a970c905045
Xslt: fixed potential buffer overflow with null character.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7154
diff
changeset
|
632 u_char *p, *value, *dst, *src, **s; |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
633 size_t len; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
634 ngx_uint_t i; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
635 ngx_str_t string; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
636 ngx_http_xslt_param_t *param; |
2139 | 637 |
638 param = params->elts; | |
639 | |
640 for (i = 0; i < params->nelts; i++) { | |
641 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
642 if (ngx_http_complex_value(r, ¶m[i].value, &string) != NGX_OK) { |
2139 | 643 return NGX_ERROR; |
644 } | |
645 | |
646 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
647 "xslt filter param: \"%s\"", string.data); | |
648 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
649 if (param[i].name) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
650 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
651 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
652 "xslt filter param name: \"%s\"", param[i].name); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
653 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
654 if (param[i].quote) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
655 if (xsltQuoteOneUserParam(ctx->transform, param[i].name, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
656 string.data) |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
657 != 0) |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
658 { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
659 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
660 "xsltQuoteOneUserParam(\"%s\", \"%s\") failed", |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
661 param[i].name, string.data); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
662 return NGX_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
663 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
664 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
665 continue; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
666 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
667 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
668 s = ngx_array_push(&ctx->params); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
669 if (s == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
670 return NGX_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
671 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
672 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
673 *s = param[i].name; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
674 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
675 s = ngx_array_push(&ctx->params); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
676 if (s == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
677 return NGX_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
678 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
679 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
680 *s = string.data; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
681 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
682 continue; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
683 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
684 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
685 /* |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
686 * parse param1=value1:param2=value2 syntax as used by parameters |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
687 * specified in xslt_stylesheet directives |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
688 */ |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
689 |
7154
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
690 if (param[i].value.lengths) { |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
691 p = string.data; |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
692 |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
693 } else { |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
694 p = ngx_pnalloc(r->pool, string.len + 1); |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
695 if (p == NULL) { |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
696 return NGX_ERROR; |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
697 } |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
698 |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
699 ngx_memcpy(p, string.data, string.len + 1); |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
700 } |
595a3de03e91
Xslt: fixed parameters parsing (ticket #1416).
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
701 |
2139 | 702 while (p && *p) { |
703 | |
704 value = p; | |
705 p = (u_char *) ngx_strchr(p, '='); | |
706 if (p == NULL) { | |
707 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
708 "invalid libxslt parameter \"%s\"", value); | |
709 return NGX_ERROR; | |
710 } | |
711 *p++ = '\0'; | |
712 | |
713 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
714 "xslt filter param name: \"%s\"", value); | |
715 | |
716 s = ngx_array_push(&ctx->params); | |
717 if (s == NULL) { | |
718 return NGX_ERROR; | |
719 } | |
720 | |
721 *s = value; | |
722 | |
723 value = p; | |
724 p = (u_char *) ngx_strchr(p, ':'); | |
725 | |
726 if (p) { | |
727 len = p - value; | |
728 *p++ = '\0'; | |
729 | |
730 } else { | |
7540
9a970c905045
Xslt: fixed potential buffer overflow with null character.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7154
diff
changeset
|
731 len = ngx_strlen(value); |
2139 | 732 } |
733 | |
734 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
735 "xslt filter param value: \"%s\"", value); | |
736 | |
737 dst = value; | |
738 src = value; | |
739 | |
740 ngx_unescape_uri(&dst, &src, len, 0); | |
741 | |
742 *dst = '\0'; | |
743 | |
744 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
745 "xslt filter param unescaped: \"%s\"", value); | |
746 | |
747 s = ngx_array_push(&ctx->params); | |
748 if (s == NULL) { | |
749 return NGX_ERROR; | |
750 } | |
751 | |
752 *s = value; | |
753 } | |
754 } | |
755 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
756 if (final) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
757 s = ngx_array_push(&ctx->params); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
758 if (s == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
759 return NGX_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
760 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
761 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
762 *s = NULL; |
2139 | 763 } |
764 | |
765 return NGX_OK; | |
766 } | |
767 | |
768 | |
2153
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
769 static u_char * |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
770 ngx_http_xslt_content_type(xsltStylesheetPtr s) |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
771 { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
772 u_char *type; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
773 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
774 if (s->mediaType) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
775 return s->mediaType; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
776 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
777 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
778 for (s = s->imports; s; s = s->next) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
779 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
780 type = ngx_http_xslt_content_type(s); |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
781 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
782 if (type) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
783 return type; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
784 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
785 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
786 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
787 return NULL; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
788 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
789 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
790 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
791 static u_char * |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
792 ngx_http_xslt_encoding(xsltStylesheetPtr s) |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
793 { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
794 u_char *encoding; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
795 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
796 if (s->encoding) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
797 return s->encoding; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
798 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
799 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
800 for (s = s->imports; s; s = s->next) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
801 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
802 encoding = ngx_http_xslt_encoding(s); |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
803 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
804 if (encoding) { |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
805 return encoding; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
806 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
807 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
808 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
809 return NULL; |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
810 } |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
811 |
6476e445d6ce
xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents:
2152
diff
changeset
|
812 |
2139 | 813 static void |
814 ngx_http_xslt_cleanup(void *data) | |
815 { | |
816 ngx_free(data); | |
817 } | |
818 | |
819 | |
820 static char * | |
821 ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
822 { | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
823 ngx_http_xslt_filter_loc_conf_t *xlcf = conf; |
2139 | 824 |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
825 ngx_str_t *value; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
826 ngx_uint_t i; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
827 ngx_pool_cleanup_t *cln; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
828 ngx_http_xslt_file_t *file; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
829 ngx_http_xslt_filter_main_conf_t *xmcf; |
2139 | 830 |
831 if (xlcf->dtd) { | |
832 return "is duplicate"; | |
833 } | |
834 | |
835 value = cf->args->elts; | |
836 | |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
837 xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module); |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
838 |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
839 file = xmcf->dtd_files.elts; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
840 for (i = 0; i < xmcf->dtd_files.nelts; i++) { |
4646
959371df1806
Fixed the reuse of parsed DTDs and XSLTs.
Ruslan Ermilov <ru@nginx.com>
parents:
4560
diff
changeset
|
841 if (ngx_strcmp(file[i].name, value[1].data) == 0) { |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
842 xlcf->dtd = file[i].data; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
843 return NGX_CONF_OK; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
844 } |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
845 } |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
846 |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
847 cln = ngx_pool_cleanup_add(cf->pool, 0); |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
848 if (cln == NULL) { |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
849 return NGX_CONF_ERROR; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
850 } |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
851 |
2139 | 852 xlcf->dtd = xmlParseDTD(NULL, (xmlChar *) value[1].data); |
853 | |
854 if (xlcf->dtd == NULL) { | |
855 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "xmlParseDTD() failed"); | |
856 return NGX_CONF_ERROR; | |
857 } | |
858 | |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
859 cln->handler = ngx_http_xslt_cleanup_dtd; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
860 cln->data = xlcf->dtd; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
861 |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
862 file = ngx_array_push(&xmcf->dtd_files); |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
863 if (file == NULL) { |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
864 return NGX_CONF_ERROR; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
865 } |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
866 |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
867 file->name = value[1].data; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
868 file->data = xlcf->dtd; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
869 |
2139 | 870 return NGX_CONF_OK; |
871 } | |
872 | |
873 | |
874 | |
875 static char * | |
876 ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
877 { | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
878 ngx_http_xslt_filter_loc_conf_t *xlcf = conf; |
2139 | 879 |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
880 ngx_str_t *value; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
881 ngx_uint_t i, n; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
882 ngx_pool_cleanup_t *cln; |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
883 ngx_http_xslt_file_t *file; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
884 ngx_http_xslt_sheet_t *sheet; |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
885 ngx_http_xslt_param_t *param; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2299
diff
changeset
|
886 ngx_http_compile_complex_value_t ccv; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
887 ngx_http_xslt_filter_main_conf_t *xmcf; |
2139 | 888 |
889 value = cf->args->elts; | |
890 | |
891 if (xlcf->sheets.elts == NULL) { | |
892 if (ngx_array_init(&xlcf->sheets, cf->pool, 1, | |
893 sizeof(ngx_http_xslt_sheet_t)) | |
894 != NGX_OK) | |
895 { | |
896 return NGX_CONF_ERROR; | |
897 } | |
898 } | |
899 | |
900 sheet = ngx_array_push(&xlcf->sheets); | |
901 if (sheet == NULL) { | |
902 return NGX_CONF_ERROR; | |
903 } | |
904 | |
905 ngx_memzero(sheet, sizeof(ngx_http_xslt_sheet_t)); | |
906 | |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
907 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2139 | 908 return NGX_CONF_ERROR; |
909 } | |
910 | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
911 xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module); |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
912 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
913 file = xmcf->sheet_files.elts; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
914 for (i = 0; i < xmcf->sheet_files.nelts; i++) { |
4646
959371df1806
Fixed the reuse of parsed DTDs and XSLTs.
Ruslan Ermilov <ru@nginx.com>
parents:
4560
diff
changeset
|
915 if (ngx_strcmp(file[i].name, value[1].data) == 0) { |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
916 sheet->stylesheet = file[i].data; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
917 goto found; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
918 } |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
919 } |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
920 |
2139 | 921 cln = ngx_pool_cleanup_add(cf->pool, 0); |
922 if (cln == NULL) { | |
923 return NGX_CONF_ERROR; | |
924 } | |
925 | |
926 sheet->stylesheet = xsltParseStylesheetFile(value[1].data); | |
927 if (sheet->stylesheet == NULL) { | |
928 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, | |
929 "xsltParseStylesheetFile(\"%s\") failed", | |
930 value[1].data); | |
931 return NGX_CONF_ERROR; | |
932 } | |
933 | |
934 cln->handler = ngx_http_xslt_cleanup_stylesheet; | |
935 cln->data = sheet->stylesheet; | |
936 | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
937 file = ngx_array_push(&xmcf->sheet_files); |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
938 if (file == NULL) { |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
939 return NGX_CONF_ERROR; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
940 } |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
941 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
942 file->name = value[1].data; |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
943 file->data = sheet->stylesheet; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
944 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
945 found: |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
946 |
2139 | 947 n = cf->args->nelts; |
948 | |
949 if (n == 2) { | |
950 return NGX_CONF_OK; | |
951 } | |
952 | |
953 if (ngx_array_init(&sheet->params, cf->pool, n - 2, | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
954 sizeof(ngx_http_xslt_param_t)) |
2139 | 955 != NGX_OK) |
956 { | |
957 return NGX_CONF_ERROR; | |
958 } | |
959 | |
960 for (i = 2; i < n; i++) { | |
961 | |
962 param = ngx_array_push(&sheet->params); | |
963 if (param == NULL) { | |
964 return NGX_CONF_ERROR; | |
965 } | |
966 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
967 ngx_memzero(param, sizeof(ngx_http_xslt_param_t)); |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2299
diff
changeset
|
968 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
2139 | 969 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2299
diff
changeset
|
970 ccv.cf = cf; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2299
diff
changeset
|
971 ccv.value = &value[i]; |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
972 ccv.complex_value = ¶m->value; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2299
diff
changeset
|
973 ccv.zero = 1; |
2139 | 974 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2299
diff
changeset
|
975 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
2139 | 976 return NGX_CONF_ERROR; |
977 } | |
978 } | |
979 | |
980 return NGX_CONF_OK; | |
981 } | |
982 | |
983 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
984 static char * |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
985 ngx_http_xslt_param(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
986 { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
987 ngx_http_xslt_filter_loc_conf_t *xlcf = conf; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
988 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
989 ngx_http_xslt_param_t *param; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
990 ngx_http_compile_complex_value_t ccv; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
991 ngx_str_t *value; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
992 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
993 value = cf->args->elts; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
994 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
995 if (xlcf->params == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
996 xlcf->params = ngx_array_create(cf->pool, 2, |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
997 sizeof(ngx_http_xslt_param_t)); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
998 if (xlcf->params == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
999 return NGX_CONF_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1000 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1001 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1002 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1003 param = ngx_array_push(xlcf->params); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1004 if (param == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1005 return NGX_CONF_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1006 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1007 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1008 param->name = value[1].data; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1009 param->quote = (cmd->post == NULL) ? 0 : 1; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1010 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1011 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1012 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1013 ccv.cf = cf; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1014 ccv.value = &value[2]; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1015 ccv.complex_value = ¶m->value; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1016 ccv.zero = 1; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1017 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1018 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1019 return NGX_CONF_ERROR; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1020 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1021 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1022 return NGX_CONF_OK; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1023 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1024 |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1025 |
2139 | 1026 static void |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1027 ngx_http_xslt_cleanup_dtd(void *data) |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1028 { |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1029 xmlFreeDtd(data); |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1030 } |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1031 |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1032 |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1033 static void |
2139 | 1034 ngx_http_xslt_cleanup_stylesheet(void *data) |
1035 { | |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1036 xsltFreeStylesheet(data); |
2139 | 1037 } |
1038 | |
1039 | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1040 static void * |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1041 ngx_http_xslt_filter_create_main_conf(ngx_conf_t *cf) |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1042 { |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1043 ngx_http_xslt_filter_main_conf_t *conf; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1044 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1045 conf = ngx_palloc(cf->pool, sizeof(ngx_http_xslt_filter_main_conf_t)); |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1046 if (conf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2899
diff
changeset
|
1047 return NULL; |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1048 } |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1049 |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1050 if (ngx_array_init(&conf->dtd_files, cf->pool, 1, |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1051 sizeof(ngx_http_xslt_file_t)) |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1052 != NGX_OK) |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1053 { |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1054 return NULL; |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1055 } |
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1056 |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1057 if (ngx_array_init(&conf->sheet_files, cf->pool, 1, |
2156
0c6d0bd60579
reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents:
2154
diff
changeset
|
1058 sizeof(ngx_http_xslt_file_t)) |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1059 != NGX_OK) |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1060 { |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1061 return NULL; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1062 } |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1063 |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1064 return conf; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1065 } |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1066 |
2139 | 1067 |
1068 static void * | |
1069 ngx_http_xslt_filter_create_conf(ngx_conf_t *cf) | |
1070 { | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1071 ngx_http_xslt_filter_loc_conf_t *conf; |
2139 | 1072 |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1073 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_xslt_filter_loc_conf_t)); |
2139 | 1074 if (conf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2899
diff
changeset
|
1075 return NULL; |
2139 | 1076 } |
1077 | |
1078 /* | |
1079 * set by ngx_pcalloc(): | |
1080 * | |
2148 | 1081 * conf->dtd = NULL; |
1082 * conf->sheets = { NULL }; | |
1083 * conf->types = { NULL }; | |
1084 * conf->types_keys = NULL; | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1085 * conf->params = NULL; |
2139 | 1086 */ |
1087 | |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
1088 conf->last_modified = NGX_CONF_UNSET; |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
1089 |
2139 | 1090 return conf; |
1091 } | |
1092 | |
1093 | |
1094 static char * | |
1095 ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
1096 { | |
2154
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1097 ngx_http_xslt_filter_loc_conf_t *prev = parent; |
4f48a2765da0
reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents:
2153
diff
changeset
|
1098 ngx_http_xslt_filter_loc_conf_t *conf = child; |
2139 | 1099 |
1100 if (conf->dtd == NULL) { | |
1101 conf->dtd = prev->dtd; | |
1102 } | |
1103 | |
1104 if (conf->sheets.nelts == 0) { | |
1105 conf->sheets = prev->sheets; | |
1106 } | |
1107 | |
4554
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1108 if (conf->params == NULL) { |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1109 conf->params = prev->params; |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1110 } |
212a0251951b
Added xslt_param and xslt_string_param directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4553
diff
changeset
|
1111 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3115
diff
changeset
|
1112 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:
3115
diff
changeset
|
1113 &prev->types_keys, &prev->types, |
2148 | 1114 ngx_http_xslt_default_types) |
2139 | 1115 != NGX_OK) |
1116 { | |
1117 return NGX_CONF_ERROR; | |
1118 } | |
1119 | |
5230
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
1120 ngx_conf_merge_value(conf->last_modified, prev->last_modified, 0); |
2139768ee404
Xslt: xslt_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4946
diff
changeset
|
1121 |
2139 | 1122 return NGX_CONF_OK; |
1123 } | |
1124 | |
1125 | |
1126 static ngx_int_t | |
5280
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1127 ngx_http_xslt_filter_preconfiguration(ngx_conf_t *cf) |
2139 | 1128 { |
1129 xmlInitParser(); | |
1130 | |
2299 | 1131 #if (NGX_HAVE_EXSLT) |
1132 exsltRegisterAll(); | |
1133 #endif | |
1134 | |
5280
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1135 return NGX_OK; |
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1136 } |
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1137 |
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1138 |
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1139 static ngx_int_t |
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1140 ngx_http_xslt_filter_init(ngx_conf_t *cf) |
e939f6e8548c
Xslt: exsltRegisterAll() moved to preconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5230
diff
changeset
|
1141 { |
2139 | 1142 ngx_http_next_header_filter = ngx_http_top_header_filter; |
1143 ngx_http_top_header_filter = ngx_http_xslt_header_filter; | |
1144 | |
1145 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
1146 ngx_http_top_body_filter = ngx_http_xslt_body_filter; | |
1147 | |
1148 return NGX_OK; | |
1149 } | |
1150 | |
1151 | |
1152 static void | |
1153 ngx_http_xslt_filter_exit(ngx_cycle_t *cycle) | |
1154 { | |
1155 xsltCleanupGlobals(); | |
1156 xmlCleanupParser(); | |
1157 } |