Back to index

lightning-sunbird  0.9+nobinonly
expat.h
Go to the documentation of this file.
00001 /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
00002    See the file COPYING for copying permission.
00003 */
00004 
00005 #ifndef XmlParse_INCLUDED
00006 #define XmlParse_INCLUDED 1
00007 
00008 #ifdef __VMS
00009 /*      0        1         2         3      0        1         2         3
00010         1234567890123456789012345678901     1234567890123456789012345678901 */
00011 #define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler
00012 #define XML_SetUnparsedEntityDeclHandler    XML_SetUnparsedEntDeclHandler
00013 #define XML_SetStartNamespaceDeclHandler    XML_SetStartNamespcDeclHandler
00014 #define XML_SetExternalEntityRefHandlerArg  XML_SetExternalEntRefHandlerArg
00015 #endif
00016 
00017 #include <stdlib.h>
00018 
00019 #if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__)
00020 #define XML_USE_MSC_EXTENSIONS 1
00021 #endif
00022 
00023 /* Expat tries very hard to make the API boundary very specifically
00024    defined.  There are two macros defined to control this boundary;
00025    each of these can be defined before including this header to
00026    achieve some different behavior, but doing so it not recommended or
00027    tested frequently.
00028 
00029    XMLCALL    - The calling convention to use for all calls across the
00030                 "library boundary."  This will default to cdecl, and
00031                 try really hard to tell the compiler that's what we
00032                 want.
00033 
00034    XMLIMPORT  - Whatever magic is needed to note that a function is
00035                 to be imported from a dynamically loaded library
00036                 (.dll, .so, or .sl, depending on your platform).
00037 
00038    The XMLCALL macro was added in Expat 1.95.7.  The only one which is
00039    expected to be directly useful in client code is XMLCALL.
00040 
00041    Note that on at least some Unix versions, the Expat library must be
00042    compiled with the cdecl calling convention as the default since
00043    system headers may assume the cdecl convention.
00044 */
00045 #ifndef XMLCALL
00046 #if defined(XML_USE_MSC_EXTENSIONS)
00047 #define XMLCALL __cdecl
00048 #elif defined(__GNUC__)
00049 #define XMLCALL __attribute__((cdecl))
00050 #else
00051 /* For any platform which uses this definition and supports more than
00052    one calling convention, we need to extend this definition to
00053    declare the convention used on that platform, if it's possible to
00054    do so.
00055 
00056    If this is the case for your platform, please file a bug report
00057    with information on how to identify your platform via the C
00058    pre-processor and how to specify the same calling convention as the
00059    platform's malloc() implementation.
00060 */
00061 #define XMLCALL
00062 #endif
00063 #endif  /* not defined XMLCALL */
00064 
00065 
00066 #if !defined(XML_STATIC) && !defined(XMLIMPORT)
00067 #ifndef XML_BUILDING_EXPAT
00068 /* using Expat from an application */
00069 
00070 #ifdef XML_USE_MSC_EXTENSIONS
00071 #define XMLIMPORT __declspec(dllimport)
00072 #endif
00073 
00074 #endif
00075 #endif  /* not defined XML_STATIC */
00076 
00077 /* If we didn't define it above, define it away: */
00078 #ifndef XMLIMPORT
00079 #define XMLIMPORT
00080 #endif
00081 
00082 
00083 #define XMLPARSEAPI(type) XMLIMPORT type XMLCALL
00084 
00085 #ifdef __cplusplus
00086 extern "C" {
00087 #endif
00088 
00089 #ifdef XML_UNICODE_WCHAR_T
00090 #define XML_UNICODE
00091 #endif
00092 
00093 struct XML_ParserStruct;
00094 typedef struct XML_ParserStruct *XML_Parser;
00095 
00096 /* BEGIN MOZILLA CHANGE (typedef XML_Char to PRUnichar) */
00097 #if 0
00098 
00099 #ifdef XML_UNICODE     /* Information is UTF-16 encoded. */
00100 #ifdef XML_UNICODE_WCHAR_T
00101 typedef wchar_t XML_Char;
00102 typedef wchar_t XML_LChar;
00103 #else
00104 typedef unsigned short XML_Char;
00105 typedef char XML_LChar;
00106 #endif /* XML_UNICODE_WCHAR_T */
00107 #else                  /* Information is UTF-8 encoded. */
00108 typedef char XML_Char;
00109 typedef char XML_LChar;
00110 #endif /* XML_UNICODE */
00111 
00112 #endif
00113 /* END MOZILLA CHANGE */
00114 
00115 /* Should this be defined using stdbool.h when C99 is available? */
00116 typedef unsigned char XML_Bool;
00117 #define XML_TRUE   ((XML_Bool) 1)
00118 #define XML_FALSE  ((XML_Bool) 0)
00119 
00120 /* The XML_Status enum gives the possible return values for several
00121    API functions.  The preprocessor #defines are included so this
00122    stanza can be added to code that still needs to support older
00123    versions of Expat 1.95.x:
00124 
00125    #ifndef XML_STATUS_OK
00126    #define XML_STATUS_OK    1
00127    #define XML_STATUS_ERROR 0
00128    #endif
00129 
00130    Otherwise, the #define hackery is quite ugly and would have been
00131    dropped.
00132 */
00133 enum XML_Status {
00134   XML_STATUS_ERROR = 0,
00135 #define XML_STATUS_ERROR XML_STATUS_ERROR
00136   XML_STATUS_OK = 1
00137 #define XML_STATUS_OK XML_STATUS_OK
00138 };
00139 
00140 enum XML_Error {
00141   XML_ERROR_NONE,
00142   XML_ERROR_NO_MEMORY,
00143   XML_ERROR_SYNTAX,
00144   XML_ERROR_NO_ELEMENTS,
00145   XML_ERROR_INVALID_TOKEN,
00146   XML_ERROR_UNCLOSED_TOKEN,
00147   XML_ERROR_PARTIAL_CHAR,
00148   XML_ERROR_TAG_MISMATCH,
00149   XML_ERROR_DUPLICATE_ATTRIBUTE,
00150   XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
00151   XML_ERROR_PARAM_ENTITY_REF,
00152   XML_ERROR_UNDEFINED_ENTITY,
00153   XML_ERROR_RECURSIVE_ENTITY_REF,
00154   XML_ERROR_ASYNC_ENTITY,
00155   XML_ERROR_BAD_CHAR_REF,
00156   XML_ERROR_BINARY_ENTITY_REF,
00157   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
00158   XML_ERROR_MISPLACED_XML_PI,
00159   XML_ERROR_UNKNOWN_ENCODING,
00160   XML_ERROR_INCORRECT_ENCODING,
00161   XML_ERROR_UNCLOSED_CDATA_SECTION,
00162   XML_ERROR_EXTERNAL_ENTITY_HANDLING,
00163   XML_ERROR_NOT_STANDALONE,
00164   XML_ERROR_UNEXPECTED_STATE,
00165   XML_ERROR_ENTITY_DECLARED_IN_PE,
00166   XML_ERROR_FEATURE_REQUIRES_XML_DTD,
00167   XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
00168   XML_ERROR_UNBOUND_PREFIX
00169 /* BEGIN MOZILLA CHANGE (blocking parser) */
00170   , XML_ERROR_SUSPENDED,
00171 /* END MOZILLA CHANGE */
00172 /* BEGIN MOZILLA CHANGE (backport of bug fix from Expat trunk) */
00173   XML_ERROR_RESERVED_PREFIX_XML,
00174   XML_ERROR_RESERVED_PREFIX_XMLNS,
00175   XML_ERROR_RESERVED_NAMESPACE_URI
00176 /* END MOZILLA CHANGE */
00177 };
00178 
00179 enum XML_Content_Type {
00180   XML_CTYPE_EMPTY = 1,
00181   XML_CTYPE_ANY,
00182   XML_CTYPE_MIXED,
00183   XML_CTYPE_NAME,
00184   XML_CTYPE_CHOICE,
00185   XML_CTYPE_SEQ
00186 };
00187 
00188 enum XML_Content_Quant {
00189   XML_CQUANT_NONE,
00190   XML_CQUANT_OPT,
00191   XML_CQUANT_REP,
00192   XML_CQUANT_PLUS
00193 };
00194 
00195 /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
00196    XML_CQUANT_NONE, and the other fields will be zero or NULL.
00197    If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
00198    numchildren will contain number of elements that may be mixed in
00199    and children point to an array of XML_Content cells that will be
00200    all of XML_CTYPE_NAME type with no quantification.
00201 
00202    If type == XML_CTYPE_NAME, then the name points to the name, and
00203    the numchildren field will be zero and children will be NULL. The
00204    quant fields indicates any quantifiers placed on the name.
00205 
00206    CHOICE and SEQ will have name NULL, the number of children in
00207    numchildren and children will point, recursively, to an array
00208    of XML_Content cells.
00209 
00210    The EMPTY, ANY, and MIXED types will only occur at top level.
00211 */
00212 
00213 typedef struct XML_cp XML_Content;
00214 
00215 struct XML_cp {
00216   enum XML_Content_Type         type;
00217   enum XML_Content_Quant        quant;
00218   XML_Char *                    name;
00219   unsigned int                  numchildren;
00220   XML_Content *                 children;
00221 };
00222 
00223 
00224 /* This is called for an element declaration. See above for
00225    description of the model argument. It's the caller's responsibility
00226    to free model when finished with it.
00227 */
00228 typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
00229                                                 const XML_Char *name,
00230                                                 XML_Content *model);
00231 
00232 XMLPARSEAPI(void)
00233 XML_SetElementDeclHandler(XML_Parser parser,
00234                           XML_ElementDeclHandler eldecl);
00235 
00236 /* The Attlist declaration handler is called for *each* attribute. So
00237    a single Attlist declaration with multiple attributes declared will
00238    generate multiple calls to this handler. The "default" parameter
00239    may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
00240    keyword. The "isrequired" parameter will be true and the default
00241    value will be NULL in the case of "#REQUIRED". If "isrequired" is
00242    true and default is non-NULL, then this is a "#FIXED" default.
00243 */
00244 typedef void (XMLCALL *XML_AttlistDeclHandler) (
00245                                     void            *userData,
00246                                     const XML_Char  *elname,
00247                                     const XML_Char  *attname,
00248                                     const XML_Char  *att_type,
00249                                     const XML_Char  *dflt,
00250                                     int              isrequired);
00251 
00252 XMLPARSEAPI(void)
00253 XML_SetAttlistDeclHandler(XML_Parser parser,
00254                           XML_AttlistDeclHandler attdecl);
00255 
00256 /* The XML declaration handler is called for *both* XML declarations
00257    and text declarations. The way to distinguish is that the version
00258    parameter will be NULL for text declarations. The encoding
00259    parameter may be NULL for XML declarations. The standalone
00260    parameter will be -1, 0, or 1 indicating respectively that there
00261    was no standalone parameter in the declaration, that it was given
00262    as no, or that it was given as yes.
00263 */
00264 typedef void (XMLCALL *XML_XmlDeclHandler) (void           *userData,
00265                                             const XML_Char *version,
00266                                             const XML_Char *encoding,
00267                                             int             standalone);
00268 
00269 XMLPARSEAPI(void)
00270 XML_SetXmlDeclHandler(XML_Parser parser,
00271                       XML_XmlDeclHandler xmldecl);
00272 
00273 
00274 typedef struct {
00275   void *(XMLCALL *malloc_fcn)(size_t size);
00276   void *(XMLCALL *realloc_fcn)(void *ptr, size_t size);
00277   void (XMLCALL *free_fcn)(void *ptr);
00278 } XML_Memory_Handling_Suite;
00279 
00280 /* Constructs a new parser; encoding is the encoding specified by the
00281    external protocol or NULL if there is none specified.
00282 */
00283 XMLPARSEAPI(XML_Parser)
00284 XML_ParserCreate(const XML_Char *encoding);
00285 
00286 /* Constructs a new parser and namespace processor.  Element type
00287    names and attribute names that belong to a namespace will be
00288    expanded; unprefixed attribute names are never expanded; unprefixed
00289    element type names are expanded only if there is a default
00290    namespace. The expanded name is the concatenation of the namespace
00291    URI, the namespace separator character, and the local part of the
00292    name.  If the namespace separator is '\0' then the namespace URI
00293    and the local part will be concatenated without any separator.
00294    When a namespace is not declared, the name and prefix will be
00295    passed through without expansion.
00296 */
00297 XMLPARSEAPI(XML_Parser)
00298 XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
00299 
00300 
00301 /* Constructs a new parser using the memory management suite referred to
00302    by memsuite. If memsuite is NULL, then use the standard library memory
00303    suite. If namespaceSeparator is non-NULL it creates a parser with
00304    namespace processing as described above. The character pointed at
00305    will serve as the namespace separator.
00306 
00307    All further memory operations used for the created parser will come from
00308    the given suite.
00309 */
00310 XMLPARSEAPI(XML_Parser)
00311 XML_ParserCreate_MM(const XML_Char *encoding,
00312                     const XML_Memory_Handling_Suite *memsuite,
00313                     const XML_Char *namespaceSeparator);
00314 
00315 /* Prepare a parser object to be re-used.  This is particularly
00316    valuable when memory allocation overhead is disproportionatly high,
00317    such as when a large number of small documnents need to be parsed.
00318    All handlers are cleared from the parser, except for the
00319    unknownEncodingHandler. The parser's external state is re-initialized
00320    except for the values of ns and ns_triplets.
00321 
00322    Added in Expat 1.95.3.
00323 */
00324 XMLPARSEAPI(XML_Bool)
00325 XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
00326 
00327 /* atts is array of name/value pairs, terminated by 0;
00328    names and values are 0 terminated.
00329 */
00330 typedef void (XMLCALL *XML_StartElementHandler) (void *userData,
00331                                                  const XML_Char *name,
00332                                                  const XML_Char **atts);
00333 
00334 typedef void (XMLCALL *XML_EndElementHandler) (void *userData,
00335                                                const XML_Char *name);
00336 
00337 
00338 /* s is not 0 terminated. */
00339 typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData,
00340                                                   const XML_Char *s,
00341                                                   int len);
00342 
00343 /* target and data are 0 terminated */
00344 typedef void (XMLCALL *XML_ProcessingInstructionHandler) (
00345                                                 void *userData,
00346                                                 const XML_Char *target,
00347                                                 const XML_Char *data);
00348 
00349 /* data is 0 terminated */
00350 typedef void (XMLCALL *XML_CommentHandler) (void *userData,
00351                                             const XML_Char *data);
00352 
00353 typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData);
00354 typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData);
00355 
00356 /* This is called for any characters in the XML document for which
00357    there is no applicable handler.  This includes both characters that
00358    are part of markup which is of a kind that is not reported
00359    (comments, markup declarations), or characters that are part of a
00360    construct which could be reported but for which no handler has been
00361    supplied. The characters are passed exactly as they were in the XML
00362    document except that they will be encoded in UTF-8 or UTF-16.
00363    Line boundaries are not normalized. Note that a byte order mark
00364    character is not passed to the default handler. There are no
00365    guarantees about how characters are divided between calls to the
00366    default handler: for example, a comment might be split between
00367    multiple calls.
00368 */
00369 typedef void (XMLCALL *XML_DefaultHandler) (void *userData,
00370                                             const XML_Char *s,
00371                                             int len);
00372 
00373 /* This is called for the start of the DOCTYPE declaration, before
00374    any DTD or internal subset is parsed.
00375 */
00376 typedef void (XMLCALL *XML_StartDoctypeDeclHandler) (
00377                                             void *userData,
00378                                             const XML_Char *doctypeName,
00379                                             const XML_Char *sysid,
00380                                             const XML_Char *pubid,
00381                                             int has_internal_subset);
00382 
00383 /* This is called for the start of the DOCTYPE declaration when the
00384    closing > is encountered, but after processing any external
00385    subset.
00386 */
00387 typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
00388 
00389 /* This is called for entity declarations. The is_parameter_entity
00390    argument will be non-zero if the entity is a parameter entity, zero
00391    otherwise.
00392 
00393    For internal entities (<!ENTITY foo "bar">), value will
00394    be non-NULL and systemId, publicID, and notationName will be NULL.
00395    The value string is NOT nul-terminated; the length is provided in
00396    the value_length argument. Since it is legal to have zero-length
00397    values, do not use this argument to test for internal entities.
00398 
00399    For external entities, value will be NULL and systemId will be
00400    non-NULL. The publicId argument will be NULL unless a public
00401    identifier was provided. The notationName argument will have a
00402    non-NULL value only for unparsed entity declarations.
00403 
00404    Note that is_parameter_entity can't be changed to XML_Bool, since
00405    that would break binary compatibility.
00406 */
00407 typedef void (XMLCALL *XML_EntityDeclHandler) (
00408                               void *userData,
00409                               const XML_Char *entityName,
00410                               int is_parameter_entity,
00411                               const XML_Char *value,
00412                               int value_length,
00413                               const XML_Char *base,
00414                               const XML_Char *systemId,
00415                               const XML_Char *publicId,
00416                               const XML_Char *notationName);
00417 
00418 XMLPARSEAPI(void)
00419 XML_SetEntityDeclHandler(XML_Parser parser,
00420                          XML_EntityDeclHandler handler);
00421 
00422 /* OBSOLETE -- OBSOLETE -- OBSOLETE
00423    This handler has been superceded by the EntityDeclHandler above.
00424    It is provided here for backward compatibility.
00425 
00426    This is called for a declaration of an unparsed (NDATA) entity.
00427    The base argument is whatever was set by XML_SetBase. The
00428    entityName, systemId and notationName arguments will never be
00429    NULL. The other arguments may be.
00430 */
00431 typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) (
00432                                     void *userData,
00433                                     const XML_Char *entityName,
00434                                     const XML_Char *base,
00435                                     const XML_Char *systemId,
00436                                     const XML_Char *publicId,
00437                                     const XML_Char *notationName);
00438 
00439 /* This is called for a declaration of notation.  The base argument is
00440    whatever was set by XML_SetBase. The notationName will never be
00441    NULL.  The other arguments can be.
00442 */
00443 typedef void (XMLCALL *XML_NotationDeclHandler) (
00444                                     void *userData,
00445                                     const XML_Char *notationName,
00446                                     const XML_Char *base,
00447                                     const XML_Char *systemId,
00448                                     const XML_Char *publicId);
00449 
00450 /* When namespace processing is enabled, these are called once for
00451    each namespace declaration. The call to the start and end element
00452    handlers occur between the calls to the start and end namespace
00453    declaration handlers. For an xmlns attribute, prefix will be
00454    NULL.  For an xmlns="" attribute, uri will be NULL.
00455 */
00456 typedef void (XMLCALL *XML_StartNamespaceDeclHandler) (
00457                                     void *userData,
00458                                     const XML_Char *prefix,
00459                                     const XML_Char *uri);
00460 
00461 typedef void (XMLCALL *XML_EndNamespaceDeclHandler) (
00462                                     void *userData,
00463                                     const XML_Char *prefix);
00464 
00465 /* This is called if the document is not standalone, that is, it has an
00466    external subset or a reference to a parameter entity, but does not
00467    have standalone="yes". If this handler returns XML_STATUS_ERROR,
00468    then processing will not continue, and the parser will return a
00469    XML_ERROR_NOT_STANDALONE error.
00470    If parameter entity parsing is enabled, then in addition to the
00471    conditions above this handler will only be called if the referenced
00472    entity was actually read.
00473 */
00474 typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData);
00475 
00476 /* This is called for a reference to an external parsed general
00477    entity.  The referenced entity is not automatically parsed.  The
00478    application can parse it immediately or later using
00479    XML_ExternalEntityParserCreate.
00480 
00481    The parser argument is the parser parsing the entity containing the
00482    reference; it can be passed as the parser argument to
00483    XML_ExternalEntityParserCreate.  The systemId argument is the
00484    system identifier as specified in the entity declaration; it will
00485    not be NULL.
00486 
00487    The base argument is the system identifier that should be used as
00488    the base for resolving systemId if systemId was relative; this is
00489    set by XML_SetBase; it may be NULL.
00490 
00491    The publicId argument is the public identifier as specified in the
00492    entity declaration, or NULL if none was specified; the whitespace
00493    in the public identifier will have been normalized as required by
00494    the XML spec.
00495 
00496    The context argument specifies the parsing context in the format
00497    expected by the context argument to XML_ExternalEntityParserCreate;
00498    context is valid only until the handler returns, so if the
00499    referenced entity is to be parsed later, it must be copied.
00500    context is NULL only when the entity is a parameter entity.
00501 
00502    The handler should return XML_STATUS_ERROR if processing should not
00503    continue because of a fatal error in the handling of the external
00504    entity.  In this case the calling parser will return an
00505    XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
00506 
00507    Note that unlike other handlers the first argument is the parser,
00508    not userData.
00509 */
00510 typedef int (XMLCALL *XML_ExternalEntityRefHandler) (
00511                                     XML_Parser parser,
00512                                     const XML_Char *context,
00513                                     const XML_Char *base,
00514                                     const XML_Char *systemId,
00515                                     const XML_Char *publicId);
00516 
00517 /* This is called in two situations:
00518    1) An entity reference is encountered for which no declaration
00519       has been read *and* this is not an error.
00520    2) An internal entity reference is read, but not expanded, because
00521       XML_SetDefaultHandler has been called.
00522    Note: skipped parameter entities in declarations and skipped general
00523          entities in attribute values cannot be reported, because
00524          the event would be out of sync with the reporting of the
00525          declarations or attribute values
00526 */
00527 typedef void (XMLCALL *XML_SkippedEntityHandler) (
00528                                     void *userData,
00529                                     const XML_Char *entityName,
00530                                     int is_parameter_entity);
00531 
00532 /* This structure is filled in by the XML_UnknownEncodingHandler to
00533    provide information to the parser about encodings that are unknown
00534    to the parser.
00535 
00536    The map[b] member gives information about byte sequences whose
00537    first byte is b.
00538 
00539    If map[b] is c where c is >= 0, then b by itself encodes the
00540    Unicode scalar value c.
00541 
00542    If map[b] is -1, then the byte sequence is malformed.
00543 
00544    If map[b] is -n, where n >= 2, then b is the first byte of an
00545    n-byte sequence that encodes a single Unicode scalar value.
00546 
00547    The data member will be passed as the first argument to the convert
00548    function.
00549 
00550    The convert function is used to convert multibyte sequences; s will
00551    point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
00552    convert function must return the Unicode scalar value represented
00553    by this byte sequence or -1 if the byte sequence is malformed.
00554 
00555    The convert function may be NULL if the encoding is a single-byte
00556    encoding, that is if map[b] >= -1 for all bytes b.
00557 
00558    When the parser is finished with the encoding, then if release is
00559    not NULL, it will call release passing it the data member; once
00560    release has been called, the convert function will not be called
00561    again.
00562 
00563    Expat places certain restrictions on the encodings that are supported
00564    using this mechanism.
00565 
00566    1. Every ASCII character that can appear in a well-formed XML document,
00567       other than the characters
00568 
00569       $@\^`{}~
00570 
00571       must be represented by a single byte, and that byte must be the
00572       same byte that represents that character in ASCII.
00573 
00574    2. No character may require more than 4 bytes to encode.
00575 
00576    3. All characters encoded must have Unicode scalar values <=
00577       0xFFFF, (i.e., characters that would be encoded by surrogates in
00578       UTF-16 are  not allowed).  Note that this restriction doesn't
00579       apply to the built-in support for UTF-8 and UTF-16.
00580 
00581    4. No Unicode character may be encoded by more than one distinct
00582       sequence of bytes.
00583 */
00584 typedef struct {
00585   int map[256];
00586   void *data;
00587   int (XMLCALL *convert)(void *data, const char *s);
00588   void (XMLCALL *release)(void *data);
00589 } XML_Encoding;
00590 
00591 /* This is called for an encoding that is unknown to the parser.
00592 
00593    The encodingHandlerData argument is that which was passed as the
00594    second argument to XML_SetUnknownEncodingHandler.
00595 
00596    The name argument gives the name of the encoding as specified in
00597    the encoding declaration.
00598 
00599    If the callback can provide information about the encoding, it must
00600    fill in the XML_Encoding structure, and return XML_STATUS_OK.
00601    Otherwise it must return XML_STATUS_ERROR.
00602 
00603    If info does not describe a suitable encoding, then the parser will
00604    return an XML_UNKNOWN_ENCODING error.
00605 */
00606 typedef int (XMLCALL *XML_UnknownEncodingHandler) (
00607                                     void *encodingHandlerData,
00608                                     const XML_Char *name,
00609                                     XML_Encoding *info);
00610 
00611 XMLPARSEAPI(void)
00612 XML_SetElementHandler(XML_Parser parser,
00613                       XML_StartElementHandler start,
00614                       XML_EndElementHandler end);
00615 
00616 XMLPARSEAPI(void)
00617 XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler);
00618 
00619 XMLPARSEAPI(void)
00620 XML_SetEndElementHandler(XML_Parser, XML_EndElementHandler);
00621 
00622 XMLPARSEAPI(void)
00623 XML_SetCharacterDataHandler(XML_Parser parser,
00624                             XML_CharacterDataHandler handler);
00625 
00626 XMLPARSEAPI(void)
00627 XML_SetProcessingInstructionHandler(XML_Parser parser,
00628                                     XML_ProcessingInstructionHandler handler);
00629 XMLPARSEAPI(void)
00630 XML_SetCommentHandler(XML_Parser parser,
00631                       XML_CommentHandler handler);
00632 
00633 XMLPARSEAPI(void)
00634 XML_SetCdataSectionHandler(XML_Parser parser,
00635                            XML_StartCdataSectionHandler start,
00636                            XML_EndCdataSectionHandler end);
00637 
00638 XMLPARSEAPI(void)
00639 XML_SetStartCdataSectionHandler(XML_Parser parser,
00640                                 XML_StartCdataSectionHandler start);
00641 
00642 XMLPARSEAPI(void)
00643 XML_SetEndCdataSectionHandler(XML_Parser parser,
00644                               XML_EndCdataSectionHandler end);
00645 
00646 /* This sets the default handler and also inhibits expansion of
00647    internal entities. These entity references will be passed to the
00648    default handler, or to the skipped entity handler, if one is set.
00649 */
00650 XMLPARSEAPI(void)
00651 XML_SetDefaultHandler(XML_Parser parser,
00652                       XML_DefaultHandler handler);
00653 
00654 /* This sets the default handler but does not inhibit expansion of
00655    internal entities.  The entity reference will not be passed to the
00656    default handler.
00657 */
00658 XMLPARSEAPI(void)
00659 XML_SetDefaultHandlerExpand(XML_Parser parser,
00660                             XML_DefaultHandler handler);
00661 
00662 XMLPARSEAPI(void)
00663 XML_SetDoctypeDeclHandler(XML_Parser parser,
00664                           XML_StartDoctypeDeclHandler start,
00665                           XML_EndDoctypeDeclHandler end);
00666 
00667 XMLPARSEAPI(void)
00668 XML_SetStartDoctypeDeclHandler(XML_Parser parser,
00669                                XML_StartDoctypeDeclHandler start);
00670 
00671 XMLPARSEAPI(void)
00672 XML_SetEndDoctypeDeclHandler(XML_Parser parser,
00673                              XML_EndDoctypeDeclHandler end);
00674 
00675 XMLPARSEAPI(void)
00676 XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
00677                                  XML_UnparsedEntityDeclHandler handler);
00678 
00679 XMLPARSEAPI(void)
00680 XML_SetNotationDeclHandler(XML_Parser parser,
00681                            XML_NotationDeclHandler handler);
00682 
00683 XMLPARSEAPI(void)
00684 XML_SetNamespaceDeclHandler(XML_Parser parser,
00685                             XML_StartNamespaceDeclHandler start,
00686                             XML_EndNamespaceDeclHandler end);
00687 
00688 XMLPARSEAPI(void)
00689 XML_SetStartNamespaceDeclHandler(XML_Parser parser,
00690                                  XML_StartNamespaceDeclHandler start);
00691 
00692 XMLPARSEAPI(void)
00693 XML_SetEndNamespaceDeclHandler(XML_Parser parser,
00694                                XML_EndNamespaceDeclHandler end);
00695 
00696 XMLPARSEAPI(void)
00697 XML_SetNotStandaloneHandler(XML_Parser parser,
00698                             XML_NotStandaloneHandler handler);
00699 
00700 XMLPARSEAPI(void)
00701 XML_SetExternalEntityRefHandler(XML_Parser parser,
00702                                 XML_ExternalEntityRefHandler handler);
00703 
00704 /* If a non-NULL value for arg is specified here, then it will be
00705    passed as the first argument to the external entity ref handler
00706    instead of the parser object.
00707 */
00708 XMLPARSEAPI(void)
00709 XML_SetExternalEntityRefHandlerArg(XML_Parser, void *arg);
00710 
00711 XMLPARSEAPI(void)
00712 XML_SetSkippedEntityHandler(XML_Parser parser,
00713                             XML_SkippedEntityHandler handler);
00714 
00715 XMLPARSEAPI(void)
00716 XML_SetUnknownEncodingHandler(XML_Parser parser,
00717                               XML_UnknownEncodingHandler handler,
00718                               void *encodingHandlerData);
00719 
00720 /* This can be called within a handler for a start element, end
00721    element, processing instruction or character data.  It causes the
00722    corresponding markup to be passed to the default handler.
00723 */
00724 XMLPARSEAPI(void)
00725 XML_DefaultCurrent(XML_Parser parser);
00726 
00727 /* If do_nst is non-zero, and namespace processing is in effect, and
00728    a name has a prefix (i.e. an explicit namespace qualifier) then
00729    that name is returned as a triplet in a single string separated by
00730    the separator character specified when the parser was created: URI
00731    + sep + local_name + sep + prefix.
00732 
00733    If do_nst is zero, then namespace information is returned in the
00734    default manner (URI + sep + local_name) whether or not the name
00735    has a prefix.
00736 
00737    Note: Calling XML_SetReturnNSTriplet after XML_Parse or
00738      XML_ParseBuffer has no effect.
00739 */
00740 
00741 XMLPARSEAPI(void)
00742 XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
00743 
00744 /* This value is passed as the userData argument to callbacks. */
00745 XMLPARSEAPI(void)
00746 XML_SetUserData(XML_Parser parser, void *userData);
00747 
00748 /* Returns the last value set by XML_SetUserData or NULL. */
00749 #define XML_GetUserData(parser) (*(void **)(parser))
00750 
00751 /* This is equivalent to supplying an encoding argument to
00752    XML_ParserCreate. On success XML_SetEncoding returns non-zero,
00753    zero otherwise.
00754    Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
00755      has no effect and returns XML_STATUS_ERROR.
00756 */
00757 XMLPARSEAPI(enum XML_Status)
00758 XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
00759 
00760 /* If this function is called, then the parser will be passed as the
00761    first argument to callbacks instead of userData.  The userData will
00762    still be accessible using XML_GetUserData.
00763 */
00764 XMLPARSEAPI(void)
00765 XML_UseParserAsHandlerArg(XML_Parser parser);
00766 
00767 /* If useDTD == XML_TRUE is passed to this function, then the parser
00768    will assume that there is an external subset, even if none is
00769    specified in the document. In such a case the parser will call the
00770    externalEntityRefHandler with a value of NULL for the systemId
00771    argument (the publicId and context arguments will be NULL as well).
00772    Note: If this function is called, then this must be done before
00773      the first call to XML_Parse or XML_ParseBuffer, since it will
00774      have no effect after that.  Returns
00775      XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
00776    Note: If the document does not have a DOCTYPE declaration at all,
00777      then startDoctypeDeclHandler and endDoctypeDeclHandler will not
00778      be called, despite an external subset being parsed.
00779    Note: If XML_DTD is not defined when Expat is compiled, returns
00780      XML_ERROR_FEATURE_REQUIRES_XML_DTD.
00781 */
00782 XMLPARSEAPI(enum XML_Error)
00783 XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
00784 
00785 
00786 /* Sets the base to be used for resolving relative URIs in system
00787    identifiers in declarations.  Resolving relative identifiers is
00788    left to the application: this value will be passed through as the
00789    base argument to the XML_ExternalEntityRefHandler,
00790    XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
00791    argument will be copied.  Returns XML_STATUS_ERROR if out of memory,
00792    XML_STATUS_OK otherwise.
00793 */
00794 XMLPARSEAPI(enum XML_Status)
00795 XML_SetBase(XML_Parser parser, const XML_Char *base);
00796 
00797 XMLPARSEAPI(const XML_Char *)
00798 XML_GetBase(XML_Parser parser);
00799 
00800 /* Returns the number of the attribute/value pairs passed in last call
00801    to the XML_StartElementHandler that were specified in the start-tag
00802    rather than defaulted. Each attribute/value pair counts as 2; thus
00803    this correspondds to an index into the atts array passed to the
00804    XML_StartElementHandler.
00805 */
00806 XMLPARSEAPI(int)
00807 XML_GetSpecifiedAttributeCount(XML_Parser parser);
00808 
00809 /* Returns the index of the ID attribute passed in the last call to
00810    XML_StartElementHandler, or -1 if there is no ID attribute.  Each
00811    attribute/value pair counts as 2; thus this correspondds to an
00812    index into the atts array passed to the XML_StartElementHandler.
00813 */
00814 XMLPARSEAPI(int)
00815 XML_GetIdAttributeIndex(XML_Parser parser);
00816 
00817 /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
00818    detected.  The last call to XML_Parse must have isFinal true; len
00819    may be zero for this call (or any other).
00820 
00821    Though the return values for these functions has always been
00822    described as a Boolean value, the implementation, at least for the
00823    1.95.x series, has always returned exactly one of the XML_Status
00824    values.
00825 */
00826 XMLPARSEAPI(enum XML_Status)
00827 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
00828 
00829 XMLPARSEAPI(void *)
00830 XML_GetBuffer(XML_Parser parser, int len);
00831 
00832 XMLPARSEAPI(enum XML_Status)
00833 XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
00834 
00835 /* BEGIN MOZILLA CHANGE (blocking parser) */
00836 XMLPARSEAPI(enum XML_Status)
00837 MOZ_XML_StopParser(XML_Parser parser, XML_Bool resumable);
00838 
00839 XMLPARSEAPI(enum XML_Status)
00840 MOZ_XML_ResumeParser(XML_Parser parser);
00841 /* END MOZILLA CHANGE */
00842 
00843 /* Creates an XML_Parser object that can parse an external general
00844    entity; context is a '\0'-terminated string specifying the parse
00845    context; encoding is a '\0'-terminated string giving the name of
00846    the externally specified encoding, or NULL if there is no
00847    externally specified encoding.  The context string consists of a
00848    sequence of tokens separated by formfeeds (\f); a token consisting
00849    of a name specifies that the general entity of the name is open; a
00850    token of the form prefix=uri specifies the namespace for a
00851    particular prefix; a token of the form =uri specifies the default
00852    namespace.  This can be called at any point after the first call to
00853    an ExternalEntityRefHandler so longer as the parser has not yet
00854    been freed.  The new parser is completely independent and may
00855    safely be used in a separate thread.  The handlers and userData are
00856    initialized from the parser argument.  Returns NULL if out of memory.
00857    Otherwise returns a new XML_Parser object.
00858 */
00859 XMLPARSEAPI(XML_Parser)
00860 XML_ExternalEntityParserCreate(XML_Parser parser,
00861                                const XML_Char *context,
00862                                const XML_Char *encoding);
00863 
00864 enum XML_ParamEntityParsing {
00865   XML_PARAM_ENTITY_PARSING_NEVER,
00866   XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
00867   XML_PARAM_ENTITY_PARSING_ALWAYS
00868 };
00869 
00870 /* Controls parsing of parameter entities (including the external DTD
00871    subset). If parsing of parameter entities is enabled, then
00872    references to external parameter entities (including the external
00873    DTD subset) will be passed to the handler set with
00874    XML_SetExternalEntityRefHandler.  The context passed will be 0.
00875 
00876    Unlike external general entities, external parameter entities can
00877    only be parsed synchronously.  If the external parameter entity is
00878    to be parsed, it must be parsed during the call to the external
00879    entity ref handler: the complete sequence of
00880    XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
00881    XML_ParserFree calls must be made during this call.  After
00882    XML_ExternalEntityParserCreate has been called to create the parser
00883    for the external parameter entity (context must be 0 for this
00884    call), it is illegal to make any calls on the old parser until
00885    XML_ParserFree has been called on the newly created parser.
00886    If the library has been compiled without support for parameter
00887    entity parsing (ie without XML_DTD being defined), then
00888    XML_SetParamEntityParsing will return 0 if parsing of parameter
00889    entities is requested; otherwise it will return non-zero.
00890    Note: If XML_SetParamEntityParsing is called after XML_Parse or
00891       XML_ParseBuffer, then it has no effect and will always return 0.
00892 */
00893 XMLPARSEAPI(int)
00894 XML_SetParamEntityParsing(XML_Parser parser,
00895                           enum XML_ParamEntityParsing parsing);
00896 
00897 /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
00898    XML_GetErrorCode returns information about the error.
00899 */
00900 XMLPARSEAPI(enum XML_Error)
00901 XML_GetErrorCode(XML_Parser parser);
00902 
00903 /* These functions return information about the current parse
00904    location.  They may be called from any callback called to report
00905    some parse event; in this case the location is the location of the
00906    first of the sequence of characters that generated the event.  When
00907    called from callbacks generated by declarations in the document
00908    prologue, the location identified isn't as neatly defined, but will
00909    be within the relevant markup.  When called outside of the callback
00910    functions, the position indicated will be just past the last parse
00911    event (regardless of whether there was an associated callback).
00912    
00913    They may also be called after returning from a call to XML_Parse
00914    or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
00915    the location is the location of the character at which the error
00916    was detected; otherwise the location is the location of the last
00917    parse event, as described above.
00918 */
00919 XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser);
00920 XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser);
00921 XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser);
00922 
00923 /* Return the number of bytes in the current event.
00924    Returns 0 if the event is in an internal entity.
00925 */
00926 XMLPARSEAPI(int)
00927 XML_GetCurrentByteCount(XML_Parser parser);
00928 
00929 /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
00930    the integer pointed to by offset to the offset within this buffer
00931    of the current parse position, and sets the integer pointed to by size
00932    to the size of this buffer (the number of input bytes). Otherwise
00933    returns a NULL pointer. Also returns a NULL pointer if a parse isn't
00934    active.
00935 
00936    NOTE: The character pointer returned should not be used outside
00937    the handler that makes the call.
00938 */
00939 XMLPARSEAPI(const char *)
00940 XML_GetInputContext(XML_Parser parser,
00941                     int *offset,
00942                     int *size);
00943 
00944 /* For backwards compatibility with previous versions. */
00945 #define XML_GetErrorLineNumber   XML_GetCurrentLineNumber
00946 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
00947 #define XML_GetErrorByteIndex    XML_GetCurrentByteIndex
00948 
00949 /* Frees the content model passed to the element declaration handler */
00950 XMLPARSEAPI(void)
00951 XML_FreeContentModel(XML_Parser parser, XML_Content *model);
00952 
00953 /* Exposing the memory handling functions used in Expat */
00954 XMLPARSEAPI(void *)
00955 XML_MemMalloc(XML_Parser parser, size_t size);
00956 
00957 XMLPARSEAPI(void *)
00958 XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
00959 
00960 XMLPARSEAPI(void)
00961 XML_MemFree(XML_Parser parser, void *ptr);
00962 
00963 /* Frees memory used by the parser. */
00964 XMLPARSEAPI(void)
00965 XML_ParserFree(XML_Parser parser);
00966 
00967 /* Returns a string describing the error. */
00968 XMLPARSEAPI(const XML_LChar *)
00969 XML_ErrorString(enum XML_Error code);
00970 
00971 /* Return a string containing the version number of this expat */
00972 XMLPARSEAPI(const XML_LChar *)
00973 XML_ExpatVersion(void);
00974 
00975 typedef struct {
00976   int major;
00977   int minor;
00978   int micro;
00979 } XML_Expat_Version;
00980 
00981 /* Return an XML_Expat_Version structure containing numeric version
00982    number information for this version of expat.
00983 */
00984 XMLPARSEAPI(XML_Expat_Version)
00985 XML_ExpatVersionInfo(void);
00986 
00987 /* Added in Expat 1.95.5. */
00988 enum XML_FeatureEnum {
00989   XML_FEATURE_END = 0,
00990   XML_FEATURE_UNICODE,
00991   XML_FEATURE_UNICODE_WCHAR_T,
00992   XML_FEATURE_DTD,
00993   XML_FEATURE_CONTEXT_BYTES,
00994   XML_FEATURE_MIN_SIZE,
00995   XML_FEATURE_SIZEOF_XML_CHAR,
00996   XML_FEATURE_SIZEOF_XML_LCHAR
00997   /* Additional features must be added to the end of this enum. */
00998 };
00999 
01000 typedef struct {
01001   enum XML_FeatureEnum  feature;
01002   const XML_LChar       *name;
01003   long int              value;
01004 } XML_Feature;
01005 
01006 XMLPARSEAPI(const XML_Feature *)
01007 XML_GetFeatureList(void);
01008 
01009 
01010 /* Expat follows the GNU/Linux convention of odd number minor version for
01011    beta/development releases and even number minor version for stable
01012    releases. Micro is bumped with each release, and set to 0 with each
01013    change to major or minor version.
01014 */
01015 #define XML_MAJOR_VERSION 1
01016 #define XML_MINOR_VERSION 95
01017 #define XML_MICRO_VERSION 7
01018 
01019 /* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
01020 XMLPARSEAPI(const XML_Char*)
01021 MOZ_XML_GetMismatchedTag(XML_Parser parser);
01022 /* END MOZILLA CHANGE */
01023 
01024 #ifdef __cplusplus
01025 }
01026 #endif
01027 
01028 #endif /* not XmlParse_INCLUDED */