@helm2/poc_jenki_rce 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of @helm2/poc_jenki_rce might be problematic. Click here for more details.
- package/LICENSE +19 -0
- package/Makefile +18 -0
- package/README.md +52 -0
- package/binding.gyp +81 -0
- package/index.d.ts +273 -0
- package/index.js +45 -0
- package/lib/bindings.js +1 -0
- package/lib/document.js +118 -0
- package/lib/element.js +82 -0
- package/lib/sax_parser.js +38 -0
- package/package.json +70 -0
- package/src/html_document.cc +7 -0
- package/src/html_document.h +18 -0
- package/src/libxmljs.cc +252 -0
- package/src/libxmljs.h +53 -0
- package/src/xml_attribute.cc +173 -0
- package/src/xml_attribute.h +40 -0
- package/src/xml_comment.cc +117 -0
- package/src/xml_comment.h +30 -0
- package/src/xml_document.cc +810 -0
- package/src/xml_document.h +67 -0
- package/src/xml_element.cc +565 -0
- package/src/xml_element.h +61 -0
- package/src/xml_namespace.cc +158 -0
- package/src/xml_namespace.h +39 -0
- package/src/xml_node.cc +761 -0
- package/src/xml_node.h +73 -0
- package/src/xml_pi.cc +161 -0
- package/src/xml_pi.h +34 -0
- package/src/xml_sax_parser.cc +424 -0
- package/src/xml_sax_parser.h +73 -0
- package/src/xml_syntax_error.cc +66 -0
- package/src/xml_syntax_error.h +25 -0
- package/src/xml_text.cc +320 -0
- package/src/xml_text.h +48 -0
- package/src/xml_textwriter.cc +315 -0
- package/src/xml_textwriter.h +62 -0
- package/src/xml_xpath_context.cc +70 -0
- package/src/xml_xpath_context.h +23 -0
- package/vendor/libxml/Copyright +23 -0
- package/vendor/libxml/DOCBparser.c +305 -0
- package/vendor/libxml/HTMLparser.c +7287 -0
- package/vendor/libxml/HTMLtree.c +1200 -0
- package/vendor/libxml/Makefile +2983 -0
- package/vendor/libxml/SAX.c +180 -0
- package/vendor/libxml/SAX2.c +3036 -0
- package/vendor/libxml/buf.c +1351 -0
- package/vendor/libxml/buf.h +72 -0
- package/vendor/libxml/c14n.c +2234 -0
- package/vendor/libxml/catalog.c +3828 -0
- package/vendor/libxml/chvalid.c +336 -0
- package/vendor/libxml/config.h +294 -0
- package/vendor/libxml/config.h.gch +0 -0
- package/vendor/libxml/debugXML.c +3423 -0
- package/vendor/libxml/dict.c +1298 -0
- package/vendor/libxml/elfgcchack.h +17818 -0
- package/vendor/libxml/enc.h +32 -0
- package/vendor/libxml/encoding.c +3975 -0
- package/vendor/libxml/entities.c +1163 -0
- package/vendor/libxml/error.c +998 -0
- package/vendor/libxml/globals.c +1126 -0
- package/vendor/libxml/hash.c +1146 -0
- package/vendor/libxml/include/libxml/DOCBparser.h +96 -0
- package/vendor/libxml/include/libxml/HTMLparser.h +306 -0
- package/vendor/libxml/include/libxml/HTMLtree.h +147 -0
- package/vendor/libxml/include/libxml/Makefile +725 -0
- package/vendor/libxml/include/libxml/Makefile.am +54 -0
- package/vendor/libxml/include/libxml/Makefile.in +725 -0
- package/vendor/libxml/include/libxml/SAX.h +173 -0
- package/vendor/libxml/include/libxml/SAX2.h +178 -0
- package/vendor/libxml/include/libxml/c14n.h +128 -0
- package/vendor/libxml/include/libxml/catalog.h +182 -0
- package/vendor/libxml/include/libxml/chvalid.h +230 -0
- package/vendor/libxml/include/libxml/debugXML.h +217 -0
- package/vendor/libxml/include/libxml/dict.h +79 -0
- package/vendor/libxml/include/libxml/encoding.h +245 -0
- package/vendor/libxml/include/libxml/entities.h +151 -0
- package/vendor/libxml/include/libxml/globals.h +508 -0
- package/vendor/libxml/include/libxml/hash.h +236 -0
- package/vendor/libxml/include/libxml/list.h +137 -0
- package/vendor/libxml/include/libxml/nanoftp.h +163 -0
- package/vendor/libxml/include/libxml/nanohttp.h +81 -0
- package/vendor/libxml/include/libxml/parser.h +1243 -0
- package/vendor/libxml/include/libxml/parserInternals.h +644 -0
- package/vendor/libxml/include/libxml/pattern.h +100 -0
- package/vendor/libxml/include/libxml/relaxng.h +217 -0
- package/vendor/libxml/include/libxml/schemasInternals.h +958 -0
- package/vendor/libxml/include/libxml/schematron.h +142 -0
- package/vendor/libxml/include/libxml/threads.h +89 -0
- package/vendor/libxml/include/libxml/tree.h +1311 -0
- package/vendor/libxml/include/libxml/uri.h +94 -0
- package/vendor/libxml/include/libxml/valid.h +458 -0
- package/vendor/libxml/include/libxml/xinclude.h +129 -0
- package/vendor/libxml/include/libxml/xlink.h +189 -0
- package/vendor/libxml/include/libxml/xmlIO.h +368 -0
- package/vendor/libxml/include/libxml/xmlautomata.h +146 -0
- package/vendor/libxml/include/libxml/xmlerror.h +945 -0
- package/vendor/libxml/include/libxml/xmlexports.h +77 -0
- package/vendor/libxml/include/libxml/xmlmemory.h +224 -0
- package/vendor/libxml/include/libxml/xmlmodule.h +57 -0
- package/vendor/libxml/include/libxml/xmlreader.h +428 -0
- package/vendor/libxml/include/libxml/xmlregexp.h +222 -0
- package/vendor/libxml/include/libxml/xmlsave.h +88 -0
- package/vendor/libxml/include/libxml/xmlschemas.h +246 -0
- package/vendor/libxml/include/libxml/xmlschemastypes.h +151 -0
- package/vendor/libxml/include/libxml/xmlstring.h +140 -0
- package/vendor/libxml/include/libxml/xmlunicode.h +202 -0
- package/vendor/libxml/include/libxml/xmlversion.h +484 -0
- package/vendor/libxml/include/libxml/xmlwin32version.h +239 -0
- package/vendor/libxml/include/libxml/xmlwriter.h +488 -0
- package/vendor/libxml/include/libxml/xpath.h +564 -0
- package/vendor/libxml/include/libxml/xpathInternals.h +632 -0
- package/vendor/libxml/include/libxml/xpointer.h +114 -0
- package/vendor/libxml/include/win32config.h +122 -0
- package/vendor/libxml/include/wsockcompat.h +54 -0
- package/vendor/libxml/legacy.c +1343 -0
- package/vendor/libxml/libxml.h +134 -0
- package/vendor/libxml/list.c +779 -0
- package/vendor/libxml/nanoftp.c +2118 -0
- package/vendor/libxml/nanohttp.c +1899 -0
- package/vendor/libxml/parser.c +15553 -0
- package/vendor/libxml/parserInternals.c +2164 -0
- package/vendor/libxml/pattern.c +2621 -0
- package/vendor/libxml/relaxng.c +11101 -0
- package/vendor/libxml/rngparser.c +1595 -0
- package/vendor/libxml/runsuite.c +1157 -0
- package/vendor/libxml/save.h +36 -0
- package/vendor/libxml/schematron.c +1787 -0
- package/vendor/libxml/threads.c +1049 -0
- package/vendor/libxml/timsort.h +601 -0
- package/vendor/libxml/tree.c +10183 -0
- package/vendor/libxml/trio.c +6895 -0
- package/vendor/libxml/trio.h +230 -0
- package/vendor/libxml/triodef.h +228 -0
- package/vendor/libxml/trionan.c +914 -0
- package/vendor/libxml/trionan.h +84 -0
- package/vendor/libxml/triop.h +150 -0
- package/vendor/libxml/triostr.c +2112 -0
- package/vendor/libxml/triostr.h +144 -0
- package/vendor/libxml/uri.c +2561 -0
- package/vendor/libxml/valid.c +7138 -0
- package/vendor/libxml/xinclude.c +2657 -0
- package/vendor/libxml/xlink.c +183 -0
- package/vendor/libxml/xmlIO.c +4135 -0
- package/vendor/libxml/xmlcatalog.c +624 -0
- package/vendor/libxml/xmllint.c +3796 -0
- package/vendor/libxml/xmlmemory.c +1163 -0
- package/vendor/libxml/xmlmodule.c +468 -0
- package/vendor/libxml/xmlreader.c +6033 -0
- package/vendor/libxml/xmlregexp.c +8271 -0
- package/vendor/libxml/xmlsave.c +2735 -0
- package/vendor/libxml/xmlschemas.c +29173 -0
- package/vendor/libxml/xmlschemastypes.c +6276 -0
- package/vendor/libxml/xmlstring.c +1050 -0
- package/vendor/libxml/xmlunicode.c +3179 -0
- package/vendor/libxml/xmlwriter.c +4738 -0
- package/vendor/libxml/xpath.c +14734 -0
- package/vendor/libxml/xpointer.c +2969 -0
- package/vendor/libxml/xzlib.c +815 -0
- package/vendor/libxml/xzlib.h +19 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
const events = require('events');
|
2
|
+
|
3
|
+
const bindings = require('./bindings');
|
4
|
+
|
5
|
+
const SaxParser = function SaxParser(callbacks) {
|
6
|
+
const parser = new bindings.SaxParser();
|
7
|
+
|
8
|
+
// attach callbacks
|
9
|
+
for (const callback in callbacks) {
|
10
|
+
parser.on(callback, callbacks[callback]);
|
11
|
+
}
|
12
|
+
|
13
|
+
return parser;
|
14
|
+
};
|
15
|
+
|
16
|
+
// Overriding the prototype, like util.inherit, wipes out the native binding.
|
17
|
+
// Copy over the methods instead.
|
18
|
+
for (const k in events.EventEmitter.prototype)
|
19
|
+
bindings.SaxParser.prototype[k] = events.EventEmitter.prototype[k];
|
20
|
+
|
21
|
+
const SaxPushParser = function SaxPushParser(callbacks) {
|
22
|
+
const parser = new bindings.SaxPushParser();
|
23
|
+
|
24
|
+
// attach callbacks
|
25
|
+
for (const callback in callbacks) {
|
26
|
+
parser.on(callback, callbacks[callback]);
|
27
|
+
}
|
28
|
+
|
29
|
+
return parser;
|
30
|
+
};
|
31
|
+
|
32
|
+
// Overriding the prototype, like util.inherit, wipes out the native binding.
|
33
|
+
// Copy over the methods instead.
|
34
|
+
for (const k in events.EventEmitter.prototype)
|
35
|
+
bindings.SaxPushParser.prototype[k] = events.EventEmitter.prototype[k];
|
36
|
+
|
37
|
+
module.exports.SaxParser = SaxParser;
|
38
|
+
module.exports.SaxPushParser = SaxPushParser;
|
package/package.json
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
{
|
2
|
+
"name": "@helm2/poc_jenki_rce",
|
3
|
+
"author": "marudor",
|
4
|
+
"contributors": [
|
5
|
+
"Jeff Smick",
|
6
|
+
"Marco Rogers"
|
7
|
+
],
|
8
|
+
"packageManager": "pnpm@6.32.9",
|
9
|
+
"binary": {
|
10
|
+
"module_name": "xmljs",
|
11
|
+
"module_path": "./build/Release/",
|
12
|
+
"host": "https://github.com",
|
13
|
+
"remote_path": "./marudor/libxmljs2/releases/download/v{version}/",
|
14
|
+
"package_name": "{node_abi}-{platform}-{arch}-{libc}.tar.gz"
|
15
|
+
},
|
16
|
+
"description": "libxml bindings for v8 javascript engine",
|
17
|
+
"version": "0.0.1",
|
18
|
+
"scripts": {
|
19
|
+
"build": "node-pre-gyp install --build-from-source",
|
20
|
+
"install": "node-pre-gyp install --fallback-to-build --loglevel http",
|
21
|
+
"test": "node --expose_gc ./node_modules/jest/bin/jest.js",
|
22
|
+
"lint": "eslint index.js test",
|
23
|
+
"tsd": "tsd",
|
24
|
+
"package": "node-pre-gyp package 2>&1"
|
25
|
+
},
|
26
|
+
"repository": {
|
27
|
+
"type": "git",
|
28
|
+
"url": "git+ssh://git@github.com/marudor/libxmljs2.git"
|
29
|
+
},
|
30
|
+
"bugs": {
|
31
|
+
"url": "http://github.com/marudor/libxmljs2/issues"
|
32
|
+
},
|
33
|
+
"main": "./index",
|
34
|
+
"license": "MIT",
|
35
|
+
"engines": {
|
36
|
+
"node": ">=12"
|
37
|
+
},
|
38
|
+
"files": [
|
39
|
+
"index.js",
|
40
|
+
"index.d.ts",
|
41
|
+
"src",
|
42
|
+
"lib",
|
43
|
+
"vendor",
|
44
|
+
"binding.gyp",
|
45
|
+
"Makefile"
|
46
|
+
],
|
47
|
+
"dependencies": {
|
48
|
+
"@mapbox/node-pre-gyp": "^1.0.9",
|
49
|
+
"bindings": "~1.5.0",
|
50
|
+
"child_process": "^1.0.2",
|
51
|
+
"nan": "~2.15.0",
|
52
|
+
"net": "^1.0.2"
|
53
|
+
},
|
54
|
+
"devDependencies": {
|
55
|
+
"eslint": "^8.14.0",
|
56
|
+
"eslint-config-marudor": "^9.0.0",
|
57
|
+
"jest": "^27.5.1",
|
58
|
+
"jest-watch-typeahead": "^1.0.0",
|
59
|
+
"prettier": "^2.6.2",
|
60
|
+
"tsd": "^0.20.0",
|
61
|
+
"typescript": "^4.6.3"
|
62
|
+
},
|
63
|
+
"types": "./index.d.ts",
|
64
|
+
"homepage": "https://github.com/marudor/libxmljs2#readme",
|
65
|
+
"directories": {
|
66
|
+
"example": "examples",
|
67
|
+
"lib": "lib",
|
68
|
+
"test": "test"
|
69
|
+
}
|
70
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
#ifndef SRC_HTML_DOCUMENT_H_
|
3
|
+
#define SRC_HTML_DOCUMENT_H_
|
4
|
+
|
5
|
+
#include "libxmljs.h"
|
6
|
+
#include "xml_document.h"
|
7
|
+
|
8
|
+
namespace libxmljs {
|
9
|
+
|
10
|
+
class HtmlDocument : public XmlDocument {
|
11
|
+
public:
|
12
|
+
explicit HtmlDocument(xmlDoc *doc) : XmlDocument(doc) {}
|
13
|
+
static void Initialize(v8::Local<v8::Object> target);
|
14
|
+
};
|
15
|
+
|
16
|
+
} // namespace libxmljs
|
17
|
+
|
18
|
+
#endif // SRC_HTML_DOCUMENT_H_
|
package/src/libxmljs.cc
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
|
3
|
+
#include <v8.h>
|
4
|
+
|
5
|
+
#include <libxml/xmlmemory.h>
|
6
|
+
|
7
|
+
#include "libxmljs.h"
|
8
|
+
#include "xml_document.h"
|
9
|
+
#include "xml_namespace.h"
|
10
|
+
#include "xml_node.h"
|
11
|
+
#include "xml_sax_parser.h"
|
12
|
+
#include "xml_textwriter.h"
|
13
|
+
|
14
|
+
using namespace v8;
|
15
|
+
namespace libxmljs {
|
16
|
+
|
17
|
+
// ensure destruction at exit time
|
18
|
+
// v8 doesn't cleanup its resources
|
19
|
+
LibXMLJS LibXMLJS::instance;
|
20
|
+
|
21
|
+
// track how much memory libxml2 is using
|
22
|
+
int xml_memory_used = 0;
|
23
|
+
|
24
|
+
// How often we report memory usage changes back to V8.
|
25
|
+
const int nan_adjust_external_memory_threshold = 1024 * 1024;
|
26
|
+
|
27
|
+
// track how many nodes haven't been freed
|
28
|
+
int nodeCount = 0;
|
29
|
+
|
30
|
+
void adjustExternalMemory() {
|
31
|
+
const int diff = xmlMemUsed() - xml_memory_used;
|
32
|
+
|
33
|
+
if (abs(diff) > nan_adjust_external_memory_threshold) {
|
34
|
+
xml_memory_used += diff;
|
35
|
+
Nan::AdjustExternalMemory(diff);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
// wrapper for xmlMemMalloc to update v8's knowledge of memory used
|
40
|
+
// the GC relies on this information
|
41
|
+
void *xmlMemMallocWrap(size_t size) {
|
42
|
+
void *res = xmlMemMalloc(size);
|
43
|
+
|
44
|
+
// no need to udpate memory if we didn't allocate
|
45
|
+
if (!res) {
|
46
|
+
return res;
|
47
|
+
}
|
48
|
+
|
49
|
+
adjustExternalMemory();
|
50
|
+
return res;
|
51
|
+
}
|
52
|
+
|
53
|
+
// wrapper for xmlMemFree to update v8's knowledge of memory used
|
54
|
+
// the GC relies on this information
|
55
|
+
void xmlMemFreeWrap(void *p) {
|
56
|
+
xmlMemFree(p);
|
57
|
+
|
58
|
+
// if v8 is no longer running, don't try to adjust memory
|
59
|
+
// this happens when the v8 vm is shutdown and the program is exiting
|
60
|
+
// our cleanup routines for libxml will be called (freeing memory)
|
61
|
+
// but v8 is already offline and does not need to be informed
|
62
|
+
// trying to adjust after shutdown will result in a fatal error
|
63
|
+
if (Isolate::GetCurrent() == 0 || Isolate::GetCurrent()->IsDead()) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
67
|
+
adjustExternalMemory();
|
68
|
+
}
|
69
|
+
|
70
|
+
// wrapper for xmlMemRealloc to update v8's knowledge of memory used
|
71
|
+
void *xmlMemReallocWrap(void *ptr, size_t size) {
|
72
|
+
void *res = xmlMemRealloc(ptr, size);
|
73
|
+
|
74
|
+
// if realloc fails, no need to update v8 memory state
|
75
|
+
if (!res) {
|
76
|
+
return res;
|
77
|
+
}
|
78
|
+
|
79
|
+
adjustExternalMemory();
|
80
|
+
return res;
|
81
|
+
}
|
82
|
+
|
83
|
+
// wrapper for xmlMemoryStrdupWrap to update v8's knowledge of memory used
|
84
|
+
char *xmlMemoryStrdupWrap(const char *str) {
|
85
|
+
char *res = xmlMemoryStrdup(str);
|
86
|
+
|
87
|
+
// if strdup fails, no need to update v8 memory state
|
88
|
+
if (!res) {
|
89
|
+
return res;
|
90
|
+
}
|
91
|
+
|
92
|
+
adjustExternalMemory();
|
93
|
+
return res;
|
94
|
+
}
|
95
|
+
|
96
|
+
void deregisterNsList(xmlNs *ns) {
|
97
|
+
while (ns != NULL) {
|
98
|
+
if (ns->_private != NULL) {
|
99
|
+
XmlNamespace *wrapper = static_cast<XmlNamespace *>(ns->_private);
|
100
|
+
wrapper->xml_obj = NULL;
|
101
|
+
ns->_private = NULL;
|
102
|
+
}
|
103
|
+
ns = ns->next;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
void deregisterNodeNamespaces(xmlNode *xml_obj) {
|
108
|
+
xmlNs *ns = NULL;
|
109
|
+
if ((xml_obj->type == XML_DOCUMENT_NODE) ||
|
110
|
+
#ifdef LIBXML_DOCB_ENABLED
|
111
|
+
(xml_obj->type == XML_DOCB_DOCUMENT_NODE) ||
|
112
|
+
#endif
|
113
|
+
(xml_obj->type == XML_HTML_DOCUMENT_NODE)) {
|
114
|
+
ns = reinterpret_cast<xmlDoc *>(xml_obj)->oldNs;
|
115
|
+
} else if ((xml_obj->type == XML_ELEMENT_NODE) ||
|
116
|
+
(xml_obj->type == XML_XINCLUDE_START) ||
|
117
|
+
(xml_obj->type == XML_XINCLUDE_END)) {
|
118
|
+
ns = xml_obj->nsDef;
|
119
|
+
}
|
120
|
+
if (ns != NULL) {
|
121
|
+
deregisterNsList(ns);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* Before libxmljs nodes are freed, they are passed to the deregistration
|
127
|
+
* callback, (configured by `xmlDeregisterNodeDefault`).
|
128
|
+
*
|
129
|
+
* In deregistering each node, we update any wrapper (e.g. `XmlElement`,
|
130
|
+
* `XmlAttribute`) to ensure that when it is destroyed, it doesn't try to
|
131
|
+
* access the freed memory.
|
132
|
+
*
|
133
|
+
* Because namespaces (`xmlNs`) attached to nodes are also freed and may be
|
134
|
+
* wrapped, it is necessary to update any wrappers (`XmlNamespace`) which have
|
135
|
+
* been created for attached namespaces.
|
136
|
+
*/
|
137
|
+
void xmlDeregisterNodeCallback(xmlNode *xml_obj) {
|
138
|
+
nodeCount--;
|
139
|
+
deregisterNodeNamespaces(xml_obj);
|
140
|
+
if (xml_obj->_private != NULL) {
|
141
|
+
static_cast<XmlNode *>(xml_obj->_private)->xml_obj = NULL;
|
142
|
+
xml_obj->_private = NULL;
|
143
|
+
}
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
|
147
|
+
// this is called for any created nodes
|
148
|
+
void xmlRegisterNodeCallback(xmlNode *xml_obj) { nodeCount++; }
|
149
|
+
|
150
|
+
LibXMLJS::LibXMLJS() {
|
151
|
+
// set the callback for when a node is created
|
152
|
+
xmlRegisterNodeDefault(xmlRegisterNodeCallback);
|
153
|
+
|
154
|
+
// set the callback for when a node is about to be freed
|
155
|
+
xmlDeregisterNodeDefault(xmlDeregisterNodeCallback);
|
156
|
+
|
157
|
+
// populated debugMemSize (see xmlmemory.h/c) and makes the call to
|
158
|
+
// xmlMemUsed work, this must happen first!
|
159
|
+
xmlMemSetup(xmlMemFreeWrap, xmlMemMallocWrap, xmlMemReallocWrap,
|
160
|
+
xmlMemoryStrdupWrap);
|
161
|
+
|
162
|
+
// initialize libxml
|
163
|
+
LIBXML_TEST_VERSION;
|
164
|
+
|
165
|
+
// initial memory usage
|
166
|
+
xml_memory_used = xmlMemUsed();
|
167
|
+
}
|
168
|
+
|
169
|
+
LibXMLJS::~LibXMLJS() { xmlCleanupParser(); }
|
170
|
+
|
171
|
+
Local<Object> listFeatures() {
|
172
|
+
Nan::EscapableHandleScope scope;
|
173
|
+
Local<Object> target = Nan::New<Object>();
|
174
|
+
#define FEAT(x) \
|
175
|
+
Nan::Set(target, Nan::New<String>(#x).ToLocalChecked(), \
|
176
|
+
Nan::New<Boolean>(xmlHasFeature(XML_WITH_##x)))
|
177
|
+
// See enum xmlFeature in parser.h
|
178
|
+
FEAT(THREAD);
|
179
|
+
FEAT(TREE);
|
180
|
+
FEAT(OUTPUT);
|
181
|
+
FEAT(PUSH);
|
182
|
+
FEAT(READER);
|
183
|
+
FEAT(PATTERN);
|
184
|
+
FEAT(WRITER);
|
185
|
+
FEAT(SAX1);
|
186
|
+
FEAT(FTP);
|
187
|
+
FEAT(HTTP);
|
188
|
+
FEAT(VALID);
|
189
|
+
FEAT(HTML);
|
190
|
+
FEAT(LEGACY);
|
191
|
+
FEAT(C14N);
|
192
|
+
FEAT(CATALOG);
|
193
|
+
FEAT(XPATH);
|
194
|
+
FEAT(XPTR);
|
195
|
+
FEAT(XINCLUDE);
|
196
|
+
FEAT(ICONV);
|
197
|
+
FEAT(ISO8859X);
|
198
|
+
FEAT(UNICODE);
|
199
|
+
FEAT(REGEXP);
|
200
|
+
FEAT(AUTOMATA);
|
201
|
+
FEAT(EXPR);
|
202
|
+
FEAT(SCHEMAS);
|
203
|
+
FEAT(SCHEMATRON);
|
204
|
+
FEAT(MODULES);
|
205
|
+
FEAT(DEBUG);
|
206
|
+
FEAT(DEBUG_MEM);
|
207
|
+
FEAT(DEBUG_RUN);
|
208
|
+
FEAT(ZLIB);
|
209
|
+
FEAT(ICU);
|
210
|
+
FEAT(LZMA);
|
211
|
+
return scope.Escape(target);
|
212
|
+
}
|
213
|
+
|
214
|
+
NAN_METHOD(XmlMemUsed) {
|
215
|
+
Nan::HandleScope scope;
|
216
|
+
return info.GetReturnValue().Set(Nan::New<Int32>(xmlMemUsed()));
|
217
|
+
}
|
218
|
+
|
219
|
+
NAN_METHOD(XmlNodeCount) {
|
220
|
+
Nan::HandleScope scope;
|
221
|
+
return info.GetReturnValue().Set(Nan::New<Int32>(nodeCount));
|
222
|
+
}
|
223
|
+
|
224
|
+
NAN_MODULE_INIT(init) {
|
225
|
+
Nan::HandleScope scope;
|
226
|
+
|
227
|
+
XmlDocument::Initialize(target);
|
228
|
+
XmlSaxParser::Initialize(target);
|
229
|
+
XmlTextWriter::Initialize(target);
|
230
|
+
|
231
|
+
Nan::Set(target, Nan::New<String>("libxml_version").ToLocalChecked(),
|
232
|
+
Nan::New<String>(LIBXML_DOTTED_VERSION).ToLocalChecked());
|
233
|
+
|
234
|
+
Nan::Set(target, Nan::New<String>("libxml_parser_version").ToLocalChecked(),
|
235
|
+
Nan::New<String>(xmlParserVersion).ToLocalChecked());
|
236
|
+
|
237
|
+
Nan::Set(target, Nan::New<String>("libxml_debug_enabled").ToLocalChecked(),
|
238
|
+
Nan::New<Boolean>(debugging));
|
239
|
+
|
240
|
+
Nan::Set(target, Nan::New<String>("features").ToLocalChecked(),
|
241
|
+
listFeatures());
|
242
|
+
|
243
|
+
Nan::Set(target, Nan::New<String>("libxml").ToLocalChecked(), target);
|
244
|
+
|
245
|
+
Nan::SetMethod(target, "xmlMemUsed", XmlMemUsed);
|
246
|
+
|
247
|
+
Nan::SetMethod(target, "xmlNodeCount", XmlNodeCount);
|
248
|
+
}
|
249
|
+
|
250
|
+
NODE_MODULE(xmljs, init)
|
251
|
+
|
252
|
+
} // namespace libxmljs
|
package/src/libxmljs.h
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
#ifndef SRC_LIBXMLJS_H_
|
3
|
+
#define SRC_LIBXMLJS_H_
|
4
|
+
|
5
|
+
#include "nan.h"
|
6
|
+
#include <node.h>
|
7
|
+
#include <v8.h>
|
8
|
+
|
9
|
+
#define LIBXMLJS_ARGUMENT_TYPE_CHECK(arg, type, err) \
|
10
|
+
if (!arg->type()) { \
|
11
|
+
return Nan::ThrowTypeError(err); \
|
12
|
+
}
|
13
|
+
|
14
|
+
#define NAN_CONSTRUCTOR_CHECK(name) \
|
15
|
+
if (!info.IsConstructCall()) { \
|
16
|
+
Nan::ThrowTypeError("Class constructor " #name \
|
17
|
+
" cannot be invoked without 'new'"); \
|
18
|
+
return; \
|
19
|
+
}
|
20
|
+
|
21
|
+
#define DOCUMENT_ARG_CHECK \
|
22
|
+
if (info.Length() == 0 || info[0]->IsNullOrUndefined()) { \
|
23
|
+
Nan::ThrowError("document argument required"); \
|
24
|
+
return; \
|
25
|
+
} \
|
26
|
+
Local<Object> doc = Nan::To<Object>(info[0]).ToLocalChecked(); \
|
27
|
+
if (!XmlDocument::constructor_template.Get(Isolate::GetCurrent()) \
|
28
|
+
->HasInstance(doc)) { \
|
29
|
+
Nan::ThrowError("document argument must be an instance of Document"); \
|
30
|
+
return; \
|
31
|
+
}
|
32
|
+
|
33
|
+
namespace libxmljs {
|
34
|
+
|
35
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
36
|
+
static const bool debugging = true;
|
37
|
+
#else
|
38
|
+
static const bool debugging = false;
|
39
|
+
#endif
|
40
|
+
|
41
|
+
// Ensure that libxml is properly initialised and destructed at shutdown
|
42
|
+
class LibXMLJS {
|
43
|
+
public:
|
44
|
+
LibXMLJS();
|
45
|
+
virtual ~LibXMLJS();
|
46
|
+
|
47
|
+
private:
|
48
|
+
static LibXMLJS instance;
|
49
|
+
};
|
50
|
+
|
51
|
+
} // namespace libxmljs
|
52
|
+
|
53
|
+
#endif // SRC_LIBXMLJS_H_
|
@@ -0,0 +1,173 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
#include "xml_attribute.h"
|
3
|
+
|
4
|
+
using namespace v8;
|
5
|
+
namespace libxmljs {
|
6
|
+
|
7
|
+
Nan::Persistent<FunctionTemplate> XmlAttribute::constructor_template;
|
8
|
+
|
9
|
+
NAN_METHOD(XmlAttribute::New) {
|
10
|
+
Nan::HandleScope scope;
|
11
|
+
|
12
|
+
return info.GetReturnValue().Set(info.Holder());
|
13
|
+
}
|
14
|
+
|
15
|
+
Local<Object> XmlAttribute::New(xmlNode *xml_obj, const xmlChar *name,
|
16
|
+
const xmlChar *value) {
|
17
|
+
Nan::EscapableHandleScope scope;
|
18
|
+
xmlAttr *attr = xmlSetProp(xml_obj, name, value);
|
19
|
+
assert(attr);
|
20
|
+
|
21
|
+
if (attr->_private) {
|
22
|
+
return scope.Escape(static_cast<XmlNode *>(xml_obj->_private)->handle());
|
23
|
+
}
|
24
|
+
|
25
|
+
XmlAttribute *attribute = new XmlAttribute(attr);
|
26
|
+
Local<Object> obj =
|
27
|
+
Nan::NewInstance(
|
28
|
+
Nan::GetFunction(Nan::New(constructor_template)).ToLocalChecked())
|
29
|
+
.ToLocalChecked();
|
30
|
+
attribute->Wrap(obj);
|
31
|
+
return scope.Escape(obj);
|
32
|
+
}
|
33
|
+
|
34
|
+
Local<Object> XmlAttribute::New(xmlAttr *attr) {
|
35
|
+
Nan::EscapableHandleScope scope;
|
36
|
+
assert(attr->type == XML_ATTRIBUTE_NODE);
|
37
|
+
|
38
|
+
if (attr->_private) {
|
39
|
+
return scope.Escape(static_cast<XmlNode *>(attr->_private)->handle());
|
40
|
+
}
|
41
|
+
|
42
|
+
XmlAttribute *attribute = new XmlAttribute(attr);
|
43
|
+
Local<Object> obj =
|
44
|
+
Nan::NewInstance(
|
45
|
+
Nan::GetFunction(Nan::New(constructor_template)).ToLocalChecked())
|
46
|
+
.ToLocalChecked();
|
47
|
+
attribute->Wrap(obj);
|
48
|
+
return scope.Escape(obj);
|
49
|
+
}
|
50
|
+
|
51
|
+
NAN_METHOD(XmlAttribute::Name) {
|
52
|
+
Nan::HandleScope scope;
|
53
|
+
XmlAttribute *attr = Nan::ObjectWrap::Unwrap<XmlAttribute>(info.Holder());
|
54
|
+
assert(attr);
|
55
|
+
|
56
|
+
return info.GetReturnValue().Set(attr->get_name());
|
57
|
+
}
|
58
|
+
|
59
|
+
NAN_METHOD(XmlAttribute::Value) {
|
60
|
+
Nan::HandleScope scope;
|
61
|
+
XmlAttribute *attr = Nan::ObjectWrap::Unwrap<XmlAttribute>(info.Holder());
|
62
|
+
assert(attr);
|
63
|
+
|
64
|
+
// attr.value('new value');
|
65
|
+
if (info.Length() > 0) {
|
66
|
+
attr->set_value(*Nan::Utf8String(info[0]));
|
67
|
+
return info.GetReturnValue().Set(info.Holder());
|
68
|
+
}
|
69
|
+
|
70
|
+
// attr.value();
|
71
|
+
return info.GetReturnValue().Set(attr->get_value());
|
72
|
+
}
|
73
|
+
|
74
|
+
NAN_METHOD(XmlAttribute::Node) {
|
75
|
+
Nan::HandleScope scope;
|
76
|
+
XmlAttribute *attr = Nan::ObjectWrap::Unwrap<XmlAttribute>(info.Holder());
|
77
|
+
assert(attr);
|
78
|
+
|
79
|
+
return info.GetReturnValue().Set(attr->get_element());
|
80
|
+
}
|
81
|
+
|
82
|
+
NAN_METHOD(XmlAttribute::Namespace) {
|
83
|
+
Nan::HandleScope scope;
|
84
|
+
XmlAttribute *attr = Nan::ObjectWrap::Unwrap<XmlAttribute>(info.Holder());
|
85
|
+
assert(attr);
|
86
|
+
|
87
|
+
return info.GetReturnValue().Set(attr->get_namespace());
|
88
|
+
}
|
89
|
+
|
90
|
+
Local<Value> XmlAttribute::get_name() {
|
91
|
+
Nan::EscapableHandleScope scope;
|
92
|
+
if (xml_obj->name)
|
93
|
+
return scope.Escape(
|
94
|
+
Nan::New<String>((const char *)xml_obj->name, xmlStrlen(xml_obj->name))
|
95
|
+
.ToLocalChecked());
|
96
|
+
|
97
|
+
return scope.Escape(Nan::Null());
|
98
|
+
}
|
99
|
+
|
100
|
+
Local<Value> XmlAttribute::get_value() {
|
101
|
+
Nan::EscapableHandleScope scope;
|
102
|
+
xmlChar *value = xmlNodeGetContent(xml_obj);
|
103
|
+
if (value != NULL) {
|
104
|
+
Local<String> ret_value =
|
105
|
+
Nan::New<String>((const char *)value, xmlStrlen(value))
|
106
|
+
.ToLocalChecked();
|
107
|
+
xmlFree(value);
|
108
|
+
return scope.Escape(ret_value);
|
109
|
+
}
|
110
|
+
|
111
|
+
return scope.Escape(Nan::Null());
|
112
|
+
}
|
113
|
+
|
114
|
+
void XmlAttribute::set_value(const char *value) {
|
115
|
+
if (xml_obj->children)
|
116
|
+
xmlFreeNodeList(xml_obj->children);
|
117
|
+
|
118
|
+
xml_obj->children = xml_obj->last = NULL;
|
119
|
+
|
120
|
+
if (value) {
|
121
|
+
xmlChar *buffer;
|
122
|
+
xmlNode *tmp;
|
123
|
+
|
124
|
+
// Encode our content
|
125
|
+
buffer = xmlEncodeEntitiesReentrant(xml_obj->doc, (const xmlChar *)value);
|
126
|
+
|
127
|
+
xml_obj->children = xmlStringGetNodeList(xml_obj->doc, buffer);
|
128
|
+
xml_obj->last = NULL;
|
129
|
+
tmp = xml_obj->children;
|
130
|
+
|
131
|
+
// Loop through the children
|
132
|
+
for (tmp = xml_obj->children; tmp; tmp = tmp->next) {
|
133
|
+
tmp->parent = reinterpret_cast<xmlNode *>(xml_obj);
|
134
|
+
tmp->doc = xml_obj->doc;
|
135
|
+
if (tmp->next == NULL)
|
136
|
+
xml_obj->last = tmp;
|
137
|
+
}
|
138
|
+
|
139
|
+
// Free up memory
|
140
|
+
xmlFree(buffer);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
Local<Value> XmlAttribute::get_element() {
|
145
|
+
Nan::EscapableHandleScope scope;
|
146
|
+
return scope.Escape(XmlElement::New(xml_obj->parent));
|
147
|
+
}
|
148
|
+
|
149
|
+
Local<Value> XmlAttribute::get_namespace() {
|
150
|
+
Nan::EscapableHandleScope scope;
|
151
|
+
if (!xml_obj->ns) {
|
152
|
+
return scope.Escape(Nan::Null());
|
153
|
+
}
|
154
|
+
return scope.Escape(XmlNamespace::New(xml_obj->ns));
|
155
|
+
}
|
156
|
+
|
157
|
+
void XmlAttribute::Initialize(Local<Object> target) {
|
158
|
+
Nan::HandleScope scope;
|
159
|
+
Local<FunctionTemplate> tmpl = Nan::New<FunctionTemplate>(XmlAttribute::New);
|
160
|
+
constructor_template.Reset(tmpl);
|
161
|
+
tmpl->Inherit(Nan::New(XmlNode::constructor_template));
|
162
|
+
tmpl->InstanceTemplate()->SetInternalFieldCount(1);
|
163
|
+
|
164
|
+
Nan::SetPrototypeMethod(tmpl, "name", XmlAttribute::Name);
|
165
|
+
Nan::SetPrototypeMethod(tmpl, "value", XmlAttribute::Value);
|
166
|
+
Nan::SetPrototypeMethod(tmpl, "node", XmlAttribute::Node);
|
167
|
+
Nan::SetPrototypeMethod(tmpl, "namespace", XmlAttribute::Namespace);
|
168
|
+
|
169
|
+
Nan::Set(target, Nan::New<String>("Attribute").ToLocalChecked(),
|
170
|
+
Nan::GetFunction(tmpl).ToLocalChecked());
|
171
|
+
}
|
172
|
+
|
173
|
+
} // namespace libxmljs
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// Copyright 2009, Squish Tech, LLC.
|
2
|
+
#ifndef SRC_XML_ATTRIBUTE_H_
|
3
|
+
#define SRC_XML_ATTRIBUTE_H_
|
4
|
+
|
5
|
+
#include "libxmljs.h"
|
6
|
+
#include "xml_element.h"
|
7
|
+
#include "xml_namespace.h"
|
8
|
+
|
9
|
+
namespace libxmljs {
|
10
|
+
|
11
|
+
class XmlAttribute : public XmlNode {
|
12
|
+
public:
|
13
|
+
explicit XmlAttribute(xmlAttr *node)
|
14
|
+
: XmlNode(reinterpret_cast<xmlNode *>(node)) {}
|
15
|
+
|
16
|
+
static void Initialize(v8::Local<v8::Object> target);
|
17
|
+
static Nan::Persistent<v8::FunctionTemplate> constructor_template;
|
18
|
+
|
19
|
+
static v8::Local<v8::Object> New(xmlNode *xml_obj, const xmlChar *name,
|
20
|
+
const xmlChar *value);
|
21
|
+
|
22
|
+
static v8::Local<v8::Object> New(xmlAttr *attr);
|
23
|
+
|
24
|
+
protected:
|
25
|
+
static NAN_METHOD(New);
|
26
|
+
static NAN_METHOD(Name);
|
27
|
+
static NAN_METHOD(Value);
|
28
|
+
static NAN_METHOD(Node);
|
29
|
+
static NAN_METHOD(Namespace);
|
30
|
+
|
31
|
+
v8::Local<v8::Value> get_name();
|
32
|
+
v8::Local<v8::Value> get_value();
|
33
|
+
void set_value(const char *value);
|
34
|
+
v8::Local<v8::Value> get_element();
|
35
|
+
v8::Local<v8::Value> get_namespace();
|
36
|
+
};
|
37
|
+
|
38
|
+
} // namespace libxmljs
|
39
|
+
|
40
|
+
#endif // SRC_XML_ATTRIBUTE_H_
|