📄 memfsys.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: memfsys.cpp,v 1.3.38.2 2004/07/12 23:05:02 sehancher 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 ***** *//////////////////////////////////////////////////////////////////////////////// // Memory File System for chunky res objects//// This is a memory file system, it stores data in chunky res objects and// allows access to these objects as if they were files//#define INITGUID 1#include "hxcom.h"#include "hxtypes.h"#include "memfsys.ver"#include "hxcomm.h"#include "ihxpckts.h"#include "hxfiles.h"#include "hxplugn.h"#include "hxengin.h"#include "hxcore.h"#include "hxprefs.h"#include "hxrendr.h"#include "hxauth.h"#include "hxauthn.h"#include "hxplgns.h"#include "hxpends.h"#undef INITGUID#include "hxathsp.h"#include "hxcorsp.h"#include "hxpktsp.h"#include "hxcomsp.h"#include "hxplnsp.h"#include "timeval.h"#include "dbcs.h" /* for HXCompareStrings */#include "hxstring.h" /* for CHXString */#include "hxurl.h" /* for CHXURL */#include "hxxfile.h" /* for HXXFile::GetReasonableLocalFileName() */#include "hxstrutl.h"#include "hxver.h"#include "chxpckts.h"#include "hxslist.h"#include "chunkres.h"#include <stdio.h>#include <string.h>#ifdef _MACINTOSH#include <fcntl.h>#include "chxdataf.h" // Macintosh file i/o#include "macasyncfile.h" // Macintosh interrupt file i/o#elif (defined (_WINDOWS ) || defined (_WIN32)) && !defined(WIN32_PLATFORM_PSPC)#include <direct.h>#else#include "hlxclib/sys/types.h"#include "hlxclib/sys/stat.h"#endif#include "findfile.h"#include "mfsiface.h"#include "memfsys.h"#if defined (_WINDOWS ) || defined (_WIN32)#define OS_SEPARATOR_CHAR '\\'#define OS_SEPARATOR_STRING "\\"#elif defined (_UNIX)#define OS_SEPARATOR_CHAR '/'#define OS_SEPARATOR_STRING "/"#elif defined (__MWERKS__)#define OS_SEPARATOR_CHAR ':'#define OS_SEPARATOR_STRING ":"#endif // defined (_WINDOWS ) || defined (WIN32)#ifdef _WIN16#define MAX_RECURSION_LEVEL 10#elif _LINUX#define MAX_RECURSION_LEVEL 30#else#define MAX_RECURSION_LEVEL 200#endif#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static char HX_THIS_FILE[] = __FILE__;#endif#ifdef _AIX#include "hxtbuf.h"#include "dllpath.h"ENABLE_MULTILOAD_DLLACCESS_PATHS(Memfsys);#endifINT32 g_nMemFSysRefCount = 0;const char* CMemoryFileSystem::zm_pDescription = "RealNetworks Memory File System";const char* CMemoryFileSystem::zm_pCopyright = HXVER_COPYRIGHT;const char* CMemoryFileSystem::zm_pMoreInfoURL = HXVER_MOREINFO;const char* CMemoryFileSystem::zm_pShortName = "pn-memory";const char* CMemoryFileSystem::zm_pProtocol = "mem";IHXMemoryFileContext* CMemoryFileSystem::z_pMemCtx = NULL;CChunkyResMgr* g_pChunkyResMgr = NULL;CHXMapPtrToPtr* g_pMapChunkyToStatus = NULL;CHXMapPtrToPtr* g_pMapStreamToChunky = NULL;CHXMapStringToOb* g_pMapURLToResponse = NULL;UINT32 CMemoryFileSystem::z_uMaxRecursionLevel = MAX_RECURSION_LEVEL;/**************************************************************************** * * Function: * * HXCreateInstance() * * Purpose: * * Function implemented by all plugin DLL's to create an instance of * any of the objects supported by the DLL. This method is similar to * Window's CoCreateInstance() in its purpose, except that it only * creates objects from this plugin DLL. * * NOTE: Aggregation is never used. Therefore and outer unknown is * not passed to this function, and you do not need to code for this * situation. * */STDAPI ENTRYPOINT(HXCREATEINSTANCE)( IUnknown** /*OUT*/ ppIUnknown){ if (!g_pChunkyResMgr) { g_pChunkyResMgr = new CChunkyResMgr; if (!g_pChunkyResMgr) { return HXR_OUTOFMEMORY; } } if (!g_pMapChunkyToStatus) { g_pMapChunkyToStatus = new CHXMapPtrToPtr; if (!g_pMapChunkyToStatus) { return HXR_OUTOFMEMORY; } } if (!g_pMapStreamToChunky) { g_pMapStreamToChunky = new CHXMapPtrToPtr; if (!g_pMapStreamToChunky) { return HXR_OUTOFMEMORY; } } if (!g_pMapURLToResponse) { g_pMapURLToResponse = new CHXMapStringToOb; if (!g_pMapURLToResponse) { return HXR_OUTOFMEMORY; } } *ppIUnknown = (IUnknown*)(IHXPlugin*) new CMemoryFileSystem; if (*ppIUnknown) { (*ppIUnknown)->AddRef(); return HXR_OK; } return HXR_OUTOFMEMORY;}/**************************************************************************** * * Function: * * CanUnload() * * Purpose: * * Function implemented by all plugin DLL's if it returns HXR_OK * then the pluginhandler can unload the DLL * */STDAPI CanUnload(void){ return (g_nMemFSysRefCount ? HXR_FAIL : HXR_OK);}/**************************************************************************** * * Function: * * HXShutdown() * * Purpose: * * Function implemented by all plugin DLL's to free any *global* * resources. This method is called just before the DLL is unloaded. * */STDAPI HXShutdown(void){ HX_ASSERT(!g_nMemFSysRefCount); POSITION p; HX_RELEASE(CMemoryFileSystem::z_pMemCtx); if (g_pChunkyResMgr) { delete g_pChunkyResMgr; g_pChunkyResMgr = NULL; } if (g_pMapStreamToChunky) { delete g_pMapStreamToChunky; g_pMapStreamToChunky = NULL; } if (g_pMapChunkyToStatus) { CMemoryFileStatus* pStatus; CChunkyRes* pRes; p = g_pMapChunkyToStatus->GetStartPosition(); while (p) { g_pMapChunkyToStatus->GetNextAssoc(p, (void*&)pRes, (void*&)pStatus); HX_ASSERT(pStatus); HX_RELEASE(pStatus); } delete g_pMapChunkyToStatus; g_pMapChunkyToStatus = NULL; } if (g_pMapURLToResponse) { CHXString sURL; IHXFileResponse* pResponse; p = g_pMapURLToResponse->GetStartPosition(); while (p) { g_pMapURLToResponse->GetNextAssoc(p, sURL, (void*&)pResponse); HX_ASSERT(pResponse); pResponse->InitDone(HXR_FAIL); HX_RELEASE(pResponse); } delete g_pMapURLToResponse; g_pMapURLToResponse = NULL; } return HXR_OK;}CMemoryFileStatus::CMemoryFileStatus(IHXMemoryFileContext* pContext, void* pID, const char* pMime) : m_pContext(pContext) , m_pID(pID) , m_ulSize(0) , m_ulContentSize(0) , m_bDone(FALSE) , m_pMime(NULL) , m_lRefCount(0){ HX_ASSERT(m_pContext); m_pContext->AddRef(); SetMime(pMime);}CMemoryFileStatus::~CMemoryFileStatus(){ HX_RELEASE(m_pContext); if (m_pMime) { delete[] m_pMime; }}void CMemoryFileStatus::SetMime(const char* pMime){ if (m_pMime) { delete[] m_pMime; m_pMime = NULL; } if (pMime && *pMime) { m_pMime = new char[strlen(pMime)+1]; if (m_pMime) { strcpy(m_pMime, pMime); /* Flawfinder: ignore */ } }}LONG32 CMemoryFileStatus::AddRef(){ return InterlockedIncrement(&m_lRefCount);}LONG32 CMemoryFileStatus::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}void CMemoryFileStatus::SetDone(BOOL bDone){ m_bDone = bDone; // Someone aborted this thing! if (m_ulSize < m_ulContentSize) { m_ulContentSize = m_ulSize; }}IHXMemoryFileContext* CMemoryFileStatus::GetContext(){ m_pContext->AddRef(); return m_pContext;}CMemoryFileSystem::CMemoryFileSystem() : m_lRefCount(0) , m_pContext(0) , m_options(NULL){ g_nMemFSysRefCount++;}CMemoryFileSystem::~CMemoryFileSystem(){ HX_ASSERT(g_nMemFSysRefCount > 0); g_nMemFSysRefCount--; if (m_pContext) { m_pContext->Release(); m_pContext = 0; } if(m_options) { m_options->Release(); m_options = 0; }}/************************************************************************ * Method: * IHXPlugin::InitPlugin * Purpose: * Initializes the plugin for use. This interface must always be * called before any other method is called. This is primarily needed * so that the plugin can have access to the context for creation of * IHXBuffers and IMalloc. */STDMETHODIMP CMemoryFileSystem::InitPlugin(IUnknown* /*IN*/ pContext){ HX_RESULT lResult; IHXPreferences* prefs = 0; IHXBuffer* base_path_buf = 0; if (pContext && !m_pContext) { m_pContext = pContext; m_pContext->AddRef(); if(!m_options || (HXR_OK != m_options->GetPropertyBuffer("BasePath", base_path_buf))) { lResult = pContext->QueryInterface(IID_IHXPreferences, (void**) &prefs); if (lResult == HXR_OK) { lResult = prefs->ReadPref("BasePath", base_path_buf); if (lResult == HXR_OK) { m_base_path = CHXString((char*)base_path_buf->GetBuffer()); } } } else { m_base_path = CHXString((char*)base_path_buf->GetBuffer()); } } if (prefs) { prefs->Release(); prefs = 0; } if (base_path_buf) { base_path_buf->Release(); base_path_buf = 0; } return HXR_OK;}/************************************************************************ * Method: * IHXPlugin::GetPluginInfo * Purpose: * Returns the basic information about this plugin. Including: * * unInterfaceCount the number of standard RMA interfaces * supported by this plugin DLL. * pIIDList array of IID's for standard RMA interfaces * supported by this plugin DLL. * bLoadMultiple whether or not this plugin DLL can be loaded * multiple times. All File Formats must set * this value to TRUE. * pDescription which is used in about UIs (can be NULL) * pCopyright which is used in about UIs (can be NULL) * pMoreInfoURL which is used in about UIs (can be NULL) */STDMETHODIMP CMemoryFileSystem::GetPluginInfo( REF(BOOL) /*OUT*/ bLoadMultiple, REF(const char*) /*OUT*/ pDescription, REF(const char*) /*OUT*/ pCopyright, REF(const char*) /*OUT*/ pMoreInfoURL, REF(ULONG32) /*OUT*/ ulVersionNumber){ bLoadMultiple = TRUE; pDescription = zm_pDescription; pCopyright = zm_pCopyright; pMoreInfoURL = zm_pMoreInfoURL; ulVersionNumber = TARVER_ULONG32_VERSION; return HXR_OK;}// *** IUnknown methods ***/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::QueryInterface// Purpose:// Implement this to export the interfaces supported by your // object.//STDMETHODIMP CMemoryFileSystem::QueryInterface(REFIID riid, void** ppvObj){ if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXPlugin)) { AddRef(); *ppvObj = (IHXPlugin*)this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXFileSystemObject)) { AddRef(); *ppvObj = (IHXFileSystemObject*)this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXMemoryFileSystem)) { AddRef(); *ppvObj = (IHXMemoryFileSystem*)this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXMemoryFileSystem2)) { AddRef(); *ppvObj = (IHXMemoryFileSystem2*)this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXValues)) { AddRef(); *ppvObj = (IHXValues*)this; return HXR_OK; } *ppvObj = NULL; return HXR_NOINTERFACE;}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::AddRef// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) CMemoryFileSystem::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) CMemoryFileSystem::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}STDMETHODIMP CMemoryFileSystem::GetFileSystemInfo(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -