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