return XML_ERROR_UNDECLARING_PREFIX;
return XML_ERROR_SYNTAX;
static Processor epilogProcessor;static Processor errorProcessor;static Processor externalEntityInitProcessor;static Processor externalEntityInitProcessor2;static Processor externalEntityInitProcessor3;static Processor externalEntityContentProcessor;static Processor internalEntityProcessor;static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName);static enum XML_ErrorprocessXmlDecl(XML_Parser parser, int isGeneralTextEntity,               const char *s, const char *next);static enum XML_ErrorinitializeEncoding(XML_Parser parser);static enum XML_ErrordoProlog(XML_Parser parser, const ENCODING *enc, const char *s,          const char *end, int tok, const char *next, const char **nextPtr,          XML_Bool haveMore);static enum XML_ErrorprocessInternalEntity(XML_Parser parser, ENTITY *entity,                       XML_Bool betweenDecl);static enum XML_ErrordoContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,          const char *start, const char *end, const char **endPtr,           XML_Bool haveMore);static enum XML_ErrordoCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr,               const char *end, const char **nextPtr, XML_Bool haveMore);#ifdef XML_DTDstatic enum XML_ErrordoIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr,                const char *end, const char **nextPtr, XML_Bool haveMore);#endif /* XML_DTD */static enum XML_ErrorstoreAtts(XML_Parser parser, const ENCODING *, const char *s,          TAG_NAME *tagNamePtr, BINDING **bindingsPtr);static enum XML_ErroraddBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,           const XML_Char *uri, BINDING **bindingsPtr);static intdefineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata,                 XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser);static enum XML_ErrorstoreAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,                    const char *, const char *, STRING_POOL *);static enum XML_ErrorappendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,                     const char *, const char *, STRING_POOL *);static ATTRIBUTE_ID *getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start,               const char *end);static intsetElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *);static enum XML_ErrorstoreEntityValue(XML_Parser parser, const ENCODING *enc, const char *start,                 const char *end);static intreportProcessingInstruction(XML_Parser parser, const ENCODING *enc,                            const char *start, const char *end);static intreportComment(XML_Parser parser, const ENCODING *enc, const char *start,              const char *end);static voidreportDefault(XML_Parser parser, const ENCODING *enc, const char *start,              const char *end);static const XML_Char * getContext(XML_Parser parser);static XML_BoolsetContext(XML_Parser parser, const XML_Char *context);static void FASTCALL normalizePublicId(XML_Char *s);static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms);/* do not call if parentParser != NULL */static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms);static voiddtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms);static intdtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms);static intcopyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *);static NAMED *lookup(HASH_TABLE *table, KEY name, size_t createSize);static void FASTCALLhashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms);static void FASTCALL hashTableClear(HASH_TABLE *);static void FASTCALL hashTableDestroy(HASH_TABLE *);static void FASTCALLhashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *);static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *);static void FASTCALLpoolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms);static void FASTCALL poolClear(STRING_POOL *);static void FASTCALL poolDestroy(STRING_POOL *);static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc,           const char *ptr, const char *end);static XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc,                const char *ptr, const char *end);static XML_Bool FASTCALL poolGrow(STRING_POOL *pool);static const XML_Char * FASTCALLpoolCopyString(STRING_POOL *pool, const XML_Char *s);static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n);static const XML_Char * FASTCALLpoolAppendString(STRING_POOL *pool, const XML_Char *s);static int FASTCALL nextScaffoldPart(XML_Parser parser);static XML_Content * build_model(XML_Parser parser);static ELEMENT_TYPE *getElementType(XML_Parser parser, const ENCODING *enc,               const char *ptr, const char *end);static XML_ParserparserCreate(const XML_Char *encodingName,             const XML_Memory_Handling_Suite *memsuite,             const XML_Char *nameSep,             DTD *dtd);static voidparserInit(XML_Parser parser, const XML_Char *encodingName);#define poolStart(pool) ((pool)->start)#define poolEnd(pool) ((pool)->ptr)#define poolLength(pool) ((pool)->ptr - (pool)->start)#define poolChop(pool) ((void)--(pool->ptr))#define poolLastChar(pool) (((pool)->ptr)[-1])#define poolDiscard(pool) ((pool)->ptr = (pool)->start)#define poolFinish(pool) ((pool)->start = (pool)->ptr)#define poolAppendChar(pool, c) \  (((pool)->ptr == (pool)->end && !poolGrow(pool)) \   ? 0 \   : ((*((pool)->ptr)++ = c), 1))struct XML_ParserStruct {  /* The first member must be userData so that the XML_GetUserData     macro works. */  void *m_userData;  void *m_handlerArg;  char *m_buffer;  const XML_Memory_Handling_Suite m_mem;  /* first character to be parsed */  const char *m_bufferPtr;  /* past last character to be parsed */  char *m_bufferEnd;  /* allocated end of buffer */  const char *m_bufferLim;  long m_parseEndByteIndex;  const char *m_parseEndPtr;  XML_Char *m_dataBuf;  XML_Char *m_dataBufEnd;  XML_StartElementHandler m_startElementHandler;  XML_EndElementHandler m_endElementHandler;  XML_CharacterDataHandler m_characterDataHandler;  XML_ProcessingInstructionHandler m_processingInstructionHandler;  XML_CommentHandler m_commentHandler;  XML_StartCdataSectionHandler m_startCdataSectionHandler;  XML_EndCdataSectionHandler m_endCdataSectionHandler;  XML_DefaultHandler m_defaultHandler;  XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler;  XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler;  XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler;  XML_NotationDeclHandler m_notationDeclHandler;  XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler;  XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler;  XML_NotStandaloneHandler m_notStandaloneHandler;  XML_ExternalEntityRefHandler m_externalEntityRefHandler;  XML_Parser m_externalEntityRefHandlerArg;  XML_SkippedEntityHandler m_skippedEntityHandler;  XML_UnknownEncodingHandler m_unknownEncodingHandler;  XML_ElementDeclHandler m_elementDeclHandler;  XML_AttlistDeclHandler m_attlistDeclHandler;  XML_EntityDeclHandler m_entityDeclHandler;  XML_XmlDeclHandler m_xmlDeclHandler;  const ENCODING *m_encoding;  INIT_ENCODING m_initEncoding;  const ENCODING *m_internalEncoding;  const XML_Char *m_protocolEncodingName;  XML_Bool m_ns;  XML_Bool m_ns_triplets;  void *m_unknownEncodingMem;  void *m_unknownEncodingData;  void *m_unknownEncodingHandlerData;  void (XMLCALL *m_unknownEncodingRelease)(void *);  PROLOG_STATE m_prologState;  Processor *m_processor;  enum XML_Error m_errorCode;  const char *m_eventPtr;  const char *m_eventEndPtr;  const char *m_positionPtr;  OPEN_INTERNAL_ENTITY *m_openInternalEntities;  OPEN_INTERNAL_ENTITY *m_freeInternalEntities;  XML_Bool m_defaultExpandInternalEntities;  int m_tagLevel;  ENTITY *m_declEntity;  const XML_Char *m_doctypeName;  const XML_Char *m_doctypeSysid;  const XML_Char *m_doctypePubid;  const XML_Char *m_declAttributeType;  const XML_Char *m_declNotationName;  const XML_Char *m_declNotationPublicId;  ELEMENT_TYPE *m_declElementType;  ATTRIBUTE_ID *m_declAttributeId;  XML_Bool m_declAttributeIsCdata;  XML_Bool m_declAttributeIsId;  DTD *m_dtd;  const XML_Char *m_curBase;  TAG *m_tagStack;  TAG *m_freeTagList;  BINDING *m_inheritedBindings;  BINDING *m_freeBindingList;  int m_attsSize;  int m_nSpecifiedAtts;  int m_idAttIndex;  ATTRIBUTE *m_atts;  NS_ATT *m_nsAtts;  unsigned long m_nsAttsVersion;  unsigned char m_nsAttsPower;  POSITION m_position;  STRING_POOL m_tempPool;  STRING_POOL m_temp2Pool;  char *m_groupConnector;  unsigned int m_groupSize;  XML_Char m_namespaceSeparator;  XML_Parser m_parentParser;  XML_ParsingStatus m_parsingStatus;#ifdef XML_DTD  XML_Bool m_isParamEntity;  XML_Bool m_useForeignDTD;  enum XML_ParamEntityParsing m_paramEntityParsing;#endif/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */  const XML_Char* m_mismatch;/* END MOZILLA CHANGE */};#define MALLOC(s) (parser->m_mem.malloc_fcn((s)))#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s)))#define FREE(p) (parser->m_mem.free_fcn((p)))#define userData (parser->m_userData)#define handlerArg (parser->m_handlerArg)#define startElementHandler (parser->m_startElementHandler)#define endElementHandler (parser->m_endElementHandler)#define characterDataHandler (parser->m_characterDataHandler)#define processingInstructionHandler \        (parser->m_processingInstructionHandler)#define commentHandler (parser->m_commentHandler)#define startCdataSectionHandler \        (parser->m_startCdataSectionHandler)#define endCdataSectionHandler (parser->m_endCdataSectionHandler)#define defaultHandler (parser->m_defaultHandler)#define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler)#define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler)#define unparsedEntityDeclHandler \        (parser->m_unparsedEntityDeclHandler)#define notationDeclHandler (parser->m_notationDeclHandler)#define startNamespaceDeclHandler \        (parser->m_startNamespaceDeclHandler)#define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler)#define notStandaloneHandler (parser->m_notStandaloneHandler)#define externalEntityRefHandler \        (parser->m_externalEntityRefHandler)#define externalEntityRefHandlerArg \        (parser->m_externalEntityRefHandlerArg)#define internalEntityRefHandler \        (parser->m_internalEntityRefHandler)#define skippedEntityHandler (parser->m_skippedEntityHandler)#define unknownEncodingHandler (parser->m_unknownEncodingHandler)#define elementDeclHandler (parser->m_elementDeclHandler)#define attlistDeclHandler (parser->m_attlistDeclHandler)#define entityDeclHandler (parser->m_entityDeclHandler)#define xmlDeclHandler (parser->m_xmlDeclHandler)#define encoding (parser->m_encoding)#define initEncoding (parser->m_initEncoding)#define internalEncoding (parser->m_internalEncoding)#define unknownEncodingMem (parser->m_unknownEncodingMem)#define unknownEncodingData (parser->m_unknownEncodingData)#define unknownEncodingHandlerData \  (parser->m_unknownEncodingHandlerData)#define unknownEncodingRelease (parser->m_unknownEncodingRelease)#define protocolEncodingName (parser->m_protocolEncodingName)#define ns (parser->m_ns)#define ns_triplets (parser->m_ns_triplets)#define prologState (parser->m_prologState)#define processor (parser->m_processor)#define errorCode (parser->m_errorCode)#define eventPtr (parser->m_eventPtr)#define eventEndPtr (parser->m_eventEndPtr)#define positionPtr (parser->m_positionPtr)#define position (parser->m_position)#define openInternalEntities (parser->m_openInternalEntities)#define freeInternalEntities (parser->m_freeInternalEntities)#define defaultExpandInternalEntities \        (parser->m_defaultExpandInternalEntities)#define tagLevel (parser->m_tagLevel)#define buffer (parser->m_buffer)#define bufferPtr (parser->m_bufferPtr)#define bufferEnd (parser->m_bufferEnd)#define parseEndByteIndex (parser->m_parseEndByteIndex)#define parseEndPtr (parser->m_parseEndPtr)#define bufferLim (parser->m_bufferLim)#define dataBuf (parser->m_dataBuf)#define dataBufEnd (parser->m_dataBufEnd)#define _dtd (parser->m_dtd)#define curBase (parser->m_curBase)#define declEntity (parser->m_declEntity)#define doctypeName (parser->m_doctypeName)#define doctypeSysid (parser->m_doctypeSysid)#define doctypePubid (parser->m_doctypePubid)#define declAttributeType (parser->m_declAttributeType)#define declNotationName (parser->m_declNotationName)#define declNotationPublicId (parser->m_declNotationPublicId)#define declElementType (parser->m_declElementType)#define declAttributeId (parser->m_declAttributeId)#define declAttributeIsCdata (parser->m_declAttributeIsCdata)#define declAttributeIsId (parser->m_declAttributeIsId)#define freeTagList (parser->m_freeTagList)#define freeBindingList (parser->m_freeBindingList)#define inheritedBindings (parser->m_inheritedBindings)#define tagStack (parser->m_tagStack)#define atts (parser->m_atts)#define attsSize (parser->m_attsSize)#define nSpecifiedAtts (parser->m_nSpecifiedAtts)#define idAttIndex (parser->m_idAttIndex)#define nsAtts (parser->m_nsAtts)#define nsAttsVersion (parser->m_nsAttsVersion)#define nsAttsPower (parser->m_nsAttsPower)#define tempPool (parser->m_tempPool)#define temp2Pool (parser->m_temp2Pool)#define groupConnector (parser->m_groupConnector)#define groupSize (parser->m_groupSize)#define namespaceSeparator (parser->m_namespaceSeparator)#define parentParser (parser->m_parentParser)#define parsing (parser->m_parsingStatus.parsing)#define finalBuffer (parser->m_parsingStatus.finalBuffer)#ifdef XML_DTD#define isParamEntity (parser->m_isParamEntity)#define useForeignDTD (parser->m_useForeignDTD)#define paramEntityParsing (parser->m_paramEntityParsing)#endif /* XML_DTD *//* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */#define mismatch (parser->m_mismatch)/* END MOZILLA CHANGE *//* BEGIN MOZILLA CHANGE (unused API) */#ifdef TX_EXEXML_Parser XMLCALLXML_ParserCreate(const XML_Char *encodingName){  return XML_ParserCreate_MM(encodingName, NULL, NULL);}#endif#if 0XML_Parser XMLCALLXML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep){  XML_Char tmp[2];  *tmp = nsSep;  return XML_ParserCreate_MM(encodingName, NULL, tmp);}#endif/* END MOZILLA CHANGE */static const XML_Char implicitContext[] = {  'x', 'm', 'l', '=', 'h', 't', 't', 'p', ':', '/', '/',  'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',  'X', 'M', 'L', '/', '1', '9', '9', '8', '/',  'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0'};XML_Parser XMLCALLXML_ParserCreate_MM(const XML_Char *encodingName,                    const XML_Memory_Handling_Suite *memsuite,                    const XML_Char *nameSep){  XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL);  if (parser != NULL && ns) {    /* implicit context only set for root parser, since child       parsers (i.e. external entity parsers) will inherit it    */    if (!setContext(parser, implicitContext)) {      XML_ParserFree(parser);      return NULL;    }  }  return parser;}static XML_ParserparserCreate(const XML_Char *encodingName,             const XML_Memory_Handling_Suite *memsuite,             const XML_Char *nameSep,             DTD *dtd){  XML_Parser parser;  if (memsuite) {    XML_Memory_Handling_Suite *mtemp;    parser = (XML_Parser)      memsuite->malloc_fcn(sizeof(struct XML_ParserStruct));    if (parser != NULL) {      mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem);      mtemp->malloc_fcn = memsuite->malloc_fcn;      mtemp->realloc_fcn = memsuite->realloc_fcn;      mtemp->free_fcn = memsuite->free_fcn;    }  }  else {    XML_Memory_Handling_Suite *mtemp;    parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct));    if (parser != NULL) {      mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem);      mtemp->malloc_fcn = malloc;      mtemp->realloc_fcn = realloc;      mtemp->free_fcn = free;    }  }  if (!parser)    return parser;  buffer = NULL;  bufferLim = NULL;  attsSize = INIT_ATTS_SIZE;  atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE));  if (atts == NULL) {    FREE(parser);    return NULL;  }  dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));  if (dataBuf == NULL) {    FREE(atts);    FREE(parser);    return NULL;  }  dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;  if (dtd)    _dtd = dtd;  else {    _dtd = dtdCreate(&parser->m_mem);    if (_dtd == NULL) {      FREE(dataBuf);      FREE(atts);      FREE(parser);      return NULL;    }  }  freeBindingList = NULL;  freeTagList = NULL;  freeInternalEntities = NULL;  groupSize = 0;  groupConnector = NULL;  unknownEncodingHandler = NULL;  unknownEncodingHandlerData = NULL;  namespaceSeparator = '!';  ns = XML_FALSE;  ns_triplets = XML_FALSE;  nsAtts = NULL;  nsAttsVersion = 0;  nsAttsPower = 0;  poolInit(&tempPool, &(parser->m_mem));  poolInit(&temp2Pool, &(parser->m_mem));  parserInit(parser, encodingName);  if (encodingName && !protocolEncodingName) {    XML_ParserFree(parser);    return NULL;  }  if (nameSep) {    ns = XML_TRUE;    internalEncoding = XmlGetInternalEncodingNS();    namespaceSeparator = *nameSep;  }  else {    internalEncoding = XmlGetInternalEncoding();  }/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */  mismatch = NULL;/* END MOZILLA CHANGE */  return parser;}static voidparserInit(XML_Parser parser, const XML_Char *encodingName){  processor = prologInitProcessor;  XmlPrologStateInit(&prologState);  protocolEncodingName = (encodingName != NULL                          ? poolCopyString(&tempPool, encodingName)                          : NULL);  curBase = NULL;  XmlInitEncoding(&initEncoding, &encoding, 0);  userData = NULL;  handlerArg = NULL;  startElementHandler = NULL;  endElementHandler = NULL;  characterDataHandler = NULL;  processingInstructionHandler = NULL;  commentHandler = NULL;  startCdataSectionHandler = NULL;  endCdataSectionHandler = NULL;  defaultHandler = NULL;  startDoctypeDeclHandler = NULL;  endDoctypeDeclHandler = NULL;  unparsedEntityDeclHandler = NULL;  notationDeclHandler = NULL;  startNamespaceDeclHandler = NULL;  endNamespaceDeclHandler = NULL;  notStandaloneHandler = NULL;  externalEntityRefHandler = NULL;  externalEntityRefHandlerArg = parser;  skippedEntityHandler = NULL;  elementDeclHandler = NULL;  attlistDeclHandler = NULL;  entityDeclHandler = NULL;  xmlDeclHandler = NULL;  bufferPtr = buffer;  bufferEnd = buffer;  parseEndByteIndex = 0;  parseEndPtr = NULL;  declElementType = NULL;  declAttributeId = NULL;  declEntity = NULL;  doctypeName = NULL;  doctypeSysid = NULL;  doctypePubid = NULL;  declAttributeType = NULL;  declNotationName = NULL;  declNotationPublicId = NULL;  declAttributeIsCdata = XML_FALSE;  declAttributeIsId = XML_FALSE;  memset(&position, 0, sizeof(POSITION));  errorCode = XML_ERROR_NONE;  eventPtr = NULL;  eventEndPtr = NULL;  positionPtr = NULL;  openInternalEntities = NULL;  defaultExpandInternalEntities = XML_TRUE;  tagLevel = 0;  tagStack = NULL;  inheritedBindings = NULL;  nSpecifiedAtts = 0;  unknownEncodingMem = NULL;  unknownEncodingRelease = NULL;  unknownEncodingData = NULL;  parentParser = NULL;  parsing = XML_INITIALIZED;#ifdef XML_DTD  isParamEntity = XML_FALSE;  useForeignDTD = XML_FALSE;  paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;#endif}/* moves list of bindings to freeBindingList */static void FASTCALLmoveToFreeBindingList(XML_Parser parser, BINDING *bindings){  while (bindings) {    BINDING *b = bindings;    bindings = bindings->nextTagBinding;    b->nextTagBinding = freeBindingList;    freeBindingList = b;  }}/* BEGIN MOZILLA CHANGE (unused API) */#if 0XML_Bool XMLCALLXML_ParserReset(XML_Parser parser, const XML_Char *encodingName){  TAG *tStk;  OPEN_INTERNAL_ENTITY *openEntityList;  if (parentParser)    return XML_FALSE;  /* move tagStack to freeTagList */  tStk = tagStack;  while (tStk) {    TAG *tag = tStk;    tStk = tStk->parent;    tag->parent = freeTagList;    moveToFreeBindingList(parser, tag->bindings);    tag->bindings = NULL;    freeTagList = tag;  }  /* move openInternalEntities to freeInternalEntities */  openEntityList = openInternalEntities;  while (openEntityList) {    OPEN_INTERNAL_ENTITY *openEntity = openEntityList;    openEntityList = openEntity->next;    openEntity->next = freeInternalEntities;    freeInternalEntities = openEntity;  }  moveToFreeBindingList(parser, inheritedBindings);  FREE(unknownEncodingMem);  if (unknownEncodingRelease)    unknownEncodingRelease(unknownEncodingData);  poolClear(&tempPool);  poolClear(&temp2Pool);  parserInit(parser, encodingName);  dtdReset(_dtd, &parser->m_mem);  return setContext(parser, implicitContext);}enum XML_Status XMLCALLXML_SetEncoding(XML_Parser parser, const XML_Char *encodingName){  /* Block after XML_Parse()/XML_ParseBuffer() has been called.     XXX There's no way for the caller to determine which of the     XXX possible error cases caused the XML_STATUS_ERROR return.  */  if (parsing == XML_PARSING || parsing == XML_SUSPENDED)    return XML_STATUS_ERROR;  if (encodingName == NULL)    protocolEncodingName = NULL;  else {    protocolEncodingName = poolCopyString(&tempPool, encodingName);    if (!protocolEncodingName)      return XML_STATUS_ERROR;  }  return XML_STATUS_OK;}#endif/* END MOZILLA CHANGE */XML_Parser XMLCALLXML_ExternalEntityParserCreate(XML_Parser oldParser,                               const XML_Char *context,                               const XML_Char *encodingName){  XML_Parser parser = oldParser;  DTD *newDtd = NULL;  DTD *oldDtd = _dtd;  XML_StartElementHandler oldStartElementHandler = startElementHandler;  XML_EndElementHandler oldEndElementHandler = endElementHandler;  XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler;  XML_ProcessingInstructionHandler oldProcessingInstructionHandler      = processingInstructionHandler;  XML_CommentHandler oldCommentHandler = commentHandler;  XML_StartCdataSectionHandler oldStartCdataSectionHandler      = startCdataSectionHandler;  XML_EndCdataSectionHandler oldEndCdataSectionHandler      = endCdataSectionHandler;  XML_DefaultHandler oldDefaultHandler = defaultHandler;  XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler      = unparsedEntityDeclHandler;  XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler;  XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler      = startNamespaceDeclHandler;  XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler      = endNamespaceDeclHandler;  XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler;  XML_ExternalEntityRefHandler oldExternalEntityRefHandler      = externalEntityRefHandler;  XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler;  XML_UnknownEncodingHandler oldUnknownEncodingHandler      = unknownEncodingHandler;  XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler;  XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler;  XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler;  XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler;  ELEMENT_TYPE * oldDeclElementType = declElementType;  void *oldUserData = userData;  void *oldHandlerArg = handlerArg;  XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities;  XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg;#ifdef XML_DTD  enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing;  int oldInEntityValue = prologState.inEntityValue;#endif  XML_Bool oldns_triplets = ns_triplets;#ifdef XML_DTD  if (!context)    newDtd = oldDtd;#endif /* XML_DTD */  /* Note that the magical uses of the pre-processor to make field     access look more like C++ require that `parser' be overwritten     here.  This makes this function more painful to follow than it     would be otherwise.  */  if (ns) {    XML_Char tmp[2];    *tmp = namespaceSeparator;    parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd);  }  else {    parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd);  }  if (!parser)    return NULL;  startElementHandler = oldStartElementHandler;  endElementHandler = oldEndElementHandler;  characterDataHandler = oldCharacterDataHandler;  processingInstructionHandler = oldProcessingInstructionHandler;  commentHandler = oldCommentHandler;  startCdataSectionHandler = oldStartCdataSectionHandler;  endCdataSectionHandler = oldEndCdataSectionHandler;  defaultHandler = oldDefaultHandler;  unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler;  notationDeclHandler = oldNotationDeclHandler;  startNamespaceDeclHandler = oldStartNamespaceDeclHandler;  endNamespaceDeclHandler = oldEndNamespaceDeclHandler;  notStandaloneHandler = oldNotStandaloneHandler;  externalEntityRefHandler = oldExternalEntityRefHandler;  skippedEntityHandler = oldSkippedEntityHandler;  unknownEncodingHandler = oldUnknownEncodingHandler;  elementDeclHandler = oldElementDeclHandler;  attlistDeclHandler = oldAttlistDeclHandler;  entityDeclHandler = oldEntityDeclHandler;  xmlDeclHandler = oldXmlDeclHandler;  declElementType = oldDeclElementType;  userData = oldUserData;  if (oldUserData == oldHandlerArg)    handlerArg = userData;  else    handlerArg = parser;  if (oldExternalEntityRefHandlerArg != oldParser)    externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;  defaultExpandInternalEntities = oldDefaultExpandInternalEntities;  ns_triplets = oldns_triplets;  parentParser = oldParser;#ifdef XML_DTD  paramEntityParsing = oldParamEntityParsing;  prologState.inEntityValue = oldInEntityValue;  if (context) {#endif /* XML_DTD */    if (!dtdCopy(_dtd, oldDtd, &parser->m_mem)      || !setContext(parser, context)) {      XML_ParserFree(parser);      return NULL;    }    processor = externalEntityInitProcessor;#ifdef XML_DTD  }  else {    /* The DTD instance referenced by _dtd is shared between the document's       root parser and external PE parsers, therefore one does not need to       call setContext. In addition, one also *must* not call setContext,       because this would overwrite existing prefix->binding pointers in       _dtd with ones that get destroyed with the external PE parser.       This would leave those prefixes with dangling pointers.    */    isParamEntity = XML_TRUE;    XmlPrologStateInitExternalEntity(&prologState);    processor = externalParEntInitProcessor;  }#endif /* XML_DTD */  return parser;}static void FASTCALLdestroyBindings(BINDING *bindings, XML_Parser parser){  for (;;) {    BINDING *b = bindings;    if (!b)      break;    bindings = b->nextTagBinding;    FREE(b->uri);    FREE(b);  }}void XMLCALLXML_ParserFree(XML_Parser parser){  TAG *tagList;  OPEN_INTERNAL_ENTITY *entityList;  if (parser == NULL)    return;  /* free tagStack and freeTagList */  tagList = tagStack;  for (;;) {    TAG *p;    if (tagList == NULL) {      if (freeTagList == NULL)        break;      tagList = freeTagList;      freeTagList = NULL;    }    p = tagList;    tagList = tagList->parent;    FREE(p->buf);    destroyBindings(p->bindings, parser);    FREE(p);  }  /* free openInternalEntities and freeInternalEntities */  entityList = openInternalEntities;  for (;;) {    OPEN_INTERNAL_ENTITY *openEntity;    if (entityList == NULL) {      if (freeInternalEntities == NULL)        break;      entityList = freeInternalEntities;      freeInternalEntities = NULL;    }    openEntity = entityList;    entityList = entityList->next;    FREE(openEntity);  }  destroyBindings(freeBindingList, parser);  destroyBindings(inheritedBindings, parser);  poolDestroy(&tempPool);  poolDestroy(&temp2Pool);#ifdef XML_DTD  /* external parameter entity parsers share the DTD structure     parser->m_dtd with the root parser, so we must not destroy it  */  if (!isParamEntity && _dtd)#else  if (_dtd)#endif /* XML_DTD */    dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem);  FREE((void *)atts);  FREE(groupConnector);  FREE(buffer);  FREE(dataBuf);  FREE(nsAtts);  FREE(unknownEncodingMem);  if (unknownEncodingRelease)    unknownEncodingRelease(unknownEncodingData);  FREE(parser);}void XMLCALLXML_UseParserAsHandlerArg(XML_Parser parser){  handlerArg = parser;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0enum XML_Error XMLCALLXML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD){#ifdef XML_DTD  /* block after XML_Parse()/XML_ParseBuffer() has been called */  if (parsing == XML_PARSING || parsing == XML_SUSPENDED)    return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING;  useForeignDTD = useDTD;  return XML_ERROR_NONE;#else  return XML_ERROR_FEATURE_REQUIRES_XML_DTD;#endif}#endif/* END MOZILLA CHANGE */void XMLCALLXML_SetReturnNSTriplet(XML_Parser parser, int do_nst){  /* block after XML_Parse()/XML_ParseBuffer() has been called */  if (parsing == XML_PARSING || parsing == XML_SUSPENDED)    return;  ns_triplets = do_nst ? XML_TRUE : XML_FALSE;}void XMLCALLXML_SetUserData(XML_Parser parser, void *p){  if (handlerArg == userData)    handlerArg = userData = p;  else    userData = p;}enum XML_Status XMLCALLXML_SetBase(XML_Parser parser, const XML_Char *p){  if (p) {    p = poolCopyString(&_dtd->pool, p);    if (!p)      return XML_STATUS_ERROR;    curBase = p;  }  else    curBase = NULL;  return XML_STATUS_OK;}const XML_Char * XMLCALLXML_GetBase(XML_Parser parser){  return curBase;}int XMLCALLXML_GetSpecifiedAttributeCount(XML_Parser parser){  return nSpecifiedAtts;}int XMLCALLXML_GetIdAttributeIndex(XML_Parser parser){  return idAttIndex;}void XMLCALLXML_SetElementHandler(XML_Parser parser,                      XML_StartElementHandler start,                      XML_EndElementHandler end){  startElementHandler = start;  endElementHandler = end;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0void XMLCALLXML_SetStartElementHandler(XML_Parser parser,                           XML_StartElementHandler start) {  startElementHandler = start;}void XMLCALLXML_SetEndElementHandler(XML_Parser parser,                         XML_EndElementHandler end) {  endElementHandler = end;}#endif/* END MOZILLA CHANGE */void XMLCALLXML_SetCharacterDataHandler(XML_Parser parser,                            XML_CharacterDataHandler handler){  characterDataHandler = handler;}void XMLCALLXML_SetProcessingInstructionHandler(XML_Parser parser,                                    XML_ProcessingInstructionHandler handler){  processingInstructionHandler = handler;}void XMLCALLXML_SetCommentHandler(XML_Parser parser,                      XML_CommentHandler handler){  commentHandler = handler;}void XMLCALLXML_SetCdataSectionHandler(XML_Parser parser,                           XML_StartCdataSectionHandler start,                           XML_EndCdataSectionHandler end){  startCdataSectionHandler = start;  endCdataSectionHandler = end;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0void XMLCALLXML_SetStartCdataSectionHandler(XML_Parser parser,                                XML_StartCdataSectionHandler start) {  startCdataSectionHandler = start;}void XMLCALLXML_SetEndCdataSectionHandler(XML_Parser parser,                              XML_EndCdataSectionHandler end) {  endCdataSectionHandler = end;}void XMLCALLXML_SetDefaultHandler(XML_Parser parser,                      XML_DefaultHandler handler){  defaultHandler = handler;  defaultExpandInternalEntities = XML_FALSE;}#endif/* END MOZILLA CHANGE */void XMLCALLXML_SetDefaultHandlerExpand(XML_Parser parser,                            XML_DefaultHandler handler){  defaultHandler = handler;  defaultExpandInternalEntities = XML_TRUE;}void XMLCALLXML_SetDoctypeDeclHandler(XML_Parser parser,                          XML_StartDoctypeDeclHandler start,                          XML_EndDoctypeDeclHandler end){  startDoctypeDeclHandler = start;  endDoctypeDeclHandler = end;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0void XMLCALLXML_SetStartDoctypeDeclHandler(XML_Parser parser,                               XML_StartDoctypeDeclHandler start) {  startDoctypeDeclHandler = start;}void XMLCALLXML_SetEndDoctypeDeclHandler(XML_Parser parser,                             XML_EndDoctypeDeclHandler end) {  endDoctypeDeclHandler = end;}void XMLCALLXML_SetUnparsedEntityDeclHandler(XML_Parser parser,                                 XML_UnparsedEntityDeclHandler handler){  unparsedEntityDeclHandler = handler;}void XMLCALLXML_SetNotationDeclHandler(XML_Parser parser,                           XML_NotationDeclHandler handler){  notationDeclHandler = handler;}void XMLCALLXML_SetNamespaceDeclHandler(XML_Parser parser,                            XML_StartNamespaceDeclHandler start,                            XML_EndNamespaceDeclHandler end){  startNamespaceDeclHandler = start;  endNamespaceDeclHandler = end;}void XMLCALLXML_SetStartNamespaceDeclHandler(XML_Parser parser,                                 XML_StartNamespaceDeclHandler start) {  startNamespaceDeclHandler = start;}void XMLCALLXML_SetEndNamespaceDeclHandler(XML_Parser parser,                               XML_EndNamespaceDeclHandler end) {  endNamespaceDeclHandler = end;}void XMLCALLXML_SetNotStandaloneHandler(XML_Parser parser,                            XML_NotStandaloneHandler handler){  notStandaloneHandler = handler;}#endif/* END MOZILLA CHANGE */void XMLCALLXML_SetExternalEntityRefHandler(XML_Parser parser,                                XML_ExternalEntityRefHandler handler){  externalEntityRefHandler = handler;}void XMLCALLXML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg){  if (arg)    externalEntityRefHandlerArg = (XML_Parser)arg;  else    externalEntityRefHandlerArg = parser;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0void XMLCALLXML_SetSkippedEntityHandler(XML_Parser parser,                            XML_SkippedEntityHandler handler){  skippedEntityHandler = handler;}void XMLCALLXML_SetUnknownEncodingHandler(XML_Parser parser,                              XML_UnknownEncodingHandler handler,                              void *data){  unknownEncodingHandler = handler;  unknownEncodingHandlerData = data;}void XMLCALLXML_SetElementDeclHandler(XML_Parser parser,                          XML_ElementDeclHandler eldecl){  elementDeclHandler = eldecl;}void XMLCALLXML_SetAttlistDeclHandler(XML_Parser parser,                          XML_AttlistDeclHandler attdecl){  attlistDeclHandler = attdecl;}void XMLCALLXML_SetEntityDeclHandler(XML_Parser parser,                         XML_EntityDeclHandler handler){  entityDeclHandler = handler;}#endif/* END MOZILLA CHANGE */void XMLCALLXML_SetXmlDeclHandler(XML_Parser parser,                      XML_XmlDeclHandler handler) {  xmlDeclHandler = handler;}int XMLCALLXML_SetParamEntityParsing(XML_Parser parser,                          enum XML_ParamEntityParsing peParsing){  /* block after XML_Parse()/XML_ParseBuffer() has been called */  if (parsing == XML_PARSING || parsing == XML_SUSPENDED)    return 0;#ifdef XML_DTD  paramEntityParsing = peParsing;  return 1;#else  return peParsing == XML_PARAM_ENTITY_PARSING_NEVER;#endif}enum XML_Status XMLCALLXML_Parse(XML_Parser parser, const char *s, int len, int isFinal){  switch (parsing) {  case XML_SUSPENDED:    errorCode = XML_ERROR_SUSPENDED;    return XML_STATUS_ERROR;  case XML_FINISHED:    errorCode = XML_ERROR_FINISHED;    return XML_STATUS_ERROR;  default:    parsing = XML_PARSING;  }  if (len == 0) {    finalBuffer = (XML_Bool)isFinal;    if (!isFinal)      return XML_STATUS_OK;    positionPtr = bufferPtr;    parseEndPtr = bufferEnd;    /* If data are left over from last buffer, and we now know that these       data are the final chunk of input, then we have to check them again       to detect errors based on this information.    */    errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);    if (errorCode == XML_ERROR_NONE) {      switch (parsing) {      case XML_SUSPENDED:        XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);        positionPtr = bufferPtr;        return XML_STATUS_SUSPENDED;      case XML_INITIALIZED:       case XML_PARSING:        parsing = XML_FINISHED;        /* fall through */      default:        return XML_STATUS_OK;      }    }    eventEndPtr = eventPtr;    processor = errorProcessor;    return XML_STATUS_ERROR;  }#ifndef XML_CONTEXT_BYTES  else if (bufferPtr == bufferEnd) {    const char *end;    int nLeftOver;    enum XML_Error result;    parseEndByteIndex += len;    positionPtr = s;    finalBuffer = (XML_Bool)isFinal;    errorCode = processor(parser, s, parseEndPtr = s + len, &end);    if (errorCode != XML_ERROR_NONE) {      eventEndPtr = eventPtr;      processor = errorProcessor;      return XML_STATUS_ERROR;    }    else {      switch (parsing) {      case XML_SUSPENDED:        result = XML_STATUS_SUSPENDED;        break;      case XML_INITIALIZED:      case XML_PARSING:        result = XML_STATUS_OK;        if (isFinal) {          parsing = XML_FINISHED;          return result;        }      }    }    XmlUpdatePosition(encoding, positionPtr, end, &position);/* BEGIN MOZILLA CHANGE (backport of bug fix from Expat trunk) */#if 0    positionPtr = end;#endif/* END MOZILLA CHANGE */    nLeftOver = s + len - end;    if (nLeftOver) {      if (buffer == NULL || nLeftOver > bufferLim - buffer) {        /* FIXME avoid integer overflow */        char *temp;        temp = (buffer == NULL                ? (char *)MALLOC(len * 2)                : (char *)REALLOC(buffer, len * 2));        if (temp == NULL) {          errorCode = XML_ERROR_NO_MEMORY;          return XML_STATUS_ERROR;        }        buffer = temp;        if (!buffer) {          errorCode = XML_ERROR_NO_MEMORY;          eventPtr = eventEndPtr = NULL;          processor = errorProcessor;          return XML_STATUS_ERROR;        }        bufferLim = buffer + len * 2;      }      memcpy(buffer, end, nLeftOver);/* BEGIN MOZILLA CHANGE (backport of bug fix from Expat trunk) */#if 0      bufferPtr = buffer;      bufferEnd = buffer + nLeftOver;    }#else    }    bufferPtr = buffer;    bufferEnd = buffer + nLeftOver;    positionPtr = bufferPtr;    parseEndPtr = bufferEnd;    eventPtr = bufferPtr;    eventEndPtr = bufferPtr;#endif/* END MOZILLA CHANGE */    return result;  }#endif  /* not defined XML_CONTEXT_BYTES */  else {    void *buff = XML_GetBuffer(parser, len);    if (buff == NULL)      return XML_STATUS_ERROR;    else {      memcpy(buff, s, len);      return XML_ParseBuffer(parser, len, isFinal);    }  }}enum XML_Status XMLCALLXML_ParseBuffer(XML_Parser parser, int len, int isFinal){  const char *start;  enum XML_Error result = XML_STATUS_OK;  switch (parsing) {  case XML_SUSPENDED:    errorCode = XML_ERROR_SUSPENDED;    return XML_STATUS_ERROR;  case XML_FINISHED:    errorCode = XML_ERROR_FINISHED;    return XML_STATUS_ERROR;  default:    parsing = XML_PARSING;  }  start = bufferPtr;  positionPtr = start;  bufferEnd += len;  parseEndPtr = bufferEnd;  parseEndByteIndex += len;  finalBuffer = (XML_Bool)isFinal;  errorCode = processor(parser, start, parseEndPtr, &bufferPtr);  if (errorCode != XML_ERROR_NONE) {    eventEndPtr = eventPtr;    processor = errorProcessor;    return XML_STATUS_ERROR;  }  else {    switch (parsing) {    case XML_SUSPENDED:      result = XML_STATUS_SUSPENDED;      break;    case XML_INITIALIZED:     case XML_PARSING:      if (isFinal) {        parsing = XML_FINISHED;        return result;      }    default: ;  /* should not happen */    }  }  XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);  positionPtr = bufferPtr;  return result;}void * XMLCALLXML_GetBuffer(XML_Parser parser, int len){  switch (parsing) {  case XML_SUSPENDED:    errorCode = XML_ERROR_SUSPENDED;    return NULL;  case XML_FINISHED:    errorCode = XML_ERROR_FINISHED;    return NULL;  default: ;  }  if (len > bufferLim - bufferEnd) {    /* FIXME avoid integer overflow */    int neededSize = len + (bufferEnd - bufferPtr);#ifdef XML_CONTEXT_BYTES    int keep = bufferPtr - buffer;    if (keep > XML_CONTEXT_BYTES)      keep = XML_CONTEXT_BYTES;    neededSize += keep;#endif  /* defined XML_CONTEXT_BYTES */    if (neededSize  <= bufferLim - buffer) {#ifdef XML_CONTEXT_BYTES      if (keep < bufferPtr - buffer) {        int offset = (bufferPtr - buffer) - keep;        memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);        bufferEnd -= offset;        bufferPtr -= offset;      }#else      memmove(buffer, bufferPtr, bufferEnd - bufferPtr);      bufferEnd = buffer + (bufferEnd - bufferPtr);      bufferPtr = buffer;#endif  /* not defined XML_CONTEXT_BYTES */    }    else {      char *newBuf;      int bufferSize = bufferLim - bufferPtr;      if (bufferSize == 0)        bufferSize = INIT_BUFFER_SIZE;      do {        bufferSize *= 2;      } while (bufferSize < neededSize);      newBuf = (char *)MALLOC(bufferSize);      if (newBuf == 0) {        errorCode = XML_ERROR_NO_MEMORY;        return NULL;      }      bufferLim = newBuf + bufferSize;#ifdef XML_CONTEXT_BYTES      if (bufferPtr) {        int keep = bufferPtr - buffer;        if (keep > XML_CONTEXT_BYTES)          keep = XML_CONTEXT_BYTES;        memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep);        FREE(buffer);        buffer = newBuf;        bufferEnd = buffer + (bufferEnd - bufferPtr) + keep;        bufferPtr = buffer + keep;      }      else {        bufferEnd = newBuf + (bufferEnd - bufferPtr);        bufferPtr = buffer = newBuf;      }#else      if (bufferPtr) {        memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr);        FREE(buffer);      }      bufferEnd = newBuf + (bufferEnd - bufferPtr);      bufferPtr = buffer = newBuf;#endif  /* not defined XML_CONTEXT_BYTES */    }  }  return bufferEnd;}enum XML_Status XMLCALLXML_StopParser(XML_Parser parser, XML_Bool resumable){  switch (parsing) {  case XML_SUSPENDED:    if (resumable) {      errorCode = XML_ERROR_SUSPENDED;      return XML_STATUS_ERROR;    }    parsing = XML_FINISHED;    break;  case XML_FINISHED:    errorCode = XML_ERROR_FINISHED;    return XML_STATUS_ERROR;  default:    if (resumable) {#ifdef XML_DTD      if (isParamEntity) {        errorCode = XML_ERROR_SUSPEND_PE;        return XML_STATUS_ERROR;      }#endif      parsing = XML_SUSPENDED;    }    else      parsing = XML_FINISHED;  }  return XML_STATUS_OK;}enum XML_Status XMLCALLXML_ResumeParser(XML_Parser parser){  enum XML_Error result = XML_STATUS_OK;  if (parsing != XML_SUSPENDED) {    errorCode = XML_ERROR_NOT_SUSPENDED;    return XML_STATUS_ERROR;  }  parsing = XML_PARSING;  errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);  if (errorCode != XML_ERROR_NONE) {    eventEndPtr = eventPtr;    processor = errorProcessor;    return XML_STATUS_ERROR;  }  else {    switch (parsing) {    case XML_SUSPENDED:      result = XML_STATUS_SUSPENDED;      break;    case XML_INITIALIZED:     case XML_PARSING:      if (finalBuffer) {        parsing = XML_FINISHED;        return result;      }    default: ;    }  }  XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);  positionPtr = bufferPtr;  return result;}void XMLCALLXML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status){  assert(status != NULL);  *status = parser->m_parsingStatus;}enum XML_Error XMLCALLXML_GetErrorCode(XML_Parser parser){  return errorCode;}long XMLCALLXML_GetCurrentByteIndex(XML_Parser parser){  if (eventPtr)    return parseEndByteIndex - (parseEndPtr - eventPtr);  return -1;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0int XMLCALLXML_GetCurrentByteCount(XML_Parser parser){  if (eventEndPtr && eventPtr)    return eventEndPtr - eventPtr;  return 0;}const char * XMLCALLXML_GetInputContext(XML_Parser parser, int *offset, int *size){#ifdef XML_CONTEXT_BYTES  if (eventPtr && buffer) {    *offset = eventPtr - buffer;    *size   = bufferEnd - buffer;    return buffer;  }#endif /* defined XML_CONTEXT_BYTES */  return (char *) 0;}#endif/* END MOZILLA CHANGE */int XMLCALLXML_GetCurrentLineNumber(XML_Parser parser){  if (eventPtr && eventPtr >= positionPtr) {    XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);    positionPtr = eventPtr;  }  return position.lineNumber + 1;}int XMLCALLXML_GetCurrentColumnNumber(XML_Parser parser){  if (eventPtr && eventPtr >= positionPtr) {    XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);    positionPtr = eventPtr;  }  return position.columnNumber;}/* BEGIN MOZILLA CHANGE (unused API) */#if 0void XMLCALLXML_FreeContentModel(XML_Parser parser, XML_Content *model){  FREE(model);}void * XMLCALLXML_MemMalloc(XML_Parser parser, size_t size){  return MALLOC(size);}void * XMLCALLXML_MemRealloc(XML_Parser parser, void *ptr, size_t size){  return REALLOC(ptr, size);}void XMLCALLXML_MemFree(XML_Parser parser, void *ptr){  FREE(ptr);}void XMLCALLXML_DefaultCurrent(XML_Parser parser){  if (defaultHandler) {    if (openInternalEntities)      reportDefault(parser,                    internalEncoding,                    openInternalEntities->internalEventPtr,                    openInternalEntities->internalEventEndPtr);    else      reportDefault(parser, encoding, eventPtr, eventEndPtr);  }}#endif#ifdef TX_EXEconst XML_LChar * XMLCALLXML_ErrorString(enum XML_Error code){  static const XML_LChar *message[] = {    0,    XML_L("out of memory"),    XML_L("syntax error"),    XML_L("no element found"),    XML_L("not well-formed (invalid token)"),    XML_L("unclosed token"),    XML_L("partial character"),    XML_L("mismatched tag"),    XML_L("duplicate attribute"),    XML_L("junk after document element"),    XML_L("illegal parameter entity reference"),    XML_L("undefined entity"),    XML_L("recursive entity reference"),    XML_L("asynchronous entity"),    XML_L("reference to invalid character number"),    XML_L("reference to binary entity"),    XML_L("reference to external entity in attribute"),    XML_L("xml declaration not at start of external entity"),    XML_L("unknown encoding"),    XML_L("encoding specified in XML declaration is incorrect"),    XML_L("unclosed CDATA section"),    XML_L("error in processing external entity reference"),    XML_L("document is not standalone"),    XML_L("unexpected parser state - please send a bug report"),    XML_L("entity declared in parameter entity"),    XML_L("requested feature requires XML_DTD support in Expat"),    XML_L("cannot change setting once parsing has begun"),    XML_L("unbound prefix"),    XML_L("must not undeclare prefix"),    XML_L("incomplete markup in parameter entity"),    XML_L("XML declaration not well-formed"),    XML_L("text declaration not well-formed"),    XML_L("illegal character(s) in public id"),    XML_L("parser suspended"),    XML_L("parser not suspended"),    XML_L("parsing aborted"),    XML_L("parsing finished"),    XML_L("cannot suspend in external parameter entity")  };  if (code > 0 && code < sizeof(message)/sizeof(message[0]))    return message[code];  return NULL;}#endif#if 0const XML_LChar * XMLCALLXML_ExpatVersion(void) {  /* V1 is used to string-ize the version number. However, it would     string-ize the actual version macro *names* unless we get them     substituted before being passed to V1. CPP is defined to expand     a macro, then rescan for more expansions. Thus, we use V2 to expand     the version macros, then CPP will expand the resulting V1() macro     with the correct numerals. */  /* ### I'm assuming cpp is portable in this respect... */#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c)#define V2(a,b,c) XML_L("expat_")V1(a,b,c)  return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION);#undef V1#undef V2}XML_Expat_Version XMLCALLXML_ExpatVersionInfo(void){  XML_Expat_Version version;  version.major = XML_MAJOR_VERSION;  version.minor = XML_MINOR_VERSION;  version.micro = XML_MICRO_VERSION;  return version;}const XML_Feature * XMLCALLXML_GetFeatureList(void){  static XML_Feature features[] = {    {XML_FEATURE_SIZEOF_XML_CHAR,  XML_L("sizeof(XML_Char)"), 0},    {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), 0},#ifdef XML_UNICODE    {XML_FEATURE_UNICODE,          XML_L("XML_UNICODE"), 0},#endif#ifdef XML_UNICODE_WCHAR_T    {XML_FEATURE_UNICODE_WCHAR_T,  XML_L("XML_UNICODE_WCHAR_T"), 0},#endif#ifdef XML_DTD    {XML_FEATURE_DTD,              XML_L("XML_DTD"), 0},#endif#ifdef XML_CONTEXT_BYTES    {XML_FEATURE_CONTEXT_BYTES,    XML_L("XML_CONTEXT_BYTES"),     XML_CONTEXT_BYTES},#endif#ifdef XML_MIN_SIZE    {XML_FEATURE_MIN_SIZE,         XML_L("XML_MIN_SIZE"), 0},#endif    {XML_FEATURE_END,              NULL, 0}  };  features[0].value = sizeof(XML_Char);  features[1].value = sizeof(XML_LChar);  return features;}#endif/* END MOZILLA CHANGE *//* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */const XML_Char * XMLCALLMOZ_XML_GetMismatchedTag(XML_Parser parser){  return mismatch;}/* END MOZILLA CHANGE *//* Initially tag->rawName always points into the parse buffer;   for those TAG instances opened while the current parse buffer was   processed, and not yet closed, we need to store tag->rawName in a more   permanent location, since the parse buffer is about to be discarded.*/static XML_BoolstoreRawNames(XML_Parser parser){  TAG *tag = tagStack;  while (tag) {    int bufSize;    int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1);    char *rawNameBuf = tag->buf + nameLen;    /* Stop if already stored.  Since tagStack is a stack, we can stop       at the first entry that has already been copied; everything       below it in the stack is already been accounted for in a       previous call to this function.    */    if (tag->rawName == rawNameBuf)      break;    /* For re-use purposes we need to ensure that the       size of tag->buf is a multiple of sizeof(XML_Char).    */    bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char));    if (bufSize > tag->bufEnd - tag->buf) {      char *temp = (char *)REALLOC(tag->buf, bufSize);      if (temp == NULL)        return XML_FALSE;      /* if tag->name.str points to tag->buf (only when namespace         processing is off) then we have to update it      */      if (tag->name.str == (XML_Char *)tag->buf)        tag->name.str = (XML_Char *)temp;      /* if tag->name.localPart is set (when namespace processing is on)         then update it as well, since it will always point into tag->buf      */      if (tag->name.localPart)        tag->name.localPart = (XML_Char *)temp + (tag->name.localPart -                                                  (XML_Char *)tag->buf);      tag->buf = temp;      tag->bufEnd = temp + bufSize;      rawNameBuf = temp + nameLen;    }    memcpy(rawNameBuf, tag->rawName, tag->rawNameLength);    tag->rawName = rawNameBuf;    tag = tag->parent;  }  return XML_TRUE;}static enum XML_Error PTRCALLcontentProcessor(XML_Parser parser,                 const char *start,                 const char *end,                 const char **endPtr){  enum XML_Error result = doContent(parser, 0, encoding, start, end,                                     endPtr, (XML_Bool)!finalBuffer);  if (result == XML_ERROR_NONE) {    if (!storeRawNames(parser))      return XML_ERROR_NO_MEMORY;  }  return result;}static enum XML_Error PTRCALLexternalEntityInitProcessor(XML_Parser parser,                            const char *start,                            const char *end,                            const char **endPtr){  enum XML_Error result = initializeEncoding(parser);  if (result != XML_ERROR_NONE)    return result;  processor = externalEntityInitProcessor2;  return externalEntityInitProcessor2(parser, start, end, endPtr);}static enum XML_Error PTRCALLexternalEntityInitProcessor2(XML_Parser parser,                             const char *start,                             const char *end,                             const char **endPtr){  const char *next = start; /* XmlContentTok doesn't always set the last arg */  int tok = XmlContentTok(encoding, start, end, &next);  switch (tok) {  case XML_TOK_BOM:    /* If we are at the end of the buffer, this would cause the next stage,       i.e. externalEntityInitProcessor3, to pass control directly to       doContent (by detecting XML_TOK_NONE) without processing any xml text       declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent.    */    if (next == end && !finalBuffer) {      *endPtr = next;      return XML_ERROR_NONE;    }    start = next;    break;  case XML_TOK_PARTIAL:    if (!finalBuffer) {      *endPtr = start;      return XML_ERROR_NONE;    }    eventPtr = start;    return XML_ERROR_UNCLOSED_TOKEN;  case XML_TOK_PARTIAL_CHAR:    if (!finalBuffer) {      *endPtr = start;      return XML_ERROR_NONE;    }    eventPtr = start;    return XML_ERROR_PARTIAL_CHAR;  }  processor = externalEntityInitProcessor3;  return externalEntityInitProcessor3(parser, start, end, endPtr);}static enum XML_Error PTRCALLexternalEntityInitProcessor3(XML_Parser parser,                             const char *start,                             const char *end,                             const char **endPtr){  int tok;  const char *next = start; /* XmlContentTok doesn't always set the last arg */  eventPtr = start;  tok = XmlContentTok(encoding, start, end, &next);  eventEndPtr = next;  switch (tok) {  case XML_TOK_XML_DECL:    {      enum XML_Error result;      result = processXmlDecl(parser, 1, start, next);      if (result != XML_ERROR_NONE)        return result;      switch (parsing) {      case XML_SUSPENDED:         *endPtr = next;        return XML_ERROR_NONE;      case XML_FINISHED:        return XML_ERROR_ABORTED;      default:        start = next;      }    }    break;  case XML_TOK_PARTIAL:    if (!finalBuffer) {      *endPtr = start;      return XML_ERROR_NONE;    }    return XML_ERROR_UNCLOSED_TOKEN;  case XML_TOK_PARTIAL_CHAR:    if (!finalBuffer) {      *endPtr = start;      return XML_ERROR_NONE;    }    return XML_ERROR_PARTIAL_CHAR;  }  processor = externalEntityContentProcessor;  tagLevel = 1;  return externalEntityContentProcessor(parser, start, end, endPtr);}static enum XML_Error PTRCALLexternalEntityContentProcessor(XML_Parser parser,                               const char *start,                               const char *end,                               const char **endPtr){  enum XML_Error result = doContent(parser, 1, encoding, start, end,                                     endPtr, (XML_Bool)!finalBuffer);  if (result == XML_ERROR_NONE) {    if (!storeRawNames(parser))      return XML_ERROR_NO_MEMORY;  }  return result;}static enum XML_ErrordoContent(XML_Parser parser,          int startTagLevel,          const ENCODING *enc,          const char *s,          const char *end,          const char **nextPtr,          XML_Bool haveMore){  /* save one level of indirection */  DTD * const dtd = _dtd;    const char **eventPP;  const char **eventEndPP;  if (enc == encoding) {    eventPP = &eventPtr;    eventEndPP = &eventEndPtr;  }  else {    eventPP = &(openInternalEntities->internalEventPtr);    eventEndPP = &(openInternalEntities->internalEventEndPtr);  }  *eventPP = s;  for (;;) {    const char *next = s; /* XmlContentTok doesn't always set the last arg */    int tok = XmlContentTok(enc, s, end, &next);    *eventEndPP = next;    switch (tok) {    case XML_TOK_TRAILING_CR:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      *eventEndPP = end;      if (characterDataHandler) {        XML_Char c = 0xA;        characterDataHandler(handlerArg, &c, 1);      }      else if (defaultHandler)        reportDefault(parser, enc, s, end);      /* We are at the end of the final buffer, should we check for          XML_SUSPENDED, XML_FINISHED?       */      if (startTagLevel == 0)        return XML_ERROR_NO_ELEMENTS;      if (tagLevel != startTagLevel)        return XML_ERROR_ASYNC_ENTITY;      *nextPtr = end;      return XML_ERROR_NONE;    case XML_TOK_NONE:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      if (startTagLevel > 0) {        if (tagLevel != startTagLevel)          return XML_ERROR_ASYNC_ENTITY;        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_NO_ELEMENTS;    case XML_TOK_INVALID:      *eventPP = next;      return XML_ERROR_INVALID_TOKEN;    case XML_TOK_PARTIAL:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_UNCLOSED_TOKEN;    case XML_TOK_PARTIAL_CHAR:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_PARTIAL_CHAR;    case XML_TOK_ENTITY_REF:      {        const XML_Char *name;        ENTITY *entity;        XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc,                                              s + enc->minBytesPerChar,                                              next - enc->minBytesPerChar);        if (ch) {          if (characterDataHandler)            characterDataHandler(handlerArg, &ch, 1);          else if (defaultHandler)            reportDefault(parser, enc, s, next);          break;        }        name = poolStoreString(&dtd->pool, enc,                                s + enc->minBytesPerChar,                                next - enc->minBytesPerChar);        if (!name)          return XML_ERROR_NO_MEMORY;        entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0);        poolDiscard(&dtd->pool);        /* First, determine if a check for an existing declaration is needed;           if yes, check that the entity exists, and that it is internal,           otherwise call the skipped entity or default handler.        */        if (!dtd->hasParamEntityRefs || dtd->standalone) {          if (!entity)            return XML_ERROR_UNDEFINED_ENTITY;          else if (!entity->is_internal)            return XML_ERROR_ENTITY_DECLARED_IN_PE;        }        else if (!entity) {          if (skippedEntityHandler)            skippedEntityHandler(handlerArg, name, 0);/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=35984) */#if 0          else if (defaultHandler)            reportDefault(parser, enc, s, next);          break;#else          return XML_ERROR_UNDEFINED_ENTITY;#endif/* END MOZILLA CHANGE */        }        if (entity->open)          return XML_ERROR_RECURSIVE_ENTITY_REF;        if (entity->notation)          return XML_ERROR_BINARY_ENTITY_REF;        if (entity->textPtr) {          enum XML_Error result;          if (!defaultExpandInternalEntities) {            if (skippedEntityHandler)              skippedEntityHandler(handlerArg, entity->name, 0);            else if (defaultHandler)              reportDefault(parser, enc, s, next);            break;          }          result = processInternalEntity(parser, entity, XML_FALSE);          if (result != XML_ERROR_NONE)            return result;        }        else if (externalEntityRefHandler) {          const XML_Char *context;          entity->open = XML_TRUE;          context = getContext(parser);          entity->open = XML_FALSE;          if (!context)            return XML_ERROR_NO_MEMORY;          if (!externalEntityRefHandler(externalEntityRefHandlerArg,                                        context,                                        entity->base,                                        entity->systemId,                                        entity->publicId))            return XML_ERROR_EXTERNAL_ENTITY_HANDLING;          poolDiscard(&tempPool);        }        else if (defaultHandler)          reportDefault(parser, enc, s, next);        break;      }    case XML_TOK_START_TAG_NO_ATTS:      /* fall through */    case XML_TOK_START_TAG_WITH_ATTS:      {        TAG *tag;        enum XML_Error result;        XML_Char *toPtr;        if (freeTagList) {          tag = freeTagList;          freeTagList = freeTagList->parent;        }        else {          tag = (TAG *)MALLOC(sizeof(TAG));          if (!tag)            return XML_ERROR_NO_MEMORY;          tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE);          if (!tag->buf) {            FREE(tag);            return XML_ERROR_NO_MEMORY;          }          tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;        }        tag->bindings = NULL;        tag->parent = tagStack;        tagStack = tag;        tag->name.localPart = NULL;        tag->name.prefix = NULL;        tag->rawName = s + enc->minBytesPerChar;        tag->rawNameLength = XmlNameLength(enc, tag->rawName);        ++tagLevel;        {          const char *rawNameEnd = tag->rawName + tag->rawNameLength;          const char *fromPtr = tag->rawName;          toPtr = (XML_Char *)tag->buf;          for (;;) {            int bufSize;            int convLen;            XmlConvert(enc,                       &fromPtr, rawNameEnd,                       (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);            convLen = toPtr - (XML_Char *)tag->buf;            if (fromPtr == rawNameEnd) {              tag->name.strLen = convLen;              break;            }            bufSize = (tag->bufEnd - tag->buf) << 1;            {              char *temp = (char *)REALLOC(tag->buf, bufSize);              if (temp == NULL)                return XML_ERROR_NO_MEMORY;              tag->buf = temp;              tag->bufEnd = temp + bufSize;              toPtr = (XML_Char *)temp + convLen;            }          }        }        tag->name.str = (XML_Char *)tag->buf;        *toPtr = XML_T('\0');        result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));        if (result)          return result;        if (startElementHandler)          startElementHandler(handlerArg, tag->name.str,                              (const XML_Char **)atts);        else if (defaultHandler)          reportDefault(parser, enc, s, next);        poolClear(&tempPool);        break;      }    case XML_TOK_EMPTY_ELEMENT_NO_ATTS:      /* fall through */    case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:      {        const char *rawName = s + enc->minBytesPerChar;        enum XML_Error result;        BINDING *bindings = NULL;        XML_Bool noElmHandlers = XML_TRUE;        TAG_NAME name;        name.str = poolStoreString(&tempPool, enc, rawName,                                   rawName + XmlNameLength(enc, rawName));        if (!name.str)          return XML_ERROR_NO_MEMORY;        poolFinish(&tempPool);        result = storeAtts(parser, enc, s, &name, &bindings);        if (result)          return result;        poolFinish(&tempPool);        if (startElementHandler) {          startElementHandler(handlerArg, name.str, (const XML_Char **)atts);          noElmHandlers = XML_FALSE;        }        if (endElementHandler) {          if (startElementHandler)            *eventPP = *eventEndPP;          endElementHandler(handlerArg, name.str);          noElmHandlers = XML_FALSE;        }        if (noElmHandlers && defaultHandler)          reportDefault(parser, enc, s, next);        poolClear(&tempPool);        while (bindings) {          BINDING *b = bindings;          if (endNamespaceDeclHandler)            endNamespaceDeclHandler(handlerArg, b->prefix->name);          bindings = bindings->nextTagBinding;          b->nextTagBinding = freeBindingList;          freeBindingList = b;          b->prefix->binding = b->prevPrefixBinding;        }      }      if (tagLevel == 0)        return epilogProcessor(parser, next, end, nextPtr);      break;    case XML_TOK_END_TAG:      if (tagLevel == startTagLevel)        return XML_ERROR_ASYNC_ENTITY;      else {        int len;        const char *rawName;        TAG *tag = tagStack;        tagStack = tag->parent;        tag->parent = freeTagList;        freeTagList = tag;        rawName = s + enc->minBytesPerChar*2;        len = XmlNameLength(enc, rawName);        if (len != tag->rawNameLength            || memcmp(tag->rawName, rawName, len) != 0) {/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */	  /* This code is copied from the |if (endElementHandler)| block below */          const XML_Char *localPart;          const XML_Char *prefix;          XML_Char *uri;          localPart = tag->name.localPart;          if (ns && localPart) {            /* localPart and prefix may have been overwritten in               tag->name.str, since this points to the binding->uri               buffer which gets re-used; so we have to add them again            */            uri = (XML_Char *)tag->name.str + tag->name.uriLen;            /* don't need to check for space - already done in storeAtts() */            while (*localPart) *uri++ = *localPart++;            prefix = (XML_Char *)tag->name.prefix;            if (ns_triplets && prefix) {              *uri++ = namespaceSeparator;              while (*prefix) *uri++ = *prefix++;             }            *uri = XML_T('\0');          }          mismatch = tag->name.str;/* END MOZILLA CHANGE */          *eventPP = rawName;          return XML_ERROR_TAG_MISMATCH;        }        --tagLevel;        if (endElementHandler) {          const XML_Char *localPart;          const XML_Char *prefix;          XML_Char *uri;          localPart = tag->name.localPart;          if (ns && localPart) {            /* localPart and prefix may have been overwritten in               tag->name.str, since this points to the binding->uri               buffer which gets re-used; so we have to add them again            */            uri = (XML_Char *)tag->name.str + tag->name.uriLen;            /* don't need to check for space - already done in storeAtts() */            while (*localPart) *uri++ = *localPart++;            prefix = (XML_Char *)tag->name.prefix;            if (ns_triplets && prefix) {              *uri++ = namespaceSeparator;              while (*prefix) *uri++ = *prefix++;             }            *uri = XML_T('\0');          }          endElementHandler(handlerArg, tag->name.str);        }        else if (defaultHandler)          reportDefault(parser, enc, s, next);        while (tag->bindings) {          BINDING *b = tag->bindings;          if (endNamespaceDeclHandler)            endNamespaceDeclHandler(handlerArg, b->prefix->name);          tag->bindings = tag->bindings->nextTagBinding;          b->nextTagBinding = freeBindingList;          freeBindingList = b;          b->prefix->binding = b->prevPrefixBinding;        }        if (tagLevel == 0)          return epilogProcessor(parser, next, end, nextPtr);      }      break;    case XML_TOK_CHAR_REF:      {        int n = XmlCharRefNumber(enc, s);        if (n < 0)          return XML_ERROR_BAD_CHAR_REF;        if (characterDataHandler) {          XML_Char buf[XML_ENCODE_MAX];          characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf));        }        else if (defaultHandler)          reportDefault(parser, enc, s, next);      }      break;    case XML_TOK_XML_DECL:      return XML_ERROR_MISPLACED_XML_PI;    case XML_TOK_DATA_NEWLINE:      if (characterDataHandler) {        XML_Char c = 0xA;        characterDataHandler(handlerArg, &c, 1);      }      else if (defaultHandler)        reportDefault(parser, enc, s, next);      break;    case XML_TOK_CDATA_SECT_OPEN:      {        enum XML_Error result;        if (startCdataSectionHandler)          startCdataSectionHandler(handlerArg);#if 0        /* Suppose you doing a transformation on a document that involves           changing only the character data.  You set up a defaultHandler           and a characterDataHandler.  The defaultHandler simply copies           characters through.  The characterDataHandler does the           transformation and writes the characters out escaping them as           necessary.  This case will fail to work if we leave out the           following two lines (because & and < inside CDATA sections will           be incorrectly escaped).           However, now we have a start/endCdataSectionHandler, so it seems           easier to let the user deal with this.        */        else if (characterDataHandler)          characterDataHandler(handlerArg, dataBuf, 0);#endif        else if (defaultHandler)          reportDefault(parser, enc, s, next);        result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore);        if (result != XML_ERROR_NONE)          return result;        else if (!next) {          processor = cdataSectionProcessor;          return result;        }      }      break;    case XML_TOK_TRAILING_RSQB:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      if (characterDataHandler) {        if (MUST_CONVERT(enc, s)) {          ICHAR *dataPtr = (ICHAR *)dataBuf;          XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);          characterDataHandler(handlerArg, dataBuf,                               dataPtr - (ICHAR *)dataBuf);        }        else          characterDataHandler(handlerArg,                               (XML_Char *)s,                               (XML_Char *)end - (XML_Char *)s);      }      else if (defaultHandler)        reportDefault(parser, enc, s, end);      /* We are at the end of the final buffer, should we check for          XML_SUSPENDED, XML_FINISHED?       */      if (startTagLevel == 0) {        *eventPP = end;        return XML_ERROR_NO_ELEMENTS;      }      if (tagLevel != startTagLevel) {        *eventPP = end;        return XML_ERROR_ASYNC_ENTITY;      }      *nextPtr = end;      return XML_ERROR_NONE;    case XML_TOK_DATA_CHARS:      if (characterDataHandler) {        if (MUST_CONVERT(enc, s)) {          for (;;) {            ICHAR *dataPtr = (ICHAR *)dataBuf;            XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);            *eventEndPP = s;            characterDataHandler(handlerArg, dataBuf,                                 dataPtr - (ICHAR *)dataBuf);            if (s == next)              break;            *eventPP = s;          }        }        else          characterDataHandler(handlerArg,                               (XML_Char *)s,                               (XML_Char *)next - (XML_Char *)s);      }      else if (defaultHandler)        reportDefault(parser, enc, s, next);      break;    case XML_TOK_PI:      if (!reportProcessingInstruction(parser, enc, s, next))        return XML_ERROR_NO_MEMORY;      break;    case XML_TOK_COMMENT:      if (!reportComment(parser, enc, s, next))        return XML_ERROR_NO_MEMORY;      break;    default:      if (defaultHandler)        reportDefault(parser, enc, s, next);      break;    }    *eventPP = s = next;    switch (parsing) {    case XML_SUSPENDED:       *nextPtr = next;      return XML_ERROR_NONE;    case XML_FINISHED:      return XML_ERROR_ABORTED;    default: ;    }  }  /* not reached */}/* Precondition: all arguments must be non-NULL;   Purpose:   - normalize attributes   - check attributes for well-formedness   - generate namespace aware attribute names (URI, prefix)   - build list of attributes for startElementHandler   - default attributes   - process namespace declarations (check and report them)   - generate namespace aware element name (URI, prefix)*/static enum XML_ErrorstoreAtts(XML_Parser parser, const ENCODING *enc,          const char *attStr, TAG_NAME *tagNamePtr,          BINDING **bindingsPtr){  DTD * const dtd = _dtd;  /* save one level of indirection */  ELEMENT_TYPE *elementType;  int nDefaultAtts;  const XML_Char **appAtts;   /* the attribute list for the application */  int attIndex = 0;  int prefixLen;  int i;  int n;  XML_Char *uri;  int nPrefixes = 0;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */  int nXMLNSDeclarations = 0;/* END MOZILLA CHANGE */  BINDING *binding;  const XML_Char *localPart;  /* lookup the element type name */  elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0);  if (!elementType) {    const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);    if (!name)      return XML_ERROR_NO_MEMORY;    elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name,                                         sizeof(ELEMENT_TYPE));    if (!elementType)      return XML_ERROR_NO_MEMORY;    if (ns && !setElementTypePrefix(parser, elementType))      return XML_ERROR_NO_MEMORY;  }  nDefaultAtts = elementType->nDefaultAtts;  /* get the attributes from the tokenizer */  n = XmlGetAttributes(enc, attStr, attsSize, atts);  if (n + nDefaultAtts > attsSize) {    int oldAttsSize = attsSize;    ATTRIBUTE *temp;    attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;    temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));    if (temp == NULL)      return XML_ERROR_NO_MEMORY;    atts = temp;    if (n > oldAttsSize)      XmlGetAttributes(enc, attStr, n, atts);  }  appAtts = (const XML_Char **)atts;  for (i = 0; i < n; i++) {    /* add the name and value to the attribute list */    ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name,                                         atts[i].name                                         + XmlNameLength(enc, atts[i].name));    if (!attId)      return XML_ERROR_NO_MEMORY;    /* Detect duplicate attributes by their QNames. This does not work when       namespace processing is turned on and different prefixes for the same       namespace are used. For this case we have a check further down.    */    if ((attId->name)[-1]) {      if (enc == encoding)        eventPtr = atts[i].name;      return XML_ERROR_DUPLICATE_ATTRIBUTE;    }    (attId->name)[-1] = 1;    appAtts[attIndex++] = attId->name;    if (!atts[i].normalized) {      enum XML_Error result;      XML_Bool isCdata = XML_TRUE;      /* figure out whether declared as other than CDATA */      if (attId->maybeTokenized) {        int j;        for (j = 0; j < nDefaultAtts; j++) {          if (attId == elementType->defaultAtts[j].id) {            isCdata = elementType->defaultAtts[j].isCdata;            break;          }        }      }      /* normalize the attribute value */      result = storeAttributeValue(parser, enc, isCdata,                                   atts[i].valuePtr, atts[i].valueEnd,                                   &tempPool);      if (result)        return result;      appAtts[attIndex] = poolStart(&tempPool);      poolFinish(&tempPool);    }    else {      /* the value did not need normalizing */      appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr,                                          atts[i].valueEnd);      if (appAtts[attIndex] == 0)        return XML_ERROR_NO_MEMORY;      poolFinish(&tempPool);    }    /* handle prefixed attribute names */    if (attId->prefix) {      if (attId->xmlns) {        /* deal with namespace declarations here */        enum XML_Error result = addBinding(parser, attId->prefix, attId,                                           appAtts[attIndex], bindingsPtr);        if (result)          return result;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */#if 0        --attIndex;#else        attIndex++;        nXMLNSDeclarations++;        (attId->name)[-1] = 3;#endif/* END MOZILLA CHANGE */      }      else {        /* deal with other prefixed names later */        attIndex++;        nPrefixes++;        (attId->name)[-1] = 2;      }    }    else      attIndex++;  }  /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */  nSpecifiedAtts = attIndex;  if (elementType->idAtt && (elementType->idAtt->name)[-1]) {    for (i = 0; i < attIndex; i += 2)      if (appAtts[i] == elementType->idAtt->name) {        idAttIndex = i;        break;      }  }  else    idAttIndex = -1;  /* do attribute defaulting */  for (i = 0; i < nDefaultAtts; i++) {    const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i;    if (!(da->id->name)[-1] && da->value) {      if (da->id->prefix) {        if (da->id->xmlns) {          enum XML_Error result = addBinding(parser, da->id->prefix, da->id,                                             da->value, bindingsPtr);          if (result)            return result;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */          (da->id->name)[-1] = 3;          nXMLNSDeclarations++;          appAtts[attIndex++] = da->id->name;          appAtts[attIndex++] = da->value;/* END MOZILLA CHANGE */        }        else {          (da->id->name)[-1] = 2;          nPrefixes++;          appAtts[attIndex++] = da->id->name;          appAtts[attIndex++] = da->value;        }      }      else {        (da->id->name)[-1] = 1;        appAtts[attIndex++] = da->id->name;        appAtts[attIndex++] = da->value;      }    }  }  appAtts[attIndex] = 0;  /* expand prefixed attribute names, check for duplicates,     and clear flags that say whether attributes were specified */  i = 0;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */#if 0  if (nPrefixes) {#else  if (nPrefixes || nXMLNSDeclarations) {#endif/* END MOZILLA CHANGE */    int j;  /* hash table index */    unsigned long version = nsAttsVersion;    int nsAttsSize = (int)1 << nsAttsPower;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */    if (nPrefixes) {/* END MOZILLA CHANGE */    /* size of hash table must be at least 2 * (# of prefixed attributes) */    if ((nPrefixes << 1) >> nsAttsPower) {  /* true for nsAttsPower = 0 */      NS_ATT *temp;      /* hash table size must also be a power of 2 and >= 8 */      while (nPrefixes >> nsAttsPower++);      if (nsAttsPower < 3)        nsAttsPower = 3;      nsAttsSize = (int)1 << nsAttsPower;      temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT));      if (!temp)        return XML_ERROR_NO_MEMORY;      nsAtts = temp;      version = 0;  /* force re-initialization of nsAtts hash table */    }    /* using a version flag saves us from initializing nsAtts every time */    if (!version) {  /* initialize version flags when version wraps around */      version = INIT_ATTS_VERSION;      for (j = nsAttsSize; j != 0; )        nsAtts[--j].version = version;    }    nsAttsVersion = --version;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */    }/* END MOZILLA CHANGE */    /* expand prefixed names and check for duplicates */    for (; i < attIndex; i += 2) {      const XML_Char *s = appAtts[i];      if (s[-1] == 2) {  /* prefixed */        ATTRIBUTE_ID *id;        const BINDING *b;        unsigned long uriHash = 0;        ((XML_Char *)s)[-1] = 0;  /* clear flag */        id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0);        b = id->prefix->binding;        if (!b)          return XML_ERROR_UNBOUND_PREFIX;        /* as we expand the name we also calculate its hash value */        for (j = 0; j < b->uriLen; j++) {          const XML_Char c = b->uri[j];          if (!poolAppendChar(&tempPool, c))            return XML_ERROR_NO_MEMORY;          uriHash = CHAR_HASH(uriHash, c);        }        while (*s++ != XML_T(':'))          ;        do {  /* copies null terminator */          const XML_Char c = *s;          if (!poolAppendChar(&tempPool, *s))            return XML_ERROR_NO_MEMORY;          uriHash = CHAR_HASH(uriHash, c);        } while (*s++);        { /* Check hash table for duplicate of expanded name (uriName).             Derived from code in lookup(HASH_TABLE *table, ...).          */          unsigned char step = 0;          unsigned long mask = nsAttsSize - 1;          j = uriHash & mask;  /* index into hash table */          while (nsAtts[j].version == version) {            /* for speed we compare stored hash values first */            if (uriHash == nsAtts[j].hash) {              const XML_Char *s1 = poolStart(&tempPool);              const XML_Char *s2 = nsAtts[j].uriName;              /* s1 is null terminated, but not s2 */              for (; *s1 == *s2 && *s1 != 0; s1++, s2++);              if (*s1 == 0)                return XML_ERROR_DUPLICATE_ATTRIBUTE;            }            if (!step)              step = PROBE_STEP(uriHash, mask, nsAttsPower);            j < step ? ( j += nsAttsSize - step) : (j -= step);          }        }        if (ns_triplets) {  /* append namespace separator and prefix */          tempPool.ptr[-1] = namespaceSeparator;          s = b->prefix->name;          do {            if (!poolAppendChar(&tempPool, *s))              return XML_ERROR_NO_MEMORY;          } while (*s++);        }        /* store expanded name in attribute list */        s = poolStart(&tempPool);        poolFinish(&tempPool);        appAtts[i] = s;        /* fill empty slot with new version, uriName and hash value */        nsAtts[j].version = version;        nsAtts[j].hash = uriHash;        nsAtts[j].uriName = s;/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */#if 0        if (!--nPrefixes)          break;#else        if (!--nPrefixes && !nXMLNSDeclarations) {          i += 2;          break;        }#endif/* END MOZILLA CHANGE */      }/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */      else if (s[-1] == 3) { /* xmlns attribute */        static const XML_Char xmlnsNamespace[] = {          'h', 't', 't', 'p', ':', '/', '/',          'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',          '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0'        };        static const XML_Char xmlnsPrefix[] = {          'x', 'm', 'l', 'n', 's', '\0'        };        XML_Bool appendXMLNS = XML_TRUE;        ((XML_Char *)s)[-1] = 0;  /* clear flag */        if (!poolAppendString(&tempPool, xmlnsNamespace)            || !poolAppendChar(&tempPool, namespaceSeparator))          return XML_ERROR_NO_MEMORY;        s += sizeof(xmlnsPrefix) / sizeof(xmlnsPrefix[0]) - 1;        if (*s == XML_T(':')) {          ++s;          do {  /* copies null terminator */            if (!poolAppendChar(&tempPool, *s))              return XML_ERROR_NO_MEMORY;          } while (*s++);          if (ns_triplets) { /* append namespace separator and prefix */            tempPool.ptr[-1] = namespaceSeparator;            if (!poolAppendString(&tempPool, xmlnsPrefix)                || !poolAppendChar(&tempPool, '\0'))              return XML_ERROR_NO_MEMORY;          }        }        else {          /* xlmns attribute without a prefix. */          if (!poolAppendString(&tempPool, xmlnsPrefix)              || !poolAppendChar(&tempPool, '\0'))            return XML_ERROR_NO_MEMORY;        }        /* store expanded name in attribute list */        s = poolStart(&tempPool);        poolFinish(&tempPool);        appAtts[i] = s;        if (!--nXMLNSDeclarations && !nPrefixes) {          i += 2;          break;        }      }/* END MOZILLA CHANGE */      else  /* not prefixed */        ((XML_Char *)s)[-1] = 0;  /* clear flag */    }  }  /* clear flags for the remaining attributes */  for (; i < attIndex; i += 2)    ((XML_Char *)(appAtts[i]))[-1] = 0;  for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)    binding->attId->name[-1] = 0;  if (!ns)    return XML_ERROR_NONE;  /* expand the element type name */  if (elementType->prefix) {    binding = elementType->prefix->binding;    if (!binding)      return XML_ERROR_UNBOUND_PREFIX;    localPart = tagNamePtr->str;    while (*localPart++ != XML_T(':'))      ;  }  else if (dtd->defaultPrefix.binding) {    binding = dtd->defaultPrefix.binding;    localPart = tagNamePtr->str;  }  else    return XML_ERROR_NONE;  prefixLen = 0;  if (ns_triplets && binding->prefix->name) {    for (; binding->prefix->name[prefixLen++];)      ;  }  tagNamePtr->localPart = localPart;  tagNamePtr->uriLen = binding->uriLen;  tagNamePtr->prefix = binding->prefix->name;  tagNamePtr->prefixLen = prefixLen;  for (i = 0; localPart[i++];)    ;  n = i + binding->uriLen + prefixLen;  if (n > binding->uriAlloc) {    TAG *p;    uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char));    if (!uri)      return XML_ERROR_NO_MEMORY;    binding->uriAlloc = n + EXPAND_SPARE;    memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char));    for (p = tagStack; p; p = p->parent)      if (p->name.str == binding->uri)        p->name.str = uri;    FREE(binding->uri);    binding->uri = uri;  }  uri = binding->uri + binding->uriLen;  memcpy(uri, localPart, i * sizeof(XML_Char));  if (prefixLen) {    uri = uri + (i - 1);    if (namespaceSeparator)      *uri = namespaceSeparator;    memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char));  }  tagNamePtr->str = binding->uri;  return XML_ERROR_NONE;}/* addBinding() overwrites the value of prefix->binding without checking.   Therefore one must keep track of the old value outside of addBinding().*/static enum XML_ErroraddBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,           const XML_Char *uri, BINDING **bindingsPtr){/* BEGIN MOZILLA CHANGE (backport of bug fix from Expat trunk) */  static const XML_Char xmlNamespace[] = {    'h', 't', 't', 'p', ':', '/', '/',    'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',    'X', 'M', 'L', '/', '1', '9', '9', '8', '/',    'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0'  };  static const int xmlLen =     (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1;  static const XML_Char xmlnsNamespace[] = {    'h', 't', 't', 'p', ':', '/', '/',    'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',    '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0'  };  static const int xmlnsLen =     (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1;  XML_Bool mustBeXML = XML_FALSE;  XML_Bool isXML = XML_TRUE;  XML_Bool isXMLNS = XML_TRUE;/* END MOZILLA CHANGE */  BINDING *b;  int len;  /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */  if (*uri == XML_T('\0') && prefix->name)    return XML_ERROR_UNDECLARING_PREFIX;/* BEGIN MOZILLA CHANGE (backport of bug fix from Expat trunk) */  if (prefix->name      && prefix->name[0] == XML_T('x')      && prefix->name[1] == XML_T('m')      && prefix->name[2] == XML_T('l')) {    /* Not allowed to bind xmlns */    if (prefix->name[3] == XML_T('n')        && prefix->name[4] == XML_T('s')        && prefix->name[5] == XML_T('\0'))      return XML_ERROR_RESERVED_PREFIX_XMLNS;    if (prefix->name[3] == XML_T('\0'))      mustBeXML = XML_TRUE;  }  for (len = 0; uri[len]; len++) {    if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))      isXML = XML_FALSE;    if (!mustBeXML && isXMLNS         && (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))      isXMLNS = XML_FALSE;  }  isXML = isXML && len == xmlLen;  isXMLNS = isXMLNS && len == xmlnsLen;  if (mustBeXML != isXML)    return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML                     : XML_ERROR_RESERVED_NAMESPACE_URI;  if (isXMLNS)    return XML_ERROR_RESERVED_NAMESPACE_URI;/* END MOZILLA CHANGE */  if (namespaceSeparator)    len++;  if (freeBindingList) {    b = freeBindingList;    if (len > b->uriAlloc) {      XML_Char *temp = (XML_Char *)REALLOC(b->uri,                          sizeof(XML_Char) * (len + EXPAND_SPARE));      if (temp == NULL)        return XML_ERROR_NO_MEMORY;      b->uri = temp;      b->uriAlloc = len + EXPAND_SPARE;    }    freeBindingList = b->nextTagBinding;  }  else {    b = (BINDING *)MALLOC(sizeof(BINDING));    if (!b)      return XML_ERROR_NO_MEMORY;    b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));    if (!b->uri) {      FREE(b);      return XML_ERROR_NO_MEMORY;    }    b->uriAlloc = len + EXPAND_SPARE;  }  b->uriLen = len;  memcpy(b->uri, uri, len * sizeof(XML_Char));  if (namespaceSeparator)    b->uri[len - 1] = namespaceSeparator;  b->prefix = prefix;  b->attId = attId;  b->prevPrefixBinding = prefix->binding;  /* NULL binding when default namespace undeclared */  if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix)    prefix->binding = NULL;  else    prefix->binding = b;  b->nextTagBinding = *bindingsPtr;  *bindingsPtr = b;  /* if attId == NULL then we are not starting a namespace scope */  if (attId && startNamespaceDeclHandler)    startNamespaceDeclHandler(handlerArg, prefix->name,                              prefix->binding ? uri : 0);  return XML_ERROR_NONE;}/* The idea here is to avoid using stack for each CDATA section when   the whole file is parsed with one call.*/static enum XML_Error PTRCALLcdataSectionProcessor(XML_Parser parser,                      const char *start,                      const char *end,                      const char **endPtr){  enum XML_Error result = doCdataSection(parser, encoding, &start, end,                                         endPtr, (XML_Bool)!finalBuffer);  if (result != XML_ERROR_NONE)    return result;  if (start) {    if (parentParser) {  /* we are parsing an external entity */      processor = externalEntityContentProcessor;      return externalEntityContentProcessor(parser, start, end, endPtr);    }    else {      processor = contentProcessor;      return contentProcessor(parser, start, end, endPtr);    }  }  return result;}/* startPtr gets set to non-null if the section is closed, and to null if   the section is not yet closed.*/static enum XML_ErrordoCdataSection(XML_Parser parser,               const ENCODING *enc,               const char **startPtr,               const char *end,               const char **nextPtr,               XML_Bool haveMore){  const char *s = *startPtr;  const char **eventPP;  const char **eventEndPP;  if (enc == encoding) {    eventPP = &eventPtr;    *eventPP = s;    eventEndPP = &eventEndPtr;  }  else {    eventPP = &(openInternalEntities->internalEventPtr);    eventEndPP = &(openInternalEntities->internalEventEndPtr);  }  *eventPP = s;  *startPtr = NULL;  for (;;) {    const char *next;    int tok = XmlCdataSectionTok(enc, s, end, &next);    *eventEndPP = next;    switch (tok) {    case XML_TOK_CDATA_SECT_CLOSE:      if (endCdataSectionHandler)        endCdataSectionHandler(handlerArg);#if 0      /* see comment under XML_TOK_CDATA_SECT_OPEN */      else if (characterDataHandler)        characterDataHandler(handlerArg, dataBuf, 0);#endif      else if (defaultHandler)        reportDefault(parser, enc, s, next);      *startPtr = next;      *nextPtr = next;      if (parsing == XML_FINISHED)        return XML_ERROR_ABORTED;      else        return XML_ERROR_NONE;    case XML_TOK_DATA_NEWLINE:      if (characterDataHandler) {        XML_Char c = 0xA;        characterDataHandler(handlerArg, &c, 1);      }      else if (defaultHandler)        reportDefault(parser, enc, s, next);      break;    case XML_TOK_DATA_CHARS:      if (characterDataHandler) {        if (MUST_CONVERT(enc, s)) {          for (;;) {            ICHAR *dataPtr = (ICHAR *)dataBuf;            XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);            *eventEndPP = next;            characterDataHandler(handlerArg, dataBuf,                                 dataPtr - (ICHAR *)dataBuf);            if (s == next)              break;            *eventPP = s;          }        }        else          characterDataHandler(handlerArg,                               (XML_Char *)s,                               (XML_Char *)next - (XML_Char *)s);      }      else if (defaultHandler)        reportDefault(parser, enc, s, next);      break;    case XML_TOK_INVALID:      *eventPP = next;      return XML_ERROR_INVALID_TOKEN;    case XML_TOK_PARTIAL_CHAR:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_PARTIAL_CHAR;    case XML_TOK_PARTIAL:    case XML_TOK_NONE:      if (haveMore) {        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_UNCLOSED_CDATA_SECTION;    default:      *eventPP = next;      return XML_ERROR_UNEXPECTED_STATE;    }    *eventPP = s = next;    switch (parsing) {    case XML_SUSPENDED:      *nextPtr = next;      return XML_ERROR_NONE;    case XML_FINISHED:      return XML_ERROR_ABORTED;    default: ;    }  }  /* not reached */}#ifdef XML_DTD/* The idea here is to avoid using stack for each IGNORE section when   the whole file is parsed with one call.*/static enum XML_Error PTRCALLignoreSectionProcessor(XML_Parser parser,                       const char *start,                       const char *end,                       const char **endPtr){  enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,                                           endPtr, (XML_Bool)!finalBuffer);  if (result != XML_ERROR_NONE)    return result;  if (start) {    processor = prologProcessor;    return prologProcessor(parser, start, end, endPtr);  }  return result;}/* startPtr gets set to non-null is the section is closed, and to null   if the section is not yet closed.*/static enum XML_ErrordoIgnoreSection(XML_Parser parser,                const ENCODING *enc,                const char **startPtr,                const char *end,                const char **nextPtr,                XML_Bool haveMore){  const char *next;  int tok;  const char *s = *startPtr;  const char **eventPP;  const char **eventEndPP;  if (enc == encoding) {    eventPP = &eventPtr;    *eventPP = s;    eventEndPP = &eventEndPtr;  }  else {    eventPP = &(openInternalEntities->internalEventPtr);    eventEndPP = &(openInternalEntities->internalEventEndPtr);  }  *eventPP = s;  *startPtr = NULL;  tok = XmlIgnoreSectionTok(enc, s, end, &next);  *eventEndPP = next;  switch (tok) {  case XML_TOK_IGNORE_SECT:    if (defaultHandler)      reportDefault(parser, enc, s, next);    *startPtr = next;    *nextPtr = next;    if (parsing == XML_FINISHED)      return XML_ERROR_ABORTED;    else      return XML_ERROR_NONE;  case XML_TOK_INVALID:    *eventPP = next;    return XML_ERROR_INVALID_TOKEN;  case XML_TOK_PARTIAL_CHAR:    if (haveMore) {      *nextPtr = s;      return XML_ERROR_NONE;    }    return XML_ERROR_PARTIAL_CHAR;  case XML_TOK_PARTIAL:  case XML_TOK_NONE:    if (haveMore) {      *nextPtr = s;      return XML_ERROR_NONE;    }    return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */  default:    *eventPP = next;    return XML_ERROR_UNEXPECTED_STATE;  }  /* not reached */}#endif /* XML_DTD */static enum XML_ErrorinitializeEncoding(XML_Parser parser){  const char *s;#ifdef XML_UNICODE  char encodingBuf[128];  if (!protocolEncodingName)    s = NULL;  else {    int i;    for (i = 0; protocolEncodingName[i]; i++) {      if (i == sizeof(encodingBuf) - 1          || (protocolEncodingName[i] & ~0x7f) != 0) {        encodingBuf[0] = '\0';        break;      }      encodingBuf[i] = (char)protocolEncodingName[i];    }    encodingBuf[i] = '\0';    s = encodingBuf;  }#else  s = protocolEncodingName;#endif  if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s))    return XML_ERROR_NONE;  return handleUnknownEncoding(parser, protocolEncodingName);}static enum XML_ErrorprocessXmlDecl(XML_Parser parser, int isGeneralTextEntity,               const char *s, const char *next){  const char *encodingName = NULL;  const XML_Char *storedEncName = NULL;  const ENCODING *newEncoding = NULL;  const char *version = NULL;  const char *versionend;  const XML_Char *storedversion = NULL;  int standalone = -1;  if (!(ns        ? XmlParseXmlDeclNS        : XmlParseXmlDecl)(isGeneralTextEntity,                           encoding,                           s,                           next,                           &eventPtr,                           &version,                           &versionend,                           &encodingName,                           &newEncoding,                           &standalone)) {    if (isGeneralTextEntity)      return XML_ERROR_TEXT_DECL;    else      return XML_ERROR_XML_DECL;  }  if (!isGeneralTextEntity && standalone == 1) {    _dtd->standalone = XML_TRUE;#ifdef XML_DTD    if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)      paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;#endif /* XML_DTD */  }  if (xmlDeclHandler) {    if (encodingName != NULL) {      storedEncName = poolStoreString(&temp2Pool,                                      encoding,                                      encodingName,                                      encodingName                                      + XmlNameLength(encoding, encodingName));      if (!storedEncName)              return XML_ERROR_NO_MEMORY;      poolFinish(&temp2Pool);    }    if (version) {      storedversion = poolStoreString(&temp2Pool,                                      encoding,                                      version,                                      versionend - encoding->minBytesPerChar);      if (!storedversion)        return XML_ERROR_NO_MEMORY;    }    xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone);  }  else if (defaultHandler)    reportDefault(parser, encoding, s, next);  if (protocolEncodingName == NULL) {    if (newEncoding) {      if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) {        eventPtr = encodingName;        return XML_ERROR_INCORRECT_ENCODING;      }      encoding = newEncoding;    }    else if (encodingName) {      enum XML_Error result;      if (!storedEncName) {        storedEncName = poolStoreString(          &temp2Pool, encoding, encodingName,          encodingName + XmlNameLength(encoding, encodingName));        if (!storedEncName)          return XML_ERROR_NO_MEMORY;      }      result = handleUnknownEncoding(parser, storedEncName);      poolClear(&temp2Pool);      if (result == XML_ERROR_UNKNOWN_ENCODING)        eventPtr = encodingName;      return result;    }  }  if (storedEncName || storedversion)    poolClear(&temp2Pool);  return XML_ERROR_NONE;}static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName){  if (unknownEncodingHandler) {    XML_Encoding info;    int i;    for (i = 0; i < 256; i++)      info.map[i] = -1;    info.convert = NULL;    info.data = NULL;    info.release = NULL;    if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName,                               &info)) {      ENCODING *enc;      unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding());      if (!unknownEncodingMem) {        if (info.release)          info.release(info.data);        return XML_ERROR_NO_MEMORY;      }      enc = (ns             ? XmlInitUnknownEncodingNS             : XmlInitUnknownEncoding)(unknownEncodingMem,                                       info.map,                                       info.convert,                                       info.data);      if (enc) {        unknownEncodingData = info.data;        unknownEncodingRelease = info.release;        encoding = enc;        return XML_ERROR_NONE;      }    }    if (info.release != NULL)      info.release(info.data);  }  return XML_ERROR_UNKNOWN_ENCODING;}static enum XML_Error PTRCALLprologInitProcessor(XML_Parser parser,                    const char *s,                    const char *end,                    const char **nextPtr){  enum XML_Error result = initializeEncoding(parser);  if (result != XML_ERROR_NONE)    return result;  processor = prologProcessor;  return prologProcessor(parser, s, end, nextPtr);}#ifdef XML_DTDstatic enum XML_Error PTRCALLexternalParEntInitProcessor(XML_Parser parser,                            const char *s,                            const char *end,                            const char **nextPtr){  enum XML_Error result = initializeEncoding(parser);  if (result != XML_ERROR_NONE)    return result;  /* we know now that XML_Parse(Buffer) has been called,     so we consider the external parameter entity read */  _dtd->paramEntityRead = XML_TRUE;  if (prologState.inEntityValue) {    processor = entityValueInitProcessor;    return entityValueInitProcessor(parser, s, end, nextPtr);  }  else {    processor = externalParEntProcessor;    return externalParEntProcessor(parser, s, end, nextPtr);  }}static enum XML_Error PTRCALLentityValueInitProcessor(XML_Parser parser,                         const char *s,                         const char *end,                         const char **nextPtr){  int tok;  const char *start = s;  const char *next = start;  eventPtr = start;  for (;;) {      tok = XmlPrologTok(encoding, start, end, &next);    eventEndPtr = next;    if (tok <= 0) {      if (!finalBuffer && tok != XML_TOK_INVALID) {        *nextPtr = s;        return XML_ERROR_NONE;      }      switch (tok) {      case XML_TOK_INVALID:        return XML_ERROR_INVALID_TOKEN;      case XML_TOK_PARTIAL:        return XML_ERROR_UNCLOSED_TOKEN;      case XML_TOK_PARTIAL_CHAR:        return XML_ERROR_PARTIAL_CHAR;      case XML_TOK_NONE:   /* start == end */      default:        break;      }      /* found end of entity value - can store it now */      return storeEntityValue(parser, encoding, s, end);    }    else if (tok == XML_TOK_XML_DECL) {      enum XML_Error result;      result = processXmlDecl(parser, 0, start, next);      if (result != XML_ERROR_NONE)        return result;      switch (parsing) {      case XML_SUSPENDED:         *nextPtr = next;        return XML_ERROR_NONE;      case XML_FINISHED:        return XML_ERROR_ABORTED;      default:        *nextPtr = next;      }      /* stop scanning for text declaration - we found one */      processor = entityValueProcessor;      return entityValueProcessor(parser, next, end, nextPtr);    }    /* If we are at the end of the buffer, this would cause XmlPrologTok to       return XML_TOK_NONE on the next call, which would then cause the       function to exit with *nextPtr set to s - that is what we want for other       tokens, but not for the BOM - we would rather like to skip it;       then, when this routine is entered the next time, XmlPrologTok will       return XML_TOK_INVALID, since the BOM is still in the buffer    */    else if (tok == XML_TOK_BOM && next == end && !finalBuffer) {      *nextPtr = next;      return XML_ERROR_NONE;    }    start = next;    eventPtr = start;  }}static enum XML_Error PTRCALLexternalParEntProcessor(XML_Parser parser,                        const char *s,                        const char *end,                        const char **nextPtr){  const char *next = s;  int tok;  tok = XmlPrologTok(encoding, s, end, &next);  if (tok <= 0) {    if (!finalBuffer && tok != XML_TOK_INVALID) {      *nextPtr = s;      return XML_ERROR_NONE;    }    switch (tok) {    case XML_TOK_INVALID:      return XML_ERROR_INVALID_TOKEN;    case XML_TOK_PARTIAL:      return XML_ERROR_UNCLOSED_TOKEN;    case XML_TOK_PARTIAL_CHAR:      return XML_ERROR_PARTIAL_CHAR;    case XML_TOK_NONE:   /* start == end */    default:      break;    }  }  /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM.     However, when parsing an external subset, doProlog will not accept a BOM     as valid, and report a syntax error, so we have to skip the BOM  */  else if (tok == XML_TOK_BOM) {    s = next;    tok = XmlPrologTok(encoding, s, end, &next);  }  processor = prologProcessor;  return doProlog(parser, encoding, s, end, tok, next,                   nextPtr, (XML_Bool)!finalBuffer);}static enum XML_Error PTRCALLentityValueProcessor(XML_Parser parser,                     const char *s,                     const char *end,                     const char **nextPtr){  const char *start = s;  const char *next = s;  const ENCODING *enc = encoding;  int tok;  for (;;) {    tok = XmlPrologTok(enc, start, end, &next);    if (tok <= 0) {      if (!finalBuffer && tok != XML_TOK_INVALID) {        *nextPtr = s;        return XML_ERROR_NONE;      }      switch (tok) {      case XML_TOK_INVALID:        return XML_ERROR_INVALID_TOKEN;      case XML_TOK_PARTIAL:        return XML_ERROR_UNCLOSED_TOKEN;      case XML_TOK_PARTIAL_CHAR:        return XML_ERROR_PARTIAL_CHAR;      case XML_TOK_NONE:   /* start == end */      default:        break;      }      /* found end of entity value - can store it now */      return storeEntityValue(parser, enc, s, end);    }    start = next;  }}#endif /* XML_DTD */static enum XML_Error PTRCALLprologProcessor(XML_Parser parser,                const char *s,                const char *end,                const char **nextPtr){  const char *next = s;  int tok = XmlPrologTok(encoding, s, end, &next);  return doProlog(parser, encoding, s, end, tok, next,                   nextPtr, (XML_Bool)!finalBuffer);}static enum XML_ErrordoProlog(XML_Parser parser,         const ENCODING *enc,         const char *s,         const char *end,         int tok,         const char *next,         const char **nextPtr,         XML_Bool haveMore){#ifdef XML_DTD  static const XML_Char externalSubsetName[] = { '#' , '\0' };#endif /* XML_DTD */  static const XML_Char atypeCDATA[] = { 'C', 'D', 'A', 'T', 'A', '\0' };  static const XML_Char atypeID[] = { 'I', 'D', '\0' };  static const XML_Char atypeIDREF[] = { 'I', 'D', 'R', 'E', 'F', '\0' };  static const XML_Char atypeIDREFS[] = { 'I', 'D', 'R', 'E', 'F', 'S', '\0' };  static const XML_Char atypeENTITY[] = { 'E', 'N', 'T', 'I', 'T', 'Y', '\0' };  static const XML_Char atypeENTITIES[] =      { 'E', 'N', 'T', 'I', 'T', 'I', 'E', 'S', '\0' };  static const XML_Char atypeNMTOKEN[] = {      'N', 'M', 'T', 'O', 'K', 'E', 'N', '\0' };  static const XML_Char atypeNMTOKENS[] = {      'N', 'M', 'T', 'O', 'K', 'E', 'N', 'S', '\0' };  static const XML_Char notationPrefix[] = {      'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N', '(', '\0' };  static const XML_Char enumValueSep[] = { '|', '\0' };  static const XML_Char enumValueStart[] = { '(', '\0' };  /* save one level of indirection */  DTD * const dtd = _dtd;   const char **eventPP;  const char **eventEndPP;  enum XML_Content_Quant quant;  if (enc == encoding) {    eventPP = &eventPtr;    eventEndPP = &eventEndPtr;  }  else {    eventPP = &(openInternalEntities->internalEventPtr);    eventEndPP = &(openInternalEntities->internalEventEndPtr);  }  for (;;) {    int role;    XML_Bool handleDefault = XML_TRUE;    *eventPP = s;    *eventEndPP = next;    if (tok <= 0) {      if (haveMore && tok != XML_TOK_INVALID) {        *nextPtr = s;        return XML_ERROR_NONE;      }      switch (tok) {      case XML_TOK_INVALID:        *eventPP = next;        return XML_ERROR_INVALID_TOKEN;      case XML_TOK_PARTIAL:        return XML_ERROR_UNCLOSED_TOKEN;      case XML_TOK_PARTIAL_CHAR:        return XML_ERROR_PARTIAL_CHAR;      case XML_TOK_NONE:#ifdef XML_DTD        /* for internal PE NOT referenced between declarations */        if (enc != encoding && !openInternalEntities->betweenDecl) {          *nextPtr = s;          return XML_ERROR_NONE;        }        /* WFC: PE Between Declarations - must check that PE contains           complete markup, not only for external PEs, but also for           internal PEs if the reference occurs between declarations.        */        if (isParamEntity || enc != encoding) {          if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc)              == XML_ROLE_ERROR)            return XML_ERROR_INCOMPLETE_PE;          *nextPtr = s;          return XML_ERROR_NONE;        }#endif /* XML_DTD */        return XML_ERROR_NO_ELEMENTS;      default:        tok = -tok;        next = end;        break;      }    }    role = XmlTokenRole(&prologState, tok, s, next, enc);    switch (role) {    case XML_ROLE_XML_DECL:      {        enum XML_Error result = processXmlDecl(parser, 0, s, next);        if (result != XML_ERROR_NONE)          return result;        enc = encoding;        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_DOCTYPE_NAME:      if (startDoctypeDeclHandler) {        doctypeName = poolStoreString(&tempPool, enc, s, next);        if (!doctypeName)          return XML_ERROR_NO_MEMORY;        poolFinish(&tempPool);        doctypePubid = NULL;        handleDefault = XML_FALSE;      }      doctypeSysid = NULL; /* always initialize to NULL */      break;    case XML_ROLE_DOCTYPE_INTERNAL_SUBSET:      if (startDoctypeDeclHandler) {        startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid,                                doctypePubid, 1);        doctypeName = NULL;        poolClear(&tempPool);        handleDefault = XML_FALSE;      }      break;#ifdef XML_DTD    case XML_ROLE_TEXT_DECL:      {        enum XML_Error result = processXmlDecl(parser, 1, s, next);        if (result != XML_ERROR_NONE)          return result;        enc = encoding;        handleDefault = XML_FALSE;      }      break;#endif /* XML_DTD */    case XML_ROLE_DOCTYPE_PUBLIC_ID:#ifdef XML_DTD      useForeignDTD = XML_FALSE;      declEntity = (ENTITY *)lookup(&dtd->paramEntities,                                    externalSubsetName,                                    sizeof(ENTITY));      if (!declEntity)        return XML_ERROR_NO_MEMORY;#endif /* XML_DTD */      dtd->hasParamEntityRefs = XML_TRUE;      if (startDoctypeDeclHandler) {        if (!XmlIsPublicId(enc, s, next, eventPP))          return XML_ERROR_PUBLICID;        doctypePubid = poolStoreString(&tempPool, enc,                                       s + enc->minBytesPerChar,                                       next - enc->minBytesPerChar);        if (!doctypePubid)          return XML_ERROR_NO_MEMORY;        normalizePublicId((XML_Char *)doctypePubid);        poolFinish(&tempPool);        handleDefault = XML_FALSE;        goto alreadyChecked;      }      /* fall through */    case XML_ROLE_ENTITY_PUBLIC_ID:      if (!XmlIsPublicId(enc, s, next, eventPP))        return XML_ERROR_PUBLICID;    alreadyChecked:      if (dtd->keepProcessing && declEntity) {        XML_Char *tem = poolStoreString(&dtd->pool,                                        enc,                                        s + enc->minBytesPerChar,                                        next - enc->minBytesPerChar);        if (!tem)          return XML_ERROR_NO_MEMORY;        normalizePublicId(tem);        declEntity->publicId = tem;        poolFinish(&dtd->pool);        if (entityDeclHandler)          handleDefault = XML_FALSE;      }      break;    case XML_ROLE_DOCTYPE_CLOSE:      if (doctypeName) {        startDoctypeDeclHandler(handlerArg, doctypeName,                                doctypeSysid, doctypePubid, 0);        poolClear(&tempPool);        handleDefault = XML_FALSE;      }      /* doctypeSysid will be non-NULL in the case of a previous         XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler         was not set, indicating an external subset      */#ifdef XML_DTD      if (doctypeSysid || useForeignDTD) {        dtd->hasParamEntityRefs = XML_TRUE; /* when docTypeSysid == NULL */        if (paramEntityParsing && externalEntityRefHandler) {          ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities,                                            externalSubsetName,                                            sizeof(ENTITY));          if (!entity)            return XML_ERROR_NO_MEMORY;          if (useForeignDTD)            entity->base = curBase;          dtd->paramEntityRead = XML_FALSE;          if (!externalEntityRefHandler(externalEntityRefHandlerArg,                                        0,                                        entity->base,                                        entity->systemId,                                        entity->publicId))            return XML_ERROR_EXTERNAL_ENTITY_HANDLING;          if (dtd->paramEntityRead &&              !dtd->standalone &&              notStandaloneHandler &&              !notStandaloneHandler(handlerArg))            return XML_ERROR_NOT_STANDALONE;          /* end of DTD - no need to update dtd->keepProcessing */        }        useForeignDTD = XML_FALSE;      }#endif /* XML_DTD */      if (endDoctypeDeclHandler) {        endDoctypeDeclHandler(handlerArg);        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_INSTANCE_START:#ifdef XML_DTD      /* if there is no DOCTYPE declaration then now is the         last chance to read the foreign DTD      */      if (useForeignDTD) {        dtd->hasParamEntityRefs = XML_TRUE;        if (paramEntityParsing && externalEntityRefHandler) {          ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities,                                            externalSubsetName,                                            sizeof(ENTITY));          if (!entity)            return XML_ERROR_NO_MEMORY;          entity->base = curBase;          dtd->paramEntityRead = XML_FALSE;          if (!externalEntityRefHandler(externalEntityRefHandlerArg,                                        0,                                        entity->base,                                        entity->systemId,                                        entity->publicId))            return XML_ERROR_EXTERNAL_ENTITY_HANDLING;          if (dtd->paramEntityRead &&              !dtd->standalone &&              notStandaloneHandler &&              !notStandaloneHandler(handlerArg))            return XML_ERROR_NOT_STANDALONE;          /* end of DTD - no need to update dtd->keepProcessing */        }      }#endif /* XML_DTD */      processor = contentProcessor;      return contentProcessor(parser, s, end, nextPtr);    case XML_ROLE_ATTLIST_ELEMENT_NAME:      declElementType = getElementType(parser, enc, s, next);      if (!declElementType)        return XML_ERROR_NO_MEMORY;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_NAME:      declAttributeId = getAttributeId(parser, enc, s, next);      if (!declAttributeId)        return XML_ERROR_NO_MEMORY;      declAttributeIsCdata = XML_FALSE;      declAttributeType = NULL;      declAttributeIsId = XML_FALSE;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_CDATA:      declAttributeIsCdata = XML_TRUE;      declAttributeType = atypeCDATA;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_ID:      declAttributeIsId = XML_TRUE;      declAttributeType = atypeID;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_IDREF:      declAttributeType = atypeIDREF;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_IDREFS:      declAttributeType = atypeIDREFS;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_ENTITY:      declAttributeType = atypeENTITY;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES:      declAttributeType = atypeENTITIES;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN:      declAttributeType = atypeNMTOKEN;      goto checkAttListDeclHandler;    case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS:      declAttributeType = atypeNMTOKENS;    checkAttListDeclHandler:      if (dtd->keepProcessing && attlistDeclHandler)        handleDefault = XML_FALSE;      break;    case XML_ROLE_ATTRIBUTE_ENUM_VALUE:    case XML_ROLE_ATTRIBUTE_NOTATION_VALUE:      if (dtd->keepProcessing && attlistDeclHandler) {        const XML_Char *prefix;        if (declAttributeType) {          prefix = enumValueSep;        }        else {          prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE                    ? notationPrefix                    : enumValueStart);        }        if (!poolAppendString(&tempPool, prefix))          return XML_ERROR_NO_MEMORY;        if (!poolAppend(&tempPool, enc, s, next))          return XML_ERROR_NO_MEMORY;        declAttributeType = tempPool.start;        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE:    case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE:      if (dtd->keepProcessing) {        if (!defineAttribute(declElementType, declAttributeId,                             declAttributeIsCdata, declAttributeIsId,                             0, parser))          return XML_ERROR_NO_MEMORY;        if (attlistDeclHandler && declAttributeType) {          if (*declAttributeType == XML_T('(')              || (*declAttributeType == XML_T('N')                  && declAttributeType[1] == XML_T('O'))) {            /* Enumerated or Notation type */            if (!poolAppendChar(&tempPool, XML_T(')'))                || !poolAppendChar(&tempPool, XML_T('\0')))              return XML_ERROR_NO_MEMORY;            declAttributeType = tempPool.start;            poolFinish(&tempPool);          }          *eventEndPP = s;          attlistDeclHandler(handlerArg, declElementType->name,                             declAttributeId->name, declAttributeType,                             0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE);          poolClear(&tempPool);          handleDefault = XML_FALSE;        }      }      break;    case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE:    case XML_ROLE_FIXED_ATTRIBUTE_VALUE:      if (dtd->keepProcessing) {        const XML_Char *attVal;        enum XML_Error result =          storeAttributeValue(parser, enc, declAttributeIsCdata,                              s + enc->minBytesPerChar,                              next - enc->minBytesPerChar,                              &dtd->pool);        if (result)          return result;        attVal = poolStart(&dtd->pool);        poolFinish(&dtd->pool);        /* ID attributes aren't allowed to have a default */        if (!defineAttribute(declElementType, declAttributeId,                             declAttributeIsCdata, XML_FALSE, attVal, parser))          return XML_ERROR_NO_MEMORY;        if (attlistDeclHandler && declAttributeType) {          if (*declAttributeType == XML_T('(')              || (*declAttributeType == XML_T('N')                  && declAttributeType[1] == XML_T('O'))) {            /* Enumerated or Notation type */            if (!poolAppendChar(&tempPool, XML_T(')'))                || !poolAppendChar(&tempPool, XML_T('\0')))              return XML_ERROR_NO_MEMORY;            declAttributeType = tempPool.start;            poolFinish(&tempPool);          }          *eventEndPP = s;          attlistDeclHandler(handlerArg, declElementType->name,                             declAttributeId->name, declAttributeType,                             attVal,                             role == XML_ROLE_FIXED_ATTRIBUTE_VALUE);          poolClear(&tempPool);          handleDefault = XML_FALSE;        }      }      break;    case XML_ROLE_ENTITY_VALUE:      if (dtd->keepProcessing) {        enum XML_Error result = storeEntityValue(parser, enc,                                            s + enc->minBytesPerChar,                                            next - enc->minBytesPerChar);        if (declEntity) {          declEntity->textPtr = poolStart(&dtd->entityValuePool);          declEntity->textLen = poolLength(&dtd->entityValuePool);          poolFinish(&dtd->entityValuePool);          if (entityDeclHandler) {            *eventEndPP = s;            entityDeclHandler(handlerArg,                              declEntity->name,                              declEntity->is_param,                              declEntity->textPtr,                              declEntity->textLen,                              curBase, 0, 0, 0);            handleDefault = XML_FALSE;          }        }        else          poolDiscard(&dtd->entityValuePool);        if (result != XML_ERROR_NONE)          return result;      }      break;    case XML_ROLE_DOCTYPE_SYSTEM_ID:#ifdef XML_DTD      useForeignDTD = XML_FALSE;#endif /* XML_DTD */      dtd->hasParamEntityRefs = XML_TRUE;      if (startDoctypeDeclHandler) {        doctypeSysid = poolStoreString(&tempPool, enc,                                       s + enc->minBytesPerChar,                                       next - enc->minBytesPerChar);        if (doctypeSysid == NULL)          return XML_ERROR_NO_MEMORY;        poolFinish(&tempPool);        handleDefault = XML_FALSE;      }#ifdef XML_DTD      else        /* use externalSubsetName to make doctypeSysid non-NULL           for the case where no startDoctypeDeclHandler is set */        doctypeSysid = externalSubsetName;#endif /* XML_DTD */      if (!dtd->standalone#ifdef XML_DTD          && !paramEntityParsing#endif /* XML_DTD */          && notStandaloneHandler          && !notStandaloneHandler(handlerArg))        return XML_ERROR_NOT_STANDALONE;#ifndef XML_DTD      break;#else /* XML_DTD */      if (!declEntity) {        declEntity = (ENTITY *)lookup(&dtd->paramEntities,                                      externalSubsetName,                                      sizeof(ENTITY));        if (!declEntity)          return XML_ERROR_NO_MEMORY;        declEntity->publicId = NULL;      }      /* fall through */#endif /* XML_DTD */    case XML_ROLE_ENTITY_SYSTEM_ID:      if (dtd->keepProcessing && declEntity) {        declEntity->systemId = poolStoreString(&dtd->pool, enc,                                               s + enc->minBytesPerChar,                                               next - enc->minBytesPerChar);        if (!declEntity->systemId)          return XML_ERROR_NO_MEMORY;        declEntity->base = curBase;        poolFinish(&dtd->pool);        if (entityDeclHandler)          handleDefault = XML_FALSE;      }      break;    case XML_ROLE_ENTITY_COMPLETE:      if (dtd->keepProcessing && declEntity && entityDeclHandler) {        *eventEndPP = s;        entityDeclHandler(handlerArg,                          declEntity->name,                          declEntity->is_param,                          0,0,                          declEntity->base,                          declEntity->systemId,                          declEntity->publicId,                          0);        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_ENTITY_NOTATION_NAME:      if (dtd->keepProcessing && declEntity) {        declEntity->notation = poolStoreString(&dtd->pool, enc, s, next);        if (!declEntity->notation)          return XML_ERROR_NO_MEMORY;        poolFinish(&dtd->pool);        if (unparsedEntityDeclHandler) {          *eventEndPP = s;          unparsedEntityDeclHandler(handlerArg,                                    declEntity->name,                                    declEntity->base,                                    declEntity->systemId,                                    declEntity->publicId,                                    declEntity->notation);          handleDefault = XML_FALSE;        }        else if (entityDeclHandler) {          *eventEndPP = s;          entityDeclHandler(handlerArg,                            declEntity->name,                            0,0,0,                            declEntity->base,                            declEntity->systemId,                            declEntity->publicId,                            declEntity->notation);          handleDefault = XML_FALSE;        }      }      break;    case XML_ROLE_GENERAL_ENTITY_NAME:      {        if (XmlPredefinedEntityName(enc, s, next)) {          declEntity = NULL;          break;        }        if (dtd->keepProcessing) {          const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);          if (!name)            return XML_ERROR_NO_MEMORY;          declEntity = (ENTITY *)lookup(&dtd->generalEntities, name,                                        sizeof(ENTITY));          if (!declEntity)            return XML_ERROR_NO_MEMORY;          if (declEntity->name != name) {            poolDiscard(&dtd->pool);            declEntity = NULL;          }          else {            poolFinish(&dtd->pool);            declEntity->publicId = NULL;            declEntity->is_param = XML_FALSE;            /* if we have a parent parser or are reading an internal parameter               entity, then the entity declaration is not considered "internal"            */            declEntity->is_internal = !(parentParser || openInternalEntities);            if (entityDeclHandler)              handleDefault = XML_FALSE;          }        }        else {          poolDiscard(&dtd->pool);          declEntity = NULL;        }      }      break;    case XML_ROLE_PARAM_ENTITY_NAME:#ifdef XML_DTD      if (dtd->keepProcessing) {        const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);        if (!name)          return XML_ERROR_NO_MEMORY;        declEntity = (ENTITY *)lookup(&dtd->paramEntities,                                           name, sizeof(ENTITY));        if (!declEntity)          return XML_ERROR_NO_MEMORY;        if (declEntity->name != name) {          poolDiscard(&dtd->pool);          declEntity = NULL;        }        else {          poolFinish(&dtd->pool);          declEntity->publicId = NULL;          declEntity->is_param = XML_TRUE;          /* if we have a parent parser or are reading an internal parameter             entity, then the entity declaration is not considered "internal"          */          declEntity->is_internal = !(parentParser || openInternalEntities);          if (entityDeclHandler)            handleDefault = XML_FALSE;        }      }      else {        poolDiscard(&dtd->pool);        declEntity = NULL;      }#else /* not XML_DTD */      declEntity = NULL;#endif /* XML_DTD */      break;    case XML_ROLE_NOTATION_NAME:      declNotationPublicId = NULL;      declNotationName = NULL;      if (notationDeclHandler) {        declNotationName = poolStoreString(&tempPool, enc, s, next);        if (!declNotationName)          return XML_ERROR_NO_MEMORY;        poolFinish(&tempPool);        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_NOTATION_PUBLIC_ID:      if (!XmlIsPublicId(enc, s, next, eventPP))        return XML_ERROR_PUBLICID;      if (declNotationName) {  /* means notationDeclHandler != NULL */        XML_Char *tem = poolStoreString(&tempPool,                                        enc,                                        s + enc->minBytesPerChar,                                        next - enc->minBytesPerChar);        if (!tem)          return XML_ERROR_NO_MEMORY;        normalizePublicId(tem);        declNotationPublicId = tem;        poolFinish(&tempPool);        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_NOTATION_SYSTEM_ID:      if (declNotationName && notationDeclHandler) {        const XML_Char *systemId          = poolStoreString(&tempPool, enc,                            s + enc->minBytesPerChar,                            next - enc->minBytesPerChar);        if (!systemId)          return XML_ERROR_NO_MEMORY;        *eventEndPP = s;        notationDeclHandler(handlerArg,                            declNotationName,                            curBase,                            systemId,                            declNotationPublicId);        handleDefault = XML_FALSE;      }      poolClear(&tempPool);      break;    case XML_ROLE_NOTATION_NO_SYSTEM_ID:      if (declNotationPublicId && notationDeclHandler) {        *eventEndPP = s;        notationDeclHandler(handlerArg,                            declNotationName,                            curBase,                            0,                            declNotationPublicId);        handleDefault = XML_FALSE;      }      poolClear(&tempPool);      break;    case XML_ROLE_ERROR:      switch (tok) {      case XML_TOK_PARAM_ENTITY_REF:        /* PE references in internal subset are           not allowed within declarations. */          return XML_ERROR_PARAM_ENTITY_REF;      case XML_TOK_XML_DECL:        return XML_ERROR_MISPLACED_XML_PI;      default:        return XML_ERROR_SYNTAX;      }#ifdef XML_DTD    case XML_ROLE_IGNORE_SECT:      {        enum XML_Error result;        if (defaultHandler)          reportDefault(parser, enc, s, next);        handleDefault = XML_FALSE;        result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore);        if (result != XML_ERROR_NONE)          return result;        else if (!next) {          processor = ignoreSectionProcessor;          return result;        }      }      break;#endif /* XML_DTD */    case XML_ROLE_GROUP_OPEN:      if (prologState.level >= groupSize) {        if (groupSize) {          char *temp = (char *)REALLOC(groupConnector, groupSize *= 2);          if (temp == NULL)            return XML_ERROR_NO_MEMORY;          groupConnector = temp;          if (dtd->scaffIndex) {            int *temp = (int *)REALLOC(dtd->scaffIndex,                          groupSize * sizeof(int));            if (temp == NULL)              return XML_ERROR_NO_MEMORY;            dtd->scaffIndex = temp;          }        }        else {          groupConnector = (char *)MALLOC(groupSize = 32);          if (!groupConnector)            return XML_ERROR_NO_MEMORY;        }      }      groupConnector[prologState.level] = 0;      if (dtd->in_eldecl) {        int myindex = nextScaffoldPart(parser);        if (myindex < 0)          return XML_ERROR_NO_MEMORY;        dtd->scaffIndex[dtd->scaffLevel] = myindex;        dtd->scaffLevel++;        dtd->scaffold[myindex].type = XML_CTYPE_SEQ;        if (elementDeclHandler)          handleDefault = XML_FALSE;      }      break;    case XML_ROLE_GROUP_SEQUENCE:      if (groupConnector[prologState.level] == '|')        return XML_ERROR_SYNTAX;      groupConnector[prologState.level] = ',';      if (dtd->in_eldecl && elementDeclHandler)        handleDefault = XML_FALSE;      break;    case XML_ROLE_GROUP_CHOICE:      if (groupConnector[prologState.level] == ',')        return XML_ERROR_SYNTAX;      if (dtd->in_eldecl          && !groupConnector[prologState.level]          && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type              != XML_CTYPE_MIXED)          ) {        dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type            = XML_CTYPE_CHOICE;        if (elementDeclHandler)          handleDefault = XML_FALSE;      }      groupConnector[prologState.level] = '|';      break;    case XML_ROLE_PARAM_ENTITY_REF:#ifdef XML_DTD    case XML_ROLE_INNER_PARAM_ENTITY_REF:      dtd->hasParamEntityRefs = XML_TRUE;      if (!paramEntityParsing)        dtd->keepProcessing = dtd->standalone;      else {        const XML_Char *name;        ENTITY *entity;        name = poolStoreString(&dtd->pool, enc,                                s + enc->minBytesPerChar,                                next - enc->minBytesPerChar);        if (!name)          return XML_ERROR_NO_MEMORY;        entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0);        poolDiscard(&dtd->pool);        /* first, determine if a check for an existing declaration is needed;           if yes, check that the entity exists, and that it is internal,           otherwise call the skipped entity handler        */        if (prologState.documentEntity &&            (dtd->standalone             ? !openInternalEntities             : !dtd->hasParamEntityRefs)) {          if (!entity)            return XML_ERROR_UNDEFINED_ENTITY;          else if (!entity->is_internal)            return XML_ERROR_ENTITY_DECLARED_IN_PE;        }        else if (!entity) {          dtd->keepProcessing = dtd->standalone;          /* cannot report skipped entities in declarations */          if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) {            skippedEntityHandler(handlerArg, name, 1);            handleDefault = XML_FALSE;          }          break;        }        if (entity->open)          return XML_ERROR_RECURSIVE_ENTITY_REF;        if (entity->textPtr) {          enum XML_Error result;          XML_Bool betweenDecl =             (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE);          result = processInternalEntity(parser, entity, betweenDecl);          if (result != XML_ERROR_NONE)            return result;          handleDefault = XML_FALSE;          break;        }        if (externalEntityRefHandler) {          dtd->paramEntityRead = XML_FALSE;          entity->open = XML_TRUE;          if (!externalEntityRefHandler(externalEntityRefHandlerArg,/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=191482) */#if 0                                        0,#else                                        entity->name,#endif/* END MOZILLA CHANGE */                                        entity->base,                                        entity->systemId,                                        entity->publicId)) {            entity->open = XML_FALSE;            return XML_ERROR_EXTERNAL_ENTITY_HANDLING;          }          entity->open = XML_FALSE;          handleDefault = XML_FALSE;          if (!dtd->paramEntityRead) {            dtd->keepProcessing = dtd->standalone;            break;          }        }        else {          dtd->keepProcessing = dtd->standalone;          break;        }      }#endif /* XML_DTD */      if (!dtd->standalone &&          notStandaloneHandler &&          !notStandaloneHandler(handlerArg))        return XML_ERROR_NOT_STANDALONE;      break;    /* Element declaration stuff */    case XML_ROLE_ELEMENT_NAME:      if (elementDeclHandler) {        declElementType = getElementType(parser, enc, s, next);        if (!declElementType)          return XML_ERROR_NO_MEMORY;        dtd->scaffLevel = 0;        dtd->scaffCount = 0;        dtd->in_eldecl = XML_TRUE;        handleDefault = XML_FALSE;      }      break;    case XML_ROLE_CONTENT_ANY:    case XML_ROLE_CONTENT_EMPTY:      if (dtd->in_eldecl) {        if (elementDeclHandler) {          XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content));          if (!content)            return XML_ERROR_NO_MEMORY;          content->quant = XML_CQUANT_NONE;          content->name = NULL;          content->numchildren = 0;          content->children = NULL;          content->type = ((role == XML_ROLE_CONTENT_ANY) ?                           XML_CTYPE_ANY :                           XML_CTYPE_EMPTY);          *eventEndPP = s;          elementDeclHandler(handlerArg, declElementType->name, content);          handleDefault = XML_FALSE;        }        dtd->in_eldecl = XML_FALSE;      }      break;    case XML_ROLE_CONTENT_PCDATA:      if (dtd->in_eldecl) {        dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type            = XML_CTYPE_MIXED;        if (elementDeclHandler)          handleDefault = XML_FALSE;      }      break;    case XML_ROLE_CONTENT_ELEMENT:      quant = XML_CQUANT_NONE;      goto elementContent;    case XML_ROLE_CONTENT_ELEMENT_OPT:      quant = XML_CQUANT_OPT;      goto elementContent;    case XML_ROLE_CONTENT_ELEMENT_REP:      quant = XML_CQUANT_REP;      goto elementContent;    case XML_ROLE_CONTENT_ELEMENT_PLUS:      quant = XML_CQUANT_PLUS;    elementContent:      if (dtd->in_eldecl) {        ELEMENT_TYPE *el;        const XML_Char *name;        int nameLen;        const char *nxt = (quant == XML_CQUANT_NONE                           ? next                           : next - enc->minBytesPerChar);        int myindex = nextScaffoldPart(parser);        if (myindex < 0)          return XML_ERROR_NO_MEMORY;        dtd->scaffold[myindex].type = XML_CTYPE_NAME;        dtd->scaffold[myindex].quant = quant;        el = getElementType(parser, enc, s, nxt);        if (!el)          return XML_ERROR_NO_MEMORY;        name = el->name;        dtd->scaffold[myindex].name = name;        nameLen = 0;        for (; name[nameLen++]; );        dtd->contentStringLen +=  nameLen;        if (elementDeclHandler)          handleDefault = XML_FALSE;      }      break;    case XML_ROLE_GROUP_CLOSE:      quant = XML_CQUANT_NONE;      goto closeGroup;    case XML_ROLE_GROUP_CLOSE_OPT:      quant = XML_CQUANT_OPT;      goto closeGroup;    case XML_ROLE_GROUP_CLOSE_REP:      quant = XML_CQUANT_REP;      goto closeGroup;    case XML_ROLE_GROUP_CLOSE_PLUS:      quant = XML_CQUANT_PLUS;    closeGroup:      if (dtd->in_eldecl) {        if (elementDeclHandler)          handleDefault = XML_FALSE;        dtd->scaffLevel--;        dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant;        if (dtd->scaffLevel == 0) {          if (!handleDefault) {            XML_Content *model = build_model(parser);            if (!model)              return XML_ERROR_NO_MEMORY;            *eventEndPP = s;            elementDeclHandler(handlerArg, declElementType->name, model);          }          dtd->in_eldecl = XML_FALSE;          dtd->contentStringLen = 0;        }      }      break;      /* End element declaration stuff */    case XML_ROLE_PI:      if (!reportProcessingInstruction(parser, enc, s, next))        return XML_ERROR_NO_MEMORY;      handleDefault = XML_FALSE;      break;    case XML_ROLE_COMMENT:      if (!reportComment(parser, enc, s, next))        return XML_ERROR_NO_MEMORY;      handleDefault = XML_FALSE;      break;    case XML_ROLE_NONE:      switch (tok) {      case XML_TOK_BOM:        handleDefault = XML_FALSE;        break;      }      break;    case XML_ROLE_DOCTYPE_NONE:      if (startDoctypeDeclHandler)        handleDefault = XML_FALSE;      break;    case XML_ROLE_ENTITY_NONE:      if (dtd->keepProcessing && entityDeclHandler)        handleDefault = XML_FALSE;      break;    case XML_ROLE_NOTATION_NONE:      if (notationDeclHandler)        handleDefault = XML_FALSE;      break;    case XML_ROLE_ATTLIST_NONE:      if (dtd->keepProcessing && attlistDeclHandler)        handleDefault = XML_FALSE;      break;    case XML_ROLE_ELEMENT_NONE:      if (elementDeclHandler)        handleDefault = XML_FALSE;      break;    } /* end of big switch */    if (handleDefault && defaultHandler)      reportDefault(parser, enc, s, next);    switch (parsing) {    case XML_SUSPENDED:       *nextPtr = next;      return XML_ERROR_NONE;    case XML_FINISHED:      return XML_ERROR_ABORTED;    default:      s = next;      tok = XmlPrologTok(enc, s, end, &next);    }  }  /* not reached */}static enum XML_Error PTRCALLepilogProcessor(XML_Parser parser,                const char *s,                const char *end,                const char **nextPtr){  processor = epilogProcessor;  eventPtr = s;  for (;;) {    const char *next = NULL;    int tok = XmlPrologTok(encoding, s, end, &next);    eventEndPtr = next;    switch (tok) {    /* report partial linebreak - it might be the last token */    case -XML_TOK_PROLOG_S:      if (defaultHandler) {        reportDefault(parser, encoding, s, next);        if (parsing == XML_FINISHED)          return XML_ERROR_ABORTED;      }      *nextPtr = next;      return XML_ERROR_NONE;    case XML_TOK_NONE:      *nextPtr = s;      return XML_ERROR_NONE;    case XML_TOK_PROLOG_S:      if (defaultHandler)        reportDefault(parser, encoding, s, next);      break;    case XML_TOK_PI:      if (!reportProcessingInstruction(parser, encoding, s, next))        return XML_ERROR_NO_MEMORY;      break;    case XML_TOK_COMMENT:      if (!reportComment(parser, encoding, s, next))        return XML_ERROR_NO_MEMORY;      break;    case XML_TOK_INVALID:      eventPtr = next;      return XML_ERROR_INVALID_TOKEN;    case XML_TOK_PARTIAL:      if (!finalBuffer) {        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_UNCLOSED_TOKEN;    case XML_TOK_PARTIAL_CHAR:      if (!finalBuffer) {        *nextPtr = s;        return XML_ERROR_NONE;      }      return XML_ERROR_PARTIAL_CHAR;    default:      return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;    }    eventPtr = s = next;    switch (parsing) {    case XML_SUSPENDED:       *nextPtr = next;      return XML_ERROR_NONE;    case XML_FINISHED:      return XML_ERROR_ABORTED;    default: ;    }  }}