⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ramvsrc.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 *	close of the file is complete. */STDMETHODIMP CRAMViewSource::CloseDone(HX_RESULT status){    return HXR_OK;}HX_RESULTCRAMViewSource::BuildSource(REF(IHXBuffer*) pOutput){    CollectOptions();    CBigByteGrowingQueue queue(m_pBuffer->GetSize()*2);    const char* tokenset = "\n\r";    const char* charset = " \r\n\t";    //output += (const char*) m_pBuffer->GetBuffer();    char* buffer = new char[m_pBuffer->GetSize()+1];    memcpy(buffer, m_pBuffer->GetBuffer(), m_pBuffer->GetSize()); /* Flawfinder: ignore */    buffer[m_pBuffer->GetSize()] = '\0';    PushHeader(&queue);    queue.EnQueue(z_pEndLine);    //queue->EnQueue("<pre><!--  Begin Source  -->\n");    char* pLine = strtok(buffer, tokenset);    while (pLine)    {	size_t pos = strspn(pLine,charset);	pLine += pos;	if (*pLine == '#' || *pLine == '/')	{	    queue.EnQueue(pLine);	    queue.EnQueue(z_pEndLine);	    pLine = strtok(NULL, tokenset);	    continue;	}	if (strchr(pLine, ':'))	{	    BOOL bHREF = PushOpenningHREF(pLine, &queue);	    PushMangledDisplayedPath(pLine, &queue);	    if (bHREF)	    {		queue.EnQueue(tag_END_HREF);	    }	    queue.EnQueue(z_pEndLine);	    pLine = strtok(NULL, tokenset);	    continue;	}	else	{	    queue.EnQueue(pLine);	    queue.EnQueue(z_pEndLine);	    pLine = strtok(NULL, tokenset);	    continue;	}    }        //queue.EnQueue("\n<!--  End Source  --></pre>\n");    m_pCommonClassFactory->CreateInstance(IID_IHXBuffer, (void**)&pOutput);    if (!pOutput)    {	return HXR_OUTOFMEMORY;    }    if (FAILED(pOutput->SetSize(queue.GetQueuedItemCount())))    {	return HXR_OUTOFMEMORY;    }        UCHAR* chr = pOutput->GetBuffer();    queue.DeQueue(chr, queue.GetQueuedItemCount());    //pOutput->GetBuffer()[m_pBuffer->GetSize()] = '\0';    HX_VECTOR_DELETE(buffer);    return HXR_OK;}BOOLCRAMViewSource::PushOpenningHREF(const char* pPositionPointer, CBigByteGrowingQueue* pQueue){    UINT32 ulLen = strlen(pPositionPointer);    if (strncmp(pPositionPointer, "rtsp://", 7) == 0 || strncmp(pPositionPointer, "pnm://", 6) == 0)    {        UINT32 ulCount = 7;        if (strncmp(pPositionPointer, "pnm://", 6) == 0) ulCount = 6;	const char* p = pPositionPointer;	const char* pEnd = p + ulLen;	p += ulCount;	// move p to the end of server name find the first : or /	while ( *p != ':' && *p != '/' && ++p != pEnd) {} ;	pQueue->EnQueue(tag_BEGIN_HREF);	// 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 - pPositionPointer - ulCount;	if ( ulServerLen == ulXMLServerLen &&	    strncmp(pBeginServer, pPositionPointer + ulCount, ulServerLen) == 0 )	{	    // use m_pServerURL	    pQueue->EnQueue(m_pServerUrl);	}	else	{	    // use the Default Port	    pQueue->EnQueue("http");        UINT32 ulOffset = 4;        if (ulCount == 6) ulOffset = 3;	    pQueue->EnQueue((void*)(pPositionPointer + ulOffset), p - pPositionPointer - ulOffset);	    pQueue->EnQueue(m_pDefaultView);	}	while ( *p != '/' && ++p != pEnd) {} ;	char* pParam = GetParameter(p, pEnd - p, FALSE);	pQueue->EnQueue("?");	pQueue->EnQueue(pParam);	HX_VECTOR_DELETE(pParam);	pQueue->EnQueue("\">");    }    else if ( strnchr(pPositionPointer, ':', min(6, ulLen)) )    {	if ( strncmp(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(tag_BEGIN_HREF);	    pQueue->EnQueue(m_pServerUrl);	    pQueue->EnQueue("?");	    char* pParam = GetParameter(pPositionPointer, ulLen, TRUE);	    pQueue->EnQueue(pParam);	    HX_VECTOR_DELETE(pParam);	    pQueue->EnQueue("\">");	}	else	{	    return FALSE;	}    }    else    {	pQueue->EnQueue(tag_BEGIN_HREF);	pQueue->EnQueue(m_pServerUrl);	pQueue->EnQueue("?");	char* pParam = GetParameter(pPositionPointer, ulLen, FALSE);	pQueue->EnQueue(pParam);	HX_VECTOR_DELETE(pParam);	pQueue->EnQueue("\">");    }    return TRUE;}UINT32CRAMViewSource::PushMangledDisplayedPath(const char* pIn, 					    CBigByteGrowingQueue* pQueue){    UINT32 ulLen = strlen(pIn);    UINT32 ulPos = 0;    if ( m_bMangleLinks )    {	const char* pProtocolEnd = strnstr(pIn, "://", ulLen);	if ( pProtocolEnd )  // we have protocol	{	    pProtocolEnd += 2; // only push one slash	    UINT32 ulLenOfProtocol = pProtocolEnd - pIn;	    pQueue->EnQueue((void*)pIn, ulLenOfProtocol);	    pIn += ulLenOfProtocol;	    ulPos += ulLenOfProtocol;	}	// find last '/'	while ( strnchr(pIn, '/', ulLen - ulPos) ) 	{	    UINT32 temp = ulPos;	    temp += strnchr(pIn, '/', ulLen - ulPos) 		    - pIn + 1;	    pIn  = strnchr(pIn, '/', ulLen - ulPos) 		    + 1;	    ulPos = temp;	    	}	pQueue->EnQueue("/.../");    }    // else we just do the whole thing...    pQueue->EnQueue((void*)pIn, ulLen - ulPos);    return ulLen;}char*CRAMViewSource::GetParameter(const char* 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, 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, pPositionPointer, ulNameLen); /* Flawfinder: ignore */	pLinkPath[len] = '\0';    }    else if ( !strncmp(pPositionPointer, "./", 2) )    {	// -1 for .	UINT32 len = strlen(m_pOurPath) + ulNameLen - 1;	strcpy(pLinkPath, m_pOurPath); /* Flawfinder: ignore */	pPositionPointer += 1;	strncat(pLinkPath, pPositionPointer, ulNameLen - 1); /* Flawfinder: ignore */	pLinkPath[len] = '\0';    }    else if ( !strncmp(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 = 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(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 - pPositionPointer) + 1;		// back 1 off of pRelativePath so we get the / that's there.	strncat(pLinkPath, pRelativePath - 1, /* Flawfinder: ignore */	    ulNameLen - (pRelativePath - pPositionPointer) + 1);	pLinkPath[len] = '\0';    }    else    {	HX_ASSERT(FALSE);	pLinkPath = '\0';    }    char* pParam = EncryptParameter(pReturnBuffer);    HX_VECTOR_DELETE(pReturnBuffer);    return pParam;}char*CRAMViewSource::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;}HX_RESULTCRAMViewSource::PushHeader(CBigByteGrowingQueue* queue){    queue->EnQueue(z_pStream);    queue->EnQueue(z_pRAMName);    queue->EnQueue(z_pEndLine);    queue->EnQueue(z_pFileName);    queue->EnQueue(m_pFileName);    queue->EnQueue(z_pEndLine);        QueueModificationTime(queue, m_ulModDate);    QueueFileSize(queue, m_ulFileSize);    return HXR_OK;}HX_RESULTCRAMViewSource::CollectOptions(){    IHXBuffer* pViewURL = NULL;    IHXBuffer* pCurrentPath = NULL;    IHXBuffer* pRemoteView = NULL;    IHXBuffer* pFileName = NULL;    UINT32 ulMangle = 0;    UINT32 ulStyles = 0;    if ( FAILED(m_pOptions->GetPropertyCString("ViewSourceURL", pViewURL)) ||	 FAILED(m_pOptions->GetPropertyCString("CurrentPath", pCurrentPath)) ||	 FAILED(m_pOptions->GetPropertyULONG32("HidePaths", ulMangle)) ||	 FAILED(m_pOptions->GetPropertyCString("RemoteViewSourceURL", pRemoteView)) ||	 FAILED(m_pOptions->GetPropertyCString("FileName", pFileName)) ||	 FAILED(m_pOptions->GetPropertyULONG32("ModificationTime", m_ulModDate)) ||	 FAILED(m_pOptions->GetPropertyULONG32("FileSize", m_ulFileSize)) )    {	HX_ASSERT(FALSE);	// return HXR_INVALID_PARAMETER;    }    m_bMangleLinks = ulMangle ? TRUE : FALSE;    m_pServerUrl = new char[pViewURL->GetSize()+1];    strcpy(m_pServerUrl, (char*)pViewURL->GetBuffer()); /* Flawfinder: ignore */    m_pOurPath = new char[pCurrentPath->GetSize()+1];    strcpy(m_pOurPath, (char*)pCurrentPath->GetBuffer()); /* Flawfinder: ignore */    m_pDefaultView = new char[pRemoteView->GetSize()+1];    strcpy(m_pDefaultView, (char*)pRemoteView->GetBuffer()); /* Flawfinder: ignore */    m_pFileName = new char[pFileName->GetSize()+1];    strcpy(m_pFileName, (char*)pFileName->GetBuffer()); /* Flawfinder: ignore */    HX_RELEASE(pRemoteView);    HX_RELEASE(pViewURL);    HX_RELEASE(pCurrentPath);    HX_RELEASE(pFileName);    return HXR_OK;}

⌨️ 快捷键说明

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