xmlesc.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,586 行 · 第 1/4 页

CPP
1,586
字号
 *		to be referenced to.
 *		This contains the absolute url if that is needed, or it
 *		is used in the call to GetParameter(...).
 *	pQueue	A pointer to a CBigByteGrowingQueue that is used for queuing up 
 *		the output.
 *      cEndQuote - the character to end the quote (either ' or ")
 *
 *  DESCRIPTION:
 *	This Method pushes HREF onto the output queue.  It must build the
 *	Url from the m_pServerUrl and the parameter (GetParameter).
 *
 *
 *  RETURNS:
 *	void
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
BOOL
CEscapeXMLtoHTML::PushOpenningHREF(const UCHAR* pPositionPointer, CBigByteGrowingQueue* pQueue, char cEndQuote)
{
    // if relative path
    // TODO: else we need to take care of full paths - 
    //	    pPositionPointer or if m_pOurPath has a protocol as well.
    const char* pszQuote = strchr((const char*) pPositionPointer, cEndQuote);
    if (pszQuote)
    {
        UINT32 ulLen = ((const UCHAR*) pszQuote) - pPositionPointer;

        if ( strncmp((const char*)pPositionPointer, "rtsp://", 7) == 0 )
        {
	    const char* p = (const char*)pPositionPointer;
	    const char* pEnd = p + ulLen;
	    p += 7;
	    // move p to the end of server name find the first : or /
	    while ( *p != ':' && *p != '/' && ++p != pEnd) {} ;

	    pQueue->EnQueue(m_pEscapeStrings[BeginHREF]);
	    // replacing rtsp with http
	    
	    //XXXJHUG  -- If the server in m_pServerUrl is the same as the 
	    // server we are about queue we will use m_pServerUrl
	    // instead of the default port and mountpoint.
	    
	    // mover past http://
	    char* pBeginServer = m_pServerUrl + 7;
	    
	    UINT32 ulServerLen = 0;
	    char* pServerPort = strchr(pBeginServer, ':');
	    // m_pServerURL will always have a port.
	    HX_ASSERT(pServerPort);
	    if ( pServerPort )
	    {
	        ulServerLen = pServerPort - pBeginServer;
	    }
	    // 7 for rtsp://
	    UINT32 ulXMLServerLen = p - (const char*)pPositionPointer - 7;
	    if ( ulServerLen == ulXMLServerLen &&
	        strncmp(pBeginServer, (const char*)pPositionPointer + 7, ulServerLen) == 0 )
	    {
	        // use m_pServerURL
	        pQueue->EnQueue(m_pServerUrl);
	    }
	    else
	    {
	        // use the Default Port
	        pQueue->EnQueue("http");
	        pQueue->EnQueue((void*)(pPositionPointer + 4), p - (const char*)pPositionPointer - 4);
	        pQueue->EnQueue(m_pDefaultView);
	    }

	    while ( *p != '/' && ++p != pEnd) {} ;
	    UCHAR* pParam = GetParameter((const UCHAR*)p, pEnd - p);

	    pQueue->EnQueue("?");
	    pQueue->EnQueue((const char*)pParam);
	    HX_VECTOR_DELETE(pParam);
	    pQueue->EnQueue("\">");
        }
        else if ( strnchr((const char*)pPositionPointer, ':', min(6, ulLen)) )
        {
	    if ( strncmp((const char*)pPositionPointer, "pnm://", 6) != 0 &&
	        (strncmp(m_pServerUrl, "http://localhost", sizeof("http://localhost") - 1) == 0 ||
	        strncmp(m_pServerUrl, "http://127.0.0.1", sizeof("http://127.0.0.1") - 1) == 0) )
	    {
	        pQueue->EnQueue(m_pEscapeStrings[BeginHREF]);
	        pQueue->EnQueue(m_pServerUrl);
	        pQueue->EnQueue("?");
	        UCHAR* pParam = GetParameter(pPositionPointer, ulLen, TRUE);
	        pQueue->EnQueue((const char*)pParam);
	        HX_VECTOR_DELETE(pParam);
	        pQueue->EnQueue("\">");
	    }
	    else
	    {
	        return FALSE;
	    }
        }
        else
        {
	    pQueue->EnQueue(m_pEscapeStrings[BeginHREF]);
	    pQueue->EnQueue(m_pServerUrl);
	    pQueue->EnQueue("?");
	    UCHAR* pParam = GetParameter(pPositionPointer, ulLen);

	    pQueue->EnQueue((const char*)pParam);
	    HX_VECTOR_DELETE(pParam);
	    pQueue->EnQueue("\">");
        }
    }
    return TRUE;
}

/*___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  PushEndingHREF(pQueue)
 *
 *  PARAMETERS:
 *	pQueue	A pointer to a CBigByteGrowingQueue that is used for queuing up 
 *		the parsered output.
 *
 *  DESCRIPTION:
 *	Pushes end of HREF onto the output queue.
 *
 *  RETURNS
 *	void
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void
CEscapeXMLtoHTML::PushEndingHREF(CBigByteGrowingQueue* pQueue)
{
    pQueue->EnQueue(m_pEscapeStrings[EndHREF]);
}

/*___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  GetParameter(pPositionPointer, ulNameLen)
 *
 *  PARAMETERS:
 *	pPositionPointer	Pointer to a character string.  It is positioned
 *		inside a quote right infront of the path or file to
 *		to be referenced to.
 *	ulNameLen	The length of the name.  It is not zero terminated.
 *
 *  DESCRIPTION:
 *	This method builds a relative path and paramiterizes it.  Then the
 *	parameter is encrypted with a call to EncryptParameter().  A string 
 *	is allocated to be returned
 *
 *  RETURNS
 *	a pointer to a new string that is to be used after the ? for an 
 *	option in a url
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
UCHAR*
CEscapeXMLtoHTML::GetParameter(const UCHAR* pPositionPointer, UINT32 ulNameLen, 
			       BOOL bFullPath)
{
    // allocate longest possible string
    char* pReturnBuffer = new char[(strlen(m_pOurPath) + ulNameLen) + 10]; 
    //  2 for a possible starting '/' and a null terminator
    // 4 for the starting src=
    // 4 for extra bytes in case we have to pad the buffer when we encypt it.
    strcpy(pReturnBuffer, "src="); /* Flawfinder: ignore */

    char* pLinkPath = pReturnBuffer + 4;
    

    // if it starts with '/' then it is a full path
    if ( *pPositionPointer == '/' || bFullPath )
    {
	strncpy(pLinkPath, (const char*)pPositionPointer, ulNameLen); /* Flawfinder: ignore */
	pLinkPath[ulNameLen] = '\0';
    }
    // if it is alpha it is simply a file name
    else if ( isalnum(*pPositionPointer) )
    {
	// 1 for "/"
	UINT32 len = strlen(m_pOurPath) + ulNameLen + 1;
	strcpy(pLinkPath, m_pOurPath); /* Flawfinder: ignore */
	strcat(pLinkPath, "/"); /* Flawfinder: ignore */
	strncat(pLinkPath, (const char*)pPositionPointer, ulNameLen); /* Flawfinder: ignore */
	pLinkPath[len] = '\0';
    }
    else if ( !strncmp((const char*)pPositionPointer, "./", 2) )
    {
	// -1 for .
	UINT32 len = strlen(m_pOurPath) + ulNameLen - 1;
	strcpy(pLinkPath, m_pOurPath); /* Flawfinder: ignore */
	pPositionPointer += 1;
	strncat(pLinkPath, (const char*)pPositionPointer, ulNameLen - 1); /* Flawfinder: ignore */
	pLinkPath[len] = '\0';
    }
    else if ( !strncmp((const char*)pPositionPointer, "../", 3 ) )
    {
	int count = 0;

	// copy m_pOurPath into pLinkPath ourselves cause we need to be at
	// the end anyway.
	const char* pSrc = m_pOurPath;
	char* pCurrentEndOfPath = pLinkPath;
	const char* pRelativePath = (const char*)pPositionPointer;
	
	// Walk to take care of any ../ that might be in the path...
	char* pDest = pCurrentEndOfPath;
	while ( *pSrc )
	{
	    while ( *pSrc == '.' && *(pSrc + 1) == '.' && *(pSrc + 2) == '/' )
	    {
		--pDest;
		while ( *(pDest-1) != '/' && (pDest-1) >= pLinkPath )
		{
		    --pDest;
		}
		pSrc += 3;
	    }
	    *pDest = *pSrc;
	    ++pDest;
	    ++pSrc;
	}
	*pDest = '\0';

	pCurrentEndOfPath += strlen(pCurrentEndOfPath);

	// back up a directory off of the file path for
	// every ../ we find
	while (!strncmp((const char*)pRelativePath, "../", 3 ))
	{
	    // we found a ../ so back up a directory on the path,
	    // walk backwards to the previous / and set it to null
	    while (*pCurrentEndOfPath != '/' && 
		pCurrentEndOfPath >= pLinkPath)
	    {
		pCurrentEndOfPath--;
	    }
	    // watch to make sure we don't have more ../ than directories
	    if ( pCurrentEndOfPath < pLinkPath)
	    {
		++pCurrentEndOfPath;
	    }
	    *pCurrentEndOfPath = '\0';
	    pRelativePath +=3;
	}

        UINT32 len = (pCurrentEndOfPath - pLinkPath) + 
	    ulNameLen - (pRelativePath - (const char*)pPositionPointer) + 1;
	
	// back 1 off of pRelativePath so we get the / that's there.
	strncat(pLinkPath, (const char*)pRelativePath - 1, /* Flawfinder: ignore */
	    ulNameLen - (pRelativePath - (const char*)pPositionPointer) + 1);
	pLinkPath[len] = '\0';
    }
    else
    {
	HX_ASSERT(FALSE);
	pLinkPath = '\0';
    }

    char* pParam = EncryptParameter(pReturnBuffer);
    HX_VECTOR_DELETE(pReturnBuffer);
    return (UCHAR*)pParam;
}

/*___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  EncryptParameter(pPath)
 *
 *  PARAMETERS:
 *	pPath	Pointer to a string to be parameterized and encrypted.
 *
 *  DESCRIPTION:
 *	First it is assigned to a variable (src), and then the parameter is
 *	encrypted
 *
 *  RETURNS
 *	a pointer to a new string that is to be used after the ? for an 
 *	option in a url
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
char*
CEscapeXMLtoHTML::EncryptParameter(char* pPath)
{
    UINT32 FinalLen;			    // length of encoded data
    UINT32 Offset = strlen(pPath);
    UINT32 nAlign = Offset % sizeof(ULONG32);
    if (nAlign > 0)
    {
	for (; nAlign < sizeof(ULONG32); nAlign++)
	{
	    pPath[Offset++] = 0;
	}
    }
    FinalLen = (Offset) * Perplex_PER_ULONG32 / sizeof(ULONG32);	
    // calc size of the outout (Perplexed) buffer.
    // alloc mem for final perplexed buffer
    // Add one to length 'cause low level perplex adds
    // a '\0' to the resulting string

    char* output = new char[FinalLen+1];

    CHXPerplex::DumpToPerplex((char*)output,FinalLen+1,(UCHAR*) pPath, Offset);
    return output;
}

/*___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  CheckTag (pObj)
 *
 *  PARAMETERS:
 *	pObj		current state
 *
 *  DESCRIPTION:
 *	This method pushes the begging of a color tag onto the queue
 *
 *  RETURNS
 *	void
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
BOOL
CEscapeXMLtoHTML::CheckTag(DataObject* pObj)
{
    if ( m_pHotTags ) 
    {
	for ( INT32 i = 0; m_pHotTags[i]; i++ )
	{
	    if ( !strcmp(pObj->tag, m_pHotTags[i]) )
	    {
		    return TRUE;
	    }
	}
    }
    return FALSE;
}
/*___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  BeginColorTag (CBigByteGrowingQueue* qu, DataObject *pObj)
 *
 *  PARAMETERS:
 *		qu			queue to output to
 *		pObj		current state
 *  DESCRIPTION:
 *		This method pushes the begging of a color tag onto the queue
 *	RETURNS
 *		void
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void
CEscapeXMLtoHTML::BeginColorTag (CBigByteGrowingQueue* qu, DataObject *pObj)
{
    qu->EnQueue(m_pEscapeStrings[BeginTagMarkup]);
    qu->EnQueue("&lt;");
    qu->EnQueue(m_pEscapeStrings[BeginTagNameMarkup]);
    pObj->state = ABOUT_TO_BEGIN_TAG;
    pObj->bPushChar = FALSE;
}

/*___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  EndColorTag (CBigByteGrowingQueue* qu, DataObject *pObj)
 *
 *  PARAMETERS:
 *		qu		queue to output to
 *		pObj		current state
 *
 *  DESCRIPTION:
 *	This method pushes the end of a color tag onto the queue
 *
 *  RETURNS
 *	void
 *___________________________________________________________________________
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void
CEscapeXMLtoHTML::EndColorTag (CBigByteGrowingQueue* qu, DataObject *pObj)
{
    if ( pObj->bInBrokenXML )
    {
        qu->EnQueue(m_pEscapeStrings[EndBrokenAttributeMarkup]);
        pObj->bInBrokenXML = FALSE;
    }
    if ( pObj->bInProcessingInstructions )
    {
       qu->EnQueue(m_pEscapeStrings[EndProcessingInstructions]);
       qu->EnQueue(m_pEscapeStrings[BeginTagMarkup]);
       qu->EnQueue("&gt;");
       qu->EnQueue(m_pEscapeStrings[EndTagMarkup]);
       pObj->bInProcessingInstructions = FALSE;
    }
    else
    {
       qu->EnQueue("&gt;");
       qu->EnQueue(m_pEscapeStrings[EndTagMarkup]);
    }
    pObj->state = IN_CONTENT;
    pObj->bPushChar = FALSE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?