📄 hxfsmgr.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: hxfsmgr.cpp,v 1.8.20.1 2004/07/09 02:06:33 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 "hxtypes.h"#include "hxresult.h"#include "hxcom.h"#include "hxcomm.h"#include "hxchkpt.h"#include "hxfiles.h"#include "hxauth.h"#include "hxlist.h"#include "hxstrutl.h"#include "dbcs.h"#include "hxplugn.h"#include "plghand2.h"#include "hxrquest.h"#include "hxplugn.h"#include "hxfsmgr.h"#include "hxmon.h"#include "chxpckts.h"#include "plghand2.h"//#include "hxperf.h"#ifdef _MACINTOSH#include "hx_moreprocesses.h"#endif#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static const char HX_THIS_FILE[] = __FILE__;#endif#if !defined(HELIX_CONFIG_NOSTATICS)BOOL HXFileSystemManager::zm_IsInited = FALSE;CHXMapStringToOb HXFileSystemManager::zm_ShortNameMap;CHXMapStringToOb HXFileSystemManager::zm_ProtocolMap;CHXSimpleList HXFileSystemManager::zm_CacheList;#else#include "globals/hxglobals.h"const BOOL HXFileSystemManager::zm_IsInited = FALSE;const CHXMapStringToOb* const HXFileSystemManager::zm_ShortNameMap = NULL;const CHXMapStringToOb* const HXFileSystemManager::zm_ProtocolMap = NULL;const CHXSimpleList* const HXFileSystemManager::zm_CacheList = NULL;#endifHXFileSystemManager::HXFileSystemManager(IUnknown* pContext) : m_lRefCount(0) , m_pContext(pContext) , m_pSamePool(0) , m_pFSManagerResponse(0) , m_pRequest(NULL) , m_pCallback(NULL) , m_pScheduler(NULL) , m_pOriginalObject(NULL) , m_pRelativePath(NULL){ if (m_pContext) { m_pContext->AddRef(); InitMountPoints(m_pContext); }}void HXFileSystemManager::InitMountPoints(IUnknown* pContext){ static const char* const PH_BASE_STR = "FSMount."; static const UINT32 PH_BASE_LEN = 8; static const char* const PH_ELEM_STR = "elem"; static const UINT32 PH_ELEM_LEN = 4; static const UINT32 PH_MAX_INT32_AS_STRING_LEN = 20; static const UINT32 PH_MAX_MEMBER_LEN = 20;#if defined(HELIX_CONFIG_NOSTATICS) BOOL& zm_IsInited = (BOOL&)HXGlobalInt32::Get(&HXFileSystemManager::zm_IsInited);#endif if (zm_IsInited) return; zm_IsInited = TRUE; IHXBuffer* mount_point = 0; IHXBuffer* real_short_name = 0; const char* short_name = 0; IHXValues* options = 0; IHXRegistry* pRegistry; IHXValues* pNameList; if(HXR_OK != pContext->QueryInterface(IID_IHXRegistry, (void**)&pRegistry)) { return; } if(HXR_OK != pRegistry->GetPropListByName("config.FSMount", pNameList)) { pRegistry->Release(); return; } HX_RESULT res; const char* plugName; UINT32 plug_id; res = pNameList->GetFirstPropertyULONG32(plugName, plug_id); while(res == HXR_OK) { HXPropType plugtype = pRegistry->GetTypeById(plug_id); if(plugtype != PT_COMPOSITE) res = HXR_FAIL; else { short_name = strrchr(plugName, '.'); if(!short_name) short_name = plugName; else short_name++; IHXValues* pPropList; if(HXR_OK == pRegistry->GetPropListById(plug_id, pPropList)) { const char* propName; UINT32 prop_id; options = new CHXHeader(); options->AddRef(); res = pPropList->GetFirstPropertyULONG32(propName, prop_id); while(res == HXR_OK) { HXPropType type = pRegistry->GetTypeById(prop_id); const char*propSubName = strrchr(propName, '.') + 1; switch(type) { case PT_INTEGER: { INT32 val; if(HXR_OK == pRegistry->GetIntById(prop_id, val)) { options->SetPropertyULONG32(propSubName, val); } break; } case PT_STRING: { IHXBuffer* pBuffer; if(HXR_OK == pRegistry->GetStrById(prop_id, pBuffer)) { options->SetPropertyBuffer(propSubName, pBuffer); pBuffer->Release(); } break; } case PT_BUFFER: { IHXBuffer* pBuffer; if(HXR_OK == pRegistry->GetBufById(prop_id, pBuffer)) { options->SetPropertyBuffer(propSubName, pBuffer); pBuffer->Release(); } break; } default: break; } res = pPropList->GetNextPropertyULONG32(propName, prop_id); } res = HXR_OK; } if(HXR_OK == options->GetPropertyBuffer("MountPoint", mount_point)) { if(HXR_OK == options->GetPropertyBuffer("ShortName", real_short_name)) short_name = (const char*) real_short_name->GetBuffer(); AddMountPoint(short_name,(const char*)mount_point->GetBuffer(), options, pContext); if(real_short_name) { real_short_name->Release(); real_short_name = 0; } mount_point->Release(); } res = pNameList->GetNextPropertyULONG32(plugName, plug_id); } } pNameList->Release(); pRegistry->Release();}HX_RESULT HXFileSystemManager::AddMountPoint(const char* pszShortName, const char* pszMountPoint, IHXValues* pOptions, IUnknown* pContext){#if defined(HELIX_CONFIG_NOSTATICS) CHXSimpleList& zm_CacheList = HXGlobalList::Get(&HXFileSystemManager::zm_CacheList); CHXMapStringToOb& zm_ShortNameMap = HXGlobalMapStringToOb::Get(&HXFileSystemManager::zm_ShortNameMap); CHXMapStringToOb& zm_ProtocolMap = HXGlobalMapStringToOb::Get(&HXFileSystemManager::zm_ProtocolMap);#endif HX_RESULT result = HXR_OK; IHXPlugin2Handler* pPlugin2Handler = NULL; CCacheInstance* pCCacheInstance = NULL; if (HXR_OK != pContext->QueryInterface(IID_IHXPlugin2Handler, (void**) &pPlugin2Handler)) return HXR_FAIL; if (!pszShortName) { result = HXR_FAIL; goto cleanup; } UINT32 nIndex; if (HXR_OK != pPlugin2Handler->FindIndexUsingStrings(PLUGIN_FILESYSTEMSHORT, (char*)pszShortName, NULL, NULL, NULL, NULL, nIndex)) { result = HXR_FAIL; goto cleanup; } IHXValues* pValues; IHXBuffer* pProtocol; pPlugin2Handler->GetPluginInfo(nIndex, pValues); pValues->GetPropertyCString(PLUGIN_FILESYSTEMPROTOCOL, pProtocol); char* pszProtocol; pszProtocol = (char*)pProtocol->GetBuffer(); pCCacheInstance = new CCacheInstance; pCCacheInstance->m_mount_point = pszMountPoint; pCCacheInstance->m_szProtocol = pszProtocol; pCCacheInstance->m_szShortName = pszShortName; pCCacheInstance->m_pOptions = pOptions; zm_ShortNameMap.SetAt(pszMountPoint, pCCacheInstance); zm_ProtocolMap.SetAt(pszMountPoint, pCCacheInstance); zm_CacheList.AddTail((void*)pCCacheInstance);cleanup: return result;}IHXValues* HXFileSystemManager::GetOptionsGivenURL(const char* pURL){ const char* pszFilePath = HXFindChar(pURL,':'); if (pszFilePath == 0) { pszFilePath = pURL; } else { pszFilePath++; } /* * Must check all plugins, we cannot take just the first one who's mount point is the start * of the url. We must find the one who matches with the mount point of the greatest length. * If p1 = /test and p2 = /test/test2 and the url is /test/test2/file we must use p2. */#if defined(HELIX_CONFIG_NOSTATICS) CHXSimpleList& zm_CacheList = HXGlobalList::Get(&HXFileSystemManager::zm_CacheList);#endif ULONG32 mount_point_len = 0; CCacheInstance* pBestOptions = NULL; for(CHXSimpleList::Iterator i = zm_CacheList.Begin(); i != zm_CacheList.End(); ++i) { CCacheInstance* pCacheOptions = (CCacheInstance*) *i; if (pCacheOptions->m_mount_point.GetLength() > 0 && (strncmp(pCacheOptions->m_mount_point, pszFilePath, pCacheOptions->m_mount_point.GetLength()) == 0)) { if((UINT32)pCacheOptions->m_mount_point.GetLength() >= mount_point_len) { mount_point_len = pCacheOptions->m_mount_point.GetLength(); pBestOptions = pCacheOptions; } } } if (pBestOptions) { return pBestOptions->m_pOptions; } return NULL;}HXFileSystemManager::~HXFileSystemManager(){ if (m_pContext) { m_pContext->Release(); m_pContext = 0; } if(m_pSamePool) { m_pSamePool->Release(); m_pSamePool = NULL; } if (m_pFSManagerResponse) { m_pFSManagerResponse->Release(); m_pFSManagerResponse = 0; } HX_RELEASE(m_pRequest); if (m_pCallback && m_pCallback->m_bIsCallbackPending && m_pScheduler) { m_pScheduler->Remove(m_pCallback->m_Handle); } HX_RELEASE(m_pCallback); HX_RELEASE(m_pScheduler); HX_RELEASE(m_pOriginalObject); HX_VECTOR_DELETE(m_pRelativePath);}// *** IUnknown methods ***/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::QueryInterface// Purpose:// Implement this to export the interfaces supported by your // object.//STDMETHODIMP HXFileSystemManager::QueryInterface(REFIID riid, void** ppvObj){ QInterfaceList qiList[] = { { GET_IIDHANDLE(IID_IHXFileSystemManager), (IHXFileSystemManager*)this }, { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXFileSystemManager*)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) HXFileSystemManager::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) HXFileSystemManager::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}/* * IHXFileSystemManager methods *//************************************************************************ * Method: * IHXFileSystemManager::Init * Purpose: */STDMETHODIMP HXFileSystemManager::Init ( IHXFileSystemManagerResponse* /*IN*/ pFileManagerResponse ){ if (!pFileManagerResponse) { return HXR_FAIL; } /* Release any earlier response */ if (m_pFSManagerResponse) { m_pFSManagerResponse->Release(); m_pFSManagerResponse = 0; } m_pFSManagerResponse = pFileManagerResponse; m_pFSManagerResponse->AddRef(); /* * We might get released (and deleted) in the response object. so * Addref here and Release after the response function is called */ AddRef(); m_pFSManagerResponse->InitDone(HXR_OK); /* Release for extra Addref */ Release(); return HXR_OK;}STDMETHODIMPHXFileSystemManager::GetFileObject(IHXRequest* pRequest,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -