Added start of file: protocol.

This commit is contained in:
warren%netscape.com 1999-06-11 01:37:24 +00:00
parent a66a71b8d7
commit c993890233
12 changed files with 1030 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#! gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
MODULE = netwerk
include $(DEPTH)/config/autoconf.mk
DIRS= \
public \
src \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,30 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#------------------------------------------------------------------------
#
# Makefile to build the pluggable HTTP
#
#------------------------------------------------------------------------
DEPTH=..\..\..
DIRS= \
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -0,0 +1,35 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
MODULE = netwerk
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
XPIDL_MODULE = netwerk_file
XPIDLSRCS = \
nsIFileChannel.idl \
$(NULL)
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
include $(DEPTH)/config/rules.mk

View File

@ -0,0 +1,29 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
MODULE = netwerk
DEPTH = ..\..\..\..
XPIDL_MODULE = netwerk_file
XPIDLSRCS = \
.\nsIFileChannel.idl \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIChannel.idl"
[scriptable, uuid(73025830-0ce2-11d3-9331-00104ba0fd40)]
interface nsIFileChannel : nsIChannel
{
/**
* Returns the creation date of the URL.
*/
readonly attribute PRTime CreationDate;
/**
* Returns the last modification date of the URL.
*/
readonly attribute PRTime ModDate;
/**
* Returns the size of the file referred to by the URL.
* @return NS_ERROR_FAILURE if the URL refers to a directory.
*/
readonly attribute unsigned long FileSize;
/**
* Returns the parent directory of a URL.
*/
readonly attribute nsIFileChannel Parent;
/**
* Returns a native path string suitable to be passes to native platform
* routines.
*/
readonly attribute string NativePath;
/**
* Returns true if the file exists.
*/
boolean Exists();
/**
* Creates an empty file if the file does not exist.
*/
void Create();
/**
* Returns true if the file exists.
*/
void Delete();
/**
* Move or renames a file.
*/
void MoveFrom(in nsIURI src);
/**
* Copies the contents of a file to a new destination. Creates the
* destination file if it doesn't already exist, otherwise overwrites
* it.
*/
void CopyFrom(in nsIURI src);
/**
* Returns true if the file URL specifies a directory. Note that this
* may be the case even if the file URL does not terminate with a slash.
*/
boolean IsDirectory();
/**
* Returns true if the file URL specifies a file and not a directory.
*/
boolean IsFile();
/**
* Returns true if the specified file is a symbolic link (on unix),
* alias (on Mac) or shortcut (on Windows).
*/
boolean IsLink();
/**
* Returns a file URL to the destination of a link (alias or shortcut).
*/
nsIFileChannel ResolveLink();
/**
* Returns a unique file name for the directory of the current URL.
*/
string MakeUniqueFileName(in string baseName);
};

View File

@ -0,0 +1,42 @@
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
LIBRARY_NAME = fileprotocol
IS_COMPONENT = 1
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsFileChannel.cpp \
nsFileProtocolHandler.cpp \
nsFileProtocolFactory.cpp \
$(NULL)
REQUIRES = xpcom netwerk raptor
MODULE = netwerk
include $(topsrcdir)/config/config.mk
TARGET = $(LIBARY)
include $(DEPTH)/config/rules.mk

View File

@ -0,0 +1,56 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
MODULE=netwerk
IS_COMPONENT=1
MAKE_OBJ_TYPE=DLL
DLLNAME=fileprotocol
DLL=.\$(OBJDIR)\$(DLLNAME).dll
LLIBS= $(LLIBS) \
$(LIBNSPR) \
$(DIST)\lib\plc3.lib \
$(DIST)\lib\xpcom.lib \
$(NULL)
MISCDEP=$(LLIBS)
CPP_OBJS= \
.\$(OBJDIR)\nsFileChannel.obj \
.\$(OBJDIR)\nsFileProtocolHandler.obj \
.\$(OBJDIR)\nsFileProtocolFactory.obj \
$(NULL)
LOCAL_INCLUDES=-I.
INCLUDES = $(LOCAL_INCLUDES)
REQUIRES= netwerk
LINCS= \
-I$(PUBLIC)\netwerk \
-I$(PUBLIC)\xpcom \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib

View File

@ -0,0 +1,271 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFileChannel.h"
#include "nscore.h"
////////////////////////////////////////////////////////////////////////////////
nsFileChannel::nsFileChannel()
{
NS_INIT_REFCNT();
}
nsresult
nsFileChannel::Init(nsIURI* uri, nsIEventSinkGetter* getter, nsIEventQueue* queue)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsFileChannel::~nsFileChannel()
{
}
NS_IMETHODIMP
nsFileChannel::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(nsIFileChannel::GetIID()) ||
aIID.Equals(nsIChannel::GetIID()) ||
aIID.Equals(nsISupports::GetIID()) ) {
*aInstancePtr = NS_STATIC_CAST(nsIFileChannel*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsFileChannel);
NS_IMPL_RELEASE(nsFileChannel);
NS_METHOD
nsFileChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
{
nsFileChannel* fc = new nsFileChannel();
if (fc == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(fc);
nsresult rv = fc->QueryInterface(aIID, aResult);
NS_RELEASE(fc);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// From nsIChannel
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::GetURI(nsIURI * *aURI)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::OpenInputStream(PRUint32 startPosition, PRInt32 count,
nsIInputStream **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::AsyncWrite(nsIInputStream *fromStream,
PRUint32 startPosition, PRInt32 writeCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamObserver *observer)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::Cancel()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::Suspend()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::Resume()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// From nsIFileChannel
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::GetCreationDate(PRTime *aCreationDate)
{
// XXX no GetCreationDate in nsFileSpec yet
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::GetModDate(PRTime *aModDate)
{
return NS_ERROR_NOT_IMPLEMENTED;
#if 0
PRUint32 date;
nsresult rv = GetModDate(&date);
LL_I2L(*aModDate, date);
return rv;
#endif
}
NS_IMETHODIMP
nsFileChannel::GetFileSize(PRUint32 *aFileSize)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::GetParent(nsIFileChannel * *aParent)
{
// return GetParent((nsIFileSpec**)aParent);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::GetNativePath(char * *aNativePath)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::Exists(PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::Create()
{
// XXX no Create in nsFileSpec -- creates non-existent file
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::Delete()
{
// XXX no Delete in nsFileSpec -- deletes file or dir
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::MoveFrom(nsIURI *src)
{
#if 0
nsresult rv;
nsIFileChannel* FileChannel;
rv = src->QueryInterface(nsIFileChannel::GetIID(), (void**)&FileChannel);
if (NS_SUCCEEDED(rv)) {
rv = FileChannel->moveToDir(this);
NS_RELEASE(FileChannel);
return rv;
}
else {
// Do it the hard way -- fetch the URL and store the bits locally.
// Delete the src when done.
return NS_ERROR_NOT_IMPLEMENTED;
}
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
NS_IMETHODIMP
nsFileChannel::CopyFrom(nsIURI *src)
{
#if 0
nsresult rv;
nsIFileChannel* FileChannel;
rv = src->QueryInterface(nsIFileChannel::GetIID(), (void**)&FileChannel);
if (NS_SUCCEEDED(rv)) {
rv = FileChannel->copyToDir(this);
NS_RELEASE(FileChannel);
return rv;
}
else {
// Do it the hard way -- fetch the URL and store the bits locally.
return NS_ERROR_NOT_IMPLEMENTED;
}
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
NS_IMETHODIMP
nsFileChannel::IsDirectory(PRBool *_retval)
{
// XXX rename isDirectory to IsDirectory
// return isDirectory(_retval);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::IsFile(PRBool *_retval)
{
// XXX rename isFile to IsFile
// return isFile(_retval);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::IsLink(PRBool *_retval)
{
// XXX no IsLink in nsFileSpec (for alias/shortcut/symlink)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::ResolveLink(nsIFileChannel **_retval)
{
// XXX no ResolveLink in nsFileSpec yet -- returns what link points to
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileChannel::MakeUniqueFileName(const char* baseName, char **_retval)
{
// XXX makeUnique needs to return the name or file spec to the newly create
// file!
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,122 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsFileChannel_h__
#define nsFileChannel_h__
#include "nsIFileChannel.h"
class nsIEventSinkGetter;
class nsFileChannel : public nsIFileChannel {
public:
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////
// from nsIChannel:
/* readonly attribute nsIURI URI; */
NS_IMETHOD GetURI(nsIURI * *aURI);
/* nsIInputStream OpenInputStream (); */
NS_IMETHOD OpenInputStream(PRUint32 startPosition, PRInt32 count, nsIInputStream **_retval);
/* nsIOutputStream OpenOutputStream (); */
NS_IMETHOD OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval);
/* void AsyncRead (in unsigned long startPosition, in long readCount, in nsISupports ctxt, in nsIEventQueue eventQueue, in nsIStreamListener listener); */
NS_IMETHOD AsyncRead(PRUint32 startPosition, PRInt32 readCount, nsISupports *ctxt, nsIEventQueue *eventQueue, nsIStreamListener *listener);
/* void AsyncWrite (in nsIInputStream fromStream, in unsigned long startPosition, in long writeCount, in nsISupports ctxt, in nsIEventQueue eventQueue, in nsIStreamObserver observer); */
NS_IMETHOD AsyncWrite(nsIInputStream *fromStream, PRUint32 startPosition, PRInt32 writeCount, nsISupports *ctxt, nsIEventQueue *eventQueue, nsIStreamObserver *observer);
/* void Cancel (); */
NS_IMETHOD Cancel();
/* void Suspend (); */
NS_IMETHOD Suspend();
/* void Resume (); */
NS_IMETHOD Resume();
////////////////////////////////////////////////////////////////////////////
// from nsIFileChannel:
/* readonly attribute PRTime CreationDate; */
NS_IMETHOD GetCreationDate(PRTime *aCreationDate);
/* readonly attribute PRTime ModDate; */
NS_IMETHOD GetModDate(PRTime *aModDate);
/* readonly attribute unsigned long FileSize; */
NS_IMETHOD GetFileSize(PRUint32 *aFileSize);
/* readonly attribute nsIFileChannel Parent; */
NS_IMETHOD GetParent(nsIFileChannel * *aParent);
/* readonly attribute string NativePath; */
NS_IMETHOD GetNativePath(char * *aNativePath);
/* boolean Exists (); */
NS_IMETHOD Exists(PRBool *_retval);
/* void Create (); */
NS_IMETHOD Create();
/* void Delete (); */
NS_IMETHOD Delete();
/* void MoveFrom (in nsIURI src); */
NS_IMETHOD MoveFrom(nsIURI *src);
/* void CopyFrom (in nsIURI src); */
NS_IMETHOD CopyFrom(nsIURI *src);
/* boolean IsDirectory (); */
NS_IMETHOD IsDirectory(PRBool *_retval);
/* boolean IsFile (); */
NS_IMETHOD IsFile(PRBool *_retval);
/* boolean IsLink (); */
NS_IMETHOD IsLink(PRBool *_retval);
/* nsIFileChannel ResolveLink (); */
NS_IMETHOD ResolveLink(nsIFileChannel **_retval);
/* string MakeUniqueFileName (in string baseName); */
NS_IMETHOD MakeUniqueFileName(const char *baseName, char **_retval);
////////////////////////////////////////////////////////////////////////////
// nsFileChannel:
nsFileChannel();
// Always make the destructor virtual:
virtual ~nsFileChannel();
// Define a Create method to be used with a factory:
static NS_METHOD
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
nsresult Init(nsIURI* uri, nsIEventSinkGetter* getter, nsIEventQueue* queue);
protected:
};
#endif // nsFileChannel_h__

View File

@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIGenericFactory.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsFileProtocolHandler.h"
#include "nscore.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kFileProtocolHandlerCID, NS_FILEPROTOCOLHANDLER_CID);
////////////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
nsresult rv;
if (aFactory == nsnull)
return NS_ERROR_NULL_POINTER;
nsIGenericFactory* fact;
if (aClass.Equals(kFileProtocolHandlerCID)) {
rv = NS_NewGenericFactory(&fact, nsFileProtocolHandler::Create);
}
else {
rv = NS_ERROR_FAILURE;
}
if (NS_SUCCEEDED(rv))
*aFactory = fact;
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kFileProtocolHandlerCID,
"File Protocol Handler",
NS_NETWORK_PROTOCOL_PROGID_PREFIX "file",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;;
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kFileProtocolHandlerCID, aPath);
if (NS_FAILED(rv)) return rv;
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,158 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFileChannel.h"
#include "nsFileProtocolHandler.h"
#include "nsIURL.h"
#include "nsCRT.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIEventSinkGetter.h"
#include "nsIProgressEventSink.h"
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
////////////////////////////////////////////////////////////////////////////////
nsFileProtocolHandler::nsFileProtocolHandler() {
NS_INIT_REFCNT();
}
nsFileProtocolHandler::~nsFileProtocolHandler() {
}
NS_IMPL_ISUPPORTS(nsFileProtocolHandler, nsIProtocolHandler::GetIID());
NS_METHOD
nsFileProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsFileProtocolHandler* ph = new nsFileProtocolHandler();
if (ph == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(ph);
nsresult rv = ph->QueryInterface(aIID, aResult);
NS_RELEASE(ph);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
NS_IMETHODIMP
nsFileProtocolHandler::GetScheme(char* *result)
{
*result = nsCRT::strdup("ftp");
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::GetDefaultPort(PRInt32 *result)
{
*result = 21;
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::MakeAbsolute(const char* aSpec,
nsIURI* aBaseURI,
char* *result)
{
// XXX optimize this to not needlessly construct the URL
nsresult rv;
nsIURI* url;
rv = NewURI(aSpec, aBaseURI, &url);
if (NS_FAILED(rv)) return rv;
rv = url->GetSpec(result);
NS_RELEASE(url);
return rv;
}
NS_IMETHODIMP
nsFileProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
// Ftp URLs (currently) have no additional structure beyond that provided by standard
// URLs, so there is no "outer" given to CreateInstance
nsIURI* url;
if (aBaseURI) {
rv = aBaseURI->Clone(&url);
}
else {
rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull,
nsIURI::GetIID(),
(void**)&url);
}
if (NS_FAILED(rv)) return rv;
rv = url->SetSpec((char*)aSpec);
if (NS_FAILED(rv)) {
NS_RELEASE(url);
return rv;
}
// XXX this is the default port for ftp. we need to strip out the actual
// XXX requested port.
rv = url->SetPort(21);
if (NS_FAILED(rv)) {
NS_RELEASE(url);
return rv;
}
*result = url;
return rv;
}
NS_IMETHODIMP
nsFileProtocolHandler::NewChannel(const char* verb, nsIURI* url,
nsIEventSinkGetter* eventSinkGetter,
nsIEventQueue* eventQueue,
nsIChannel* *result)
{
nsresult rv;
nsIProgressEventSink* eventSink;
rv = eventSinkGetter->GetEventSink(verb, nsIProgressEventSink::GetIID(),
(nsISupports**)&eventSink);
if (NS_FAILED(rv)) return rv;
nsFileChannel* channel = new nsFileChannel();
if (channel == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(channel);
rv = channel->Init(url, eventSinkGetter, eventQueue);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = channel;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsFileProtocolHandler_h___
#define nsFileProtocolHandler_h___
#include "nsIProtocolHandler.h"
// {25029490-F132-11d2-9588-00805F369F95}
#define NS_FILEPROTOCOLHANDLER_CID \
{ /* fbc81170-1f69-11d3-9344-00104ba0fd40 */ \
0xfbc81170, \
0x1f69, \
0x11d3, \
{0x93, 0x44, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
class nsFileProtocolHandler : public nsIProtocolHandler
{
public:
NS_DECL_ISUPPORTS
// nsIProtocolHandler methods:
NS_IMETHOD GetScheme(char * *aScheme);
NS_IMETHOD GetDefaultPort(PRInt32 *aDefaultPort);
NS_IMETHOD MakeAbsolute(const char *aRelativeSpec, nsIURI *aBaseURI,
char **_retval);
NS_IMETHOD NewURI(const char *aSpec, nsIURI *aBaseURI,
nsIURI **_retval);
NS_IMETHOD NewChannel(const char* verb, nsIURI* url,
nsIEventSinkGetter *eventSinkGetter,
nsIEventQueue *eventQueue,
nsIChannel **_retval);
// nsFileProtocolHandler methods:
nsFileProtocolHandler();
virtual ~nsFileProtocolHandler();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
protected:
nsISupports* mEventSinkGetter;
};
#endif /* nsFileProtocolHandler_h___ */