Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
e7686eebad This commit was manufactured by cvs2svn to create tag 'WHH-6-17_BASE'.
git-svn-id: svn://10.0.0.236/tags/WHH-6-17_BASE@35819 18797224-902f-48f8-a5cc-f745e15eee43
1999-06-17 21:41:27 +00:00
765 changed files with 218656 additions and 105 deletions

View File

@@ -1,105 +0,0 @@
/*
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is mozilla.org code.
The Initial Developer of the Original Code is Sun Microsystems,
Inc. Portions created by Sun are
Copyright (C) 1999 Sun Microsystems, Inc. All
Rights Reserved.
Contributor(s):
*/
#ifndef __JavaDOMGlobals_h__
#define __JavaDOMGlobals_h__
#include "jni.h"
#include "prclist.h"
#include "nsError.h"
#ifdef ERROR
#undef ERROR
#endif
class nsISupports;
class nsIDOMNode;
struct PRLogModuleInfo;
struct PRLock;
class JavaDOMGlobals {
public:
static jclass attrClass;
static jclass cDataSectionClass;
static jclass commentClass;
static jclass documentClass;
static jclass documentFragmentClass;
static jclass documentTypeClass;
static jclass domImplementationClass;
static jclass elementClass;
static jclass entityClass;
static jclass entityReferenceClass;
static jclass namedNodeMapClass;
static jclass nodeClass;
static jclass nodeListClass;
static jclass notationClass;
static jclass processingInstructionClass;
static jclass textClass;
static jfieldID nodePtrFID;
static jfieldID nodeListPtrFID;
static jfieldID domImplementationPtrFID;
static jfieldID nodeTypeAttributeFID;
static jfieldID nodeTypeCDataSectionFID;
static jfieldID nodeTypeCommentFID;
static jfieldID nodeTypeDocumentFragmentFID;
static jfieldID nodeTypeDocumentFID;
static jfieldID nodeTypeDocumentTypeFID;
static jfieldID nodeTypeElementFID;
static jfieldID nodeTypeEntityFID;
static jfieldID nodeTypeEntityReferenceFID;
static jfieldID nodeTypeNotationFID;
static jfieldID nodeTypeProcessingInstructionFID;
static jfieldID nodeTypeTextFID;
static jclass domExceptionClass;
static jmethodID domExceptionInitMID;
static jclass runtimeExceptionClass;
static jmethodID runtimeExceptionInitMID;
static const char* const DOM_EXCEPTION_MESSAGE[];
typedef enum ExceptionType { EXCEPTION_RUNTIME,
EXCEPTION_DOM } ExceptionType;
static PRLogModuleInfo* log;
static PRCList garbage;
static PRLock* garbageLock;
static PRInt32 javaMaxInt;
static void Initialize(JNIEnv *env);
static void Destroy(JNIEnv *env);
static jobject CreateNodeSubtype(JNIEnv *env,
nsIDOMNode *node);
static void AddToGarbage(nsISupports* domObject);
static void TakeOutGarbage();
static void ThrowException(JNIEnv *env,
const char * message = NULL,
nsresult rv = NS_OK,
ExceptionType exceptionType = EXCEPTION_RUNTIME);
};
#endif /* __JavaDOMGlobals_h__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
#! 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= \
base \
dns \
build \
protocol \
test \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,33 @@
#! 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,27 @@
#!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
DIRS= \
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,61 @@
#!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
XPIDL_MODULE = netwerk_base
XPIDLSRCS = \
nsIRequest.idl \
nsIChannel.idl \
nsIURI.idl \
nsIURL.idl \
nsIStreamObserver.idl \
nsIStreamListener.idl \
nsIIOService.idl \
nsIEventSinkGetter.idl \
nsIPrompt.idl \
nsIProtocolHandler.idl \
nsIProgressEventSink.idl \
nsINetModRegEntry.idl \
nsINetModuleMgr.idl \
nsINetNotify.idl \
$(NULL)
EXPORTS = \
netCore.h \
nsIFileTransportService.h \
nsISocketTransportService.h \
nsIHeader.h \
nsIProxy.h \
$(NULL)
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,58 @@
#!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 = ..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
EXPORTS = \
netCore.h \
nsIFileTransportService.h \
nsISocketTransportService.h \
nsIHeader.h \
nsIProxy.h \
$(NULL)
XPIDLSRCS = \
.\nsIRequest.idl \
.\nsIChannel.idl \
.\nsIURI.idl \
.\nsIURL.idl \
.\nsIStreamObserver.idl \
.\nsIStreamListener.idl \
.\nsIIOService.idl \
.\nsIEventSinkGetter.idl \
.\nsIPrompt.idl \
.\nsIProtocolHandler.idl \
.\nsIProgressEventSink.idl \
.\nsINetModRegEntry.idl \
.\nsINetModuleMgr.idl \
.\nsINetNotify.idl \
$(NULL)
include <$(DEPTH)/config/rules.mak>
$(DEPTH)\netwerk\dist\include:
-mkdir $(DEPTH)\netwerk\dist
-mkdir $(DEPTH)\netwerk\dist\include

View File

@@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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 __netCore_h__
#define __netCore_h__
#include "nsError.h"
/* networking error codes */
// NET RANGE: 1 -20
// FTP RANGE: 21-30
// HTTP RANGE: 31-40
// DNS RANGE: 41-50
#define NS_ERROR_ALREADY_CONNECTED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 1)
#define NS_ERROR_NOT_CONNECTED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
#define NS_ERROR_CONNECTION_REFUSED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 3)
#define NS_ERROR_DNS_DOES_NOT_EXIST \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 4)
#define NS_ERROR_TCP_TIMEOUT \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 5)
#define NS_ERROR_IN_PROGRESS \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 6)
#undef NS_NET
#ifdef _IMPL_NS_NET
#ifdef XP_PC
#define NS_NET _declspec(dllexport)
#else /* !XP_PC */
#define NS_NET
#endif /* !XP_PC */
#else /* !_IMPL_NS_NET */
#ifdef XP_PC
#define NS_NET _declspec(dllimport)
#else /* !XP_PC */
#define NS_NET
#endif /* !XP_PC */
#endif /* !_IMPL_NS_NET */
#endif // __netCore_h__

View File

@@ -0,0 +1,91 @@
/* -*- 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 "nsIRequest.idl"
interface nsIURI;
interface nsIInputStream;
interface nsIOutputStream;
interface nsIEventQueue;
interface nsIStreamObserver;
interface nsIStreamListener;
/**
* nsIChannel is the abstract base class for transports and URLs.
* It's abstract in that it doesn't provide a means to specify the
* location/destination of the data being accessed.
*/
[scriptable, uuid(89f4afe0-1868-11d3-9337-00104ba0fd40)]
interface nsIChannel : nsIRequest
{
/**
* Returns the URL to which the channel refers.
*/
readonly attribute nsIURI URI;
/**
* Opens a blocking input stream to the URL's specified source.
* @param startPosition - The offset from the start of the data
* from which to read.
* @param readCount - The number of bytes to read. If -1, everything
* up to the end of the data is read. If greater than the end of
* the data, the amount available is returned in the stream.
*/
nsIInputStream OpenInputStream(in unsigned long startPosition,
in long readCount);
/**
* Opens a blocking output stream to the URL's specified destination.
* @param startPosition - The offset from the start of the data
* from which to begin writing.
*/
nsIOutputStream OpenOutputStream(in unsigned long startPosition);
/**
* Reads asynchronously from the URL's specified source. Notifications
* are provided to the stream listener on the thread of the specified
* event queue.
* The startPosition argument designates the offset in the source where
* the data will be read.
* If the readCount == -1 then all the available data is delivered to
* the stream listener.
*/
void AsyncRead(in unsigned long startPosition,
in long readCount,
in nsISupports ctxt,
in nsIEventQueue eventQueue,
in nsIStreamListener listener);
/**
* Writes asynchronously to the URL's specified destination. Notifications
* are provided to the stream observer on the thread of the specified
* event queue.
* The startPosition argument designates the offset in the destination where
* the data will be written.
* If the writeCount == -1, then all the available data in the input
* stream is written.
*/
void AsyncWrite(in nsIInputStream fromStream,
in unsigned long startPosition,
in long writeCount,
in nsISupports ctxt,
in nsIEventQueue eventQueue,
in nsIStreamObserver observer);
};

View File

@@ -0,0 +1,26 @@
/* -*- 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 "nsISupports.idl"
[scriptable, uuid(fb65fd70-1881-11d3-9337-00104ba0fd40)]
interface nsIEventSinkGetter : nsISupports
{
nsISupports GetEventSink(in string verb, in nsIIDRef eventSinkIID);
};

View File

@@ -0,0 +1,55 @@
/* -*- 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 nsIFileTransportService_h___
#define nsIFileTransportService_h___
#include "nsISupports.h"
class nsIChannel;
#define NS_IFILETRANSPORTSERVICE_IID \
{ /* 2355dca0-ea35-11d2-931b-00104ba0fd40 */ \
0x2355dca0, \
0xea35, \
0x11d2, \
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
#define NS_FILETRANSPORTSERVICE_CID \
{ /* 2bb2b250-ea35-11d2-931b-00104ba0fd40 */ \
0x2bb2b250, \
0xea35, \
0x11d2, \
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
class nsIFileTransportService : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILETRANSPORTSERVICE_IID);
NS_IMETHOD CreateTransport(const char* path,
nsIChannel* *result) = 0;
NS_IMETHOD ProcessPendingRequests(void) = 0;
};
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIFileTransportService_h___ */

View File

@@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _nsIHeader_h_
#define _nsIHeader_h_
#include "nsISupports.h"
/*
nsIHeader. A class to encapsulate and share the header reading and
writing on requests/responses of several protocols.
I am not convinced the GetHeaderMultiple is the right way to
do multiple values, but give me a better way... TODO think.
- Gagan Saksena 03/08/99
*/
class nsIHeader : public nsISupports
{
public:
/*
SetHeader- set a particular header. The implementation is protocol
specific. For e.g. HTTP will put a colon and space to separate
the header with the value and then trail it will an newline.
So SetHeader for HTTP with say ("Accept", "text/html") will
result in a string "Accept: text/html\n" being added to the header
set.
*/
NS_IMETHOD SetHeader(const char* i_Header, const char* i_Value) = 0;
/*
Get the first occurence of the header and its corresponding value.
Note that if you expect the possibility of multiple values, you
should use GetHeaderMultiple() version.
*/
NS_IMETHOD GetHeader(const char* i_Header, char* *o_Value) = 0;
/*
This version returns an array of values associated with this
header. TODO think of a better way to do this...
*/
NS_IMETHOD GetHeaderMultiple(
const char* i_Header,
char** *o_ValueArray,
int *o_Count) = 0;
static const nsIID& GetIID() {
// {4CD2C720-D5CF-11d2-B013-006097BFC036}
static const nsIID NS_IHEADER_IID =
{ 0x4cd2c720, 0xd5cf, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
return NS_IHEADER_IID;
}
};
//TODO verify error offsets!
#define NS_ERROR_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 115);
#endif // _nsIHeader_h_

View File

@@ -0,0 +1,145 @@
/* -*- 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 "nsISupports.idl"
interface nsIProtocolHandler;
interface nsIURI;
interface nsIEventSinkGetter;
interface nsIChannel;
interface nsIStreamObserver;
interface nsIStreamListener;
interface nsIEventQueue;
interface nsIBufferInputStream;
interface nsIBufferOutputStream;
interface nsIFileChannel;
[scriptable, uuid(01f0a170-1881-11d3-9337-00104ba0fd40)]
interface nsIIOService : nsISupports
{
/**
* Returns a protocol handler for a given URI scheme.
*/
nsIProtocolHandler GetProtocolHandler(in string scheme);
/**
* Returns an absolute URI string from a relative specification and
* a base URI.
*/
string MakeAbsolute(in string aRelativeSpec, in nsIURI aBaseURI);
/**
* This method constructs a new URI by first determining the scheme
* of the URI spec, and then delegating the construction of the URI
* to the protocol handler for that scheme. QueryInterface can be used
* on the resulting URI object to obtain a more specific type of URI.
*/
nsIURI NewURI(in string aSpec, in nsIURI aBaseURI);
/**
* Creates a channel for a given URI. The eventSinkGetter is used to
* obtain the appropriate callbacks for the URI's protocol from the
* application.
*/
nsIChannel NewChannelFromURI(in string verb,
in nsIURI aURI,
in nsIEventSinkGetter eventSinkGetter);
/**
* Convenience routine that first creates a URI by calling NewURI, and
* then passes the URI to NewChannelFromURI.
*/
nsIChannel NewChannel(in string verb,
in string aSpec,
in nsIURI aBaseURI,
in nsIEventSinkGetter eventSinkGetter);
/**
* Get the application name string that will be used as part
* of a HTTP request.
*/
readonly attribute wstring AppCodeName;
/**
* Get the application version string that will be used as part
* of a HTTP request.
*/
readonly attribute wstring AppVersion;
/**
* Get the application name.
*/
readonly attribute wstring AppName;
/**
* Get the translation of the application. The value for language
* is usually a 2-letter code such as "en" and occasionally a
* five-character code to indicate a language subtype, such as "zh_CN".
*/
readonly attribute wstring Language;
/**
* Get the current platform (machine type).
*/
readonly attribute wstring Platform;
/**
* Get the HTTP advertised user agent string.
*/
readonly attribute wstring UserAgent;
/**
* Returns a new stream observer that marshals data from another
* stream observer over to the thread specified by an event queue.
*/
nsIStreamObserver NewAsyncStreamObserver(in nsIStreamObserver receiver,
in nsIEventQueue eventQueue);
/**
* An asynchronous stream listener is used to ship data over to another thread specified
* by the thread's event queue. The receiver stream listener is then used to receive
* the data on the other thread.
*/
nsIStreamListener NewAsyncStreamListener(in nsIStreamListener receiver,
in nsIEventQueue eventQueue);
/**
* A synchronous stream listener pushes data through a pipe that ends up
* in an input stream to be read by another thread.
*/
nsIStreamListener NewSyncStreamListener(out nsIBufferInputStream inStream,
out nsIBufferOutputStream outStream);
/**
* This convenience routine first looks up the file protocol handler, and
* then uses it to construct a file channel from a native path string.
*/
nsIFileChannel NewChannelFromNativePath(in string nativePath);
};
%{C++
#define NS_IOSERVICE_CID \
{ /* 9ac9e770-18bc-11d3-9337-00104ba0fd40 */ \
0x9ac9e770, \
0x18bc, \
0x11d3, \
{0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
%}

View File

@@ -0,0 +1,42 @@
/* -*- Mode: IDL; 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.
*/
/* This interface defines a registry entry for the networking libraries
* external module registry. */
#include "nsISupports.idl"
#include "nsINetNotify.idl"
interface nsIEventQueue;
interface nsINetModRegEntry;
%{ C++
// {F126BD90-1472-11d3-A15A-0050041CAF44}
#define NS_NETMODREGENTRY_CID \
{ 0xf126bd90, 0x1472, 0x11d3, { 0xa1, 0x5a, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
%}
[scriptable, uuid(9F482BD0-1476-11d3-A15A-0050041CAF44)]
interface nsINetModRegEntry : nsISupports {
readonly attribute nsINetNotify mNotify;
readonly attribute nsIEventQueue mEventQ;
readonly attribute string mTopic;
readonly attribute nsCIDPtr mCID;
boolean Equals(in nsINetModRegEntry aEntry);
};

View File

@@ -0,0 +1,73 @@
/* -*- Mode: IDL; 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.
*/
/* The nsINetModuleMgr singleton service allows external module to register
* themselves with the networking library to receive events they want to
* receive.
*
* An external module that is interested in being notified when a particular
* networking level event occurs would register with this service, and
* implement the appropriate interface(s) that correspond to the events they
* want to receive. These interfaces are defined by networking internal
* components (for example, http would define a notification interface that
* the external cookies module would implement).
*/
#include "nsISupports.idl"
#include "nsIEnumerator.idl"
#include "nsINetNotify.idl"
interface nsIEventQueue;
%{ C++
// {4EBDAFE0-13BA-11d3-A15A-0050041CAF44}
#define NS_NETMODULEMGR_CID \
{ 0x4ebdafe0, 0x13ba, 0x11d3, { 0xa1, 0x5a, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
%}
[scriptable, uuid(ff9ead40-0ef2-11d3-9de6-0010a4053fd0)]
interface nsINetModuleMgr : nsISupports {
// Register the external module to receive notifications.
//
// ARGUMENTS:
// aTopic: The internal component that the external module wants to monitor.
// aEventQueue: The event queue to receive the events.
// aNotify: The external module interface methods to be called when an event is fired.
//
// RETURNS: nsresult
void RegisterModule(in string aTopic, in nsIEventQueue aEventQueue, in nsINetNotify aNotify, in nsCIDPtr aCID);
// Unregister the external module. Removes the nsINetModuleMgr binding between
// internal component and external module.
//
// ARGUMENTS:
// aTopic: The internal component being monitored.
// aNotify: The external modules notification module.
//
// RETURNS: nsresult
void UnregisterModule(in string aTopic, in nsIEventQueue aEventQueue, in nsINetNotify aNotify, in nsCIDPtr aCID);
// Enumerates all the registered modules for the specified topic.
//
// ARGUMENTS:
// aTopic: the component to get all the notifiers for.
// aEnumerator: the array of notifiers.
void EnumerateModules(in string aTopic, out nsISimpleEnumerator aEnumerator);
};

View File

@@ -0,0 +1,24 @@
/* -*- Mode: IDL; 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 "nsISupports.idl"
[uuid(4A3019E0-1CF3-11d3-A15B-0050041CAF44)]
interface nsINetNotify : nsISupports {
};

View File

@@ -0,0 +1,43 @@
/* -*- 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 "nsISupports.idl"
interface nsIURI;
/**
* An instance of nsIFfpEventSink should be passed as the eventSink
* argument of nsINetService::NewConnection for ftp URLs. It defines
* the callbacks to the application program (the html parser).
*/
[scriptable, uuid(dd47ee00-18c2-11d3-9337-00104ba0fd40)]
interface nsIProgressEventSink : nsISupports
{
/**
* Notify the EventSink that progress as occurred for the URL load.<BR>
*/
void OnProgress(in nsISupports ctxt,
in unsigned long aProgress,
in unsigned long aProgressMax);
/**
* Notify the EventSink with a status message for the URL load.<BR>
*/
void OnStatus(in nsISupports ctxt, in wstring aMsg);
};

View File

@@ -0,0 +1,34 @@
/* -*- 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 "nsISupports.idl"
[scriptable, uuid(a63f70c0-148b-11d3-9333-00104ba0fd40)]
interface nsIPrompt : nsISupports
{
boolean Confirm(in nsISupports ctxt, in wstring text);
boolean Prompt(in nsISupports ctxt, in wstring text,
in wstring defaultText, out wstring result);
boolean PromptUsernameAndPassword(in nsISupports ctxt, in wstring text,
out wstring user, out wstring pwd);
boolean PromptPassword(in nsISupports ctxt, in wstring text,
out wstring pwd);
};

View File

@@ -0,0 +1,55 @@
/* -*- 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 "nsISupports.idl"
interface nsIURI;
interface nsIEventSinkGetter;
interface nsIChannel;
interface nsIEventQueue;
[scriptable, uuid(8984a6f0-1893-11d3-9337-00104ba0fd40)]
interface nsIProtocolHandler : nsISupports
{
readonly attribute string Scheme;
readonly attribute long DefaultPort;
string MakeAbsolute(in string aRelativeSpec, in nsIURI aBaseURI);
/**
* Makes a URI object that is suitable for loading by this protocol.
* In the usual case (when only the accessors provided by nsIURI are
* needed), this method just constructs a standard URI using the
* component manager with kStandardURLCID.
*/
nsIURI NewURI(in string aSpec, in nsIURI aBaseURI);
nsIChannel NewChannel(in string verb,
in nsIURI aURI,
in nsIEventSinkGetter eventSinkGetter,
in nsIEventQueue eventQueue);
};
%{C++
#define NS_NETWORK_PROTOCOL_PROGID "component://netscape/network/protocol"
#define NS_NETWORK_PROTOCOL_PROGID_PREFIX NS_NETWORK_PROTOCOL_PROGID "?name="
#define NS_NETWORK_PROTOCOL_PROGID_PREFIX_LENGTH 43 // nsCRT::strlen(NS_NETWORK_PROTOCOL_PROGID_PREFIX)
%}

View File

@@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 _nsIProxy_h_
#define _nsIProxy_h_
#include "nsISupports.h"
/*
The nsIProxy interface allows setting and getting of proxy host and port.
This is for use by protocol handlers. If you are writing a protocol handler
and would like to support proxy behaviour then derive from this as well as
the nsIProtocolHandler class.
-Gagan Saksena 02/25/99
*/
class nsIProxy : public nsISupports
{
public:
/*
Get and Set the Proxy Host
*/
NS_IMETHOD GetProxyHost(const char* *o_ProxyHost) const = 0;
NS_IMETHOD SetProxyHost(const char* i_ProxyHost) = 0;
/*
Get and Set the Proxy Port
-1 on Set call indicates switch to default port
*/
NS_IMETHOD_(PRInt32)
GetProxyPort(void) const = 0;
NS_IMETHOD SetProxyPort(PRInt32 i_ProxyPort) = 0;
static const nsIID& GetIID() {
// {0492D011-CD2F-11d2-B013-006097BFC036}
static const nsIID NS_IPROXY_IID=
{ 0x492d011, 0xcd2f, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
return NS_IPROXY_IID;
};
};
#endif /* _nsIProxy_h_ */

View File

@@ -0,0 +1,43 @@
/* -*- 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 "nsISupports.idl"
interface nsIRequest : nsISupports
{
/**
* Cancels the current request. This will close any open input or
* output streams and terminate any async requests.
*/
void Cancel();
/**
* Suspends the current requests. This may have the effect of closing
* any underlying transport (in order to free up resources), although
* any open streams remain logically opened and will continue delivering
* data when the transport is resumed.
*/
void Suspend();
/**
* Resumes the current request. This may have the effect of re-opening
* any underlying transport and will resume the delivery of data to
* any open streams.
*/
void Resume();
};

View File

@@ -0,0 +1,56 @@
/* -*- 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 nsISocketTransportService_h___
#define nsISocketTransportService_h___
#include "nsISupports.h"
class nsIChannel;
#define NS_ISOCKETTRANSPORTSERVICE_IID \
{ /* 9610f120-ef12-11d2-92b6-00105a1b0d64 */ \
0x9610f120, \
0xef12, \
0x11d2, \
{0x92, 0xb6, 0x00, 0x10, 0x5a, 0x1b, 0x0d, 0x64} \
}
#define NS_SOCKETTRANSPORTSERVICE_CID \
{ /* c07e81e0-ef12-11d2-92b6-00105a1b0d64 */ \
0xc07e81e0, \
0xef12, \
0x11d2, \
{0x92, 0xb6, 0x00, 0x10, 0x5a, 0x1b, 0x0d, 0x64} \
}
class nsISocketTransportService : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOCKETTRANSPORTSERVICE_IID);
NS_IMETHOD CreateTransport(const char* host, PRInt32 port,
nsIChannel* *result) = 0;
NS_IMETHOD Shutdown(void) = 0;
};
////////////////////////////////////////////////////////////////////////////////
#endif /* nsISocketTransportService_h___ */

View File

@@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsIStreamObserver.idl"
interface nsIBufferInputStream;
interface nsIBufferOutputStream;
interface nsIEventQueue;
[scriptable, uuid(1a637020-1482-11d3-9333-00104ba0fd40)]
interface nsIStreamListener : nsIStreamObserver
{
void OnDataAvailable(in nsISupports ctxt,
in nsIBufferInputStream inStr,
in unsigned long sourceOffset,
in unsigned long count);
};
%{C++
// An asynchronous stream listener is used to ship data over to another thread specified
// by the thread's event queue. The receiver stream listener is then used to receive
// the data on the other thread.
extern NS_NET nsresult
NS_NewAsyncStreamListener(nsIStreamListener* *result,
nsIEventQueue* eventQueue,
nsIStreamListener* receiver);
// A synchronous stream listener pushes data through a pipe that ends up
// in an input stream to be read by another thread.
extern NS_NET nsresult
NS_NewSyncStreamListener(nsIBufferInputStream **inStream,
nsIBufferOutputStream **outStream,
nsIStreamListener **listener);
%}

View File

@@ -0,0 +1,59 @@
/* -*- 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 "nsISupports.idl"
interface nsIEventQueue;
[scriptable, uuid(fd91e2e0-1481-11d3-9333-00104ba0fd40)]
interface nsIStreamObserver : nsISupports
{
void OnStartBinding(in nsISupports ctxt);
void OnStopBinding(in nsISupports ctxt,
in nsresult status,
in wstring errorMsg);
/**
* Called after the stream is opened for reading or writing.
* The content type or headers may be accessed after this method
* is called.
*/
void OnStartRequest(in nsISupports ctxt);
void OnStopRequest(in nsISupports ctxt,
in nsresult status,
in wstring errorMsg);
};
%{C++
// An asynchronous stream observer is used to ship data over to another thread specified
// by the thread's event queue. The receiver stream observer is then used to receive
// the notifications on the other thread.
extern NS_NET nsresult
NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
nsIEventQueue* eventQueue,
nsIStreamObserver* receiver);
// Generic status codes for OnStopBinding:
#define NS_BINDING_SUCCEEDED NS_OK
#define NS_BINDING_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 1)
#define NS_BINDING_ABORTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
%}

View File

@@ -0,0 +1,122 @@
/* -*- 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 "nsISupports.idl"
/**
* URIs are essentially structured names for things -- anything.
* This interface provides accessors to destructure those names.
*
* This interface follows Tim Berners-Lee's URI spec:
*
* http://www.w3.org/Addressing/URI/URI_Overview.html
*
* essentially:
*
* ftp://username:password@hostname:portnumber/pathname
* \ / \ / \ / \ /\ /
* - --------------- ------ -------- -------
* | | | | |
* | | | | Path
* | | | Port
* | | Host
* | PreHost
* Scheme
*
* The subclass nsIURL provides a means to open an input or output
* stream to a URI as a source/destination, as well as providing additional
* accessors to destructure the path, query and reference portions typically
* associated with URLs.
*/
[scriptable, uuid(07a22cc0-0ce5-11d3-9331-00104ba0fd40)]
interface nsIURI : nsISupports
{
/**
* Returns a string representation of the URI. Setting the spec
* causes the new spec to be parsed, initializing the URI. Setting
* the spec (or any of the accessors) causes also any currently
* open streams on the URI's channel to be closed.
*/
attribute string Spec;
/**
* The Scheme is the protocol to which this URI refers. Setting
* the scheme is a special operation that builds up an equivalent
* URI string from the new scheme and all the other URI attributes
* and passes the it to the nsIOService to create a new URI for
* the new scheme.
*/
attribute string Scheme;
/**
* The PreHost portion includes elements like the optional
* username:password, or maybe other scheme specific items.
*/
attribute string PreHost;
/**
* The Host is the internet domain name to which this URI refers.
* Note that it could be an IP address as well.
*/
attribute string Host;
/**
* A return value of -1 indicates that no port value is set and the
* implementor of the specific scheme will use its default port.
* Similarly setting a value of -1 indicates that the default is to be used.
* Thus as an example:
* for HTTP, Port 80 is same as a return value of -1.
* However after setting a port (even if its default), the port number will
* appear in the ToNewCString function.
*/
attribute long Port;
/**
* Note that the path includes the leading '/' Thus if no path is
* available the Path accessor will return a "/"
* For SetPath if none is provided, one would be prefixed to the path.
*/
attribute string Path;
/**
* Note that this comparison is only on char* level. Use
* the scheme specific URI to do a more thorough check. For example,
* in HTTP:
* http://foo.com:80 == http://foo.com
* but this function through nsIURI alone will not return equality
* for this case.
*/
boolean Equals(in nsIURI other);
/**
* Clones the current URI. The newly created URI will be in a closed
* state even if the underlying channel of the cloned URI is open.
* Cloning allows the current location to be retained since once the
* channel is opened the URI may get redirected to a new location.
*/
nsIURI Clone();
/**
* Returns a new URI string that merges the relative part with defaults
* from the current URI's location. If the relative part actually
* specifies an absolute URI, the string is returned as is.
*/
string MakeAbsolute(in string relativePart);
};

View File

@@ -0,0 +1,83 @@
/* -*- 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 "nsIURI.idl"
interface nsIChannel;
interface nsIEventSinkGetter;
[scriptable, uuid(78406350-0ce5-11d3-9331-00104ba0fd40)]
interface nsIURL : nsIURI
{
// The following 4 attributes breakdown the Path attribute
// into its constituents...
/**
* Returns the directory portion of a URL.
* If the URL denotes a path to a directory and not a file,
* e.g. http://foo/bar/, then the Directory attribute accesses
* the complete /foo/bar/ portion, and the FileName is the
* empty string. If the trailing slash is omitted, then the
* Directory is /foo/ and the file is bar (i.e. this is a
* syntactic, not a semantic breakdown of the Path).
*/
attribute string Directory;
/**
* Returns the file name portion of a URL.
* If the URL denotes a path to a directory and not a file,
* e.g. http://foo/bar/, then the Directory attribute accesses
* the complete /foo/bar/ portion, and the FileName is the
* empty string.
*/
attribute string FileName;
/**
* Returns the query portion (the part after the "?") of the URL.
* If there isn't one, the empty string is returned.
*/
attribute string Query;
/**
* Returns the reference portion (the part after the "#") of the URL.
* If there isn't one, the empty string is returned.
*/
attribute string Ref;
};
%{C++
/**
* Protocol writers can obtain a default nsIURL implementation by calling the
* component manager with NS_STANDARDURL_CID. The implementation returned will
* only implement the set of accessors specified by nsIURL. After obtaining the
* instance from the component manager, the Init routine must be called on it
* to initialize it from the user's URL spec.
*/
#define NS_STANDARDURL_CID \
{ /* 46fc2a26-ff66-11d2-8ccb-0060b0fc14a3 */ \
0x46fc2a26, \
0xff66, \
0x11d2, \
{0x8c, 0xcb, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
}
%}

View File

@@ -0,0 +1,54 @@
# 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
LIBRARY_NAME = netwerkbase_s
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsAsyncStreamListener.cpp \
nsSyncStreamListener.cpp \
nsIOService.cpp \
nsSocketTransport.cpp \
nsSocketTransportStreams.cpp \
nsSocketTransportService.cpp \
nsStandardUrl.cpp \
nsNetModuleMgr.cpp \
nsNetModRegEntry.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk
MKSHLIB :=
# we don't want the shared lib, but we want to force the creation of a
# static l\ib.
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,52 @@
# 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 = ..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
LIBRARY_NAME=netwerkbase_s
CPP_OBJS = \
.\$(OBJDIR)\nsAsyncStreamListener.obj \
.\$(OBJDIR)\nsSyncStreamListener.obj \
.\$(OBJDIR)\nsIOService.obj \
.\$(OBJDIR)\nsSocketTransport.obj \
.\$(OBJDIR)\nsSocketTransportStreams.obj \
.\$(OBJDIR)\nsSocketTransportService.obj \
.\$(OBJDIR)\nsStandardUrl.obj \
.\$(OBJDIR)\nsNetModuleMgr.obj \
.\$(OBJDIR)\nsNetModRegEntry.obj \
$(NULL)
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,540 @@
/* -*- 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 "nsIStreamObserver.h"
#include "nsIStreamListener.h"
#include "nsIBufferInputStream.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsIEventQueue.h"
class nsAsyncStreamObserver : public nsIStreamObserver
{
public:
NS_DECL_ISUPPORTS
// nsIStreamObserver methods:
NS_IMETHOD OnStartBinding(nsISupports* context);
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg);
NS_IMETHOD OnStartRequest(nsISupports* context);
NS_IMETHOD OnStopRequest(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg);
// nsAsyncStreamObserver methods:
nsAsyncStreamObserver(nsIEventQueue* aEventQ)
: mReceiver(nsnull), mStatus(NS_OK)
{
NS_INIT_REFCNT();
mEventQueue = aEventQ;
NS_IF_ADDREF(mEventQueue);
}
virtual ~nsAsyncStreamObserver();
void Init(nsIStreamObserver* aListener) {
mReceiver = aListener;
NS_ADDREF(mReceiver);
}
nsISupports* GetReceiver() { return mReceiver; }
nsresult GetStatus() { return mStatus; }
void SetStatus(nsresult value) { mStatus = value; }
protected:
nsIEventQueue* mEventQueue;
nsIStreamObserver* mReceiver;
nsresult mStatus;
};
class nsAsyncStreamListener : public nsAsyncStreamObserver,
public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIStreamListener methods:
NS_IMETHOD OnStartBinding(nsISupports* context)
{
return nsAsyncStreamObserver::OnStartBinding(context);
}
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
return nsAsyncStreamObserver::OnStopBinding(context, aStatus, aMsg);
}
NS_IMETHOD OnStartRequest(nsISupports* context)
{
return nsAsyncStreamObserver::OnStartRequest(context);
}
NS_IMETHOD OnStopRequest(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
return nsAsyncStreamObserver::OnStopRequest(context, aStatus, aMsg);
}
NS_IMETHOD OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength);
// nsAsyncStreamListener methods:
nsAsyncStreamListener(nsIEventQueue* aEventQ)
: nsAsyncStreamObserver(aEventQ) {}
void Init(nsIStreamListener* aListener) {
mReceiver = aListener;
NS_ADDREF(mReceiver);
}
};
////////////////////////////////////////////////////////////////////////////////
class nsStreamListenerEvent : public PLEvent
{
public:
nsStreamListenerEvent(nsAsyncStreamObserver* listener,
nsISupports* context);
virtual ~nsStreamListenerEvent();
nsresult Fire(nsIEventQueue* aEventQ);
NS_IMETHOD HandleEvent() = 0;
protected:
static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent);
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);
nsAsyncStreamObserver* mListener;
nsISupports* mContext;
};
////////////////////////////////////////////////////////////////////////////////
nsStreamListenerEvent::nsStreamListenerEvent(nsAsyncStreamObserver* listener,
nsISupports* context)
: mListener(listener), mContext(context)
{
NS_ADDREF(mListener);
NS_IF_ADDREF(mContext);
}
nsStreamListenerEvent::~nsStreamListenerEvent()
{
NS_RELEASE(mListener);
NS_IF_RELEASE(mContext);
}
void PR_CALLBACK nsStreamListenerEvent::HandlePLEvent(PLEvent* aEvent)
{
// WARNING: This is a dangerous cast since it must adjust the pointer
// to compensate for the vtable...
nsStreamListenerEvent *ev = (nsStreamListenerEvent*)aEvent;
nsresult rv = ev->HandleEvent();
ev->mListener->SetStatus(rv);
}
void PR_CALLBACK nsStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
{
// WARNING: This is a dangerous cast since it must adjust the pointer
// to compensate for the vtable...
nsStreamListenerEvent *ev = (nsStreamListenerEvent*)aEvent;
delete ev;
}
nsresult
nsStreamListenerEvent::Fire(nsIEventQueue* aEventQueue)
{
NS_PRECONDITION(nsnull != aEventQueue, "nsIEventQueue for thread is null");
PL_InitEvent(this, nsnull,
(PLHandleEventProc) nsStreamListenerEvent::HandlePLEvent,
(PLDestroyEventProc) nsStreamListenerEvent::DestroyPLEvent);
PRStatus status = aEventQueue->PostEvent(this);
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
////////////////////////////////////////////////////////////////////////////////
nsAsyncStreamObserver::~nsAsyncStreamObserver()
{
NS_RELEASE(mReceiver);
NS_IF_RELEASE(mEventQueue);
}
NS_IMPL_ISUPPORTS(nsAsyncStreamObserver, nsIStreamObserver::GetIID());
NS_IMPL_ISUPPORTS_INHERITED(nsAsyncStreamListener,
nsAsyncStreamObserver,
nsIStreamListener);
////////////////////////////////////////////////////////////////////////////////
//
// OnStartBinding...
//
////////////////////////////////////////////////////////////////////////////////
class nsOnStartBindingEvent : public nsStreamListenerEvent
{
public:
nsOnStartBindingEvent(nsAsyncStreamObserver* listener,
nsISupports* context)
: nsStreamListenerEvent(listener, context), mContentType(nsnull) {}
virtual ~nsOnStartBindingEvent();
NS_IMETHOD HandleEvent();
protected:
char* mContentType;
};
nsOnStartBindingEvent::~nsOnStartBindingEvent()
{
if (mContentType)
delete[] mContentType;
}
NS_IMETHODIMP
nsOnStartBindingEvent::HandleEvent()
{
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
return receiver->OnStartBinding(mContext);
}
NS_IMETHODIMP
nsAsyncStreamObserver::OnStartBinding(nsISupports* context)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStartBindingEvent* event =
new nsOnStartBindingEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
////////////////////////////////////////////////////////////////////////////////
//
// OnStopBinding
//
////////////////////////////////////////////////////////////////////////////////
class nsOnStopBindingEvent : public nsStreamListenerEvent
{
public:
nsOnStopBindingEvent(nsAsyncStreamObserver* listener,
nsISupports* context)
: nsStreamListenerEvent(listener, context),
mStatus(NS_OK), mMessage(nsnull) {}
virtual ~nsOnStopBindingEvent();
nsresult Init(nsresult status, const PRUnichar* aMsg);
NS_IMETHOD HandleEvent();
protected:
nsresult mStatus;
PRUnichar* mMessage;
};
nsOnStopBindingEvent::~nsOnStopBindingEvent()
{
}
nsresult
nsOnStopBindingEvent::Init(nsresult status, const PRUnichar* aMsg)
{
mStatus = status;
mMessage = (PRUnichar*)aMsg;
return NS_OK;
}
NS_IMETHODIMP
nsOnStopBindingEvent::HandleEvent()
{
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
return receiver->OnStopBinding(mContext, mStatus, mMessage);
}
NS_IMETHODIMP
nsAsyncStreamObserver::OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStopBindingEvent* event =
new nsOnStopBindingEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aStatus, aMsg);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
////////////////////////////////////////////////////////////////////////////////
//
// OnStartRequest...
//
////////////////////////////////////////////////////////////////////////////////
class nsOnStartRequestEvent : public nsStreamListenerEvent
{
public:
nsOnStartRequestEvent(nsAsyncStreamObserver* listener,
nsISupports* context)
: nsStreamListenerEvent(listener, context), mContentType(nsnull) {}
virtual ~nsOnStartRequestEvent();
NS_IMETHOD HandleEvent();
protected:
char* mContentType;
};
nsOnStartRequestEvent::~nsOnStartRequestEvent()
{
if (mContentType)
delete[] mContentType;
}
NS_IMETHODIMP
nsOnStartRequestEvent::HandleEvent()
{
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
return receiver->OnStartRequest(mContext);
}
NS_IMETHODIMP
nsAsyncStreamObserver::OnStartRequest(nsISupports* context)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStartRequestEvent* event =
new nsOnStartRequestEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
////////////////////////////////////////////////////////////////////////////////
//
// OnStopRequest
//
////////////////////////////////////////////////////////////////////////////////
class nsOnStopRequestEvent : public nsStreamListenerEvent
{
public:
nsOnStopRequestEvent(nsAsyncStreamObserver* listener,
nsISupports* context)
: nsStreamListenerEvent(listener, context),
mStatus(NS_OK), mMessage(nsnull) {}
virtual ~nsOnStopRequestEvent();
nsresult Init(nsresult status, const PRUnichar* aMsg);
NS_IMETHOD HandleEvent();
protected:
nsresult mStatus;
PRUnichar* mMessage;
};
nsOnStopRequestEvent::~nsOnStopRequestEvent()
{
}
nsresult
nsOnStopRequestEvent::Init(nsresult status, const PRUnichar* aMsg)
{
mStatus = status;
mMessage = (PRUnichar*)aMsg;
return NS_OK;
}
NS_IMETHODIMP
nsOnStopRequestEvent::HandleEvent()
{
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
return receiver->OnStopRequest(mContext, mStatus, mMessage);
}
NS_IMETHODIMP
nsAsyncStreamObserver::OnStopRequest(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStopRequestEvent* event =
new nsOnStopRequestEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aStatus, aMsg);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
////////////////////////////////////////////////////////////////////////////////
//
// OnDataAvailable
//
////////////////////////////////////////////////////////////////////////////////
class nsOnDataAvailableEvent : public nsStreamListenerEvent
{
public:
nsOnDataAvailableEvent(nsAsyncStreamObserver* listener,
nsISupports* context)
: nsStreamListenerEvent(listener, context),
mIStream(nsnull), mLength(0) {}
virtual ~nsOnDataAvailableEvent();
nsresult Init(nsIBufferInputStream* aIStream, PRUint32 aSourceOffset,
PRUint32 aLength);
NS_IMETHOD HandleEvent();
protected:
nsIBufferInputStream* mIStream;
PRUint32 mSourceOffset;
PRUint32 mLength;
};
nsOnDataAvailableEvent::~nsOnDataAvailableEvent()
{
NS_RELEASE(mIStream);
}
nsresult
nsOnDataAvailableEvent::Init(nsIBufferInputStream* aIStream, PRUint32 aSourceOffset,
PRUint32 aLength)
{
mSourceOffset = aSourceOffset;
mLength = aLength;
mIStream = aIStream;
NS_ADDREF(mIStream);
return NS_OK;
}
NS_IMETHODIMP
nsOnDataAvailableEvent::HandleEvent()
{
nsIStreamListener* receiver = (nsIStreamListener*)mListener->GetReceiver();
return receiver->OnDataAvailable(mContext, mIStream, mSourceOffset, mLength);
}
NS_IMETHODIMP
nsAsyncStreamListener::OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnDataAvailableEvent* event =
new nsOnDataAvailableEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aIStream, aSourceOffset, aLength);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
////////////////////////////////////////////////////////////////////////////////
NS_NET nsresult
NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
nsIEventQueue* eventQueue,
nsIStreamObserver* receiver)
{
nsAsyncStreamObserver* l =
new nsAsyncStreamObserver(eventQueue);
if (l == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
l->Init(receiver);
NS_ADDREF(l);
*result = l;
return NS_OK;
}
NS_NET nsresult
NS_NewAsyncStreamListener(nsIStreamListener* *result,
nsIEventQueue* eventQueue,
nsIStreamListener* receiver)
{
nsAsyncStreamListener* l =
new nsAsyncStreamListener(eventQueue);
if (l == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
l->Init(receiver);
NS_ADDREF(l);
*result = l;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,368 @@
/* -*- 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 "nsFileTransport.h"
#include "nsFileTransportService.h"
#include "nsIStreamListener.h"
#include "nsCRT.h"
#include "nscore.h"
#include "nsIFileStream.h"
#include "nsFileSpec.h"
#include "nsIBuffer.h"
#include "nsIBufferInputStream.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
// nsFileTransport methods:
nsFileTransport::nsFileTransport()
: mPath(nsnull), mContext(nsnull), mListener(nsnull), mState(ENDED),
mSuspended(PR_FALSE), mFileStream(nsnull), mBuffer(nsnull),
mBufferStream(nsnull), mStatus(NS_OK), mService(nsnull), mSourceOffset(0)
{
NS_INIT_REFCNT();
mMonitor = PR_NewMonitor();
}
nsFileTransport::~nsFileTransport()
{
if (mPath) nsCRT::free(mPath);
PR_DestroyMonitor(mMonitor);
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mContext);
NS_IF_RELEASE(mService);
NS_IF_RELEASE(mFileStream);
NS_IF_RELEASE(mBuffer);
NS_IF_RELEASE(mBufferStream);
}
nsresult
nsFileTransport::Init(const char* path,
nsFileTransportService* service)
{
mPath = nsCRT::strdup(path);
if (mPath == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
mService = service;
NS_ADDREF(mService);
return NS_OK;
}
nsresult
nsFileTransport::Init(nsISupports* context,
nsIStreamListener* listener,
State state, PRUint32 startPosition, PRInt32 count)
{
nsresult rv = NS_OK;
if (!mMonitor)
return NS_ERROR_OUT_OF_MEMORY;
PR_EnterMonitor(mMonitor);
if (mState != ENDED)
rv = NS_ERROR_FAILURE;
else {
mContext = context;
NS_IF_ADDREF(mContext);
mListener = listener;
NS_ADDREF(mListener);
mState = state;
mSourceOffset = startPosition;
mAmount = count;
}
PR_ExitMonitor(mMonitor);
return rv;
}
NS_IMPL_ADDREF(nsFileTransport);
NS_IMPL_RELEASE(nsFileTransport);
NS_IMETHODIMP
nsFileTransport::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsIChannel::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = NS_STATIC_CAST(nsIChannel*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIRunnable::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIRunnable*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP
nsFileTransport::Cancel(void)
{
nsresult rv = NS_OK;
if (!mMonitor)
return NS_ERROR_OUT_OF_MEMORY;
PR_EnterMonitor(mMonitor);
mStatus = NS_BINDING_ABORTED;
if (mSuspended) {
Resume();
}
mState = ENDING;
PR_ExitMonitor(mMonitor);
return rv;
}
NS_IMETHODIMP
nsFileTransport::Suspend(void)
{
nsresult rv = NS_OK;
if (!mMonitor)
return NS_ERROR_OUT_OF_MEMORY;
PR_EnterMonitor(mMonitor);
if (!mSuspended) {
// XXX close the stream here?
mStatus = mService->Suspend(this);
mSuspended = PR_TRUE;
}
PR_ExitMonitor(mMonitor);
return rv;
}
NS_IMETHODIMP
nsFileTransport::Resume(void)
{
nsresult rv = NS_OK;
if (!mMonitor)
return NS_ERROR_OUT_OF_MEMORY;
PR_EnterMonitor(mMonitor);
if (!mSuspended) {
// XXX re-open the stream and seek here?
mStatus = mService->Resume(this);
mSuspended = PR_FALSE;
}
PR_ExitMonitor(mMonitor);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:
NS_IMETHODIMP
nsFileTransport::GetURI(nsIURI* *aURL)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileTransport::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener)
{
nsresult rv;
nsIStreamListener* asyncListener;
rv = NS_NewAsyncStreamListener(&asyncListener, eventQueue, listener);
if (NS_FAILED(rv)) return rv;
rv = Init(ctxt, asyncListener, START_READ, startPosition, readCount);
NS_RELEASE(asyncListener);
rv = mService->DispatchRequest(this);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsFileTransport::AsyncWrite(nsIInputStream* fromStream,
PRUint32 startPosition,
PRInt32 writeCount,
nsISupports* context,
nsIEventQueue* appEventQueue,
nsIStreamObserver* observer)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileTransport::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
nsIInputStream* *result)
{
nsresult rv;
NS_ASSERTION(startPosition == 0, "fix me");
nsIStreamListener* syncListener;
nsIBufferInputStream* inStr;
rv = NS_NewSyncStreamListener(&syncListener, &inStr);
if (NS_FAILED(rv)) return rv;
rv = Init(nsnull, syncListener, START_READ, 0, -1);
NS_RELEASE(syncListener);
if (NS_FAILED(rv)) {
NS_RELEASE(inStr);
return rv;
}
rv = mService->DispatchRequest(this);
if (NS_FAILED(rv)) {
NS_RELEASE(inStr);
return rv;
}
*result = inStr;
return NS_OK;
}
NS_IMETHODIMP
nsFileTransport::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
void
nsFileTransport::Process(void)
{
if (!mMonitor) {
mState = ENDING;
return;
}
PR_EnterMonitor(mMonitor);
switch (mState) {
case START_READ: {
nsISupports* fs;
nsFileSpec spec(mPath);
mStatus = mListener->OnStartBinding(mContext); // always send the start notification
if (NS_FAILED(mStatus)) goto error;
mStatus = NS_NewTypicalInputFileStream(&fs, spec);
if (NS_FAILED(mStatus)) goto error;
mStatus = fs->QueryInterface(nsIInputStream::GetIID(), (void**)&mFileStream);
NS_RELEASE(fs);
if (NS_FAILED(mStatus)) goto error;
mStatus = NS_NewBuffer(&mBuffer, NS_FILE_TRANSPORT_BUFFER_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(mStatus)) goto error;
mStatus = NS_NewBufferInputStream(&mBufferStream, mBuffer, PR_FALSE);
if (NS_FAILED(mStatus)) goto error;
mState = READING;
break;
}
case READING: {
if (NS_FAILED(mStatus)) goto error;
PRUint32 amt;
nsIInputStream* inStr = NS_STATIC_CAST(nsIInputStream*, mFileStream);
PRUint32 inLen;
mStatus = inStr->GetLength(&inLen);
if (NS_FAILED(mStatus)) goto error;
mStatus = mBuffer->WriteFrom(inStr, inLen, &amt);
if (mStatus == NS_BASE_STREAM_EOF) goto error;
if (NS_FAILED(mStatus)) goto error;
// and feed the buffer to the application via the byte buffer stream:
// XXX maybe amt should be mBufferStream->GetLength():
mStatus = mListener->OnDataAvailable(mContext, mBufferStream, mSourceOffset, amt);
if (NS_FAILED(mStatus)) goto error;
mSourceOffset += amt;
// stay in the READING state
break;
}
case START_WRITE: {
nsISupports* fs;
nsFileSpec spec(mPath);
mStatus = mListener->OnStartBinding(mContext); // always send the start notification
if (NS_FAILED(mStatus)) goto error;
mStatus = NS_NewTypicalOutputFileStream(&fs, spec);
if (NS_FAILED(mStatus)) goto error;
mStatus = fs->QueryInterface(nsIOutputStream::GetIID(), (void**)&mFileStream);
NS_RELEASE(fs);
if (NS_FAILED(mStatus)) goto error;
mStatus = NS_NewBuffer(&mBuffer, NS_FILE_TRANSPORT_BUFFER_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(mStatus)) goto error;
mStatus = NS_NewBufferInputStream(&mBufferStream, mBuffer, PR_FALSE);
if (NS_FAILED(mStatus)) goto error;
mState = WRITING;
break;
}
case WRITING: {
break;
}
case ENDING: {
NS_IF_RELEASE(mBufferStream);
mBufferStream = nsnull;
NS_IF_RELEASE(mFileStream);
mFileStream = nsnull;
// XXX where do we get the error message?
(void)mListener->OnStopBinding(mContext, mStatus, nsnull);
mState = ENDED;
break;
}
case ENDED: {
NS_NOTREACHED("trying to continue an ended file transfer");
break;
}
}
PR_ExitMonitor(mMonitor);
return;
error:
mState = ENDING;
PR_ExitMonitor(mMonitor);
return;
}
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileTransport::Run(void)
{
while (mState != ENDED && !mSuspended) {
Process();
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,102 @@
/* -*- 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 nsFileTransport_h___
#define nsFileTransport_h___
#include "nsIChannel.h"
#include "nsIThread.h"
#include "nsIEventQueue.h"
#include "prmon.h"
class nsFileTransportService;
class nsIBaseStream;
class nsIString;
class nsIBuffer;
class nsIBufferInputStream;
class nsFileTransport : public nsIChannel, public nsIRunnable
{
public:
NS_DECL_ISUPPORTS
// nsIRequest methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
// nsIChannel methods:
NS_IMETHOD GetURI(nsIURI * *aURL);
NS_IMETHOD OpenInputStream(PRUint32 startPosition, PRInt32 readCount, nsIInputStream **_retval);
NS_IMETHOD OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval);
NS_IMETHOD AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener);
NS_IMETHOD AsyncWrite(nsIInputStream *fromStream,
PRUint32 startPosition, PRInt32 writeCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamObserver *observer);
// nsIRunnable methods:
NS_IMETHOD Run(void);
// nsFileTransport methods:
nsFileTransport();
virtual ~nsFileTransport();
enum State {
START_READ,
READING,
START_WRITE,
WRITING,
ENDING,
ENDED
};
nsresult Init(const char* path,
nsFileTransportService* service);
nsresult Init(nsISupports* context,
nsIStreamListener* listener,
State state, PRUint32 startPosition, PRInt32 count);
void Process(void);
protected:
char* mPath;
nsISupports* mContext;
nsIStreamListener* mListener;
nsFileTransportService* mService;
State mState;
PRBool mSuspended;
// state variables:
nsIBaseStream* mFileStream; // cast to nsIInputStream/nsIOutputStream for reading/writing
nsIBuffer* mBuffer;
nsIBufferInputStream* mBufferStream;
nsresult mStatus;
PRUint32 mSourceOffset;
PRInt32 mAmount;
private:
PRMonitor* mMonitor;
};
#define NS_FILE_TRANSPORT_BUFFER_SIZE (4*1024)
#endif /* nsFileTransport_h___ */

View File

@@ -0,0 +1,132 @@
/* -*- 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 "nsFileTransportService.h"
#include "nsFileTransport.h"
#include "nsIThread.h"
#include "nsIFileStream.h"
#include "prmem.h"
#include "nsIStreamListener.h"
////////////////////////////////////////////////////////////////////////////////
// nsFileTransportService methods:
nsFileTransportService::nsFileTransportService()
: mPool(nsnull)
{
NS_INIT_REFCNT();
}
nsresult
nsFileTransportService::Init()
{
nsresult rv;
rv = NS_NewThreadPool(&mPool, NS_FILE_TRANSPORT_WORKER_COUNT,
NS_FILE_TRANSPORT_WORKER_COUNT, 8*1024);
return rv;
}
nsFileTransportService::~nsFileTransportService()
{
// this will wait for all outstanding requests to be processed, then
// join with the worker threads, and finally free the pool:
NS_IF_RELEASE(mPool);
}
NS_METHOD
nsFileTransportService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsFileTransportService* trans = new nsFileTransportService();
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(trans);
nsresult rv = trans->Init();
if (NS_SUCCEEDED(rv)) {
rv = trans->QueryInterface(aIID, aResult);
}
NS_RELEASE(trans);
return rv;
}
NS_IMPL_ISUPPORTS(nsFileTransportService, nsIFileTransportService::GetIID());
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileTransportService::CreateTransport(const char* path,
nsIChannel* *result)
{
nsresult rv;
nsFileTransport* trans = new nsFileTransport();
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = trans->Init(path, this);
if (NS_FAILED(rv)) {
delete trans;
return rv;
}
NS_ADDREF(trans);
*result = trans;
return NS_OK;
}
NS_IMETHODIMP
nsFileTransportService::ProcessPendingRequests(void)
{
return mPool->ProcessPendingRequests();
}
nsresult
nsFileTransportService::DispatchRequest(nsIRunnable* runnable)
{
return mPool->DispatchRequest(runnable);
}
////////////////////////////////////////////////////////////////////////////////
nsresult
nsFileTransportService::Suspend(nsFileTransport* request)
{
nsresult rv;
if (mSuspended == nsnull) {
rv = NS_NewISupportsArray(&mSuspended);
if (NS_FAILED(rv)) return rv;
}
return mSuspended->AppendElement(NS_STATIC_CAST(nsIChannel*, request));
}
nsresult
nsFileTransportService::Resume(nsFileTransport* request)
{
nsresult rv;
if (mSuspended == nsnull)
return NS_ERROR_FAILURE;
// XXX RemoveElement returns a bool instead of nsresult!
PRBool removed = mSuspended->RemoveElement(NS_STATIC_CAST(nsIChannel*, request));
rv = removed ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
// restart the request
rv = mPool->DispatchRequest(NS_STATIC_CAST(nsIRunnable*, request));
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,64 @@
/* -*- 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 nsFileTransportService_h___
#define nsFileTransportService_h___
#include "nsIFileTransportService.h"
#include "nsISupportsArray.h"
#include "nsIThread.h"
#include "nscore.h"
#include "nsIEventQueue.h"
class nsFileTransport;
////////////////////////////////////////////////////////////////////////////////
#define NS_FILE_TRANSPORT_WORKER_COUNT 4
class nsFileTransportService : public nsIFileTransportService
{
public:
NS_DECL_ISUPPORTS
// nsIFileTransportService methods:
NS_IMETHOD CreateTransport(const char* path,
nsIChannel* *result);
NS_IMETHOD ProcessPendingRequests(void);
// nsFileTransportService methods:
nsFileTransportService();
virtual ~nsFileTransportService();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsresult Init();
nsresult DispatchRequest(nsIRunnable* runnable);
nsresult Suspend(nsFileTransport* request);
nsresult Resume(nsFileTransport* request);
protected:
nsIThreadPool* mPool;
nsISupportsArray* mSuspended;
};
////////////////////////////////////////////////////////////////////////////////
#endif /* nsFileTransportService_h___ */

View File

@@ -0,0 +1,359 @@
/* -*- 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 "nsIOService.h"
#include "nsIProtocolHandler.h"
#include "nscore.h"
#include "nsString2.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsIFileTransportService.h"
#include "nsIURI.h"
#include "nsIStreamListener.h"
#include "nsCOMPtr.h"
#include "prprf.h"
#include "prmem.h" // for PR_Malloc
#include <ctype.h> // for isalpha
#include "nsIFileProtocolHandler.h" // for NewChannelFromNativePath
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
nsIOService::nsIOService()
{
NS_INIT_REFCNT();
}
nsresult
nsIOService::Init()
{
return NS_OK;
}
nsIOService::~nsIOService()
{
}
NS_METHOD
nsIOService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsIOService* ios = new nsIOService();
if (ios == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(ios);
nsresult rv = ios->QueryInterface(aIID, aResult);
NS_RELEASE(ios);
return rv;
}
NS_IMPL_ISUPPORTS(nsIOService, nsIIOService::GetIID());
////////////////////////////////////////////////////////////////////////////////
#define MAX_SCHEME_LENGTH 64 // XXX big enough?
#define MAX_NET_PROGID_LENGTH (MAX_SCHEME_LENGTH + NS_NETWORK_PROTOCOL_PROGID_PREFIX_LENGTH + 1)
NS_IMETHODIMP
nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
{
nsresult rv;
NS_ASSERTION(NS_NETWORK_PROTOCOL_PROGID_PREFIX_LENGTH
== nsCRT::strlen(NS_NETWORK_PROTOCOL_PROGID_PREFIX),
"need to fix NS_NETWORK_PROTOCOL_PROGID_PREFIX_LENGTH");
// XXX we may want to speed this up by introducing our own protocol
// scheme -> protocol handler mapping, avoiding the string manipulation
// and service manager stuff
char buf[MAX_NET_PROGID_LENGTH];
nsAutoString2 progID(NS_NETWORK_PROTOCOL_PROGID_PREFIX);
progID += scheme;
progID.ToCString(buf, MAX_NET_PROGID_LENGTH);
nsIProtocolHandler* handler;
rv = nsServiceManager::GetService(buf, nsIProtocolHandler::GetIID(),
(nsISupports**)&handler);
if (NS_FAILED(rv)) return rv;
*result = handler;
return NS_OK;
}
static nsresult
GetScheme(const char* inURI, char* *scheme)
{
// search for something up to a colon, and call it the scheme
char c;
const char* URI = inURI;
PRUint32 i = 0;
PRUint32 length = 0;
while ((c = *URI++) != '\0') {
if (c == ':') {
char* newScheme = (char *)PR_Malloc(length+1);
if (newScheme == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsCRT::memcpy(newScheme, inURI, length);
newScheme[length] = '\0';
*scheme = newScheme;
return NS_OK;
}
else if (isalpha(c)) {
length++;
}
}
return NS_ERROR_FAILURE; // no colon
}
NS_IMETHODIMP
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
nsIURI* *result)
{
nsresult rv;
char* scheme;
rv = GetScheme(aSpec, &scheme);
if (NS_FAILED(rv)) {
if (aBaseURI)
rv = aBaseURI->GetScheme(&scheme);
if (NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsIProtocolHandler> handler;
rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
nsCRT::free(scheme);
if (NS_FAILED(rv)) return rv;
rv = handler->NewURI(aSpec, aBaseURI, result);
//NS_RELEASE(handler);
return rv;
}
NS_IMETHODIMP
nsIOService::NewChannelFromURI(const char* verb, nsIURI *aURI,
nsIEventSinkGetter *eventSinkGetter,
nsIChannel **result)
{
nsresult rv;
char* scheme;
rv = aURI->GetScheme(&scheme);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIProtocolHandler> handler;
rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIEventQueue> eventQ;
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
if (NS_FAILED(rv)) return rv;
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(),
getter_AddRefs(eventQ));
if (NS_FAILED(rv)) return rv;
nsIChannel* channel;
rv = handler->NewChannel(verb, aURI, eventSinkGetter, eventQ,
&channel);
if (NS_FAILED(rv)) return rv;
*result = channel;
return rv;
}
NS_IMETHODIMP
nsIOService::NewChannel(const char* verb, const char *aSpec,
nsIURI *aBaseURI,
nsIEventSinkGetter *eventSinkGetter,
nsIChannel **result)
{
nsresult rv;
nsIURI* uri;
rv = NewURI(aSpec, aBaseURI, &uri);
if (NS_FAILED(rv)) return rv;
rv = NewChannelFromURI(verb, uri, eventSinkGetter, result);
NS_RELEASE(uri);
return rv;
}
NS_IMETHODIMP
nsIOService::MakeAbsolute(const char *aSpec,
nsIURI *aBaseURI,
char **result)
{
nsresult rv;
NS_ASSERTION(aBaseURI, "It doesn't make sense to not supply a base URI");
char* scheme;
rv = GetScheme(aSpec, &scheme);
if (NS_SUCCEEDED(rv)) {
// if aSpec has a scheme, then it's already absolute
*result = nsCRT::strdup(aSpec);
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
// else ask the protocol handler for the base URI to deal with it
rv = aBaseURI->GetScheme(&scheme);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIProtocolHandler> handler;
rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
nsCRT::free(scheme);
if (NS_FAILED(rv)) return rv;
rv = handler->MakeAbsolute(aSpec, aBaseURI, result);
return rv;
}
NS_IMETHODIMP
nsIOService::GetAppCodeName(PRUnichar* *aAppCodeName)
{
*aAppCodeName = mAppCodeName.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsIOService::GetAppVersion(PRUnichar* *aAppVersion)
{
*aAppVersion = mAppVersion.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsIOService::GetAppName(PRUnichar* *aAppName)
{
*aAppName = mAppName.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsIOService::GetLanguage(PRUnichar* *aLanguage)
{
*aLanguage = mAppLanguage.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsIOService::GetPlatform(PRUnichar* *aPlatform)
{
*aPlatform = mAppPlatform.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsIOService::GetUserAgent(PRUnichar* *aUserAgent)
{
// XXX this should load the http module and ask for the user agent string from it.
char buf[200];
PR_snprintf(buf, 200, "%.100s/%.90s", mAppCodeName.GetBuffer(), mAppVersion.GetBuffer());
nsAutoString2 aUA(buf);
*aUserAgent = aUA.ToNewUnicode();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsIOService::NewAsyncStreamObserver(nsIStreamObserver *receiver, nsIEventQueue *eventQueue,
nsIStreamObserver **result)
{
return NS_NewAsyncStreamObserver(result, eventQueue, receiver);
}
NS_IMETHODIMP
nsIOService::NewAsyncStreamListener(nsIStreamListener *receiver, nsIEventQueue *eventQueue,
nsIStreamListener **result)
{
return NS_NewAsyncStreamListener(result, eventQueue, receiver);
}
NS_IMETHODIMP
nsIOService::NewSyncStreamListener(nsIBufferInputStream **inStream,
nsIBufferOutputStream **outStream,
nsIStreamListener **listener)
{
return NS_NewSyncStreamListener(inStream, outStream, listener);
}
NS_IMETHODIMP
nsIOService::NewChannelFromNativePath(const char *nativePath, nsIFileChannel **result)
{
nsresult rv;
nsIProtocolHandler* handler;
rv = GetProtocolHandler("file", &handler);
if (NS_FAILED(rv)) return rv;
nsIFileProtocolHandler* fileHandler = nsnull;
rv = handler->QueryInterface(nsIFileProtocolHandler::GetIID(),
(void**)&fileHandler);
NS_RELEASE(handler);
if (NS_FAILED(rv)) return rv;
nsIFileChannel* channel;
rv = fileHandler->NewChannelFromNativePath(nativePath, &channel);
NS_RELEASE(fileHandler);
if (NS_FAILED(rv)) return rv;
*result = channel;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// HELPER ROUTINES
////////////////////////////////////////////////////////////////////////////////
#if 0
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
nsresult NS_NewURI(nsIURI** aInstancePtrResult,
const char *aSpec,
nsIURI* aBaseURI)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsINetService *inet = nsnull;
nsresult rv = nsServiceManager::GetService(kNetServiceCID,
kINetServiceIID,
(nsISupports **)&inet);
if (NS_FAILED(rv)) return rv;
rv = inet->NewURI(aSpec, aInstancePtrResult, aBaseURI);
if (NS_FAILED(rv)) return rv;
nsServiceManager::ReleaseService(kNetServiceCID, inet);
return rv;
}
#endif
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,73 @@
/* -*- 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 nsIOService_h__
#define nsIOService_h__
#include "nsIIOService.h"
#include "nsString2.h"
class nsIOService : public nsIIOService
{
public:
NS_DECL_ISUPPORTS
// nsIIOService methods:
NS_IMETHOD GetProtocolHandler(const char *scheme,
nsIProtocolHandler **_retval);
NS_IMETHOD MakeAbsolute(const char *aRelativeSpec,
nsIURI *aBaseURI,
char **_retval);
NS_IMETHOD NewURI(const char *aSpec, nsIURI *aBaseURI,
nsIURI **_retval);
NS_IMETHOD NewChannelFromURI(const char* verb, nsIURI *aURI,
nsIEventSinkGetter *eventSinkGetter,
nsIChannel **_retval);
NS_IMETHOD NewChannel(const char* verb, const char *aSpec,
nsIURI *aBaseURI,
nsIEventSinkGetter *eventSinkGetter,
nsIChannel **_retval);
NS_IMETHOD GetAppCodeName(PRUnichar* *aAppCodeName);
NS_IMETHOD GetAppVersion(PRUnichar* *aAppVersion);
NS_IMETHOD GetAppName(PRUnichar* *aAppName);
NS_IMETHOD GetLanguage(PRUnichar* *aLanguage);
NS_IMETHOD GetPlatform(PRUnichar* *aPlatform);
NS_IMETHOD GetUserAgent(PRUnichar* *aUserAgent);
NS_IMETHOD NewAsyncStreamObserver(nsIStreamObserver *receiver, nsIEventQueue *eventQueue, nsIStreamObserver **_retval);
NS_IMETHOD NewAsyncStreamListener(nsIStreamListener *receiver, nsIEventQueue *eventQueue, nsIStreamListener **_retval);
NS_IMETHOD NewSyncStreamListener(nsIBufferInputStream **inStream, nsIBufferOutputStream **outStream, nsIStreamListener **_retval);
NS_IMETHOD NewChannelFromNativePath(const char *nativePath, nsIFileChannel **_retval);
// nsIOService methods:
nsIOService();
virtual ~nsIOService();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsresult Init();
protected:
nsString2 mAppName;
nsString2 mAppCodeName;
nsString2 mAppVersion;
nsString2 mAppLanguage;
nsString2 mAppPlatform;
};
#endif // nsIOService_h__

View File

@@ -0,0 +1,140 @@
/* -*- 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 "nsNetModRegEntry.h"
#include "plstr.h"
//////////////////////////////
//// nsISupports
//////////////////////////////
NS_IMPL_ISUPPORTS(nsNetModRegEntry, nsINetModRegEntry::GetIID());
//////////////////////////////
//// nsINetModRegEntry
//////////////////////////////
NS_IMETHODIMP
nsNetModRegEntry::GetMNotify(nsINetNotify **aNotify) {
*aNotify = mNotify;
NS_ADDREF(*aNotify);
return NS_OK;
}
NS_IMETHODIMP
nsNetModRegEntry::GetMEventQ(nsIEventQueue **aEventQ) {
*aEventQ = mEventQ;
NS_ADDREF(*aEventQ);
return NS_OK;
}
NS_IMETHODIMP
nsNetModRegEntry::GetMTopic(char **aTopic) {
*aTopic = new char [PL_strlen(mTopic) + 1];
if (!*aTopic) return NS_ERROR_OUT_OF_MEMORY;
PL_strcpy(*aTopic, mTopic);
return NS_OK;
}
NS_IMETHODIMP
nsNetModRegEntry::GetMCID(nsCID **aMCID) {
*aMCID = &mCID;
return NS_OK;
}
NS_IMETHODIMP
nsNetModRegEntry::Equals(nsINetModRegEntry* aEntry, PRBool *_retVal) {
nsresult rv = NS_OK;
PRBool retVal = PR_TRUE;
NS_ADDREF(aEntry);
char * topic = 0;
nsINetNotify* notify = 0;
nsIEventQueue* eventQ = 0;
nsCID *cid = 0;
rv = aEntry->GetMTopic(&topic);
if (NS_FAILED(rv)) {
retVal = PR_FALSE;
goto end;
}
if (PL_strcmp(topic, mTopic)) {
retVal = PR_FALSE;
goto end;
}
rv = aEntry->GetMNotify(&notify);
if (NS_FAILED(rv)) {
retVal = PR_FALSE;
goto end;
}
if (notify != mNotify) {
retVal = PR_FALSE;
goto end;
}
rv = aEntry->GetMEventQ(&eventQ);
if (NS_FAILED(rv)) {
retVal = PR_FALSE;
goto end;
}
if (eventQ != mEventQ) {
retVal = PR_FALSE;
goto end;
}
rv = aEntry->GetMCID(&cid);
if (NS_FAILED(rv)) {
retVal = PR_FALSE;
goto end;
}
if (!mCID.Equals(*cid)) {
retVal = PR_FALSE;
goto end;
}
end:
NS_IF_RELEASE(notify);
NS_IF_RELEASE(eventQ);
*_retVal = retVal;
NS_RELEASE(aEntry);
return rv;
}
//////////////////////////////
//// nsNetModRegEntry
//////////////////////////////
nsNetModRegEntry::nsNetModRegEntry(const char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify, nsCID aCID)
: mEventQ(aEventQ), mNotify(aNotify) {
NS_INIT_REFCNT();
mTopic = new char [PL_strlen(aTopic) + 1];
PL_strcpy(mTopic, aTopic);
NS_ADDREF(mEventQ);
NS_ADDREF(mNotify);
mCID = aCID;
}
nsNetModRegEntry::~nsNetModRegEntry() {
delete [] mTopic;
NS_RELEASE(mEventQ);
NS_RELEASE(mNotify);
}

View File

@@ -0,0 +1,48 @@
/* -*- 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 ___nsNetModRegEntry_h___
#define ___nsNetModRegEntry_h___
#include "nsINetModRegEntry.h"
#include "nsIEventQueue.h"
class nsNetModRegEntry : nsINetModRegEntry {
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsINetModRegEntry
NS_IMETHOD GetMNotify(nsINetNotify **aNotify);
NS_IMETHOD GetMEventQ(nsIEventQueue **aEventQ);
NS_IMETHOD GetMTopic(char **aTopic);
NS_IMETHOD GetMCID(nsCID **aCID);
NS_IMETHOD Equals(nsINetModRegEntry* aEntry, PRBool *_retVal);
// nsNetModRegEntry
nsNetModRegEntry(const char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify, nsCID aCID);
~nsNetModRegEntry();
char *mTopic;
nsIEventQueue *mEventQ;
nsINetNotify *mNotify;
nsCID mCID;
};
#endif //___nsNetModRegEntry_h___

View File

@@ -0,0 +1,226 @@
/* -*- Mode: IDL; 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 "nsNetModuleMgr.h"
#include "nsNetModRegEntry.h"
#include "nsEnumeratorUtils.h" // for nsArrayEnumerator
#include "nsString2.h"
#include "nsIEventQueue.h"
// Entry routines.
static PRBool DeleteEntry(nsISupports *aElement, void *aData) {
NS_ASSERTION(aElement, "null pointer");
NS_RELEASE(aElement);
return PR_TRUE;
}
///////////////////////////////////
//// nsISupports
///////////////////////////////////
NS_IMPL_ISUPPORTS(nsNetModuleMgr, nsINetModuleMgr::GetIID());
///////////////////////////////////
//// nsINetModuleMgr
///////////////////////////////////
NS_IMETHODIMP
nsNetModuleMgr::RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID) {
nsresult rv;
PRUint32 cnt;
// XXX before registering an object for a particular topic
// XXX QI the nsINetNotify interface passed in for the interfaces
// XXX supported by the topic.
PR_Lock(mLock);
nsINetModRegEntry* newEntryI = nsnull;
nsNetModRegEntry *newEntry =
new nsNetModRegEntry(aTopic, aEventQueue, aNotify, *aCID);
if (!newEntry)
return NS_ERROR_OUT_OF_MEMORY;
rv = newEntry->QueryInterface(nsINetModRegEntry::GetIID(), (void**)&newEntryI);
if (NS_FAILED(rv)) return rv;
// Check for a previous registration
mEntries->Count(&cnt);
for (PRUint32 i = 0; i < cnt; i++) {
nsINetModRegEntry* curEntry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i));
PRBool same = PR_FALSE;
rv = newEntryI->Equals(curEntry, &same);
if (NS_FAILED(rv)) {
PR_Unlock(mLock);
return rv;
}
// if we've already got this one registered, yank it, and replace it with the new one
if (same) {
NS_RELEASE(curEntry);
mEntries->DeleteElementAt(i);
break;
}
}
mEntries->AppendElement(NS_STATIC_CAST(nsISupports*, newEntryI));
PR_Unlock(mLock);
NS_RELEASE(newEntryI);
return NS_OK;
}
NS_IMETHODIMP
nsNetModuleMgr::UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID) {
PR_Lock(mLock);
nsresult rv;
PRUint32 cnt;
nsINetModRegEntry* tmpEntryI = nsnull;
nsNetModRegEntry *tmpEntry =
new nsNetModRegEntry(aTopic, aEventQueue, aNotify, *aCID);
if (!tmpEntry)
return NS_ERROR_OUT_OF_MEMORY;
rv = tmpEntry->QueryInterface(nsINetModRegEntry::GetIID(), (void**)&tmpEntryI);
if (NS_FAILED(rv)) return rv;
mEntries->Count(&cnt);
for (PRUint32 i = 0; i < cnt; i++) {
nsINetModRegEntry* curEntry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i));
NS_ADDREF(curEntry); // get our ref to it
PRBool same = PR_FALSE;
rv = tmpEntryI->Equals(curEntry, &same);
if (NS_FAILED(rv)) {
PR_Unlock(mLock);
return rv;
}
if (same) {
NS_RELEASE(curEntry);
mEntries->DeleteElementAt(i);
break;
}
NS_RELEASE(curEntry); // ditch our ref to it
}
PR_Unlock(mLock);
NS_RELEASE(tmpEntryI);
return NS_OK;
}
NS_IMETHODIMP
nsNetModuleMgr::EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnumerator) {
nsresult rv;
PRUint32 cnt;
char *topic = nsnull;
// get all the entries for this topic
PR_Lock(mLock);
rv = mEntries->Count(&cnt);
if (NS_FAILED(rv)) return rv;
// create the new array
nsISupportsArray *topicEntries = nsnull;
rv = NS_NewISupportsArray(&topicEntries);
if (NS_FAILED(rv)) return rv;
// run through the main entry array looking for topic matches.
for (PRUint32 i = 0; i < cnt; i++) {
nsINetModRegEntry *entry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i));
rv = entry->GetMTopic(&topic);
if (NS_FAILED(rv)) {
NS_RELEASE(topicEntries);
NS_RELEASE(entry);
PR_Unlock(mLock);
return rv;
}
if (!PL_strcmp(aTopic, topic)) {
delete [] topic;
topic = nsnull;
// found a match, add it to the list
rv = topicEntries->AppendElement(NS_STATIC_CAST(nsISupports*, entry));
if (NS_FAILED(rv)) {
NS_RELEASE(topicEntries);
NS_RELEASE(entry);
PR_Unlock(mLock);
return rv;
}
}
delete [] topic;
topic = nsnull;
NS_RELEASE(entry);
}
nsISimpleEnumerator *outEnum = nsnull;
nsArrayEnumerator *arrEnum = new nsArrayEnumerator(topicEntries);
NS_RELEASE(topicEntries);
if (!arrEnum) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = arrEnum->QueryInterface(nsISimpleEnumerator::GetIID(), (void**)&outEnum);
if (NS_FAILED(rv)) {
delete arrEnum;
return rv;
}
*aEnumerator = outEnum;
PR_Unlock(mLock);
return NS_OK;
}
///////////////////////////////////
//// nsNetModuleMgr
///////////////////////////////////
nsNetModuleMgr::nsNetModuleMgr() {
NS_INIT_REFCNT();
NS_NewISupportsArray(&mEntries);
mLock = PR_NewLock();
}
nsNetModuleMgr::~nsNetModuleMgr() {
if (mEntries) {
mEntries->EnumerateForwards(DeleteEntry, nsnull);
NS_RELEASE(mEntries);
}
PR_DestroyLock(mLock);
}
NS_METHOD
nsNetModuleMgr::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
static nsNetModuleMgr* mgr = nsnull;
if (!mgr) mgr = new nsNetModuleMgr();
if (!mgr) return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mgr);
nsresult rv = mgr->QueryInterface(aIID, aResult);
// don't release our ref as this is a singleton service.
//NS_RELEASE(mgr);
return rv;
}

View File

@@ -0,0 +1,50 @@
/* -*- 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 ___nsNetModuleMgr_h__
#define ___nsNetModuleMgr_h__
#include "nsINetModuleMgr.h"
#include "prlock.h"
#include "nspr.h"
#include "nsISupportsArray.h"
class nsNetModuleMgr : public nsINetModuleMgr {
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsINetModuleMgr
NS_IMETHOD RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID);
NS_IMETHOD UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID);
NS_IMETHOD EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnumerator);
// nsNetModuleMgr
nsNetModuleMgr();
~nsNetModuleMgr();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsISupportsArray *mEntries;
PRLock *mLock;
};
#endif // ___nsNetModuleMgr_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,148 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsSocketTransport_h___
#define nsSocketTransport_h___
#include "prclist.h"
#include "prio.h"
#include "prnetdb.h"
#include "nsIChannel.h"
#include "nsIInputStream.h"
#include "nsIBufferInputStream.h"
//
// This is the size of the global buffer used by all nsSocketTransport
// instances when reading from or writing to the network.
//
#define MAX_IO_BUFFER_SIZE 8192
//
// This is the maximum amount of data that will be read into a stream before
// another transport is processed...
//
#define MAX_IO_TRANSFER_SIZE 32768
enum nsSocketState {
eSocketState_Created = 0,
eSocketState_WaitDNS = 1,
eSocketState_Closed = 2,
eSocketState_WaitConnect = 3,
eSocketState_Connected = 4,
eSocketState_WaitReadWrite = 5,
eSocketState_DoneRead = 6,
eSocketState_DoneWrite = 7,
eSocketState_Done = 8,
eSocketState_Timeout = 9,
eSocketState_Error = 10,
eSocketState_Max = 11
};
enum nsSocketOperation {
eSocketOperation_None = 0,
eSocketOperation_Connect = 1,
eSocketOperation_ReadWrite = 2,
eSocketOperation_Max = 3
};
// Forward declarations...
class nsSocketTransportService;
class nsSocketTransportStream;
class nsSocketTransport : public nsIChannel
{
public:
// nsISupports methods:
NS_DECL_ISUPPORTS
// nsIRequest methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
// nsIChannel methods:
NS_IMETHOD GetURI(nsIURI * *aURL);
NS_IMETHOD OpenInputStream(PRUint32 startPosition, PRInt32 readCount, nsIInputStream **_retval);
NS_IMETHOD OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval);
NS_IMETHOD AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener);
NS_IMETHOD AsyncWrite(nsIInputStream *fromStream,
PRUint32 startPosition, PRInt32 writeCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamObserver *observer);
// nsSocketTransport methods:
nsSocketTransport();
virtual ~nsSocketTransport();
nsresult Init(nsSocketTransportService* aService,
const char* aHost,
PRInt32 aPort);
nsresult Process(PRInt16 aSelectFlags);
nsresult CloseConnection(void);
// Access methods used by the socket transport service...
PRFileDesc* GetSocket(void) { return mSocketFD; }
PRInt16 GetSelectFlags(void) { return mSelectFlags; }
PRCList* GetListNode(void) { return &mListLink; }
static nsSocketTransport* GetInstance(PRCList* qp) { return (nsSocketTransport*)((char*)qp - offsetof(nsSocketTransport, mListLink)); }
protected:
nsresult doConnection(PRInt16 aSelectFlags);
nsresult doResolveHost(void);
nsresult doRead(PRInt16 aSelectFlags);
nsresult doWrite(PRInt16 aSelectFlags);
protected:
PRCList mListLink;
PRLock* mLock;
nsSocketState mCurrentState;
nsSocketOperation mOperation;
PRInt32 mSuspendCount;
PRFileDesc* mSocketFD;
PRNetAddr mNetAddress;
PRInt16 mSelectFlags;
char* mHostName;
PRInt32 mPort;
nsISupports* mReadContext;
nsIStreamListener* mReadListener;
nsSocketTransportStream* mReadStream;
nsISupports* mWriteContext;
nsIStreamObserver* mWriteObserver;
nsIBufferInputStream* mWriteStream;
PRUint32 mSourceOffset;
nsSocketTransportService* mService;
};
#endif /* nsSocketTransport_h___ */

View File

@@ -0,0 +1,492 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsSocketTransportService.h"
#include "nsSocketTransport.h"
#include "nsAutoLock.h"
#define MAX_OPEN_CONNECTIONS 50
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsSocketTransportService::nsSocketTransportService()
{
NS_INIT_REFCNT();
PR_INIT_CLIST(&mWorkQ);
mThread = nsnull;
mThreadEvent = nsnull;
mThreadLock = nsnull;
mSelectFDSet = nsnull;
mSelectFDSetCount = 0;
mActiveTransportList = nsnull;
mThreadRunning = PR_FALSE;
}
nsSocketTransportService::~nsSocketTransportService()
{
//
// It is impossible for the nsSocketTransportService to be deleted while
// the transport thread is running because it holds a reference to the
// nsIRunnable (ie. the nsSocketTransportService instance)...
//
NS_ASSERTION(!mThread && !mThreadRunning,
"The socket transport thread is still running...");
if (mSelectFDSet) {
PR_Free(mSelectFDSet);
mSelectFDSet = nsnull;
}
if (mActiveTransportList) {
PR_Free(mActiveTransportList);
mActiveTransportList = nsnull;
}
if (mThreadEvent) {
PR_DestroyPollableEvent(mThreadEvent);
mThreadEvent = nsnull;
}
if (mThreadLock) {
PR_DestroyLock(mThreadLock);
mThreadLock = nsnull;
}
}
NS_METHOD
nsSocketTransportService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsSocketTransportService* trans = new nsSocketTransportService();
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(trans);
nsresult rv = trans->Init();
if (NS_SUCCEEDED(rv)) {
rv = trans->QueryInterface(aIID, aResult);
}
NS_RELEASE(trans);
return rv;
}
nsresult nsSocketTransportService::Init(void)
{
nsresult rv = NS_OK;
NS_ASSERTION(!mThread, "Socket transport thread has already been created!.");
//
// Create FDSET list used by PR_Poll(...)
//
if (!mSelectFDSet) {
mSelectFDSet = (PRPollDesc*)PR_Malloc(sizeof(PRPollDesc)*MAX_OPEN_CONNECTIONS);
if (mSelectFDSet) {
memset(mSelectFDSet, 0, sizeof(PRPollDesc)*MAX_OPEN_CONNECTIONS);
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
//
// Create the list of Active transport objects... This list contains the
// nsSocketTransport corresponding to each PRFileDesc* in the mSelectFDSet
//
if (NS_SUCCEEDED(rv) && !mActiveTransportList) {
mActiveTransportList = (nsSocketTransport**)PR_Malloc(sizeof(nsSocketTransport*)*MAX_OPEN_CONNECTIONS);
if (mActiveTransportList) {
memset(mActiveTransportList, 0, sizeof(nsSocketTransport*)*MAX_OPEN_CONNECTIONS);
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
//
// Create the pollable event used to immediately wake up the transport
// thread when it is blocked in PR_Poll(...)
//
if (NS_SUCCEEDED(rv) && !mThreadEvent) {
mThreadEvent = PR_NewPollableEvent();
if (!mThreadEvent) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
//
// Create the synchronization lock for the transport thread...
//
if (NS_SUCCEEDED(rv) && !mThreadLock) {
mThreadLock = PR_NewLock();
if (!mThreadLock) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
//
// Create the transport thread...
//
if (NS_SUCCEEDED(rv) && !mThread) {
mThreadRunning = PR_TRUE;
rv = NS_NewThread(&mThread, this);
}
return rv;
}
nsresult nsSocketTransportService::AddToWorkQ(nsSocketTransport* aTransport)
{
PRStatus status;
PRBool bFireEvent = PR_FALSE;
nsresult rv = NS_OK;
PRCList* qp;
{
nsAutoLock lock(mThreadLock);
//
// Only add the transport if it is *not* already on the list...
//
qp = aTransport->GetListNode();
if (PR_CLIST_IS_EMPTY(qp)) {
NS_ADDREF(aTransport);
bFireEvent = PR_CLIST_IS_EMPTY(&mWorkQ);
PR_APPEND_LINK(qp, &mWorkQ);
}
}
//
// Only fire an event if this is the first entry in the workQ. Otherwise,
// the event has already been fired and the transport thread will process
// all of the entries at once...
//
if (bFireEvent) {
status = PR_SetPollableEvent(mThreadEvent);
if (PR_FAILURE == status) {
rv = NS_ERROR_FAILURE;
}
}
return rv;
}
nsresult nsSocketTransportService::ProcessWorkQ(void)
{
nsresult rv = NS_OK;
PRCList* qp;
//
// Only process pending operations while there is space available in the
// select list...
//
// XXX: Need a way to restart the ProcessWorkQ(...) when space becomes
// available in the select set...
//
PR_Lock(mThreadLock);
while (!PR_CLIST_IS_EMPTY(&mWorkQ) &&
(MAX_OPEN_CONNECTIONS > mSelectFDSetCount)) {
nsSocketTransport* transport;
// Get the next item off of the workQ...
qp = PR_LIST_HEAD(&mWorkQ);
transport = nsSocketTransport::GetInstance(qp);
PR_REMOVE_AND_INIT_LINK(qp);
// Try to perform the operation...
//
// Do not process the transport while holding the transport service
// lock... A deadlock could occur if another thread is holding the
// transport lock and tries to add the transport to the service's WorkQ...
//
// Do not pass any select flags...
PR_Unlock(mThreadLock);
rv = transport->Process(0);
PR_Lock(mThreadLock);
//
// If the operation would block, then add it to the select list for
// later processing when the data arrives...
//
if (NS_BASE_STREAM_WOULD_BLOCK == rv) {
rv = AddToSelectList(transport);
}
// Release the transport object (since it is no longer on the WorkQ).
NS_RELEASE(transport);
}
PR_Unlock(mThreadLock);
return rv;
}
nsresult nsSocketTransportService::AddToSelectList(nsSocketTransport* aTransport)
{
nsresult rv = NS_OK;
if (aTransport && (MAX_OPEN_CONNECTIONS > mSelectFDSetCount) ) {
PRPollDesc* pfd;
int i;
// Check to see if the transport is already in the list...
for (i=1; i<mSelectFDSetCount; i++) {
if (mActiveTransportList[i] == aTransport) {
break;
}
}
// Add the FileDesc to the PRPollDesc list...
if (i == mSelectFDSetCount) {
pfd = &mSelectFDSet[mSelectFDSetCount];
pfd->fd = aTransport->GetSocket();;
pfd->in_flags = aTransport->GetSelectFlags();
pfd->out_flags = 0;
// Add the transport instance to the corresponding active transport list...
NS_ADDREF(aTransport);
mActiveTransportList[mSelectFDSetCount] = aTransport;
mSelectFDSetCount += 1;
}
}
else {
rv = NS_ERROR_FAILURE;
}
return rv;
}
nsresult nsSocketTransportService::RemoveFromSelectList(nsSocketTransport* aTransport)
{
int i;
nsresult rv = NS_ERROR_FAILURE;
for (i=1; i<mSelectFDSetCount; i++) {
if (mActiveTransportList[i] == aTransport) {
int last = mSelectFDSetCount-1;
NS_RELEASE(mActiveTransportList[i]);
// Move the last element in the array into the new empty slot...
if (i != last) {
memcpy(&mSelectFDSet[i], &mSelectFDSet[last], sizeof(mSelectFDSet[0]));
mSelectFDSet[last].fd = nsnull;
mActiveTransportList[i] = mActiveTransportList[last];
mActiveTransportList[last] = nsnull;
} else {
mSelectFDSet[i].fd = nsnull;
mActiveTransportList[i] = nsnull;
}
mSelectFDSetCount -= 1;
rv = NS_OK;
break;
}
}
return rv;
}
//
// --------------------------------------------------------------------------
// nsISupports implementation...
// --------------------------------------------------------------------------
//
NS_IMPL_ADDREF(nsSocketTransportService);
NS_IMPL_RELEASE(nsSocketTransportService);
NS_IMETHODIMP
nsSocketTransportService::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsISocketTransportService::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = NS_STATIC_CAST(nsISocketTransportService*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIRunnable::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIRunnable*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
//
// --------------------------------------------------------------------------
// nsIRunnable implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportService::Run(void)
{
//
// Initialize the FDSET used by PR_Poll(...). The first item in the FDSet
// is *always* the pollable event (ie. mThreadEvent).
//
mSelectFDSet[0].fd = mThreadEvent;
mSelectFDSet[0].in_flags = PR_POLL_READ;
mSelectFDSetCount = 1;
while (mThreadRunning) {
PRInt32 count;
nsSocketTransport* transport;
// XXX: PR_Poll(...) needs a timeout value...
count = PR_Poll(mSelectFDSet, mSelectFDSetCount, PR_INTERVAL_NO_TIMEOUT);
/* One or more sockets has data... */
if (count > 0) {
nsresult rv;
int i;
/* Process any sockets with data first... */
for (i=mSelectFDSetCount-1; i>=1; i--) {
PRPollDesc* pfd;
PRInt16 out_flags;
pfd = &mSelectFDSet[i];
if (pfd->out_flags) {
// Clear the out_flags for next time...
out_flags = pfd->out_flags;
pfd->out_flags = 0;
transport = mActiveTransportList[i];
NS_ASSERTION(transport, "Null transport in active list...");
if (transport) {
rv = transport->Process(out_flags);
if (NS_BASE_STREAM_WOULD_BLOCK == rv) {
// Update the select flags...
pfd->in_flags = transport->GetSelectFlags();
}
//
// If the operation completed, then remove the entry from the
// select list...
//
else {
rv = RemoveFromSelectList(transport);
}
}
}
}
/* Process any pending operations on the mWorkQ... */
if (mSelectFDSet[0].out_flags) {
//
// Clear the pollable event... This call should *never* block since
// PR_Poll(...) said that it had been fired...
//
NS_ASSERTION(!(mSelectFDSet[0].out_flags & PR_POLL_EXCEPT),
"Exception on Pollable event.");
PR_WaitForPollableEvent(mThreadEvent);
rv = ProcessWorkQ();
}
}
/* PR_Poll(...) timeout... */
else if (count == 0) {
}
/* PR_Poll(...) error.. */
else {
}
}
return NS_OK;
}
//
// --------------------------------------------------------------------------
// nsISocketTransportService implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportService::CreateTransport(const char* aHost,
PRInt32 aPort,
nsIChannel** aResult)
{
nsresult rv = NS_OK;
nsSocketTransport* transport = nsnull;
// Parameter validation...
NS_ASSERTION(aResult, "aResult == nsnull.");
if (!aResult) {
return NS_ERROR_NULL_POINTER;
}
// Create and initialize a new connection object...
NS_NEWXPCOM(transport, nsSocketTransport);
if (transport) {
rv = transport->Init(this, aHost, aPort);
if (NS_FAILED(rv)) {
delete transport;
transport = nsnull;
}
}
else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
// Set the reference count to one...
if (NS_SUCCEEDED(rv)) {
NS_ADDREF(transport);
}
*aResult = transport;
return rv;
}
NS_IMETHODIMP
nsSocketTransportService::Shutdown(void)
{
PRStatus status;
nsresult rv = NS_OK;
if (mThread) {
//
// Clear the running flag and wake up the transport thread...
//
mThreadRunning = PR_FALSE;
status = PR_SetPollableEvent(mThreadEvent);
// XXX: what should happen if this fails?
NS_ASSERTION(PR_SUCCESS == status, "Unable to wake up the transport thread.");
// Wait for the transport thread to exit nsIRunnable::Run()
if (PR_SUCCESS == status) {
mThread->Join();
}
NS_RELEASE(mThread);
} else {
rv = NS_ERROR_FAILURE;
}
return rv;
}

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsSocketTransportService_h___
#define nsSocketTransportService_h___
#include "nspr.h"
#include "nsIThread.h"
#include "nsISocketTransportService.h"
#include "nsIInputStream.h"
// Forward declarations...
class nsSocketTransport;
class nsSocketTransportService : public nsISocketTransportService,
public nsIRunnable
{
public:
NS_DECL_ISUPPORTS
// nsISocketTransportService methods:
NS_IMETHOD CreateTransport(const char* aHost,
PRInt32 aPort,
nsIChannel** aResult);
NS_IMETHOD Shutdown(void);
// nsIRunnable methods:
NS_IMETHOD Run(void);
// nsSocketTransportService methods:
nsSocketTransportService();
virtual ~nsSocketTransportService();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsresult Init(void);
nsresult AddToWorkQ(nsSocketTransport* aTransport);
// The following methods are called by the transport thread...
nsresult ProcessWorkQ(void);
nsresult AddToSelectList(nsSocketTransport* aTransport);
nsresult RemoveFromSelectList(nsSocketTransport* aTransport);
protected:
nsIThread* mThread;
PRFileDesc* mThreadEvent;
PRLock* mThreadLock;
PRBool mThreadRunning;
PRCList mWorkQ;
PRInt32 mSelectFDSetCount;
PRPollDesc* mSelectFDSet;
nsSocketTransport** mActiveTransportList;
};
#endif /* nsSocketTransportService_h___ */

View File

@@ -0,0 +1,309 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "nsIBuffer.h"
//
// --------------------------------------------------------------------------
// Private implementation of a nsIBufferInputStream used by the
// nsSocketTransport implementation
// --------------------------------------------------------------------------
//
#if defined(XP_PC)
#include <windows.h> // Interlocked increment...
#endif
#include "nspr.h"
#include "nscore.h"
#include "nsSocketTransportStreams.h"
#include "nsSocketTransport.h"
#if defined(PR_LOGGING)
//
// Log module for SocketTransport logging...
//
// To enable logging (see prlog.h for full details):
//
// set NSPR_LOG_MODULES=nsSocketTransport:5
// set NSPR_LOG_FILE=nspr.log
//
// this enables PR_LOG_DEBUG level information and places all output in
// the file nspr.log
//
// gSocketLog is defined in nsSocketTransport.cpp
//
extern PRLogModuleInfo* gSocketLog;
#endif /* PR_LOGGING */
nsSocketTransportStream::nsSocketTransportStream()
{
NS_INIT_REFCNT();
mIsStreamBlocking = PR_FALSE;
mIsTransportSuspended = PR_FALSE;
mMonitor = nsnull;
mTransport = nsnull;
mBuffer = nsnull;
mStream = nsnull;
}
nsSocketTransportStream::~nsSocketTransportStream()
{
NS_IF_RELEASE(mTransport);
NS_IF_RELEASE(mStream);
NS_IF_RELEASE(mBuffer);
if (mMonitor) {
PR_DestroyMonitor(mMonitor);
mMonitor = nsnull;
}
}
nsresult nsSocketTransportStream::Init(nsSocketTransport* aTransport,
PRBool aBlockingFlag)
{
nsresult rv = NS_OK;
NS_ASSERTION(aTransport, "Null transport supplied.");
mIsStreamBlocking = aBlockingFlag;
mMonitor = PR_NewMonitor();
if (!mMonitor) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_SUCCEEDED(rv) && aTransport) {
mTransport = aTransport;
NS_ADDREF(mTransport);
} else {
rv = NS_ERROR_NULL_POINTER;
}
if (NS_SUCCEEDED(rv)) {
rv = NS_NewBuffer(&mBuffer, MAX_IO_BUFFER_SIZE/2, 2*MAX_IO_BUFFER_SIZE, nsnull);
}
if (NS_SUCCEEDED(rv)) {
rv = NS_NewBufferInputStream(&mStream, mBuffer);
}
return rv;
}
nsresult nsSocketTransportStream::BlockTransport(void)
{
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("nsSocketTransportStream::BlockTransport() [this=%x].\n", this));
//
// XXX: It would be nice to call mTransport->Suspend() here...
// Unfortunately, BlockTransport() is called within the transport lock.
// So, since NSPR locks are not re-enterent we must rely on the caller
// (ie. the transport) to suspend itself...
//
mIsTransportSuspended = PR_TRUE;
Unlock();
return NS_OK;
}
nsresult nsSocketTransportStream::FillStream(nsReadSegmentFun reader,
void* closure,
PRUint32 count,
PRUint32 *writeCount)
{
return mBuffer->WriteSegments(reader, closure, count, writeCount);
}
//
// --------------------------------------------------------------------------
// nsISupports implementation...
// --------------------------------------------------------------------------
//
NS_IMPL_THREADSAFE_ISUPPORTS(nsSocketTransportStream,
nsIBufferInputStream::GetIID());
//
// --------------------------------------------------------------------------
// nsIBaseStream implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportStream::Close()
{
return mStream->Close();
}
//
// --------------------------------------------------------------------------
// nsIInputStream implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportStream::GetLength(PRUint32 *aResult)
{
return mStream->GetLength(aResult);
}
NS_IMETHODIMP
nsSocketTransportStream::Read(char * aBuf, PRUint32 aCount,
PRUint32 *aReadCount)
{
nsresult rv;
// Enter the stream lock...
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("+++ Entering nsSocketTransportStream::Read() [this=%x].\t"
"aCount=%d\n",
this, aCount));
do {
rv = mStream->Read(aBuf, aCount, aReadCount);
if (mIsStreamBlocking && (NS_BASE_STREAM_WOULD_BLOCK == rv)) {
Wait();
} else {
break;
}
} while (1);
//
// If the transport is blocked waiting for room in the input stream, then
// resume it...
//
if (mIsTransportSuspended && (*aReadCount) ) {
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("nsSocketTransportStream::Read() [this=%x]. "
"Resuming transport [%x].\n",
this, mTransport));
mTransport->Resume();
mIsTransportSuspended = PR_FALSE;
}
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("--- Leaving nsSocketTransportStream::Read() [this=%x].\t"
"rv = %x. aReadCount=%d\n",
this, rv, *aReadCount));
// Leave the stream lock...
Unlock();
return rv;
}
//
// --------------------------------------------------------------------------
// nsIBufferInputStream implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportStream::GetBuffer(nsIBuffer* *result)
{
return mStream->GetBuffer(result);
}
NS_IMETHODIMP
nsSocketTransportStream::FillFrom(nsIInputStream* aStream,
PRUint32 aCount,
PRUint32 *aWriteCount)
{
nsresult rv;
// Enter the stream lock...
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("+++ Entering nsSocketTransportStream::Fill() [this=%x].\t"
"aCount=%d\n",
this, aCount));
rv = mStream->FillFrom(aStream, aCount, aWriteCount);
if (mIsStreamBlocking && (NS_BASE_STREAM_WOULD_BLOCK != rv)) {
Notify();
}
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("--- Leaving nsSocketTransportStream::Fill() [this=%x].\t"
"rv = %x. aWriteCount=%d\n",
this, rv, *aWriteCount));
// Leave the stream lock...
Unlock();
return rv;
}
NS_IMETHODIMP
nsSocketTransportStream::Fill(const char* aBuf,
PRUint32 aCount,
PRUint32 *aWriteCount)
{
nsresult rv;
// Enter the stream lock...
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("+++ Entering nsSocketTransportStream::Fill() [this=%x].\t"
"aCount=%d\n",
this, aCount));
rv = mStream->Fill(aBuf, aCount, aWriteCount);
if (mIsStreamBlocking && (NS_BASE_STREAM_WOULD_BLOCK != rv)) {
Notify();
}
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("--- Leaving nsSocketTransportStream::Fill() [this=%x].\t"
"rv = %x. aWriteCount=%d\n",
this, rv, *aWriteCount));
// Leave the stream lock...
Unlock();
return rv;
}

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 nsSocketTransportStreams_h___
#define nsSocketTransportStreams_h___
#include "prtypes.h"
#include "nsIBufferInputStream.h"
#include "nsIBuffer.h"
// Forward declarations...
class nsSocketTransport;
class nsSocketTransportStream : public nsIBufferInputStream
{
public:
nsSocketTransportStream();
// nsISupports methods:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close();
// nsIInputStream methods:
NS_IMETHOD GetLength(PRUint32 *aResult);
NS_IMETHOD Read(char * aBuf, PRUint32 aCount, PRUint32 *aReadCount);
// nsIBufferInputStream methods:
NS_IMETHOD GetBuffer(nsIBuffer* *result);
NS_IMETHOD Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
NS_IMETHOD FillFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval);
// nsSocketTransportStream methods:
nsresult Init(nsSocketTransport* aTransport, PRBool aBlockingFlag);
nsresult BlockTransport(void);
nsresult FillStream(nsReadSegmentFun reader, void* closure, PRUint32 count,
PRUint32 *writeCount);
void Lock(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_EnterMonitor(mMonitor); }
void Notify(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_Notify(mMonitor); }
void Wait(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_Wait(mMonitor, PR_INTERVAL_NO_TIMEOUT); }
void Unlock(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_ExitMonitor(mMonitor); }
protected:
virtual ~nsSocketTransportStream();
private:
PRBool mIsTransportSuspended;
PRBool mIsStreamBlocking;
PRMonitor* mMonitor;
nsIBuffer* mBuffer;
nsIBufferInputStream* mStream;
nsSocketTransport* mTransport;
};
#endif /* nsSocketTransportStreams_h___ */

View File

@@ -0,0 +1,663 @@
/* -*- 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 "nsStandardUrl.h"
#include "nscore.h"
#include "nsCRT.h"
#include "nsString.h"
#include "prmem.h"
#include "prprf.h"
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kThisStandardUrlImplementationCID,
NS_THIS_STANDARDURL_IMPLEMENTATION_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
// nsStandardURL methods:
nsStandardURL::nsStandardURL(nsISupports* outer)
: mScheme(nsnull),
mPreHost(nsnull),
mHost(nsnull),
mPort(-1),
mPath(nsnull),
mRef(nsnull),
mQuery(nsnull),
mSpec(nsnull)
{
NS_INIT_AGGREGATED(outer);
}
nsStandardURL::~nsStandardURL()
{
if (mScheme) delete[] mScheme;
if (mPreHost) delete[] mPreHost;
if (mHost) delete[] mHost;
if (mRef) delete[] mRef;
if (mQuery) delete[] mQuery;
if (mSpec) delete[] mSpec;
}
NS_IMPL_AGGREGATED(nsStandardURL);
NS_IMETHODIMP
nsStandardURL::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(kThisStandardUrlImplementationCID) || // used by Equals
aIID.Equals(nsIURL::GetIID()) ||
aIID.Equals(nsIURI::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = NS_STATIC_CAST(nsIURI*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
// nsIURI methods:
NS_IMETHODIMP
nsStandardURL::GetSpec(char* *result)
{
nsAutoString string;
// NS_LOCK_INSTANCE();
// XXX Special-case javascript: URLs for the moment.
// This code will go away when we actually start doing
// protocol-specific parsing.
if (PL_strcmp(mScheme, "javascript") == 0) {
string.SetString(mSpec);
} else if (PL_strcmp(mScheme, "about") == 0) {
string.SetString(mScheme);
string.Append(':');
string.Append(mPath);
} else {
string.SetLength(0);
string.Append(mScheme);
string.Append("://");
if (nsnull != mHost) {
string.Append(mHost);
if (0 < mPort) {
string.Append(':');
string.Append(mPort, 10);
}
}
string.Append(mPath);
if (nsnull != mRef) {
string.Append('#');
string.Append(mRef);
}
if (nsnull != mQuery) {
string.Append('?');
string.Append(mQuery);
}
}
// NS_UNLOCK_INSTANCE();
*result = string.ToNewCString();
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::SetSpec(char* aSpec)
{
return Parse(aSpec, this);
}
NS_IMETHODIMP
nsStandardURL::GetScheme(char* *result)
{
*result = mScheme;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::SetScheme(char* scheme)
{
mScheme = nsCRT::strdup(scheme);
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::GetPreHost(char* *result)
{
*result = mPreHost;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::SetPreHost(char* preHost)
{
mPreHost = nsCRT::strdup(preHost);
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::GetHost(char* *result)
{
*result = mHost;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::SetHost(char* host)
{
mHost = nsCRT::strdup(host);
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::GetPort(PRInt32 *result)
{
*result = mPort;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::SetPort(PRInt32 port)
{
mPort = port;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::GetPath(char* *result)
{
*result = mPath;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::SetPath(char* path)
{
mPath = nsCRT::strdup(path);
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::Equals(nsIURI* other, PRBool *result)
{
PRBool eq = PR_FALSE;
if (other) {
// NS_LOCK_INSTANCE();
nsStandardURL* otherUrl;
nsresult rv =
other->QueryInterface(kThisStandardUrlImplementationCID,
(void**)&otherUrl);
if (NS_SUCCEEDED(rv)) {
eq = PRBool((0 == PL_strcmp(mScheme, otherUrl->mScheme)) &&
(0 == PL_strcasecmp(mHost, otherUrl->mHost)) &&
(mPort == otherUrl->mPort) &&
(0 == PL_strcmp(mPath, otherUrl->mPath)));
NS_RELEASE(otherUrl);
}
// NS_UNLOCK_INSTANCE();
}
*result = eq;
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::Clone(nsIURI* *result)
{
nsStandardURL* url = new nsStandardURL(nsnull); // XXX outer?
if (url == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mScheme = nsCRT::strdup(mScheme);
if (url->mScheme == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mPreHost = nsCRT::strdup(mPreHost);
if (url->mPreHost == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mHost = nsCRT::strdup(mHost);
if (url->mHost == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mPort = mPort;
url->mPath = nsCRT::strdup(mPath);
if (url->mPath == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mRef = nsCRT::strdup(mRef);
if (url->mRef == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mQuery = nsCRT::strdup(mQuery);
if (url->mQuery == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
url->mSpec = nsCRT::strdup(mSpec);
if (url->mSpec == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
*result = url;
NS_ADDREF(url);
return NS_OK;
}
NS_IMETHODIMP
nsStandardURL::MakeAbsolute(const char *relativePart, char **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// XXX recode to use nsString api's
// XXX don't bother with port numbers
// XXX don't bother with ref's
// XXX null pointer checks are incomplete
nsresult
nsStandardURL::Parse(const char* spec, nsIURI* aBaseUrl)
{
// XXX hack!
nsString specStr(spec);
char* uProtocol = nsnull;
char* uHost = nsnull;
char* uFile = nsnull;
PRInt32 uPort;
if (nsnull != aBaseUrl) {
nsresult rslt = aBaseUrl->GetScheme(&uProtocol);
if (rslt != NS_OK) return rslt;
rslt = aBaseUrl->GetHost(&uHost);
if (rslt != NS_OK) return rslt;
rslt = aBaseUrl->GetPath(&uFile);
if (rslt != NS_OK) return rslt;
rslt = aBaseUrl->GetPort(&uPort);
if (rslt != NS_OK) return rslt;
}
// NS_LOCK_INSTANCE();
PR_FREEIF(mScheme);
PR_FREEIF(mHost);
PR_FREEIF(mPath);
PR_FREEIF(mRef);
PR_FREEIF(mQuery);
mPort = -1;
if (nsnull == spec) {
if (nsnull == aBaseUrl) {
// NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
}
mScheme = (nsnull != uProtocol) ? nsCRT::strdup(uProtocol) : nsnull;
mHost = (nsnull != uHost) ? nsCRT::strdup(uHost) : nsnull;
mPort = uPort;
mPath = (nsnull != uFile) ? nsCRT::strdup(uFile) : nsnull;
// NS_UNLOCK_INSTANCE();
return NS_OK;
}
// Strip out reference and search info
char* ref = strpbrk(spec, "#?");
if (nsnull != ref) {
char* search = nsnull;
if ('#' == *ref) {
search = PL_strchr(ref + 1, '?');
if (nsnull != search) {
*search++ = '\0';
}
PRIntn hashLen = nsCRT::strlen(ref + 1);
if (0 != hashLen) {
mRef = (char*) PR_Malloc(hashLen + 1);
PL_strcpy(mRef, ref + 1);
}
}
else {
search = ref + 1;
}
if (nsnull != search) {
// The rest is the search
PRIntn searchLen = nsCRT::strlen(search);
if (0 != searchLen) {
mQuery = (char*) PR_Malloc(searchLen + 1);
PL_strcpy(mQuery, search);
}
}
// XXX Terminate string at start of reference or search
*ref = '\0';
}
// The URL is considered absolute if and only if it begins with a
// protocol spec. A protocol spec is an alphanumeric string of 1 or
// more characters that is terminated with a colon.
PRBool isAbsolute = PR_FALSE;
const char* cp;
const char* ap = spec;
char ch;
while (0 != (ch = *ap)) {
if (((ch >= 'a') && (ch <= 'z')) ||
((ch >= 'A') && (ch <= 'Z')) ||
((ch >= '0') && (ch <= '9'))) {
ap++;
continue;
}
if ((ch == ':') && (ap - spec >= 2)) {
isAbsolute = PR_TRUE;
cp = ap;
break;
}
break;
}
if (!isAbsolute) {
// relative spec
if (nsnull == aBaseUrl) {
// NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
}
// keep protocol and host
mScheme = (nsnull != uProtocol) ? nsCRT::strdup(uProtocol) : nsnull;
mHost = (nsnull != uHost) ? nsCRT::strdup(uHost) : nsnull;
mPort = uPort;
// figure out file name
PRInt32 len = nsCRT::strlen(spec) + 1;
if ((len > 1) && (spec[0] == '/')) {
// Relative spec is absolute to the server
mPath = nsCRT::strdup(spec);
} else {
if (spec[0] != '\0') {
// Strip out old tail component and put in the new one
char* dp = PL_strrchr(uFile, '/');
if (!dp) {
// NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
}
PRInt32 dirlen = (dp + 1) - uFile;
mPath = (char*) PR_Malloc(dirlen + len);
PL_strncpy(mPath, uFile, dirlen);
PL_strcpy(mPath + dirlen, spec);
}
else {
mPath = nsCRT::strdup(uFile);
}
}
/* Stolen from netlib's mkparse.c.
*
* modifies a url of the form /foo/../foo1 -> /foo1
* and /foo/./foo1 -> /foo/foo1
*/
char *fwdPtr = mPath;
char *urlPtr = mPath;
for(; *fwdPtr != '\0'; fwdPtr++)
{
if(*fwdPtr == '/' && *(fwdPtr+1) == '.' && *(fwdPtr+2) == '/')
{
/* remove ./
*/
fwdPtr += 1;
}
else if(*fwdPtr == '/' && *(fwdPtr+1) == '.' && *(fwdPtr+2) == '.' &&
(*(fwdPtr+3) == '/' || *(fwdPtr+3) == '\0'))
{
/* remove foo/..
*/
/* reverse the urlPtr to the previous slash
*/
if(urlPtr != mPath)
urlPtr--; /* we must be going back at least one */
for(;*urlPtr != '/' && urlPtr != mPath; urlPtr--)
; /* null body */
/* forward the fwd_prt past the ../
*/
fwdPtr += 2;
}
else
{
/* copy the url incrementaly
*/
*urlPtr++ = *fwdPtr;
}
}
*urlPtr = '\0'; /* terminate the url */
// Now that we've resolved the relative URL, we need to reconstruct
// a URL spec from the components.
ReconstructSpec();
} else {
// absolute spec
PR_FREEIF(mSpec);
PRInt32 slen = specStr.Length();
mSpec = (char *) PR_Malloc(slen + 1);
specStr.ToCString(mSpec, slen+1);
// get protocol first
PRInt32 plen = cp - spec;
mScheme = (char*) PR_Malloc(plen + 1);
PL_strncpy(mScheme, spec, plen);
mScheme[plen] = 0;
cp++; // eat : in protocol
// skip over one, two or three slashes if it isn't about:
if (nsCRT::strcmp(mScheme, "about") != 0) {
if (*cp == '/') {
cp++;
if (*cp == '/') {
cp++;
if (*cp == '/') {
cp++;
}
}
} else {
// NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
}
}
#if defined(XP_UNIX) || defined (XP_MAC)
// Always leave the top level slash for absolute file paths under Mac and UNIX.
// The code above sometimes results in stripping all of slashes
// off. This only happens when a previously stripped url is asked to be
// parsed again. Under Win32 this is not a problem since file urls begin
// with a drive letter not a slash. This problem show's itself when
// nested documents such as iframes within iframes are parsed.
if (nsCRT::strcmp(mScheme, "file") == 0) {
if (*cp != '/') {
cp--;
}
}
#endif /* XP_UNIX */
const char* cp0 = cp;
if ((nsCRT::strcmp(mScheme, "resource") == 0) ||
(nsCRT::strcmp(mScheme, "file") == 0) ||
(nsCRT::strcmp(mScheme, "about") == 0)) {
// resource/file url's do not have host names.
// The remainder of the string is the file name
PRInt32 flen = nsCRT::strlen(cp);
mPath = (char*) PR_Malloc(flen + 1);
PL_strcpy(mPath, cp);
#ifdef NS_WIN32
if (nsCRT::strcmp(mScheme, "file") == 0) {
// If the filename starts with a "x|" where is an single
// character then we assume it's a drive name and change the
// vertical bar back to a ":"
if ((flen >= 2) && (mPath[1] == '|')) {
mPath[1] = ':';
}
}
#endif /* NS_WIN32 */
} else {
// Host name follows protocol for http style urls
cp = PL_strpbrk(cp, "/:");
if (nsnull == cp) {
// There is only a host name
PRInt32 hlen = nsCRT::strlen(cp0);
mHost = (char*) PR_Malloc(hlen + 1);
PL_strcpy(mHost, cp0);
}
else {
PRInt32 hlen = cp - cp0;
mHost = (char*) PR_Malloc(hlen + 1);
PL_strncpy(mHost, cp0, hlen);
mHost[hlen] = 0;
if (':' == *cp) {
// We have a port number
cp0 = cp+1;
cp = PL_strchr(cp, '/');
mPort = strtol(cp0, (char **)nsnull, 10);
}
}
if (nsnull == cp) {
// There is no file name
// Set filename to "/"
mPath = (char*) PR_Malloc(2);
mPath[0] = '/';
mPath[1] = 0;
}
else {
// The rest is the file name
PRInt32 flen = nsCRT::strlen(cp);
mPath = (char*) PR_Malloc(flen + 1);
PL_strcpy(mPath, cp);
}
}
}
// printf("protocol='%s' host='%s' file='%s'\n", mScheme, mHost, mPath);
// NS_UNLOCK_INSTANCE();
return NS_OK;
}
void
nsStandardURL::ReconstructSpec()
{
PR_FREEIF(mSpec);
char portBuffer[10];
if (-1 != mPort) {
PR_snprintf(portBuffer, 10, ":%d", mPort);
}
else {
portBuffer[0] = '\0';
}
PRInt32 plen = PL_strlen(mScheme) + PL_strlen(mHost) +
PL_strlen(portBuffer) + PL_strlen(mPath) + 4;
if (mRef) {
plen += 1 + PL_strlen(mRef);
}
if (mQuery) {
plen += 1 + PL_strlen(mQuery);
}
mSpec = (char *) PR_Malloc(plen + 1);
if (PL_strcmp(mScheme, "about") == 0) {
PR_snprintf(mSpec, plen, "%s:%s", mScheme, mPath);
} else {
PR_snprintf(mSpec, plen, "%s://%s%s%s",
mScheme, ((nsnull != mHost) ? mHost : ""), portBuffer,
mPath);
}
if (mRef) {
PL_strcat(mSpec, "#");
PL_strcat(mSpec, mRef);
}
if (mQuery) {
PL_strcat(mSpec, "?");
PL_strcat(mSpec, mQuery);
}
}
////////////////////////////////////////////////////////////////////////////////
// nsIURI methods:
NS_IMETHODIMP
nsStandardURL::GetDirectory(char * *aDirectory)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::SetDirectory(char * aDirectory)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::GetFileName(char * *aFileName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::SetFileName(char * aFileName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::GetQuery(char * *aQuery)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::SetQuery(char * aQuery)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::GetRef(char * *aRef)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStandardURL::SetRef(char * aRef)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
NS_METHOD
nsStandardURL::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsStandardURL* url = new nsStandardURL(aOuter);
if (url == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(url);
nsresult rv = url->QueryInterface(aIID, aResult);
NS_RELEASE(url);
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,118 @@
/* -*- 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 nsStandardUrl_h__
#define nsStandardUrl_h__
#include "nsIURL.h"
#include "nsAgg.h"
// XXX regenerate:
#define NS_THIS_STANDARDURL_IMPLEMENTATION_CID \
{ /* 905ed480-f11f-11d2-9322-000000000000 */ \
0x905ed480, \
0xf11f, \
0x11d2, \
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
}
class nsStandardURL : public nsIURI
{
public:
NS_DECL_AGGREGATED
////////////////////////////////////////////////////////////////////////////
// nsIURI methods:
/* attribute string Spec; */
NS_IMETHOD GetSpec(char * *aSpec);
NS_IMETHOD SetSpec(char * aSpec);
/* attribute string Scheme; */
NS_IMETHOD GetScheme(char * *aScheme);
NS_IMETHOD SetScheme(char * aScheme);
/* attribute string PreHost; */
NS_IMETHOD GetPreHost(char * *aPreHost);
NS_IMETHOD SetPreHost(char * aPreHost);
/* attribute string Host; */
NS_IMETHOD GetHost(char * *aHost);
NS_IMETHOD SetHost(char * aHost);
/* attribute long Port; */
NS_IMETHOD GetPort(PRInt32 *aPort);
NS_IMETHOD SetPort(PRInt32 aPort);
/* attribute string Path; */
NS_IMETHOD GetPath(char * *aPath);
NS_IMETHOD SetPath(char * aPath);
/* boolean Equals (in nsIURI other); */
NS_IMETHOD Equals(nsIURI *other, PRBool *_retval);
/* nsIURI Clone (); */
NS_IMETHOD Clone(nsIURI **_retval);
/* string MakeAbsolute (in string relativePart); */
NS_IMETHOD MakeAbsolute(const char *relativePart, char **_retval);
////////////////////////////////////////////////////////////////////////////
// nsIURI methods:
/* attribute string Directory; */
NS_IMETHOD GetDirectory(char * *aDirectory);
NS_IMETHOD SetDirectory(char * aDirectory);
/* attribute string FileName; */
NS_IMETHOD GetFileName(char * *aFileName);
NS_IMETHOD SetFileName(char * aFileName);
/* attribute string Query; */
NS_IMETHOD GetQuery(char * *aQuery);
NS_IMETHOD SetQuery(char * aQuery);
/* attribute string Ref; */
NS_IMETHOD GetRef(char * *aRef);
NS_IMETHOD SetRef(char * aRef);
////////////////////////////////////////////////////////////////////////////
// nsStandardURL methods:
nsStandardURL(nsISupports* outer);
virtual ~nsStandardURL();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
protected:
nsresult Parse(const char* spec, nsIURI* aBaseUrl);
void ReconstructSpec();
protected:
char* mScheme;
char* mPreHost;
char* mHost;
PRInt32 mPort;
char* mPath;
char* mRef;
char* mQuery;
char* mSpec; // XXX go away
};
#endif // nsStandardUrl_h__

View File

@@ -0,0 +1,174 @@
/* -*- 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 "nsIStreamListener.h"
#include "nsCRT.h"
#include "nsIBufferInputStream.h"
#include "nsIBufferOutputStream.h"
#include "nsIBuffer.h"
////////////////////////////////////////////////////////////////////////////////
class nsSyncStreamListener : public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
// nsIStreamObserver methods:
NS_IMETHOD OnStartBinding(nsISupports* context);
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg);
NS_IMETHOD OnStartRequest(nsISupports* context);
NS_IMETHOD OnStopRequest(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg);
// nsIStreamListener methods:
NS_IMETHOD OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength);
// nsSyncStreamListener methods:
nsSyncStreamListener()
: mOutputStream(nsnull) {
NS_INIT_REFCNT();
}
virtual ~nsSyncStreamListener();
nsresult Init(nsIBufferInputStream* *result);
nsIBufferOutputStream* GetOutputStream() { return mOutputStream; }
protected:
nsIBufferOutputStream* mOutputStream;
};
////////////////////////////////////////////////////////////////////////////////
#define NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE (4 * 1024)
#define NS_SYNC_STREAM_LISTENER_BUFFER_SIZE (32 * 1024)
nsresult
nsSyncStreamListener::Init(nsIBufferInputStream* *result)
{
nsresult rv;
nsIBufferInputStream* in;
rv = NS_NewPipe(&in, &mOutputStream, NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE,
NS_SYNC_STREAM_LISTENER_BUFFER_SIZE, PR_TRUE, nsnull);
if (NS_FAILED(rv)) return rv;
*result = in;
return NS_OK;
}
nsSyncStreamListener::~nsSyncStreamListener()
{
NS_IF_RELEASE(mOutputStream);
}
NS_IMPL_ADDREF(nsSyncStreamListener);
NS_IMPL_RELEASE(nsSyncStreamListener);
NS_IMETHODIMP
nsSyncStreamListener::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(nsIStreamListener::GetIID()) ||
aIID.Equals(nsIStreamObserver::GetIID()) ||
aIID.Equals(nsISupports::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIStreamListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsSyncStreamListener::OnStartBinding(nsISupports* context)
{
return NS_OK;
}
NS_IMETHODIMP
nsSyncStreamListener::OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
// XXX what do we do with the status and error message?
return mOutputStream->Close();
}
NS_IMETHODIMP
nsSyncStreamListener::OnStartRequest(nsISupports* context)
{
return NS_OK;
}
NS_IMETHODIMP
nsSyncStreamListener::OnStopRequest(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
// XXX what do we do with the status and error message?
return mOutputStream->Close();
}
NS_IMETHODIMP
nsSyncStreamListener::OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength)
{
nsresult rv;
PRUint32 amt;
PRInt32 count = (PRInt32)aLength;
while (count > 0) { // this should only go around once since the output stream is blocking
rv = mOutputStream->WriteFrom(aIStream, count, &amt);
if (NS_FAILED(rv)) return rv;
count -= amt;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
NS_NET nsresult
NS_NewSyncStreamListener(nsIBufferInputStream **inStream,
nsIBufferOutputStream **outStream,
nsIStreamListener **listener)
{
nsSyncStreamListener* l = new nsSyncStreamListener();
if (l == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = l->Init(inStream);
if (NS_FAILED(rv)) {
delete l;
return rv;
}
NS_ADDREF(l);
*listener = l;
*outStream = l->GetOutputStream();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,59 @@
# 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.
NODEPEND=1
IGNORE_MANIFEST = 1
MODULE = urltest
DEPTH= ..\..\..
MAKE_OBJ_TYPE=EXE
EXENAME=urltest
PDBFILE=nunettest.pdb
MAPFILE=nunettest.map
OBJS= \
.\$(OBJDIR)\urltest.obj \
$(NULL)
PROGRAM=.\$(OBJDIR)\$(EXENAME).EXE
LCFLAGS=-DNETSCAPE
LLIBS=$(LLIBS) \
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\nunet.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\plc3.lib
LINCS=$(LINCS) -I. \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\nunet \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\xpcom
# clobber and clobber_all will remove the following garbage:
GARBAGE = $(GARBAGE) _gen
include <$(DEPTH)/config/rules.mak>
install:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\$(EXENAME).exe

View File

@@ -0,0 +1,2 @@
These tests need to be cleaned up a lot. There is still left over
stuff from previous test. TODO -Gagan Saksena

View File

@@ -0,0 +1,316 @@
/* -*- 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.
*/
/*
TODO- big cleanup! -Gagan Saksena 03/25/99
*/
#include <stdio.h>
#include <assert.h>
#ifdef WIN32
#include <windows.h>
#endif
#include "plstr.h"
#include "nsIEventQueue.h"
#include "nsIComponentManager.h"
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsINetService.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsString.h"
#include "nsIURL.h"
#include "nsINetService.h"
#ifdef XP_PC
#define NETLIB_DLL "netlib.dll"
#define XPCOM_DLL "xpcom32.dll"
#else
#ifdef XP_MAC
#include "nsMacRepository.h"
#else
#define NETLIB_DLL "libnetlib.so"
#define XPCOM_DLL "libxpcom.so"
#endif
#endif
// Define CIDs...
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
// Define IIDs...
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
//NS_DEFINE_IID(kIPostToServerIID, NS_IPOSTTOSERVER_IID);
#ifdef XP_UNIX
extern "C" char *fe_GetConfigDir(void) {
printf("XXX: return /tmp for fe_GetConfigDir\n");
return strdup("/tmp");
}
#endif /* XP_UNIX */
#if 0 // Enable after the stream listener interface is cleared up.
class TestConsumer : public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
TestConsumer();
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info);
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 Progress, PRUint32 ProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length);
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg);
protected:
~TestConsumer();
};
TestConsumer::TestConsumer()
{
NS_INIT_REFCNT();
}
NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
NS_IMPL_ISUPPORTS(TestConsumer,kIStreamListenerIID);
TestConsumer::~TestConsumer()
{
if (bTraceEnabled) {
printf("\n+++ TestConsumer is being deleted...\n");
}
}
NS_IMETHODIMP TestConsumer::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info)
{
if (bTraceEnabled) {
printf("\n+++ TestConsumer::GetBindInfo: URL: %p\n", aURL);
}
return 0;
}
NS_IMETHODIMP TestConsumer::OnProgress(nsIURL* aURL, PRUint32 Progress,
PRUint32 ProgressMax)
{
if (bTraceEnabled) {
printf("\n+++ TestConsumer::OnProgress: URL: %p - %d of total %d\n", aURL, Progress, ProgressMax);
}
return 0;
}
NS_IMETHODIMP TestConsumer::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
{
if (bTraceEnabled) {
printf("\n+++ TestConsumer::OnStatus: ");
nsAutoString str(aMsg);
char* c = str.ToNewCString();
fputs(c, stdout);
free(c);
fputs("\n", stdout);
}
return 0;
}
NS_IMETHODIMP TestConsumer::OnStartBinding(nsIURL* aURL, const char *aContentType)
{
if (bTraceEnabled) {
printf("\n+++ TestConsumer::OnStartBinding: URL: %p, Content type: %s\n", aURL, aContentType);
}
return 0;
}
NS_IMETHODIMP TestConsumer::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length)
{
PRUint32 len;
if (bTraceEnabled) {
printf("\n+++ TestConsumer::OnDataAvailable: URL: %p, %d bytes available...\n", aURL, length);
}
do {
nsresult err;
char buffer[80];
PRUint32 i;
err = pIStream->Read(buffer, 0, 80, &len);
if (err == NS_OK) {
for (i=0; i<len; i++) {
putchar(buffer[i]);
}
}
} while (len > 0);
return 0;
}
NS_IMETHODIMP TestConsumer::OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg)
{
if (bTraceEnabled) {
printf("\n+++ TestConsumer::OnStopBinding... URL: %p status: %d\n", aURL, status);
}
if (NS_FAILED(status)) {
const char* url;
aURL->GetSpec(&url);
printf("Unable to load URL %s\n", url);
}
/* The document has been loaded, so drop out of the message pump... */
urlLoaded = 1;
return 0;
}
#endif // 0 - enabled after streamlistener is fixed.
nsresult ReadStreamSynchronously(nsIInputStream* aIn)
{
nsresult rv;
char buffer[1024];
if (nsnull != aIn) {
PRUint32 len;
do {
PRUint32 i;
rv = aIn->Read(buffer, sizeof(buffer), &len);
for (i=0; i<len; i++) {
putchar(buffer[i]);
}
} while (len > 0);
}
return NS_OK;
}
int testURL(const char* pURL=0);
int main(int argc, char **argv)
{
nsAutoString url_address;
// char buf[256];
// nsIStreamListener *pConsumer;
nsIEventQueueService* pEventQService;
// nsIURL *pURL;
nsresult result;
int i;
if (argc < 2) {
printf("urltest: <URL> \n");
return 0;
}
NS_InitXPCOM(nsnull);
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, "./components");
testURL(argv[1]);
return 0;
#if 0
nsRepository::RegisterComponent(
kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterComponent(
kNetServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
// Create the Event Queue for this thread...
pEventQService = nsnull;
result = nsServiceManager::GetService(kEventQueueServiceCID,
kIEventQueueServiceIID,
(nsISupports **)&pEventQService);
if (NS_SUCCEEDED(result)) {
// XXX: What if this fails?
result = pEventQService->CreateThreadEventQueue();
}
for (i=1; i < argc; i++) {
if (PL_strcasecmp(argv[i], "-all") == 0) {
testURL(0);
continue;
}
testURL(argv[i]);
}
if (nsnull != pEventQService) {
pEventQService->DestroyThreadEventQueue();
nsServiceManager::ReleaseService(kEventQueueServiceCID, pEventQService);
}
return 0;
#endif
}
int testURL(const char* i_pURL)
{
const char* temp;
if (i_pURL)
{
nsIURL* pURL = CreateURL(i_pURL);
pURL->DebugString(&temp);
cout << temp <<endl;
nsIInputStream* is = 0;
if (NS_OK == pURL->GetStream(&is))
{
ReadStreamSynchronously(is);
}
pURL->Release();
return 0;
}
const int tests = 8;
const char* url[tests] =
{
"http://username:password@hostname.com:80/pathname/./more/stuff/../path",
"username@host:8080/path",
"http://gagan/",
"host:port/netlib", //port should now be 0
"", //empty string
"mailbox:///foo", // No host specified path should be /foo
"user:pass@hostname.edu:80/pathname", //this is always user:pass and not http:user
"username:password@hostname:80/pathname"
};
for (int i = 0; i< tests; ++i)
{
nsIURL* pURL = CreateURL(url[i]);
pURL->DebugString(&temp);
cout << temp << endl;
pURL->Release();
}
return 0;
}

View File

@@ -0,0 +1,74 @@
# 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@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = netwerk
IS_COMPONENT = 1
MODULE = netwerk
CPPSRCS = \
nsNetFactory.cpp \
$(NULL)
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libnetwerkbase_s.a \
$(DIST)/lib/libnetwerkdns_s.a \
$(NULL)
LOCAL_INCLUDES += \
-I$(srcdir)/../base/src \
-I$(srcdir)/../dns/src \
$(NULL)
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
ifeq ($(OS_ARCH),HP-UX)
EXTRA_DSO_LDOPTS = -c objs/objslist
else
EXTRA_DSO_LDOPTS = \
$(MKSHLIB_FORCE_ALL) \
$(SHARED_LIBRARY_LIBS) \
$(MKSHLIB_UNFORCE_ALL) \
$(NULL)
endif
include $(DEPTH)/config/rules.mk
ifeq ($(OS_ARCH),HP-UX)
shared_library_objs: $(SHARED_LIBRARY_LIBS)
rm -rf objs
mkdir objs
(cd objs; for lib in $(SHARED_LIBRARY_LIBS); do ar xv ../$$lib; done) \
| awk '{ print "objs/"$$3 }' > objs/objslist
$(LIBRARY) $(SHARED_LIBRARY): shared_library_objs Makefile
else
$(LIBRARY) $(SHARED_LIBRARY): $(SHARED_LIBRARY_LIBS) Makefile
endif

View File

@@ -0,0 +1,55 @@
#!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
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
MAKE_OBJ_TYPE=DLL
DLLNAME=netwerk
DLL=.\$(OBJDIR)\$(DLLNAME).dll
CPP_OBJS= \
.\$(OBJDIR)\nsNetFactory.obj \
$(NULL)
LLIBS= \
$(DIST)\lib\netwerkbase_s.lib \
$(DIST)\lib\netwerkdns_s.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR)
MISCDEP=$(LLIBS)
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
-I$(DEPTH)\netwerk\base\src \
-I$(DEPTH)\netwerk\dns\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib

View File

@@ -0,0 +1,144 @@
/* -*- 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 "nsIOService.h"
#include "nsNetModuleMgr.h"
//#include "nsFileTransportService.h"
#include "nsSocketTransportService.h"
#include "nscore.h"
#include "nsStandardUrl.h"
#include "nsDnsService.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
//static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kExternalModuleManagerCID, NS_NETMODULEMGR_CID);
static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
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(kIOServiceCID)) {
rv = NS_NewGenericFactory(&fact, nsIOService::Create);
}
#if 0
else if (aClass.Equals(kFileTransportServiceCID)) {
rv = NS_NewGenericFactory(&fact, nsFileTransportService::Create);
}
#endif
else if (aClass.Equals(kSocketTransportServiceCID)) {
rv = NS_NewGenericFactory(&fact, nsSocketTransportService::Create);
}
else if (aClass.Equals(kStandardURLCID)) {
rv = NS_NewGenericFactory(&fact, nsStandardURL::Create);
}
else if (aClass.Equals(kExternalModuleManagerCID)) {
rv = NS_NewGenericFactory(&fact, nsNetModuleMgr::Create);
}
else if (aClass.Equals(kDNSServiceCID)) {
rv = NS_NewGenericFactory(&fact, nsDNSService::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(kIOServiceCID,
"Network Service",
"component://netscape/network/net-service",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
#if 0
rv = compMgr->RegisterComponent(kFileTransportServiceCID,
"File Transport Service",
"component://netscape/network/file-transport-service",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
#endif
rv = compMgr->RegisterComponent(kSocketTransportServiceCID,
"Socket Transport Service",
"component://netscape/network/socket-transport-service",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kStandardURLCID,
"Standard URL Implementation",
"component://netscape/network/standard-url",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kExternalModuleManagerCID,
"External Module Manager",
"component://netscape/network/net-extern-mod",
aPath, PR_TRUE, PR_TRUE);
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(kIOServiceCID, aPath);
if (NS_FAILED(rv)) return rv;
#if 0
rv = compMgr->UnregisterComponent(kFileTransportServiceCID, aPath);
if (NS_FAILED(rv)) return rv;
#endif
rv = compMgr->UnregisterComponent(kSocketTransportServiceCID, aPath);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kStandardURLCID, aPath);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kExternalModuleManagerCID, aPath);
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,33 @@
#! 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,27 @@
#!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
DIRS= \
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,42 @@
#!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_dns
XPIDLSRCS = \
nsIDNSListener.idl \
nsIDNSService.idl \
$(NULL)
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(DEPTH)/config/rules.mk

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 = ..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
XPIDL_MODULE = netwerk_dns
XPIDLSRCS = \
.\nsIDNSListener.idl \
.\nsIDNSService.idl \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,52 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
%{C++
#include "prnetdb.h"
typedef struct nsHostEnt
{
PRHostEnt hostEnt;
char buffer[PR_NETDB_BUF_SIZE];
} nsHostEnt;
%}
[ptr] native nsHostEntStar(nsHostEnt);
[scriptable, uuid(7686cef0-206e-11d3-9348-00104ba0fd40)]
interface nsIDNSListener : nsISupports
{
/**
* Notify the listener that we are about to lookup the requested hostname.
*/
void OnStartLookup(in nsISupports ctxt, in string hostname);
/**
* Notify the listener that we have found one or more addresses for the hostname.
*/
void OnFound(in nsISupports ctxt, in string hostname,
in nsHostEntStar entry);
/**
* Notify the listener that we the lookup has completed.
*/
void OnStopLookup(in nsISupports ctxt, in string hostname);
};

View File

@@ -0,0 +1,42 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
%{C++
#define NS_DNSSERVICE_CID \
{ /* 718e7c81-f8b8-11d2-b951-c80918051d3c */ \
0x718e7c81, \
0xf8b8, \
0x11d2, \
{ 0xb9, 0x51, 0xc8, 0x09, 0x18, 0x05, 0x1d, 0x3c } \
}
%}
interface nsIRequest;
interface nsIDNSListener;
[scriptable, uuid(598f2f80-206f-11d3-9348-00104ba0fd40)]
interface nsIDNSService : nsISupports
{
nsIRequest Lookup(in nsISupports ctxt, in string hostname,
in nsIDNSListener listener);
};

View File

@@ -0,0 +1,53 @@
# 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 = netwerkdns_s
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsDnsService.cpp \
$(NULL)
EXPORTS = \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = netwerk
include $(topsrcdir)/config/config.mk
MKSHLIB :=
# we don't want the shared lib, but we want to force the creation of a
# static l\ib.
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,44 @@
# 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 = ..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
LIBRARY_NAME=netwerkdns_s
CPP_OBJS = \
.\$(OBJDIR)\nsDnsService.obj \
$(NULL)
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,159 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDnsService.h"
#include "nsIDNSListener.h"
#include "nsIRequest.h"
#include "prnetdb.h"
////////////////////////////////////////////////////////////////////////////////
class nsDNSRequest;
class nsDNSLookup
{
public:
nsresult AddDNSRequest(nsDNSRequest* request);
const char* mHostName;
PRHostEnt mHostEntry; // NSPR or platform specific hostent?
PRIntn mCount;
PRBool mComplete;
PRIntn mIndex; // XXX - for round robin
void * mListenerQueue; // XXX - maintain a list of nsDNSRequests.
};
class nsDNSRequest : public nsIRequest
{
nsIDNSListener* mListener;
nsDNSLookup* mHostNameLookup;
// nsIRequest methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
};
////////////////////////////////////////////////////////////////////////////////
// nsDNSService methods:
nsDNSService::nsDNSService()
{
NS_INIT_REFCNT();
}
nsresult
nsDNSService::Init()
{
// initialize DNS cache (persistent?)
#if defined(XP_MAC)
// create Open Transport Service Provider for DNS Lookups
#elif defined(_WIN)
// create DNS EventHandler Window
#elif defined(XP_UNIX)
// XXXX - ?
#endif
return NS_OK;
}
nsDNSService::~nsDNSService()
{
// deallocate cache
#if defined(XP_MAC)
// deallocate Open Transport Service Provider
#elif defined(_WIN)
// dispose DNS EventHandler Window
#elif defined(XP_UNIX)
// XXXX - ?
#endif
}
NS_IMPL_ISUPPORTS(nsDNSService, nsIDNSService::GetIID());
NS_METHOD
nsDNSService::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
{
nsDNSService* ph = new nsDNSService();
if (ph == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(ph);
nsresult rv = ph->QueryInterface(aIID, aResult);
NS_RELEASE(ph);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIDNSService methods:
NS_IMETHODIMP
nsDNSService::Lookup(nsISupports* ctxt,
const char* hostname,
nsIDNSListener* listener,
nsIRequest* *DNSRequest)
{
nsresult rv;
PRStatus status;
nsHostEnt* hostentry;
/*
check cache for existing nsDNSLookup with matching hostname
call OnStartLookup
if (nsDNSLookup doesn't exist) {
create nsDNSLookup for this hostname
kick off DNS Lookup
}
if (nsDNSLookup already has at least one address) {
call OnFound
}
if (nsDNSLookup is already complete) {
call OnStopLookup
return null
}
create nsDNSRequest
queue nsDNSRequest on nsDNSLookup // XXXX - potential race condition here
return nsDNSRequest
*/
// temporary SYNC version
hostentry = new nsHostEnt;
if (!hostentry)
return NS_ERROR_OUT_OF_MEMORY;
rv = listener->OnStartLookup(ctxt, hostname);
status = PR_GetHostByName(hostname, hostentry->buffer, PR_NETDB_BUF_SIZE, &hostentry->hostEnt);
if (PR_SUCCESS == status)
rv = listener->OnFound(ctxt, hostname, hostentry); // turn ownership of hostentry over to listener?
else
delete hostentry;
rv = listener->OnStopLookup(ctxt, hostname);
return NS_OK;
}

View File

@@ -0,0 +1,67 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDNSService_h__
#define nsDNSService_h__
#include "nsIDNSService.h"
#ifdef XP_PC
#include <windows.h>
#endif
class nsIDNSListener;
class nsICancelable;
class nsDNSService : public nsIDNSService
{
public:
NS_DECL_ISUPPORTS
// nsDNSService methods:
nsDNSService();
virtual ~nsDNSService();
nsresult Init();
// Define a Create method to be used with a factory:
static NS_METHOD
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
// nsIDNSService methods:
NS_IMETHOD Lookup(nsISupports *ctxt,
const char *hostname,
nsIDNSListener *listener,
nsIRequest **result);
protected:
// nsDNSLookup cache? - list of nsDNSLookups
#if defined(XP_MAC)
InetSvcRef mServiceRef;
#elif defined(XP_UNIX)
//XXX - to be defined
#elif defined(_WIN32)
WNDCLASS wc;
HWND DNSWindow;
UINT msgAsyncSelect;
UINT msgFoundDNS;
#endif
};
#endif /* nsDNSService_h__ */

37
mozilla/netwerk/gen-makefile.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/sh
# Relative location of |makefiles|
MODULE_DIR="mozilla/netwerk"
# Name of module
MODULE=`basename $MODULE_DIR`
# Depth of module from topsrcdir
MODULE_DEPTH=`echo $MODULE_DIR | sed -e 's|[^/]||g' -e 's|/|../|g' -e 's|/$||'`
# Relative directory script was run from
RUN_DIR=`echo $PWD | sed -e 's|.*\('$MODULE_DIR'\)$|\1|'`
if [ -z "$RUN_DIR" -o "$RUN_DIR" != "$MODULE_DIR" ]
then
echo
echo "This script needs to be run from $MODULE_DIR"
echo
exit -1
fi
if [ -n "$MODULE_DEPTH" ]
then
cd $MODULE_DEPTH
fi
if [ -f config.status ]
then
CONFIG_FILES=`cat $MODULE/makefiles` ./config.status
else
echo
echo "Missing config.status in $PWD"
echo "Have you run ./configure yet?"
echo
exit -1
fi

View File

@@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Defining the following causes NS_NET to be defined as NS_EXPORT. */
#define _IMPL_NS_NET
#include "MacSharedPrefix.h"

View File

@@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Defining the following causes NS_NET to be defined as NS_EXPORT. */
#define _IMPL_NS_NET
#include "MacSharedPrefix_debug.h"

Binary file not shown.

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.
DEPTH = ..
MODULE = netwerk
DIRS= \
base \
dns \
build \
protocol \
test \
$(NULL)
include <$(DEPTH)\config\rules.mak>

21
mozilla/netwerk/makefiles Normal file
View File

@@ -0,0 +1,21 @@
netwerk/Makefile
netwerk/base/Makefile
netwerk/base/public/Makefile
netwerk/base/src/Makefile
netwerk/dns/Makefile
netwerk/dns/public/Makefile
netwerk/dns/src/Makefile
netwerk/build/Makefile
netwerk/protocol/Makefile
netwerk/protocol/file/Makefile
netwerk/protocol/file/public/Makefile
netwerk/protocol/file/src/Makefile
netwerk/protocol/ftp/Makefile
netwerk/protocol/ftp/public/Makefile
netwerk/protocol/ftp/src/Makefile
netwerk/protocol/http/Makefile
netwerk/protocol/http/public/Makefile
netwerk/protocol/http/src/Makefile
netwerk/protocol/resource/Makefile
netwerk/protocol/resource/src/Makefile
netwerk/test/Makefile

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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
MODULE = netwerk
include $(DEPTH)/config/autoconf.mk
DIRS= \
file \
resource \
ftp \
http \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,33 @@
#! 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,42 @@
#!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 \
nsIFileProtocolHandler.idl \
$(NULL)
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,36 @@
#!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 = ..\..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
XPIDL_MODULE = netwerk_file
XPIDLSRCS = \
.\nsIFileChannel.idl \
.\nsIFileProtocolHandler.idl \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,122 @@
/* -*- 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"
interface nsISimpleEnumerator;
[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 an enumeration of the elements in a directory. Each
* element in the enumeration is an nsIFileChannel.
* @return NS_ERROR_FAILURE if the current nsIFileChannel does
* not specify a directory.
*/
readonly attribute nsISimpleEnumerator Children;
/**
* 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 rename 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);
/**
* Executes a program specified by the file channel.
* @param args - The program arguments to run with. If not specified,
* the Query portion of the URI is used as the argument string.
*/
void Execute(in string args);
};

View File

@@ -0,0 +1,26 @@
/* -*- 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 "nsIProtocolHandler.idl"
interface nsIFileChannel;
interface nsIFileProtocolHandler : nsIProtocolHandler
{
nsIFileChannel NewChannelFromNativePath(in string nativePath);
};

View File

@@ -0,0 +1,47 @@
# 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
LIBRARY_NAME = fileprotocol
IS_COMPONENT = 1
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsFileChannel.cpp \
nsFileProtocolHandler.cpp \
nsFileProtocolFactory.cpp \
$(NULL)
REQUIRES = xpcom netwerk raptor
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
TARGET = $(LIBARY)
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,61 @@
#!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
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
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
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
$(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,843 @@
/* -*- 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"
#include "nsIEventSinkGetter.h"
#include "nsIURI.h"
#include "nsIEventQueue.h"
#include "nsIStreamListener.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsFileProtocolHandler.h"
#include "nsIBuffer.h"
#include "nsIBufferInputStream.h"
#include "nsIBufferOutputStream.h"
#include "nsAutoLock.h"
#include "netCore.h"
#include "nsIFileStream.h"
#include "nsISimpleEnumerator.h"
#include "nsIURL.h"
#include "prio.h"
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
nsFileChannel::nsFileChannel()
: mURI(nsnull), mGetter(nsnull), mListener(nsnull), mEventQueue(nsnull),
mContext(nsnull), mState(QUIESCENT),
mSuspended(PR_FALSE), mFileStream(nsnull),
mBufferInputStream(nsnull), mBufferOutputStream(nsnull),
mStatus(NS_OK), mHandler(nsnull), mSourceOffset(0)
{
NS_INIT_REFCNT();
}
nsresult
nsFileChannel::Init(nsFileProtocolHandler* handler,
const char* verb, nsIURI* uri, nsIEventSinkGetter* getter,
nsIEventQueue* queue)
{
nsresult rv;
mHandler = handler;
NS_ADDREF(mHandler);
mGetter = getter;
NS_IF_ADDREF(mGetter);
mLock = PR_NewLock();
if (mLock == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
if (getter) {
rv = getter->GetEventSink(verb, nsIStreamListener::GetIID(), (nsISupports**)&mListener);
// ignore the failure -- we can live without having an event sink
}
mURI = uri;
NS_ADDREF(mURI);
// XXX temporary, until we integrate more thoroughly with nsFileSpec
char* url;
rv = mURI->GetSpec(&url);
if (NS_FAILED(rv)) return rv;
nsFileURL fileURL(url);
nsCRT::free(url);
mSpec = fileURL;
mEventQueue = queue;
NS_IF_ADDREF(mEventQueue);
return NS_OK;
}
nsFileChannel::~nsFileChannel()
{
NS_IF_RELEASE(mURI);
NS_IF_RELEASE(mGetter);
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mEventQueue);
NS_IF_RELEASE(mContext);
NS_IF_RELEASE(mHandler);
NS_ASSERTION(mFileStream == nsnull, "channel not closed");
NS_ASSERTION(mBufferInputStream == nsnull, "channel not closed");
NS_ASSERTION(mBufferOutputStream == nsnull, "channel not closed");
if (mLock)
PR_DestroyLock(mLock);
}
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(kISupportsIID)) {
*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 nsIRequest
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::Cancel()
{
nsAutoLock lock(mLock);
nsresult rv = NS_OK;
mStatus = NS_BINDING_ABORTED;
if (mSuspended) {
Resume();
}
mState = ENDING;
return rv;
}
NS_IMETHODIMP
nsFileChannel::Suspend()
{
nsAutoLock lock(mLock);
nsresult rv = NS_OK;
if (!mSuspended) {
// XXX close the stream here?
mStatus = mHandler->Suspend(this);
mSuspended = PR_TRUE;
}
return rv;
}
NS_IMETHODIMP
nsFileChannel::Resume()
{
nsAutoLock lock(mLock);
nsresult rv = NS_OK;
if (!mSuspended) {
// XXX re-open the stream and seek here?
mStatus = mHandler->Resume(this);
mSuspended = PR_FALSE;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////
class nsAsyncOutputStream : public nsIBufferOutputStream {
public:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close() {
return mOutputStream->Close();
}
// nsIOutputStream methods:
NS_IMETHOD Write(const char *buf, PRUint32 count, PRUint32 *writeCount) {
nsresult rv;
rv = mOutputStream->Write(buf, count, writeCount);
if (NS_FAILED(rv)) return rv;
rv = mListener->OnDataAvailable(mContext, mInputStream, mOffset, *writeCount);
mOffset += *writeCount;
return rv;
}
NS_IMETHOD Flush() {
return mOutputStream->Flush();
}
// nsIBufferOutputStream methods:
NS_IMETHOD GetBuffer(nsIBuffer * *aBuffer) {
return mOutputStream->GetBuffer(aBuffer);
}
NS_IMETHOD WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *writeCount) {
nsresult rv;
rv = mOutputStream->WriteFrom(inStr, count, writeCount);
if (NS_FAILED(rv)) return rv;
rv = mListener->OnDataAvailable(mContext, mInputStream, mOffset, *writeCount);
mOffset += *writeCount;
return rv;
}
nsAsyncOutputStream()
: mContext(nsnull), mListener(nsnull), mInputStream(nsnull),
mOutputStream(nsnull), mOffset(0)
{
NS_INIT_REFCNT();
}
nsresult Init(nsISupports* context, nsIStreamListener* listener,
PRUint32 growBySize, PRUint32 maxSize) {
nsresult rv;
rv = NS_NewPipe(&mInputStream, &mOutputStream,
growBySize, maxSize, PR_TRUE, nsnull);
if (NS_FAILED(rv)) return rv;
mContext = context;
NS_IF_ADDREF(mContext);
mListener = listener;
NS_ADDREF(mListener);
return rv;
}
virtual ~nsAsyncOutputStream() {
NS_IF_RELEASE(mContext);
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mInputStream);
NS_IF_RELEASE(mOutputStream);
}
static NS_METHOD Create(nsIBufferInputStream* *inStr,
nsIBufferOutputStream* *outStr,
nsISupports* context, nsIStreamListener* listener,
PRUint32 growBySize, PRUint32 maxSize) {
nsAsyncOutputStream* str = new nsAsyncOutputStream();
if (str == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(str);
nsresult rv = str->Init(context, listener, growBySize, maxSize);
if (NS_FAILED(rv)) {
NS_RELEASE(str);
return rv;
}
*inStr = str->mInputStream;
NS_ADDREF(*inStr);
*outStr = str;
return NS_OK;
}
protected:
nsISupports* mContext;
nsIStreamListener* mListener;
nsIBufferInputStream* mInputStream;
nsIBufferOutputStream* mOutputStream;
PRUint32 mOffset;
};
NS_IMPL_ISUPPORTS(nsAsyncOutputStream, nsIBufferOutputStream::GetIID());
////////////////////////////////////////////////////////////////////////////////
// From nsIChannel
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::GetURI(nsIURI * *aURI)
{
*aURI = mURI;
NS_ADDREF(mURI);
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
nsIInputStream **result)
{
nsAutoLock lock(mLock);
nsresult rv;
if (mState != QUIESCENT)
return NS_ERROR_IN_PROGRESS;
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
NS_FILE_TRANSPORT_SEGMENT_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE, PR_TRUE, nsnull);
// rv = serv->NewSyncStreamListener(&mBufferInputStream, &mBufferOutputStream, &mListener);
if (NS_FAILED(rv)) return rv;
mState = START_READ;
mSourceOffset = startPosition;
mAmount = readCount;
mListener = nsnull;
rv = mHandler->DispatchRequest(this);
if (NS_FAILED(rv)) return rv;
*result = mBufferInputStream;
NS_ADDREF(*result);
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **result)
{
nsAutoLock lock(mLock);
nsresult rv;
if (mState != QUIESCENT)
return NS_ERROR_IN_PROGRESS;
#if 0
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsIStreamListener* syncListener;
nsIBufferInputStream* inStr;
nsIBufferOutputStream* outStr;
rv = serv->NewSyncStreamListener(&inStr, &outStr, &syncListener);
if (NS_FAILED(rv)) return rv;
mListener = syncListener;
mOutputStream = outStr;
mState = START_READ;
mSourceOffset = startPosition;
mAmount = readCount;
rv = mHandler->DispatchRequest(this);
if (NS_FAILED(rv)) {
NS_RELEASE(inStr);
return rv;
}
*result = inStr;
#else
NS_ASSERTION(startPosition == 0, "implement startPosition");
nsISupports* str;
rv = NS_NewTypicalOutputFileStream(&str, mSpec);
if (NS_FAILED(rv)) return rv;
rv = str->QueryInterface(nsIOutputStream::GetIID(), (void**)result);
NS_RELEASE(str);
return rv;
#endif
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener)
{
nsAutoLock lock(mLock);
nsresult rv;
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = serv->NewAsyncStreamListener(listener, eventQueue, &mListener);
if (NS_FAILED(rv)) return rv;
rv = nsAsyncOutputStream::Create(&mBufferInputStream,
&mBufferOutputStream,
ctxt, mListener,
NS_FILE_TRANSPORT_SEGMENT_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(rv)) return rv;
mContext = ctxt;
NS_IF_ADDREF(mContext);
mState = START_READ;
mSourceOffset = startPosition;
mAmount = readCount;
rv = mHandler->DispatchRequest(this);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::AsyncWrite(nsIInputStream *fromStream,
PRUint32 startPosition, PRInt32 writeCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamObserver *observer)
{
nsAutoLock lock(mLock);
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRunnable methods:
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::Run(void)
{
while (mState != QUIESCENT && !mSuspended) {
Process();
}
return NS_OK;
}
static NS_METHOD
nsWriteToFile(void* closure,
const char* fromRawSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount)
{
nsIOutputStream* outStr = (nsIOutputStream*)closure;
nsresult rv = outStr->Write(fromRawSegment, count, writeCount);
return rv;
}
void
nsFileChannel::Process(void)
{
nsAutoLock lock(mLock);
switch (mState) {
case START_READ: {
nsISupports* fs;
NS_ASSERTION(mSourceOffset == 0, "implement seek");
if (mListener) {
mStatus = mListener->OnStartBinding(mContext); // always send the start notification
if (NS_FAILED(mStatus)) goto error;
}
mStatus = NS_NewTypicalInputFileStream(&fs, mSpec);
if (NS_FAILED(mStatus)) goto error;
mStatus = fs->QueryInterface(nsIInputStream::GetIID(), (void**)&mFileStream);
NS_RELEASE(fs);
if (NS_FAILED(mStatus)) goto error;
mState = READING;
break;
}
case READING: {
if (NS_FAILED(mStatus)) goto error;
nsIInputStream* fileStr = NS_STATIC_CAST(nsIInputStream*, mFileStream);
PRUint32 inLen;
mStatus = fileStr->GetLength(&inLen);
if (NS_FAILED(mStatus)) goto error;
PRUint32 amt;
mStatus = mBufferOutputStream->WriteFrom(fileStr, inLen, &amt);
if (NS_FAILED(mStatus)) goto error;
// and feed the buffer to the application via the buffer stream:
if (mListener) {
mStatus = mListener->OnDataAvailable(mContext, mBufferInputStream, mSourceOffset, amt);
if (NS_FAILED(mStatus)) goto error;
}
mSourceOffset += amt;
// stay in the READING state
break;
}
case START_WRITE: {
nsISupports* fs;
if (mListener) {
mStatus = mListener->OnStartBinding(mContext); // always send the start notification
if (NS_FAILED(mStatus)) goto error;
}
mStatus = NS_NewTypicalOutputFileStream(&fs, mSpec);
if (NS_FAILED(mStatus)) goto error;
mStatus = fs->QueryInterface(nsIOutputStream::GetIID(), (void**)&mFileStream);
NS_RELEASE(fs);
if (NS_FAILED(mStatus)) goto error;
mState = WRITING;
break;
}
case WRITING: {
if (NS_FAILED(mStatus)) goto error;
#if 0
PRUint32 amt;
mStatus = mBuffer->ReadSegments(nsWriteToFile, mFileStream, (PRUint32)-1, &amt);
if (mStatus == NS_BASE_STREAM_EOF) goto error;
if (NS_FAILED(mStatus)) goto error;
nsAutoCMonitor mon(mBuffer);
mon.Notify();
mSourceOffset += amt;
#endif
// stay in the WRITING state
break;
}
case ENDING: {
mBufferOutputStream->Flush();
if (mListener) {
// XXX where do we get the error message?
(void)mListener->OnStopBinding(mContext, mStatus, nsnull);
}
NS_IF_RELEASE(mBufferOutputStream);
mBufferOutputStream = nsnull;
NS_IF_RELEASE(mBufferInputStream);
mBufferInputStream = nsnull;
NS_IF_RELEASE(mFileStream);
mFileStream = nsnull;
NS_IF_RELEASE(mContext);
mContext = nsnull;
mState = QUIESCENT;
break;
}
case QUIESCENT: {
NS_NOTREACHED("trying to continue a quiescent file transfer");
break;
}
}
return;
error:
mState = ENDING;
return;
}
////////////////////////////////////////////////////////////////////////////////
// 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)
{
nsFileSpec::TimeStamp date;
mSpec.GetModDate(date);
LL_I2L(*aModDate, date);
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::GetFileSize(PRUint32 *aFileSize)
{
*aFileSize = mSpec.GetFileSize();
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::GetParent(nsIFileChannel * *aParent)
{
nsresult rv;
nsFileSpec parentSpec;
mSpec.GetParent(parentSpec);
nsFileURL parentURL(parentSpec);
const char* urlStr = parentURL.GetURLString();
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsIChannel* channel;
rv = serv->NewChannel("load", // XXX what should this be?
urlStr, nsnull,
mGetter, &channel);
if (NS_FAILED(rv)) return rv;
// this cast is safe because nsFileURL::GetURLString aways
// returns file: strings, and consequently we'll make nsIFileChannel
// objects from them:
*aParent = NS_STATIC_CAST(nsIFileChannel*, channel);
return NS_OK;
}
class nsDirEnumerator : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS
nsDirEnumerator() : mHandler(nsnull), mDir(nsnull), mNext(nsnull) {
NS_INIT_REFCNT();
}
nsresult Init(nsFileProtocolHandler* handler, nsFileSpec& spec) {
const char* path = spec.GetNativePathCString();
mDir = PR_OpenDir(path);
if (mDir == nsnull) // not a directory?
return NS_ERROR_FAILURE;
mHandler = handler;
NS_ADDREF(mHandler);
return NS_OK;
}
NS_IMETHOD HasMoreElements(PRBool *result) {
nsresult rv;
if (mNext == nsnull && mDir) {
PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH);
if (entry == nsnull) {
// end of dir entries
PRStatus status = PR_CloseDir(mDir);
if (status != PR_SUCCESS)
return NS_ERROR_FAILURE;
mDir = nsnull;
*result = PR_FALSE;
return NS_OK;
}
const char* path = entry->name;
rv = mHandler->NewChannelFromNativePath(path, &mNext);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(mNext, "NewChannel failed");
}
*result = mNext != nsnull;
return NS_OK;
}
NS_IMETHOD GetNext(nsISupports **result) {
nsresult rv;
PRBool hasMore;
rv = HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
*result = mNext; // might return nsnull
mNext = nsnull;
return NS_OK;
}
virtual ~nsDirEnumerator() {
if (mDir) {
PRStatus status = PR_CloseDir(mDir);
NS_ASSERTION(status == PR_SUCCESS, "close failed");
}
NS_IF_RELEASE(mHandler);
NS_IF_RELEASE(mNext);
}
protected:
nsFileProtocolHandler* mHandler;
PRDir* mDir;
nsIFileChannel* mNext;
};
NS_IMPL_ISUPPORTS(nsDirEnumerator, nsISimpleEnumerator::GetIID());
NS_IMETHODIMP
nsFileChannel::GetChildren(nsISimpleEnumerator * *aChildren)
{
nsresult rv;
PRBool isDir;
rv = IsDirectory(&isDir);
if (NS_FAILED(rv)) return rv;
if (!isDir)
return NS_ERROR_FAILURE;
nsDirEnumerator* dirEnum = new nsDirEnumerator();
if (dirEnum == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(dirEnum);
rv = dirEnum->Init(mHandler, mSpec);
if (NS_FAILED(rv)) {
NS_RELEASE(dirEnum);
return rv;
}
*aChildren = dirEnum;
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::GetNativePath(char * *aNativePath)
{
char* nativePath = nsCRT::strdup(mSpec.GetNativePathCString());
if (nativePath == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
*aNativePath = nativePath;
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::Exists(PRBool *result)
{
*result = mSpec.Exists();
return NS_OK;
}
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* fc;
rv = src->QueryInterface(nsIFileChannel::GetIID(), (void**)&fc);
if (NS_SUCCEEDED(rv)) {
rv = fc->moveToDir(this);
NS_RELEASE(fc);
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* fc;
rv = src->QueryInterface(nsIFileChannel::GetIID(), (void**)&fc);
if (NS_SUCCEEDED(rv)) {
rv = fc->copyToDir(this);
NS_RELEASE(fc);
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 *result)
{
*result = mSpec.IsDirectory();
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::IsFile(PRBool *result)
{
*result = mSpec.IsFile();
return NS_OK;
}
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;
}
NS_IMETHODIMP
nsFileChannel::Execute(const char *args)
{
nsresult rv;
char* queryArgs = nsnull;
if (args == nsnull) {
nsIURL* url;
rv = mURI->QueryInterface(nsIURL::GetIID(), (void**)&url);
if (NS_SUCCEEDED(rv)) {
rv = url->GetQuery(&queryArgs);
NS_RELEASE(url);
if (NS_FAILED(rv)) return rv;
args = queryArgs;
}
}
rv = mSpec.Execute(args);
if (queryArgs)
nsCRT::free(queryArgs);
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,183 @@
/* -*- 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"
#include "nsIThread.h"
#include "nsFileSpec.h"
#include "prlock.h"
class nsIEventSinkGetter;
class nsIStreamListener;
class nsFileProtocolHandler;
class nsIBaseStream;
class nsIBuffer;
class nsIBufferInputStream;
class nsIBufferOutputStream;
class nsFileChannel : public nsIFileChannel, public nsIRunnable {
public:
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////
// from nsIRequest:
/* void Cancel (); */
NS_IMETHOD Cancel();
/* void Suspend (); */
NS_IMETHOD Suspend();
/* void Resume (); */
NS_IMETHOD Resume();
////////////////////////////////////////////////////////////////////////////
// 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);
////////////////////////////////////////////////////////////////////////////
// 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 nsISimpleEnumerator Children; */
NS_IMETHOD GetChildren(nsISimpleEnumerator * *aChildren);
/* 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);
/* void Execute (in string args); */
NS_IMETHOD Execute(const char *args);
////////////////////////////////////////////////////////////////////////////
// nsIRunnable methods:
NS_IMETHOD Run(void);
////////////////////////////////////////////////////////////////////////////
// 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(nsFileProtocolHandler* handler,
const char* verb, nsIURI* uri, nsIEventSinkGetter* getter,
nsIEventQueue* queue);
void Process(void);
enum State {
QUIESCENT,
START_READ,
READING,
START_WRITE,
WRITING,
ENDING
};
protected:
nsIURI* mURI;
nsIEventSinkGetter* mGetter; // XXX it seems wrong keeping this -- used by GetParent
nsIStreamListener* mListener;
nsIEventQueue* mEventQueue;
nsFileSpec mSpec;
nsISupports* mContext;
nsFileProtocolHandler* mHandler;
State mState;
PRBool mSuspended;
// state variables:
nsIBaseStream* mFileStream; // cast to nsIInputStream/nsIOutputStream for reading/Writing
nsIBufferInputStream* mBufferInputStream;
nsIBufferOutputStream* mBufferOutputStream;
nsresult mStatus;
PRUint32 mSourceOffset;
PRInt32 mAmount;
private:
PRLock* mLock;
};
#define NS_FILE_TRANSPORT_SEGMENT_SIZE (4*1024)
#define NS_FILE_TRANSPORT_BUFFER_SIZE (32*1024)
#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,236 @@
/* -*- 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"
#include "nsIThread.h"
#include "nsISupportsArray.h"
#include "nsFileSpec.h"
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
////////////////////////////////////////////////////////////////////////////////
nsFileProtocolHandler::nsFileProtocolHandler()
: mPool(nsnull), mSuspended(nsnull)
{
NS_INIT_REFCNT();
}
#define NS_FILE_TRANSPORT_WORKER_STACK_SIZE (8*1024)
nsresult
nsFileProtocolHandler::Init()
{
nsresult rv;
rv = NS_NewThreadPool(&mPool, NS_FILE_TRANSPORT_WORKER_COUNT,
NS_FILE_TRANSPORT_WORKER_COUNT,
NS_FILE_TRANSPORT_WORKER_STACK_SIZE);
return rv;
}
nsFileProtocolHandler::~nsFileProtocolHandler()
{
// this will wait for all outstanding requests to be processed, then
// join with the worker threads, and finally free the pool:
NS_IF_RELEASE(mPool);
NS_IF_RELEASE(mSuspended);
}
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->Init();
if (NS_SUCCEEDED(rv)) {
rv = ph->QueryInterface(aIID, aResult);
}
NS_RELEASE(ph);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
NS_IMETHODIMP
nsFileProtocolHandler::GetScheme(char* *result)
{
*result = nsCRT::strdup("file");
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::GetDefaultPort(PRInt32 *result)
{
*result = -1; // no port for file: URLs
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;
// file: 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;
}
*result = url;
return rv;
}
NS_IMETHODIMP
nsFileProtocolHandler::NewChannel(const char* verb, nsIURI* url,
nsIEventSinkGetter* eventSinkGetter,
nsIEventQueue* eventQueue,
nsIChannel* *result)
{
nsresult rv;
nsFileChannel* channel;
rv = nsFileChannel::Create(nsnull, nsIFileChannel::GetIID(), (void**)&channel);
if (NS_FAILED(rv)) return rv;
rv = channel->Init(this, verb, url, eventSinkGetter, eventQueue);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = channel;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileProtocolHandler::NewChannelFromNativePath(const char* nativePath,
nsIFileChannel* *result)
{
nsresult rv;
nsFileSpec spec(nativePath);
nsFileURL fileURL(spec);
const char* urlStr = fileURL.GetURLString();
nsIURI* uri;
rv = NewURI(urlStr, nsnull, &uri);
if (NS_FAILED(rv)) return rv;
rv = NewChannel("load", // XXX what should this be?
uri,
nsnull, // XXX bogus getter
nsnull, // XXX bogus
(nsIChannel**)result);
NS_RELEASE(uri);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
nsresult
nsFileProtocolHandler::ProcessPendingRequests(void)
{
return mPool->ProcessPendingRequests();
}
nsresult
nsFileProtocolHandler::DispatchRequest(nsIRunnable* runnable)
{
return mPool->DispatchRequest(runnable);
}
////////////////////////////////////////////////////////////////////////////////
nsresult
nsFileProtocolHandler::Suspend(nsFileChannel* request)
{
nsresult rv;
if (mSuspended == nsnull) {
rv = NS_NewISupportsArray(&mSuspended);
if (NS_FAILED(rv)) return rv;
}
return mSuspended->AppendElement(NS_STATIC_CAST(nsIChannel*, request));
}
nsresult
nsFileProtocolHandler::Resume(nsFileChannel* request)
{
nsresult rv;
if (mSuspended == nsnull)
return NS_ERROR_FAILURE;
// XXX RemoveElement returns a bool instead of nsresult!
PRBool removed = mSuspended->RemoveElement(NS_STATIC_CAST(nsIChannel*, request));
rv = removed ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
// restart the request
rv = mPool->DispatchRequest(NS_STATIC_CAST(nsIRunnable*, request));
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,79 @@
/* -*- 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 "nsIFileProtocolHandler.h"
class nsISupportsArray;
class nsIRunnable;
class nsFileChannel;
class nsIThreadPool;
#define NS_FILE_TRANSPORT_WORKER_COUNT 4
// {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 nsIFileProtocolHandler
{
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);
// nsIFileProtocolHandler methods:
NS_IMETHOD NewChannelFromNativePath(const char* nativePath,
nsIFileChannel* *result);
// nsFileProtocolHandler methods:
nsFileProtocolHandler();
virtual ~nsFileProtocolHandler();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsresult Init();
nsresult DispatchRequest(nsIRunnable* runnable);
nsresult Suspend(nsFileChannel* request);
nsresult Resume(nsFileChannel* request);
nsresult ProcessPendingRequests(void);
protected:
nsIThreadPool* mPool;
nsISupportsArray* mSuspended;
};
#endif /* nsFileProtocolHandler_h___ */

View File

@@ -0,0 +1,33 @@
#! 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,27 @@
#!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
DIRS= \
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,44 @@
#!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_ftp
XPIDLSRCS = \
nsIFTPChannel.idl \
$(NULL)
EXPORTS = \
ftpCore.h \
$(NULL)
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,45 @@
/* -*- 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 __ftpCore_h___
#define __ftpCore_h___
#include "nsError.h"
//////////////////////////////
//// FTP CODES RANGE: 20-30
//////////////////////////////
#define NS_ERROR_FTP_LOGIN \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 21)
#define NS_ERROR_FTP_MODE \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 22)
#define NS_ERROR_FTP_CWD \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 23)
#define NS_ERROR_FTP_PASV \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 24)
#define NS_ERROR_FTP_DEL_DIR \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 25)
#define NS_ERROR_FTP_MKDIR \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 26)
#endif // __ftpCore_h___

View File

@@ -0,0 +1,39 @@
#!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 = ..\..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
XPIDL_MODULE = netwerk_ftp
XPIDLSRCS = \
.\nsIFTPChannel.idl \
$(NULL)
EXPORTS = \
ftpCore.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,38 @@
/* -*- 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"
interface nsIStreamListener;
[scriptable, uuid(64718e40-18c2-11d3-9337-00104ba0fd40)]
interface nsIFTPChannel : nsIChannel
{
// PRE connect
// POST connect
// Initiate connect
void Get();
void Put();
void SetStreamListener(in nsIStreamListener aListener);
};

View File

@@ -0,0 +1,47 @@
# 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 = ftpprotocol
IS_COMPONENT = 1
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsFtpProtocolHandler.cpp \
nsFTPChannel.cpp \
nsFtpStreamListenerEvent.cpp \
nsFtpConnectionThread.cpp \
nsFtpFactory.cpp \
$(NULL)
MODULE = netwerk
include $(topsrcdir)/config/config.mk
# hack until necko lands
ifndef NECKO
PUBLIC = $(DEPTH)/netwerk/dist/include
endif
TARGET = $(LIBARY)
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,54 @@
# 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 = ..\..\..\..
// temporary, until we land:
!ifndef NECKO
include <$(DEPTH)/config/config.mak>
PUBLIC = $(DEPTH)\netwerk\dist\include
!endif
MAKE_OBJ_TYPE=DLL
DLLNAME=ftpprotocol
DLL=.\$(OBJDIR)\$(DLLNAME).dll
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
CPP_OBJS = \
.\$(OBJDIR)\nsFtpProtocolHandler.obj \
.\$(OBJDIR)\nsFTPChannel.obj \
.\$(OBJDIR)\nsFtpStreamListenerEvent.obj \
.\$(OBJDIR)\nsFtpConnectionThread.obj \
.\$(OBJDIR)\nsFtpFactory.obj \
$(NULL)
LLIBS= \
$(DIST)\lib\netwerk.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR)
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components

View File

@@ -0,0 +1,295 @@
/* -*- 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.
*/
// ftp implementation
#include "nsFTPChannel.h"
#include "nscore.h"
#include "nsIServiceManager.h"
#include "nsIBufferInputStream.h"
#include "nsFtpConnectionThread.h"
#include "nsIEventQueueService.h"
#include "nsIProgressEventSink.h"
#include "nsIEventSinkGetter.h"
#include "prprf.h" // PR_sscanf
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
// There are actually two transport connections established for an
// ftp connection. One is used for the command channel , and
// the other for the data channel. The command channel is the first
// connection made and is used to negotiate the second, data, channel.
// The data channel is driven by the command channel and is either
// initiated by the server (PORT command) or by the client (PASV command).
// Client initiation is the most command case and is attempted first.
nsFTPChannel::nsFTPChannel()
: mUrl(nsnull), mConnected(PR_FALSE), mListener(nsnull) {
nsresult rv;
NS_INIT_REFCNT();
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
if (NS_SUCCEEDED(rv)) {
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
}
if (NS_FAILED(rv))
mEventQueue = nsnull;
}
nsFTPChannel::~nsFTPChannel() {
NS_IF_RELEASE(mUrl);
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mEventQueue);
}
NS_IMPL_ADDREF(nsFTPChannel);
NS_IMPL_RELEASE(nsFTPChannel);
NS_IMETHODIMP
nsFTPChannel::QueryInterface(const nsIID& aIID, void** aInstancePtr) {
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(nsIFTPChannel::GetIID()) ||
aIID.Equals(nsIChannel::GetIID()) ||
aIID.Equals(kISupportsIID) ) {
*aInstancePtr = NS_STATIC_CAST(nsIFTPChannel*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIStreamListener::GetIID()) ||
aIID.Equals(nsIStreamObserver::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIStreamListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
nsFTPChannel::Init(const char* verb, nsIURI* uri, nsIEventSinkGetter* getter,
nsIEventQueue* queue)
{
nsresult rv;
if (mConnected)
return NS_ERROR_FAILURE;
mUrl = uri;
NS_ADDREF(mUrl);
mEventQueue = queue;
NS_ADDREF(mEventQueue);
nsIProgressEventSink* eventSink;
rv = getter->GetEventSink(verb, nsIProgressEventSink::GetIID(),
(nsISupports**)&eventSink);
if (NS_FAILED(rv)) return rv;
mEventSink = eventSink;
NS_ADDREF(mEventSink);
return NS_OK;
}
NS_METHOD
nsFTPChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
{
nsFTPChannel* fc = new nsFTPChannel();
if (fc == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(fc);
nsresult rv = fc->QueryInterface(aIID, aResult);
NS_RELEASE(fc);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP
nsFTPChannel::Cancel(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::Suspend(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::Resume(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:
NS_IMETHODIMP
nsFTPChannel::GetURI(nsIURI * *aURL)
{
NS_ADDREF(mUrl);
*aURL = mUrl;
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
nsIInputStream **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::AsyncWrite(nsIInputStream *fromStream,
PRUint32 startPosition,
PRInt32 writeCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamObserver *observer)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::GetContentType(char* *contentType) {
// XXX for ftp we need to do a file extension-to-type mapping lookup
// XXX in some hash table/registry of mime-types
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIFTPChannel methods:
NS_IMETHODIMP
nsFTPChannel::Get(void) {
nsresult rv;
nsIThread* workerThread = nsnull;
nsFtpConnectionThread* protocolInterpreter =
new nsFtpConnectionThread(mEventQueue, this);
NS_ASSERTION(protocolInterpreter, "ftp protocol interpreter alloc failed");
NS_ADDREF(protocolInterpreter);
if (!protocolInterpreter)
return NS_ERROR_OUT_OF_MEMORY;
protocolInterpreter->Init(workerThread, mUrl);
protocolInterpreter->SetUsePasv(PR_TRUE);
rv = NS_NewThread(&workerThread, protocolInterpreter);
NS_ASSERTION(NS_SUCCEEDED(rv), "new thread failed");
// XXX this release should probably be in the destructor.
NS_RELEASE(protocolInterpreter);
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::Put(void) {
nsresult rv;
nsIThread* workerThread = nsnull;
nsFtpConnectionThread* protocolInterpreter =
new nsFtpConnectionThread(mEventQueue, this);
NS_ASSERTION(protocolInterpreter, "ftp protocol interpreter alloc failed");
NS_ADDREF(protocolInterpreter);
if (!protocolInterpreter)
return NS_ERROR_OUT_OF_MEMORY;
protocolInterpreter->Init(workerThread, mUrl);
protocolInterpreter->SetAction(PUT);
protocolInterpreter->SetUsePasv(PR_TRUE);
rv = NS_NewThread(&workerThread, protocolInterpreter);
NS_ASSERTION(NS_SUCCEEDED(rv), "new thread failed");
// XXX this release should probably be in the destructor.
NS_RELEASE(protocolInterpreter);
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::SetStreamListener(nsIStreamListener *aListener) {
mListener = aListener;
NS_ADDREF(mListener);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIStreamObserver methods:
NS_IMETHODIMP
nsFTPChannel::OnStartBinding(nsISupports* context) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg) {
// Release the lock so the user get's the data stream
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::OnStartRequest(nsISupports* context) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFTPChannel::OnStopRequest(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg) {
// Release the lock so the user get's the data stream
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIStreamListener methods:
NS_IMETHODIMP
nsFTPChannel::OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength) {
// Fill in the buffer w/ the new data.
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,102 @@
/* -*- 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.
*/
// ftp implementation header
#ifndef nsFTPChannel_h___
#define nsFTPChannel_h___
#include "nsIFTPChannel.h"
#include "nsIStreamListener.h"
#include "nsIThread.h"
#include "nsIURI.h"
#include "nsString2.h"
#include "nsIEventQueue.h"
class nsIEventSinkGetter;
class nsIProgressEventSink;
class nsFTPChannel : public nsIFTPChannel,
public nsIStreamListener {
public:
NS_DECL_ISUPPORTS
// nsIRequest methods:
NS_IMETHOD Cancel();
NS_IMETHOD Suspend();
NS_IMETHOD Resume();
// nsIChannel methods:
NS_IMETHOD GetURI(nsIURI * *aURL);
NS_IMETHOD OpenInputStream(PRUint32 startPosition, PRInt32 readCount, nsIInputStream **_retval);
NS_IMETHOD OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval);
NS_IMETHOD AsyncRead(PRUint32 startPosition, PRInt32 readCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamListener *listener);
NS_IMETHOD AsyncWrite(nsIInputStream *fromStream,
PRUint32 startPosition,
PRInt32 writeCount,
nsISupports *ctxt,
nsIEventQueue *eventQueue,
nsIStreamObserver *observer);
// nsIFTPChannel methods:
NS_IMETHOD Get(void);
NS_IMETHOD Put(void);
NS_IMETHOD SetStreamListener(nsIStreamListener* aListener);
// nsIStreamObserver methods:
NS_IMETHOD OnStartBinding(nsISupports* context);
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg);
NS_IMETHOD OnStartRequest(nsISupports *ctxt);
NS_IMETHOD OnStopRequest(nsISupports *ctxt,
nsresult status,
const PRUnichar *errorMsg);
// nsIStreamListener methods:
NS_IMETHOD OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength);
// nsFTPChannel methods:
nsFTPChannel();
virtual ~nsFTPChannel();
// Define a Create method to be used with a factory:
static NS_METHOD
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
nsresult Init(const char* verb, nsIURI* uri, nsIEventSinkGetter* getter,
nsIEventQueue* queue);
NS_IMETHOD GetContentType(char* *contentType);
protected:
nsIURI* mUrl;
nsIEventQueue* mEventQueue;
nsIProgressEventSink* mEventSink;
PRBool mConnected;
nsIStreamListener* mListener;
};
#endif /* nsFTPChannel_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,182 @@
/* -*- 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 "nsIThread.h"
#include "nsISocketTransportService.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIURI.h"
#include "prlock.h"
#include "nsString2.h"
#include "nsIEventQueue.h"
#include "time.h" // XXX should probably be using PRTime stuff
// ftp server types
#define FTP_GENERIC_TYPE 0
#define FTP_UNIX_TYPE 1
#define FTP_DCTS_TYPE 2
#define FTP_NCSA_TYPE 3
#define FTP_PETER_LEWIS_TYPE 4
#define FTP_MACHTEN_TYPE 5
#define FTP_CMS_TYPE 6
#define FTP_TCPC_TYPE 7
#define FTP_VMS_TYPE 8
#define FTP_NT_TYPE 9
#define FTP_WEBSTAR_TYPE 10
// ftp states
typedef enum _FTP_STATE {
///////////////////////
//// Internal states
///////////////////////
FTP_READ_BUF,
FTP_ERROR,
FTP_COMPLETE,
///////////////////////
//// Command channel connection setup states
///////////////////////
FTP_S_USER, // send username
FTP_R_USER,
FTP_S_PASS, // send password
FTP_R_PASS,
FTP_S_SYST, // send system (interrogates server)
FTP_R_SYST,
FTP_S_ACCT, // send account
FTP_R_ACCT,
FTP_S_MACB,
FTP_R_MACB,
FTP_S_PWD , // send parent working directory (pwd)
FTP_R_PWD ,
FTP_S_DEL_FILE, // send delete file
FTP_R_DEL_FILE,
FTP_S_DEL_DIR , // send delete directory
FTP_R_DEL_DIR ,
FTP_S_MKDIR, // send mkdir
FTP_R_MKDIR,
FTP_S_MODE, // send ASCII or BINARY
FTP_R_MODE,
FTP_S_CWD, // send change working directory
FTP_R_CWD,
FTP_S_SIZE, // send size
FTP_R_SIZE,
FTP_S_PUT, // send STOR to upload the file
FTP_R_PUT,
FTP_S_RETR, // send retrieve to download the file
FTP_R_RETR,
FTP_S_MDTM, // send MDTM to get time information
FTP_R_MDTM,
FTP_S_LIST, // send LIST or NLST (server dependent) to get a dir listing
FTP_R_LIST,
///////////////////////
//// Data channel connection setup states
///////////////////////
FTP_S_PASV, // send passsive
FTP_R_PASV,
// FTP_S_PORT, // send port
// FTP_R_PORT
} FTP_STATE;
// higher level ftp actions
typedef enum _FTP_ACTION {
GET,
PUT,
MKDIR,
DEL
} FTP_ACTION;
class nsFtpConnectionThread : public nsIRunnable {
public:
NS_DECL_ISUPPORTS
nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamListener *aListener);
virtual ~nsFtpConnectionThread();
// nsIRunnable method
NS_IMETHOD Run();
#if 0
// nsICancelable methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
#endif
nsresult Init(nsIThread* aThread,
nsIURI* aUrl);
// user level setup
nsresult SetAction(FTP_ACTION aAction);
nsresult SetUsePasv(PRBool aUsePasv);
private:
nsresult Read(void);
void SetSystInternals(void);
FTP_STATE FindActionState(void);
FTP_STATE FindGetState(void);
nsresult MapResultCodeToString(nsresult aResultCode, PRUnichar* *aOutMsg);
// Private members
nsIEventQueue* mEventQueue; // used to communicate outside this thread
nsIURI* mUrl;
FTP_STATE mState; // the current state
FTP_STATE mNextState; // the next state
FTP_ACTION mAction; // the higher level action
nsIInputStream* mCInStream; // command channel input
nsIOutputStream* mCOutStream; // command channel output
//nsString2 mDataAddress; // the host:port combo for the data connection
nsIInputStream* mDInStream; // data channel input
nsIOutputStream* mDOutStream; // data channel output
PRInt32 mResponseCode; // the last command response code.
nsString2 mResponseMsg; // the last command response text
nsString2 mUsername;
nsString2 mPassword;
nsString2 mFilename; // url filename (if any)
PRInt32 mLength; // length of the file
time_t mLastModified; // last modified time for file
// these members should be hung off of a specific transport connection
PRInt32 mServerType;
PRBool mPasv;
PRBool mList; // use LIST instead of NLST
// end "these ...."
PRBool mConnected;
PRBool mUseDefaultPath; // use PWD to figure out path
PRBool mUsePasv; // use a passive data connection.
PRBool mAscii; // transfer mode (ascii or binary)
PRBool mDirectory; // this url is a directory
nsIStreamListener* mListener; // the listener we want to call
// during our event firing.
PRLock *mLock;
PRThread *mThread;
};
#define NS_FTP_THREAD_SEGMENT_SIZE (4*1024)
#define NS_FTP_THREAD_BUFFER_SIZE (16*1024)

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 "nsFtpProtocolHandler.h"
#include "nscore.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kFtpProtocolHandlerCID, NS_FTPPROTOCOLHANDLER_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(kFtpProtocolHandlerCID)) {
rv = NS_NewGenericFactory(&fact, nsFtpProtocolHandler::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(kFtpProtocolHandlerCID,
"FTP Protocol Handler",
NS_NETWORK_PROTOCOL_PROGID_PREFIX "ftp",
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(kFtpProtocolHandlerCID, aPath);
if (NS_FAILED(rv)) return rv;
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,149 @@
/* -*- 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 "nsFTPChannel.h"
#include "nsFtpProtocolHandler.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);
////////////////////////////////////////////////////////////////////////////////
nsFtpProtocolHandler::nsFtpProtocolHandler() {
NS_INIT_REFCNT();
}
nsFtpProtocolHandler::~nsFtpProtocolHandler() {
}
NS_IMPL_ISUPPORTS(nsFtpProtocolHandler, nsIProtocolHandler::GetIID());
NS_METHOD
nsFtpProtocolHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
{
nsFtpProtocolHandler* ph = new nsFtpProtocolHandler();
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
nsFtpProtocolHandler::GetScheme(char* *result)
{
*result = nsCRT::strdup("ftp");
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsFtpProtocolHandler::GetDefaultPort(PRInt32 *result)
{
*result = 21;
return NS_OK;
}
NS_IMETHODIMP
nsFtpProtocolHandler::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
nsFtpProtocolHandler::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
nsFtpProtocolHandler::NewChannel(const char* verb, nsIURI* url,
nsIEventSinkGetter* eventSinkGetter,
nsIEventQueue* eventQueue,
nsIChannel* *result)
{
nsresult rv;
nsFTPChannel* channel;
rv = nsFTPChannel::Create(nsnull, nsIFTPChannel::GetIID(), (void**)&channel);
if (NS_FAILED(rv)) return rv;
rv = channel->Init(verb, url, eventSinkGetter, eventQueue);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = channel;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,57 @@
/* -*- 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 nsFtpProtocolHandler_h___
#define nsFtpProtocolHandler_h___
#include "nsIProtocolHandler.h"
// {25029490-F132-11d2-9588-00805F369F95}
#define NS_FTPPROTOCOLHANDLER_CID \
{ 0x25029490, 0xf132, 0x11d2, { 0x95, 0x88, 0x0, 0x80, 0x5f, 0x36, 0x9f, 0x95 } }
class nsFtpProtocolHandler : 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);
// nsFtpProtocolHandler methods:
nsFtpProtocolHandler();
virtual ~nsFtpProtocolHandler();
// Define a Create method to be used with a factory:
static NS_METHOD
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
protected:
nsISupports* mEventSinkGetter;
};
#endif /* nsFtpProtocolHandler_h___ */

View File

@@ -0,0 +1,212 @@
/* -*- 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 "nsFtpStreamListenerEvent.h"
#include "nsIBufferInputStream.h"
#include "nscore.h"
nsFtpStreamListenerEvent::nsFtpStreamListenerEvent(nsIStreamListener* listener,
nsISupports* context)
: mListener(listener), mContext(context)
{
NS_IF_ADDREF(mListener);
NS_IF_ADDREF(mContext);
}
nsFtpStreamListenerEvent::~nsFtpStreamListenerEvent()
{
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mContext);
}
void PR_CALLBACK nsFtpStreamListenerEvent::HandlePLEvent(PLEvent* aEvent)
{
// WARNING: This is a dangerous cast since it must adjust the pointer
// to compensate for the vtable...
nsFtpStreamListenerEvent *ev = (nsFtpStreamListenerEvent*)aEvent;
nsresult rv = ev->HandleEvent();
//ev->mListener->SetStatus(rv);
}
void PR_CALLBACK nsFtpStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
{
// WARNING: This is a dangerous cast since it must adjust the pointer
// to compensate for the vtable...
nsFtpStreamListenerEvent *ev = (nsFtpStreamListenerEvent*)aEvent;
delete ev;
}
nsresult
nsFtpStreamListenerEvent::Fire(nsIEventQueue* aEventQueue)
{
NS_PRECONDITION(nsnull != aEventQueue, "nsIEventQueue for thread is null");
PL_InitEvent(this, nsnull,
(PLHandleEventProc) nsFtpStreamListenerEvent::HandlePLEvent,
(PLDestroyEventProc) nsFtpStreamListenerEvent::DestroyPLEvent);
PRStatus status = aEventQueue->PostEvent(this);
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
////////////////////////////////////////////////////////////////////////////////
//
// OnStartBinding...
//
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFtpOnStartBindingEvent::HandleEvent()
{
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener;
return receiver->OnStartBinding(mContext);
}
/*
NS_IMETHODIMP
nsMarshalingStreamObserver::OnStartBinding(nsISupports* context)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStartBindingEvent* event =
new nsOnStartBindingEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
*/
////////////////////////////////////////////////////////////////////////////////
//
// OnDataAvailable
//
////////////////////////////////////////////////////////////////////////////////
nsFtpOnDataAvailableEvent::~nsFtpOnDataAvailableEvent()
{
NS_RELEASE(mIStream);
}
nsresult
nsFtpOnDataAvailableEvent::Init(nsIBufferInputStream* aIStream,
PRUint32 aSourceOffset, PRUint32 aLength)
{
mLength = aLength;
mSourceOffset = aSourceOffset;
mIStream = aIStream;
NS_ADDREF(mIStream);
return NS_OK;
}
NS_IMETHODIMP
nsFtpOnDataAvailableEvent::HandleEvent()
{
nsIStreamListener* receiver = (nsIStreamListener*)mListener;
return receiver->OnDataAvailable(mContext, mIStream, mSourceOffset, mLength);
}
/*
NS_IMETHODIMP
nsMarshalingStreamListener::OnDataAvailable(nsISupports* context,
nsIBufferInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnDataAvailableEvent* event =
new nsOnDataAvailableEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aIStream, aSourceOffset, aLength);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
*/
////////////////////////////////////////////////////////////////////////////////
//
// OnStopBinding
//
////////////////////////////////////////////////////////////////////////////////
nsFtpOnStopBindingEvent::~nsFtpOnStopBindingEvent()
{
}
nsresult
nsFtpOnStopBindingEvent::Init(nsresult status, PRUnichar* aMsg)
{
mStatus = status;
mMessage = aMsg;
return NS_OK;
}
NS_IMETHODIMP
nsFtpOnStopBindingEvent::HandleEvent()
{
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener;
return receiver->OnStopBinding(mContext, mStatus, mMessage);
}
/*
NS_IMETHODIMP
nsMarshalingStreamObserver::OnStopBinding(nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStopBindingEvent* event =
new nsOnStopBindingEvent(this, context);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aStatus, aMsg);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
}
*/
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

Some files were not shown because too many files have changed in this diff Show More