Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
8.7 KiB

  1. /*===========================================================================
  2. Parsifal XML Parser
  3. Copyright (c) 2002-2004 Toni Uusitalo
  4. released to the public domain 2002-11-15
  5. http://www.saunalahti.fi/~samiuus/toni/xmlproc/
  6. Parsifal is free for both commercial and non-commercial use and
  7. redistribution, provided that author's copyright and disclaimer are
  8. retained intact. You are free to modify Parsifal for your own use and
  9. to redistribute Parsifal with your modifications, provided that the
  10. modifications are clearly documented.
  11. DISCLAIMER
  12. ----------
  13. This program is distributed in the hope that it will be useful, but
  14. WITHOUT ANY WARRANTY; without even the implied warranty of
  15. Merchantability or fitness for a particular purpose. Please use it AT
  16. YOUR OWN RISK.
  17. ===========================================================================*/
  18. #ifndef PARSIFAL__H
  19. #define PARSIFAL__H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include "bistream.h"
  24. #include "xmlhash.h"
  25. #include "xmlvect.h"
  26. #include "xmlsbuf.h"
  27. #include "xmlpool.h"
  28. #ifndef XMLCH_DEFINED
  29. #define XMLCH_DEFINED
  30. typedef unsigned char XMLCH;
  31. #endif
  32. typedef struct tagXMLRUNTIMETAG
  33. {
  34. XMLCH *qname;
  35. XMLCH *uri;
  36. XMLCH *localName;
  37. XMLCH *prefix;
  38. LPXMLHTABLE Scope;
  39. LPXMLHTABLE prevScope;
  40. XMLSTRINGBUF nameBuf;
  41. } XMLRUNTIMETAG, *LPXMLRUNTIMETAG;
  42. typedef struct tagXMLRUNTIMEATT
  43. {
  44. XMLCH *qname;
  45. XMLCH *value;
  46. XMLCH *uri;
  47. XMLCH *localName;
  48. XMLCH *prefix;
  49. XMLSTRINGBUF nameBuf;
  50. XMLSTRINGBUF valBuf;
  51. } XMLRUNTIMEATT, *LPXMLRUNTIMEATT;
  52. typedef struct tagXMLPARSERRUNTIME
  53. {
  54. LPXMLHTABLE nsScope;
  55. LPXMLHTABLE namedAtts;
  56. LPXMLHTABLE entitiesTable;
  57. LPXMLHTABLE declAttTable;
  58. LPXMLVECTOR atts;
  59. LPXMLVECTOR tagstack;
  60. LPXMLVECTOR entities;
  61. LPBUFFEREDISTREAM refReader;
  62. XMLCH *doctypeName, *publicID, *systemID;
  63. const XMLCH *nameStart;
  64. XMLSTRINGBUF charsBuf;
  65. LPXMLPOOL strPool;
  66. struct tagDTD *dtd;
  67. } XMLPARSERRUNTIME, *LPXMLPARSERRUNTIME;
  68. enum tagXMLERRCODE {
  69. ERR_XMLP_MEMORY_ALLOC = 1,
  70. ERR_XMLP_READER_FATAL,
  71. ERR_XMLP_INVALID_TOKEN,
  72. ERR_XMLP_INVALID_NAME,
  73. ERR_XMLP_INVALID_END_TAG,
  74. ERR_XMLP_UNDEF_ENTITY,
  75. ERR_XMLP_WS_NOT_ALLOWED,
  76. ERR_XMLP_WS_REQUIRED,
  77. ERR_XMLP_UNCLOSED_TAG,
  78. ERR_XMLP_EXPECTED_FOUND,
  79. ERR_XMLP_EXPECTED_TOKEN,
  80. ERR_XMLP_MULTIPLE_TOP,
  81. ERR_XMLP_INVALID_AT_TOP,
  82. ERR_XMLP_UNDEF_NSPREFIX,
  83. ERR_XMLP_DUPL_ATTRIBUTE,
  84. ERR_XMLP_ENCODING,
  85. ERR_XMLP_UNSUP_ENCODING,
  86. ERR_XMLP_INVALID_DECL,
  87. ERR_XMLP_INVALID_ATT_VALUE,
  88. ERR_XMLP_ABORT,
  89. ERR_XMLP_ILLEGAL_CHAR,
  90. ERR_XMLP_RECURSIVE_ENTITY_REF,
  91. ERR_XMLP_IO,
  92. ERR_XMLP_SWITCH_ENCODING
  93. };
  94. typedef enum tagXMLERRCODE XMLERRCODE;
  95. enum tagXMLENTITYTYPE {
  96. XML_ENTITY_INT_PARAM = 1,
  97. XML_ENTITY_INT_GEN,
  98. XML_ENTITY_EXT_PARAM,
  99. XML_ENTITY_EXT_GEN,
  100. XML_ENTITY_UNPARSED,
  101. XML_ENTITY_DOCTYPE
  102. };
  103. typedef enum tagXMLENTITYTYPE XMLENTITYTYPE;
  104. #define XMLFLAG_NAMESPACES 0x1 /* http://xml.org/sax/features/namespaces */
  105. #define XMLFLAG_NAMESPACE_PREFIXES 0x2 /* http://xml.org/sax/features/namespace-prefixes */
  106. #define XMLFLAG_EXTERNAL_GENERAL_ENTITIES 0x4 /* http://xml.org/sax/features/external-general-entities */
  107. #define XMLFLAG_PRESERVE_GENERAL_ENTITIES 0x8
  108. #define XMLFLAG_UNDEF_GENERAL_ENTITIES 0x10
  109. #define XMLFLAG_PRESERVE_WS_ATTRIBUTES 0x20
  110. #define XMLFLAG_CONVERT_EOL 0x40
  111. /* for XML_ATTRIBUTEDECL_HANDLER valueDef param: */
  112. #define XMLATTDECL_DEF_FIXED 1
  113. #define XMLATTDECL_DEF_REQUIRED 2
  114. #define XMLATTDECL_DEF_IMPLIED 3
  115. /* for XML_ATTRIBUTEDECL_HANDLER type param: */
  116. #define XMLATTDECL_TYPE_CDATA 1
  117. #define XMLATTDECL_TYPE_ID 2
  118. #define XMLATTDECL_TYPE_IDREF 3
  119. #define XMLATTDECL_TYPE_IDREFS 4
  120. #define XMLATTDECL_TYPE_ENTITY 5
  121. #define XMLATTDECL_TYPE_ENTITIES 6
  122. #define XMLATTDECL_TYPE_NMTOKEN 7
  123. #define XMLATTDECL_TYPE_NMTOKENS 8
  124. #define XMLATTDECL_TYPE_NOTATION 9
  125. #define XMLATTDECL_TYPE_ENUMERATED 10
  126. typedef struct tagXMLENTITY
  127. {
  128. XMLENTITYTYPE type;
  129. int len;
  130. int open;
  131. XMLCH *name;
  132. XMLCH *value;
  133. XMLCH *publicID;
  134. XMLCH *systemID;
  135. XMLCH *notation;
  136. } XMLENTITY, *LPXMLENTITY;
  137. typedef int (*XML_EVENT_HANDLER)(void *UserData);
  138. typedef int (*XML_START_ELEMENT_HANDLER)(void *UserData, const XMLCH *uri,
  139. const XMLCH *localName, const XMLCH *qName,
  140. LPXMLVECTOR atts);
  141. typedef int (*XML_END_ELEMENT_HANDLER)(void *UserData, const XMLCH *uri,
  142. const XMLCH *localName, const XMLCH *qName);
  143. typedef int (*XML_CHARACTERS_HANDLER)(void *UserData, const XMLCH *chars, int cbSize);
  144. typedef int (*XML_PI_HANDLER)(void *UserData, const XMLCH *target, const XMLCH *data);
  145. typedef int (*XML_START_DTD_HANDLER)(void *UserData, const XMLCH *name,
  146. const XMLCH *publicId, const XMLCH *systemId,
  147. int hasInternalSubset);
  148. typedef int (*XML_XMLDECL_HANDLER)(void *UserData, const XMLCH *version,
  149. const XMLCH *encoding, const XMLCH *standalone);
  150. typedef int (*XML_RESOLVE_ENTITY_HANDLER)(void *UserData, LPXMLENTITY entity,
  151. LPBUFFEREDISTREAM reader);
  152. typedef int (*XML_SKIPPED_ENTITY_HANDLER)(void *UserData, const XMLCH *name);
  153. typedef int (*XML_ENTITY_EVENT_HANDLER)(void *UserData, LPXMLENTITY entity);
  154. typedef int (*XML_ATTRIBUTEDECL_HANDLER)(void *UserData, const XMLCH *eName,
  155. const XMLCH *aName, int type, const XMLCH *typeStr, int valueDef,
  156. const XMLCH *def);
  157. typedef int (*XML_ELEMENTDECL_HANDLER)(void *UserData, const XMLCH *name,
  158. void *contentModel);
  159. typedef int (*XML_NOTATIONDECL_HANDLER)(void *UserData, const XMLCH *name,
  160. const XMLCH *publicID, const XMLCH *systemID);
  161. typedef struct tagXMLPARSER
  162. {
  163. LPBUFFEREDISTREAM reader;
  164. LPXMLPARSERRUNTIME prt;
  165. XMLCH *DocumentElement;
  166. XMLCH ErrorString[128];
  167. int ErrorCode;
  168. int ErrorLine;
  169. int ErrorColumn;
  170. void *UserData;
  171. unsigned long XMLFlags;
  172. XML_EVENT_HANDLER startDocumentHandler;
  173. XML_EVENT_HANDLER endDocumentHandler;
  174. XML_EVENT_HANDLER startCDATAHandler;
  175. XML_EVENT_HANDLER endCDATAHandler;
  176. XML_EVENT_HANDLER endDTDHandler;
  177. XML_CHARACTERS_HANDLER charactersHandler;
  178. XML_CHARACTERS_HANDLER ignorableWhitespaceHandler;
  179. XML_CHARACTERS_HANDLER commentHandler;
  180. XML_CHARACTERS_HANDLER defaultHandler;
  181. XML_START_ELEMENT_HANDLER startElementHandler;
  182. XML_END_ELEMENT_HANDLER endElementHandler;
  183. XML_PI_HANDLER processingInstructionHandler;
  184. XML_START_DTD_HANDLER startDTDHandler;
  185. XML_XMLDECL_HANDLER xmlDeclHandler;
  186. XML_SKIPPED_ENTITY_HANDLER skippedEntityHandler;
  187. XML_ENTITY_EVENT_HANDLER startEntityHandler;
  188. XML_ENTITY_EVENT_HANDLER endEntityHandler;
  189. XML_RESOLVE_ENTITY_HANDLER resolveEntityHandler;
  190. XML_RESOLVE_ENTITY_HANDLER externalEntityParsedHandler;
  191. XML_ATTRIBUTEDECL_HANDLER attributeDeclHandler;
  192. XML_ELEMENTDECL_HANDLER elementDeclHandler;
  193. XML_ENTITY_EVENT_HANDLER entityDeclHandler;
  194. XML_NOTATIONDECL_HANDLER notationDeclHandler;
  195. /*XML_ERROR_HANDLER */ void (*errorHandler)(struct tagXMLPARSER *parser);
  196. } XMLPARSER, *LPXMLPARSER;
  197. typedef void (*XML_ERROR_HANDLER)(LPXMLPARSER parser);
  198. #ifndef XMLAPI
  199. #define XMLAPI
  200. #endif
  201. #define XML_OK 0
  202. #define XML_ABORT 1
  203. #define _XMLParser_SetFlag(parser,flag,valBool) \
  204. ((valBool) ? (((LPXMLPARSER)parser)->XMLFlags |= (flag)) : \
  205. (((LPXMLPARSER)parser)->XMLFlags &= ~(flag)) )
  206. #define _XMLParser_GetFlag(parser,flag) \
  207. ((((LPXMLPARSER)parser)->XMLFlags & (flag)) == (flag))
  208. #define _XMLParser_AttIsDefaulted(att) (!(att->nameBuf.str))
  209. LPXMLPARSER XMLAPI XMLParser_Create(LPXMLPARSER *parser);
  210. int XMLAPI XMLParser_Parse(LPXMLPARSER parser, LPFNINPUTSRC inputSrc, void *inputData, const XMLCH *encoding);
  211. void XMLAPI XMLParser_Free(LPXMLPARSER parser);
  212. LPXMLRUNTIMEATT XMLAPI XMLParser_GetNamedItem(LPXMLPARSER parser, const XMLCH *name);
  213. XMLCH XMLAPI *XMLParser_GetSystemID(LPXMLPARSER parser);
  214. XMLCH XMLAPI *XMLParser_GetPublicID(LPXMLPARSER parser);
  215. XMLCH XMLAPI *XMLParser_GetPrefixMapping(LPXMLPARSER parser, const XMLCH *prefix);
  216. int XMLAPI XMLParser_GetCurrentLine(LPXMLPARSER parser);
  217. int XMLAPI XMLParser_GetCurrentColumn(LPXMLPARSER parser);
  218. LPXMLENTITY XMLAPI XMLParser_GetCurrentEntity(LPXMLPARSER parser);
  219. XMLCH XMLAPI *XMLParser_GetVersionString();
  220. int XMLAPI XMLNormalizeBuf(XMLCH *buf, int len);
  221. #ifdef __cplusplus
  222. }
  223. #endif /* __cplusplus */
  224. #endif /* PARSIFAL__H */