📄 validatr.cpp
字号:
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 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
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (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.
*
* 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 4096
HXValidator::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);
}
STDMETHODIMP
HXValidator::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
*
*
*/
STDMETHODIMP
HXValidator::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.
* - we no longer need to check to see if the url
* is longer than a fixed value.
if (j >= MAX_URL_STRING)
{
// exceeds the max. length of URL
// skip the whole line
while (pContent[i] != '\n' && pContent[i] != '\r' &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -