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

📄 validatr.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: validatr.cpp,v 1.6.20.2 2004/07/09 02:07:59 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** */#include "hxcom.h"#include "hlxclib/stdio.h"#include "hxtypes.h"#include "hxresult.h"#include "hxassert.h"#include "hxcomm.h"#include "hxplugn.h"#include "hxfiles.h"#include "hxmeta.h"#include "hxcore.h"#include "hxpends.h"#include "timeval.h"#include "pq.h"#include "hxstring.h"#include "hxslist.h"#include "hxrquest.h"#include "hxbuffer.h"#include "chxpckts.h"#include "dbcs.h"#include "hxmarsh.h"#include "hxmime.h"#include "hxstrutl.h"#include "plghand2.h"#include "validatr.h"#include "hxxfile.h"#include "rmfftype.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE		static const char HX_THIS_FILE[] = __FILE__;#endif#define MAX_URL_STRING		4096HXValidator::HXValidator(IUnknown* pContext)	: m_lRefCount (0)	, m_pContext (NULL)	, m_bRefresh (TRUE){    if (pContext)    {	m_pContext = pContext;	m_pContext->AddRef();    }}HXValidator::~HXValidator(){    CHXSimpleList::Iterator i;    // cleanup the protocol list    i = m_ProtocolList.Begin();    for (; i != m_ProtocolList.End(); ++i)    {	CHXString* pProtocol = (CHXString*) (*i);	HX_DELETE(pProtocol);    }    m_ProtocolList.RemoveAll();    HX_RELEASE(m_pContext);}STDMETHODIMPHXValidator::QueryInterface(REFIID riid, void**ppvObj){    QInterfaceList qiList[] =        {            { GET_IIDHANDLE(IID_IHXValidator), (IHXValidator*)this },            { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXValidator*)this },        };        return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);}///////////////////////////////////////////////////////////////////////////  Method://	IUnknown::AddRef//  Purpose://	Everyone usually implements this the same... feel free to use//	this implementation.//STDMETHODIMP_(ULONG32) HXValidator::AddRef(){    return InterlockedIncrement(&m_lRefCount);}///////////////////////////////////////////////////////////////////////////  Method://	IUnknown::Release//  Purpose://	Everyone usually implements this the same... feel free to use//	this implementation.//STDMETHODIMP_(ULONG32) HXValidator::Release(){    if (InterlockedDecrement(&m_lRefCount) > 0)    {        return m_lRefCount;    }    delete this;    return 0;}/************************************************************************ *	Method: *	    IHXValidator::ValidateProtocol *	Purpose: *	    Find out if the protocol is valid *	     * */STDMETHODIMP_(BOOL)HXValidator::ValidateProtocol(char* pProtocol){    BOOL	bResult = FALSE;    CHXString*	pValue = NULL;    CHXSimpleList::Iterator i;    if (!pProtocol)    {	goto cleanup;    }    if (m_bRefresh)    {	BuildProtocolList();	m_bRefresh = FALSE;    }    i = m_ProtocolList.Begin();    for (; i != m_ProtocolList.End(); ++i)    {	pValue = (CHXString*) (*i);	if (strcasecmp(pProtocol, (const char*)(*pValue)) == 0)	{	    bResult = TRUE;	    break;	}    }cleanup:    return bResult;}/************************************************************************ *	Method: *	    IHXValidator::ValidateMetaFile *	Purpose: *	    Find out if it is a meta file *	     * */STDMETHODIMPHXValidator::ValidateMetaFile(IHXRequest* pRequest,			       IHXBuffer* pData){    HX_RESULT	hr = HXR_OK;        BOOL	bIsRAM = FALSE;    BOOL	bTrackFound = FALSE;    BOOL	bHeaderToBeSet = FALSE;    UINT32	ulFileType = 0;    UINT32	ulSize = 0;    UINT32	ulMajorVersion = 0;    int		i = 0;     int		j = 0;    int		iLen = 0;    int		iSize = 0;    char*	pMimeType = NULL;    char*	pFileExt = NULL;    char*	pProtocol = NULL;    char*	pCursor = NULL;    char*	pLine = NULL;    char*	pContent = NULL;    char*	pTemp = NULL;    char*	pURL = NULL;    const char* pConstTemp = NULL;    const char* charset = " \r\n\t";    const char* tokenset = "\n\r";        UINT32	ulProtocol = 0;    CHXString*	pString = NULL;    IHXBuffer*	pValue = NULL;    IHXValues*	pResponseHeaders = NULL;        if (pRequest)    {	pRequest->AddRef();    }    if (pData)    {        pData->AddRef();    }    else    {	hr = HXR_FAILED;	goto cleanup;    }    if (pRequest)    {        pRequest->GetURL(pConstTemp);        if (HXXFile::IsPlusURL(pConstTemp))        {	    hr = HXR_FAILED;	    goto cleanup;        }    }    ulSize = pData->GetSize() + 1;    pContent = new char[ulSize];    memset(pContent, 0, ulSize);    memcpy(pContent, (char*)pData->GetBuffer(), pData->GetSize()); /* Flawfinder: ignore */    // if the first FOURCC is either ".RA " or ".RMF"    if (pData->GetSize() >= 4)    {	ulFileType = (UINT32) getlong((UCHAR*) pContent);    	const char* pContentType = NULL;	switch (ulFileType)	{	    case RM_HEADER_OBJECT:	    case RMS_HEADER_OBJECT:	    case RA_FILE_MAGIC_NUMBER:	    {		pContentType = REALAUDIO_MIME_TYPE;	    }	    break;	    case REDHAT_PACKAGE_MAGIC_NUMBER:	    {		pContentType = REDHAT_PACKAGE_MIME_TYPE;	    }	    break;	}		if (pContentType)	{	    if (pRequest)	    {		pRequest->GetResponseHeaders(pResponseHeaders);		if (!pResponseHeaders)		{		    pResponseHeaders = (IHXValues*) new CHXHeader;		    pResponseHeaders->AddRef();		    bHeaderToBeSet = TRUE;		}		if (HXR_OK !=		    pResponseHeaders->GetPropertyCString("Content-Type",							 pValue) ||		    !pValue)		{		    pValue = (IHXBuffer*) new CHXBuffer;		    pValue->AddRef();		    pValue->Set((UCHAR*)pContentType,				::strlen(pContentType) + 1);		    pResponseHeaders->SetPropertyCString("Content-Type",							 pValue);		    if (bHeaderToBeSet)		    {			pRequest->SetResponseHeaders(pResponseHeaders);		    }		}	    }	    	    hr = HXR_FAILED;	    goto cleanup;	}    }    // retreive the MimeType and FileExt    if (pRequest)    {	if (HXR_OK == pRequest->GetResponseHeaders(pResponseHeaders) &&	    pResponseHeaders)	{	    if (HXR_OK == pResponseHeaders->GetPropertyCString("Content-Type", pValue) &&		pValue)	    {		pMimeType = (char*)pValue->GetBuffer();	    }	}	pTemp = (char*)pConstTemp;	if (pTemp)	{	    pURL = new char[strlen(pTemp) + 1];	    strcpy(pURL, pTemp); /* Flawfinder: ignore */	    pTemp = strrchr(pURL, '?');	    if (pTemp)	    {		*pTemp = '\0';	    }	    pFileExt = strrchr(pURL, '.');	}    }    // determine whether it is a RAM file    if ((pMimeType &&	 ((strcasecmp(pMimeType, "audio/x-pn-realaudio") == 0) ||	  (strcasecmp(pMimeType, "audio/x-pn-realaudio-plugin") == 0))) ||	(pFileExt &&	 ((strcasecmp(pFileExt, ".ram") == 0) ||	  (strcasecmp(pFileExt, ".rpm") == 0) ||	  (strcasecmp(pFileExt, ".rmm") == 0))))    {	bIsRAM = TRUE;        iLen = pData->GetSize();	char* ramFile = new char[iLen+1];    	while( i <= iLen && !bTrackFound)	{/* * XXXJHUG  12/07/00 change to allow unlimitted length ram files.

⌨️ 快捷键说明

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