annotate src/http/modules/ngx_http_xslt_filter_module.c @ 4412:d620f497c50f

Copyright updated.
author Maxim Konovalov <maxim@nginx.com>
date Wed, 18 Jan 2012 15:07:43 +0000
parents 47c1a9bff989
children 3dd8a403faa1
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>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 #include <libxslt/xsltutils.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
2299
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
19 #if (NGX_HAVE_EXSLT)
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
20 #include <libexslt/exslt.h>
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
21 #endif
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
22
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 #ifndef NGX_HTTP_XSLT_REUSE_DTD
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 #define NGX_HTTP_XSLT_REUSE_DTD 1
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
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 typedef struct {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
30 u_char *name;
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
31 void *data;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
32 } ngx_http_xslt_file_t;
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
33
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 typedef struct {
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
36 ngx_array_t dtd_files; /* 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
37 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
38 } ngx_http_xslt_filter_main_conf_t;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
39
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 typedef struct {
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 xsltStylesheetPtr stylesheet;
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
43 ngx_array_t params; /* ngx_http_complex_value_t */
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 } ngx_http_xslt_sheet_t;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 typedef struct {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 xmlDtdPtr dtd;
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
49 ngx_array_t sheets; /* ngx_http_xslt_sheet_t */
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
50 ngx_hash_t types;
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
51 ngx_array_t *types_keys;
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
52 } ngx_http_xslt_filter_loc_conf_t;
2139
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 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 xmlDocPtr doc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 xmlParserCtxtPtr ctxt;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 ngx_http_request_t *request;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 ngx_array_t params;
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
60
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
61 ngx_uint_t done; /* unsigned done:1; */
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 } ngx_http_xslt_filter_ctx_t;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 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
66 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
67 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
68 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
69
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 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
72 const xmlChar *externalId, const xmlChar *systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 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
74
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 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
77 ngx_http_xslt_filter_ctx_t *ctx);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 static ngx_int_t ngx_http_xslt_params(ngx_http_request_t *r,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 ngx_http_xslt_filter_ctx_t *ctx, ngx_array_t *params);
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
80 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
81 static u_char *ngx_http_xslt_encoding(xsltStylesheetPtr s);
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 static void ngx_http_xslt_cleanup(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 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
85 void *conf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 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
87 void *conf);
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
88 static void ngx_http_xslt_cleanup_dtd(void *data);
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 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
90 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
91 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
92 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
93 void *child);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 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
95 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
96
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 ngx_str_t ngx_http_xslt_default_types[] = {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 ngx_string("text/xml"),
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 ngx_null_string
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 static ngx_command_t ngx_http_xslt_filter_commands[] = {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 { ngx_string("xml_entities"),
2150
50cede290146 fix xslt module context levels
Igor Sysoev <igor@sysoev.ru>
parents: 2148
diff changeset
107 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
108 ngx_http_xslt_entities,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 NGX_HTTP_LOC_CONF_OFFSET,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 NULL },
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113 { ngx_string("xslt_stylesheet"),
2151
c8331f70d799 xslt_stylesheet should be valid for location only
Igor Sysoev <igor@sysoev.ru>
parents: 2150
diff changeset
114 NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 ngx_http_xslt_stylesheet,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 NGX_HTTP_LOC_CONF_OFFSET,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 NULL },
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 { ngx_string("xslt_types"),
2150
50cede290146 fix xslt module context levels
Igor Sysoev <igor@sysoev.ru>
parents: 2148
diff changeset
121 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 ngx_http_types_slot,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 NGX_HTTP_LOC_CONF_OFFSET,
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
124 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
125 &ngx_http_xslt_default_types[0] },
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 ngx_null_command
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 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
132 NULL, /* preconfiguration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 ngx_http_xslt_filter_init, /* postconfiguration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
135 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
136 NULL, /* init main configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 NULL, /* create server configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 NULL, /* merge server configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 ngx_http_xslt_filter_create_conf, /* create location configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 ngx_http_xslt_filter_merge_conf /* merge location configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 ngx_module_t ngx_http_xslt_filter_module = {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 NGX_MODULE_V1,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 &ngx_http_xslt_filter_module_ctx, /* module context */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 ngx_http_xslt_filter_commands, /* module directives */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 NGX_HTTP_MODULE, /* module type */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 NULL, /* init master */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 NULL, /* init module */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 NULL, /* init process */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 NULL, /* init thread */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 NULL, /* exit thread */
2983
4cc8b90f8cef style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
156 ngx_http_xslt_filter_exit, /* exit process */
2196
fab3fa7339ff call ngx_http_xslt_filter_exit()
Igor Sysoev <igor@sysoev.ru>
parents: 2159
diff changeset
157 ngx_http_xslt_filter_exit, /* exit master */
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 NGX_MODULE_V1_PADDING
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 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
163 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
164
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 ngx_http_xslt_header_filter(ngx_http_request_t *r)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
169 ngx_http_xslt_filter_ctx_t *ctx;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
170 ngx_http_xslt_filter_loc_conf_t *conf;
2139
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_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 "xslt filter header");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 return ngx_http_next_header_filter(r);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 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
180
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 if (conf->sheets.nelts == 0
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
182 || ngx_http_test_content_type(r, &conf->types) == NULL)
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 return ngx_http_next_header_filter(r);
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 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
188
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 if (ctx) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 return ngx_http_next_header_filter(r);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 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
194 if (ctx == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 }
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_http_set_ctx(r, ctx, ngx_http_xslt_filter_module);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 r->main_filter_need_in_memory = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 return NGX_OK;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 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
208 {
2984
097c1242995b preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents: 2983
diff changeset
209 int wellFormed;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 ngx_chain_t *cl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 ngx_http_xslt_filter_ctx_t *ctx;
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 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
214 "xslt filter body");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 if (in == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 return ngx_http_next_body_filter(r, in);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 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
221
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 if (ctx == NULL || ctx->done) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 return ngx_http_next_body_filter(r, in);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 }
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 for (cl = in; cl; cl = cl->next) {
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 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
229
3642
ac33852faaac style fix
Igor Sysoev <igor@sysoev.ru>
parents: 3516
diff changeset
230 if (ctx->ctxt->myDoc) {
2139
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 #if (NGX_HTTP_XSLT_REUSE_DTD)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 ctx->ctxt->myDoc->extSubset = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 xmlFreeDoc(ctx->ctxt->myDoc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 xmlFreeParserCtxt(ctx->ctxt);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 return ngx_http_xslt_send(r, ctx, NULL);
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
2899
61d5b945730a fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
243 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
244
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245 ctx->doc = ctx->ctxt->myDoc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247 #if (NGX_HTTP_XSLT_REUSE_DTD)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 ctx->doc->extSubset = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250
2984
097c1242995b preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents: 2983
diff changeset
251 wellFormed = ctx->ctxt->wellFormed;
097c1242995b preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents: 2983
diff changeset
252
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253 xmlFreeParserCtxt(ctx->ctxt);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254
2984
097c1242995b preserve XML wellFormed field before freeing memory
Igor Sysoev <igor@sysoev.ru>
parents: 2983
diff changeset
255 if (wellFormed) {
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 return ngx_http_xslt_send(r, ctx,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257 ngx_http_xslt_apply_stylesheet(r, ctx));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 xmlFreeDoc(ctx->doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 "not well formed XML document");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 return ngx_http_xslt_send(r, ctx, NULL);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 return NGX_OK;
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
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 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 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
275 ngx_buf_t *b)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277 ngx_int_t rc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278 ngx_chain_t out;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
279 ngx_pool_cleanup_t *cln;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
281 ctx->done = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
283 if (b == NULL) {
2821
26e06e009ced allow to pass image filter errors via the same location where the filter is set
Igor Sysoev <igor@sysoev.ru>
parents: 2787
diff changeset
284 return ngx_http_filter_finalize_request(r, NULL,
2787
3daf68f2efe3 ngx_http_filter_finalize_request() and ngx_http_clean_header()
Igor Sysoev <igor@sysoev.ru>
parents: 2588
diff changeset
285 NGX_HTTP_INTERNAL_SERVER_ERROR);
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286 }
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 cln = ngx_pool_cleanup_add(r->pool, 0);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
289
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290 if (cln == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
291 ngx_free(b->pos);
2821
26e06e009ced allow to pass image filter errors via the same location where the filter is set
Igor Sysoev <igor@sysoev.ru>
parents: 2787
diff changeset
292 return ngx_http_filter_finalize_request(r, NULL,
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
293 NGX_HTTP_INTERNAL_SERVER_ERROR);
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
2159
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
296 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
297 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
298
2159
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
299 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
300 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
301 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
302 }
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
303
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
304 ngx_http_clear_last_modified(r);
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
305 }
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 rc = ngx_http_next_header_filter(r);
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 (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310 ngx_free(b->pos);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311 return rc;
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->handler = ngx_http_xslt_cleanup;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
315 cln->data = b->pos;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
317 out.buf = b;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
318 out.next = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 return ngx_http_next_body_filter(r, &out);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 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
326 ngx_buf_t *b)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 {
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
328 int err;
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
329 xmlParserCtxtPtr ctxt;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331 if (ctx->ctxt == NULL) {
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 ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334 if (ctxt == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
336 "xmlCreatePushParserCtxt() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
340 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
341 ctxt->sax->setDocumentLocator = NULL;
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
342 ctxt->sax->warning = NULL;
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
343 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
344 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
345 ctxt->sax->_private = ctx;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346 ctxt->replaceEntities = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347 ctxt->loadsubset = 1;
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 ctx->ctxt = ctxt;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 ctx->request = r;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352
2899
61d5b945730a fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
353 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
354 (b->last_buf) || (b->last_in_chain));
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 if (err == 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 b->pos = b->last;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 return NGX_OK;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362 "xmlParseChunk() failed, error:%d", err);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363
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 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369 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
370 const xmlChar *externalId, const xmlChar *systemId)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371 {
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
372 xmlParserCtxtPtr ctxt = data;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
374 xmlDocPtr doc;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
375 xmlDtdPtr dtd;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
376 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
377 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
378 ngx_http_xslt_filter_loc_conf_t *conf;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
379
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
380 ctx = ctxt->sax->_private;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 r = ctx->request;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 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
384
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 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
386 "xslt filter extSubset: \"%s\" \"%s\" \"%s\"",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387 name ? name : (xmlChar *) "",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388 externalId ? externalId : (xmlChar *) "",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389 systemId ? systemId : (xmlChar *) "");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
391 doc = ctxt->myDoc;
2139
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 #if (NGX_HTTP_XSLT_REUSE_DTD)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 dtd = conf->dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
396
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397 #else
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399 dtd = xmlCopyDtd(conf->dtd);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400 if (dtd == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 "xmlCopyDtd() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
403 return;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
406 if (doc->children == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
407 xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);
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 } else {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 xmlAddPrevSibling(doc->children, (xmlNodePtr) dtd);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
413 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415 doc->extSubset = dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417
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 static void ngx_cdecl
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
420 ngx_http_xslt_sax_error(void *data, const char *msg, ...)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421 {
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
422 xmlParserCtxtPtr ctxt = data;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423
3686
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
424 size_t n;
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
425 va_list args;
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
426 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
427 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
428
47c1a9bff989 use xmlSAXHandler._private field to store xslt filter context
Igor Sysoev <igor@sysoev.ru>
parents: 3642
diff changeset
429 ctx = ctxt->sax->_private;
2139
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 buf[0] = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433 va_start(args, msg);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434 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
435 va_end(args);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 while (--n && (buf[n] == CR || buf[n] == LF)) { /* void */ }
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 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
440 "libxml2 error: \"%*s\"", n + 1, buf);
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 }
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 static ngx_buf_t *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445 ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 ngx_http_xslt_filter_ctx_t *ctx)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
448 int len, rc, doc_type;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
449 u_char *type, *encoding;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
450 ngx_buf_t *b;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
451 ngx_uint_t i;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
452 xmlChar *buf;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
453 xmlDocPtr doc, res;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
454 ngx_http_xslt_sheet_t *sheet;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
455 ngx_http_xslt_filter_loc_conf_t *conf;
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 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
458 sheet = conf->sheets.elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459 doc = ctx->doc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461 /* preallocate array for 4 params */
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 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
464 != NGX_OK)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467 return NULL;
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 for (i = 0; i < conf->sheets.nelts; i++) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472 if (ngx_http_xslt_params(r, ctx, &sheet[i].params) != NGX_OK) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
474 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
477 res = xsltApplyStylesheet(sheet[i].stylesheet, doc, ctx->params.elts);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
480
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
481 if (res == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
482 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
483 "xsltApplyStylesheet() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
484 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485 }
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 doc = res;
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 /* reset array elements */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
490 ctx->params.nelts = 0;
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
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
493 /* there must be at least one stylesheet */
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494
2159
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
495 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
496 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
497
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
498 } else {
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
499 type = NULL;
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
500 }
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
501
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
502 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
503 doc_type = doc->type;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
504
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
505 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
506 "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
507 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
508 encoding ? encoding : (u_char *) "(null)");
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
509
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
510 rc = xsltSaveResultToString(&buf, &len, doc, sheet[i - 1].stylesheet);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 if (rc != 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 "xsltSaveResultToString() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
520 if (len == 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
521 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
522 "xsltSaveResultToString() returned zero-length result");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
523 return NULL;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527 if (b == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
528 ngx_free(buf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
529 return NULL;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
532 b->pos = buf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 b->last = buf + len;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534 b->memory = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535
2159
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
536 if (encoding) {
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
537 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
538 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
539 }
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
540
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
541 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
542 return b;
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
543 }
0ec936b0010a clear Last-Modified; set content-type and length for main request only
Igor Sysoev <igor@sysoev.ru>
parents: 2158
diff changeset
544
2899
61d5b945730a fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
545 b->last_buf = 1;
61d5b945730a fix XSLT filter in SSI subrequests
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
546
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
547 if (type) {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
548 len = ngx_strlen(type);
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
549
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
550 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
551 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
552 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
553
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
554 } 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
555
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
556 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
557 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
558 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
559
2882
896db5a09bd2 reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
560 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
561
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
562 return b;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
565
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
566 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
567 ngx_http_xslt_params(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
568 ngx_array_t *params)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
569 {
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
570 u_char *p, *last, *value, *dst, *src, **s;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
571 size_t len;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
572 ngx_uint_t i;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
573 ngx_str_t string;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
574 ngx_http_complex_value_t *param;
2139
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 param = params->elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 for (i = 0; i < params->nelts; i++) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
580 if (ngx_http_complex_value(r, &param[i], &string) != NGX_OK) {
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
581 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
582 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 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
585 "xslt filter param: \"%s\"", string.data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
587 p = string.data;
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
588 last = string.data + string.len - 1;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
589
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590 while (p && *p) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
591
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
592 value = p;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 p = (u_char *) ngx_strchr(p, '=');
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
594 if (p == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
595 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
596 "invalid libxslt parameter \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
598 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
599 *p++ = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
601 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
602 "xslt filter param name: \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604 s = ngx_array_push(&ctx->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
605 if (s == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
606 return NGX_ERROR;
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 *s = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 value = p;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612 p = (u_char *) ngx_strchr(p, ':');
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
614 if (p) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
615 len = p - value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616 *p++ = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618 } else {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 len = last - value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
620 }
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 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
623 "xslt filter param value: \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
624
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625 dst = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626 src = value;
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_unescape_uri(&dst, &src, len, 0);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630 *dst = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
631
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632 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
633 "xslt filter param unescaped: \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
634
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 s = ngx_array_push(&ctx->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 if (s == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640 *s = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 s = ngx_array_push(&ctx->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645 if (s == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649 *s = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651 return NGX_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
653
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654
2153
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
655 static u_char *
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
656 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
657 {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
658 u_char *type;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
659
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
660 if (s->mediaType) {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
661 return s->mediaType;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
662 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
663
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
664 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
665
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
666 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
667
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
668 if (type) {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
669 return type;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
670 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
671 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
672
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
673 return NULL;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
674 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
675
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
676
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
677 static u_char *
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
678 ngx_http_xslt_encoding(xsltStylesheetPtr s)
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
679 {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
680 u_char *encoding;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
681
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
682 if (s->encoding) {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
683 return s->encoding;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
684 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
685
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
686 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
687
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
688 encoding = ngx_http_xslt_encoding(s);
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
689
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
690 if (encoding) {
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
691 return encoding;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
692 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
693 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
694
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
695 return NULL;
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
696 }
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
697
6476e445d6ce xsl:output's media-type and encoding support
Igor Sysoev <igor@sysoev.ru>
parents: 2152
diff changeset
698
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
699 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700 ngx_http_xslt_cleanup(void *data)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
701 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
702 ngx_free(data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704
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 static char *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 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
708 {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
709 ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
711 ngx_str_t *value;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
712 ngx_uint_t i;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
713 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
714 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
715 ngx_http_xslt_filter_main_conf_t *xmcf;
2139
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 if (xlcf->dtd) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718 return "is duplicate";
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721 value = cf->args->elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
722
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
723 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
724
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
725 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
726 for (i = 0; i < xmcf->dtd_files.nelts; i++) {
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
727 if (ngx_strcmp(file[i].name, &value[1].data) == 0) {
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
728 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
729 return NGX_CONF_OK;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
730 }
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
731 }
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
732
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
733 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
734 if (cln == NULL) {
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
735 return NGX_CONF_ERROR;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
736 }
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
737
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 xlcf->dtd = xmlParseDTD(NULL, (xmlChar *) value[1].data);
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 if (xlcf->dtd == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741 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
742 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
745 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
746 cln->data = xlcf->dtd;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
747
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
748 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
749 if (file == NULL) {
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
750 return NGX_CONF_ERROR;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
751 }
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
752
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
753 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
754 file->data = xlcf->dtd;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
755
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
757 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
758
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
759
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
760
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
761 static char *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
762 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
763 {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
764 ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
765
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
766 ngx_str_t *value;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
767 ngx_uint_t i, n;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
768 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
769 ngx_http_xslt_file_t *file;
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
770 ngx_http_xslt_sheet_t *sheet;
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
771 ngx_http_complex_value_t *param;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
772 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
773 ngx_http_xslt_filter_main_conf_t *xmcf;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
774
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
775 value = cf->args->elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
776
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
777 if (xlcf->sheets.elts == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
778 if (ngx_array_init(&xlcf->sheets, cf->pool, 1,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779 sizeof(ngx_http_xslt_sheet_t))
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
780 != NGX_OK)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
781 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
784 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
785
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
786 sheet = ngx_array_push(&xlcf->sheets);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
787 if (sheet == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
788 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
789 }
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 ngx_memzero(sheet, sizeof(ngx_http_xslt_sheet_t));
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 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
794 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
795 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
797 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
798
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
799 file = xmcf->sheet_files.elts;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
800 for (i = 0; i < xmcf->sheet_files.nelts; i++) {
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
801 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
802 sheet->stylesheet = file[i].data;
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
803 goto found;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
804 }
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
805 }
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
806
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
807 cln = ngx_pool_cleanup_add(cf->pool, 0);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
808 if (cln == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
809 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
810 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
811
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
812 sheet->stylesheet = xsltParseStylesheetFile(value[1].data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
813 if (sheet->stylesheet == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
814 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
815 "xsltParseStylesheetFile(\"%s\") failed",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
816 value[1].data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
817 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
818 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
819
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
820 cln->handler = ngx_http_xslt_cleanup_stylesheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
821 cln->data = sheet->stylesheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
822
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
823 file = ngx_array_push(&xmcf->sheet_files);
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
824 if (file == NULL) {
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
825 return NGX_CONF_ERROR;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
826 }
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
827
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
828 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
829 file->data = sheet->stylesheet;
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
830
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
831 found:
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
832
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
833 n = cf->args->nelts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
834
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
835 if (n == 2) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
836 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
837 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
838
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
839 if (ngx_array_init(&sheet->params, cf->pool, n - 2,
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
840 sizeof(ngx_http_complex_value_t))
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
841 != NGX_OK)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
843 return NGX_CONF_ERROR;
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 for (i = 2; i < n; i++) {
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 param = ngx_array_push(&sheet->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
849 if (param == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
850 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
851 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
852
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
853 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
854
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
855 ccv.cf = cf;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
856 ccv.value = &value[i];
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
857 ccv.complex_value = param;
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
858 ccv.zero = 1;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
859
2588
a6954ce88b80 use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents: 2299
diff changeset
860 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
861 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
862 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
865 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
866 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
867
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 static void
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
870 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
871 {
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
872 xmlFreeDtd(data);
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
873 }
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
874
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
875
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
876 static void
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
877 ngx_http_xslt_cleanup_stylesheet(void *data)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
878 {
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
879 xsltFreeStylesheet(data);
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
880 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
881
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
882
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
883 static void *
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
884 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
885 {
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
886 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
887
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
888 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
889 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
890 return NULL;
2154
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
2156
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
893 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
894 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
895 != NGX_OK)
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
896 {
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
897 return NULL;
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
898 }
0c6d0bd60579 reuse compiled DTD hash in different locations, add DTD cleanup
Igor Sysoev <igor@sysoev.ru>
parents: 2154
diff changeset
899
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
900 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
901 sizeof(ngx_http_xslt_file_t))
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
902 != NGX_OK)
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
903 {
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
904 return NULL;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
905 }
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
906
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
907 return conf;
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
908 }
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
909
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
910
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
911 static void *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
912 ngx_http_xslt_filter_create_conf(ngx_conf_t *cf)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
913 {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
914 ngx_http_xslt_filter_loc_conf_t *conf;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
915
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
916 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
917 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
918 return NULL;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
919 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
920
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 * set by ngx_pcalloc():
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
923 *
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
924 * conf->dtd = NULL;
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
925 * conf->sheets = { NULL };
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
926 * conf->types = { NULL };
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
927 * conf->types_keys = NULL;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928 */
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 conf;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
934 static char *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
935 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
936 {
2154
4f48a2765da0 reuse compiled XSLT tree in different locations
Igor Sysoev <igor@sysoev.ru>
parents: 2153
diff changeset
937 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
938 ngx_http_xslt_filter_loc_conf_t *conf = child;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
939
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
940 if (conf->dtd == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
941 conf->dtd = prev->dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
942 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
943
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
944 if (conf->sheets.nelts == 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
945 conf->sheets = prev->sheets;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
946 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
947
3372
6b8e5c882e47 support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents: 3115
diff changeset
948 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
949 &prev->types_keys, &prev->types,
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
950 ngx_http_xslt_default_types)
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
951 != NGX_OK)
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_ERROR;
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 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
957 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
958
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
959
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
960 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
961 ngx_http_xslt_filter_init(ngx_conf_t *cf)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
962 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
963 xmlInitParser();
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
964
2299
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
965 #if (NGX_HAVE_EXSLT)
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
966 exsltRegisterAll();
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
967 #endif
3e213fa0cbb3 exslt support
Igor Sysoev <igor@sysoev.ru>
parents: 2196
diff changeset
968
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
969 ngx_http_next_header_filter = ngx_http_top_header_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
970 ngx_http_top_header_filter = ngx_http_xslt_header_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
971
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
972 ngx_http_next_body_filter = ngx_http_top_body_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
973 ngx_http_top_body_filter = ngx_http_xslt_body_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
974
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
975 return NGX_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
976 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
977
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
978
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
979 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
980 ngx_http_xslt_filter_exit(ngx_cycle_t *cycle)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
981 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
982 xsltCleanupGlobals();
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
983 xmlCleanupParser();
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
984 }