annotate src/http/modules/ngx_http_xslt_filter_module.c @ 2151:c8331f70d799

xslt_stylesheet should be valid for location only
author Igor Sysoev <igor@sysoev.ru>
date Tue, 05 Aug 2008 13:07:42 +0000
parents 50cede290146
children b23e83f5b182
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
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 #include <ngx_config.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 #include <libxml/parser.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 #include <libxml/tree.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 #include <libxslt/xslt.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 #include <libxslt/xsltInternals.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 #include <libxslt/transform.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 #include <libxslt/xsltutils.h>
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 #ifndef NGX_HTTP_XSLT_REUSE_DTD
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 #define NGX_HTTP_XSLT_REUSE_DTD 1
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 typedef struct {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 ngx_array_t *lengths;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 ngx_array_t *values;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 } ngx_http_xslt_param_t;
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 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 xsltStylesheetPtr stylesheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 ngx_array_t params; /* ngx_http_xslt_param_t */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 } ngx_http_xslt_sheet_t;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 typedef struct {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37 xmlDtdPtr dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 ngx_array_t sheets; /* ngx_http_xslt_sheet_t */
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
39 ngx_hash_t types;
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
40 ngx_array_t *types_keys;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 } ngx_http_xslt_filter_conf_t;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 typedef struct {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 xmlDocPtr doc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 xmlParserCtxtPtr ctxt;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 xmlSAXHandler *sax;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 ngx_http_request_t *request;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 ngx_array_t params;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 unsigned done:1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 unsigned html:1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 } ngx_http_xslt_filter_ctx_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 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
56 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
57 static ngx_int_t ngx_http_xslt_filter_internal_error(ngx_http_request_t *r);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 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
59 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
60
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 static void ngx_http_xslt_sax_start_document(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 static void ngx_http_xslt_sax_end_document(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 static void ngx_http_xslt_sax_internal_subset(void *data, const xmlChar *name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 const xmlChar *externalId, const xmlChar *systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 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
67 const xmlChar *externalId, const xmlChar *systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 static void ngx_http_xslt_sax_entity_decl(void *data, const xmlChar *name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 int type, const xmlChar *publicId, const xmlChar *systemId,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 xmlChar *content);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 static void ngx_http_xslt_sax_attribute_decl(void *data, const xmlChar *elem,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 const xmlChar *fullname, int type, int def, const xmlChar *defaultValue,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 xmlEnumerationPtr tree);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 static void ngx_http_xslt_sax_element_decl(void *data, const xmlChar * name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 int type, xmlElementContentPtr content);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 static void ngx_http_xslt_sax_notation_decl(void *data, const xmlChar *name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 const xmlChar *publicId, const xmlChar *systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 static void ngx_http_xslt_sax_unparsed_entity_decl(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 const xmlChar *notationName);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 static void ngx_http_xslt_sax_start_element(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 int nb_namespaces, const xmlChar **namespaces, int nb_attributes,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 int nb_defaulted, const xmlChar **attributes);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 static void ngx_http_xslt_sax_end_element(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 const xmlChar * localname ATTRIBUTE_UNUSED,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 const xmlChar * prefix ATTRIBUTE_UNUSED,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 const xmlChar * URI ATTRIBUTE_UNUSED);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 static void ngx_http_xslt_sax_characters(void *data, const xmlChar *p, int len);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 static void ngx_http_xslt_sax_cdata_block(void *data, const xmlChar *p,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 int len);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 static xmlEntityPtr ngx_http_xslt_sax_get_entity(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 const xmlChar *name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 static xmlEntityPtr ngx_http_xslt_sax_get_parameter_entity(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 const xmlChar *name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 static xmlParserInputPtr ngx_http_xslt_sax_resolve_entity(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 const xmlChar *publicId, const xmlChar *systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 static void ngx_http_xslt_sax_reference(void *data, const xmlChar *name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 static void ngx_http_xslt_sax_comment(void *data, const xmlChar *value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 static void ngx_http_xslt_sax_processing_instruction(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 const xmlChar *target, const xmlChar *pidata);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 static int ngx_http_xslt_sax_is_standalone(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 static int ngx_http_xslt_sax_has_internal_subset(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 static int ngx_http_xslt_sax_has_external_subset(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 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
106
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 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
109 ngx_http_xslt_filter_ctx_t *ctx);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 static ngx_int_t ngx_http_xslt_params(ngx_http_request_t *r,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 ngx_http_xslt_filter_ctx_t *ctx, ngx_array_t *params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 static void ngx_http_xslt_cleanup(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 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
115 void *conf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 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
117 void *conf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 static void ngx_http_xslt_cleanup_stylesheet(void *data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 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
120 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
121 void *child);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 static ngx_int_t ngx_http_xslt_filter_init(ngx_conf_t *cf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 ngx_str_t ngx_http_xslt_default_types[] = {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 ngx_string("text/xml"),
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 ngx_null_string
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 static ngx_command_t ngx_http_xslt_filter_commands[] = {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 { ngx_string("xml_entities"),
2150
50cede290146 fix xslt module context levels
Igor Sysoev <igor@sysoev.ru>
parents: 2148
diff changeset
134 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
135 ngx_http_xslt_entities,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 NGX_HTTP_LOC_CONF_OFFSET,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 NULL },
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 { ngx_string("xslt_stylesheet"),
2151
c8331f70d799 xslt_stylesheet should be valid for location only
Igor Sysoev <igor@sysoev.ru>
parents: 2150
diff changeset
141 NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 ngx_http_xslt_stylesheet,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 NGX_HTTP_LOC_CONF_OFFSET,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 NULL },
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146
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,
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
151 offsetof(ngx_http_xslt_filter_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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 ngx_null_command
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 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
159 NULL, /* preconfiguration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 ngx_http_xslt_filter_init, /* postconfiguration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 NULL, /* create main configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 NULL, /* init main configuration */
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 NULL, /* create server configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 NULL, /* merge server configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 ngx_http_xslt_filter_create_conf, /* create location configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 ngx_http_xslt_filter_merge_conf /* merge location configuration */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 ngx_module_t ngx_http_xslt_filter_module = {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 NGX_MODULE_V1,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 &ngx_http_xslt_filter_module_ctx, /* module context */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 ngx_http_xslt_filter_commands, /* module directives */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 NGX_HTTP_MODULE, /* module type */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178 NULL, /* init master */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 NULL, /* init module */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 NULL, /* init process */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 NULL, /* init thread */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 NULL, /* exit thread */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 NULL, /* exit process */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 NULL, /* exit master */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 NGX_MODULE_V1_PADDING
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 };
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 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
190 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
191
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 ngx_http_xslt_header_filter(ngx_http_request_t *r)
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 ngx_http_xslt_filter_ctx_t *ctx;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 ngx_http_xslt_filter_conf_t *conf;
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 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
200 "xslt filter header");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 return ngx_http_next_header_filter(r);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 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
207
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 if (conf->sheets.nelts == 0
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
209 || ngx_http_test_content_type(r, &conf->types) == NULL)
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 return ngx_http_next_header_filter(r);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 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
215
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 if (ctx) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 return ngx_http_next_header_filter(r);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_xslt_filter_ctx_t));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 if (ctx == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 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
226
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 r->main_filter_need_in_memory = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229 return NGX_OK;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 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
235 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 ngx_chain_t *cl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 ngx_http_xslt_filter_ctx_t *ctx;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 "xslt filter body");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 if (in == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 return ngx_http_next_body_filter(r, in);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246 ctx = ngx_http_get_module_ctx(r, ngx_http_xslt_filter_module);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 if (ctx == NULL || ctx->done) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 return ngx_http_next_body_filter(r, in);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
251
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 for (cl = in; cl; cl = cl->next) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 if (ngx_http_xslt_add_chunk(r, ctx, cl->buf) != NGX_OK) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 if (ctx->ctxt->myDoc){
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 #if (NGX_HTTP_XSLT_REUSE_DTD)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259 ctx->ctxt->myDoc->extSubset = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261 xmlFreeDoc(ctx->ctxt->myDoc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264 xmlFreeParserCtxt(ctx->ctxt);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 return ngx_http_xslt_send(r, ctx, NULL);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
267 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 if (cl->buf->last_buf) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271 ctx->doc = ctx->ctxt->myDoc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 #if (NGX_HTTP_XSLT_REUSE_DTD)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 ctx->doc->extSubset = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277 xmlFreeParserCtxt(ctx->ctxt);
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 if (ctx->ctxt->wellFormed) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280 return ngx_http_xslt_send(r, ctx,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
281 ngx_http_xslt_apply_stylesheet(r, ctx));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
283
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
284 xmlFreeDoc(ctx->doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
285
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
287 "not well formed XML document");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
288
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
289 return ngx_http_xslt_send(r, ctx, NULL);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
291 }
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 return NGX_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
294 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
295
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
296
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
297 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298 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
299 ngx_buf_t *b)
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 ngx_int_t rc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 ngx_chain_t out;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
303 ngx_pool_cleanup_t *cln;
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 ctx->done = 1;
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 if (b == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
308 return ngx_http_xslt_filter_internal_error(r);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
309 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311 cln = ngx_pool_cleanup_add(r->pool, 0);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
312
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
313 if (cln == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
314 ngx_free(b->pos);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
315 return ngx_http_special_response_handler(r,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316 NGX_HTTP_INTERNAL_SERVER_ERROR);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319 if (ctx->html) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 r->headers_out.content_type_len = sizeof("text/html") - 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321 r->headers_out.content_type.len = sizeof("text/html") - 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322 r->headers_out.content_type.data = (u_char *) "text/html";
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 r->headers_out.content_length_n = b->last - b->pos;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 if (r->headers_out.content_length) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328 r->headers_out.content_length->hash = 0;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 r->headers_out.content_length = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332 r->allow_ranges = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334 rc = ngx_http_next_header_filter(r);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
336 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 ngx_free(b->pos);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 return rc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
340
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 cln->handler = ngx_http_xslt_cleanup;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342 cln->data = b->pos;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 out.buf = b;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345 out.next = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347 return ngx_http_next_body_filter(r, &out);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
348 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352 ngx_http_xslt_filter_internal_error(ngx_http_request_t *r)
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 ngx_int_t rc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 /* clear the modules contexts */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359 rc = ngx_http_special_response_handler(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361 /* NGX_ERROR resets any pending data */
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 return (rc == NGX_OK) ? NGX_ERROR : rc;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 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
369 ngx_buf_t *b)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371 int err;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372 xmlSAXHandler *sax;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373 xmlParserCtxtPtr ctxt;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375 if (ctx->ctxt == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377 ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
378 if (ctxt == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
379 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 "xmlCreatePushParserCtxt() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384 ctx->sax = ngx_palloc(r->pool, sizeof(xmlSAXHandler));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 if (ctx->sax == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387 }
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 sax = ctxt->sax;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391 ngx_memcpy(ctx->sax, sax, sizeof(xmlSAXHandler));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
393 sax->startDocument = ngx_http_xslt_sax_start_document;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394 sax->endDocument = ngx_http_xslt_sax_end_document;
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 sax->internalSubset = ngx_http_xslt_sax_internal_subset;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397 sax->externalSubset = ngx_http_xslt_sax_external_subset;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398 sax->entityDecl = ngx_http_xslt_sax_entity_decl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399 sax->attributeDecl = ngx_http_xslt_sax_attribute_decl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400 sax->elementDecl = ngx_http_xslt_sax_element_decl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401 sax->notationDecl = ngx_http_xslt_sax_notation_decl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 sax->unparsedEntityDecl = ngx_http_xslt_sax_unparsed_entity_decl;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
403 sax->setDocumentLocator = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405 sax->startElementNs = ngx_http_xslt_sax_start_element;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
406 sax->endElementNs = ngx_http_xslt_sax_end_element;
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 sax->characters = ngx_http_xslt_sax_characters;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
409 sax->ignorableWhitespace = ngx_http_xslt_sax_characters;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 sax->cdataBlock = ngx_http_xslt_sax_cdata_block;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411 sax->getEntity = ngx_http_xslt_sax_get_entity;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412 sax->resolveEntity = ngx_http_xslt_sax_resolve_entity;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
413 sax->getParameterEntity = ngx_http_xslt_sax_get_parameter_entity;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414 sax->reference = ngx_http_xslt_sax_reference;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415 sax->comment = ngx_http_xslt_sax_comment;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416 sax->processingInstruction = ngx_http_xslt_sax_processing_instruction;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418 sax->isStandalone = ngx_http_xslt_sax_is_standalone;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419 sax->hasInternalSubset = ngx_http_xslt_sax_has_internal_subset;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
420 sax->hasExternalSubset = ngx_http_xslt_sax_has_external_subset;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422 sax->warning = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423 sax->error = ngx_http_xslt_sax_error;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
424 sax->fatalError = ngx_http_xslt_sax_error;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
425
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
426 ctxt->userData = ctx;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428 ctxt->replaceEntities = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429 ctxt->loadsubset = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
431 ctx->ctxt = ctxt;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 ctx->request = r;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433 }
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 err = xmlParseChunk(ctx->ctxt, (char *) b->pos,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 (int) (b->last - b->pos), b->last_buf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438 if (err == 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439 b->pos = b->last;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440 return NGX_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444 "xmlParseChunk() failed, error:%d", err);
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 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
450 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
451 ngx_http_xslt_sax_start_document(void *data)
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 ngx_http_xslt_filter_ctx_t *ctx = data;
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 ctx->sax->startDocument(ctx->ctxt);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460 ngx_http_xslt_sax_end_document(void *data)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
462 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
463
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464 ctx->sax->endDocument(ctx->ctxt);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
468 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469 ngx_http_xslt_sax_internal_subset(void *data, const xmlChar *name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470 const xmlChar *externalId, const xmlChar *systemId)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
474 ctx->sax->internalSubset(ctx->ctxt, name, externalId, systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
477
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 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
480 const xmlChar *externalId, const xmlChar *systemId)
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 ngx_http_xslt_filter_ctx_t *ctx = data;
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 xmlDocPtr doc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485 xmlDtdPtr dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
486 ngx_http_request_t *r;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
487 ngx_http_xslt_filter_conf_t *conf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
488
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
489 r = ctx->request;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
490
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
491 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
492
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
493 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
494 "xslt filter extSubset: \"%s\" \"%s\" \"%s\"",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495 name ? name : (xmlChar *) "",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
496 externalId ? externalId : (xmlChar *) "",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
497 systemId ? systemId : (xmlChar *) "");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
498
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
499 doc = ctx->ctxt->myDoc;
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 #if (NGX_HTTP_XSLT_REUSE_DTD)
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 dtd = conf->dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
504
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
505 #else
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
506
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
507 dtd = xmlCopyDtd(conf->dtd);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
508 if (dtd == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
509 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
510 "xmlCopyDtd() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511 return;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 dtd->name = xmlStrdup(name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 if (doc->children == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517 xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519 } else {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
520 xmlAddPrevSibling(doc->children, (xmlNodePtr) dtd);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
521 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
522
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
523 #endif
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
524
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
525 doc->extSubset = dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
528
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
529 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
530 ngx_http_xslt_sax_entity_decl(void *data, const xmlChar *name, int type,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
531 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
532 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535 ctx->sax->entityDecl(ctx->ctxt, name, type, publicId, systemId, content);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537
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 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
540 ngx_http_xslt_sax_attribute_decl(void *data, const xmlChar *elem,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
541 const xmlChar *fullname, int type, int def, const xmlChar *defaultValue,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
542 xmlEnumerationPtr tree)
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 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
545
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
546 ctx->sax->attributeDecl(ctx->ctxt, elem, fullname, type, def, defaultValue,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
547 tree);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
548 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
551 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
552 ngx_http_xslt_sax_element_decl(void *data, const xmlChar * name, int type,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
553 xmlElementContentPtr content)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
554 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
555 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
556
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
557 ctx->sax->elementDecl(ctx->ctxt, name, type, content);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
558 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
559
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
560
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
561 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
562 ngx_http_xslt_sax_notation_decl(void *data, const xmlChar *name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
563 const xmlChar *publicId, const xmlChar *systemId)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
564 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
565 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
566
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
567 ctx->sax->notationDecl(ctx->ctxt, name, publicId, systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
568 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
569
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
570
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
571 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
572 ngx_http_xslt_sax_unparsed_entity_decl(void *data, const xmlChar *name,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
573 const xmlChar *publicId, const xmlChar *systemId,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
574 const xmlChar *notationName)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
575 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
576 ngx_http_xslt_filter_ctx_t *ctx = data;
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 ctx->sax->unparsedEntityDecl(ctx->ctxt, name, publicId, systemId,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579 notationName);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
580 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
581
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 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 ngx_http_xslt_sax_start_element(void *data, const xmlChar *localname,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585 const xmlChar *prefix, const xmlChar *URI, int nb_namespaces,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586 const xmlChar **namespaces, int nb_attributes, int nb_defaulted,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
587 const xmlChar **attributes)
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 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
591 ctx->sax->startElementNs(ctx->ctxt, localname, prefix, URI, nb_namespaces,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
592 namespaces, nb_attributes, nb_defaulted, attributes);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
594
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
595
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
596 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597 ngx_http_xslt_sax_end_element(void *data,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
598 const xmlChar * localname ATTRIBUTE_UNUSED,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
599 const xmlChar * prefix ATTRIBUTE_UNUSED,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600 const xmlChar * URI ATTRIBUTE_UNUSED)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
601 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
602 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604 ctx->sax->endElementNs(ctx->ctxt, localname, prefix, URI);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
605 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
606
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
608 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
609 ngx_http_xslt_sax_characters(void *data, const xmlChar *p, int len)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613 ctx->sax->characters(ctx->ctxt, p, len);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
614 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
615
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618 ngx_http_xslt_sax_cdata_block(void *data, const xmlChar *p, int len)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
620 ngx_http_xslt_filter_ctx_t *ctx = data;
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 ctx->sax->cdataBlock(ctx->ctxt, p, len);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626 static xmlEntityPtr
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627 ngx_http_xslt_sax_get_entity(void *data, const xmlChar *name)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
628 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
631 return ctx->sax->getEntity(ctx->ctxt, name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 static xmlEntityPtr
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 ngx_http_xslt_sax_get_parameter_entity(void *data, const xmlChar *name)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640 return ctx->sax->getParameterEntity(ctx->ctxt, name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 static xmlParserInputPtr
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645 ngx_http_xslt_sax_resolve_entity(void *data, const xmlChar *publicId,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646 const xmlChar *systemId)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650 return ctx->sax->resolveEntity(ctx->ctxt, publicId, systemId);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
653
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655 ngx_http_xslt_sax_reference(void *data, const xmlChar *name)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659 ctx->sax->reference(ctx->ctxt, name);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
663 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
664 ngx_http_xslt_sax_comment(void *data, const xmlChar *value)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
665 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
666 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668 ctx->sax->comment(ctx->ctxt, value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673 ngx_http_xslt_sax_processing_instruction(void *data, const xmlChar *target,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674 const xmlChar *pidata)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678 ctx->sax->processingInstruction(ctx->ctxt, target, pidata);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
679 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
680
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
682 static int
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
683 ngx_http_xslt_sax_is_standalone(void *data)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
684 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
685 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
686
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
687 return ctx->sax->isStandalone(ctx->ctxt);
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
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 static int
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
692 ngx_http_xslt_sax_has_internal_subset(void *data)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 return ctx->sax->hasInternalSubset(ctx->ctxt);
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
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 static int
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
701 ngx_http_xslt_sax_has_external_subset(void *data)
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 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
705 return ctx->sax->hasExternalSubset(ctx->ctxt);
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709 static void ngx_cdecl
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710 ngx_http_xslt_sax_error(void *data, const char *msg, ...)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
711 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
712 ngx_http_xslt_filter_ctx_t *ctx = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
713
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
714 size_t n;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 va_list args;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
716 u_char buf[NGX_MAX_ERROR_STR];
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
717
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718 buf[0] = '\0';
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 va_start(args, msg);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721 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
722 va_end(args);
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 while (--n && (buf[n] == CR || buf[n] == LF)) { /* void */ }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
725
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
726 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
727 "libxml2 error: \"%*s\"", n, buf);
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
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 static ngx_buf_t *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
732 ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
733 ngx_http_xslt_filter_ctx_t *ctx)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
734 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735 int len, rc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
736 ngx_buf_t *b;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
737 ngx_uint_t i;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 xmlChar *buf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
739 xmlDocPtr doc, res;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 ngx_http_xslt_sheet_t *sheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741 ngx_http_xslt_filter_conf_t *conf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 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
744 sheet = conf->sheets.elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745 doc = ctx->doc;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
746
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
747 /* preallocate array for 4 params */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
748
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
749 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
750 != NGX_OK)
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 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
753 return NULL;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 for (i = 0; i < conf->sheets.nelts; i++) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
757
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
758 if (ngx_http_xslt_params(r, ctx, &sheet[i].params) != NGX_OK) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
759 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
760 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
761 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
762
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
763 res = xsltApplyStylesheet(sheet[i].stylesheet, doc, ctx->params.elts);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
764
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
765 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
766
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
767 if (res == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
768 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
769 "xsltApplyStylesheet() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
770 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
771 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
772
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
773 doc = res;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
774
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
775 /* reset array elements */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
776 ctx->params.nelts = 0;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
777 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
778
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779 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
780 "xslt filter doc type: %d", doc->type);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
781
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782 ctx->html = (doc->type == XML_HTML_DOCUMENT_NODE) ? 1 : 0;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
784 rc = xsltSaveResultToString(&buf, &len, doc, sheet[i - 1].stylesheet);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
785
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
786 xmlFreeDoc(doc);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
787
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
788 if (rc != 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
789 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
790 "xsltSaveResultToString() failed");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
791 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
792 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
793
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
794 if (len == 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
795 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796 "xsltSaveResultToString() returned zero-length result");
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
797 return NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
798 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
799
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
800 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
801 if (b == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
802 ngx_free(buf);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
803 return NULL;
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 b->pos = buf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
807 b->last = buf + len;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
808 b->memory = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
809 b->last_buf = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
810
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
811 return b;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
812 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
813
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
814
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
815 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
816 ngx_http_xslt_params(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
817 ngx_array_t *params)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
818 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
819 u_char *p, *last, *value, *dst, *src, **s;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
820 size_t len;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
821 ngx_uint_t i;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
822 ngx_str_t string;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
823 ngx_http_xslt_param_t *param;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
824
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
825 param = params->elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
826
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
827 for (i = 0; i < params->nelts; i++) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
828
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
829 if (ngx_http_script_run(r, &string, param[i].lengths->elts, 1,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
830 param[i].values->elts)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
831 == NULL)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
832 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
833 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
834 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
835
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
836 last = string.data + string.len - 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
837 *last = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
838
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
839 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
840 "xslt filter param: \"%s\"", string.data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
841
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842 p = string.data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
843
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
844 while (p && *p) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
845
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
846 value = p;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
847 p = (u_char *) ngx_strchr(p, '=');
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
848 if (p == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
849 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
850 "invalid libxslt parameter \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
851 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
852 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
853 *p++ = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
854
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
855 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
856 "xslt filter param name: \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
857
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
858 s = ngx_array_push(&ctx->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
859 if (s == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
860 return NGX_ERROR;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
863 *s = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
864
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
865 value = p;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
866 p = (u_char *) ngx_strchr(p, ':');
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
867
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
868 if (p) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
869 len = p - value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
870 *p++ = '\0';
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
871
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
872 } else {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
873 len = last - value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
874 }
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 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
877 "xslt filter param value: \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
878
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
879 dst = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
880 src = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
881
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
882 ngx_unescape_uri(&dst, &src, len, 0);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
883
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
884 *dst = '\0';
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 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
887 "xslt filter param unescaped: \"%s\"", value);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
888
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
889 s = ngx_array_push(&ctx->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
890 if (s == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
891 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
892 }
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 *s = value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
895 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
898 s = ngx_array_push(&ctx->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
899 if (s == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
900 return NGX_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
901 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
902
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
903 *s = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
904
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
905 return NGX_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
906 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
907
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
908
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
909 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
910 ngx_http_xslt_cleanup(void *data)
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 ngx_free(data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
913 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
914
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
915
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
916 static char *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
917 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
918 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
919 ngx_http_xslt_filter_conf_t *xlcf = conf;
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 ngx_str_t *value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
922
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
923 if (xlcf->dtd) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
924 return "is duplicate";
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
925 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
926
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927 value = cf->args->elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 xlcf->dtd = xmlParseDTD(NULL, (xmlChar *) value[1].data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
930
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
931 if (xlcf->dtd == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932 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
933 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
934 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
935
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
936 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
937 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
941 static char *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
942 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
943 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
944 ngx_http_xslt_filter_conf_t *xlcf = conf;
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 ngx_str_t *value;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
947 ngx_uint_t i, n;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
948 ngx_pool_cleanup_t *cln;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
949 ngx_http_xslt_sheet_t *sheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
950 ngx_http_xslt_param_t *param;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
951 ngx_http_script_compile_t sc;
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 value = cf->args->elts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
954
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
955 if (xlcf->sheets.elts == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
956 if (ngx_array_init(&xlcf->sheets, cf->pool, 1,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
957 sizeof(ngx_http_xslt_sheet_t))
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
958 != NGX_OK)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
959 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
960 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
961 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
962 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
963
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
964 sheet = ngx_array_push(&xlcf->sheets);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
965 if (sheet == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
966 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
967 }
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 ngx_memzero(sheet, sizeof(ngx_http_xslt_sheet_t));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
970
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
971 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
972 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
973 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
974
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
975 cln = ngx_pool_cleanup_add(cf->pool, 0);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
976 if (cln == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
977 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
978 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
979
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
980 sheet->stylesheet = xsltParseStylesheetFile(value[1].data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
981 if (sheet->stylesheet == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
982 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
983 "xsltParseStylesheetFile(\"%s\") failed",
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
984 value[1].data);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
985 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
986 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
987
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
988 cln->handler = ngx_http_xslt_cleanup_stylesheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
989 cln->data = sheet->stylesheet;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
990
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
991 n = cf->args->nelts;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
992
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
993 if (n == 2) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
994 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
995 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
996
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
997 if (ngx_array_init(&sheet->params, cf->pool, n - 2,
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
998 sizeof(ngx_http_xslt_param_t))
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
999 != NGX_OK)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1000 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1001 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1002 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1003
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1004 for (i = 2; i < n; i++) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1005
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1006 param = ngx_array_push(&sheet->params);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1007 if (param == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1008 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1009 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1010
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1011 param->lengths = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1012 param->values = NULL;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1013
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1014 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1015
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1016 sc.cf = cf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1017 sc.source = &value[i];
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1018 sc.lengths = &param->lengths;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1019 sc.values = &param->values;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1020 sc.variables = ngx_http_script_variables_count(&value[i]);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1021 sc.complete_lengths = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1022 sc.complete_values = 1;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1023
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1024 if (ngx_http_script_compile(&sc) != NGX_OK) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1025 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1026 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1027 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1028
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1029 return NGX_CONF_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1030 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1031
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1032
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1033 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1034 ngx_http_xslt_cleanup_stylesheet(void *data)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1035 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1036 xsltStylesheetPtr stylesheet = data;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1037
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1038 xsltFreeStylesheet(stylesheet);
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1039 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1040
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1041
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1042
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1043 static void *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1044 ngx_http_xslt_filter_create_conf(ngx_conf_t *cf)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1045 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1046 ngx_http_xslt_filter_conf_t *conf;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1047
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1048 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_xslt_filter_conf_t));
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1049 if (conf == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1050 return NGX_CONF_ERROR;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1051 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1052
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1053 /*
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1054 * set by ngx_pcalloc():
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1055 *
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1056 * conf->dtd = NULL;
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1057 * conf->sheets = { NULL };
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1058 * conf->types = { NULL };
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1059 * conf->types_keys = NULL;
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1060 */
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1061
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1062 return conf;
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 static char *
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1067 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
1068 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1069 ngx_http_xslt_filter_conf_t *prev = parent;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1070 ngx_http_xslt_filter_conf_t *conf = child;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1071
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1072 if (conf->dtd == NULL) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1073 conf->dtd = prev->dtd;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1074 }
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1075
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1076 if (conf->sheets.nelts == 0) {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1077 conf->sheets = prev->sheets;
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
2148
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1080 if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1081 prev->types_keys, &prev->types,
071bc0fc1459 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2139
diff changeset
1082 ngx_http_xslt_default_types)
2139
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1083 != NGX_OK)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1084 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1085 return NGX_CONF_ERROR;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1088 return NGX_CONF_OK;
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1092 static ngx_int_t
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1093 ngx_http_xslt_filter_init(ngx_conf_t *cf)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1094 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1095 xmlInitParser();
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1096
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1097 ngx_http_next_header_filter = ngx_http_top_header_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1098 ngx_http_top_header_filter = ngx_http_xslt_header_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1099
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1100 ngx_http_next_body_filter = ngx_http_top_body_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1101 ngx_http_top_body_filter = ngx_http_xslt_body_filter;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1102
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1103 return NGX_OK;
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1104 }
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
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1107 static void
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1108 ngx_http_xslt_filter_exit(ngx_cycle_t *cycle)
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1109 {
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1110 xsltCleanupGlobals();
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1111 xmlCleanupParser();
dad4423ef56a ngx_http_xslt_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1112 }