MOZ_XML_ResumeParser(XML_Parser parser) { blocked = XML_FALSE; return XML_STATUS_OK; }
XML_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 XMLCALL XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) { assert(status != NULL); *status = parser->m_parsingStatus; }
static Processor externalEntityContentProcessor;static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName);static enum XML_ErrorprocessXmlDecl(XML_Parser parser, int isGeneralTextEntity,               const char *, const char *);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);static enum XML_ErrorprocessInternalParamEntity(XML_Parser parser, ENTITY *entity);static enum XML_ErrordoContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,          const char *start, const char *end, const char **endPtr);static enum XML_ErrordoCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr,               const char *end, const char **nextPtr);#ifdef XML_DTDstatic enum XML_ErrordoIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr,                const char *end, const char **nextPtr);#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 (*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;  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;#ifdef XML_DTD  XML_Bool m_isParamEntity;  XML_Bool m_useForeignDTD;  enum XML_ParamEntityParsing m_paramEntityParsing;#endif/* BEGIN MOZILLA CHANGE (Blocking parser) */  XML_Bool m_blocked;/* END MOZILLA CHANGE *//* 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 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)#ifdef XML_DTD#define isParamEntity (parser->m_isParamEntity)#define useForeignDTD (parser->m_useForeignDTD)#define paramEntityParsing (parser->m_paramEntityParsing)#endif /* XML_DTD *//* BEGIN MOZILLA CHANGE (Blocking parser) */#define blocked (parser->m_blocked)/* END MOZILLA CHANGE *//* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */#define mismatch (parser->m_mismatch)/* END MOZILLA CHANGE */#ifdef XML_DTD#define parsing \  (parentParser \    ? \    (isParamEntity \      ? \      (processor != externalParEntInitProcessor) \      : \      (processor != externalEntityInitProcessor)) \    : \    (processor != prologInitProcessor))#else#define parsing \  (parentParser \    ? \    (processor != externalEntityInitProcessor) \    : \    (processor != prologInitProcessor))#endif /* XML_DTD *//* 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;  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 (Blocking parser) */  blocked = XML_FALSE;/* END MOZILLA CHANGE *//* 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 = 0;  defaultExpandInternalEntities = XML_TRUE;  tagLevel = 0;  tagStack = NULL;  inheritedBindings = NULL;  nSpecifiedAtts = 0;  unknownEncodingMem = NULL;  unknownEncodingRelease = NULL;  unknownEncodingData = NULL;  parentParser = NULL;#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;  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;  }  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)    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){  for (;;) {    TAG *p;    if (tagStack == NULL) {      if (freeTagList == NULL)        break;      tagStack = freeTagList;      freeTagList = NULL;    }    p = tagStack;    tagStack = tagStack->parent;    FREE(p->buf);    destroyBindings(p->bindings, parser);    FREE(p);  }  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)    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)    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)    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){/* BEGIN MOZILLA CHANGE (Blocking parser) */  if (blocked) {    /* First unblock parser */    return XML_STATUS_ERROR;  }/* END MOZILLA CHANGE */  if (len == 0) {    if (!isFinal)      return XML_STATUS_OK;    positionPtr = bufferPtr;    errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0);    if (errorCode == XML_ERROR_NONE)      return XML_STATUS_OK;/* BEGIN MOZILLA CHANGE (Blocking parser) */    if (errorCode == XML_ERROR_SUSPENDED) {      bufferPtr = eventPtr;      parseEndPtr = eventEndPtr;      XmlUpdatePosition(encoding, positionPtr, eventEndPtr, &position);      return XML_STATUS_ERROR;    }/* END MOZILLA CHANGE */    eventEndPtr = eventPtr;    processor = errorProcessor;    return XML_STATUS_ERROR;  }#ifndef XML_CONTEXT_BYTES  else if (bufferPtr == bufferEnd) {    const char *end;    int nLeftOver;    parseEndByteIndex += len;    positionPtr = s;    if (isFinal) {      errorCode = processor(parser, s, parseEndPtr = s + len, 0);      if (errorCode == XML_ERROR_NONE)        return XML_STATUS_OK;      eventEndPtr = eventPtr;      processor = errorProcessor;      return XML_STATUS_ERROR;    }    errorCode = processor(parser, s, parseEndPtr = s + len, &end);    if (errorCode != XML_ERROR_NONE) {/* BEGIN MOZILLA CHANGE (Blocking parser) */      if (blocked) {        parseEndPtr = eventEndPtr;        parseEndByteIndex -= len - (eventPtr - s); /* This is how much we've read thus far*/        XmlUpdatePosition(encoding, positionPtr, eventEndPtr, &position);        eventEndPtr = eventPtr;        return XML_STATUS_ERROR;      }/* END MOZILLA CHANGE */      eventEndPtr = eventPtr;      processor = errorProcessor;      return XML_STATUS_ERROR;    }    XmlUpdatePosition(encoding, positionPtr, end, &position);    positionPtr = end;    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);      bufferPtr = buffer;      bufferEnd = buffer + nLeftOver;    }    return XML_STATUS_OK;  }#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 = bufferPtr;  positionPtr = start;  bufferEnd += len;  parseEndByteIndex += len;  errorCode = processor(parser, start, parseEndPtr = bufferEnd,                        isFinal ? (const char **)NULL : &bufferPtr);  if (errorCode == XML_ERROR_NONE) {    if (!isFinal) {      XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);      positionPtr = bufferPtr;    }    return XML_STATUS_OK;  }/* BEGIN MOZILLA CHANGE (Blocking parser) */  else if (errorCode == XML_ERROR_SUSPENDED) {    int unparsed = bufferEnd - eventEndPtr;    bufferPtr = eventPtr;    parseEndPtr = eventEndPtr;    bufferEnd -= unparsed; /* Substract what we haven't parsed */    parseEndByteIndex -= unparsed;    XmlUpdatePosition(encoding, positionPtr, eventEndPtr, &position);    return XML_STATUS_ERROR;  }/* END MOZILLA CHANGE */  else {    eventEndPtr = eventPtr;    processor = errorProcessor;    return XML_STATUS_ERROR;  }}void * XMLCALLXML_GetBuffer(XML_Parser parser, int len){  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;}/* BEGIN MOZILLA CHANGE (Blocking parser) */enum XML_Status XMLCALLMOZ_XML_StopParser(XML_Parser parser, XML_Bool resumable){  blocked = XML_TRUE;  return XML_STATUS_OK;}enum XML_Status XMLCALLMOZ_XML_ResumeParser(XML_Parser parser){  blocked = XML_FALSE;  return XML_STATUS_OK;}/* END MOZILLA CHANGE */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) {    XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);    positionPtr = eventPtr;  }  return position.lineNumber + 1;}int XMLCALLXML_GetCurrentColumnNumber(XML_Parser parser){  if (eventPtr) {    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")  };  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);  if (result != XML_ERROR_NONE)    return result;  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 && endPtr) {      *endPtr = next;      return XML_ERROR_NONE;    }    start = next;    break;  case XML_TOK_PARTIAL:    if (endPtr) {      *endPtr = start;      return XML_ERROR_NONE;    }    eventPtr = start;    return XML_ERROR_UNCLOSED_TOKEN;  case XML_TOK_PARTIAL_CHAR:    if (endPtr) {      *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){  const char *next = start; /* XmlContentTok doesn't always set the last arg */  int tok = XmlContentTok(encoding, start, end, &next);  switch (tok) {  case XML_TOK_XML_DECL:    {      enum XML_Error result = processXmlDecl(parser, 1, start, next);      if (result != XML_ERROR_NONE)        return result;      start = next;    }    break;  case XML_TOK_PARTIAL:    if (endPtr) {      *endPtr = start;      return XML_ERROR_NONE;    }    eventPtr = start;    return XML_ERROR_UNCLOSED_TOKEN;  case XML_TOK_PARTIAL_CHAR:    if (endPtr) {      *endPtr = start;      return XML_ERROR_NONE;    }    eventPtr = start;    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);  if (result != XML_ERROR_NONE)    return result;  if (!storeRawNames(parser))    return XML_ERROR_NO_MEMORY;  return result;}