Advertisement
Guest User

Changes in nginx-html-xslt vs nginx (0.7.67)

a guest
Mar 8th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 23.92 KB | None | 0 0
  1. Index: src/http/ngx_http_variables.c
  2. ===================================================================
  3. --- src/http/ngx_http_variables.c   (revision 4524)
  4. +++ src/http/ngx_http_variables.c   (working copy)
  5. @@ -427,7 +427,7 @@
  6.  
  7.      v = &r->variables[index];
  8.  
  9. -    if (v->valid) {
  10. +    if (v->valid || v->not_found) {
  11.          if (!v->no_cacheable) {
  12.              return v;
  13.          }
  14. Index: src/http/modules/ngx_http_xslt_filter_module.c
  15. ===================================================================
  16. --- src/http/modules/ngx_http_xslt_filter_module.c  (revision 4524)
  17. +++ src/http/modules/ngx_http_xslt_filter_module.c  (working copy)
  18. @@ -9,6 +9,7 @@
  19.  #include <ngx_http.h>
  20.  
  21.  #include <libxml/parser.h>
  22. +#include <libxml/HTMLparser.h>
  23.  #include <libxml/tree.h>
  24.  #include <libxslt/xslt.h>
  25.  #include <libxslt/xsltInternals.h>
  26. @@ -19,7 +20,6 @@
  27.  #include <libexslt/exslt.h>
  28.  #endif
  29.  
  30. -
  31.  #ifndef NGX_HTTP_XSLT_REUSE_DTD
  32.  #define NGX_HTTP_XSLT_REUSE_DTD  1
  33.  #endif
  34. @@ -48,6 +48,8 @@
  35.      ngx_array_t          sheets;       /* ngx_http_xslt_sheet_t */
  36.      ngx_hash_t           types;
  37.      ngx_array_t         *types_keys;
  38. +    ngx_flag_t           html_parser;
  39. +    ngx_flag_t           parse_recover;
  40.  } ngx_http_xslt_filter_loc_conf_t;
  41.  
  42.  
  43. @@ -57,6 +59,8 @@
  44.      xmlSAXHandler       *sax;
  45.      ngx_http_request_t  *request;
  46.      ngx_array_t          params;
  47. +    ngx_flag_t           html_parser;
  48. +    ngx_flag_t           parse_recover;
  49.  
  50.      ngx_uint_t           done;         /* unsigned  done:1; */
  51.  } ngx_http_xslt_filter_ctx_t;
  52. @@ -68,49 +72,8 @@
  53.      ngx_http_xslt_filter_ctx_t *ctx, ngx_buf_t *b);
  54.  
  55.  
  56. -static void ngx_http_xslt_sax_start_document(void *data);
  57. -static void ngx_http_xslt_sax_end_document(void *data);
  58. -static void ngx_http_xslt_sax_internal_subset(void *data, const xmlChar *name,
  59. -    const xmlChar *externalId, const xmlChar *systemId);
  60.  static void ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
  61.      const xmlChar *externalId, const xmlChar *systemId);
  62. -static void ngx_http_xslt_sax_entity_decl(void *data, const xmlChar *name,
  63. -    int type, const xmlChar *publicId, const xmlChar *systemId,
  64. -    xmlChar *content);
  65. -static void ngx_http_xslt_sax_attribute_decl(void *data, const xmlChar *elem,
  66. -    const xmlChar *fullname, int type, int def, const xmlChar *defaultValue,
  67. -    xmlEnumerationPtr tree);
  68. -static void ngx_http_xslt_sax_element_decl(void *data, const xmlChar * name,
  69. -    int type, xmlElementContentPtr content);
  70. -static void ngx_http_xslt_sax_notation_decl(void *data, const xmlChar *name,
  71. -    const xmlChar *publicId, const xmlChar *systemId);
  72. -static void ngx_http_xslt_sax_unparsed_entity_decl(void *data,
  73. -    const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId,
  74. -    const xmlChar *notationName);
  75. -static void ngx_http_xslt_sax_start_element(void *data,
  76. -    const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI,
  77. -    int nb_namespaces, const xmlChar **namespaces, int nb_attributes,
  78. -    int nb_defaulted, const xmlChar **attributes);
  79. -static void ngx_http_xslt_sax_end_element(void *data,
  80. -    const xmlChar * localname ATTRIBUTE_UNUSED,
  81. -    const xmlChar * prefix ATTRIBUTE_UNUSED,
  82. -    const xmlChar * URI ATTRIBUTE_UNUSED);
  83. -static void ngx_http_xslt_sax_characters(void *data, const xmlChar *p, int len);
  84. -static void ngx_http_xslt_sax_cdata_block(void *data, const xmlChar *p,
  85. -    int len);
  86. -static xmlEntityPtr ngx_http_xslt_sax_get_entity(void *data,
  87. -    const xmlChar *name);
  88. -static xmlEntityPtr ngx_http_xslt_sax_get_parameter_entity(void *data,
  89. -    const xmlChar *name);
  90. -static xmlParserInputPtr ngx_http_xslt_sax_resolve_entity(void *data,
  91. -    const xmlChar *publicId, const xmlChar *systemId);
  92. -static void ngx_http_xslt_sax_reference(void *data, const xmlChar *name);
  93. -static void ngx_http_xslt_sax_comment(void *data, const xmlChar *value);
  94. -static void ngx_http_xslt_sax_processing_instruction(void *data,
  95. -    const xmlChar *target, const xmlChar *pidata);
  96. -static int ngx_http_xslt_sax_is_standalone(void *data);
  97. -static int ngx_http_xslt_sax_has_internal_subset(void *data);
  98. -static int ngx_http_xslt_sax_has_external_subset(void *data);
  99.  static void ngx_cdecl ngx_http_xslt_sax_error(void *data, const char *msg, ...);
  100.  
  101.  
  102. @@ -137,7 +100,7 @@
  103.  
  104.  
  105.  ngx_str_t  ngx_http_xslt_default_types[] = {
  106. -    ngx_string("text/xml"),
  107. +    ngx_string("example/workaround"),
  108.      ngx_null_string
  109.  };
  110.  
  111. @@ -165,6 +128,20 @@
  112.        offsetof(ngx_http_xslt_filter_loc_conf_t, types_keys),
  113.        &ngx_http_xslt_default_types[0] },
  114.  
  115. +    { ngx_string("xslt_html_parser"),
  116. +      NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
  117. +      ngx_conf_set_flag_slot,
  118. +      NGX_HTTP_LOC_CONF_OFFSET,
  119. +      offsetof(ngx_http_xslt_filter_loc_conf_t, html_parser),
  120. +      NULL },
  121. +
  122. +    { ngx_string("xslt_parse_recover"),
  123. +      NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
  124. +      ngx_conf_set_flag_slot,
  125. +      NGX_HTTP_LOC_CONF_OFFSET,
  126. +      offsetof(ngx_http_xslt_filter_loc_conf_t, parse_recover),
  127. +      NULL },
  128. +
  129.        ngx_null_command
  130.  };
  131.  
  132. @@ -240,6 +217,9 @@
  133.  
  134.      r->main_filter_need_in_memory = 1;
  135.  
  136. +    ctx->html_parser = conf->html_parser;
  137. +    ctx->parse_recover = conf->parse_recover;
  138. +
  139.      return NGX_OK;
  140.  }
  141.  
  142. @@ -247,7 +227,6 @@
  143.  static ngx_int_t
  144.  ngx_http_xslt_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
  145.  {
  146. -    int                          wellFormed;
  147.      ngx_chain_t                 *cl;
  148.      ngx_http_xslt_filter_ctx_t  *ctx;
  149.  
  150. @@ -264,6 +243,10 @@
  151.          return ngx_http_next_body_filter(r, in);
  152.      }
  153.  
  154. +    if (r->headers_out.content_length_n == 0) {
  155. +        return ngx_http_xslt_send(r, ctx, in->buf);
  156. +    }
  157. +
  158.      for (cl = in; cl; cl = cl->next) {
  159.  
  160.          if (ngx_http_xslt_add_chunk(r, ctx, cl->buf) != NGX_OK) {
  161. @@ -276,7 +259,11 @@
  162.                  xmlFreeDoc(ctx->ctxt->myDoc);
  163.              }
  164.  
  165. -            xmlFreeParserCtxt(ctx->ctxt);
  166. +            if (ctx->html_parser) {
  167. +                htmlFreeParserCtxt(ctx->ctxt);
  168. +            } else {
  169. +                xmlFreeParserCtxt(ctx->ctxt);
  170. +            }
  171.  
  172.              return ngx_http_xslt_send(r, ctx, NULL);
  173.          }
  174. @@ -289,11 +276,13 @@
  175.              ctx->doc->extSubset = NULL;
  176.  #endif
  177.  
  178. -            wellFormed = ctx->ctxt->wellFormed;
  179. +            if (ctx->html_parser) {
  180. +                htmlFreeParserCtxt(ctx->ctxt);
  181. +            } else {
  182. +                xmlFreeParserCtxt(ctx->ctxt);
  183. +            }
  184.  
  185. -            xmlFreeParserCtxt(ctx->ctxt);
  186. -
  187. -            if (wellFormed) {
  188. +            if (ctx->parse_recover || ctx->ctxt->wellFormed) {
  189.                  return ngx_http_xslt_send(r, ctx,
  190.                                         ngx_http_xslt_apply_stylesheet(r, ctx));
  191.              }
  192. @@ -371,12 +360,21 @@
  193.      xmlParserCtxtPtr   ctxt;
  194.  
  195.      if (ctx->ctxt == NULL) {
  196. -
  197. -        ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
  198. -        if (ctxt == NULL) {
  199. -            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  200. -                          "xmlCreatePushParserCtxt() failed");
  201. -            return NGX_ERROR;
  202. +        
  203. +        if (ctx->html_parser) {
  204. +            ctxt = htmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL, XML_CHAR_ENCODING_UTF8);
  205. +            if (ctxt == NULL) {
  206. +                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  207. +                              "htmlCreatePushParserCtxt() failed");
  208. +                return NGX_ERROR;
  209. +            }
  210. +        } else {
  211. +            ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
  212. +            if (ctxt == NULL) {
  213. +                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  214. +                              "xmlCreatePushParserCtxt() failed");
  215. +                return NGX_ERROR;
  216. +            }
  217.          }
  218.  
  219.          ctx->sax = ngx_palloc(r->pool, sizeof(xmlSAXHandler));
  220. @@ -388,96 +386,69 @@
  221.  
  222.          ngx_memcpy(ctx->sax, sax, sizeof(xmlSAXHandler));
  223.  
  224. -        sax->startDocument = ngx_http_xslt_sax_start_document;
  225. -        sax->endDocument = ngx_http_xslt_sax_end_document;
  226. -
  227. -        sax->internalSubset = ngx_http_xslt_sax_internal_subset;
  228.          sax->externalSubset = ngx_http_xslt_sax_external_subset;
  229. -        sax->entityDecl = ngx_http_xslt_sax_entity_decl;
  230. -        sax->attributeDecl = ngx_http_xslt_sax_attribute_decl;
  231. -        sax->elementDecl = ngx_http_xslt_sax_element_decl;
  232. -        sax->notationDecl = ngx_http_xslt_sax_notation_decl;
  233. -        sax->unparsedEntityDecl = ngx_http_xslt_sax_unparsed_entity_decl;
  234.          sax->setDocumentLocator = NULL;
  235. -
  236. -        sax->startElementNs = ngx_http_xslt_sax_start_element;
  237. -        sax->endElementNs = ngx_http_xslt_sax_end_element;
  238. -
  239. -        sax->characters = ngx_http_xslt_sax_characters;
  240. -        sax->ignorableWhitespace = ngx_http_xslt_sax_characters;
  241. -        sax->cdataBlock = ngx_http_xslt_sax_cdata_block;
  242. -        sax->getEntity = ngx_http_xslt_sax_get_entity;
  243. -        sax->resolveEntity = ngx_http_xslt_sax_resolve_entity;
  244. -        sax->getParameterEntity = ngx_http_xslt_sax_get_parameter_entity;
  245. -        sax->reference = ngx_http_xslt_sax_reference;
  246. -        sax->comment = ngx_http_xslt_sax_comment;
  247. -        sax->processingInstruction = ngx_http_xslt_sax_processing_instruction;
  248. -
  249. -        sax->isStandalone = ngx_http_xslt_sax_is_standalone;
  250. -        sax->hasInternalSubset = ngx_http_xslt_sax_has_internal_subset;
  251. -        sax->hasExternalSubset = ngx_http_xslt_sax_has_external_subset;
  252. -
  253.          sax->warning = NULL;
  254.          sax->error = ngx_http_xslt_sax_error;
  255.          sax->fatalError = ngx_http_xslt_sax_error;
  256.  
  257. -        ctxt->userData = ctx;
  258. +        sax->_private = ctx;
  259.  
  260.          ctxt->replaceEntities = 1;
  261.          ctxt->loadsubset = 1;
  262.  
  263.          ctx->ctxt = ctxt;
  264.          ctx->request = r;
  265. +        
  266. +        if (ctx->html_parser) {
  267. +            if (ctx->parse_recover) {
  268. +                htmlCtxtUseOptions(ctxt, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET | HTML_PARSE_COMPACT);
  269. +            } else {
  270. +                htmlCtxtUseOptions(ctxt, HTML_PARSE_NONET | HTML_PARSE_COMPACT);
  271. +            }
  272. +        } else {
  273. +            if (ctx->parse_recover) {
  274. +                xmlCtxtUseOptions(ctxt, XML_PARSE_RECOVER | XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
  275. +            }
  276. +        }
  277.      }
  278.  
  279. -    err = xmlParseChunk(ctx->ctxt, (char *) b->pos, (int) (b->last - b->pos),
  280. -                        (b->last_buf) || (b->last_in_chain));
  281. +    if (ctx->html_parser) {
  282. +        err = htmlParseChunk(ctx->ctxt, (char *) b->pos, (int) (b->last - b->pos),
  283. +                             (b->last_buf) || (b->last_in_chain));
  284.  
  285. -    if (err == 0) {
  286. -        b->pos = b->last;
  287. -        return NGX_OK;
  288. -    }
  289. +        if (ctx->parse_recover || err == 0) {
  290. +            b->pos = b->last;
  291. +            return NGX_OK;
  292. +        }
  293.  
  294. -    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  295. -                  "xmlParseChunk() failed, error:%d", err);
  296. +        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  297. +                      "htmlParseChunk() failed, error:%d", err);
  298.  
  299. -    return NGX_ERROR;
  300. -}
  301. +        return NGX_ERROR;
  302. +    } else {
  303. +        err = xmlParseChunk(ctx->ctxt, (char *) b->pos, (int) (b->last - b->pos),
  304. +                            (b->last_buf) || (b->last_in_chain));
  305.  
  306. +        if (ctx->parse_recover || err == 0) {
  307. +            b->pos = b->last;
  308. +            return NGX_OK;
  309. +        }
  310.  
  311. -static void
  312. -ngx_http_xslt_sax_start_document(void *data)
  313. -{
  314. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  315. +        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  316. +                      "xmlParseChunk() failed, error:%d", err);
  317.  
  318. -    ctx->sax->startDocument(ctx->ctxt);
  319. +        return NGX_ERROR;
  320. +    }
  321.  }
  322.  
  323.  
  324.  static void
  325. -ngx_http_xslt_sax_end_document(void *data)
  326. -{
  327. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  328. -
  329. -    ctx->sax->endDocument(ctx->ctxt);
  330. -}
  331. -
  332. -
  333. -static void
  334. -ngx_http_xslt_sax_internal_subset(void *data, const xmlChar *name,
  335. -    const xmlChar *externalId, const xmlChar *systemId)
  336. -{
  337. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  338. -
  339. -    ctx->sax->internalSubset(ctx->ctxt, name, externalId, systemId);
  340. -}
  341. -
  342. -
  343. -static void
  344.  ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
  345.      const xmlChar *externalId, const xmlChar *systemId)
  346.  {
  347. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  348. +    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) data;
  349. +    ngx_http_xslt_filter_ctx_t *ctx = ctxt->sax->_private;
  350.  
  351.      xmlDocPtr                         doc;
  352.      xmlDtdPtr                         dtd;
  353. @@ -522,190 +493,11 @@
  354.  }
  355.  
  356.  
  357. -static void
  358. -ngx_http_xslt_sax_entity_decl(void *data, const xmlChar *name, int type,
  359. -    const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
  360. -{
  361. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  362. -
  363. -    ctx->sax->entityDecl(ctx->ctxt, name, type, publicId, systemId, content);
  364. -}
  365. -
  366. -
  367. -static void
  368. -ngx_http_xslt_sax_attribute_decl(void *data, const xmlChar *elem,
  369. -    const xmlChar *fullname, int type, int def, const xmlChar *defaultValue,
  370. -    xmlEnumerationPtr tree)
  371. -{
  372. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  373. -
  374. -    ctx->sax->attributeDecl(ctx->ctxt, elem, fullname, type, def, defaultValue,
  375. -                            tree);
  376. -}
  377. -
  378. -
  379. -static void
  380. -ngx_http_xslt_sax_element_decl(void *data, const xmlChar * name, int type,
  381. -    xmlElementContentPtr content)
  382. -{
  383. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  384. -
  385. -    ctx->sax->elementDecl(ctx->ctxt, name, type, content);
  386. -}
  387. -
  388. -
  389. -static void
  390. -ngx_http_xslt_sax_notation_decl(void *data, const xmlChar *name,
  391. -    const xmlChar *publicId, const xmlChar *systemId)
  392. -{
  393. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  394. -
  395. -    ctx->sax->notationDecl(ctx->ctxt, name, publicId, systemId);
  396. -}
  397. -
  398. -
  399. -static void
  400. -ngx_http_xslt_sax_unparsed_entity_decl(void *data, const xmlChar *name,
  401. -    const xmlChar *publicId, const xmlChar *systemId,
  402. -    const xmlChar *notationName)
  403. -{
  404. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  405. -
  406. -    ctx->sax->unparsedEntityDecl(ctx->ctxt, name, publicId, systemId,
  407. -                                 notationName);
  408. -}
  409. -
  410. -
  411. -static void
  412. -ngx_http_xslt_sax_start_element(void *data, const xmlChar *localname,
  413. -    const xmlChar *prefix, const xmlChar *URI, int nb_namespaces,
  414. -    const xmlChar **namespaces, int nb_attributes, int nb_defaulted,
  415. -    const xmlChar **attributes)
  416. -{
  417. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  418. -
  419. -    ctx->sax->startElementNs(ctx->ctxt, localname, prefix, URI, nb_namespaces,
  420. -        namespaces, nb_attributes, nb_defaulted, attributes);
  421. -}
  422. -
  423. -
  424. -static void
  425. -ngx_http_xslt_sax_end_element(void *data,
  426. -    const xmlChar * localname ATTRIBUTE_UNUSED,
  427. -    const xmlChar * prefix ATTRIBUTE_UNUSED,
  428. -    const xmlChar * URI ATTRIBUTE_UNUSED)
  429. -{
  430. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  431. -
  432. -    ctx->sax->endElementNs(ctx->ctxt, localname, prefix, URI);
  433. -}
  434. -
  435. -
  436. -static void
  437. -ngx_http_xslt_sax_characters(void *data, const xmlChar *p, int len)
  438. -{
  439. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  440. -
  441. -    ctx->sax->characters(ctx->ctxt, p, len);
  442. -}
  443. -
  444. -
  445. -static void
  446. -ngx_http_xslt_sax_cdata_block(void *data, const xmlChar *p, int len)
  447. -{
  448. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  449. -
  450. -    ctx->sax->cdataBlock(ctx->ctxt, p, len);
  451. -}
  452. -
  453. -
  454. -static xmlEntityPtr
  455. -ngx_http_xslt_sax_get_entity(void *data, const xmlChar *name)
  456. -{
  457. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  458. -
  459. -    return ctx->sax->getEntity(ctx->ctxt, name);
  460. -}
  461. -
  462. -
  463. -static xmlEntityPtr
  464. -ngx_http_xslt_sax_get_parameter_entity(void *data, const xmlChar *name)
  465. -{
  466. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  467. -
  468. -    return ctx->sax->getParameterEntity(ctx->ctxt, name);
  469. -}
  470. -
  471. -
  472. -static xmlParserInputPtr
  473. -ngx_http_xslt_sax_resolve_entity(void *data, const xmlChar *publicId,
  474. -    const xmlChar *systemId)
  475. -{
  476. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  477. -
  478. -    return ctx->sax->resolveEntity(ctx->ctxt, publicId, systemId);
  479. -}
  480. -
  481. -
  482. -static void
  483. -ngx_http_xslt_sax_reference(void *data, const xmlChar *name)
  484. -{
  485. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  486. -
  487. -    ctx->sax->reference(ctx->ctxt, name);
  488. -}
  489. -
  490. -
  491. -static void
  492. -ngx_http_xslt_sax_comment(void *data, const xmlChar *value)
  493. -{
  494. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  495. -
  496. -    ctx->sax->comment(ctx->ctxt, value);
  497. -}
  498. -
  499. -
  500. -static void
  501. -ngx_http_xslt_sax_processing_instruction(void *data, const xmlChar *target,
  502. -    const xmlChar *pidata)
  503. -{
  504. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  505. -
  506. -    ctx->sax->processingInstruction(ctx->ctxt, target, pidata);
  507. -}
  508. -
  509. -
  510. -static int
  511. -ngx_http_xslt_sax_is_standalone(void *data)
  512. -{
  513. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  514. -
  515. -    return ctx->sax->isStandalone(ctx->ctxt);
  516. -}
  517. -
  518. -
  519. -static int
  520. -ngx_http_xslt_sax_has_internal_subset(void *data)
  521. -{
  522. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  523. -
  524. -    return ctx->sax->hasInternalSubset(ctx->ctxt);
  525. -}
  526. -
  527. -
  528. -static int
  529. -ngx_http_xslt_sax_has_external_subset(void *data)
  530. -{
  531. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  532. -
  533. -    return ctx->sax->hasExternalSubset(ctx->ctxt);
  534. -}
  535. -
  536. -
  537.  static void ngx_cdecl
  538.  ngx_http_xslt_sax_error(void *data, const char *msg, ...)
  539.  {
  540. -    ngx_http_xslt_filter_ctx_t *ctx = data;
  541. +    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) data;
  542. +    ngx_http_xslt_filter_ctx_t *ctx = ctxt->sax->_private;
  543.  
  544.      size_t    n;
  545.      va_list   args;
  546. @@ -869,60 +661,49 @@
  547.                         "xslt filter param: \"%s\"", string.data);
  548.  
  549.          p = string.data;
  550. -        last = string.data + string.len - 1;
  551. +        last = string.data + string.len;
  552.  
  553. -        while (p && *p) {
  554. +        value = p;
  555. +        p = (u_char *) ngx_strchr(p, '=');
  556. +        if (p == NULL) {
  557. +            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  558. +                            "invalid libxslt parameter \"%s\"", value);
  559. +            return NGX_ERROR;
  560. +        }
  561. +        *p++ = '\0';
  562.  
  563. -            value = p;
  564. -            p = (u_char *) ngx_strchr(p, '=');
  565. -            if (p == NULL) {
  566. -                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
  567. -                                "invalid libxslt parameter \"%s\"", value);
  568. -                return NGX_ERROR;
  569. -            }
  570. -            *p++ = '\0';
  571. +        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  572. +                       "xslt filter param name: \"%s\"", value);
  573.  
  574. -            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  575. -                           "xslt filter param name: \"%s\"", value);
  576. +        s = ngx_array_push(&ctx->params);
  577. +        if (s == NULL) {
  578. +            return NGX_ERROR;
  579. +        }
  580.  
  581. -            s = ngx_array_push(&ctx->params);
  582. -            if (s == NULL) {
  583. -                return NGX_ERROR;
  584. -            }
  585. +        *s = value;
  586.  
  587. -            *s = value;
  588. +        value = p;
  589. +        len = last - value;
  590.  
  591. -            value = p;
  592. -            p = (u_char *) ngx_strchr(p, ':');
  593. +        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  594. +                       "xslt filter param value: \"%s\"", value);
  595.  
  596. -            if (p) {
  597. -                len = p - value;
  598. -                *p++ = '\0';
  599. +        dst = value;
  600. +        src = value;
  601.  
  602. -            } else {
  603. -                len = last - value;
  604. -            }
  605. +        ngx_unescape_uri(&dst, &src, len, 0);
  606.  
  607. -            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  608. -                           "xslt filter param value: \"%s\"", value);
  609. +        *dst = '\0';
  610.  
  611. -            dst = value;
  612. -            src = value;
  613. +        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  614. +                       "xslt filter param unescaped: \"%s\"", value);
  615.  
  616. -            ngx_unescape_uri(&dst, &src, len, 0);
  617. -
  618. -            *dst = '\0';
  619. -
  620. -            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  621. -                           "xslt filter param unescaped: \"%s\"", value);
  622. -
  623. -            s = ngx_array_push(&ctx->params);
  624. -            if (s == NULL) {
  625. -                return NGX_ERROR;
  626. -            }
  627. -
  628. -            *s = value;
  629. +        s = ngx_array_push(&ctx->params);
  630. +        if (s == NULL) {
  631. +            return NGX_ERROR;
  632.          }
  633. +
  634. +        *s = value;
  635.      }
  636.  
  637.      s = ngx_array_push(&ctx->params);
  638. @@ -1210,8 +991,13 @@
  639.       *     conf->sheets = { NULL };
  640.       *     conf->types = { NULL };
  641.       *     conf->types_keys = NULL;
  642. +     *     conf->html_parser = NULL;
  643. +     *     conf->parse_recover = NULL;
  644.       */
  645.  
  646. +    conf->html_parser = NGX_CONF_UNSET;
  647. +    conf->parse_recover = NGX_CONF_UNSET;
  648. +
  649.      return conf;
  650.  }
  651.  
  652. @@ -1238,6 +1024,9 @@
  653.          return NGX_CONF_ERROR;
  654.      }
  655.  
  656. +    ngx_conf_merge_value(conf->html_parser, prev->html_parser, 0);
  657. +    ngx_conf_merge_value(conf->parse_recover, prev->parse_recover, 1);
  658. +
  659.      return NGX_CONF_OK;
  660.  }
  661.  
  662. Index: auto/options
  663. ===================================================================
  664. --- auto/options    (revision 4524)
  665. +++ auto/options    (working copy)
  666. @@ -125,6 +125,9 @@
  667.  NGX_PERL=perl
  668.  
  669.  USE_LIBXSLT=NO
  670. +LIBXML2=NONE
  671. +LIBXSLT=NONE
  672. +
  673.  USE_LIBGD=NO
  674.  
  675.  NGX_GOOGLE_PERFTOOLS=NO
  676. @@ -262,6 +265,9 @@
  677.          --with-zlib-opt=*)               ZLIB_OPT="$value"          ;;
  678.          --with-zlib-asm=*)               ZLIB_ASM="$value"          ;;
  679.  
  680. +        --with-libxml2=*)                LIBXML2="$value"           ;;
  681. +        --with-libxslt=*)                LIBXSLT="$value"           ;;
  682. +
  683.          --test-build-devpoll)            NGX_TEST_BUILD_DEVPOLL=YES ;;
  684.          --test-build-eventport)          NGX_TEST_BUILD_EVENTPORT=YES ;;
  685.          --test-build-epoll)              NGX_TEST_BUILD_EPOLL=YES   ;;
  686. @@ -394,6 +400,9 @@
  687.                                       for specified CPU, the valid values:
  688.                                       pentium, pentiumpro
  689.  
  690. +  --with-libxml2=DIR                 set path to libxml2 library sources
  691. +  --with-libxslt=DIR                 set path to libxslt library sources
  692. +
  693.    --with-openssl=DIR                 set path to OpenSSL library sources
  694.    --with-openssl-opt=OPTIONS         set additional options for OpenSSL building
  695.  
  696. Index: auto/lib/libxslt/conf
  697. ===================================================================
  698. --- auto/lib/libxslt/conf   (revision 4524)
  699. +++ auto/lib/libxslt/conf   (working copy)
  700. @@ -13,6 +13,23 @@
  701.                        #include <libxslt/xsltutils.h>"
  702.      ngx_feature_path="/usr/include/libxml2"
  703.      ngx_feature_libs="-lxml2 -lxslt"
  704. +    if [ "$LIBXML2" != NONE ]; then
  705. +        ngx_feature_path="$LIBXML2/include/libxml2"
  706. +        if [ $NGX_RPATH = YES ]; then
  707. +            ngx_feature_libs="-R$LIBXML2/lib -L$LIBXML2/lib $ngx_feature_libs"
  708. +        else
  709. +            ngx_feature_libs="-L$LIBXML2/lib $ngx_feature_libs"
  710. +        fi
  711. +    fi
  712. +    if [ "$LIBXSLT" != NONE ]; then
  713. +        ngx_feature_path="$LIBXSLT/include $ngx_feature_path"
  714. +        if [ $NGX_RPATH = YES ]; then
  715. +            ngx_feature_libs="-R$LIBXSLT/lib -L$LIBXSLT/lib $ngx_feature_libs"
  716. +        else
  717. +            ngx_feature_libs="-L$LIBXSLT/lib $ngx_feature_libs"
  718. +        fi
  719. +    fi    
  720. +
  721.      ngx_feature_test="xmlParserCtxtPtr    ctxt = NULL;
  722.                        xsltStylesheetPtr   sheet = NULL;
  723.                        xmlDocPtr           doc;
  724. @@ -94,13 +111,29 @@
  725.      ngx_feature_name=NGX_HAVE_EXSLT
  726.      ngx_feature_run=no
  727.      ngx_feature_incs="#include <libexslt/exslt.h>"
  728. -    ngx_feature_path="/usr/include/libxml2"
  729. -    ngx_feature_libs="-lexslt"
  730. +    ngx_feature_libs="-lexslt $ngx_feature_libs"
  731.      ngx_feature_test="exsltRegisterAll();"
  732.      . auto/feature
  733.  
  734.  if [ $ngx_found = no ]; then
  735.  
  736. +    # /usr
  737. +
  738. +    ngx_feature="libexslt in /usr/"
  739. +    ngx_feature_path="/usr/libxml2 /usr/include"
  740. +
  741. +    if [ $NGX_RPATH = YES ]; then
  742. +        ngx_feature_libs="-R/usr/lib -L/usr/lib -lexslt"
  743. +    else
  744. +        ngx_feature_libs="-L/usr/lib -lexslt"
  745. +    fi
  746. +
  747. +    . auto/feature
  748. +fi
  749. +
  750. +
  751. +if [ $ngx_found = no ]; then
  752. +
  753.      # FreeBSD port
  754.  
  755.      ngx_feature="libexslt in /usr/local/"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement