annotate src/http/modules/ngx_http_xslt_filter_module.c @ 5230:2139768ee404

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