3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #include <ngx_config.h>
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
14 #include <libxslt/xslt.h>
15 #include <libxslt/xsltInternals.h>
16 #include <libxslt/transform.h>
17 #include <libxslt/variables.h>
18 #include <libxslt/xsltutils.h>
21 #include <libexslt/exslt.h>
25 #ifndef NGX_HTTP_XSLT_REUSE_DTD
26 #define NGX_HTTP_XSLT_REUSE_DTD 1
33 } ngx_http_xslt_file_t;
37 ngx_array_t dtd_files; /* ngx_http_xslt_file_t */
38 ngx_array_t sheet_files; /* ngx_http_xslt_file_t */
39 } ngx_http_xslt_filter_main_conf_t;
44 ngx_http_complex_value_t value;
45 ngx_uint_t quote; /* unsigned quote:1; */
46 } ngx_http_xslt_param_t;
50 xsltStylesheetPtr stylesheet;
51 ngx_array_t params; /* ngx_http_xslt_param_t */
52 } ngx_http_xslt_sheet_t;
57 ngx_array_t sheets; /* ngx_http_xslt_sheet_t */
59 ngx_array_t *types_keys;
60 ngx_array_t *params; /* ngx_http_xslt_param_t */
61 ngx_flag_t last_modified;
62 } ngx_http_xslt_filter_loc_conf_t;
67 xmlParserCtxtPtr ctxt;
68 xsltTransformContextPtr transform;
69 ngx_http_request_t *request;
72 ngx_uint_t done; /* unsigned done:1; */
73 } ngx_http_xslt_filter_ctx_t;
76 static ngx_int_t ngx_http_xslt_send(ngx_http_request_t *r,
77 ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b);
78 static ngx_int_t ngx_http_xslt_add_chunk(ngx_http_request_t *r,
79 ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b);
82 static void ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
83 const xmlChar *externalId, const xmlChar *systemId);
84 static void ngx_cdecl ngx_http_xslt_sax_error(void *data, const char *msg, ...);
87 static ngx_buf_t *ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
88 ngx_http_xslt_filter_ctx_t *ctx);
89 static ngx_int_t ngx_http_xslt_params(ngx_http_request_t *r,
90 ngx_http_xslt_filter_ctx_t *ctx, ngx_array_t *params, ngx_uint_t final);
91 static u_char *ngx_http_xslt_content_type(xsltStylesheetPtr s);
92 static u_char *ngx_http_xslt_encoding(xsltStylesheetPtr s);
93 static void ngx_http_xslt_cleanup(void *data);
95 static char *ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd,
97 static char *ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd,
99 static char *ngx_http_xslt_param(ngx_conf_t *cf, ngx_command_t *cmd,
101 static void ngx_http_xslt_cleanup_dtd(void *data);
102 static void ngx_http_xslt_cleanup_stylesheet(void *data);
103 static void *ngx_http_xslt_filter_create_main_conf(ngx_conf_t *cf);
104 static void *ngx_http_xslt_filter_create_conf(ngx_conf_t *cf);
105 static char *ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent,
107 static ngx_int_t ngx_http_xslt_filter_preconfiguration(ngx_conf_t *cf);
108 static ngx_int_t ngx_http_xslt_filter_init(ngx_conf_t *cf);
109 static void ngx_http_xslt_filter_exit(ngx_cycle_t *cycle);
112 static ngx_str_t ngx_http_xslt_default_types[] = {
113 ngx_string("text/xml"),
118 static ngx_command_t ngx_http_xslt_filter_commands[] = {
120 { ngx_string("xml_entities"),
121 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
122 ngx_http_xslt_entities,
123 NGX_HTTP_LOC_CONF_OFFSET,
127 { ngx_string("xslt_stylesheet"),
128 NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
129 ngx_http_xslt_stylesheet,
130 NGX_HTTP_LOC_CONF_OFFSET,
134 { ngx_string("xslt_param"),
135 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
137 NGX_HTTP_LOC_CONF_OFFSET,
141 { ngx_string("xslt_string_param"),
142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
144 NGX_HTTP_LOC_CONF_OFFSET,
148 { ngx_string("xslt_types"),
149 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
151 NGX_HTTP_LOC_CONF_OFFSET,
152 offsetof(ngx_http_xslt_filter_loc_conf_t, types_keys),
153 &ngx_http_xslt_default_types[0] },
155 { ngx_string("xslt_last_modified"),
156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
157 ngx_conf_set_flag_slot,
158 NGX_HTTP_LOC_CONF_OFFSET,
159 offsetof(ngx_http_xslt_filter_loc_conf_t, last_modified),
166 static ngx_http_module_t ngx_http_xslt_filter_module_ctx = {
167 ngx_http_xslt_filter_preconfiguration, /* preconfiguration */
168 ngx_http_xslt_filter_init, /* postconfiguration */
170 ngx_http_xslt_filter_create_main_conf, /* create main configuration */
171 NULL, /* init main configuration */
173 NULL, /* create server configuration */
174 NULL, /* merge server configuration */
176 ngx_http_xslt_filter_create_conf, /* create location configuration */
177 ngx_http_xslt_filter_merge_conf /* merge location configuration */
181 ngx_module_t ngx_http_xslt_filter_module = {
183 &ngx_http_xslt_filter_module_ctx, /* module context */
184 ngx_http_xslt_filter_commands, /* module directives */
185 NGX_HTTP_MODULE, /* module type */
186 NULL, /* init master */
187 NULL, /* init module */
188 NULL, /* init process */
189 NULL, /* init thread */
190 NULL, /* exit thread */
191 ngx_http_xslt_filter_exit, /* exit process */
192 ngx_http_xslt_filter_exit, /* exit master */
193 NGX_MODULE_V1_PADDING
197 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
198 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
202 ngx_http_xslt_header_filter(ngx_http_request_t *r)
204 ngx_http_xslt_filter_ctx_t *ctx;
205 ngx_http_xslt_filter_loc_conf_t *conf;
207 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
208 "xslt filter header");
210 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
211 return ngx_http_next_header_filter(r);
214 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);
216 if (conf->sheets.nelts == 0
217 || ngx_http_test_content_type(r, &conf->types) == NULL)
219 return ngx_http_next_header_filter(r);
222 ctx = ngx_http_get_module_ctx(r, ngx_http_xslt_filter_module);
225 return ngx_http_next_header_filter(r);
228 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_xslt_filter_ctx_t));
233 ngx_http_set_ctx(r, ctx, ngx_http_xslt_filter_module);
235 r->main_filter_need_in_memory = 1;
242 ngx_http_xslt_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
246 ngx_http_xslt_filter_ctx_t *ctx;
248 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
252 return ngx_http_next_body_filter(r, in);
255 ctx = ngx_http_get_module_ctx(r, ngx_http_xslt_filter_module);
257 if (ctx == NULL || ctx->done) {
258 return ngx_http_next_body_filter(r, in);
261 for (cl = in; cl; cl = cl->next) {
263 if (ngx_http_xslt_add_chunk(r, ctx, cl->buf) != NGX_OK) {
265 if (ctx->ctxt->myDoc) {
267 #if (NGX_HTTP_XSLT_REUSE_DTD)
268 ctx->ctxt->myDoc->extSubset = NULL;
270 xmlFreeDoc(ctx->ctxt->myDoc);
273 xmlFreeParserCtxt(ctx->ctxt);
275 return ngx_http_xslt_send(r, ctx, NULL);
278 if (cl->buf->last_buf || cl->buf->last_in_chain) {
280 ctx->doc = ctx->ctxt->myDoc;
282 #if (NGX_HTTP_XSLT_REUSE_DTD)
283 ctx->doc->extSubset = NULL;
286 wellFormed = ctx->ctxt->wellFormed;
288 xmlFreeParserCtxt(ctx->ctxt);
291 return ngx_http_xslt_send(r, ctx,
292 ngx_http_xslt_apply_stylesheet(r, ctx));
295 xmlFreeDoc(ctx->doc);
297 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
298 "not well formed XML document");
300 return ngx_http_xslt_send(r, ctx, NULL);
309 ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
314 ngx_pool_cleanup_t *cln;
315 ngx_http_xslt_filter_loc_conf_t *conf;
320 return ngx_http_filter_finalize_request(r, &ngx_http_xslt_filter_module,
321 NGX_HTTP_INTERNAL_SERVER_ERROR);
324 cln = ngx_pool_cleanup_add(r->pool, 0);
328 return ngx_http_filter_finalize_request(r, &ngx_http_xslt_filter_module,
329 NGX_HTTP_INTERNAL_SERVER_ERROR);
333 r->headers_out.content_length_n = b->last - b->pos;
335 if (r->headers_out.content_length) {
336 r->headers_out.content_length->hash = 0;
337 r->headers_out.content_length = NULL;
340 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);
342 if (!conf->last_modified) {
343 ngx_http_clear_last_modified(r);
344 ngx_http_clear_etag(r);
347 ngx_http_weak_etag(r);
351 rc = ngx_http_next_header_filter(r);
353 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
358 cln->handler = ngx_http_xslt_cleanup;
364 return ngx_http_next_body_filter(r, &out);
369 ngx_http_xslt_add_chunk(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
373 xmlParserCtxtPtr ctxt;
375 if (ctx->ctxt == NULL) {
377 ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
379 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
380 "xmlCreatePushParserCtxt() failed");
383 xmlCtxtUseOptions(ctxt, XML_PARSE_NOENT|XML_PARSE_DTDLOAD
384 |XML_PARSE_NOWARNING);
386 ctxt->sax->externalSubset = ngx_http_xslt_sax_external_subset;
387 ctxt->sax->setDocumentLocator = NULL;
388 ctxt->sax->error = ngx_http_xslt_sax_error;
389 ctxt->sax->fatalError = ngx_http_xslt_sax_error;
390 ctxt->sax->_private = ctx;
396 err = xmlParseChunk(ctx->ctxt, (char *) b->pos, (int) (b->last - b->pos),
397 (b->last_buf) || (b->last_in_chain));
404 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
405 "xmlParseChunk() failed, error:%d", err);
412 ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
413 const xmlChar *externalId, const xmlChar *systemId)
415 xmlParserCtxtPtr ctxt = data;
419 ngx_http_request_t *r;
420 ngx_http_xslt_filter_ctx_t *ctx;
421 ngx_http_xslt_filter_loc_conf_t *conf;
423 ctx = ctxt->sax->_private;
426 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);
428 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
429 "xslt filter extSubset: \"%s\" \"%s\" \"%s\"",
430 name ? name : (xmlChar *) "",
431 externalId ? externalId : (xmlChar *) "",
432 systemId ? systemId : (xmlChar *) "");
436 #if (NGX_HTTP_XSLT_REUSE_DTD)
442 dtd = xmlCopyDtd(conf->dtd);
444 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
445 "xmlCopyDtd() failed");
449 if (doc->children == NULL) {
450 xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);
453 xmlAddPrevSibling(doc->children, (xmlNodePtr) dtd);
458 doc->extSubset = dtd;
462 static void ngx_cdecl
463 ngx_http_xslt_sax_error(void *data, const char *msg, ...)
465 xmlParserCtxtPtr ctxt = data;
469 ngx_http_xslt_filter_ctx_t *ctx;
470 u_char buf[NGX_MAX_ERROR_STR];
472 ctx = ctxt->sax->_private;
477 n = (size_t) vsnprintf((char *) buf, NGX_MAX_ERROR_STR, msg, args);
480 while (--n && (buf[n] == CR || buf[n] == LF)) { /* void */ }
482 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
483 "libxml2 error: \"%*s\"", n + 1, buf);
488 ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
489 ngx_http_xslt_filter_ctx_t *ctx)
491 int len, rc, doc_type;
492 u_char *type, *encoding;
497 ngx_http_xslt_sheet_t *sheet;
498 ngx_http_xslt_filter_loc_conf_t *conf;
500 conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);
501 sheet = conf->sheets.elts;
504 /* preallocate array for 4 params */
506 if (ngx_array_init(&ctx->params, r->pool, 4 * 2 + 1, sizeof(char *))
513 for (i = 0; i < conf->sheets.nelts; i++) {
515 ctx->transform = xsltNewTransformContext(sheet[i].stylesheet, doc);
516 if (ctx->transform == NULL) {
522 && ngx_http_xslt_params(r, ctx, conf->params, 0) != NGX_OK)
524 xsltFreeTransformContext(ctx->transform);
529 if (ngx_http_xslt_params(r, ctx, &sheet[i].params, 1) != NGX_OK) {
530 xsltFreeTransformContext(ctx->transform);
535 res = xsltApplyStylesheetUser(sheet[i].stylesheet, doc,
536 ctx->params.elts, NULL, NULL,
539 xsltFreeTransformContext(ctx->transform);
543 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
544 "xsltApplyStylesheet() failed");
550 /* reset array elements */
551 ctx->params.nelts = 0;
554 /* there must be at least one stylesheet */
557 type = ngx_http_xslt_content_type(sheet[i - 1].stylesheet);
563 encoding = ngx_http_xslt_encoding(sheet[i - 1].stylesheet);
564 doc_type = doc->type;
566 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
567 "xslt filter type: %d t:%s e:%s",
568 doc_type, type ? type : (u_char *) "(null)",
569 encoding ? encoding : (u_char *) "(null)");
571 rc = xsltSaveResultToString(&buf, &len, doc, sheet[i - 1].stylesheet);
576 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
577 "xsltSaveResultToString() failed");
582 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
583 "xsltSaveResultToString() returned zero-length result");
587 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
598 r->headers_out.charset.len = ngx_strlen(encoding);
599 r->headers_out.charset.data = encoding;
609 len = ngx_strlen(type);
611 r->headers_out.content_type_len = len;
612 r->headers_out.content_type.len = len;
613 r->headers_out.content_type.data = type;
615 } else if (doc_type == XML_HTML_DOCUMENT_NODE) {
617 r->headers_out.content_type_len = sizeof("text/html") - 1;
618 ngx_str_set(&r->headers_out.content_type, "text/html");
621 r->headers_out.content_type_lowcase = NULL;
628 ngx_http_xslt_params(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
629 ngx_array_t *params, ngx_uint_t final)
631 u_char *p, *last, *value, *dst, *src, **s;
635 ngx_http_xslt_param_t *param;
637 param = params->elts;
639 for (i = 0; i < params->nelts; i++) {
641 if (ngx_http_complex_value(r, ¶m[i].value, &string) != NGX_OK) {
645 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
646 "xslt filter param: \"%s\"", string.data);
650 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
651 "xslt filter param name: \"%s\"", param[i].name);
653 if (param[i].quote) {
654 if (xsltQuoteOneUserParam(ctx->transform, param[i].name,
658 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
659 "xsltQuoteOneUserParam(\"%s\", \"%s\") failed",
660 param[i].name, string.data);
667 s = ngx_array_push(&ctx->params);
674 s = ngx_array_push(&ctx->params);
685 * parse param1=value1:param2=value2 syntax as used by parameters
686 * specified in xslt_stylesheet directives
690 last = string.data + string.len;
695 p = (u_char *) ngx_strchr(p, '=');
697 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
698 "invalid libxslt parameter \"%s\"", value);
703 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
704 "xslt filter param name: \"%s\"", value);
706 s = ngx_array_push(&ctx->params);
714 p = (u_char *) ngx_strchr(p, ':');
724 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
725 "xslt filter param value: \"%s\"", value);
730 ngx_unescape_uri(&dst, &src, len, 0);
734 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
735 "xslt filter param unescaped: \"%s\"", value);
737 s = ngx_array_push(&ctx->params);
747 s = ngx_array_push(&ctx->params);
760 ngx_http_xslt_content_type(xsltStylesheetPtr s)
768 for (s = s->imports; s; s = s->next) {
770 type = ngx_http_xslt_content_type(s);
782 ngx_http_xslt_encoding(xsltStylesheetPtr s)
790 for (s = s->imports; s; s = s->next) {
792 encoding = ngx_http_xslt_encoding(s);
804 ngx_http_xslt_cleanup(void *data)
811 ngx_http_xslt_entities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
813 ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
817 ngx_pool_cleanup_t *cln;
818 ngx_http_xslt_file_t *file;
819 ngx_http_xslt_filter_main_conf_t *xmcf;
822 return "is duplicate";
825 value = cf->args->elts;
827 xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module);
829 file = xmcf->dtd_files.elts;
830 for (i = 0; i < xmcf->dtd_files.nelts; i++) {
831 if (ngx_strcmp(file[i].name, value[1].data) == 0) {
832 xlcf->dtd = file[i].data;
837 cln = ngx_pool_cleanup_add(cf->pool, 0);
839 return NGX_CONF_ERROR;
842 xlcf->dtd = xmlParseDTD(NULL, (xmlChar *) value[1].data);
844 if (xlcf->dtd == NULL) {
845 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "xmlParseDTD() failed");
846 return NGX_CONF_ERROR;
849 cln->handler = ngx_http_xslt_cleanup_dtd;
850 cln->data = xlcf->dtd;
852 file = ngx_array_push(&xmcf->dtd_files);
854 return NGX_CONF_ERROR;
857 file->name = value[1].data;
858 file->data = xlcf->dtd;
866 ngx_http_xslt_stylesheet(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
868 ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
872 ngx_pool_cleanup_t *cln;
873 ngx_http_xslt_file_t *file;
874 ngx_http_xslt_sheet_t *sheet;
875 ngx_http_xslt_param_t *param;
876 ngx_http_compile_complex_value_t ccv;
877 ngx_http_xslt_filter_main_conf_t *xmcf;
879 value = cf->args->elts;
881 if (xlcf->sheets.elts == NULL) {
882 if (ngx_array_init(&xlcf->sheets, cf->pool, 1,
883 sizeof(ngx_http_xslt_sheet_t))
886 return NGX_CONF_ERROR;
890 sheet = ngx_array_push(&xlcf->sheets);
892 return NGX_CONF_ERROR;
895 ngx_memzero(sheet, sizeof(ngx_http_xslt_sheet_t));
897 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
898 return NGX_CONF_ERROR;
901 xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module);
903 file = xmcf->sheet_files.elts;
904 for (i = 0; i < xmcf->sheet_files.nelts; i++) {
905 if (ngx_strcmp(file[i].name, value[1].data) == 0) {
906 sheet->stylesheet = file[i].data;
911 cln = ngx_pool_cleanup_add(cf->pool, 0);
913 return NGX_CONF_ERROR;
916 sheet->stylesheet = xsltParseStylesheetFile(value[1].data);
917 if (sheet->stylesheet == NULL) {
918 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
919 "xsltParseStylesheetFile(\"%s\") failed",
921 return NGX_CONF_ERROR;
924 cln->handler = ngx_http_xslt_cleanup_stylesheet;
925 cln->data = sheet->stylesheet;
927 file = ngx_array_push(&xmcf->sheet_files);
929 return NGX_CONF_ERROR;
932 file->name = value[1].data;
933 file->data = sheet->stylesheet;
943 if (ngx_array_init(&sheet->params, cf->pool, n - 2,
944 sizeof(ngx_http_xslt_param_t))
947 return NGX_CONF_ERROR;
950 for (i = 2; i < n; i++) {
952 param = ngx_array_push(&sheet->params);
954 return NGX_CONF_ERROR;
957 ngx_memzero(param, sizeof(ngx_http_xslt_param_t));
958 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
961 ccv.value = &value[i];
962 ccv.complex_value = ¶m->value;
965 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
966 return NGX_CONF_ERROR;
975 ngx_http_xslt_param(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
977 ngx_http_xslt_filter_loc_conf_t *xlcf = conf;
979 ngx_http_xslt_param_t *param;
980 ngx_http_compile_complex_value_t ccv;
983 value = cf->args->elts;
985 if (xlcf->params == NULL) {
986 xlcf->params = ngx_array_create(cf->pool, 2,
987 sizeof(ngx_http_xslt_param_t));
988 if (xlcf->params == NULL) {
989 return NGX_CONF_ERROR;
993 param = ngx_array_push(xlcf->params);
995 return NGX_CONF_ERROR;
998 param->name = value[1].data;
999 param->quote = (cmd->post == NULL) ? 0 : 1;
1001 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1004 ccv.value = &value[2];
1005 ccv.complex_value = ¶m->value;
1008 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1009 return NGX_CONF_ERROR;
1017 ngx_http_xslt_cleanup_dtd(void *data)
1024 ngx_http_xslt_cleanup_stylesheet(void *data)
1026 xsltFreeStylesheet(data);
1031 ngx_http_xslt_filter_create_main_conf(ngx_conf_t *cf)
1033 ngx_http_xslt_filter_main_conf_t *conf;
1035 conf = ngx_palloc(cf->pool, sizeof(ngx_http_xslt_filter_main_conf_t));
1040 if (ngx_array_init(&conf->dtd_files, cf->pool, 1,
1041 sizeof(ngx_http_xslt_file_t))
1047 if (ngx_array_init(&conf->sheet_files, cf->pool, 1,
1048 sizeof(ngx_http_xslt_file_t))
1059 ngx_http_xslt_filter_create_conf(ngx_conf_t *cf)
1061 ngx_http_xslt_filter_loc_conf_t *conf;
1063 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_xslt_filter_loc_conf_t));
1069 * set by ngx_pcalloc():
1072 * conf->sheets = { NULL };
1073 * conf->types = { NULL };
1074 * conf->types_keys = NULL;
1075 * conf->params = NULL;
1078 conf->last_modified = NGX_CONF_UNSET;
1085 ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
1087 ngx_http_xslt_filter_loc_conf_t *prev = parent;
1088 ngx_http_xslt_filter_loc_conf_t *conf = child;
1090 if (conf->dtd == NULL) {
1091 conf->dtd = prev->dtd;
1094 if (conf->sheets.nelts == 0) {
1095 conf->sheets = prev->sheets;
1098 if (conf->params == NULL) {
1099 conf->params = prev->params;
1102 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
1103 &prev->types_keys, &prev->types,
1104 ngx_http_xslt_default_types)
1107 return NGX_CONF_ERROR;
1110 ngx_conf_merge_value(conf->last_modified, prev->last_modified, 0);
1117 ngx_http_xslt_filter_preconfiguration(ngx_conf_t *cf)
1121 #if (NGX_HAVE_EXSLT)
1130 ngx_http_xslt_filter_init(ngx_conf_t *cf)
1132 ngx_http_next_header_filter = ngx_http_top_header_filter;
1133 ngx_http_top_header_filter = ngx_http_xslt_header_filter;
1135 ngx_http_next_body_filter = ngx_http_top_body_filter;
1136 ngx_http_top_body_filter = ngx_http_xslt_body_filter;
1143 ngx_http_xslt_filter_exit(ngx_cycle_t *cycle)
1145 xsltCleanupGlobals();