зеркало из https://github.com/mozilla/pjs.git
Began fleshing out http protocol.
This commit is contained in:
Родитель
d80503f3dd
Коммит
e9faed107d
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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___ */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,581 +0,0 @@
|
|||
/* -*- 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 "nsUrl.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
|
||||
static NS_DEFINE_CID(kTypicalUrlCID, NS_TYPICALURL_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsUrl methods:
|
||||
|
||||
nsUrl::nsUrl(nsISupports* outer)
|
||||
: mScheme(nsnull),
|
||||
mPreHost(nsnull),
|
||||
mHost(nsnull),
|
||||
mPort(-1),
|
||||
mPath(nsnull),
|
||||
mRef(nsnull),
|
||||
mQuery(nsnull),
|
||||
mSpec(nsnull)
|
||||
{
|
||||
NS_INIT_AGGREGATED(outer);
|
||||
}
|
||||
|
||||
nsUrl::~nsUrl()
|
||||
{
|
||||
if (mScheme) delete[] mScheme;
|
||||
if (mPreHost) delete[] mPreHost;
|
||||
if (mHost) delete[] mHost;
|
||||
if (mRef) delete[] mRef;
|
||||
if (mQuery) delete[] mQuery;
|
||||
if (mSpec) delete[] mSpec;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsUrl::Init(const char* aSpec,
|
||||
nsIUrl* aBaseUrl)
|
||||
{
|
||||
return Parse(aSpec, aBaseUrl);
|
||||
}
|
||||
|
||||
NS_IMPL_AGGREGATED(nsUrl);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_ASSERTION(aInstancePtr, "no instance pointer");
|
||||
if (aIID.Equals(kTypicalUrlCID) || // used by Equals
|
||||
aIID.Equals(nsIUrl::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIUrl*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIUrl methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::GetScheme(const char* *result)
|
||||
{
|
||||
*result = mScheme;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::SetScheme(const char* scheme)
|
||||
{
|
||||
mScheme = nsCRT::strdup(scheme);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::GetPreHost(const char* *result)
|
||||
{
|
||||
*result = mPreHost;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::SetPreHost(const char* preHost)
|
||||
{
|
||||
mPreHost = nsCRT::strdup(preHost);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::GetHost(const char* *result)
|
||||
{
|
||||
*result = mHost;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::SetHost(const char* host)
|
||||
{
|
||||
mHost = nsCRT::strdup(host);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::GetPort(PRInt32 *result)
|
||||
{
|
||||
*result = mPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::SetPort(PRInt32 port)
|
||||
{
|
||||
mPort = port;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::GetPath(const char* *result)
|
||||
{
|
||||
*result = mPath;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::SetPath(const char* path)
|
||||
{
|
||||
mPath = nsCRT::strdup(path);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::Equals(nsIUrl* other)
|
||||
{
|
||||
PRBool eq = PR_FALSE;
|
||||
if (other) {
|
||||
// NS_LOCK_INSTANCE();
|
||||
nsUrl* otherUrl;
|
||||
if (NS_SUCCEEDED(other->QueryInterface(kTypicalUrlCID, (void**)&otherUrl))) {
|
||||
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();
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::Clone(nsIUrl* *result)
|
||||
{
|
||||
nsUrl* url = new nsUrl(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;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrl::ToNewCString(const 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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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
|
||||
nsUrl::Parse(const char* spec, nsIUrl* aBaseUrl)
|
||||
{
|
||||
// XXX hack!
|
||||
nsString specStr(spec);
|
||||
|
||||
const char* uProtocol = nsnull;
|
||||
const char* uHost = nsnull;
|
||||
const 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
|
||||
nsUrl::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);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -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();
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
||||
|
|
@ -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___ */
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -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___ */
|
|
@ -19,7 +19,8 @@ DEPTH = ..\..
|
|||
|
||||
MODULE = netwerk
|
||||
|
||||
#DIRS= \
|
||||
# $(NULL)
|
||||
DIRS= \
|
||||
http \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
Загрузка…
Ссылка в новой задаче