-
Notifications
You must be signed in to change notification settings - Fork 15
/
libxml.bak.cpp
626 lines (592 loc) · 19.8 KB
/
libxml.bak.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/**
* This is the main Class script, We use NAN as a wrapper to libxml2 c+++ functions
*/
#include "libxml.h"
#include <algorithm>
#include <iostream>
#include <memory>
#include <string>
#include <assert.h>
void Libxml::errorsHandler(void *userData, xmlErrorPtr error)
{
return;
};
Libxml::Libxml()
{
//Maybe deport debug activation here ? in the future ..
}
//Destructor
Libxml::~Libxml()
{
// Free memory dtd & xml file ..
// If dtd is already null, just do nothing
if (Libxml::docPtr != NULL)
{
// Force clear memory DOC XML loaded
xmlFreeDoc(Libxml::docPtr);
Libxml::docPtr = NULL;
}
}
Napi::FunctionReference &Libxml::constructor()
{
static Napi::FunctionReference myConstructor;
return myConstructor;
}
Napi::Object Libxml::Init(Napi::Env env, Napi::Object exports)
{
Napi::Function tpl = Napi::Function::New(env, Libxml::New);
// tpl->SetClassName(Napi::String::New(env, "Libxml"));
Napi::Function func = DefineClass(
env, "Libxml", {InstanceMethod("loadXml", &loadXml)});
InstanceMethod("loadXml", &loadXml),
InstanceMethod("loadXmlFromString", &loadXmlFromString),
InstanceMethod("loadDtds", &loadDtds),
// InstanceMethod("loadDtdsFromString", &loadDtdsFromString),
InstanceMethod("loadSchemas", &loadSchemas),
InstanceMethod("validateAgainstDtds", &validateAgainstDtds),
InstanceMethod("validateAgainstSchemas", &validateAgainstSchemas),
InstanceMethod("getDtd", &getDtd),
InstanceMethod("xpathSelect", &xpathSelect),
InstanceMethod("freeXml", &freeXml),
InstanceMethod("freeDtds", &freeDtds),
InstanceMethod("freeSchemas", &freeSchemas),
InstanceMethod("clearAll", &clearAll),
Local<ObjectTemplate> instTpl = tpl->InstanceTemplate();
constructor().Reset(Napi::GetFunction(tpl));
(target).Set(Napi::String::New(env, "Libxml"), tpl->GetFunction());
}
Napi::Value Libxml::New(const Napi::CallbackInfo &info)
{
if (info.IsConstructCall())
{
// this functions is important if we use multithreading !
xmlInitParser();
Libxml *obj = new Libxml();
obj->Wrap(info.This());
return info.This();
}
else
{
const int argc = 1;
Napi::Value argv[argc] = {info[0]};
Napi::Function cons = Napi::New(env, constructor());
return Napi::NewInstance(cons, argc, argv);
}
}
Napi::Value Libxml::loadXml(const Napi::CallbackInfo &info)
{
if (info.Length() < 1)
{
Napi::TypeError::New(env, "loadXml requires at least 1 argument").ThrowAsJavaScriptException();
return env.Null();
}
Napi::Array errors = Napi::Array::New(env);
xmlResetLastError();
xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
XmlSyntaxError::PushToArray);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
Napi::String val(env, info[0].ToString());
const char *filename(*val);
// Those options shoudl be send by the user, it enable/disbale errors, warnings ..
int options;
options = (XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
if (libxml->docPtr != NULL)
{
xmlFreeDoc(libxml->docPtr);
libxml->docPtr = nullptr;
}
libxml->docPtr = xmlReadFile(filename, NULL, options);
xmlSetStructuredErrorFunc(NULL, NULL);
if (libxml->docPtr == NULL)
{
// We set property to libxml element only if notWellformed
info.Holder().Set(Napi::String::New(env, "wellformedErrors"), errors);
return env.False();
}
else
{
return env.True();
}
}
Napi::Value Libxml::loadXmlFromString(const Napi::CallbackInfo &info)
{
if (info.Length() < 1)
{
Napi::TypeError::New(env, "loadXmlFromString requires at least 1 argument").ThrowAsJavaScriptException();
return env.Null();
}
Napi::Array errors = Napi::Array::New(env);
xmlResetLastError();
xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
XmlSyntaxError::PushToArray);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
Napi::String str(env, info[0].ToString());
string txt(*str);
// Those options shoudl be send by the user, it enable/disbale errors, warnings ..
int options;
options = (XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
if (libxml->docPtr != NULL)
{
xmlFreeDoc(libxml->docPtr);
libxml->docPtr = nullptr;
}
libxml->docPtr = xmlReadMemory(txt.c_str(), txt.Length(), NULL, NULL, options);
xmlSetStructuredErrorFunc(NULL, NULL);
if (libxml->docPtr == NULL)
{
// We set property to libxml element only if notWellformed
info.Holder().Set(Napi::String::New(env, "wellformedErrors"), errors);
return env.False();
}
else
{
return env.True();
}
}
Napi::Value Libxml::getDtd(const Napi::CallbackInfo &info)
{
Napi::HandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
assert(libxml);
xmlDtdPtr dtd = xmlGetIntSubset(libxml->docPtr);
if (!dtd)
{
return return env.Null();
}
const char *name = (const char *)dtd->name;
const char *extId = (const char *)dtd->ExternalID;
const char *sysId = (const char *)dtd->SystemID;
Napi::Object dtdObj = Napi::Object::New(env);
Napi::Value nameValue = (Napi::Value)env.Null();
Napi::Value extValue = (Napi::Value)env.Null();
Napi::Value sysValue = (Napi::Value)env.Null();
if (name != NULL)
{
nameValue = (Napi::Value)Napi::String::New(env, name, strlen(name));
}
if (extId != NULL)
{
extValue = (Napi::Value)Napi::String::New(env, extId, strlen(extId));
}
if (sysId != NULL)
{
sysValue = (Napi::Value)Napi::String::New(env, sysId, strlen(sysId));
}
// to get publicId or systemId it's the same ... http://xmlsoft.org/html/libxml-tree.html#xmlDtd
(dtdObj).Set(Napi::String::New(env, "name"), nameValue);
(dtdObj).Set(Napi::String::New(env, "externalId"), extValue);
(dtdObj).Set(Napi::String::New(env, "systemId"), sysValue);
return return dtdObj;
}
Napi::Value Libxml::loadDtds(const Napi::CallbackInfo &info)
{
if (info.Length() < 1)
{
Napi::TypeError::New(env, "loadDtds requires at least 1 argument, an array of DTDs").ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsArray())
{
Napi::TypeError::New(env, "loadDtds requires an array").ThrowAsJavaScriptException();
return env.Null();
}
Napi::EscapableHandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
Napi::Array dtdsPathsLocal = info[0].As<Napi::Array>();
Napi::Array errors = Napi::Array::New(env);
// disbale errors erreurs etc
//Napi::Array errorsDTD = Napi::Array::New(env);
xmlResetLastError();
xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
XmlSyntaxError::PushToArray);
for (unsigned int i = 0; i < dtdsPathsLocal->Length(); i++)
{
if ((dtdsPathsLocal).Has(i) && (dtdsPathsLocal).Get(i).IsString())
{
Napi::String value = (dtdsPathsLocal).Get(i)->ToString();
Napi::String pathV8(env, value->ToString());
string pathStr(*pathV8);
const char *path(*pathV8);
xmlChar *pathDTDCasted = xmlCharStrdup(path);
xmlDtdPtr dtd = xmlParseDTD(NULL, pathDTDCasted);
if (dtd == NULL)
{
//DTD is bad, we set error and not assign it + next
errors.Set(i, Napi::String::New(env, pathStr.c_str()));
continue;
}
libxml->dtdsPaths.push_back(dtd);
}
}
xmlSetStructuredErrorFunc(NULL, NULL);
// We set dtdsLoadedErrors property for js side
if (errors->Length())
{
info.Holder().Set(Napi::String::New(env, "dtdsLoadedErrors"), errors);
}
}
// Napi::Value Libxml::loadDtdsFromString(const Napi::CallbackInfo& info){
// if (info.Length() < 1){
// Napi::TypeError::New(env, "loadDtds requires at least 1 argument, an array of DTDs").ThrowAsJavaScriptException();
return env.Null();
// }
// if(!info[0].IsArray()){
// Napi::TypeError::New(env, "loadDtds requires an array").ThrowAsJavaScriptException();
return env.Null();
// }
// Napi::EscapableHandleScope scope(env);
// Libxml* libxml = info.Holder().Unwrap<Libxml>();
// Napi::Array dtdsStrLocal = info[0].As<Napi::Array>();
// Napi::Array errors = Napi::Array::New(env);
// int options;
// options = (XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
// // disbale errors erreurs etc
// //Napi::Array errorsDTD = Napi::Array::New(env);
// xmlResetLastError();
// xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
// XmlSyntaxError::PushToArray);
// for (unsigned int i = 0; i < dtdsStrLocal->Length(); i++){
// if ((dtdsStrLocal).Has(i) && (dtdsStrLocal).Get(i).IsString()) {
// Napi::String value = (dtdsStrLocal).Get(i)->ToString();
// Napi::String strV8(env, value->ToString());
// string pathStr (*strV8);
// xmlDocPtr dtdDoc = xmlReadMemory(pathStr.c_str(),pathStr.Length(),NULL,NULL,options);;
// if (dtdDoc == NULL) {
// //DTD is bad, we set error and not assign it + next
// errors.Set(i, Napi::String::New(env, pathStr.c_str()));
// continue;
// }
// // Parse DTD from memory
// xmlParserInputBufferPtr dtdBuf = xmlParserInputBufferCreateMem(pathStr.c_str(), pathStr.size(),
// XML_CHAR_ENCODING_UTF8);
// if (!dtdBuf) {
// errors.Set(i, Napi::String::New(env, pathStr.c_str()));
// continue;
// }
// xmlDtdPtr pDtd = xmlIOParseDTD(NULL, dtdBuf, XML_CHAR_ENCODING_UTF8);
// if (pDtd == NULL) {
// xmlFreeDtd(pDtd);
// errors.Set(i, Napi::String::New(env, pathStr.c_str()));
// continue;
// }
// libxml->dtdsPaths.push_back(pDtd);
// }
// }
// xmlSetStructuredErrorFunc(NULL, NULL);
// // We set dtdsLoadedErrors property for js side
// if(errors->Length()){
// info.Holder().Set(Napi::String::New(env, "dtdsLoadedErrors"), errors);
// }
// }
Napi::Value Libxml::loadSchemas(const Napi::CallbackInfo &info)
{
if (info.Length() < 1)
{
Napi::TypeError::New(env, "loadSchemas requires at least 1 argument, an array of Schemas").ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsArray())
{
Napi::TypeError::New(env, "loadSchemas requires an array").ThrowAsJavaScriptException();
return env.Null();
}
Napi::EscapableHandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
Napi::Array schemasPathsLocal = info[0].As<Napi::Array>();
Napi::Array errors = Napi::Array::New(env);
// disbale errors erreurs etc
//Napi::Array errorsDTD = Napi::Array::New(env);
xmlResetLastError();
xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
XmlSyntaxError::PushToArray);
for (unsigned int i = 0; i < schemasPathsLocal->Length(); i++)
{
if ((schemasPathsLocal).Has(i) && (schemasPathsLocal).Get(i).IsString())
{
Napi::String value = (schemasPathsLocal).Get(i)->ToString();
Napi::String pathV8(env, value->ToString());
string pathStr(*pathV8);
const char *path(*pathV8);
xmlSchemaParserCtxtPtr pctxt;
xmlSchemaPtr schema;
// If cannot create Parse schema, just continue
if ((pctxt = xmlSchemaNewParserCtxt(path)) == NULL)
{
errors.Set(i, Napi::String::New(env, pathStr.c_str()));
continue;
}
// Chargement du contenu du XML Schema
schema = xmlSchemaParse(pctxt);
xmlSchemaFreeParserCtxt(pctxt);
if (schema == NULL)
{
errors.Set(i, Napi::String::New(env, pathStr.c_str()));
continue;
}
libxml->schemasPaths.push_back(schema);
}
}
xmlSetStructuredErrorFunc(NULL, NULL);
// We set dtdLoadedErrors property for js side
if (errors->Length())
{
info.Holder().Set(Napi::String::New(env, "schemasLoadedErrors"), errors);
}
}
Napi::Value Libxml::validateAgainstDtds(const Napi::CallbackInfo &info)
{
Libxml *libxml = info.Holder().Unwrap<Libxml>();
if (libxml->dtdsPaths.empty())
{
return env.Null();
return;
}
if (int newMaxNbError = info[0].As<Napi::Number>().Int64Value())
{
XmlSyntaxError::ChangeMaxNumberOfError(newMaxNbError);
}
//Setting contexte of validation
const char *dtdValidationErrorsPath;
bool oneOfTheDtdValidate = false;
string dtdValidateName;
//If length 0, return null; to implement
Napi::Object errorsValidations = Napi::Object::New(env);
for (vector<xmlDtdPtr>::iterator dtd = libxml->dtdsPaths.begin(); dtd != libxml->dtdsPaths.end(); ++dtd)
{
const char *dtdName = (const char *)(*dtd)->SystemID;
//Napi::Array errors = New<v8::Array>(3);
Napi::Array errors = Napi::Array::New(env);
xmlResetLastError();
xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
XmlSyntaxError::PushToArray);
Napi::String SystemIDString = Napi::String::New(env, dtdName);
// Création du contexte de validation
xmlValidCtxtPtr vctxt;
//vctxt = xmlNewValidCtxt();
if ((vctxt = xmlNewValidCtxt()) == NULL)
{
continue;
}
//Instead we could set this to disable output : xmlSetStructuredErrorFunc(vctxt,errorsHandler);
vctxt->userData = (void *)Libxml::errorsHandler;
vctxt->error = (xmlValidityErrorFunc)Libxml::errorsHandler;
vctxt->warning = (xmlValidityWarningFunc)Libxml::errorsHandler;
// Validation
int result = xmlValidateDtd(vctxt, libxml->docPtr, *dtd);
// Libération des erreurs etc
xmlSetStructuredErrorFunc(NULL, NULL);
xmlFreeValidCtxt(vctxt);
if (result != 0)
{
oneOfTheDtdValidate = true;
dtdValidateName = dtdName;
break;
}
errorsValidations.Set(SystemIDString, errors);
dtdValidationErrorsPath = dtdName;
}
if (oneOfTheDtdValidate)
{
if (dtdValidateName.Length())
{
return Napi::String::New(env, dtdValidateName);
}
else
{
return env.True();
}
}
else
{
info.Holder().Set(Napi::String::New(env, "validationDtdErrors"), errorsValidations);
return env.False();
}
}
Napi::Value Libxml::validateAgainstSchemas(const Napi::CallbackInfo &info)
{
Libxml *libxml = info.Holder().Unwrap<Libxml>();
if (libxml->schemasPaths.empty())
{
return env.Null();
return;
}
if (int newMaxNbError = info[0].As<Napi::Number>().Int64Value())
{
XmlSyntaxError::ChangeMaxNumberOfError(newMaxNbError);
}
//Setting contexte of validation
const char *schemaValidationErrorsPath;
bool oneOfTheSchemaValidate = false;
string schemaValidateName;
//If length 0, return null; to implement
Napi::Object errorsValidations = Napi::Object::New(env);
for (vector<xmlSchemaPtr>::iterator xsd = libxml->schemasPaths.begin(); xsd != libxml->schemasPaths.end(); ++xsd)
{
Napi::Array errors = Napi::Array::New(env);
xmlResetLastError();
xmlSetStructuredErrorFunc(reinterpret_cast<void *>(&errors),
XmlSyntaxError::PushToArray);
const char *xsdName = (const char *)(*xsd)->doc->URL;
Napi::String urlSchema = Napi::String::New(env, xsdName);
// Création du contexte de validation
xmlSchemaValidCtxtPtr vctxt;
if ((vctxt = xmlSchemaNewValidCtxt(*xsd)) == NULL)
{
continue;
}
//Instead we could set this to disable output : xmlSetStructuredErrorFunc(vctxt,errorsHandler);
xmlSchemaSetValidErrors(vctxt, (xmlSchemaValidityErrorFunc)Libxml::errorsHandler, (xmlSchemaValidityWarningFunc)Libxml::errorsHandler, (void *)Libxml::errorsHandler);
int result = xmlSchemaValidateDoc(vctxt, libxml->docPtr);
// Libération des erreurs etc
xmlSetStructuredErrorFunc(NULL, NULL);
xmlSchemaFreeValidCtxt(vctxt);
if (result == 0)
{
oneOfTheSchemaValidate = true;
schemaValidateName = xsdName;
break;
}
errorsValidations.Set(urlSchema, errors);
schemaValidationErrorsPath = xsdName;
}
if (oneOfTheSchemaValidate)
{
if (schemaValidateName.Length())
{
return Napi::String::New(env, schemaValidateName);
}
else
{
return env.True();
}
}
else
{
info.Holder().Set(Napi::String::New(env, "validationSchemaErrors"), errorsValidations);
return env.False();
}
}
Napi::Value Libxml::xpathSelect(const Napi::CallbackInfo &info)
{
if (info.Length() < 1)
{
Napi::TypeError::New(env, "xpathSelect requires at least 1 argument").ThrowAsJavaScriptException();
return env.Null();
}
Napi::EscapableHandleScope scope(env);
Napi::Value res;
Libxml *libxml = info.Holder().Unwrap<Libxml>();
Napi::String val(env, info[0].ToString());
const char *xpathToGet(*val);
xmlChar *xpathExpr = xmlCharStrdup(xpathToGet);
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(libxml->docPtr);
if (xpathCtx == NULL)
{
Napi::TypeError::New(env, "Error: unable to create new XPath context").ThrowAsJavaScriptException();
return env.Null();
}
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
if (xpathObj == NULL)
{
xmlXPathFreeContext(xpathCtx);
return env.False();
}
else if (xpathObj)
{
switch (xpathObj->type)
{
case XPATH_BOOLEAN:
res = Napi::Boolean::New(env, xpathObj->boolval);
break;
case XPATH_NUMBER:
res = Napi::Number::New(env, xpathObj->floatval);
break;
case XPATH_STRING:
res = Napi::String::New(env, (const char *)xpathObj->stringval,
xmlStrlen(xpathObj->stringval));
break;
default:
res = env.Null();
break;
}
}
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
return return scope.Escape(res);
}
Napi::Value Libxml::freeXml(const Napi::CallbackInfo &info)
{
Napi::HandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
// Delete Javascript property
bool deleted = Napi::Delete(info.Holder(), Napi::String::New(env, "wellformedErrors")).FromMaybe(false);
// If doc is already null, just do nothing and only available on manual mod
if (libxml->docPtr == NULL)
{
return;
}
// Force clear memory DTD loaded
xmlFreeDoc(libxml->docPtr);
libxml->docPtr = NULL;
};
Napi::Value Libxml::freeDtds(const Napi::CallbackInfo &info)
{
Napi::HandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
// Delete Javascript property
bool deletedLoaded = Napi::Delete(info.Holder(), Napi::String::New(env, "dtdsLoadedErrors")).FromMaybe(false);
bool deleted = Napi::Delete(info.Holder(), Napi::String::New(env, "validationDtdErrors")).FromMaybe(false);
// If dtds is already empty, just stop here
if (libxml->dtdsPaths.empty())
{
return;
}
for (vector<xmlDtdPtr>::iterator dtd = libxml->dtdsPaths.begin(); dtd != libxml->dtdsPaths.end(); ++dtd)
{
if (*dtd != NULL)
{
// Force clear memory DTD loaded
xmlFreeDtd(*dtd);
*dtd = nullptr;
}
}
// clear the vector of dtds
libxml->dtdsPaths.clear();
}
Napi::Value Libxml::freeSchemas(const Napi::CallbackInfo &info)
{
Napi::HandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
// Delete Javascript property
bool deletedLoaded = Napi::Delete(info.Holder(), Napi::String::New(env, "schemasLoadedErrors")).FromMaybe(false);
bool deleted = Napi::Delete(info.Holder(), Napi::String::New(env, "validationSchemasErrors")).FromMaybe(false);
// If dtds is already empty, just stop here
if (libxml->schemasPaths.empty())
{
return;
}
for (vector<xmlSchemaPtr>::iterator xsd = libxml->schemasPaths.begin(); xsd != libxml->schemasPaths.end(); ++xsd)
{
if (*xsd != NULL)
{
// Force clear memory xsd loaded
xmlSchemaFree(*xsd);
*xsd = nullptr;
}
}
// clear the vector of dtds
libxml->schemasPaths.clear();
}
Napi::Value Libxml::clearAll(const Napi::CallbackInfo &info)
{
Napi::HandleScope scope(env);
Libxml *libxml = info.Holder().Unwrap<Libxml>();
// Attention this function clear all the libxml2 memory for all threads!
xmlCleanupParser();
}
void InitLibxml(Napi::Object exports) { Libxml::Init(exports); }
NODE_API_MODULE(libxml, InitLibxml);