NuNet. Not in the build yet. First checkin.... miles to go before I sleep (or work)

This commit is contained in:
gagan%netscape.com 1999-03-22 23:46:37 +00:00
Родитель 2fea5b1c6b
Коммит d046261255
20 изменённых файлов: 2029 добавлений и 0 удалений

25
nunet/base/makefile.win Normal file
Просмотреть файл

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

Просмотреть файл

@ -0,0 +1,66 @@
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
NODEPEND=1
IGNORE_MANIFEST = 1
MODULE = nunet
DEPTH= ..\..\..
include <$(DEPTH)/config/config.mak>
MAKE_OBJ_TYPE=DLL
DLLNAME=nunet.dll
PDBFILE=nunet.pdb
MAPFILE=nunet.map
DEFFILE=nunet.def
#// Currently the HTTP handler is being built together with core.
#// It needs to move to its own dir, once the kinks of dynamic
#// registration are resolved.
OBJS= \
.\$(OBJDIR)\nsURL.obj \
.\$(OBJDIR)\nsHTTPHandler.obj \
.\$(OBJDIR)\nsHTTPInstance.obj \
$(NULL)
DLL=.\$(OBJDIR)\$(DLLNAME)
LCFLAGS=-DNETSCAPE -D_IMPL_NS_NET
LLIBS=$(LLIBS) $(LIBNSPR) \
$(DIST)\lib\plc3.lib \
$(DIST)\lib\js32$(VERSION_NUMBER).lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(NULL)
LINCS=$(LINCS) -I. \
-I..\..\public \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\security \
-I$(PUBLIC)\js \
-I$(PUBLIC)\xpcom \
$(NULL)
# clobber and clobber_all will remove the following garbage:
GARBAGE = $(GARBAGE) _gen
include <$(DEPTH)/config/rules.mak>
libs:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME) $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\nunet.lib $(DIST)\lib

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

628
nunet/base/src/nsURL.cpp Normal file
Просмотреть файл

@ -0,0 +1,628 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// TODOs for this file-
// - Check error states returned from all occurences of ExtractPortFrom
// - Grep on other TODOs...
//
#include "nsURL.h"
#include <stdlib.h>
#include "plstr.h"
#include "nsIProtocolHandler.h"
#include "nsIHTTPHandler.h" // This will go away with DPs work.
static const PRInt32 DEFAULT_PORT = -1;
#define SET_POSITION(__part,__start,__length) \
{ \
m_Position[__part][0] = __start; \
m_Position[__part][1] = __length; \
}
NS_NET
nsICoolURL* CreateURL(const char* i_URL)
{
nsICoolURL* pReturn = new nsURL(i_URL);
if (pReturn)
pReturn->AddRef();
return pReturn;
}
nsURL::nsURL(const char* i_URL):m_Port(DEFAULT_PORT),mRefCnt(0)
{
NS_PRECONDITION( (0 != i_URL), "No url string specified!");
if (i_URL)
{
m_URL = new char[PL_strlen(i_URL) + 1];
if (m_URL)
{
PL_strcpy(m_URL, i_URL);
}
}
else
{
m_URL = new char[1];
*m_URL = '\0';
}
for (int i=0; i<TOTAL_PARTS; ++i)
{
for (int j=0; j<2; ++j)
{
m_Position[i][j] = -1;
}
}
Parse();
}
nsURL::~nsURL()
{
if (m_URL)
{
delete[] m_URL;
m_URL = 0;
}
}
NS_IMPL_ADDREF(nsURL);
PRBool
nsURL::Equals(const nsIURI* i_URI) const
{
NS_NOTYETIMPLEMENTED("Eeeks!");
return PR_FALSE;
}
nsresult
nsURL::Extract(const char* *o_OutputString, nsURL::Part i_id) const
{
int i = (int) i_id;
if (o_OutputString)
{
*o_OutputString = new char(m_Position[i][1]+1);
if (!*o_OutputString)
return NS_ERROR_OUT_OF_MEMORY;
char* dest = (char*) *o_OutputString;
char* src = m_URL + m_Position[i][0];
for (int j=0; j<m_Position[i][1]; ++j)
{
*dest++ = *src++;
}
*dest = '\0';
return NS_OK;
}
return NS_ERROR_URL_PARSING;
}
nsresult
nsURL::ExtractPortFrom(int start, int length)
{
char* port = new char[length +1];
if (!port)
{
return NS_ERROR_OUT_OF_MEMORY;
}
PL_strncpy(port, m_URL+start, length);
*(port + length) = '\0';
m_Port = atoi(port);
delete[] port;
return NS_OK;
}
nsresult
nsURL::GetStream(nsIInputStream* *o_InputStream)
{
NS_PRECONDITION( (0 != m_URL), "GetStream called on empty url!");
nsresult result = NS_OK; // change to failure
//OpenProtocolInstance and request the input stream
nsIProtocolInstance* pi = 0;
result = OpenProtocolInstance(&pi);
if (NS_OK != result)
return result;
return pi->GetInputStream(o_InputStream);
}
nsresult nsURL::OpenProtocolInstance(nsIProtocolInstance* *o_ProtocolInstance)
{
const char* scheme =0;
GetScheme(&scheme);
// If the expected behaviour is to have http as the default scheme, a
// caller must check that before calling this function.
if (0 == scheme)
return NS_ERROR_BAD_URL;
// Here we should check with the repository for a
// protocol handler that can handle this scheme.
// Then assuming this is class returned
nsISupports* iFoo= 0;
#if 0 //Turned on with DPs code to check from Repository as above.
if (iFoo)
{
nsIProtocolHandler *pHandler=0;
if (NS_OK == iFoo->QueryInterface(nsIProtocolHandler::GetIID(), (void**)&pHandler)))
{
return pHandler->GetProtocolInstance(this, o_ProtocolInstance);
}
}
else
return NS_ERROR_NO_PROTOCOL_FOUND; // ??? This the right error or check with repository for error?
#else // For now hardcode it...
if (0==PL_strcasecmp(scheme, "http"))
{
nsIHTTPHandler* pHandler= 0;
if (NS_OK == CreateOrGetHTTPHandler(&pHandler))
{
if (pHandler)
{
return pHandler->GetProtocolInstance(this, o_ProtocolInstance);
}
}
}
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
// This code will need thorough testing. A lot of this has to do with
// usability and expected behaviour when a user types something in the
// location bar.
nsresult nsURL::Parse(void)
{
NS_PRECONDITION( (0 != m_URL), "Parse called on empty url!");
if (!m_URL)
{
return NS_ERROR_URL_PARSING;
}
//Remember to remove leading/trailing spaces, etc. TODO
int len = PL_strlen(m_URL);
static const char delimiters[] = "/:@"; //this order is optimized.
char* brk = PL_strpbrk(m_URL, delimiters);
char* lastbrk = brk;
if (brk)
{
switch (*brk)
{
case '/' :
// If the URL starts with a slash then everything is a path
if (brk == m_URL)
{
SET_POSITION(PATH, 0, len);
return NS_OK;
}
else // The first part is host, so its host/path
{
SET_POSITION(HOST, 0, (brk - m_URL));
SET_POSITION(PATH, (brk - m_URL), (len - (brk - m_URL)));
return NS_OK;
}
break;
case ':' :
// If the first colon is followed by // then its definitely a spec
if ((*(brk+1) == '/') && (*(brk+2) == '/')) // e.g. http://
{
SET_POSITION(SCHEME, 0, (brk - m_URL));
lastbrk = brk+3;
brk = PL_strpbrk(lastbrk, delimiters);
if (brk)
{
switch (*brk)
{
case '/' : // standard case- http://host/path
SET_POSITION(HOST, (lastbrk - m_URL), (brk - lastbrk));
SET_POSITION(PATH, (brk - m_URL), (len - (brk - m_URL)));
return NS_OK;
break;
case ':' :
{
// It could be http://user:pass@host/path or http://host:port/path
// For the first case, there has to be an at after this colon, so...
char* atSign = PL_strchr(brk, '@');
if (atSign)
{
SET_POSITION(PREHOST, (lastbrk - m_URL), (atSign - lastbrk));
brk = PL_strpbrk(atSign+1, "/:");
if (brk) // http://user:pass@host:port/path or http://user:pass@host/path
{
SET_POSITION(HOST, (atSign+1 - m_URL), (brk - (atSign+1)));
if (*brk == '/')
{
SET_POSITION(PATH, (brk - m_URL), len - (brk - m_URL));
return NS_OK;
}
else // we have a port since (brk == ':')
{
lastbrk = brk+1;
brk = PL_strchr(lastbrk, '/');
if (brk) // http://user:pass@host:port/path
{
ExtractPortFrom((lastbrk - m_URL), (brk-lastbrk));
SET_POSITION(PATH, (brk-m_URL), len - (brk-m_URL));
return NS_OK;
}
else // http://user:pass@host:port
{
ExtractPortFrom((lastbrk - m_URL), len - (lastbrk - m_URL));
return NS_OK;
}
}
}
else // its just http://user:pass@host
{
SET_POSITION(HOST, (atSign+1 - m_URL), len - (atSign+1 - m_URL));
return NS_OK;
}
}
else // definitely the port option, i.e. http://host:port/path
{
SET_POSITION(HOST, (lastbrk-m_URL), (brk-lastbrk));
lastbrk = brk+1;
brk = PL_strchr(lastbrk, '/');
if (brk) // http://host:port/path
{
ExtractPortFrom((lastbrk-m_URL),(brk-lastbrk));
SET_POSITION(PATH, (brk-m_URL), len - (brk-m_URL));
return NS_OK;
}
else // http://host:port
{
ExtractPortFrom((lastbrk-m_URL),len - (lastbrk-m_URL));
return NS_OK;
}
}
}
break;
case '@' :
// http://user@host...
{
SET_POSITION(PREHOST, (lastbrk-m_URL), (brk-lastbrk));
lastbrk = brk+1;
brk = PL_strpbrk(lastbrk, ":/");
if (brk)
{
SET_POSITION(HOST, (lastbrk-m_URL), (brk - lastbrk));
if (*brk == ':') // http://user@host:port...
{
lastbrk = brk+1;
brk = PL_strchr(lastbrk, '/');
if (brk) // http://user@host:port/path
{
ExtractPortFrom((lastbrk-m_URL),(brk-lastbrk));
SET_POSITION(PATH, (brk-m_URL), len - (brk-m_URL));
return NS_OK;
}
else // http://user@host:port
{
ExtractPortFrom((lastbrk-m_URL),len - (lastbrk-m_URL));
return NS_OK;
}
}
else // (*brk == '/') so no port just path i.e. http://user@host/path
{
SET_POSITION(PATH, (brk - m_URL), len - (brk - m_URL));
return NS_OK;
}
}
else // its just http://user@host
{
SET_POSITION(HOST, (lastbrk+1 - m_URL), len - (lastbrk+1 - m_URL));
return NS_OK;
}
}
break;
default: NS_POSTCONDITION(0, "This just can't be!");
break;
}
}
else // everything else is a host, as in http://host
{
SET_POSITION(HOST, (lastbrk - m_URL), len - (lastbrk - m_URL));
return NS_OK;
}
}
else // host:port...
{
SET_POSITION(HOST, 0, (brk - m_URL));
lastbrk = brk+1;
brk = PL_strpbrk(lastbrk, delimiters);
if (brk)
{
switch (*brk)
{
case '/' : // The path, so its host:port/path
ExtractPortFrom(lastbrk-m_URL, brk-lastbrk);
SET_POSITION(PATH, brk- m_URL, len - (brk-m_URL));
return NS_OK;
break;
case ':' :
return NS_ERROR_URL_PARSING;
break;
case '@' :
// This is a special case of user:pass@host... so
// Cleanout our earliar knowledge of host
SET_POSITION(HOST, -1, -1);
SET_POSITION(PREHOST, 0, (brk-m_URL));
lastbrk = brk+1;
brk = PL_strpbrk(lastbrk, ":/");
if (brk)
{
SET_POSITION(HOST, (lastbrk-m_URL), (brk-lastbrk));
if (*brk == ':') // user:pass@host:port...
{
lastbrk = brk+1;
brk = PL_strchr(lastbrk, '/');
if (brk) // user:pass@host:port/path
{
ExtractPortFrom((lastbrk-m_URL),(brk-lastbrk));
SET_POSITION(PATH, (brk-m_URL), len - (brk-m_URL));
return NS_OK;
}
else // user:pass@host:port
{
ExtractPortFrom((lastbrk-m_URL),len - (lastbrk-m_URL));
return NS_OK;
}
}
else // (*brk == '/') so user:pass@host/path
{
SET_POSITION(PATH, (brk - m_URL), len - (brk - m_URL));
return NS_OK;
}
}
else // its user:pass@host so everthing else is just the host
{
SET_POSITION(HOST, (lastbrk-m_URL), len - (lastbrk-m_URL));
return NS_OK;
}
break;
default: NS_POSTCONDITION(0, "This just can't be!");
break;
}
}
else // Everything else is just the port
{
ExtractPortFrom(lastbrk-m_URL, len - (lastbrk-m_URL));
return NS_OK;
}
}
break;
case '@' :
//Everything before the @ is the prehost stuff
SET_POSITION(PREHOST, 0, brk-m_URL);
lastbrk = brk+1;
brk = PL_strpbrk(lastbrk, ":/");
if (brk)
{
SET_POSITION(HOST, (lastbrk-m_URL), (brk-lastbrk));
if (*brk == ':') // user@host:port...
{
lastbrk = brk+1;
brk = PL_strchr(lastbrk, '/');
if (brk) // user@host:port/path
{
ExtractPortFrom((lastbrk-m_URL),(brk-lastbrk));
SET_POSITION(PATH, (brk-m_URL), len - (brk-m_URL));
return NS_OK;
}
else // user@host:port
{
ExtractPortFrom((lastbrk-m_URL),len - (lastbrk-m_URL));
return NS_OK;
}
}
else // (*brk == '/') so user@host/path
{
SET_POSITION(PATH, (brk - m_URL), len - (brk - m_URL));
return NS_OK;
}
}
else // its user@host so everything else is just the host
{
SET_POSITION(HOST, (lastbrk-m_URL), (len - (lastbrk-m_URL)));
return NS_OK;
}
break;
default:
NS_POSTCONDITION(0, "This just can't be!");
break;
}
}
else // everything is a host
{
SET_POSITION(HOST, 0, len);
}
return NS_OK;
}
nsresult
nsURL::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = NULL;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(nsICoolURL::GetIID())) {
*aInstancePtr = (void*) ((nsICoolURL*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIURI::GetIID())) {
*aInstancePtr = (void*) ((nsIURI*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_RELEASE(nsURL);
nsresult
nsURL::SetHost(const char* i_Host)
{
NS_NOTYETIMPLEMENTED("Eeeks!");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsURL::SetPath(const char* i_Path)
{
NS_NOTYETIMPLEMENTED("Eeeks!");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsURL::SetPort(PRInt32 i_Port)
{
if (m_Port != i_Port)
{
m_Port = i_Port;
if (DEFAULT_PORT == m_Port)
{
//Just REMOVE the earliar one.
NS_NOTYETIMPLEMENTED("Eeeks!");
}
else
{
//Insert the string equivalent
NS_NOTYETIMPLEMENTED("Eeeks!");
}
Parse();
}
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsURL::SetPreHost(const char* i_PreHost)
{
NS_NOTYETIMPLEMENTED("Eeeks!");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsURL::SetScheme(const char* i_Scheme)
{
NS_NOTYETIMPLEMENTED("Eeeks!");
return NS_ERROR_NOT_IMPLEMENTED;
}
#ifdef DEBUG
nsresult
nsURL::DebugString(const char* *o_String) const
{
if (!m_URL)
return NS_OK;
const char* tempBuff = 0;
char* tmp = new char[PL_strlen(m_URL) + 64];
char* tmp2 = tmp;
for (int i=PL_strlen(m_URL)+64; i>0 ; --i)
*tmp2++ = '\0';
/*///
PL_strcpy(tmp, "m_URL= ");
PL_strcat(tmp, m_URL);
GetScheme(&tempBuff);
PL_strcat(tmp, "\nScheme= ");
PL_strcat(tmp, tempBuff);
GetPreHost(&tempBuff);
PL_strcat(tmp, "\nPreHost= ");
PL_strcat(tmp, tempBuff);
GetHost(&tempBuff);
PL_strcat(tmp, "\nHost= ");
PL_strcat(tmp, tempBuff);
char* tempPort = new char[6];
if (tempPort)
{
itoa(m_Port, tempPort, 10);
PL_strcat(tmp, "\nPort= ");
PL_strcat(tmp, tempPort);
delete[] tempPort;
}
else
PL_strcat(tmp, "\nPort couldn't be conv'd to string!");
GetPath(&tempBuff);
PL_strcat(tmp, "\nPath= ");
PL_strcat(tmp, tempBuff);
PL_strcat(tmp, "\n");
/*///
char delimiter[] = ",";
#define TEMP_AND_DELIMITER PL_strcat(tmp, tempBuff); \
PL_strcat(tmp, delimiter)
PL_strcpy(tmp, m_URL);
PL_strcat(tmp, "\n");
GetScheme(&tempBuff);
TEMP_AND_DELIMITER;
GetPreHost(&tempBuff);
TEMP_AND_DELIMITER;
GetHost(&tempBuff);
TEMP_AND_DELIMITER;
char* tempPort = new char[6];
if (tempPort)
{
itoa(m_Port, tempPort, 10);
PL_strcat(tmp, tempPort);
PL_strcat(tmp, delimiter);
delete[] tempPort;
}
else
PL_strcat(tmp, "\nPort couldn't be conv'd to string!");
GetPath(&tempBuff);
PL_strcat(tmp, tempBuff);
PL_strcat(tmp, "\n");
//*///
*o_String = tmp;
return NS_OK;
}
#endif // DEBUG

209
nunet/base/src/nsURL.h Normal file
Просмотреть файл

@ -0,0 +1,209 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsURL_h_
#define _nsURL_h_
/*
The nsURL class holds the default implementation of the nsICoolURL class.
For explaination on the implementation see -
http://www.w3.org/Addressing/URL/url-spec.txt
and the headers for nsICoolURL.h and nsIURI.h
- Gagan Saksena
*/
#include "nsICoolURL.h"
class nsURL : public nsICoolURL
{
public:
//Constructor
nsURL(const char* i_URL);
//Functions from nsISupports
NS_DECL_ISUPPORTS
//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);
/*
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);
/*
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);
/*
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);
/*
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);
//Functions from nsICoolURL.h
/*
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);
/*
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;
#ifdef DEBUG
NS_METHOD DebugString(const char* *o_URLString) const;
#endif //DEBUG
protected:
//Called only from Release
virtual ~nsURL();
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);
};
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_ */

17
nunet/base/src/nunet.def Normal file
Просмотреть файл

@ -0,0 +1,17 @@
; 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.
LIBRARY nunet.dll

Просмотреть файл

@ -0,0 +1,60 @@
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
NODEPEND=1
IGNORE_MANIFEST = 1
MODULE = urltest
DEPTH= ..\..\..
MAKE_OBJ_TYPE=EXE
EXENAME=urltest
PDBFILE=nunettest.pdb
MAPFILE=nunettest.map
OBJS= \
.\$(OBJDIR)\urltest.obj \
$(NULL)
PROGRAM=.\$(OBJDIR)\$(EXENAME).EXE
LCFLAGS=-DNETSCAPE
LLIBS=$(LLIBS) \
$(LIBNSPR) \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\nunet.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\plc3.lib
LINCS=$(LINCS) -I. \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\nunet \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\xpcom
# clobber and clobber_all will remove the following garbage:
GARBAGE = $(GARBAGE) _gen
include <$(DEPTH)/config/rules.mak>
install:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\$(EXENAME).exe

Просмотреть файл

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

30
nunet/makefile.win Normal file
Просмотреть файл

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

33
nunet/public/makefile.win Normal file
Просмотреть файл

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

114
nunet/public/nsICoolURL.h Normal file
Просмотреть файл

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsICoolURL_h_
#define _nsICoolURL_h_
/*
The nsICoolURL 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
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.
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
*/
#include "nsIURI.h"
#include "nsIInputStream.h"
#include "nsIProtocolInstance.h"
class nsICoolURL : public nsIURI
{
public:
//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;
#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.
TODO - return status?
*/
NS_IMETHOD GetDocument(const char* *o_Data) = 0;
#endif
/*
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;
#ifdef DEBUG
NS_IMETHOD DebugString(const char* *o_URLString) const=0;
#endif //DEBUG
static const nsIID& GetIID() {
// {6DA32F00-BD64-11d2-B00F-006097BFC036}
static const nsIID NS_ICOOLURL_IID =
{ 0x6da32f00, 0xbd64, 0x11d2, { 0xb0, 0xf, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
return NS_ICOOLURL_IID;
};
};
// Should change to NS_METHOD CreateURL(nsICoolURL* *o_URL, const char* i_URL)
// and be placed where?
extern NS_NET
nsICoolURL* CreateURL(const char* i_URL);
#endif /* _nsICoolURL_h_ */

Просмотреть файл

@ -0,0 +1,80 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIHTTPHandler_h_
#define _nsIHTTPHandler_h_
#include "nsIProtocolHandler.h"
/*
The nsIHTTPHandler class is the bare minimum interface expected for
an HTTP handler. The set of interfaces this handler is derived from decides
the expected behaviour. For example another HTTPHandler may decide
not to use proxies or to support proxy connections, in which case
it will not derive from nsIProxy.
-Gagan Saksena 02/25/99
*/
class nsIHTTPHandler : public nsIProtocolHandler//, public nsIProxy
// TODO should also have caching interfaces
// as well as security stuff, etc.
{
public:
/*
GetDefaultPort returns the default port associated with this
protocol.
*/
NS_METHOD_(PRInt32) GetDefaultPort(void) const
{
static const PRInt32 defaultPort = 80;
return defaultPort;
};
/*
The GetScheme function uniquely identifies the scheme this handler
is associated with.
*/
NS_METHOD GetScheme(const char* *o_Scheme) const
{
static const char* scheme = "http";
*o_Scheme = scheme;
return NS_OK;
};
static const nsIID& GetIID() {
// {A3BE3AF0-CD2D-11d2-B013-006097BFC036}
static const nsIID NS_IHTTPHandler_IID =
{ 0xa3be3af0, 0xcd2d, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
return NS_IHTTPHandler_IID;
};
protected:
};
//Possible errors
#define NS_ERROR_BAD_REQUEST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 200);
//TODO think where this should be placed.
extern NS_METHOD CreateOrGetHTTPHandler(nsIHTTPHandler* *o_HTTPHandler);
#endif /* _nsIHTTPHandler_h_ */

Просмотреть файл

@ -0,0 +1,116 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIHTTPInstance_h_
#define _nsIHTTPInstance_h_
#include "nsIProtocolInstance.h"
typedef enum {
HTTP_ZERO_NINE, // HTTP/0.9
HTTP_ONE_ZERO, // HTTP/1.0
HTTP_ONE_ONE // HTTP/1.1
} HTTPVersion;
/*
The nsIHTTPInstance class is the interface to an intance
of the HTTP that acts on a per URL basis.
There are a ton of things that an instance should hold
but due to the lack of time I am letting those things
be used from the old code base. Someday someone will
step in and get rid of old code and put things here
like socket, other connection data, etc.
-Gagan Saksena 03/06/99
*/
class nsIHTTPInstance : public nsIProtocolInstance
{
public:
#if 0 // TODO Past N2 things. As much as I want it now.... so much
// to do and so little resources. Argh...!
// Will have to write nsIHTTPRequest and nsIHTTPResponse classes
// both derived from nsIHeader. The response's setheader should
// return NS_ERROR_ARE_YOU_NUTS?
// TODO think if the Request/Response should move out in
// its own interface. Would other protocols like to
// share this interface?
/*
Request functions-
These functions set/get parameters on the outbound request and may only
be set before Load() function gets called. Calling them after
the Load() method will result in a NS_ERROR_ALREADY_CONNECTED
*/
NS_IMETHOD GetRequest(nsIHTTPRequest* *o_Request) const = 0;
NS_IMETHOD SetRequest(nsIHTTPRequest* i_Request) = 0;
/*
Response funtion. A call to this implicitly calls Load() on this
protocol instance. Thats why it's not const.
*/
NS_IMETHOD GetResponse(nsIHTTPResponse* *o_Response) = 0;
#endif // Past N2 things...
// All request functions before the Load gets called. These
// should move to nsIHTTPRequest
/*
I am not describing each since most are obvious and then
it would be better to describe them in nsIHTTPRequest
For most of these headers there is a default that gets
set in a default HTTP request which can be modified from the
nsIHTTPHandler.
This is definitely not the complete set. But nsIHTTPRequest will
have it. TODO...
*/
NS_IMETHOD SetAccept(const char* i_AcceptHeader) = 0;
//NS_IMETHOD SetAcceptType() = 0;
NS_IMETHOD SetCookie(const char* i_Cookie) = 0;
NS_IMETHOD SetUserAgent(const char* i_UserAgent) = 0;
NS_IMETHOD SetHTTPVersion(HTTPVersion i_Version = HTTP_ONE_ONE) = 0;
// All response functions which if called, will call Load implicitly.
// Should move these to nsIHTTPResponse.
NS_IMETHOD_(PRInt32) GetContentLength(void) const = 0;
NS_IMETHOD GetContentType(const char* *o_Type) const = 0;
//NS_IMETHOD_(PRTime) GetDate(void) const = 0;
NS_IMETHOD_(PRInt32) GetResponseStatus(void) const = 0;
NS_IMETHOD GetResponseString(const char* *o_String) const = 0;
NS_IMETHOD GetServer(const char* *o_String) const = 0;
static const nsIID& GetIID() {
// {843D1020-D0DF-11d2-B013-006097BFC036}
static const nsIID NS_IHTTPInstance_IID =
{ 0x843d1020, 0xd0df, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
return NS_IHTTPInstance_IID;
};
};
//Possible errors
//#define NS_ERROR_WHATEVER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 400);
#endif /* _nsIHTTPInstance_h_ */

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIProtocolHandler_h_
#define _nsIProtocolHandler_h_
#include "nsISupports.h"
#include "nsICoolURL.h"
/*
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
*/
class nsIProtocolHandler : public nsISupports
{
public:
/*
GetDefaultPort returns the default port associated with this
protocol.
*/
NS_IMETHOD_(PRInt32) GetDefaultPort(void) const = 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(nsICoolURL* i_URL,
nsIProtocolInstance* *o_Instance) = 0;
/*
The GetScheme function uniquely identifies the scheme this handler
is associated with.
*/
NS_IMETHOD GetScheme(const char* *o_Scheme) const = 0;
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;
};
};
#endif /* _nsIProtocolHandler_h_ */

Просмотреть файл

@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIProtocolInstance_h_
#define _nsIProtocolInstance_h_
#include "nsISupports.h"
class nsIInputStream;
/*
The nsIProtocolInstance class is a common interface to all protocol
functionality. This base interface will support at getting the input
stream and the outputstream for the "connection"
There are still issues on what is the most common interface for the
extreme cases of an interactive protocol like HTTP vs. events based
one like SMTP/IMAP. This interface will probably go thru some
redesigning.
-Gagan Saksena 03/15/99
*/
class nsIProtocolInstance : public nsISupports
{
public:
/*
The GetInputStream function. Note that this function is not a const
and calling it may result in a state change for the protocol instance.
Its upto the protocol to reflect an already open input stream through
the return methods.
*/
NS_IMETHOD GetInputStream( nsIInputStream* *o_Stream) = 0;
/*
The interrupt function for stopping an active instance.
*/
NS_IMETHOD Interrupt(void) = 0;
/*
The load function that makes the actual attempt to starts the
retrieval process. Depending upon the protocol's implementation
this function may open the network connection.
*/
NS_IMETHOD Load(void) = 0;
static const nsIID& GetIID() {
// {3594D180-CB85-11d2-A1BA-444553540000}
static const nsIID NS_IProtocolInstance_IID =
{ 0x3594d180, 0xcb85, 0x11d2, { 0xa1, 0xba, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0 } };
return NS_IProtocolInstance_IID;
};
protected:
/*
Protocol's check for connection status. Once Load is called, this
should return true. TODO THINK
NS_IMETHOD_(PRBool) IsConnected(void) = 0;
*/
};
//Possible errors
#define NS_ERROR_ALREADY_CONNECTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 150);
#endif /* _nsIProtocolInstance_h_ */

61
nunet/public/nsIProxy.h Normal file
Просмотреть файл

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIProxy_h_
#define _nsIProxy_h_
#include "nsISupports.h"
/*
The nsIProxy interface allows setting and getting of proxy host and port.
This is for use by protocol handlers. If you are writing a protocol handler
and would like to support proxy behaviour then derive from this as well as
the nsIProtocolHandler class.
-Gagan Saksena 02/25/99
*/
class nsIProxy : public nsISupports
{
public:
/*
Get and Set the Proxy Host
*/
NS_IMETHOD GetProxyHost(const char* *o_ProxyHost) const = 0;
NS_IMETHOD SetProxyHost(const char* i_ProxyHost) = 0;
/*
Get and Set the Proxy Port
-1 on Set call indicates switch to default port
*/
NS_IMETHOD_(PRInt32)
GetProxyPort(void) const = 0;
NS_IMETHOD SetProxyPort(PRInt32 i_ProxyPort) = 0;
static const nsIID& GetIID() {
// {0492D011-CD2F-11d2-B013-006097BFC036}
static const nsIID NS_IPROXY_IID=
{ 0x492d011, 0xcd2f, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
return NS_IPROXY_IID;
};
};
#endif /* _nsIProxy_h_ */

125
nunet/public/nsIURI.h Normal file
Просмотреть файл

@ -0,0 +1,125 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIURI_h_
#define _nsIURI_h_
#include "nsISupports.h"
/*
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!
-Gagan Saksena 03/15/99
*/
class nsIURI : public nsISupports
{
public:
//Core parsing functions
/*
The Scheme is the protocol that this URI refers to.
*/
NS_IMETHOD GetScheme(const char* *o_Scheme) const = 0;
NS_IMETHOD SetScheme(const char* i_Scheme) = 0;
/*
The PreHost portion includes elements like the optional
username:password, or maybe other scheme specific items.
*/
NS_IMETHOD GetPreHost(const char* *o_PreHost) const = 0;
NS_IMETHOD SetPreHost(const char* i_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* *o_Host) const = 0;
NS_IMETHOD SetHost(const char* i_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.
*/
NS_IMETHOD_(PRInt32)
GetPort(void) const = 0;
NS_IMETHOD SetPort(PRInt32 i_Port) = 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* *o_Path) const = 0;
NS_IMETHOD SetPath(const char* i_Path) = 0;
//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.
*/
NS_IMETHOD_(PRBool) Equals(const nsIURI* i_URI) const = 0;
/*
Writes a string representation of the URI.
*/
NS_IMETHOD ToString(const char* *o_URIString) const = 0;
static const nsIID& GetIID() {
// {EF4B5380-C07A-11d2-A1BA-00609794CF59}
static const nsIID NS_IURI_IID =
{ 0xef4b5380, 0xc07a, 0x11d2, { 0xa1, 0xba, 0x0, 0x60, 0x97, 0x94, 0xcf, 0x59 } };
return NS_IURI_IID;
};
};
#endif /* _nsIURI_h_ */