annotate src/http/modules/ngx_http_xslt_filter_module.c @ 4946:2570296374b4

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