Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OGR 4 : * Purpose: Convenience function for parsing with Expat library 5 : * Author: Even Rouault, even dot rouault at spatialys.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2009, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef OGR_EXPATH_INCLUDED 14 : #define OGR_EXPATH_INCLUDED 15 : 16 : #ifdef HAVE_EXPAT 17 : 18 : #include "cpl_port.h" 19 : #include <expat.h> 20 : 21 : #include <memory> 22 : 23 : /* Compatibility stuff for expat >= 1.95.0 and < 1.95.7 */ 24 : #ifndef XMLCALL 25 : #define XMLCALL 26 : #endif 27 : #ifndef XML_STATUS_OK 28 : #define XML_STATUS_OK 1 29 : #define XML_STATUS_ERROR 0 30 : #endif 31 : 32 : #undef XML_FALSE 33 : #define XML_FALSE static_cast<XML_Bool>(0) 34 : 35 : #undef XML_TRUE 36 : #define XML_TRUE static_cast<XML_Bool>(1) 37 : 38 : /* XML_StopParser only available for expat >= 1.95.8 */ 39 : #if !defined(XML_MAJOR_VERSION) || \ 40 : (XML_MAJOR_VERSION * 10000 + XML_MINOR_VERSION * 100 + \ 41 : XML_MICRO_VERSION) < 19508 42 : #define XML_StopParser(parser, resumable) 43 : #warning \ 44 : "Expat version is too old and does not have XML_StopParser. Corrupted files could hang OGR" 45 : #endif 46 : 47 : /* Only for internal use ! */ 48 : XML_Parser CPL_DLL OGRCreateExpatXMLParser(void); 49 : 50 : // 51 : //! @cond Doxygen_Suppress 52 : struct CPL_DLL OGRExpatUniquePtrDeleter 53 : { 54 199 : void operator()(XML_Parser oParser) const 55 : { 56 199 : XML_ParserFree(oParser); 57 199 : } 58 : }; 59 : 60 : //! @endcond 61 : 62 : /** Unique pointer type for XML_Parser. 63 : * @since GDAL 3.2 64 : */ 65 : using OGRExpatUniquePtr = 66 : std::unique_ptr<XML_ParserStruct, OGRExpatUniquePtrDeleter>; 67 : 68 : #endif /* HAVE_EXPAT */ 69 : 70 : #endif /* OGR_EXPATH_INCLUDED */