Ejemplo n.º 1
0
unsigned long XMLNamePool::Hash(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
	register unsigned long h = 0;
	register const XMLChar* s = namespaceURI.c_str();
	while (*s) h = (h << 5) + h + (unsigned long) *s++;
	s = localName.c_str();
	while (*s) h = (h << 5) + h + (unsigned long) *s++;
	s = qname.c_str();
	while (*s) h = (h << 5) + h + (unsigned long) *s++;
	return h;
}
Ejemplo n.º 2
0
int CSAX2ParserBase::HandleExternalEntityRef(const XML_Char* context, const XML_Char* base,
									         const XML_Char* systemId, const XML_Char* publicId)
{
	csl_assert (systemId != NULL);

	if (context == NULL && !m_includeExtParEntities) return 0;
	if (context != NULL && !m_includeExtGenEntities) return 0;

	CInputSource* pInputSource = NULL;
	XMLString resolvedSystemId;
	if (base)
		resolvedSystemId = ResolveSystemId(base, systemId);
	else
		resolvedSystemId = systemId;

	CEntityResolver* pEntityResolver = NULL;
	CEntityResolverImp defaultResolver;

	XMLString pId;
	if (publicId) pId = XMLString(publicId);

	if (m_pEntityResolver)
	{
		pInputSource = m_pEntityResolver->ResolveEntity(publicId ? &pId : NULL, resolvedSystemId);
		pEntityResolver = m_pEntityResolver;
	}
	if (!pInputSource && m_includeExtGenEntities)
	{
		pInputSource = defaultResolver.ResolveEntity(publicId ? &pId : NULL, resolvedSystemId);
		pEntityResolver = &defaultResolver;
	}

	if (pInputSource)
	{
		XML_Parser extParser = XML_ExternalEntityParserCreate(GetExpatParser(), context, 0);

		XML_SetBase(extParser, resolvedSystemId.c_str());

		try
		{
			if (pInputSource->GetCharacterStream())
			{
				ParseCharExternal(extParser, pInputSource->GetCharacterStream());
			}
			else if (pInputSource->GetByteStream())
			{
				ParseExternal(extParser, pInputSource->GetByteStream());
			}
			else
			{
				throw CSAXParseException("no input stream", EMPTY_STRING, pInputSource->GetSystemId(), 0, 0, CXMLException(CXMLException::EXMLBadInputSource, string()));
			}
		}
		catch (CXMLException& e)
		{
			// cleanup before we propagate the exception
			pEntityResolver->DoneWithInputSource(pInputSource);
			XML_ParserFree(extParser);
			throw e;
		}
		pEntityResolver->DoneWithInputSource(pInputSource);
		XML_ParserFree(extParser);
		return 1;
	}
	else
	{
		return 0;
	}
}