Home | History | Annotate | Download | only in libraries
      1 #ifndef LIBRARIES_EXPAT_H
      2 #define LIBRARIES_EXPAT_H
      3 
      4 /*
      5 ** Copyright (c) 2001-2007 Expat maintainers.
      6 **
      7 ** Permission is hereby granted, free of charge, to any person obtaining
      8 ** a copy of this software and associated documentation files (the
      9 ** "Software"), to deal in the Software without restriction, including
     10 ** without limitation the rights to use, copy, modify, merge, publish,
     11 ** distribute, sublicense, and/or sell copies of the Software, and to
     12 ** permit persons to whom the Software is furnished to do so, subject to
     13 ** the following conditions:
     14 **
     15 ** The above copyright notice and this permission notice shall be included
     16 ** in all copies or substantial portions of the Software.
     17 **
     18 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     19 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     21 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
     22 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     23 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     24 ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     25 */
     26 
     27 
     28 /****************************************************************************/
     29 
     30 #ifdef __cplusplus
     31 extern "C" {
     32 #endif
     33 
     34 #ifdef __GNUC__
     35    #ifdef __PPC__
     36     #pragma pack(2)
     37    #endif
     38 #elif defined(__VBCC__)
     39    #pragma amiga-align
     40 #endif
     41 
     42 /****************************************************************************/
     43 
     44 
     45 #include <stdlib.h>
     46 
     47 #ifndef XMLCALL
     48 #define XMLCALL
     49 #endif
     50 
     51 typedef char XML_Char;
     52 typedef char XML_LChar;
     53 typedef long XML_Index;
     54 typedef unsigned long XML_Size;
     55 
     56 struct XML_ParserStruct;
     57 typedef struct XML_ParserStruct *XML_Parser;
     58 
     59 typedef unsigned char XML_Bool;
     60 #define XML_TRUE   ((XML_Bool) 1)
     61 #define XML_FALSE  ((XML_Bool) 0)
     62 
     63 enum XML_Status {
     64   XML_STATUS_ERROR = 0,
     65 #define XML_STATUS_ERROR XML_STATUS_ERROR
     66   XML_STATUS_OK = 1,
     67 #define XML_STATUS_OK XML_STATUS_OK
     68   XML_STATUS_SUSPENDED = 2,
     69 #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
     70 };
     71 
     72 enum XML_Error {
     73   XML_ERROR_NONE,
     74   XML_ERROR_NO_MEMORY,
     75   XML_ERROR_SYNTAX,
     76   XML_ERROR_NO_ELEMENTS,
     77   XML_ERROR_INVALID_TOKEN,
     78   XML_ERROR_UNCLOSED_TOKEN,
     79   XML_ERROR_PARTIAL_CHAR,
     80   XML_ERROR_TAG_MISMATCH,
     81   XML_ERROR_DUPLICATE_ATTRIBUTE,
     82   XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
     83   XML_ERROR_PARAM_ENTITY_REF,
     84   XML_ERROR_UNDEFINED_ENTITY,
     85   XML_ERROR_RECURSIVE_ENTITY_REF,
     86   XML_ERROR_ASYNC_ENTITY,
     87   XML_ERROR_BAD_CHAR_REF,
     88   XML_ERROR_BINARY_ENTITY_REF,
     89   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
     90   XML_ERROR_MISPLACED_XML_PI,
     91   XML_ERROR_UNKNOWN_ENCODING,
     92   XML_ERROR_INCORRECT_ENCODING,
     93   XML_ERROR_UNCLOSED_CDATA_SECTION,
     94   XML_ERROR_EXTERNAL_ENTITY_HANDLING,
     95   XML_ERROR_NOT_STANDALONE,
     96   XML_ERROR_UNEXPECTED_STATE,
     97   XML_ERROR_ENTITY_DECLARED_IN_PE,
     98   XML_ERROR_FEATURE_REQUIRES_XML_DTD,
     99   XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
    100   XML_ERROR_UNBOUND_PREFIX,
    101   XML_ERROR_UNDECLARING_PREFIX,
    102   XML_ERROR_INCOMPLETE_PE,
    103   XML_ERROR_XML_DECL,
    104   XML_ERROR_TEXT_DECL,
    105   XML_ERROR_PUBLICID,
    106   XML_ERROR_SUSPENDED,
    107   XML_ERROR_NOT_SUSPENDED,
    108   XML_ERROR_ABORTED,
    109   XML_ERROR_FINISHED,
    110   XML_ERROR_SUSPEND_PE,
    111   XML_ERROR_RESERVED_PREFIX_XML,
    112   XML_ERROR_RESERVED_PREFIX_XMLNS,
    113   XML_ERROR_RESERVED_NAMESPACE_URI
    114 };
    115 
    116 enum XML_Content_Type {
    117   XML_CTYPE_EMPTY = 1,
    118   XML_CTYPE_ANY,
    119   XML_CTYPE_MIXED,
    120   XML_CTYPE_NAME,
    121   XML_CTYPE_CHOICE,
    122   XML_CTYPE_SEQ
    123 };
    124 
    125 enum XML_Content_Quant {
    126   XML_CQUANT_NONE,
    127   XML_CQUANT_OPT,
    128   XML_CQUANT_REP,
    129   XML_CQUANT_PLUS
    130 };
    131 
    132 typedef struct XML_cp XML_Content;
    133 
    134 struct XML_cp {
    135   enum XML_Content_Type         type;
    136   enum XML_Content_Quant        quant;
    137   XML_Char *                    name;
    138   unsigned int                  numchildren;
    139   XML_Content *                 children;
    140 };
    141 
    142 
    143 typedef void (*XML_ElementDeclHandler) (void *userData,
    144                                         const XML_Char *name,
    145                                         XML_Content *model);
    146 
    147 void
    148 XML_SetElementDeclHandler(XML_Parser parser,
    149                           XML_ElementDeclHandler eldecl);
    150 
    151 typedef void (*XML_AttlistDeclHandler) (
    152                                     void            *userData,
    153                                     const XML_Char  *elname,
    154                                     const XML_Char  *attname,
    155                                     const XML_Char  *att_type,
    156                                     const XML_Char  *dflt,
    157                                     int              isrequired);
    158 
    159 void
    160 XML_SetAttlistDeclHandler(XML_Parser parser,
    161                           XML_AttlistDeclHandler attdecl);
    162 
    163 typedef void (*XML_XmlDeclHandler) (void *userData,
    164                                     const XML_Char *version,
    165                                     const XML_Char *encoding,
    166                                     int             standalone);
    167 
    168 void
    169 XML_SetXmlDeclHandler(XML_Parser parser,
    170                       XML_XmlDeclHandler xmldecl);
    171 
    172 
    173 typedef struct {
    174   void *(*malloc_fcn)(size_t size);
    175   void *(*realloc_fcn)(void *ptr, size_t size);
    176   void (*free_fcn)(void *ptr);
    177 } XML_Memory_Handling_Suite;
    178 
    179 XML_Parser
    180 XML_ParserCreate(const XML_Char *encoding);
    181 
    182 XML_Parser
    183 XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
    184 
    185 
    186 XML_Parser
    187 XML_ParserCreate_MM(const XML_Char *encoding,
    188                     const XML_Memory_Handling_Suite *memsuite,
    189                     const XML_Char *namespaceSeparator);
    190 
    191 XML_Bool
    192 XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
    193 
    194 typedef void (*XML_StartElementHandler) (void *userData,
    195                                          const XML_Char *name,
    196                                          const XML_Char **atts);
    197 
    198 typedef void (*XML_EndElementHandler) (void *userData,
    199                                        const XML_Char *name);
    200 
    201 
    202 typedef void (*XML_CharacterDataHandler) (void *userData,
    203                                           const XML_Char *s,
    204                                           int len);
    205 
    206 typedef void (*XML_ProcessingInstructionHandler) (
    207                                                 void *userData,
    208                                                 const XML_Char *target,
    209                                                 const XML_Char *data);
    210 
    211 typedef void (*XML_CommentHandler) (void *userData,
    212                                     const XML_Char *data);
    213 
    214 typedef void (*XML_StartCdataSectionHandler) (void *userData);
    215 typedef void (*XML_EndCdataSectionHandler) (void *userData);
    216 
    217 typedef void (*XML_DefaultHandler) (void *userData,
    218                                     const XML_Char *s,
    219                                     int len);
    220 
    221 typedef void (*XML_StartDoctypeDeclHandler) (
    222                                             void *userData,
    223                                             const XML_Char *doctypeName,
    224                                             const XML_Char *sysid,
    225                                             const XML_Char *pubid,
    226                                             int has_internal_subset);
    227 
    228 typedef void (*XML_EndDoctypeDeclHandler)(void *userData);
    229 
    230 typedef void (*XML_EntityDeclHandler) (
    231                               void *userData,
    232                               const XML_Char *entityName,
    233                               int is_parameter_entity,
    234                               const XML_Char *value,
    235                               int value_length,
    236                               const XML_Char *base,
    237                               const XML_Char *systemId,
    238                               const XML_Char *publicId,
    239                               const XML_Char *notationName);
    240 
    241 void
    242 XML_SetEntityDeclHandler(XML_Parser parser,
    243                          XML_EntityDeclHandler handler);
    244 
    245 typedef void (*XML_UnparsedEntityDeclHandler) (
    246                                     void *userData,
    247                                     const XML_Char *entityName,
    248                                     const XML_Char *base,
    249                                     const XML_Char *systemId,
    250                                     const XML_Char *publicId,
    251                                     const XML_Char *notationName);
    252 
    253 typedef void (*XML_NotationDeclHandler) (
    254                                     void *userData,
    255                                     const XML_Char *notationName,
    256                                     const XML_Char *base,
    257                                     const XML_Char *systemId,
    258                                     const XML_Char *publicId);
    259 
    260 typedef void (*XML_StartNamespaceDeclHandler) (
    261                                     void *userData,
    262                                     const XML_Char *prefix,
    263                                     const XML_Char *uri);
    264 
    265 typedef void (*XML_EndNamespaceDeclHandler) (
    266                                     void *userData,
    267                                     const XML_Char *prefix);
    268 
    269 typedef int (*XML_NotStandaloneHandler) (void *userData);
    270 
    271 typedef int (*XML_ExternalEntityRefHandler) (
    272                                     XML_Parser parser,
    273                                     const XML_Char *context,
    274                                     const XML_Char *base,
    275                                     const XML_Char *systemId,
    276                                     const XML_Char *publicId);
    277 
    278 typedef void (*XML_SkippedEntityHandler) (
    279                                     void *userData,
    280                                     const XML_Char *entityName,
    281                                     int is_parameter_entity);
    282 
    283 typedef struct {
    284   int map[256];
    285   void *data;
    286   int (*convert)(void *data, const char *s);
    287   void (*release)(void *data);
    288 } XML_Encoding;
    289 
    290 typedef int (*XML_UnknownEncodingHandler) (
    291                                     void *encodingHandlerData,
    292                                     const XML_Char *name,
    293                                     XML_Encoding *info);
    294 
    295 void
    296 XML_SetElementHandler(XML_Parser parser,
    297                       XML_StartElementHandler start,
    298                       XML_EndElementHandler end);
    299 
    300 void
    301 XML_SetStartElementHandler(XML_Parser parser,
    302                            XML_StartElementHandler handler);
    303 
    304 void
    305 XML_SetEndElementHandler(XML_Parser parser,
    306                          XML_EndElementHandler handler);
    307 
    308 void
    309 XML_SetCharacterDataHandler(XML_Parser parser,
    310                             XML_CharacterDataHandler handler);
    311 
    312 void
    313 XML_SetProcessingInstructionHandler(XML_Parser parser,
    314                                     XML_ProcessingInstructionHandler handler);
    315 void
    316 XML_SetCommentHandler(XML_Parser parser,
    317                       XML_CommentHandler handler);
    318 
    319 void
    320 XML_SetCdataSectionHandler(XML_Parser parser,
    321                            XML_StartCdataSectionHandler start,
    322                            XML_EndCdataSectionHandler end);
    323 
    324 void
    325 XML_SetStartCdataSectionHandler(XML_Parser parser,
    326                                 XML_StartCdataSectionHandler start);
    327 
    328 void
    329 XML_SetEndCdataSectionHandler(XML_Parser parser,
    330                               XML_EndCdataSectionHandler end);
    331 
    332 void
    333 XML_SetDefaultHandler(XML_Parser parser,
    334                       XML_DefaultHandler handler);
    335 
    336 void
    337 XML_SetDefaultHandlerExpand(XML_Parser parser,
    338                             XML_DefaultHandler handler);
    339 
    340 void
    341 XML_SetDoctypeDeclHandler(XML_Parser parser,
    342                           XML_StartDoctypeDeclHandler start,
    343                           XML_EndDoctypeDeclHandler end);
    344 
    345 void
    346 XML_SetStartDoctypeDeclHandler(XML_Parser parser,
    347                                XML_StartDoctypeDeclHandler start);
    348 
    349 void
    350 XML_SetEndDoctypeDeclHandler(XML_Parser parser,
    351                              XML_EndDoctypeDeclHandler end);
    352 
    353 void
    354 XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
    355                                  XML_UnparsedEntityDeclHandler handler);
    356 
    357 void
    358 XML_SetNotationDeclHandler(XML_Parser parser,
    359                            XML_NotationDeclHandler handler);
    360 
    361 void
    362 XML_SetNamespaceDeclHandler(XML_Parser parser,
    363                             XML_StartNamespaceDeclHandler start,
    364                             XML_EndNamespaceDeclHandler end);
    365 
    366 void
    367 XML_SetStartNamespaceDeclHandler(XML_Parser parser,
    368                                  XML_StartNamespaceDeclHandler start);
    369 
    370 void
    371 XML_SetEndNamespaceDeclHandler(XML_Parser parser,
    372                                XML_EndNamespaceDeclHandler end);
    373 
    374 void
    375 XML_SetNotStandaloneHandler(XML_Parser parser,
    376                             XML_NotStandaloneHandler handler);
    377 
    378 void
    379 XML_SetExternalEntityRefHandler(XML_Parser parser,
    380                                 XML_ExternalEntityRefHandler handler);
    381 
    382 void
    383 XML_SetExternalEntityRefHandlerArg(XML_Parser parser,
    384                                    void *arg);
    385 
    386 void
    387 XML_SetSkippedEntityHandler(XML_Parser parser,
    388                             XML_SkippedEntityHandler handler);
    389 
    390 void
    391 XML_SetUnknownEncodingHandler(XML_Parser parser,
    392                               XML_UnknownEncodingHandler handler,
    393                               void *encodingHandlerData);
    394 
    395 void
    396 XML_DefaultCurrent(XML_Parser parser);
    397 
    398 void
    399 XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
    400 
    401 void
    402 XML_SetUserData(XML_Parser parser, void *userData);
    403 
    404 #define XML_GetUserData(parser) (*(void **)(parser))
    405 
    406 enum XML_Status
    407 XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
    408 
    409 void
    410 XML_UseParserAsHandlerArg(XML_Parser parser);
    411 
    412 enum XML_Error
    413 XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
    414 
    415 
    416 enum XML_Status
    417 XML_SetBase(XML_Parser parser, const XML_Char *base);
    418 
    419 const XML_Char *
    420 XML_GetBase(XML_Parser parser);
    421 
    422 int
    423 XML_GetSpecifiedAttributeCount(XML_Parser parser);
    424 
    425 int
    426 XML_GetIdAttributeIndex(XML_Parser parser);
    427 
    428 enum XML_Status
    429 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
    430 
    431 void *
    432 XML_GetBuffer(XML_Parser parser, int len);
    433 
    434 enum XML_Status
    435 XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
    436 
    437 enum XML_Status
    438 XML_StopParser(XML_Parser parser, XML_Bool resumable);
    439 
    440 enum XML_Status
    441 XML_ResumeParser(XML_Parser parser);
    442 
    443 enum XML_Parsing {
    444   XML_INITIALIZED,
    445   XML_PARSING,
    446   XML_FINISHED,
    447   XML_SUSPENDED
    448 };
    449 
    450 typedef struct {
    451   enum XML_Parsing parsing;
    452   XML_Bool finalBuffer;
    453 } XML_ParsingStatus;
    454 
    455 void
    456 XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
    457 
    458 XML_Parser
    459 XML_ExternalEntityParserCreate(XML_Parser parser,
    460                                const XML_Char *context,
    461                                const XML_Char *encoding);
    462 
    463 enum XML_ParamEntityParsing {
    464   XML_PARAM_ENTITY_PARSING_NEVER,
    465   XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
    466   XML_PARAM_ENTITY_PARSING_ALWAYS
    467 };
    468 
    469 int
    470 XML_SetParamEntityParsing(XML_Parser parser,
    471                           enum XML_ParamEntityParsing parsing);
    472 
    473 enum XML_Error
    474 XML_GetErrorCode(XML_Parser parser);
    475 
    476 int XML_GetCurrentLineNumber(XML_Parser parser);
    477 int XML_GetCurrentColumnNumber(XML_Parser parser);
    478 long XML_GetCurrentByteIndex(XML_Parser parser);
    479 
    480 int
    481 XML_GetCurrentByteCount(XML_Parser parser);
    482 
    483 const char *
    484 XML_GetInputContext(XML_Parser parser,
    485                     int *offset,
    486                     int *size);
    487 
    488 #define XML_GetErrorLineNumber   XML_GetCurrentLineNumber
    489 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
    490 #define XML_GetErrorByteIndex    XML_GetCurrentByteIndex
    491 
    492 void
    493 XML_FreeContentModel(XML_Parser parser, XML_Content *model);
    494 
    495 void *
    496 XML_MemMalloc(XML_Parser parser, size_t size);
    497 
    498 void *
    499 XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
    500 
    501 void
    502 XML_MemFree(XML_Parser parser, void *ptr);
    503 
    504 void
    505 XML_ParserFree(XML_Parser parser);
    506 
    507 const XML_LChar *
    508 XML_ErrorString(enum XML_Error code);
    509 
    510 const XML_LChar *
    511 XML_ExpatVersion(void);
    512 
    513 typedef struct {
    514   int major;
    515   int minor;
    516   int micro;
    517 } XML_Expat_Version;
    518 
    519 XML_Expat_Version
    520 XML_ExpatVersionInfo(void);
    521 
    522 enum XML_FeatureEnum {
    523   XML_FEATURE_END = 0,
    524   XML_FEATURE_UNICODE,
    525   XML_FEATURE_UNICODE_WCHAR_T,
    526   XML_FEATURE_DTD,
    527   XML_FEATURE_CONTEXT_BYTES,
    528   XML_FEATURE_MIN_SIZE,
    529   XML_FEATURE_SIZEOF_XML_CHAR,
    530   XML_FEATURE_SIZEOF_XML_LCHAR,
    531   XML_FEATURE_NS,
    532   XML_FEATURE_LARGE_SIZE
    533 };
    534 
    535 typedef struct {
    536   enum XML_FeatureEnum  feature;
    537   const XML_LChar       *name;
    538   long int              value;
    539 } XML_Feature;
    540 
    541 const XML_Feature *
    542 XML_GetFeatureList(void);
    543 
    544 
    545 #define XML_MAJOR_VERSION 2
    546 #define XML_MINOR_VERSION 0
    547 #define XML_MICRO_VERSION 1
    548 
    549 
    550 /****************************************************************************/
    551 
    552 #ifdef __GNUC__
    553    #ifdef __PPC__
    554     #pragma pack()
    555    #endif
    556 #elif defined(__VBCC__)
    557    #pragma default-align
    558 #endif
    559 
    560 #ifdef __cplusplus
    561 }
    562 #endif
    563 
    564 /****************************************************************************/
    565 
    566 #endif  /* EXPAT_EXPAT_H */
    567