зеркало из https://github.com/mozilla/pjs.git
Fixed up nsIUrl and added an implementation that allows for setting the parts. Added MakeAbsoluteUrl to nsINetService and nsIProtocolHandler.
This commit is contained in:
Родитель
ff6ad10f0b
Коммит
8930d4895d
|
@ -24,12 +24,11 @@ EXPORTS = \
|
|||
nsIConnectionGroup.h \
|
||||
nsIFileTransportService.h \
|
||||
nsINetService.h \
|
||||
nsIProtocolInstance.h \
|
||||
nsIProtocolConnection.h \
|
||||
nsIProtocolHandler.h \
|
||||
nsIStreamListener.h \
|
||||
nsITransport.h \
|
||||
nsIURL.h \
|
||||
nsIURI.h \
|
||||
nsIUrl.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIURL;
|
||||
class nsIProtocolInstance;
|
||||
class nsIUrl;
|
||||
class nsIProtocolConnection;
|
||||
class nsIConnectionGroup;
|
||||
class nsIProtocolHandler;
|
||||
|
||||
|
@ -47,24 +47,40 @@ class nsINetService : public nsISupports
|
|||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_INETSERVICE_IID);
|
||||
|
||||
NS_IMETHOD GetProtocolHandler(nsIURL* url, nsIProtocolHandler* *result) = 0;
|
||||
NS_IMETHOD GetProtocolHandler(const char* scheme,
|
||||
nsIProtocolHandler* *result) = 0;
|
||||
|
||||
NS_IMETHOD NewConnectionGroup(nsIConnectionGroup* *result) = 0;
|
||||
|
||||
NS_IMETHOD NewURL(nsIURL* *result,
|
||||
const char* aSpec,
|
||||
const nsIURL* aBaseURL,
|
||||
nsISupports* aContainer) = 0;
|
||||
/**
|
||||
* Returns the absolute URL given a (possibly) relative spec, and
|
||||
* a base URL. Returns a string that must be freed with delete[].
|
||||
*/
|
||||
NS_IMETHOD MakeAbsoluteUrl(const char* aSpec,
|
||||
nsIUrl* aBaseUrl,
|
||||
char* *result) = 0;
|
||||
|
||||
NS_IMETHOD Open(nsIURL* url, nsISupports* eventSink,
|
||||
nsIConnectionGroup* group,
|
||||
nsIProtocolInstance* *result) = 0;
|
||||
/**
|
||||
* This method constructs a new URL by first determining the scheme
|
||||
* of the url spec, and then delegating the construction of the URL
|
||||
* 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 NewConnection(nsIUrl* url,
|
||||
nsISupports* eventSink,
|
||||
nsIConnectionGroup* group,
|
||||
nsIProtocolConnection* *result) = 0;
|
||||
|
||||
/**
|
||||
* @return NS_OK if there are active connections
|
||||
* @return NS_COMFALSE if there are not.
|
||||
*/
|
||||
NS_IMETHOD HasActiveConnections() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIINetService_h___ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- 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
|
||||
|
@ -16,73 +16,52 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsIProtocolHandler_h_
|
||||
#define _nsIProtocolHandler_h_
|
||||
#ifndef nsIProtocolHandler_h___
|
||||
#define nsIProtocolHandler_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIURL.h"
|
||||
|
||||
class nsIConnectionGroup; // This should really be nsIURLGroup. TODO change
|
||||
class nsIConnectionGroup;
|
||||
|
||||
/*
|
||||
The nsIProtocolHandler class is a common interface to all protocols
|
||||
being loaded dynamically. This base interface is required to be
|
||||
derived from, for all protocols that expect to be loaded dynamically.
|
||||
|
||||
Currently this just has functions to identify itself and return a
|
||||
ProtocolInstance for the specified URL. I will add more things after
|
||||
I find out more "common" elements for our two extreme cases HTTP and
|
||||
IMAP/SMTP
|
||||
|
||||
-Gagan Saksena
|
||||
|
||||
*/
|
||||
#define NS_IPROTOCOLHANDLER_IID \
|
||||
{ /* 5da8b1b0-ea35-11d2-931b-00104ba0fd40 */ \
|
||||
0x5da8b1b0, \
|
||||
0xea35, \
|
||||
0x11d2, \
|
||||
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
class nsIProtocolHandler : public nsISupports
|
||||
{
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPROTOCOLHANDLER_IID);
|
||||
|
||||
/*
|
||||
GetDefaultPort returns the default port associated with this
|
||||
protocol.
|
||||
*/
|
||||
NS_IMETHOD_(PRInt32) GetDefaultPort(void) const = 0;
|
||||
NS_IMETHOD GetScheme(const char* *result) = 0;
|
||||
|
||||
/*
|
||||
The GetProtocolInstance function. This function returns a per-URL
|
||||
instance of a dummy class nsIProtocolInstance which could be used
|
||||
for querying and setting per-URL properties of the connection. A
|
||||
protocol implementor may decide to reuse the same connection and
|
||||
hence supply the same protocol instance to handle the specified URL.
|
||||
*/
|
||||
NS_IMETHOD GetProtocolInstance(nsIURL* i_URL,
|
||||
nsIProtocolInstance* *o_Instance,
|
||||
nsIConnectionGroup* i_Group = 0) = 0;
|
||||
NS_IMETHOD GetDefaultPort(PRInt32 *result) = 0;
|
||||
|
||||
/*
|
||||
The GetScheme function uniquely identifies the scheme this handler
|
||||
is associated with.
|
||||
*/
|
||||
NS_IMETHOD GetScheme(const char* *o_Scheme) const = 0;
|
||||
NS_IMETHOD MakeAbsoluteUrl(const char* aSpec,
|
||||
nsIUrl* aBaseUrl,
|
||||
char* *result) = 0;
|
||||
|
||||
/*
|
||||
The Open function directly assumes that the information in the
|
||||
URL and the default header information with this handler is
|
||||
sufficient to make a connection and process the request. So
|
||||
This is the same as getting the protocol instance and right away
|
||||
calling Load on it.
|
||||
*/
|
||||
static const nsIID& GetIID() {
|
||||
// {63E10A11-CD1F-11d2-B013-006097BFC036}
|
||||
static const nsIID NS_IProtocolHandler_IID =
|
||||
{ 0x63e10a11, 0xcd1f, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
|
||||
return NS_IProtocolHandler_IID;
|
||||
};
|
||||
/**
|
||||
* Makes a URL object that is suitable for loading by this protocol.
|
||||
* In the usual case (when only the accessors provided by nsIUrl are
|
||||
* 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 NewConnection(nsIUrl* url,
|
||||
nsISupports* eventSink,
|
||||
nsIConnectionGroup* group,
|
||||
nsIProtocolConnection* *result) = 0;
|
||||
};
|
||||
|
||||
// Base Prog ID! Looks like a url but don't be fooled by its looks... it can kreate ya.
|
||||
#define NS_COMPONENT_NETSCAPE_NETWORK_PROTOCOLS "component://netscape/network/protocols?name="
|
||||
#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)
|
||||
|
||||
#endif /* _nsIProtocolHandler_h_ */
|
||||
#endif /* nsIIProtocolHandler_h___ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- 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
|
||||
|
@ -16,116 +16,117 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsIURL_h_
|
||||
#define _nsIURL_h_
|
||||
#ifndef nsIUrl_h___
|
||||
#define nsIUrl_h___
|
||||
|
||||
/*
|
||||
The nsIURL class is an interface to the URL behaviour.
|
||||
This follows the URL spec at-
|
||||
|
||||
http://www.w3.org/Addressing/URL/url-spec.txt
|
||||
|
||||
For the purpose of this class, here is the most elaborate form of a URL
|
||||
and its corresponding parts-
|
||||
|
||||
ftp://username:password@hostname:portnumber/pathname
|
||||
\ / \ / \ / \ /\ /
|
||||
- --------------- ------ -------- -------
|
||||
| | | | |
|
||||
| | | | Path
|
||||
| | | Port
|
||||
| | Host
|
||||
| PreHost
|
||||
Scheme
|
||||
#include "nsISupports.h"
|
||||
|
||||
The URL class extends the URI behaviour by providing a mechanism
|
||||
for consumers to retreive (and on protocol specific levels put)
|
||||
documents defined by the URI.
|
||||
#undef GetPort // Windows (sigh)
|
||||
|
||||
Functions missing from this file are the stream listener portions
|
||||
for asynch operations. TODO.
|
||||
|
||||
Please send me a mail before you add anything to this file.
|
||||
Thanks!- Gagan Saksena
|
||||
#define NS_IURL_IID \
|
||||
{ /* 82c1b000-ea35-11d2-931b-00104ba0fd40 */ \
|
||||
0x82c1b000, \
|
||||
0xea35, \
|
||||
0x11d2, \
|
||||
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
/**
|
||||
* The nsIURI class is an interface to the URI behaviour for parsing
|
||||
* portions out of a URI. This follows Tim Berners-Lee's URI spec at-
|
||||
*
|
||||
* http://www.w3.org/Addressing/URI/URI_Overview.html
|
||||
*
|
||||
* For the purpose of this class, here is the most elaborate form of a URI
|
||||
* and its corresponding parts-
|
||||
*
|
||||
* ftp://username:password@hostname:portnumber/pathname
|
||||
* \ / \ / \ / \ /\ /
|
||||
* - --------------- ------ -------- -------
|
||||
* | | | | |
|
||||
* | | | | Path
|
||||
* | | | Port
|
||||
* | | Host
|
||||
* | PreHost
|
||||
* Scheme
|
||||
*
|
||||
* Note that this class does not assume knowledge of search/query portions
|
||||
* embedded within the path portion of the URI.
|
||||
*
|
||||
* This class pretty much "final" and there shouldn't be anything added.
|
||||
* If you do feel something belongs here, please do send me a mail. Thanks!
|
||||
*/
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIProtocolInstance.h"
|
||||
|
||||
class nsIURL : public nsIURI
|
||||
class nsIUrl : public nsISupports
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
Used for testing purposes. if you need a string representation for
|
||||
your work, use ToString().
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IURL_IID);
|
||||
|
||||
// Core parsing functions
|
||||
|
||||
/**
|
||||
* The Scheme is the protocol that this URI refers to.
|
||||
*/
|
||||
NS_IMETHOD GetScheme(const char* *result) = 0;
|
||||
NS_IMETHOD SetScheme(const char* scheme) = 0;
|
||||
|
||||
/**
|
||||
* The PreHost portion includes elements like the optional
|
||||
* username:password, or maybe other scheme specific items.
|
||||
*/
|
||||
NS_IMETHOD GetPreHost(const char* *result) = 0;
|
||||
NS_IMETHOD SetPreHost(const char* preHost) = 0;
|
||||
|
||||
/**
|
||||
* The Host is the internet domain name to which this URI refers.
|
||||
* Note that it could be an IP address as well.
|
||||
*/
|
||||
NS_IMETHOD GetHost(const char* *result) = 0;
|
||||
NS_IMETHOD SetHost(const char* host) = 0;
|
||||
|
||||
/**
|
||||
* 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 ToString function.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHOD DebugString(const char* *o_URLString) const=0;
|
||||
#endif //DEBUG
|
||||
NS_IMETHOD GetPort(PRInt32 *result) = 0;
|
||||
NS_IMETHOD SetPort(PRInt32 port) = 0;
|
||||
|
||||
//Core action functions
|
||||
/*
|
||||
Note: The GetStream function also opens a connection using
|
||||
the available information in the URL. This is the same as
|
||||
calling OpenInputStream on the connection returned from
|
||||
OpenProtocolInstance. Note that this stream doesn't contain any
|
||||
header information either.
|
||||
*/
|
||||
NS_IMETHOD GetStream(nsIInputStream* *o_InputStream) = 0;
|
||||
/**
|
||||
* Note that the path includes the leading '/' Thus if no path is
|
||||
* available the GetPath will return a "/"
|
||||
* For SetPath if none is provided, one would be prefixed to the path.
|
||||
*/
|
||||
NS_IMETHOD GetPath(const char* *result) = 0;
|
||||
NS_IMETHOD SetPath(const char* path) = 0;
|
||||
|
||||
#if 0 //Will go away...
|
||||
/*
|
||||
The GetDocument function BLOCKS till the data is made available
|
||||
or an error condition is encountered. The return type is the overall
|
||||
success status which depends on the protocol implementation.
|
||||
Its just a convenience function that internally sets up a temp
|
||||
stream in memory and buffers everything. Note that this
|
||||
mechanism strips off the headers and only the raw data is
|
||||
copied to the passed string.
|
||||
// Other utility functions
|
||||
/**
|
||||
* 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.
|
||||
* @return NS_OK if equal
|
||||
* @return NS_COMFALSE if not equal
|
||||
*/
|
||||
NS_IMETHOD Equals(nsIUrl* other) = 0;
|
||||
|
||||
TODO - return status?
|
||||
*/
|
||||
NS_IMETHOD GetDocument(const char* *o_Data) = 0;
|
||||
#endif
|
||||
/**
|
||||
* Makes a copy of the URL.
|
||||
*/
|
||||
NS_IMETHOD Clone(nsIUrl* *result) = 0;
|
||||
|
||||
/*
|
||||
MakeAbsoluteFrom function takes a new string that is a relative url,
|
||||
and converts this object to represent the final form. As an example
|
||||
if this is "http://foo/bar" and we call MakeAbsoluteFrom("/baz")
|
||||
then this will change to "http://foo/baz" There is a whole series
|
||||
of possibilities here. Check this URL for more details (TODO -Gagan)
|
||||
*/
|
||||
NS_IMETHOD MakeAbsoluteFrom(const char* i_NewURL) = 0;
|
||||
/**
|
||||
* Writes a string representation of the URI.
|
||||
* Free string with delete[].
|
||||
*/
|
||||
NS_IMETHOD ToNewCString(const char* *uriString) = 0;
|
||||
|
||||
/*
|
||||
The OpenProtocolInstance method sets up the connection as decided by the
|
||||
protocol implementation. This may then be used to get various
|
||||
connection specific details like the input and the output streams
|
||||
associated with the connection, or the header information by querying
|
||||
on the connection type which will be protocol specific.
|
||||
|
||||
*/
|
||||
NS_IMETHOD OpenProtocolInstance(nsIProtocolInstance* *o_ProtocolInstance) = 0;
|
||||
|
||||
|
||||
|
||||
static const nsIID& GetIID() {
|
||||
// {6DA32F00-BD64-11d2-B00F-006097BFC036}
|
||||
static const nsIID NS_IURL_IID =
|
||||
{ 0x6da32f00, 0xbd64, 0x11d2, { 0xb0, 0xf, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
|
||||
return NS_IURL_IID;
|
||||
};
|
||||
};
|
||||
|
||||
// Should change to NS_METHOD CreateURL(nsIURL* *o_URL, const char* i_URL)
|
||||
// and be placed where?
|
||||
extern NS_NET
|
||||
nsIURL* CreateURL(const char* i_URL);
|
||||
|
||||
|
||||
#endif /* _nsIURL_h_ */
|
||||
#endif /* nsIIUrl_h___ */
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
|
||||
#include "nsNetService.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsURL.h"
|
||||
#include "nsUrl.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIFileTransportService.h"
|
||||
#include "nsConnectionGroup.h"
|
||||
#include <ctype.h> // for isalpha
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
|
||||
|
||||
|
@ -48,21 +49,27 @@ NS_IMPL_ISUPPORTS(nsNetService, nsINetService::GetIID());
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetService::GetProtocolHandler(nsIURL* url, nsIProtocolHandler* *result)
|
||||
{
|
||||
#if 0 // will fix later...
|
||||
nsresult rv;
|
||||
const char* scheme;
|
||||
|
||||
rv = url->GetScheme(&scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#define MAX_SCHEME_LENGTH 64 // XXX big enough?
|
||||
|
||||
# define BUF_SIZE 128
|
||||
char buf[BUF_SIZE];
|
||||
#define MAX_NET_PROGID_LENGTH (MAX_SCHEME_LENGTH + NS_NETWORK_PROTOCOL_PROGID_PREFIX_LENGTH + 1)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetService::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, BUF_SIZE);
|
||||
progID.ToCString(buf, MAX_NET_PROGID_LENGTH);
|
||||
|
||||
nsIProtocolHandler* handler;
|
||||
rv = nsServiceManager::GetService(buf, nsIProtocolHandler::GetIID(),
|
||||
|
@ -71,7 +78,6 @@ nsNetService::GetProtocolHandler(nsIURL* url, nsIProtocolHandler* *result)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = handler;
|
||||
#endif // fix TODO
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -91,56 +97,93 @@ nsNetService::NewConnectionGroup(nsIConnectionGroup* *result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetService::NewURL(nsIURL* *result,
|
||||
const char* aSpec,
|
||||
const nsIURL* aBaseURL,
|
||||
nsISupports* aContainer)
|
||||
static nsresult
|
||||
GetScheme(const char* url, char* schemeBuf)
|
||||
{
|
||||
#if 0
|
||||
nsresult rv;
|
||||
nsURL* url;
|
||||
if (aBaseURL)
|
||||
{
|
||||
aBaseURL->Clone(&url);
|
||||
PR_ASSERT(url);
|
||||
if (!url)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = url->MakeAbsoluteFrom(aSpec);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete url;
|
||||
url = 0;
|
||||
return rv;
|
||||
// search for something up to a colon, and call it the scheme
|
||||
PRUint32 i = 0;
|
||||
char c;
|
||||
while ((c = *url++) != '\0') {
|
||||
if (c == ':') {
|
||||
schemeBuf[i] = '\0';
|
||||
return NS_OK;
|
||||
}
|
||||
else if (isalpha(c)) {
|
||||
schemeBuf[i] = c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
url = new nsURL(aSpec);
|
||||
if (nsnull == url)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_ADDREF(url);
|
||||
*result = url;
|
||||
#endif // TODO
|
||||
return NS_OK;
|
||||
if (++i == MAX_SCHEME_LENGTH)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetService::MakeAbsoluteUrl(const char* aSpec,
|
||||
nsIUrl* aBaseUrl,
|
||||
char* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
char schemeBuf[MAX_SCHEME_LENGTH];
|
||||
const char* scheme = schemeBuf;
|
||||
rv = GetScheme(aSpec, schemeBuf);
|
||||
// XXX if this succeeds, we could return a copy of aSpec
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = aBaseUrl->GetScheme(&scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsIProtocolHandler* handler;
|
||||
rv = GetProtocolHandler(scheme, &handler);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = handler->MakeAbsoluteUrl(aSpec, aBaseUrl, result);
|
||||
NS_RELEASE(handler);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetService::Open(nsIURL* url, nsISupports* eventSink,
|
||||
nsIConnectionGroup* group,
|
||||
nsIProtocolInstance* *result)
|
||||
nsNetService::NewUrl(nsIUrl* *result,
|
||||
const char* aSpec,
|
||||
nsIUrl* aBaseUrl)
|
||||
{
|
||||
#if 0
|
||||
nsresult rv;
|
||||
char schemeBuf[MAX_SCHEME_LENGTH];
|
||||
const char* scheme = schemeBuf;
|
||||
rv = GetScheme(aSpec, schemeBuf);
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = aBaseUrl->GetScheme(&scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsIProtocolHandler* handler;
|
||||
rv = GetProtocolHandler(url, &handler);
|
||||
rv = GetProtocolHandler(scheme, &handler);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return handler->Open(url, eventSink, group, result);
|
||||
#endif // TODO - there is no open on the handler.
|
||||
return NS_OK;
|
||||
|
||||
rv = handler->NewUrl(result, aSpec, aBaseUrl);
|
||||
NS_RELEASE(handler);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetService::NewConnection(nsIUrl* url,
|
||||
nsISupports* eventSink,
|
||||
nsIConnectionGroup* group,
|
||||
nsIProtocolConnection* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
const char* scheme;
|
||||
rv = url->GetScheme(&scheme);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIProtocolHandler* handler;
|
||||
rv = GetProtocolHandler(scheme, &handler);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = handler->NewConnection(url, eventSink, group, result);
|
||||
NS_RELEASE(handler);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -158,3 +201,5 @@ nsNetService::HasActiveConnections()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
|
|
@ -27,15 +27,18 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsINetService methods:
|
||||
NS_IMETHOD GetProtocolHandler(nsIURL* url, nsIProtocolHandler* *result);
|
||||
NS_IMETHOD GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result);
|
||||
NS_IMETHOD NewConnectionGroup(nsIConnectionGroup* *result);
|
||||
NS_IMETHOD NewURL(nsIURL* *result,
|
||||
NS_IMETHOD MakeAbsoluteUrl(const char* aSpec,
|
||||
nsIUrl* aBaseUrl,
|
||||
char* *result);
|
||||
NS_IMETHOD NewUrl(nsIUrl* *result,
|
||||
const char* aSpec,
|
||||
const nsIURL* aBaseURL = 0,
|
||||
nsISupports* aContainer = 0);
|
||||
NS_IMETHOD Open(nsIURL* url, nsISupports* eventSink,
|
||||
nsIConnectionGroup* aGroup,
|
||||
nsIProtocolInstance* *result);
|
||||
nsIUrl* aBaseUrl);
|
||||
NS_IMETHOD NewConnection(nsIUrl* url,
|
||||
nsISupports* eventSink,
|
||||
nsIConnectionGroup* group,
|
||||
nsIProtocolConnection* *result);
|
||||
NS_IMETHOD HasActiveConnections();
|
||||
|
||||
// nsNetService methods:
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- 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
|
||||
|
@ -16,211 +16,71 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsURL_h_
|
||||
#define _nsURL_h_
|
||||
#ifndef nsUrl_h__
|
||||
#define nsUrl_h__
|
||||
|
||||
/*
|
||||
The nsURL class holds the default implementation of the nsIURL class.
|
||||
For explanation on the implementation see -
|
||||
#include "nsIUrl.h"
|
||||
#include "nsAgg.h"
|
||||
|
||||
http://www.w3.org/Addressing/URL/url-spec.txt
|
||||
and the headers for nsIURL.h and nsIURI.h
|
||||
|
||||
- Gagan Saksena
|
||||
*/
|
||||
// XXX regenerate:
|
||||
#define NS_TYPICALURL_CID \
|
||||
{ /* 8ffae6d0-ee37-11d2-9322-000000000000 */ \
|
||||
0x8ffae6d0, \
|
||||
0xee37, \
|
||||
0x11d2, \
|
||||
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
|
||||
}
|
||||
|
||||
#include "nsIURL.h"
|
||||
|
||||
class nsURL : public nsIURL
|
||||
class nsUrl : public nsIUrl
|
||||
{
|
||||
|
||||
public:
|
||||
//Constructor
|
||||
nsURL(const char* i_URL);
|
||||
|
||||
//Functions from nsISupports
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_AGGREGATED
|
||||
|
||||
//Functions from nsIURI
|
||||
//Core parsing functions.
|
||||
/*
|
||||
The Scheme is the protocol that this URL refers to.
|
||||
*/
|
||||
NS_METHOD GetScheme(const char* *o_Scheme) const;
|
||||
NS_METHOD SetScheme(const char* i_Scheme);
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsIUrl methods:
|
||||
|
||||
/*
|
||||
The PreHost portion includes elements like the optional
|
||||
username:password, or maybe other scheme specific items.
|
||||
*/
|
||||
NS_METHOD GetPreHost(const char* *o_PreHost) const;
|
||||
NS_METHOD SetPreHost(const char* i_PreHost);
|
||||
NS_IMETHOD GetScheme(const char* *result);
|
||||
NS_IMETHOD SetScheme(const char* scheme);
|
||||
|
||||
/*
|
||||
The Host is the internet domain name to which this URL refers.
|
||||
Note that it could be an IP address as well.
|
||||
*/
|
||||
NS_METHOD GetHost(const char* *o_Host) const;
|
||||
NS_METHOD SetHost(const char* i_Host);
|
||||
NS_IMETHOD GetPreHost(const char* *result);
|
||||
NS_IMETHOD SetPreHost(const char* preHost);
|
||||
|
||||
/*
|
||||
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 ToString function.
|
||||
*/
|
||||
NS_METHOD_(PRInt32) GetPort(void) const;
|
||||
NS_METHOD SetPort(PRInt32 i_Port);
|
||||
NS_IMETHOD GetHost(const char* *result);
|
||||
NS_IMETHOD SetHost(const char* host);
|
||||
|
||||
/*
|
||||
Note that the path includes the leading '/' Thus if no path is
|
||||
available the GetPath will return a "/"
|
||||
For SetPath if none is provided, one would be prefixed to the path.
|
||||
*/
|
||||
NS_METHOD GetPath(const char* *o_Path) const;
|
||||
NS_METHOD SetPath(const char* i_Path);
|
||||
NS_IMETHOD GetPort(PRInt32 *result);
|
||||
NS_IMETHOD SetPort(PRInt32 port);
|
||||
|
||||
//Functions from nsIURL.h
|
||||
NS_IMETHOD GetPath(const char* *result);
|
||||
NS_IMETHOD SetPath(const char* path);
|
||||
|
||||
/*
|
||||
Create a copy of this url in the specified location.
|
||||
Use this as much as possible instead of creating a fresh one
|
||||
each time since we save on the parsing overhead.
|
||||
*/
|
||||
NS_METHOD Clone(nsURL* *o_URL) const;
|
||||
NS_IMETHOD Equals(nsIUrl* other);
|
||||
NS_IMETHOD Clone(nsIUrl* *result);
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_METHOD DebugString(const char* *o_URLString) const;
|
||||
#endif //DEBUG
|
||||
NS_IMETHOD ToNewCString(const char* *result);
|
||||
|
||||
/*
|
||||
Note: The GetStream function also opens a connection using
|
||||
the available information in the URL. This is the same as
|
||||
calling OpenInputStream on the connection returned from
|
||||
OpenProtocolInstance.
|
||||
*/
|
||||
NS_METHOD GetStream(nsIInputStream* *o_InputStream);
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsUrl methods:
|
||||
|
||||
/*
|
||||
MakeAbsoluteFrom function takes a new string that is a relative url,
|
||||
and converts this object to represent the final form. As an example
|
||||
if this is "http://foo/bar" and we call MakeAbsoluteFrom("/baz")
|
||||
then this will change to "http://foo/baz" There is a whole series
|
||||
of possibilities here. Check this URL for more details (TODO -Gagan)
|
||||
*/
|
||||
NS_METHOD MakeAbsoluteFrom(const char* i_NewURL);
|
||||
nsUrl(nsISupports* outer);
|
||||
virtual ~nsUrl();
|
||||
|
||||
/*
|
||||
The OpenProtocolInstance method sets up the connection as decided by the
|
||||
protocol implementation. This may then be used to get various
|
||||
connection specific details like the input and the output streams
|
||||
associated with the connection, or the header information by querying
|
||||
on the connection type which will be protocol specific.
|
||||
*/
|
||||
NS_METHOD OpenProtocolInstance(nsIProtocolInstance* *o_ProtocolInstance);
|
||||
|
||||
|
||||
//Other utility functions
|
||||
/*
|
||||
Note that this comparison is only on char* level. Cast nsIURL to
|
||||
the scheme specific URL to do a more thorough check. For example--
|
||||
in HTTP-
|
||||
http://foo.com:80 == http://foo.com
|
||||
but this function through nsIURL alone will not return equality.
|
||||
*/
|
||||
NS_METHOD_(PRBool) Equals(const nsIURI* i_URI) const;
|
||||
|
||||
/*
|
||||
Writes a string representation of the URL.
|
||||
*/
|
||||
NS_METHOD ToString(const char* *o_URLString) const;
|
||||
nsresult Init(const char* aSpec,
|
||||
nsIUrl* aBaseURL);
|
||||
|
||||
protected:
|
||||
|
||||
//Called only from Release
|
||||
virtual ~nsURL();
|
||||
nsresult Parse(const char* spec, nsIUrl* aBaseUrl);
|
||||
void ReconstructSpec();
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SCHEME,
|
||||
PREHOST,
|
||||
HOST,
|
||||
PATH,
|
||||
TOTAL_PARTS // Must always be the last one.
|
||||
} Part;
|
||||
|
||||
/*
|
||||
Parses the portions of the URL into individual pieces
|
||||
like spec, prehost, host, path etc.
|
||||
*/
|
||||
NS_METHOD Parse();
|
||||
|
||||
/*
|
||||
Extract a portion from the given part id.
|
||||
*/
|
||||
NS_METHOD Extract(const char* *o_OutputString, Part i_id) const;
|
||||
|
||||
/*
|
||||
This holds the offsets and the lengths of each part.
|
||||
Optimizes on storage and speed.
|
||||
*/
|
||||
int m_Position[TOTAL_PARTS][2];
|
||||
|
||||
char* m_URL;
|
||||
PRInt32 m_Port;
|
||||
private:
|
||||
NS_METHOD ExtractPortFrom(int start, int length);
|
||||
protected:
|
||||
char* mScheme;
|
||||
char* mPreHost;
|
||||
char* mHost;
|
||||
PRInt32 mPort;
|
||||
char* mPath;
|
||||
char* mRef;
|
||||
char* mQuery;
|
||||
char* mSpec; // XXX go away
|
||||
};
|
||||
|
||||
inline
|
||||
NS_METHOD
|
||||
nsURL::GetHost(const char* *o_Host) const
|
||||
{
|
||||
return Extract(o_Host, HOST);
|
||||
}
|
||||
|
||||
inline
|
||||
NS_METHOD
|
||||
nsURL::GetScheme(const char* *o_Scheme) const
|
||||
{
|
||||
return Extract(o_Scheme, SCHEME);
|
||||
}
|
||||
|
||||
inline
|
||||
NS_METHOD
|
||||
nsURL::GetPreHost(const char* *o_PreHost) const
|
||||
{
|
||||
return Extract(o_PreHost, PREHOST);
|
||||
}
|
||||
|
||||
inline
|
||||
NS_METHOD_(PRInt32)
|
||||
nsURL::GetPort() const
|
||||
{
|
||||
return m_Port;
|
||||
}
|
||||
|
||||
inline
|
||||
NS_METHOD
|
||||
nsURL::GetPath(const char* *o_Path) const
|
||||
{
|
||||
return Extract(o_Path, PATH);
|
||||
}
|
||||
|
||||
inline
|
||||
NS_METHOD
|
||||
nsURL::ToString(const char* *o_URLString) const
|
||||
{
|
||||
*o_URLString = m_URL;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//Possible bad url passed.
|
||||
#define NS_ERROR_URL_PARSING NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 100);
|
||||
#define NS_ERROR_BAD_URL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 101);
|
||||
|
||||
#endif /* _nsURL_h_ */
|
||||
#endif // nsUrl_h__
|
||||
|
|
|
@ -30,6 +30,7 @@ LLIBS= \
|
|||
$(DIST)\lib\netwerkbase_s.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
MISCDEP=$(LLIBS)
|
||||
|
|
|
@ -22,10 +22,12 @@
|
|||
#include "nsNetService.h"
|
||||
#include "nsFileTransportService.h"
|
||||
#include "nscore.h"
|
||||
#include "nsUrl.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kNetServiceCID, NS_NETSERVICE_CID);
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kTypicalUrlCID, NS_TYPICALURL_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -76,11 +78,10 @@ nsNetFactory::CreateInstance(nsISupports *aOuter,
|
|||
if (aResult == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kNetServiceCID)) {
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsNetService* net = new nsNetService();
|
||||
if (net == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -92,6 +93,8 @@ nsNetFactory::CreateInstance(nsISupports *aOuter,
|
|||
inst = net;
|
||||
}
|
||||
else if (mClassID.Equals(kFileTransportServiceCID)) {
|
||||
if (aOuter) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsFileTransportService* trans = new nsFileTransportService();
|
||||
if (trans == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -102,6 +105,19 @@ nsNetFactory::CreateInstance(nsISupports *aOuter,
|
|||
}
|
||||
inst = trans;
|
||||
}
|
||||
else if (mClassID.Equals(kFileTransportServiceCID)) {
|
||||
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 {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче