File: xslt_extensions.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 3,056 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Copyright (C) 2001-2002 Thomas Broyer, Charlie Bozeman and Daniel Veillard.
 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is fur-
 * nished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
 * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
 * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the authors shall not
 * be used in advertising or otherwise to promote the sale, use or other deal-
 * ings in this Software without prior written authorization from him.
 */

#include "third_party/blink/renderer/core/xml/xslt_extensions.h"

#include <libxml/xpathInternals.h>
#include <libxslt/extensions.h>
#include <libxslt/extra.h>
#include <libxslt/xsltutils.h>

#include "base/check.h"

namespace blink {

// FIXME: This code is taken from libexslt 1.1.11; should sync with newer
// versions.
static void ExsltNodeSetFunction(xmlXPathParserContextPtr ctxt, int nargs) {
  xmlChar* strval;
  xmlNodePtr ret_node;
  xmlXPathObjectPtr ret;

  if (nargs != 1) {
    xmlXPathSetArityError(ctxt);
    return;
  }

  if (xmlXPathStackIsNodeSet(ctxt)) {
    xsltFunctionNodeSet(ctxt, nargs);
    return;
  }

  // node-set can also take a string and turn it into a singleton node
  // set with one text node. This may null-deref if allocating the
  // document, text node, etc. fails; that behavior is expected.

  // Create a document to hold the text node result.
  xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
  xmlDocPtr fragment = xsltCreateRVT(tctxt);
  xsltRegisterLocalRVT(tctxt, fragment);

  // Create the text node and wrap it in a result set.
  strval = xmlXPathPopString(ctxt);
  ret_node = xmlNewDocText(fragment, strval);
  xmlAddChild(reinterpret_cast<xmlNodePtr>(fragment), ret_node);
  ret = xmlXPathNewNodeSet(ret_node);
  CHECK(ret);

  if (strval)
    xmlFree(strval);

  valuePush(ctxt, ret);
}

void RegisterXSLTExtensions(xsltTransformContextPtr ctxt) {
  xsltRegisterExtFunction(ctxt, (const xmlChar*)"node-set",
                          (const xmlChar*)"http://exslt.org/common",
                          ExsltNodeSetFunction);
}

}  // namespace blink