httpfilesys.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:11k
- /* ***** 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 ***** */
- /****************************************************************************
- * Defines
- */
- #define INITGUID /* Interface ID's */
- /****************************************************************************
- * Includes
- */
- #include "hlxclib/string.h" /* strcpy */
- #include "hxtypes.h"
- #include "hxver.h" /* HXVER_COPYRIGHT */
- #include "hxcom.h" /* IUnknown */
- #include "hxcomm.h" /* IHXCommonClassFactory */
- #include "ihxpckts.h" /* IHXValues */
- #include "hxprefs.h"
- #include "httpfilesys.h" /* CHTTPFileSystem */
- #include "httpfileobj.h" /* CHTTPFileObject */
- #include "hxcache2.h"
- #include "httpfilesys.ver" /* version info */
- #include "debug.h"
- #define D_HTTP_FS 0x1000000
- #undef INITGUID
- /****************************************************************************
- *
- * 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** ppFileSystemObj)
- {
- DPRINTF(D_HTTP_FS, ("HTTPFileSystem HXCREATEINSTANCE()n"));
- HX_RESULT res = HXR_OUTOFMEMORY;
- *ppFileSystemObj = (IUnknown*)(IHXPlugin*)new CHXHTTPFileSystem();
- if (*ppFileSystemObj != NULL)
- {
- (*ppFileSystemObj)->AddRef();
- res = HXR_OK;
- }
-
- return res;
- }
- STDAPI ENTRYPOINT(CanUnload2)(void)
- {
- return (CHXBaseCountingObject::ObjectsActive() > 0 ? HXR_FAIL : HXR_OK);
- }
- // CHXHTTPFileSystem Class Methods
- /****************************************************************************
- * CHXHTTPFileSystem static variables
- *
- * These variables are passed to the Helix core to provide information about
- * this plug-in. They are required to be static in order to remain valid
- * for the lifetime of the plug-in.
- */
- const char* const CHXHTTPFileSystem::zm_pDescription = "Helix HTTP File System";
- const char* const CHXHTTPFileSystem::zm_pCopyright = HXVER_COPYRIGHT;
- const char* const CHXHTTPFileSystem::zm_pMoreInfoURL = HXVER_MOREINFO;
- const char* const CHXHTTPFileSystem::zm_pShortName = "hx-http";
- const char* const CHXHTTPFileSystem::zm_pProtocol = FILE_SYS_PROTOCOL;
- /****************************************************************************
- * CHXHTTPFileSystem::CHXHTTPFileSystem
- *
- * Constructor
- */
- CHXHTTPFileSystem::CHXHTTPFileSystem(void)
- : m_RefCount (0),
- m_pContext (NULL),
- m_pOptions (NULL)
- {
- DPRINTF(D_HTTP_FS, ("CHXHTTPFileSystem()n"));
- }
- /****************************************************************************
- * CHXHTTPFileSystem::~CHXHTTPFileSystem
- *
- * Destructor. Be sure to release all outstanding references to objects.
- */
- CHXHTTPFileSystem::~CHXHTTPFileSystem(void)
- {
- DPRINTF(D_HTTP_FS, ("~CHXHTTPFileSystem()n"));
- HX_RELEASE(m_pContext);
- HX_RELEASE(m_pOptions);
- }
- // IHXFileSystemObject Interface Methods
- /****************************************************************************
- * IHXFileSystemObject::GetFileSystemInfo
- *
- * This routine returns crucial information required to associate this
- * plug-in with a given protocol. This information tells the core which
- * File System plug-in to use for a particular protocol. For example, in the
- * URL: "file://myfile.txt", the protocol would be "file". This routine is
- * called when the Helix core application is launched.
- */
- STDMETHODIMP
- CHXHTTPFileSystem::GetFileSystemInfo(REF(const char*) pShortName,
- REF(const char*) pProtocol)
- {
- DPRINTF(D_HTTP_FS, ("GetFileSystemInfo()n"));
- pShortName = zm_pShortName;
- pProtocol = zm_pProtocol;
- return HXR_OK;
- }
- /****************************************************************************
- * IHXFileSystemObject::InitFileSystem
- *
- * This routine performs any additional initialization steps required for
- * the file system. It is called prior to the CreatFile() request. Any
- * options provided usually refer to mounting options related to the server,
- * such as base path or authentication preferences.
- */
- STDMETHODIMP
- CHXHTTPFileSystem::InitFileSystem(IHXValues* options )
- {
- DPRINTF(D_HTTP_FS, ("InitFileSystem()n"));
- if(options)
- {
- m_pOptions = options;
- m_pOptions->AddRef();
- }
-
- return HXR_OK;
- }
- /****************************************************************************
- * IHXFileSystemObject::CreateFile
- *
- * This routine creates a new File Object which handles all of the file I/O
- * functionality of this class. This File Object is eventually handed off
- * to a File Format plug-in which handles file I/O through this File Object.
- * This method is called called when an URL with a protocol associated with
- * this plug-in is opened.
- */
- STDMETHODIMP
- CHXHTTPFileSystem::CreateFile(IUnknown** ppFileObject)
- {
- DPRINTF(D_HTTP_FS, ("CreateFile()n"));
- HX_RESULT res = HXR_OUTOFMEMORY;
- // Create a new File Object which implements the file I/O methods
- CHXHTTPFileObject* pFileObj = new CHXHTTPFileObject(m_pContext, m_pOptions);
- if (pFileObj != NULL)
- {
- pFileObj->QueryInterface(IID_IUnknown, (void**)ppFileObject);
- res = (pFileObj != NULL) ? HXR_OK : HXR_UNEXPECTED;
- }
- return res;
- }
- /****************************************************************************
- * IHXFileSystemObject::CreateDir
- *
- * This routine is analagous to CreatFile, except directories instead of
- * files are of concern. It is not implemented in this plugin.
- */
- STDMETHODIMP
- CHXHTTPFileSystem::CreateDir(IUnknown** /* ppDirectoryObject */)
- {
- DPRINTF(D_HTTP_FS, ("CreateDir()n"));
- return HXR_NOTIMPL;
- }
- // IHXPlugin Interface Methods
- /****************************************************************************
- * IHXPlugin::GetPluginInfo
- *
- * This routine returns descriptive information about the plug-in, most
- * of which is used in the About box of the user interface. It is called
- * when the Helix core application is launched.
- */
- STDMETHODIMP
- CHXHTTPFileSystem::GetPluginInfo(REF(BOOL) bLoadMultiple,
- REF(const char*) pDescription,
- REF(const char*) pCopyright,
- REF(const char*) pMoreInfoURL,
- REF(UINT32) versionNumber)
- {
- DPRINTF(D_HTTP_FS, ("GetPluginInfo()n"));
- bLoadMultiple = TRUE;
- pDescription = zm_pDescription;
- pCopyright = zm_pCopyright;
- pMoreInfoURL = zm_pMoreInfoURL;
- versionNumber = TARVER_ULONG32_VERSION;
- return HXR_OK;
- }
- /****************************************************************************
- * IHXPlugin::InitPlugin
- *
- * This routine performs initialization steps such as determining if
- * required interfaces are available. It is called when the Helix core
- * application is launched, and whenever an URL with a protocol associated
- * with this plug-in is opened.
- */
- STDMETHODIMP
- CHXHTTPFileSystem::InitPlugin(IUnknown* pContext)
- {
- DPRINTF(D_HTTP_FS, ("InitPlugin()n"));
- HX_RESULT res = HXR_OK;
- if (pContext == NULL)
- {
- res = HXR_NOINTERFACE;
- }
- else
- {
- m_pContext = pContext;
- m_pContext->AddRef();
- }
- return res;
- }
- // IUnknown COM Interface Methods
- /****************************************************************************
- * IUnknown::AddRef
- *
- * This routine increases the object reference count in a thread safe
- * manner. The reference count is used to manage the lifetime of an object.
- * This method must be explicitly called by the user whenever a new
- * reference to an object is used.
- */
- STDMETHODIMP_(UINT32) CHXHTTPFileSystem::AddRef(void)
- {
- return InterlockedIncrement(&m_RefCount);
- }
- /****************************************************************************
- * IUnknown::Release
- *
- * This routine decreases the object reference count in a thread safe
- * manner, and deletes the object if no more references to it exist. It must
- * be called explicitly by the user whenever an object is no longer needed.
- */
- STDMETHODIMP_(UINT32) CHXHTTPFileSystem::Release(void)
- {
- if (InterlockedDecrement(&m_RefCount) > 0)
- {
- return m_RefCount;
- }
- delete this;
- return 0;
- }
- /****************************************************************************
- * IUnknown::QueryInterface
- *
- * This routine indicates which interfaces this object supports. If a given
- * interface is supported, the object's reference count is incremented, and
- * a reference to that interface is returned. Otherwise a NULL object and
- * error code are returned. This method is called by other objects to
- * discover the functionality of this object.
- */
- STDMETHODIMP CHXHTTPFileSystem::QueryInterface(REFIID interfaceID,
- void** ppInterfaceObj)
- {
- // By definition all COM objects support the IUnknown interface
- if (IsEqualIID(interfaceID, IID_IUnknown))
- {
- AddRef();
- *ppInterfaceObj = (IUnknown*)(IHXPlugin*)this;
- return HXR_OK;
- }
- // IHXPlugin interface is supported
- else if (IsEqualIID(interfaceID, IID_IHXPlugin))
- {
- AddRef();
- *ppInterfaceObj = (IHXPlugin*)this;
- return HXR_OK;
- }
- // IHXFileSystemObject interface is supported
- else if (IsEqualIID(interfaceID, IID_IHXFileSystemObject))
- {
- AddRef();
- *ppInterfaceObj = (IHXFileSystemObject*)this;
- return HXR_OK;
- }
- // No other interfaces are supported
- *ppInterfaceObj = NULL;
- return HXR_NOINTERFACE;
- }