Began fleshing out http protocol.

This commit is contained in:
warren%netscape.com 1999-04-12 22:34:20 +00:00
parent 86b13a8940
commit a7c8e361b8
20 changed files with 809 additions and 44 deletions

View File

@ -66,9 +66,9 @@ public:
* to the protocol handler for that scheme. QueryInterface can be used
* on the resulting URL object to obtain a more specific type of URL.
*/
NS_IMETHOD NewUrl(nsIUrl* *result,
const char* aSpec,
nsIUrl* aBaseUrl) = 0;
NS_IMETHOD NewUrl(const char* aSpec,
nsIUrl* aBaseUrl,
nsIUrl* *result) = 0;
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,

View File

@ -42,7 +42,7 @@ public:
// can be called after Open
// freed by caller with delete[]
NS_IMETHOD GetContentType(char* *contentType);
NS_IMETHOD GetContentType(char* *contentType) = 0;
// blocking:
NS_IMETHOD GetInputStream(nsIInputStream* *result) = 0;

View File

@ -22,6 +22,8 @@
#include "nsISupports.h"
class nsIConnectionGroup;
class nsIUrl;
class nsIProtocolConnection;
#define NS_IPROTOCOLHANDLER_IID \
{ /* 5da8b1b0-ea35-11d2-931b-00104ba0fd40 */ \
@ -50,13 +52,12 @@ public:
* needed), this method just constructs a typical URL using the
* component manager with kTypicalUrlCID.
*/
NS_IMETHOD NewUrl(nsIUrl* *result,
const char* aSpec,
const nsIUrl* aBaseURL) = 0;
NS_IMETHOD NewUrl(const char* aSpec,
nsIUrl* aBaseUrl,
nsIUrl* *result) = 0;
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,
nsIConnectionGroup* group,
nsIProtocolConnection* *result) = 0;
};

View File

@ -125,8 +125,44 @@ public:
* Writes a string representation of the URI.
* Free string with delete[].
*/
NS_IMETHOD ToNewCString(const char* *uriString) = 0;
NS_IMETHOD ToNewCString(char* *uriString) = 0;
};
////////////////////////////////////////////////////////////////////////////////
// The "Typical URL" Implementation
// XXX regenerate:
#define NS_ITYPICALURL_IID \
{ /* 5053f850-f11e-11d2-9322-000000000000 */ \
0x5053f850, \
0xf11e, \
0x11d2, \
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
}
// XXX regenerate:
#define NS_TYPICALURL_CID \
{ /* 8ffae6d0-ee37-11d2-9322-000000000000 */ \
0x8ffae6d0, \
0xee37, \
0x11d2, \
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
}
/**
* The nsITypicalUrl interface defines the initializer for a URL
* implementation that only supports the accessors of nsIUrl.
*
* Protocol writers can obtain one by calling the component manager
* to create an instance of a typical URL by the CID, and then call
* the Init routine on it and finally QueryInterface to get the nsIUrl
* to return.
*/
class nsITypicalUrl : public nsISupports
{
public:
NS_IMETHOD Init(const char* spec, nsIUrl* baseUrl) = 0;
};
#endif /* nsIIUrl_h___ */

View File

@ -18,6 +18,7 @@
#include "nsNetService.h"
#include "nsIProtocolHandler.h"
#include "nsIProtocolConnection.h"
#include "nsUrl.h"
#include "nscore.h"
#include "nsString2.h"
@ -143,9 +144,9 @@ nsNetService::MakeAbsoluteUrl(const char* aSpec,
}
NS_IMETHODIMP
nsNetService::NewUrl(nsIUrl* *result,
const char* aSpec,
nsIUrl* aBaseUrl)
nsNetService::NewUrl(const char* aSpec,
nsIUrl* aBaseUrl,
nsIUrl* *result)
{
nsresult rv;
char schemeBuf[MAX_SCHEME_LENGTH];
@ -160,7 +161,7 @@ nsNetService::NewUrl(nsIUrl* *result,
rv = GetProtocolHandler(scheme, &handler);
if (NS_FAILED(rv)) return rv;
rv = handler->NewUrl(result, aSpec, aBaseUrl);
rv = handler->NewUrl(aSpec, aBaseUrl, result);
NS_RELEASE(handler);
return rv;
}
@ -181,8 +182,19 @@ nsNetService::NewConnection(nsIUrl* url,
rv = GetProtocolHandler(scheme, &handler);
if (NS_FAILED(rv)) return rv;
rv = handler->NewConnection(url, eventSink, group, result);
nsIProtocolConnection* connection;
rv = handler->NewConnection(url, eventSink, &connection);
NS_RELEASE(handler);
if (NS_FAILED(rv)) return rv;
if (group) {
rv = group->AppendElement(connection);
if (NS_FAILED(rv)) {
NS_RELEASE(connection);
return rv;
}
}
*result = connection;
return rv;
}

View File

@ -32,9 +32,9 @@ public:
NS_IMETHOD MakeAbsoluteUrl(const char* aSpec,
nsIUrl* aBaseUrl,
char* *result);
NS_IMETHOD NewUrl(nsIUrl* *result,
const char* aSpec,
nsIUrl* aBaseUrl);
NS_IMETHOD NewUrl(const char* aSpec,
nsIUrl* aBaseUrl,
nsIUrl* *result);
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,
nsIConnectionGroup* group,

View File

@ -24,6 +24,10 @@
#include "prprf.h"
static NS_DEFINE_CID(kTypicalUrlCID, NS_TYPICALURL_CID);
static NS_DEFINE_CID(kThisTypicalUrlImplementationCID,
NS_THIS_TYPICALURL_IMPLEMENTATION_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
// nsUrl methods:
@ -51,7 +55,7 @@ nsUrl::~nsUrl()
if (mSpec) delete[] mSpec;
}
nsresult
NS_IMETHODIMP
nsUrl::Init(const char* aSpec,
nsIUrl* aBaseUrl)
{
@ -64,13 +68,18 @@ NS_IMETHODIMP
nsUrl::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(kTypicalUrlCID) || // used by Equals
if (aIID.Equals(kThisTypicalUrlImplementationCID) || // used by Equals
aIID.Equals(nsIUrl::GetIID()) ||
aIID.Equals(nsISupports::GetIID())) {
aIID.Equals(kISupportsIID)) {
*aInstancePtr = NS_STATIC_CAST(nsIUrl*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsITypicalUrl::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsITypicalUrl*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -154,7 +163,10 @@ nsUrl::Equals(nsIUrl* other)
if (other) {
// NS_LOCK_INSTANCE();
nsUrl* otherUrl;
if (NS_SUCCEEDED(other->QueryInterface(kTypicalUrlCID, (void**)&otherUrl))) {
nsresult rv =
other->QueryInterface(kThisTypicalUrlImplementationCID,
(void**)&otherUrl);
if (NS_SUCCEEDED(rv)) {
eq = PRBool((0 == PL_strcmp(mScheme, otherUrl->mScheme)) &&
(0 == PL_strcasecmp(mHost, otherUrl->mHost)) &&
(mPort == otherUrl->mPort) &&
@ -198,7 +210,7 @@ nsUrl::Clone(nsIUrl* *result)
}
NS_IMETHODIMP
nsUrl::ToNewCString(const char* *result)
nsUrl::ToNewCString(char* *result)
{
nsAutoString string;
// NS_LOCK_INSTANCE();

View File

@ -23,15 +23,15 @@
#include "nsAgg.h"
// XXX regenerate:
#define NS_TYPICALURL_CID \
{ /* 8ffae6d0-ee37-11d2-9322-000000000000 */ \
0x8ffae6d0, \
0xee37, \
#define NS_THIS_TYPICALURL_IMPLEMENTATION_CID \
{ /* 905ed480-f11f-11d2-9322-000000000000 */ \
0x905ed480, \
0xf11f, \
0x11d2, \
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
}
class nsUrl : public nsIUrl
class nsUrl : public nsIUrl, public nsITypicalUrl
{
public:
NS_DECL_AGGREGATED
@ -57,7 +57,12 @@ public:
NS_IMETHOD Equals(nsIUrl* other);
NS_IMETHOD Clone(nsIUrl* *result);
NS_IMETHOD ToNewCString(const char* *result);
NS_IMETHOD ToNewCString(char* *result);
////////////////////////////////////////////////////////////////////////////
// nsITypicalUrl methods:
NS_IMETHOD Init(const char* spec, nsIUrl* baseUrl);
////////////////////////////////////////////////////////////////////////////
// nsUrl methods:
@ -65,9 +70,6 @@ public:
nsUrl(nsISupports* outer);
virtual ~nsUrl();
nsresult Init(const char* aSpec,
nsIUrl* aBaseURL);
protected:
nsresult Parse(const char* spec, nsIUrl* aBaseUrl);
void ReconstructSpec();

View File

@ -16,7 +16,7 @@
# Reserved.
DEPTH=..\..
MODULE=rdf
MODULE=netwerk
MAKE_OBJ_TYPE=DLL
DLLNAME=netwerk
@ -35,8 +35,6 @@ LLIBS= \
MISCDEP=$(LLIBS)
# XXX Note dependencies on implementation dirs for factory methods.
LINCS= -I$(PUBLIC)\netwerk \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \

View File

@ -105,17 +105,10 @@ nsNetFactory::CreateInstance(nsISupports *aOuter,
}
inst = trans;
}
else if (mClassID.Equals(kFileTransportServiceCID)) {
else if (mClassID.Equals(kTypicalUrlCID)) {
nsUrl* url = new nsUrl(aOuter);
if (url == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
#if 0
rv = url->Init();
if (NS_FAILED(rv)) {
delete url;
return rv;
}
#endif
inst = url;
}
else {
@ -173,6 +166,12 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
"File Transport Service",
"component://netscape/network/file-transport-service",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;;
rv = compMgr->RegisterComponent(kTypicalUrlCID,
"Typical URL Implementation",
"component://netscape/network/typcial-url",
aPath, PR_TRUE, PR_TRUE);
return rv;
}
@ -188,6 +187,9 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kFileTransportServiceCID, aPath);
if (NS_FAILED(rv)) return rv;;
rv = compMgr->UnregisterComponent(kTypicalUrlCID, aPath);
return rv;
}

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,28 @@
#!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 = ..\..\..\..
EXPORTS = \
nsIHttpEventSink.h \
nsIHttpProtocolConnection.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

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 nsIHttpEventSink_h___
#define nsIHttpEventSink_h___
#include "nsISupports.h"
#include "nscore.h"
class nsIUrl;
#define NS_IHTTPEVENTSINK_IID \
{ /* b297b0a0-ea35-11d2-931b-00104ba0fd40 */ \
0xb297b0a0, \
0xea35, \
0x11d2, \
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
/**
* An instance of nsIHttpEventSink should be passed as the eventSink
* argument of nsINetService::NewConnection for http URLs. It defines
* the callbacks to the application program (the html parser).
*/
class nsIHttpEventSink : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTTPEVENTSINK_IID);
/**
* Notify the EventSink that progress as occurred for the URL load.<BR>
*/
NS_IMETHOD OnProgress(nsIUrl* aURL, PRUint32 aProgress, PRUint32 aProgressMax) = 0;
/**
* Notify the EventSink with a status message for the URL load.<BR>
*/
NS_IMETHOD OnStatus(nsIUrl* aURL, const PRUnichar* aMsg) = 0;
};
#endif /* nsIIHttpEventSink_h___ */

View File

@ -0,0 +1,49 @@
# 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 = ..\..\..\..
MAKE_OBJ_TYPE=DLL
DLLNAME=http
DLL=.\$(OBJDIR)\$(DLLNAME).dll
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
CPP_OBJS = \
.\$(OBJDIR)\nsHttpProtocolHandler.obj \
.\$(OBJDIR)\nsHttpProtocolConnection.obj \
.\$(OBJDIR)\nsHttpFactory.obj \
$(NULL)
LLIBS= \
$(DIST)\lib\netwerk.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR)
LINCS = \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\netwerk \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components

View File

@ -0,0 +1,154 @@
/* -*- 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 "nsIFactory.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsHttpProtocolHandler.h"
#include "nscore.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kHttpProtocolHandlerCID, NS_HTTPPROTOCOLHANDLER_CID);
////////////////////////////////////////////////////////////////////////////////
class nsNetFactory : public nsIFactory
{
public:
nsNetFactory(const nsCID &aClass);
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~nsNetFactory();
protected:
nsCID mClassID;
};
////////////////////////////////////////////////////////////////////////
nsNetFactory::nsNetFactory(const nsCID &aClass)
: mClassID(aClass)
{
NS_INIT_REFCNT();
}
nsNetFactory::~nsNetFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMPL_ISUPPORTS(nsNetFactory, nsIFactory::GetIID());
NS_IMETHODIMP
nsNetFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult rv;
if (aResult == nsnull)
return NS_ERROR_NULL_POINTER;
nsISupports *inst = nsnull;
if (mClassID.Equals(kHttpProtocolHandlerCID)) {
if (aOuter) return NS_ERROR_NO_AGGREGATION;
nsHttpProtocolHandler* net = new nsHttpProtocolHandler();
if (net == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
inst = net;
}
else {
return NS_ERROR_NO_INTERFACE;
}
NS_ADDREF(inst);
*aResult = inst;
return rv;
}
nsresult nsNetFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// 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)
{
if (aFactory == nsnull)
return NS_ERROR_NULL_POINTER;
nsNetFactory* factory = new nsNetFactory(aClass);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}
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(kHttpProtocolHandlerCID,
"HTTP Protocol Handler",
NS_NETWORK_PROTOCOL_PROGID_PREFIX "http",
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(kHttpProtocolHandlerCID, aPath);
if (NS_FAILED(rv)) return rv;
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,148 @@
/* -*- 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 "nsHttpProtocolConnection.h"
#include "nscore.h"
#include "nsIUrl.h"
#include "nsIHttpEventSink.h"
nsHttpProtocolConnection::nsHttpProtocolConnection()
: mUrl(nsnull), mEventSink(nsnull)
{
}
nsHttpProtocolConnection::~nsHttpProtocolConnection()
{
NS_IF_RELEASE(mUrl);
NS_IF_RELEASE(mEventSink);
}
NS_IMPL_ADDREF(nsHttpProtocolConnection);
NS_IMPL_RELEASE(nsHttpProtocolConnection);
NS_IMETHODIMP
nsHttpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(nsIHttpProtocolConnection::GetIID()) ||
aIID.Equals(nsIProtocolConnection::GetIID()) ||
aIID.Equals(nsISupports::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIHttpProtocolConnection*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink)
{
nsresult rv;
mUrl = url;
NS_ADDREF(mUrl);
rv = eventSink->QueryInterface(nsIHttpEventSink::GetIID(), (void**)&mEventSink);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsICancelable methods:
NS_IMETHODIMP
nsHttpProtocolConnection::Cancel(void)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Suspend(void)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Resume(void)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolConnection methods:
NS_IMETHODIMP
nsHttpProtocolConnection::Open(nsIUrl* url, nsISupports* eventSink)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::GetContentType(char* *contentType)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::GetInputStream(nsIInputStream* *result)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::GetOutputStream(nsIOutputStream* *result)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::AsyncWrite(nsIInputStream* data, PRUint32 count,
nsresult (*callback)(void* closure, PRUint32 count),
void* closure)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIHttpProtocolConnection methods:
NS_IMETHODIMP
nsHttpProtocolConnection::Get(void)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::GetByteRange(PRUint32 from, PRUint32 to)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Put(void)
{
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Post(void)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,63 @@
/* -*- 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 nsHttpProtocolConnection_h___
#define nsHttpProtocolConnection_h___
#include "nsIHttpProtocolConnection.h"
class nsIConnectionGroup;
class nsIHttpEventSink;
class nsHttpProtocolConnection : public nsIHttpProtocolConnection
{
public:
NS_DECL_ISUPPORTS
// nsICancelable methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
// nsIProtocolConnection methods:
NS_IMETHOD Open(nsIUrl* url, nsISupports* eventSink);
NS_IMETHOD GetContentType(char* *contentType);
NS_IMETHOD GetInputStream(nsIInputStream* *result);
NS_IMETHOD GetOutputStream(nsIOutputStream* *result);
NS_IMETHOD AsyncWrite(nsIInputStream* data, PRUint32 count,
nsresult (*callback)(void* closure, PRUint32 count),
void* closure);
// nsIHttpProtocolConnection methods:
NS_IMETHOD Get(void);
NS_IMETHOD GetByteRange(PRUint32 from, PRUint32 to);
NS_IMETHOD Put(void);
NS_IMETHOD Post(void);
// nsHttpProtocolConnection methods:
nsHttpProtocolConnection();
virtual ~nsHttpProtocolConnection();
nsresult Init(nsIUrl* url, nsISupports* eventSink);
protected:
nsIUrl* mUrl;
nsIHttpEventSink* mEventSink;
};
#endif /* nsHttpProtocolConnection_h___ */

View File

@ -0,0 +1,116 @@
/* -*- 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 "nsHttpProtocolHandler.h"
#include "nsHttpProtocolConnection.h"
#include "nsIUrl.h"
#include "nsCRT.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kTypicalUrlCID, NS_TYPICALURL_CID);
////////////////////////////////////////////////////////////////////////////////
nsHttpProtocolHandler::nsHttpProtocolHandler()
{
}
nsHttpProtocolHandler::~nsHttpProtocolHandler()
{
}
NS_IMPL_ISUPPORTS(nsHttpProtocolHandler, nsIProtocolHandler::GetIID());
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
NS_IMETHODIMP
nsHttpProtocolHandler::GetScheme(const char* *result)
{
*result = nsCRT::strdup("http");
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolHandler::GetDefaultPort(PRInt32 *result)
{
*result = 80;
return NS_OK;
}
NS_IMETHODIMP
nsHttpProtocolHandler::MakeAbsoluteUrl(const char* aSpec,
nsIUrl* aBaseUrl,
char* *result)
{
// XXX optimize this to not needlessly construct the URL
nsresult rv;
nsIUrl* url;
rv = NewUrl(aSpec, aBaseUrl, &url);
if (NS_FAILED(rv)) return rv;
rv = url->ToNewCString(result);
NS_RELEASE(url);
return rv;
}
NS_IMETHODIMP
nsHttpProtocolHandler::NewUrl(const char* aSpec,
nsIUrl* aBaseUrl,
nsIUrl* *result)
{
nsresult rv;
// http URLs (currently) have no additional structure beyond that provided by typical
// URLs, so there is no "outer" given to CreateInstance
nsITypicalUrl* url;
rv = nsComponentManager::CreateInstance(kTypicalUrlCID, nsnull,
nsITypicalUrl::GetIID(),
(void**)&url);
if (NS_FAILED(rv)) return rv;
rv = url->Init(aSpec, aBaseUrl);
return rv;
}
NS_IMETHODIMP
nsHttpProtocolHandler::NewConnection(nsIUrl* url,
nsISupports* eventSink,
nsIProtocolConnection* *result)
{
nsresult rv;
nsHttpProtocolConnection* connection = new nsHttpProtocolConnection();
if (connection == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = connection->Init(url, eventSink);
if (NS_FAILED(rv)) {
delete connection;
return rv;
}
NS_ADDREF(connection);
*result = connection;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

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.
*/
#ifndef nsHttpProtocolHandler_h___
#define nsHttpProtocolHandler_h___
#include "nsIProtocolHandler.h"
// XXX regenerate:
#define NS_HTTPPROTOCOLHANDLER_CID \
{ /* 59321440-f125-11d2-9322-000000000000 */ \
0x59321440, \
0xf125, \
0x11d2, \
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
}
class nsHttpProtocolHandler : public nsIProtocolHandler
{
public:
NS_DECL_ISUPPORTS
// nsIProtocolHandler methods:
NS_IMETHOD GetScheme(const char* *result);
NS_IMETHOD GetDefaultPort(PRInt32 *result);
NS_IMETHOD MakeAbsoluteUrl(const char* aSpec,
nsIUrl* aBaseUrl,
char* *result);
NS_IMETHOD NewUrl(const char* aSpec,
nsIUrl* aBaseUrl,
nsIUrl* *result);
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,
nsIProtocolConnection* *result);
// nsHttpProtocolHandler methods:
nsHttpProtocolHandler();
virtual ~nsHttpProtocolHandler();
protected:
};
#endif /* nsHttpProtocolHandler_h___ */

View File

@ -19,7 +19,8 @@ DEPTH = ..\..
MODULE = netwerk
#DIRS= \
# $(NULL)
DIRS= \
http \
$(NULL)
include <$(DEPTH)\config\rules.mak>