diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/xml/init | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/xml/init')
-rw-r--r-- | library/cpp/xml/init/init.cpp | 39 | ||||
-rw-r--r-- | library/cpp/xml/init/init.h | 5 | ||||
-rw-r--r-- | library/cpp/xml/init/ptr.cpp | 1 | ||||
-rw-r--r-- | library/cpp/xml/init/ptr.h | 69 | ||||
-rw-r--r-- | library/cpp/xml/init/ya.make | 15 |
5 files changed, 129 insertions, 0 deletions
diff --git a/library/cpp/xml/init/init.cpp b/library/cpp/xml/init/init.cpp new file mode 100644 index 0000000000..aa96c2dd31 --- /dev/null +++ b/library/cpp/xml/init/init.cpp @@ -0,0 +1,39 @@ +#include "init.h" + +#include <libxml/xmlIO.h> +#include <libxml/parser.h> +#include <libxml/parserInternals.h> +#include <libxml/tree.h> + +#include <library/cpp/charset/recyr.hh> +#include <util/generic/singleton.h> + +namespace { + int CharEncodingInput(unsigned char* out, int* outlen, const unsigned char* in, int* inlen) { + size_t read = 0, written = 0; + RECODE_RESULT r = Recode(CODES_WIN, CODES_UTF8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, read, written); + if (r == RECODE_EOOUTPUT) + return -1; + if (r != RECODE_OK) + return -2; + *inlen = (int)read; + *outlen = (int)written; + return (int)written; + } + + class TLibXml2 { + public: + inline TLibXml2() { + xmlInitParser(); + xmlNewCharEncodingHandler("windows-1251", CharEncodingInput, nullptr); + } + + inline ~TLibXml2() { + xmlCleanupParser(); + } + }; +} + +void NXml::InitEngine() { + Singleton<TLibXml2>(); +} diff --git a/library/cpp/xml/init/init.h b/library/cpp/xml/init/init.h new file mode 100644 index 0000000000..2cdc46c655 --- /dev/null +++ b/library/cpp/xml/init/init.h @@ -0,0 +1,5 @@ +#pragma once + +namespace NXml { + void InitEngine(); +} diff --git a/library/cpp/xml/init/ptr.cpp b/library/cpp/xml/init/ptr.cpp new file mode 100644 index 0000000000..e11a6460c3 --- /dev/null +++ b/library/cpp/xml/init/ptr.cpp @@ -0,0 +1 @@ +#include "ptr.h" diff --git a/library/cpp/xml/init/ptr.h b/library/cpp/xml/init/ptr.h new file mode 100644 index 0000000000..7387c7cc40 --- /dev/null +++ b/library/cpp/xml/init/ptr.h @@ -0,0 +1,69 @@ +#pragma once + +#include <util/generic/ptr.h> +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> +#include <libxml/xmlsave.h> +#include <libxml/uri.h> +#include <libxml/xmlschemas.h> + +template <class T, void (*DestroyFun)(T*)> +struct TFunctionDestroy { + static inline void Destroy(T* t) noexcept { + if (t) + DestroyFun(t); + } +}; + +namespace NXml { +#define DEF_HOLDER(type, free) typedef THolder<type, TFunctionDestroy<type, free>> T##type##Holder +#define DEF_PTR(type, free) typedef TAutoPtr<type, TFunctionDestroy<type, free>> T##type##Ptr + + // define xmlDocPtr -> TxmlDocHolder TxmlDocPtr + DEF_HOLDER(xmlDoc, xmlFreeDoc); + DEF_PTR(xmlDoc, xmlFreeDoc); + + // xmlXPathContextPtr xpathCtx; + DEF_HOLDER(xmlXPathContext, xmlXPathFreeContext); + DEF_PTR(xmlXPathContext, xmlXPathFreeContext); + + // xmlXPathObjectPtr xpathObj; + DEF_HOLDER(xmlXPathObject, xmlXPathFreeObject); + DEF_PTR(xmlXPathObject, xmlXPathFreeObject); + + // xmlNodeSetPtr nodes + DEF_HOLDER(xmlNodeSet, xmlXPathFreeNodeSet); + DEF_PTR(xmlNodeSet, xmlXPathFreeNodeSet); + + // xmlSchemaParserCtxtPtr ctxt; + DEF_HOLDER(xmlSchemaParserCtxt, xmlSchemaFreeParserCtxt); + DEF_PTR(xmlSchemaParserCtxt, xmlSchemaFreeParserCtxt); + + // xmlSchemaPtr schema; + DEF_HOLDER(xmlSchema, xmlSchemaFree); + DEF_PTR(xmlSchema, xmlSchemaFree); + + // xmlSchemaValidCtxt ctxt; + DEF_HOLDER(xmlSchemaValidCtxt, xmlSchemaFreeValidCtxt); + DEF_PTR(xmlSchemaValidCtxt, xmlSchemaFreeValidCtxt); + + // xmlSaveCtxtPtr + inline void xmlFreeSave(xmlSaveCtxt* c) { + // returns int + xmlSaveClose(c); + } + DEF_HOLDER(xmlSaveCtxt, xmlFreeSave); + DEF_PTR(xmlSaveCtxt, xmlFreeSave); + + DEF_PTR(xmlURI, xmlFreeURI); + DEF_PTR(xmlNode, xmlFreeNode); + DEF_PTR(xmlParserCtxt, xmlFreeParserCtxt); + DEF_PTR(xmlParserInputBuffer, xmlFreeParserInputBuffer); + DEF_PTR(xmlDtd, xmlFreeDtd); + DEF_PTR(xmlValidCtxt, xmlFreeValidCtxt); + +#undef DEF_HOLDER +#undef DEF_PTR +} diff --git a/library/cpp/xml/init/ya.make b/library/cpp/xml/init/ya.make new file mode 100644 index 0000000000..5f3883c2c9 --- /dev/null +++ b/library/cpp/xml/init/ya.make @@ -0,0 +1,15 @@ +LIBRARY() + +OWNER(pg) + +PEERDIR( + contrib/libs/libxml + library/cpp/charset +) + +SRCS( + ptr.cpp + init.cpp +) + +END() |