http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/7956696e/thirdparty/libxml2/bakefile/libxml2.bkl ---------------------------------------------------------------------- diff --git a/thirdparty/libxml2/bakefile/libxml2.bkl b/thirdparty/libxml2/bakefile/libxml2.bkl new file mode 100644 index 0000000..f314465 --- /dev/null +++ b/thirdparty/libxml2/bakefile/libxml2.bkl @@ -0,0 +1,749 @@ +<?xml version="1.0" ?> + +<!-- Author: Francesco Montorsi <[email protected]> --> +<!-- Date: 30/8/2004 --> +<!-- Last revision: 26/1/2005 --> + + +<!-- LIBXML2 BAKEFILE --> +<!-- --> +<!-- The bakefile used to build the library and the test --> +<!-- programs. The makefiles output is put: --> +<!-- --> +<!-- - in the ..\LIB folder --> +<!-- - in the ..\BIN folder --> +<!-- --> + +<makefile> + + <using module="datafiles"/> + <requires version="0.1.5"/> + + + <!-- This is a bakefile, that is, a generic template used to --> + <!-- generate makefiles ALL supported compilers. --> + <!-- To use this project file you need Bakefile installed. --> + <!-- With the command "bakefile_gen" you can regen all the --> + <!-- makefiles and project files. --> + <!-- See http://bakefile.sourceforge.net for more info. --> + + + <!-- + This file is divided in: + - generic options + - generic variables + - libxml2 options + - libxml2 variables + - about config.h creation + - templates + - libxml2 library target + - libxml2 test program targets + --> + + + + <!-- --> + <!-- GENERIC OPTIONS --> + <!-- --> + + + <!-- This is a standard option that determines --> + <!-- whether the user wants to build this library as --> + <!-- a dll or as a static library. --> + <option name="SHARED"> + <values>0,1</values> + <values-description>,DLL</values-description> + <default-value>0</default-value> + <description>If set to zero a STATIC libxml library will be built</description> + </option> + + <!-- Configuration for building the bakefile with --> + <!-- unicode strings or not (unicode or ansi). --> + <option name="UNICODE"> + <values>0,1</values> + <values-description>,Unicode</values-description> + <default-value>0</default-value> + <description>Compile Unicode build?</description> + </option> + + + <!-- There are several options that deal with build --> + <!-- types. First, there's this one, BUILD. --> + <!-- --> + <!-- BUILD determines whether or not we want to build --> + <!-- in release or debug mode. Note that in practice --> + <!-- this means modifying the optimize tag, which by --> + <!-- default is set to off. In this case debug means --> + <!-- off (no optimizations), and release means speed --> + <!-- (fast with inlining). There is also a size option --> + <!-- that is not addressed in this example bakefile. --> + <option name="BUILD"> + <values>debug,release</values> + <values-description>Debug,Release</values-description> + <default-value>release</default-value> + <description> + Type of compiled binaries + </description> + </option> + + + + <!-- --> + <!-- GENERIC VARIABLES --> + <!-- --> + + <!-- Set the ISDLL variable, so that we can use it --> + <!-- inside an if statement later on (options not --> + <!-- allowed in if statements). --> + <set var="ISDLL" cond="SHARED=='1'">1</set> + <set var="ISDLL" cond="SHARED=='0'">0</set> + + <!-- The unicode define we want. By default bakefile --> + <!-- makes variables an empty string, so if unicode --> + <!-- is not defined $(UNICODE_DEFINE) would expand --> + <!-- to nothing (literally). --> + <set var="UNICODE_DEFINE"> + <if cond="FORMAT!='autoconf' and UNICODE=='1'">_UNICODE</if> + </set> + + <!-- The debug define we need with win32 compilers --> + <!-- (on Linux, the wx-config program is used). --> + <set var="DEBUG_DEFINE"> + <if cond="FORMAT!='autoconf' and BUILD=='debug'"> + __WXDEBUG__ + </if> + </set> + + <!-- Value we will use later on for the debug-info --> + <!-- tag inside our templates. --> + <set var="DEBUGINFO"> + <if cond="BUILD=='debug'">on</if> + <if cond="BUILD=='release'">off</if> + </set> + + <!-- Value we will use later on for the debug-runtime --> + <!-- tag inside our templates. --> + <set var="DEBUGRUNTIME"> + <if cond="BUILD=='debug'">on</if> + <if cond="BUILD=='release'">off</if> + </set> + + <!-- Value for optimize tag. --> + <set var="OPTIMIZEFLAG"> + <if cond="BUILD=='debug'">off</if> + <if cond="BUILD=='release'">speed</if> + </set> + + <!-- Level of warnings. Here we max it out in debug --> + <!-- mode, and turn them off in release mode. --> + <set var="WARNINGS"> + <if cond="BUILD=='debug'">max</if> + <if cond="BUILD=='release'">no</if> + </set> + + <!-- Set MYCPPFLAGS as empty; maybe it will be filled later... --> + <set var="MYCPPFLAGS"></set> + <if cond="FORMAT=='mingw' or FORMAT=='autoconf'"> + + <!-- With GCC, settings warnings to MAX would force --> + <!-- Bakefile to call GCC with "-W -Wall" which generates --> + <!-- a *lot* of warnings about wxWidgets headers... --> + <!-- this is why "-W -Wall" is here replaced by "-Wall". --> + <set var="WARNINGS">default</set> + <set var="MYCPPFLAGS">-Wall</set> + </if> + + + + + + + <!-- --> + <!-- LIBXML2 OPTIONS --> + <!-- --> + <!-- Note #1: not all of them are used by win32 makefiles --> + <!-- --> + <!-- Note #2: since all combinations of non-path options are --> + <!-- translated into different 'configurations' by --> + <!-- Bakefile when using the MSVC6PRJ output, we must --> + <!-- avoid to create a 10 MB libxml2.dsp file forcing --> + <!-- some options to their default values... this --> + <!-- behaviour can be overridden by the --> + <!-- FULL_OPTIONS_SUPPORT --> + <!-- variable defined below... --> + + <set var="FULL_OPTIONS_SUPPORT"> + <if cond="FORMAT=='msvc6prj'">0</if> + <if cond="FORMAT!='msvc6prj'">1</if> + </set> + + <option name="ICONV_DIR" category="path"> + <default-value>c:\iconv</default-value> + <description>The iconv library main folder</description> + </option> + + <option name="WITH_TRIO"> + <values>0,1</values> + <default-value>0</default-value> + <description>Enable TRIO string manipulator</description> + </option> + + <!-- see the note #2 --> + <if cond="FULL_OPTIONS_SUPPORT=='0'"> + <set var="WITH_THREADS">native</set> + </if> + <if cond="FULL_OPTIONS_SUPPORT=='1'"> + <option name="WITH_THREADS"> + <values>no,ctls,native,posix</values> + <default-value>native</default-value> + <description>Enable thread safety</description> + </option> + </if> + + <option name="WITH_FTP"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable FTP client</description> + </option> + + <option name="WITH_HTTP"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable HTTP client</description> + </option> + + <option name="WITH_C14N"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable C14N support</description> + </option> + + <option name="WITH_CATALOG"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable catalog support</description> + </option> + + <option name="WITH_DOCB"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable DocBook support</description> + </option> + + <option name="WITH_XPATH"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable XPath support</description> + </option> + + <option name="WITH_XPTR"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable XPointer support</description> + </option> + + <option name="WITH_XINCLUDE"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable XInclude support</description> + </option> + + <!-- see the note #2 --> + <if cond="FULL_OPTIONS_SUPPORT=='0'"> + <set var="WITH_ICONV">1</set> + </if> + <if cond="FULL_OPTIONS_SUPPORT=='1'"> + <option name="WITH_ICONV"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable iconv support</description> + </option> + </if> + + <option name="WITH_ISO8859X"> + <values>0,1</values> + <default-value>0</default-value> + <description>Enable iso8859x support</description> + </option> + + <!-- see the note #2 --> + <if cond="FULL_OPTIONS_SUPPORT=='0'"> + <set var="WITH_ZLIB">0</set> + </if> + <if cond="FULL_OPTIONS_SUPPORT=='1'"> + <option name="WITH_ZLIB"> + <values>0,1</values> + <default-value>0</default-value> + <description>Enable ZLIB support</description> + </option> + </if> + + <option name="WITH_REGEXPS"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable regular expressions</description> + </option> + + <option name="WITH_TREE"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable tree api</description> + </option> + + <option name="WITH_READER"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable xmlReader api</description> + </option> + + <option name="WITH_WRITER"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable xmlWriter api</description> + </option> + + <option name="WITH_WALKER"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable xmlDocWalker api</description> + </option> + + <option name="WITH_PATTERN"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable xmlPattern api</description> + </option> + + <option name="WITH_PUSH"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable push api</description> + </option> + + <option name="WITH_VALID"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable DTD validation support</description> + </option> + + <option name="WITH_SAX1"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable SAX1 api</description> + </option> + + <option name="WITH_SCHEMAS"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable XML Schema support</description> + </option> + + <option name="WITH_LEGACY"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable deprecated APIs</description> + </option> + + <option name="WITH_OUTPUT"> + <values>0,1</values> + <default-value>1</default-value> + <description>Enable serialization support</description> + </option> + + <option name="WITH_PYTHON"> + <values>0,1</values> + <default-value>0</default-value> + <description>Build Python bindings</description> + </option> + + + + + <!-- --> + <!-- LIBXML2 VARIABLES --> + <!-- --> + + <!-- Put all the objects files generated by --> + <!-- the compilation in a subfolder of BUILD --> + <set var="BUILDDIR">$(FORMAT)</set> + + <!-- This variable is set to 1 when the current output writer supports --> + <!-- the __DEFINE_ARG variable. Otherwise it's set to zero. --> + <set var="HAS_DEFINE_ARG"> + <if cond="FORMAT!='msvc6prj'">1</if> + <if cond="FORMAT=='msvc6prj'">0</if> + </set> + + <!-- The root directory of libxml2 --> + <set var="XMLBASEDIR">..</set> + + <!-- The directory where libxml2' tests will be put --> + <set var="XMLTESTDIR">$(XMLBASEDIR)$(DIRSEP)bin</set> + + <set var="LIBXML_MAJOR_VERSION">2</set> + <set var="LIBXML_MINOR_VERSION">6</set> + <set var="LIBXML_MICRO_VERSION">16</set> + + <!-- some defines related to threads --> + <set var="THREADS_DEF"> + <if cond="HAS_DEFINE_ARG=='1' and WITH_THREADS=='native'"> + $(__DEFINE_ARG)_REENTRANT $(__DEFINE_ARG)HAVE_WIN32_THREADS + </if> + <if cond="HAS_DEFINE_ARG=='1' and WITH_THREADS=='ctls'"> + $(__DEFINE_ARG)_REENTRANT $(__DEFINE_ARG)HAVE_WIN32_THREADS $(__DEFINE_ARG)HAVE_COMPILER_TLS + </if> + <if cond="HAS_DEFINE_ARG=='1' and WITH_THREADS=='posix'"> + $(__DEFINE_ARG)_REENTRANT $(__DEFINE_ARG)HAVE_PTHREAD_H + </if> + </set> + <if cond="FORMAT=='borland'"> + <set var="THREADS_DEF"> + <if cond="WITH_THREADS=='native'">$(THREADS_DEF) $(__DEFINE_ARG)__MT__</if> + <if cond="WITH_THREADS=='ctls'">$(THREADS_DEF) $(__DEFINE_ARG)__MT__</if> + <if cond="WITH_THREADS=='posix'">$(THREADS_DEF) $(__DEFINE_ARG)__MT__</if> + </set> + </if> + + + <!-- some other conditional defines --> + <set var="ZLIB_DEF"><if cond="WITH_ZLIB=='1'">HAVE_ZLIB_H</if></set> + <set var="DEBUG_DEF"><if cond="BUILD=='debug'">_DEBUG</if></set> + <set var="DEBUG_DEF"><if cond="BUILD=='release'">NDEBUG</if></set> + + <!-- this is very very important when compiling with MINGW: without this line, + the test programs (and all the programs built with libxml2 which use xmlFree) + won't build because of "undefined references to __xmlFree" --> + <set var="STATIC_DEF"><if cond="SHARED=='0'">LIBXML_STATIC</if></set> + + <!-- some conditional libraries dependencies --> + <set var="ICONV_LIB"><if cond="WITH_ICONV=='1'">iconv</if></set> + <set var="WSOCK32_LIB"><if cond="WITH_THREADS=='native'">wsock32</if></set> + <set var="ZLIB_LIB"><if cond="WITH_ZLIB=='1'">zdll</if></set> + <set var="POSIX_LIB"><if cond="WITH_THREADS=='posix'">pthreadVC</if></set> + + <set var="XMLINCLUDEDIR">$(XMLBASEDIR)$(DIRSEP)include$(DIRSEP)libxml$(DIRSEP)</set> + + + + + <!-- --> + <!-- ABOUT CONFIG.H HEADER CREATION --> + <!-- --> + + <set var="CONFIG_SRCNAME">win32config.h</set> + <set var="CONFIG_DSTNAME">config.h</set> + + <if cond="FORMAT!='msvc6prj' and FORMAT!='autoconf' and FORMAT!='gnu'"> + <copy-file-to-file id="setup"> + <!-- On win32 we need to manually copy a default config.h file --> + <!-- from the include/mc/msw folder to include/mc --> + <src>../include/$(CONFIG_SRCNAME)</src> + <dst>../$(CONFIG_DSTNAME)</dst> + <dependency-of>all</dependency-of> + + <!-- With autoconf, we will use the configure script to translate --> + <!-- include/mc/config.h.in to include/mc/config.h and thus we do --> + <!-- not need to do anything here... --> + </copy-file-to-file> + </if> + + <if cond="FORMAT!='msvc6prj'"> + + <mkdir id="setuplibdir"><dir>$(XMLBASEDIR)$(DIRSEP)lib</dir></mkdir> + <mkdir id="setupbindir"><dir>$(XMLBASEDIR)$(DIRSEP)bin</dir></mkdir> + + <!-- Creates all output folders --> + <phony id="setupdirs"> + <dependency-of>all</dependency-of> + <depends>setuplibdir</depends> + <depends>setupbindir</depends> + </phony> + </if> + + <!-- This defines a tag which includes headers on MSVC --> + <!-- Note that $(value) is stuck in there by bakefile, --> + <!-- and is the value between the beginning and end tag. --> + <define-tag name="headers" rules="dll,lib,exe"> + <if cond="FORMAT=='msvc6prj'"> + <msvc-project-files> + $(value) + </msvc-project-files> + </if> + </define-tag> + + <!-- Creates the following custom build rule for MSVC6PRJ file: + copies ..\include\win32config.h into ..\config.h + NOTE: this tag must be used before the <sources> tag if you want that the configuration + file will be created before any other source file is compiled... --> + <define-tag name="msvc-copy-setup-h" rules="dll,lib,action"> + <if cond="FORMAT=='msvc6prj'"> + <headers>$(XMLBASEDIR)\include\$(CONFIG_SRCNAME)</headers> + <set var="__subdir">$(value)</set> + <set var="_custom_build_files" append="1">$(XMLBASEDIR)\include\$(CONFIG_SRCNAME)</set> + <set var="_custom_build____include_win32config_h"> +Creating the configuration file ..\$(CONFIG_DSTNAME) from ..\include\$(CONFIG_SRCNAME) +InputPath=..\include\$(CONFIG_SRCNAME) + +"..\$(CONFIG_DSTNAME)" : $(DOLLAR)(SOURCE) "$(DOLLAR)(INTDIR)" "$(DOLLAR)(OUTDIR)" +$(TAB)copy "$(DOLLAR)(InputPath)" ..\$(CONFIG_DSTNAME) + </set> + </if> + </define-tag> + + + + + + <!-- --> + <!-- TEMPLATES --> + <!-- --> + + <!-- The basic template: used by all the targets --> + <template id="base"> + <if cond="FORMAT=='mingw'"> + <define>HAVE_W32API_H</define> + <ldflags>-mthreads</ldflags> + </if> + + <cxxflags>$(MYCPPFLAGS)</cxxflags> + <warnings>$(WARNINGS)</warnings> + <define>$(UNICODE_DEFINE)</define> + <optimize>$(OPTIMIZEFLAG)</optimize> + <debug-info>$(DEBUGINFO)</debug-info> + <debug-runtime-libs>$(DEBUGRUNTIME)</debug-runtime-libs> + </template> + + <!-- The template used both by the library and by the test programs --> + <template id="xml2" template="base"> + + <!-- -I & -L equivalents --> + <include>$(XMLBASEDIR)$(DIRSEP)include</include> + <include>$(ICONV_DIR)$(DIRSEP)include</include> + <lib-path>$(ICONV_DIR)$(DIRSEP)lib</lib-path> + + <!-- some conditional define flags --> + <cflags>$(THREADS_DEF)</cflags> + <define>$(ZLIB_DEF)</define> + <define>$(DEBUG_DEF)</define> + <define>$(STATIC_DEF)</define> + + <if cond="HAS_DEFINE_ARG=='0'"> + + <!-- we are probably using an IDE output: defaults to WITH_THREADS=='native' --> + <define>_REENTRANT</define> + <define>HAVE_WIN32_THREADS</define> + </if> + + + <!-- these must always be defined on win32 --> + <define>WIN32</define> + <define>_WINDOWS</define> + <define>_MBCS</define> + + <if cond="FORMAT=='borland'"> + <define>_NO_VCL</define> + <define>EILSEQ=2</define> + </if> + </template> + + <!-- The template used by libxml2 test programs --> + <template id="xml2test" template="xml2"> + <dirname>$(XMLTESTDIR)</dirname> + <app-type>console</app-type> + + <library>libxml2</library> + + <sys-lib>$(ICONV_LIB)</sys-lib> + <sys-lib>$(WSOCK32_LIB)</sys-lib> + <sys-lib>$(ZLIB_LIB)</sys-lib> + <sys-lib>$(POSIX_LIB)</sys-lib> + </template> + + + + + + + <!-- --> + <!-- LIBXML2 LIBRARY TARGET --> + <!-- --> + + <lib id="libxml2" template="xml2"> + + <!-- this is useful only when using MSVC6PRJ --> + <if cond="FORMAT=='msvc6prj'"> + <msvc-copy-setup-h/> + <msvc-file-group>Config headers:*config.h</msvc-file-group> + </if> + <if cond="FORMAT!='msvc6prj'"> + <depends>setup</depends> + <depends>setuplibdir</depends> + </if> + + <!-- output folder --> + <dirname>$(XMLBASEDIR)$(DIRSEP)lib</dirname> + + <!-- The output name must be "libxml2.lib" with all compilers. + Since mingw format autoadds the "lib" prefix to the library + name, we must intercept that case to avoid to get "liblibxml2.a" --> + <if cond="FORMAT!='mingw'"> + <libname>libxml2</libname> + </if> + <if cond="FORMAT=='mingw'"> + <libname>xml2</libname> + </if> + + <!-- the list of source files to compile --> + <sources> + $(XMLBASEDIR)$(DIRSEP)c14n.c + $(XMLBASEDIR)$(DIRSEP)catalog.c + $(XMLBASEDIR)$(DIRSEP)chvalid.c + $(XMLBASEDIR)$(DIRSEP)debugXML.c + $(XMLBASEDIR)$(DIRSEP)dict.c + $(XMLBASEDIR)$(DIRSEP)DOCBparser.c + $(XMLBASEDIR)$(DIRSEP)encoding.c + $(XMLBASEDIR)$(DIRSEP)entities.c + $(XMLBASEDIR)$(DIRSEP)error.c + $(XMLBASEDIR)$(DIRSEP)globals.c + $(XMLBASEDIR)$(DIRSEP)hash.c + $(XMLBASEDIR)$(DIRSEP)HTMLparser.c + $(XMLBASEDIR)$(DIRSEP)HTMLtree.c + $(XMLBASEDIR)$(DIRSEP)legacy.c + $(XMLBASEDIR)$(DIRSEP)list.c + $(XMLBASEDIR)$(DIRSEP)nanoftp.c + $(XMLBASEDIR)$(DIRSEP)nanohttp.c + $(XMLBASEDIR)$(DIRSEP)parser.c + $(XMLBASEDIR)$(DIRSEP)parserInternals.c + $(XMLBASEDIR)$(DIRSEP)pattern.c + $(XMLBASEDIR)$(DIRSEP)relaxng.c + $(XMLBASEDIR)$(DIRSEP)SAX2.c + $(XMLBASEDIR)$(DIRSEP)SAX.c + $(XMLBASEDIR)$(DIRSEP)threads.c + $(XMLBASEDIR)$(DIRSEP)tree.c + $(XMLBASEDIR)$(DIRSEP)uri.c + $(XMLBASEDIR)$(DIRSEP)valid.c + $(XMLBASEDIR)$(DIRSEP)xinclude.c + $(XMLBASEDIR)$(DIRSEP)xlink.c + $(XMLBASEDIR)$(DIRSEP)xmlIO.c + $(XMLBASEDIR)$(DIRSEP)xmlmemory.c + $(XMLBASEDIR)$(DIRSEP)xmlreader.c + $(XMLBASEDIR)$(DIRSEP)xmlregexp.c + $(XMLBASEDIR)$(DIRSEP)xmlsave.c + $(XMLBASEDIR)$(DIRSEP)xmlschemas.c + $(XMLBASEDIR)$(DIRSEP)xmlschemastypes.c + $(XMLBASEDIR)$(DIRSEP)xmlunicode.c + $(XMLBASEDIR)$(DIRSEP)xmlwriter.c + $(XMLBASEDIR)$(DIRSEP)xpath.c + $(XMLBASEDIR)$(DIRSEP)xpointer.c + $(XMLBASEDIR)$(DIRSEP)xmlstring.c + </sources> + + <!-- the list of header files (for IDE projects) --> + <headers> + $(XMLINCLUDEDIR)c14n.h + $(XMLINCLUDEDIR)catalog.h + $(XMLINCLUDEDIR)chvalid.h + $(XMLINCLUDEDIR)debugXML.h + $(XMLINCLUDEDIR)dict.h + $(XMLINCLUDEDIR)DOCBparser.h + $(XMLINCLUDEDIR)encoding.h + $(XMLINCLUDEDIR)entities.h + $(XMLINCLUDEDIR)globals.h + $(XMLINCLUDEDIR)hash.h + $(XMLINCLUDEDIR)HTMLparser.h + $(XMLINCLUDEDIR)HTMLtree.h + $(XMLINCLUDEDIR)list.h + $(XMLINCLUDEDIR)nanoftp.h + $(XMLINCLUDEDIR)nanohttp.h + $(XMLINCLUDEDIR)parser.h + $(XMLINCLUDEDIR)parserInternals.h + $(XMLINCLUDEDIR)pattern.h + $(XMLINCLUDEDIR)relaxng.h + $(XMLINCLUDEDIR)SAX.h + $(XMLINCLUDEDIR)SAX2.h + $(XMLINCLUDEDIR)schemasInternals.h + $(XMLINCLUDEDIR)threads.h + $(XMLINCLUDEDIR)tree.h + $(XMLINCLUDEDIR)uri.h + $(XMLINCLUDEDIR)valid.h + $(XMLINCLUDEDIR)xinclude.h + $(XMLINCLUDEDIR)xlink.h + $(XMLINCLUDEDIR)xmlautomata.h + $(XMLINCLUDEDIR)xmlerror.h + $(XMLINCLUDEDIR)xmlexports.h + $(XMLINCLUDEDIR)xmlIO.h + $(XMLINCLUDEDIR)xmlmemory.h + $(XMLINCLUDEDIR)xmlmodule.h + $(XMLINCLUDEDIR)xmlreader.h + $(XMLINCLUDEDIR)xmlregexp.h + $(XMLINCLUDEDIR)xmlsave.h + $(XMLINCLUDEDIR)xmlschemas.h + $(XMLINCLUDEDIR)xmlschemastypes.h + $(XMLINCLUDEDIR)xmlstring.h + $(XMLINCLUDEDIR)xmlunicode.h + $(XMLINCLUDEDIR)xmlversion.h + $(XMLINCLUDEDIR)xmlwriter.h + $(XMLINCLUDEDIR)xpath.h + $(XMLINCLUDEDIR)xpathInternals.h + $(XMLINCLUDEDIR)xpointer.h + </headers> + + <!-- these ones are not inside the include/libxml folder --> + <headers> + $(XMLBASEDIR)$(DIRSEP)libxml.h + $(XMLBASEDIR)$(DIRSEP)triodef.h + $(XMLBASEDIR)$(DIRSEP)trionan.h + $(XMLBASEDIR)$(DIRSEP)include$(DIRSEP)wsockcompat.h + </headers> + </lib> + + + + <!-- --> + <!-- LIBXML2 test programs --> + <!-- --> + + <set var="BUILD_ALL_TESTS"> + + <!-- when using full options support with MSVC6PRJ we should + avoid to create all the DSP files required for the test + programs: they would take a _lot_ of space !! --> + <if cond="FORMAT=='msvc6prj' and FULL_OPTIONS_SUPPORT=='1'">0</if> + + <!-- when creating a makefile or using MSVC6PRJ with limited + options support, then we can build all the tests safely --> + <if cond="FORMAT!='msvc6prj' or FULL_OPTIONS_SUPPORT=='0'">1</if> + + </set> + + <if cond="BUILD_ALL_TESTS=='1'"> + + <exe id="testAutomata" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testAutomata.c</sources></exe> + <exe id="testC14N" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testC14N.c</sources></exe> + <exe id="testHTML" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testHTML.c</sources></exe> + <exe id="testReader" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testReader.c</sources></exe> + <exe id="testRegexp" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testRegexp.c</sources></exe> + <exe id="testRelax" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testRelax.c</sources></exe> + <exe id="testSax" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testSax.c</sources></exe> + <exe id="testSchemas" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testSchemas.c</sources></exe> + <exe id="testURI" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testURI.c</sources></exe> + <exe id="testXPath" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testXPath.c</sources></exe> + <exe id="xmllint" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)xmllint.c</sources></exe> + + <if cond="FORMAT=='autoconf'"> + <exe id="testdso" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testdso.c</sources></exe> + </if> + + <!-- FIXME: + <exe id="testModule" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testModule.c</sources></exe> + + <if cond="WITH_THREADS=='posix'"> + <exe id="testThreads" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testThreads.c</sources></exe> + </if> + <if cond="WITH_THREADS=='ctls' or WITH_THREADS=='native'"> + <exe id="testThreadsWin32" template="xml2test"><sources>$(XMLBASEDIR)$(DIRSEP)testThreadsWin32.c</sources></exe> + </if> + --> + </if> + +</makefile>
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/7956696e/thirdparty/libxml2/buf.c ---------------------------------------------------------------------- diff --git a/thirdparty/libxml2/buf.c b/thirdparty/libxml2/buf.c new file mode 100644 index 0000000..07922ff --- /dev/null +++ b/thirdparty/libxml2/buf.c @@ -0,0 +1,1345 @@ +/* + * buf.c: memory buffers for libxml2 + * + * new buffer structures and entry points to simplify the maintainance + * of libxml2 and ensure we keep good control over memory allocations + * and stay 64 bits clean. + * The new entry point use the xmlBufPtr opaque structure and + * xmlBuf...() counterparts to the old xmlBuf...() functions + * + * See Copyright for the status of this software. + * + * [email protected] + */ + +#define IN_LIBXML +#include "libxml.h" + +#include <string.h> /* for memset() only ! */ +#include <limits.h> +#ifdef HAVE_CTYPE_H +#include <ctype.h> +#endif +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif + +#include <libxml/tree.h> +#include <libxml/globals.h> +#include <libxml/tree.h> +#include <libxml/parserInternals.h> /* for XML_MAX_TEXT_LENGTH */ +#include "buf.h" + +#define WITH_BUFFER_COMPAT + +/** + * xmlBuf: + * + * A buffer structure. The base of the structure is somehow compatible + * with struct _xmlBuffer to limit risks on application which accessed + * directly the input->buf->buffer structures. + */ + +struct _xmlBuf { + xmlChar *content; /* The buffer content UTF8 */ + unsigned int compat_use; /* for binary compatibility */ + unsigned int compat_size; /* for binary compatibility */ + xmlBufferAllocationScheme alloc; /* The realloc method */ + xmlChar *contentIO; /* in IO mode we may have a different base */ + size_t use; /* The buffer size used */ + size_t size; /* The buffer size */ + xmlBufferPtr buffer; /* wrapper for an old buffer */ + int error; /* an error code if a failure occured */ +}; + +#ifdef WITH_BUFFER_COMPAT +/* + * Macro for compatibility with xmlBuffer to be used after an xmlBuf + * is updated. This makes sure the compat fields are updated too. + */ +#define UPDATE_COMPAT(buf) \ + if (buf->size < INT_MAX) buf->compat_size = buf->size; \ + else buf->compat_size = INT_MAX; \ + if (buf->use < INT_MAX) buf->compat_use = buf->use; \ + else buf->compat_use = INT_MAX; + +/* + * Macro for compatibility with xmlBuffer to be used in all the xmlBuf + * entry points, it checks that the compat fields have not been modified + * by direct call to xmlBuffer function from code compiled before 2.9.0 . + */ +#define CHECK_COMPAT(buf) \ + if (buf->size != (size_t) buf->compat_size) \ + if (buf->compat_size < INT_MAX) \ + buf->size = buf->compat_size; \ + if (buf->use != (size_t) buf->compat_use) \ + if (buf->compat_use < INT_MAX) \ + buf->use = buf->compat_use; + +#else /* ! WITH_BUFFER_COMPAT */ +#define UPDATE_COMPAT(buf) +#define CHECK_COMPAT(buf) +#endif /* WITH_BUFFER_COMPAT */ + +/** + * xmlBufMemoryError: + * @extra: extra informations + * + * Handle an out of memory condition + * To be improved... + */ +static void +xmlBufMemoryError(xmlBufPtr buf, const char *extra) +{ + __xmlSimpleError(XML_FROM_BUFFER, XML_ERR_NO_MEMORY, NULL, NULL, extra); + if ((buf) && (buf->error == 0)) + buf->error = XML_ERR_NO_MEMORY; +} + +/** + * xmlBufOverflowError: + * @extra: extra informations + * + * Handle a buffer overflow error + * To be improved... + */ +static void +xmlBufOverflowError(xmlBufPtr buf, const char *extra) +{ + __xmlSimpleError(XML_FROM_BUFFER, XML_BUF_OVERFLOW, NULL, NULL, extra); + if ((buf) && (buf->error == 0)) + buf->error = XML_BUF_OVERFLOW; +} + + +/** + * xmlBufCreate: + * + * routine to create an XML buffer. + * returns the new structure. + */ +xmlBufPtr +xmlBufCreate(void) { + xmlBufPtr ret; + + ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf)); + if (ret == NULL) { + xmlBufMemoryError(NULL, "creating buffer"); + return(NULL); + } + ret->compat_use = 0; + ret->use = 0; + ret->error = 0; + ret->buffer = NULL; + ret->size = xmlDefaultBufferSize; + ret->compat_size = xmlDefaultBufferSize; + ret->alloc = xmlBufferAllocScheme; + ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); + if (ret->content == NULL) { + xmlBufMemoryError(ret, "creating buffer"); + xmlFree(ret); + return(NULL); + } + ret->content[0] = 0; + ret->contentIO = NULL; + return(ret); +} + +/** + * xmlBufCreateSize: + * @size: initial size of buffer + * + * routine to create an XML buffer. + * returns the new structure. + */ +xmlBufPtr +xmlBufCreateSize(size_t size) { + xmlBufPtr ret; + + ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf)); + if (ret == NULL) { + xmlBufMemoryError(NULL, "creating buffer"); + return(NULL); + } + ret->compat_use = 0; + ret->use = 0; + ret->error = 0; + ret->buffer = NULL; + ret->alloc = xmlBufferAllocScheme; + ret->size = (size ? size+2 : 0); /* +1 for ending null */ + ret->compat_size = (int) ret->size; + if (ret->size){ + ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); + if (ret->content == NULL) { + xmlBufMemoryError(ret, "creating buffer"); + xmlFree(ret); + return(NULL); + } + ret->content[0] = 0; + } else + ret->content = NULL; + ret->contentIO = NULL; + return(ret); +} + +/** + * xmlBufDetach: + * @buf: the buffer + * + * Remove the string contained in a buffer and give it back to the + * caller. The buffer is reset to an empty content. + * This doesn't work with immutable buffers as they can't be reset. + * + * Returns the previous string contained by the buffer. + */ +xmlChar * +xmlBufDetach(xmlBufPtr buf) { + xmlChar *ret; + + if (buf == NULL) + return(NULL); + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) + return(NULL); + if (buf->buffer != NULL) + return(NULL); + if (buf->error) + return(NULL); + + ret = buf->content; + buf->content = NULL; + buf->size = 0; + buf->use = 0; + buf->compat_use = 0; + buf->compat_size = 0; + + return ret; +} + + +/** + * xmlBufCreateStatic: + * @mem: the memory area + * @size: the size in byte + * + * routine to create an XML buffer from an immutable memory area. + * The area won't be modified nor copied, and is expected to be + * present until the end of the buffer lifetime. + * + * returns the new structure. + */ +xmlBufPtr +xmlBufCreateStatic(void *mem, size_t size) { + xmlBufPtr ret; + + if ((mem == NULL) || (size == 0)) + return(NULL); + + ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf)); + if (ret == NULL) { + xmlBufMemoryError(NULL, "creating buffer"); + return(NULL); + } + if (size < INT_MAX) { + ret->compat_use = size; + ret->compat_size = size; + } else { + ret->compat_use = INT_MAX; + ret->compat_size = INT_MAX; + } + ret->use = size; + ret->size = size; + ret->alloc = XML_BUFFER_ALLOC_IMMUTABLE; + ret->content = (xmlChar *) mem; + ret->error = 0; + ret->buffer = NULL; + return(ret); +} + +/** + * xmlBufGetAllocationScheme: + * @buf: the buffer + * + * Get the buffer allocation scheme + * + * Returns the scheme or -1 in case of error + */ +int +xmlBufGetAllocationScheme(xmlBufPtr buf) { + if (buf == NULL) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufGetAllocationScheme: buf == NULL\n"); +#endif + return(-1); + } + return(buf->alloc); +} + +/** + * xmlBufSetAllocationScheme: + * @buf: the buffer to tune + * @scheme: allocation scheme to use + * + * Sets the allocation scheme for this buffer + * + * returns 0 in case of success and -1 in case of failure + */ +int +xmlBufSetAllocationScheme(xmlBufPtr buf, + xmlBufferAllocationScheme scheme) { + if ((buf == NULL) || (buf->error != 0)) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufSetAllocationScheme: buf == NULL or in error\n"); +#endif + return(-1); + } + if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || + (buf->alloc == XML_BUFFER_ALLOC_IO)) + return(-1); + if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) || + (scheme == XML_BUFFER_ALLOC_EXACT) || + (scheme == XML_BUFFER_ALLOC_HYBRID) || + (scheme == XML_BUFFER_ALLOC_IMMUTABLE) || + (scheme == XML_BUFFER_ALLOC_BOUNDED)) { + buf->alloc = scheme; + if (buf->buffer) + buf->buffer->alloc = scheme; + return(0); + } + /* + * Switching a buffer ALLOC_IO has the side effect of initializing + * the contentIO field with the current content + */ + if (scheme == XML_BUFFER_ALLOC_IO) { + buf->alloc = XML_BUFFER_ALLOC_IO; + buf->contentIO = buf->content; + } + return(-1); +} + +/** + * xmlBufFree: + * @buf: the buffer to free + * + * Frees an XML buffer. It frees both the content and the structure which + * encapsulate it. + */ +void +xmlBufFree(xmlBufPtr buf) { + if (buf == NULL) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufFree: buf == NULL\n"); +#endif + return; + } + + if ((buf->alloc == XML_BUFFER_ALLOC_IO) && + (buf->contentIO != NULL)) { + xmlFree(buf->contentIO); + } else if ((buf->content != NULL) && + (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { + xmlFree(buf->content); + } + xmlFree(buf); +} + +/** + * xmlBufEmpty: + * @buf: the buffer + * + * empty a buffer. + */ +void +xmlBufEmpty(xmlBufPtr buf) { + if ((buf == NULL) || (buf->error != 0)) return; + if (buf->content == NULL) return; + CHECK_COMPAT(buf) + buf->use = 0; + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { + buf->content = BAD_CAST ""; + } else if ((buf->alloc == XML_BUFFER_ALLOC_IO) && + (buf->contentIO != NULL)) { + size_t start_buf = buf->content - buf->contentIO; + + buf->size += start_buf; + buf->content = buf->contentIO; + buf->content[0] = 0; + } else { + buf->content[0] = 0; + } + UPDATE_COMPAT(buf) +} + +/** + * xmlBufShrink: + * @buf: the buffer to dump + * @len: the number of xmlChar to remove + * + * Remove the beginning of an XML buffer. + * NOTE that this routine behaviour differs from xmlBufferShrink() + * as it will return 0 on error instead of -1 due to size_t being + * used as the return type. + * + * Returns the number of byte removed or 0 in case of failure + */ +size_t +xmlBufShrink(xmlBufPtr buf, size_t len) { + if ((buf == NULL) || (buf->error != 0)) return(0); + CHECK_COMPAT(buf) + if (len == 0) return(0); + if (len > buf->use) return(0); + + buf->use -= len; + if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || + ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL))) { + /* + * we just move the content pointer, but also make sure + * the perceived buffer size has shrinked accordingly + */ + buf->content += len; + buf->size -= len; + + /* + * sometimes though it maybe be better to really shrink + * on IO buffers + */ + if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { + size_t start_buf = buf->content - buf->contentIO; + if (start_buf >= buf->size) { + memmove(buf->contentIO, &buf->content[0], buf->use); + buf->content = buf->contentIO; + buf->content[buf->use] = 0; + buf->size += start_buf; + } + } + } else { + memmove(buf->content, &buf->content[len], buf->use); + buf->content[buf->use] = 0; + } + UPDATE_COMPAT(buf) + return(len); +} + +/** + * xmlBufGrowInternal: + * @buf: the buffer + * @len: the minimum free size to allocate + * + * Grow the available space of an XML buffer, @len is the target value + * Error checking should be done on buf->error since using the return + * value doesn't work that well + * + * Returns 0 in case of error or the length made available otherwise + */ +static size_t +xmlBufGrowInternal(xmlBufPtr buf, size_t len) { + size_t size; + xmlChar *newbuf; + + if ((buf == NULL) || (buf->error != 0)) return(0); + CHECK_COMPAT(buf) + + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); + if (buf->use + len < buf->size) + return(buf->size - buf->use); + + /* + * Windows has a BIG problem on realloc timing, so we try to double + * the buffer size (if that's enough) (bug 146697) + * Apparently BSD too, and it's probably best for linux too + * On an embedded system this may be something to change + */ +#if 1 + if (buf->size > (size_t) len) + size = buf->size * 2; + else + size = buf->use + len + 100; +#else + size = buf->use + len + 100; +#endif + + if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { + /* + * Used to provide parsing limits + */ + if ((buf->use + len >= XML_MAX_TEXT_LENGTH) || + (buf->size >= XML_MAX_TEXT_LENGTH)) { + xmlBufMemoryError(buf, "buffer error: text too long\n"); + return(0); + } + if (size >= XML_MAX_TEXT_LENGTH) + size = XML_MAX_TEXT_LENGTH; + } + if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { + size_t start_buf = buf->content - buf->contentIO; + + newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size); + if (newbuf == NULL) { + xmlBufMemoryError(buf, "growing buffer"); + return(0); + } + buf->contentIO = newbuf; + buf->content = newbuf + start_buf; + } else { + newbuf = (xmlChar *) xmlRealloc(buf->content, size); + if (newbuf == NULL) { + xmlBufMemoryError(buf, "growing buffer"); + return(0); + } + buf->content = newbuf; + } + buf->size = size; + UPDATE_COMPAT(buf) + return(buf->size - buf->use); +} + +/** + * xmlBufGrow: + * @buf: the buffer + * @len: the minimum free size to allocate + * + * Grow the available space of an XML buffer, @len is the target value + * This is been kept compatible with xmlBufferGrow() as much as possible + * + * Returns -1 in case of error or the length made available otherwise + */ +int +xmlBufGrow(xmlBufPtr buf, int len) { + size_t ret; + + if ((buf == NULL) || (len < 0)) return(-1); + if (len == 0) + return(0); + ret = xmlBufGrowInternal(buf, len); + if (buf->error != 0) + return(-1); + return((int) ret); +} + +/** + * xmlBufInflate: + * @buf: the buffer + * @len: the minimum extra free size to allocate + * + * Grow the available space of an XML buffer, adding at least @len bytes + * + * Returns 0 if successful or -1 in case of error + */ +int +xmlBufInflate(xmlBufPtr buf, size_t len) { + if (buf == NULL) return(-1); + xmlBufGrowInternal(buf, len + buf->size); + if (buf->error) + return(-1); + return(0); +} + +/** + * xmlBufDump: + * @file: the file output + * @buf: the buffer to dump + * + * Dumps an XML buffer to a FILE *. + * Returns the number of #xmlChar written + */ +size_t +xmlBufDump(FILE *file, xmlBufPtr buf) { + size_t ret; + + if ((buf == NULL) || (buf->error != 0)) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufDump: buf == NULL or in error\n"); +#endif + return(0); + } + if (buf->content == NULL) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufDump: buf->content == NULL\n"); +#endif + return(0); + } + CHECK_COMPAT(buf) + if (file == NULL) + file = stdout; + ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file); + return(ret); +} + +/** + * xmlBufContent: + * @buf: the buffer + * + * Function to extract the content of a buffer + * + * Returns the internal content + */ + +xmlChar * +xmlBufContent(const xmlBuf *buf) +{ + if ((!buf) || (buf->error)) + return NULL; + + return(buf->content); +} + +/** + * xmlBufEnd: + * @buf: the buffer + * + * Function to extract the end of the content of a buffer + * + * Returns the end of the internal content or NULL in case of error + */ + +xmlChar * +xmlBufEnd(xmlBufPtr buf) +{ + if ((!buf) || (buf->error)) + return NULL; + CHECK_COMPAT(buf) + + return(&buf->content[buf->use]); +} + +/** + * xmlBufAddLen: + * @buf: the buffer + * @len: the size which were added at the end + * + * Sometime data may be added at the end of the buffer without + * using the xmlBuf APIs that is used to expand the used space + * and set the zero terminating at the end of the buffer + * + * Returns -1 in case of error and 0 otherwise + */ +int +xmlBufAddLen(xmlBufPtr buf, size_t len) { + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (len > (buf->size - buf->use)) + return(-1); + buf->use += len; + UPDATE_COMPAT(buf) + if (buf->size > buf->use) + buf->content[buf->use] = 0; + else + return(-1); + return(0); +} + +/** + * xmlBufErase: + * @buf: the buffer + * @len: the size to erase at the end + * + * Sometime data need to be erased at the end of the buffer + * + * Returns -1 in case of error and 0 otherwise + */ +int +xmlBufErase(xmlBufPtr buf, size_t len) { + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (len > buf->use) + return(-1); + buf->use -= len; + buf->content[buf->use] = 0; + UPDATE_COMPAT(buf) + return(0); +} + +/** + * xmlBufLength: + * @buf: the buffer + * + * Function to get the length of a buffer + * + * Returns the length of data in the internal content + */ + +size_t +xmlBufLength(const xmlBufPtr buf) +{ + if ((!buf) || (buf->error)) + return 0; + CHECK_COMPAT(buf) + + return(buf->use); +} + +/** + * xmlBufUse: + * @buf: the buffer + * + * Function to get the length of a buffer + * + * Returns the length of data in the internal content + */ + +size_t +xmlBufUse(const xmlBufPtr buf) +{ + if ((!buf) || (buf->error)) + return 0; + CHECK_COMPAT(buf) + + return(buf->use); +} + +/** + * xmlBufAvail: + * @buf: the buffer + * + * Function to find how much free space is allocated but not + * used in the buffer. It does not account for the terminating zero + * usually needed + * + * Returns the amount or 0 if none or an error occured + */ + +size_t +xmlBufAvail(const xmlBufPtr buf) +{ + if ((!buf) || (buf->error)) + return 0; + CHECK_COMPAT(buf) + + return(buf->size - buf->use); +} + +/** + * xmlBufIsEmpty: + * @buf: the buffer + * + * Tell if a buffer is empty + * + * Returns 0 if no, 1 if yes and -1 in case of error + */ +int +xmlBufIsEmpty(const xmlBufPtr buf) +{ + if ((!buf) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + + return(buf->use == 0); +} + +/** + * xmlBufResize: + * @buf: the buffer to resize + * @size: the desired size + * + * Resize a buffer to accommodate minimum size of @size. + * + * Returns 0 in case of problems, 1 otherwise + */ +int +xmlBufResize(xmlBufPtr buf, size_t size) +{ + unsigned int newSize; + xmlChar* rebuf = NULL; + size_t start_buf; + + if ((buf == NULL) || (buf->error)) + return(0); + CHECK_COMPAT(buf) + + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); + if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { + /* + * Used to provide parsing limits + */ + if (size >= XML_MAX_TEXT_LENGTH) { + xmlBufMemoryError(buf, "buffer error: text too long\n"); + return(0); + } + } + + /* Don't resize if we don't have to */ + if (size < buf->size) + return 1; + + /* figure out new size */ + switch (buf->alloc){ + case XML_BUFFER_ALLOC_IO: + case XML_BUFFER_ALLOC_DOUBLEIT: + /*take care of empty case*/ + newSize = (buf->size ? buf->size*2 : size + 10); + while (size > newSize) { + if (newSize > UINT_MAX / 2) { + xmlBufMemoryError(buf, "growing buffer"); + return 0; + } + newSize *= 2; + } + break; + case XML_BUFFER_ALLOC_EXACT: + newSize = size+10; + break; + case XML_BUFFER_ALLOC_HYBRID: + if (buf->use < BASE_BUFFER_SIZE) + newSize = size; + else { + newSize = buf->size * 2; + while (size > newSize) { + if (newSize > UINT_MAX / 2) { + xmlBufMemoryError(buf, "growing buffer"); + return 0; + } + newSize *= 2; + } + } + break; + + default: + newSize = size+10; + break; + } + + if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { + start_buf = buf->content - buf->contentIO; + + if (start_buf > newSize) { + /* move data back to start */ + memmove(buf->contentIO, buf->content, buf->use); + buf->content = buf->contentIO; + buf->content[buf->use] = 0; + buf->size += start_buf; + } else { + rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize); + if (rebuf == NULL) { + xmlBufMemoryError(buf, "growing buffer"); + return 0; + } + buf->contentIO = rebuf; + buf->content = rebuf + start_buf; + } + } else { + if (buf->content == NULL) { + rebuf = (xmlChar *) xmlMallocAtomic(newSize); + } else if (buf->size - buf->use < 100) { + rebuf = (xmlChar *) xmlRealloc(buf->content, newSize); + } else { + /* + * if we are reallocating a buffer far from being full, it's + * better to make a new allocation and copy only the used range + * and free the old one. + */ + rebuf = (xmlChar *) xmlMallocAtomic(newSize); + if (rebuf != NULL) { + memcpy(rebuf, buf->content, buf->use); + xmlFree(buf->content); + rebuf[buf->use] = 0; + } + } + if (rebuf == NULL) { + xmlBufMemoryError(buf, "growing buffer"); + return 0; + } + buf->content = rebuf; + } + buf->size = newSize; + UPDATE_COMPAT(buf) + + return 1; +} + +/** + * xmlBufAdd: + * @buf: the buffer to dump + * @str: the #xmlChar string + * @len: the number of #xmlChar to add + * + * Add a string range to an XML buffer. if len == -1, the length of + * str is recomputed. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) { + unsigned int needSize; + + if ((str == NULL) || (buf == NULL) || (buf->error)) + return -1; + CHECK_COMPAT(buf) + + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; + if (len < -1) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufAdd: len < 0\n"); +#endif + return -1; + } + if (len == 0) return 0; + + if (len < 0) + len = xmlStrlen(str); + + if (len < 0) return -1; + if (len == 0) return 0; + + needSize = buf->use + len + 2; + if (needSize > buf->size){ + if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { + /* + * Used to provide parsing limits + */ + if (needSize >= XML_MAX_TEXT_LENGTH) { + xmlBufMemoryError(buf, "buffer error: text too long\n"); + return(-1); + } + } + if (!xmlBufResize(buf, needSize)){ + xmlBufMemoryError(buf, "growing buffer"); + return XML_ERR_NO_MEMORY; + } + } + + memmove(&buf->content[buf->use], str, len*sizeof(xmlChar)); + buf->use += len; + buf->content[buf->use] = 0; + UPDATE_COMPAT(buf) + return 0; +} + +/** + * xmlBufAddHead: + * @buf: the buffer + * @str: the #xmlChar string + * @len: the number of #xmlChar to add + * + * Add a string range to the beginning of an XML buffer. + * if len == -1, the length of @str is recomputed. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) { + unsigned int needSize; + + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; + if (str == NULL) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufAddHead: str == NULL\n"); +#endif + return -1; + } + if (len < -1) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufAddHead: len < 0\n"); +#endif + return -1; + } + if (len == 0) return 0; + + if (len < 0) + len = xmlStrlen(str); + + if (len <= 0) return -1; + + if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { + size_t start_buf = buf->content - buf->contentIO; + + if (start_buf > (unsigned int) len) { + /* + * We can add it in the space previously shrinked + */ + buf->content -= len; + memmove(&buf->content[0], str, len); + buf->use += len; + buf->size += len; + UPDATE_COMPAT(buf) + return(0); + } + } + needSize = buf->use + len + 2; + if (needSize > buf->size){ + if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { + /* + * Used to provide parsing limits + */ + if (needSize >= XML_MAX_TEXT_LENGTH) { + xmlBufMemoryError(buf, "buffer error: text too long\n"); + return(-1); + } + } + if (!xmlBufResize(buf, needSize)){ + xmlBufMemoryError(buf, "growing buffer"); + return XML_ERR_NO_MEMORY; + } + } + + memmove(&buf->content[len], &buf->content[0], buf->use); + memmove(&buf->content[0], str, len); + buf->use += len; + buf->content[buf->use] = 0; + UPDATE_COMPAT(buf) + return 0; +} + +/** + * xmlBufCat: + * @buf: the buffer to add to + * @str: the #xmlChar string + * + * Append a zero terminated string to an XML buffer. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufCat(xmlBufPtr buf, const xmlChar *str) { + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; + if (str == NULL) return -1; + return xmlBufAdd(buf, str, -1); +} + +/** + * xmlBufCCat: + * @buf: the buffer to dump + * @str: the C char string + * + * Append a zero terminated C string to an XML buffer. + * + * Returns 0 successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufCCat(xmlBufPtr buf, const char *str) { + const char *cur; + + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; + if (str == NULL) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufCCat: str == NULL\n"); +#endif + return -1; + } + for (cur = str;*cur != 0;cur++) { + if (buf->use + 10 >= buf->size) { + if (!xmlBufResize(buf, buf->use+10)){ + xmlBufMemoryError(buf, "growing buffer"); + return XML_ERR_NO_MEMORY; + } + } + buf->content[buf->use++] = *cur; + } + buf->content[buf->use] = 0; + UPDATE_COMPAT(buf) + return 0; +} + +/** + * xmlBufWriteCHAR: + * @buf: the XML buffer + * @string: the string to add + * + * routine which manages and grows an output buffer. This one adds + * xmlChars at the end of the buffer. + * + * Returns 0 if successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufWriteCHAR(xmlBufPtr buf, const xmlChar *string) { + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) + return(-1); + return(xmlBufCat(buf, string)); +} + +/** + * xmlBufWriteChar: + * @buf: the XML buffer output + * @string: the string to add + * + * routine which manage and grows an output buffer. This one add + * C chars at the end of the array. + * + * Returns 0 if successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufWriteChar(xmlBufPtr buf, const char *string) { + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) + return(-1); + return(xmlBufCCat(buf, string)); +} + + +/** + * xmlBufWriteQuotedString: + * @buf: the XML buffer output + * @string: the string to add + * + * routine which manage and grows an output buffer. This one writes + * a quoted or double quoted #xmlChar string, checking first if it holds + * quote or double-quotes internally + * + * Returns 0 if successful, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +int +xmlBufWriteQuotedString(xmlBufPtr buf, const xmlChar *string) { + const xmlChar *cur, *base; + if ((buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) + return(-1); + if (xmlStrchr(string, '\"')) { + if (xmlStrchr(string, '\'')) { +#ifdef DEBUG_BUFFER + xmlGenericError(xmlGenericErrorContext, + "xmlBufWriteQuotedString: string contains quote and double-quotes !\n"); +#endif + xmlBufCCat(buf, "\""); + base = cur = string; + while(*cur != 0){ + if(*cur == '"'){ + if (base != cur) + xmlBufAdd(buf, base, cur - base); + xmlBufAdd(buf, BAD_CAST """, 6); + cur++; + base = cur; + } + else { + cur++; + } + } + if (base != cur) + xmlBufAdd(buf, base, cur - base); + xmlBufCCat(buf, "\""); + } + else{ + xmlBufCCat(buf, "\'"); + xmlBufCat(buf, string); + xmlBufCCat(buf, "\'"); + } + } else { + xmlBufCCat(buf, "\""); + xmlBufCat(buf, string); + xmlBufCCat(buf, "\""); + } + return(0); +} + +/** + * xmlBufFromBuffer: + * @buffer: incoming old buffer to convert to a new one + * + * Helper routine to switch from the old buffer structures in use + * in various APIs. It creates a wrapper xmlBufPtr which will be + * used for internal processing until the xmlBufBackToBuffer() is + * issued. + * + * Returns a new xmlBufPtr unless the call failed and NULL is returned + */ +xmlBufPtr +xmlBufFromBuffer(xmlBufferPtr buffer) { + xmlBufPtr ret; + + if (buffer == NULL) + return(NULL); + + ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf)); + if (ret == NULL) { + xmlBufMemoryError(NULL, "creating buffer"); + return(NULL); + } + ret->use = buffer->use; + ret->size = buffer->size; + ret->compat_use = buffer->use; + ret->compat_size = buffer->size; + ret->error = 0; + ret->buffer = buffer; + ret->alloc = buffer->alloc; + ret->content = buffer->content; + ret->contentIO = buffer->contentIO; + + return(ret); +} + +/** + * xmlBufBackToBuffer: + * @buf: new buffer wrapping the old one + * + * Function to be called once internal processing had been done to + * update back the buffer provided by the user. This can lead to + * a failure in case the size accumulated in the xmlBuf is larger + * than what an xmlBuffer can support on 64 bits (INT_MAX) + * The xmlBufPtr @buf wrapper is deallocated by this call in any case. + * + * Returns the old xmlBufferPtr unless the call failed and NULL is returned + */ +xmlBufferPtr +xmlBufBackToBuffer(xmlBufPtr buf) { + xmlBufferPtr ret; + + if ((buf == NULL) || (buf->error)) + return(NULL); + CHECK_COMPAT(buf) + if (buf->buffer == NULL) { + xmlBufFree(buf); + return(NULL); + } + + ret = buf->buffer; + /* + * What to do in case of error in the buffer ??? + */ + if (buf->use > INT_MAX) { + /* + * Worse case, we really allocated and used more than the + * maximum allowed memory for an xmlBuffer on this architecture. + * Keep the buffer but provide a truncated size value. + */ + xmlBufOverflowError(buf, "Used size too big for xmlBuffer"); + ret->use = INT_MAX; + ret->size = INT_MAX; + } else if (buf->size > INT_MAX) { + /* + * milder case, we allocated more than the maximum allowed memory + * for an xmlBuffer on this architecture, but used less than the + * limit. + * Keep the buffer but provide a truncated size value. + */ + xmlBufOverflowError(buf, "Allocated size too big for xmlBuffer"); + ret->size = INT_MAX; + } + ret->use = (int) buf->use; + ret->size = (int) buf->size; + ret->alloc = buf->alloc; + ret->content = buf->content; + ret->contentIO = buf->contentIO; + xmlFree(buf); + return(ret); +} + +/** + * xmlBufMergeBuffer: + * @buf: an xmlBufPtr + * @buffer: the buffer to consume into @buf + * + * The content of @buffer is appended to @buf and @buffer is freed + * + * Returns -1 in case of error, 0 otherwise, in any case @buffer is freed + */ +int +xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer) { + int ret = 0; + + if ((buf == NULL) || (buf->error)) { + xmlBufferFree(buffer); + return(-1); + } + CHECK_COMPAT(buf) + if ((buffer != NULL) && (buffer->content != NULL) && + (buffer->use > 0)) { + ret = xmlBufAdd(buf, buffer->content, buffer->use); + } + xmlBufferFree(buffer); + return(ret); +} + +/** + * xmlBufResetInput: + * @buf: an xmlBufPtr + * @input: an xmlParserInputPtr + * + * Update the input to use the current set of pointers from the buffer. + * + * Returns -1 in case of error, 0 otherwise + */ +int +xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input) { + if ((input == NULL) || (buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + input->base = input->cur = buf->content; + input->end = &buf->content[buf->use]; + return(0); +} + +/** + * xmlBufGetInputBase: + * @buf: an xmlBufPtr + * @input: an xmlParserInputPtr + * + * Get the base of the @input relative to the beginning of the buffer + * + * Returns the size_t corresponding to the displacement + */ +size_t +xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input) { + size_t base; + + if ((input == NULL) || (buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + base = input->base - buf->content; + /* + * We could do some pointer arythmetic checks but that's probably + * sufficient. + */ + if (base > buf->size) { + xmlBufOverflowError(buf, "Input reference outside of the buffer"); + base = 0; + } + return(base); +} + +/** + * xmlBufSetInputBaseCur: + * @buf: an xmlBufPtr + * @input: an xmlParserInputPtr + * @base: the base value relative to the beginning of the buffer + * @cur: the cur value relative to the beginning of the buffer + * + * Update the input to use the base and cur relative to the buffer + * after a possible reallocation of its content + * + * Returns -1 in case of error, 0 otherwise + */ +int +xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, + size_t base, size_t cur) { + if ((input == NULL) || (buf == NULL) || (buf->error)) + return(-1); + CHECK_COMPAT(buf) + input->base = &buf->content[base]; + input->cur = input->base + cur; + input->end = &buf->content[buf->use]; + return(0); +} + +#define bottom_buf +#include "elfgcchack.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/7956696e/thirdparty/libxml2/buf.h ---------------------------------------------------------------------- diff --git a/thirdparty/libxml2/buf.h b/thirdparty/libxml2/buf.h new file mode 100644 index 0000000..ebdc978 --- /dev/null +++ b/thirdparty/libxml2/buf.h @@ -0,0 +1,72 @@ +/* + * Summary: Internal Interfaces for memory buffers in libxml2 + * Description: this module describes most of the new xmlBuf buffer + * entry points, those are private routines, with a + * few exceptions exported in tree.h. This was added + * in 2.9.0. + * + * Copy: See Copyright for the status of this software. + * + * Author: Daniel Veillard + */ + +#ifndef __XML_BUF_H__ +#define __XML_BUF_H__ + +#include <libxml/tree.h> + +#ifdef __cplusplus +extern "C" { +#endif + +xmlBufPtr xmlBufCreate(void); +xmlBufPtr xmlBufCreateSize(size_t size); +xmlBufPtr xmlBufCreateStatic(void *mem, size_t size); + +int xmlBufSetAllocationScheme(xmlBufPtr buf, + xmlBufferAllocationScheme scheme); +int xmlBufGetAllocationScheme(xmlBufPtr buf); + +void xmlBufFree(xmlBufPtr buf); +void xmlBufEmpty(xmlBufPtr buf); + +/* size_t xmlBufShrink(xmlBufPtr buf, size_t len); */ +int xmlBufGrow(xmlBufPtr buf, int len); +int xmlBufInflate(xmlBufPtr buf, size_t len); +int xmlBufResize(xmlBufPtr buf, size_t len); + +int xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len); +int xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len); +int xmlBufCat(xmlBufPtr buf, const xmlChar *str); +int xmlBufCCat(xmlBufPtr buf, const char *str); +int xmlBufWriteCHAR(xmlBufPtr buf, const xmlChar *string); +int xmlBufWriteChar(xmlBufPtr buf, const char *string); +int xmlBufWriteQuotedString(xmlBufPtr buf, const xmlChar *string); + +size_t xmlBufAvail(const xmlBufPtr buf); +size_t xmlBufLength(const xmlBufPtr buf); +/* size_t xmlBufUse(const xmlBufPtr buf); */ +int xmlBufIsEmpty(const xmlBufPtr buf); +int xmlBufAddLen(xmlBufPtr buf, size_t len); +int xmlBufErase(xmlBufPtr buf, size_t len); + +/* const xmlChar * xmlBufContent(const xmlBuf *buf); */ +/* const xmlChar * xmlBufEnd(xmlBufPtr buf); */ + +xmlChar * xmlBufDetach(xmlBufPtr buf); + +size_t xmlBufDump(FILE *file, xmlBufPtr buf); + +xmlBufPtr xmlBufFromBuffer(xmlBufferPtr buffer); +xmlBufferPtr xmlBufBackToBuffer(xmlBufPtr buf); +int xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer); + +int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input); +size_t xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input); +int xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, + size_t base, size_t cur); +#ifdef __cplusplus +} +#endif +#endif /* __XML_BUF_H__ */ +
