зеркало из https://github.com/mozilla/gecko-dev.git
HTTP Handler work.
This commit is contained in:
Родитель
f99ba44b2a
Коммит
945fb72b35
|
@ -0,0 +1,73 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _kHTTPHeaders_h_
|
||||
#define _kHTTPHeaders_h_
|
||||
|
||||
/*
|
||||
Just the const headers used in HTTP.
|
||||
HH = HTTP Header;
|
||||
*/
|
||||
const char kHH_ACCEPT[] = "Accept";
|
||||
const char kHH_ACCEPT_CHAR[] = "Accept-Charset";
|
||||
const char kHH_ACCEPT_ENCODING[] = "Accept-Encoding";
|
||||
const char kHH_ACCEPT_LANGUAGE[] = "Accept-Language";
|
||||
const char kHH_ALLOW[] = "Allow";
|
||||
const char kHH_AUTHENTICATION[] = "Authentication";
|
||||
const char kHH_CONNECTION[] = "Connection";
|
||||
const char kHH_CONTENT_BASE[] = "Content-Base";
|
||||
const char kHH_CONTENT_ENCODING[] = "Content-Encoding";
|
||||
const char kHH_CONTENT_LANGUAGE[] = "Content-Language";
|
||||
const char kHH_CONTENT_LENGTH[] = "Content-Length";
|
||||
const char kHH_CONTENT_LOCATION[] = "Content-Location";
|
||||
const char kHH_CONTENT_MD5[] = "Content-MD5";
|
||||
const char kHH_CONTENT_RANGE[] = "Content-Range";
|
||||
const char kHH_CONTENT_TRANSFER_ENCODING[] = "Content-Transfer-Encoding";
|
||||
const char kHH_CONTENT_TYPE[] = "Content-Type";
|
||||
const char kHH_DATE[] = "Date";
|
||||
const char kHH_DERIVED_FROM[] = "Derived-From";
|
||||
const char kHH_ETAG[] = "ETag";
|
||||
const char kHH_EXPECT[] = "Expect";
|
||||
const char kHH_EXPIRES[] = "Expires";
|
||||
const char kHH_FROM[] = "From";
|
||||
const char kHH_FORWARDED[] = "Forwarded";
|
||||
const char kHH_HOST[] = "Host";
|
||||
const char kHH_IF_MATCH[] = "If-Match";
|
||||
const char kHH_IF_MATCH_ANY[] = "If-Match-Any";
|
||||
const char kHH_IF_MODIFIED_SINCE[] = "If-Modified-Since";
|
||||
const char kHH_IF_NONE_MATCH[] = "If-None-Match";
|
||||
const char kHH_IF_NONE_MATCH_ANY[] = "If-None-Match-Any";
|
||||
const char kHH_IF_RANGE[] = "If-Range";
|
||||
const char kHH_IF_UNMODIFIED_SINCE[] = "If-Unmodified-Since";
|
||||
const char kHH_LAST_MODIFIED[] = "Last-Modified";
|
||||
const char kHH_LINK[] = "Link";
|
||||
const char kHH_MAX_FORWARDS[] = "Max-Forwards";
|
||||
const char kHH_MESSAGE_ID[] = "Message-Id";
|
||||
const char kHH_MIME[] = "Mime";
|
||||
const char kHH_PRAGMA[] = "Pragma";
|
||||
const char kHH_RANGE[] = "Range";
|
||||
const char kHH_REFERER[] = "Referer";
|
||||
const char kHH_TITLE[] = "Title";
|
||||
const char kHH_TRAILER[] = "Trailer";
|
||||
const char kHH_TRANSFER[] = "Transfer";
|
||||
const char kHH_URI[] = "URI";
|
||||
const char kHH_USER_AGENT[] = "User-Agent";
|
||||
const char kHH_VERSION[] = "Version";
|
||||
const char kHH_WWW_AUTHENTICATE[] = "WWW-Authenticate";
|
||||
|
||||
#endif //_kHTTPHeaders_h_
|
|
@ -0,0 +1,41 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _kHTTPStates_h_
|
||||
#define _kHTTPStates_h_
|
||||
|
||||
/*
|
||||
HTTP States.
|
||||
*/
|
||||
typedef enum _HTTPStates
|
||||
{
|
||||
// The initial stage when a connection is set up
|
||||
IDLE,
|
||||
// The request has been built. Now just waiting for Open-- final call that connects.
|
||||
WAITING_FOR_OPEN,
|
||||
// Encountered a problem or a situation that requires user input.
|
||||
WAITING_FOR_USER_INPUT,
|
||||
// Waiting for a connection to go thru.
|
||||
WAITING_FOR_TRANSPORT,
|
||||
// Connected and now waiting for response.
|
||||
WAITING_FOR_RESPONSE,
|
||||
// Done
|
||||
DONE
|
||||
} HTTPStates;
|
||||
|
||||
#endif //_kHTTPStates_h_
|
|
@ -1,3 +1,5 @@
|
|||
#!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
|
||||
|
@ -13,37 +15,62 @@
|
|||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
MODULE = netwerk
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile to build the pluggable HTTP
|
||||
# This depends on the pluggable architecture apis exposed
|
||||
# by NuNet.
|
||||
#
|
||||
# -Gagan Saksena 03/25/99
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
DEPTH = ..\..\..\..
|
||||
DEPTH=..\..\..\..
|
||||
MODULE=plughttp
|
||||
|
||||
IS_COMPONENT=1
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
DLLNAME=http
|
||||
DLLNAME=plughttp
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
|
||||
LLIBS= $(LLIBS) \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(NULL)
|
||||
MISCDEP=$(LLIBS)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsHttpProtocolHandler.obj \
|
||||
.\$(OBJDIR)\nsHttpProtocolConnection.obj \
|
||||
.\$(OBJDIR)\nsHttpFactory.obj \
|
||||
$(NULL)
|
||||
EXPORTS= \
|
||||
nsHTTPCID.h \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\netwerk.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(LIBNSPR)
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsHTTPHandler.obj \
|
||||
.\$(OBJDIR)\nsHTTPHandlerFactory.obj \
|
||||
.\$(OBJDIR)\nsHTTPConnection.obj \
|
||||
.\$(OBJDIR)\nsHTTPRequest.obj \
|
||||
.\$(OBJDIR)\nsHTTPRequestObserver.obj \
|
||||
.\$(OBJDIR)\nsHTTPResponseListener.obj \
|
||||
.\$(OBJDIR)\nsHTTPResponse.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\netwerk \
|
||||
$(NULL)
|
||||
LOCAL_INCLUDES=-I.
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
INCLUDES = $(LOCAL_INCLUDES)
|
||||
|
||||
REQUIRES= netwerk
|
||||
|
||||
LINCS= \
|
||||
-I..\public \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\netwerk \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
XPCOM Class ID for the HTTP Handler that can be created with the
|
||||
factory.
|
||||
|
||||
-Gagan Saksena 03/24/99
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsHTTPCID_h__
|
||||
#define nsHTTPCID_h__
|
||||
|
||||
// {1C49C1D0-E254-11d2-B016-006097BFC036}
|
||||
#define NS_HTTP_HANDLER_FACTORY_CID \
|
||||
{ 0x1c49c1d0, 0xe254, 0x11d2, { 0xb0, 0x16, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } }
|
||||
|
||||
#endif // nsHTTPCID_h__
|
|
@ -0,0 +1,200 @@
|
|||
/* -*- 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 "nsHTTPConnection.h"
|
||||
#include "netCore.h"
|
||||
#include "nsIHTTPEventSink.h"
|
||||
#include "nsIHTTPHandler.h"
|
||||
#include "nsHTTPRequest.h"
|
||||
#include "nsHTTPResponse.h"
|
||||
|
||||
nsHTTPConnection::nsHTTPConnection(
|
||||
nsIURL* i_URL,
|
||||
nsIEventQueue* i_EQ,
|
||||
nsIHTTPEventSink* i_HTTPEventSink,
|
||||
nsIHTTPHandler* i_Handler):
|
||||
m_pURL( dont_QueryInterface(i_URL)),
|
||||
m_bConnected(PR_FALSE),
|
||||
m_State(HS_IDLE),
|
||||
mRefCnt(0),
|
||||
m_pHandler(dont_QueryInterface(i_Handler)),
|
||||
m_pEventSink(dont_QueryInterface(i_HTTPEventSink)),
|
||||
m_pResponse(nsnull),
|
||||
m_pEventQ(dont_QueryInterface(i_EQ))
|
||||
|
||||
{
|
||||
//TODO think if we need to make a copy of the URL and keep it here
|
||||
//since it might get deleted off the creators thread. And the
|
||||
//stream listener could be elsewhere...
|
||||
|
||||
/*
|
||||
Set up a request object - later set to a clone of a default
|
||||
request from the handler
|
||||
*/
|
||||
m_pRequest = new nsHTTPRequest(m_pURL);
|
||||
if (!m_pRequest)
|
||||
NS_ERROR("unable to create new nsHTTPRequest!");
|
||||
|
||||
}
|
||||
|
||||
nsHTTPConnection::~nsHTTPConnection()
|
||||
{
|
||||
//TODO if we keep our copy of m_pURL, then delete it too.
|
||||
if (m_pRequest)
|
||||
{
|
||||
delete m_pRequest;
|
||||
m_pRequest = 0;
|
||||
}
|
||||
if (m_pResponse)
|
||||
{
|
||||
delete m_pResponse;
|
||||
m_pResponse = 0;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPConnection);
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::Cancel(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::Suspend(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::Resume(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetInputStream(nsIInputStream* *o_Stream)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetOutputStream(nsIOutputStream* *o_Stream)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetRequestHeader(const char* i_Header, const char* *o_Value) const
|
||||
{
|
||||
NS_ASSERTION(m_pRequest, "The request object vanished from underneath the connection!");
|
||||
return m_pRequest->GetHeader(i_Header, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::SetRequestHeader(const char* i_Header, const char* i_Value)
|
||||
{
|
||||
NS_ASSERTION(m_pRequest, "The request object vanished from underneath the connection!");
|
||||
return m_pRequest->SetHeader(i_Header, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetResponseHeader(const char* i_Header, const char* *o_Value)
|
||||
{
|
||||
if (!m_bConnected)
|
||||
Open();
|
||||
if (m_pResponse)
|
||||
return m_pResponse->GetHeader(i_Header, o_Value);
|
||||
else
|
||||
return NS_ERROR_NOT_IMPLEMENTED; // NS_ERROR_NO_RESPONSE_YET ?
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::Open(void)
|
||||
{
|
||||
if (m_bConnected || (m_State > HS_IDLE))
|
||||
return NS_ERROR_ALREADY_CONNECTED;
|
||||
|
||||
m_bConnected = PR_TRUE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::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(nsIProtocolConnection::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIProtocolConnection*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIHTTPConnection::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHTTPConnection*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIProtocolConnection*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(nsHTTPConnection);
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetResponseStatus(PRInt32* o_Status)
|
||||
{
|
||||
PRInt32 status = -1;
|
||||
if (!m_bConnected)
|
||||
Open();
|
||||
*o_Status = status;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetResponseString(const char* *o_String)
|
||||
{
|
||||
if (!m_bConnected)
|
||||
Open();
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::SetRequestMethod(HTTPMethod i_Method)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPConnection::GetURL(nsIURL* *o_URL) const
|
||||
{
|
||||
if (o_URL)
|
||||
*o_URL = m_pURL;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/* -*- 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 _nsHTTPConnection_h_
|
||||
#define _nsHTTPConnection_h_
|
||||
|
||||
#ifndef nsIURL
|
||||
#define nsIURL nsIUrl
|
||||
#endif
|
||||
|
||||
#include "nsIHTTPConnection.h"
|
||||
#include "nsIProtocolConnection.h"
|
||||
#include "nsHTTPEnums.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsHTTPHandler.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIHTTPEventSink.h"
|
||||
|
||||
class nsHTTPRequest;
|
||||
class nsHTTPResponse;
|
||||
/*
|
||||
The nsHTTPConnection class is an example implementation of a
|
||||
protocol instnce that is active on a per-URL basis.
|
||||
|
||||
Currently this is being built with the Netlib dll. But after
|
||||
the registration stuff that DP is working on gets completed
|
||||
this will move to the HTTP lib.
|
||||
|
||||
-Gagan Saksena 02/25/99
|
||||
*/
|
||||
class nsHTTPConnection : public nsIHTTPConnection , public nsIProtocolConnection
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
nsHTTPConnection(
|
||||
nsIURL* i_URL,
|
||||
nsIEventQueue* i_EQ,
|
||||
nsIHTTPEventSink* i_HTTPEventSink,
|
||||
nsIHTTPHandler* i_Handler
|
||||
);
|
||||
|
||||
~nsHTTPConnection();
|
||||
|
||||
// Functions from nsISupports
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
// Functions from nsICancelable
|
||||
NS_IMETHOD Cancel(void);
|
||||
|
||||
NS_IMETHOD Suspend(void);
|
||||
|
||||
NS_IMETHOD Resume(void);
|
||||
|
||||
// Functions from nsIProtocolConnection
|
||||
|
||||
// blocking:
|
||||
NS_IMETHOD GetInputStream(nsIInputStream* *o_Stream);
|
||||
|
||||
// The actual connect call
|
||||
NS_IMETHOD Open(void);
|
||||
|
||||
// blocking:
|
||||
NS_IMETHOD GetOutputStream(nsIOutputStream* *o_Stream);
|
||||
|
||||
// Functions from nsIHTTPConnection
|
||||
NS_IMETHOD GetRequestHeader(const char* i_Header, const char* *o_Value) const;
|
||||
NS_IMETHOD SetRequestHeader(const char* i_Header, const char* i_Value);
|
||||
|
||||
NS_IMETHOD SetRequestMethod(HTTPMethod i_Method=HM_GET);
|
||||
|
||||
NS_IMETHOD GetResponseHeader(const char* i_Header, const char* *o_Value);
|
||||
|
||||
NS_IMETHOD GetResponseStatus(PRInt32* o_Status);
|
||||
|
||||
NS_IMETHOD GetResponseString(const char* *o_String);
|
||||
|
||||
NS_IMETHOD GetURL(nsIURL* *o_URL) const;
|
||||
|
||||
NS_IMETHOD EventSink(nsIHTTPEventSink* *o_EventSink) const { if (o_EventSink) *o_EventSink = m_pEventSink; return NS_OK; };
|
||||
private:
|
||||
nsCOMPtr<nsIURL> m_pURL;
|
||||
PRBool m_bConnected;
|
||||
nsCOMPtr<nsIHTTPHandler> m_pHandler;
|
||||
HTTPState m_State;
|
||||
nsCOMPtr<nsIEventQueue> m_pEventQ;
|
||||
nsCOMPtr<nsIHTTPEventSink> m_pEventSink;
|
||||
nsHTTPRequest* m_pRequest;
|
||||
nsHTTPResponse* m_pResponse;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPConnection_h_ */
|
|
@ -0,0 +1,65 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsHTTPEnums_h_
|
||||
#define _nsHTTPEnums_h_
|
||||
|
||||
typedef enum {
|
||||
HM_DELETE,
|
||||
HM_GET,
|
||||
HM_HEAD,
|
||||
HM_INDEX,
|
||||
HM_LINK,
|
||||
HM_OPTIONS,
|
||||
HM_POST,
|
||||
HM_PUT,
|
||||
HM_PATCH,
|
||||
HM_TRACE,
|
||||
HM_UNLINK,
|
||||
TOTAL_NUMBER_OF_METHODS // Always the last
|
||||
} HTTPMethod;
|
||||
|
||||
/*
|
||||
HTTP States.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
// The initial stage when a connection is set up
|
||||
// For pipelining we repeat from here
|
||||
HS_IDLE,
|
||||
// A temporarily suspended state.
|
||||
HS_SUSPENDED,
|
||||
// The request has been built. Now just waiting for Open-- final call that connects.
|
||||
HS_WAITING_FOR_OPEN,
|
||||
// Encountered a problem or a situation that requires user input.
|
||||
HS_WAITING_FOR_USER_INPUT,
|
||||
// Waiting for a connection to go thru.
|
||||
HS_WAITING_FOR_TRANSPORT,
|
||||
// Connected and now waiting for response.
|
||||
HS_WAITING_FOR_RESPONSE,
|
||||
// Done
|
||||
HS_DONE
|
||||
} HTTPState;
|
||||
|
||||
typedef enum {
|
||||
HTTP_ZERO_NINE, // HTTP/0.9
|
||||
HTTP_ONE_ZERO, // HTTP/1.0
|
||||
HTTP_ONE_ONE // HTTP/1.1
|
||||
} HTTPVersion;
|
||||
|
||||
#endif //_knsHTTPEnumss_h_
|
|
@ -0,0 +1,239 @@
|
|||
/* -*- 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 "nsHTTPHandler.h"
|
||||
#include "nsHTTPConnection.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIProxy.h"
|
||||
#include "plstr.h" // For PL_strcasecmp maybe DEBUG only... TODO check
|
||||
#include "nsIUrl.h"
|
||||
#include "nsSocketKey.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsStandardUrl.h"
|
||||
#include "nsIHTTPEventSink.h"
|
||||
|
||||
static NS_DEFINE_CID(kStandardUrlCID, NS_THIS_STANDARDURL_IMPLEMENTATION_CID);
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
NS_METHOD CreateOrGetHTTPHandler(nsIHTTPHandler* *o_HTTPHandler)
|
||||
{
|
||||
if (o_HTTPHandler)
|
||||
{
|
||||
*o_HTTPHandler = nsHTTPHandler::GetInstance();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsHTTPHandler::nsHTTPHandler():
|
||||
m_pTransportTable(nsnull),
|
||||
mRefCnt(0)
|
||||
{
|
||||
if (NS_FAILED(NS_NewISupportsArray(getter_AddRefs(m_pConnections)))) {
|
||||
NS_ERROR("unable to create new ISupportsArray");
|
||||
}
|
||||
}
|
||||
|
||||
nsHTTPHandler::~nsHTTPHandler()
|
||||
{
|
||||
if (m_pTransportTable)
|
||||
{
|
||||
delete m_pTransportTable;
|
||||
m_pTransportTable = 0;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPHandler);
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::NewConnection(nsIURL* i_URL,
|
||||
nsISupports* i_eventSink,
|
||||
nsIEventQueue* i_eventQueue,
|
||||
nsIProtocolConnection* *o_Instance)
|
||||
{
|
||||
//Assert that iURL's scheme is HTTP
|
||||
//This should only happen in debug checks... TODO
|
||||
const char* scheme = 0;
|
||||
if (i_URL)
|
||||
{
|
||||
i_URL->GetScheme(&scheme);
|
||||
if (0 == PL_strcasecmp(scheme, "http"))
|
||||
{
|
||||
nsHTTPConnection* pConn = nsnull;
|
||||
nsIURL* pURL = nsnull;
|
||||
//Check to see if an instance already exists in the active list
|
||||
PRUint32 count;
|
||||
m_pConnections->Count(&count);
|
||||
for (--count; count >= 0; --count)
|
||||
{
|
||||
//switch to static_cast...
|
||||
pConn = (nsHTTPConnection*)((nsIHTTPConnection*) m_pConnections->ElementAt(count));
|
||||
//Do other checks here as well... TODO
|
||||
if ((NS_OK == pConn->GetURL(&pURL)) && (pURL == i_URL))
|
||||
{
|
||||
NS_ADDREF(pConn);
|
||||
*o_Instance = pConn;
|
||||
return NS_OK; // TODO return NS_USING_EXISTING... or NS_DUPLICATE_REQUEST something like that.
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that the event sink is http
|
||||
nsCOMPtr<nsIHTTPEventSink> httpEventSink (do_QueryInterface(i_eventSink));
|
||||
|
||||
// Create one
|
||||
nsHTTPConnection* pNewInstance = new nsHTTPConnection(
|
||||
i_URL,
|
||||
i_eventQueue,
|
||||
httpEventSink,
|
||||
this);
|
||||
if (pNewInstance)
|
||||
{
|
||||
NS_ADDREF(pNewInstance);
|
||||
*o_Instance = pNewInstance;
|
||||
// add this instance to the active list of connections
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ASSERTION(0, "Non-HTTP request coming to HTTP Handler!!!");
|
||||
//return NS_ERROR_MISMATCHED_URL;
|
||||
}
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTTPHandler::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(nsIProtocolHandler::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIProtocolHandler*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIHTTPHandler::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHTTPHandler*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIProxy::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIProxy*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIProtocolHandler*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(nsHTTPHandler);
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::MakeAbsoluteUrl(const char* i_URL,
|
||||
nsIURL* i_BaseURL,
|
||||
char* *o_Result) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::NewUrl(const char* i_URL,
|
||||
nsIURL* i_BaseURL,
|
||||
nsIURL* *o_Result) const
|
||||
{
|
||||
//todo clean this up...
|
||||
nsresult rv;
|
||||
|
||||
nsIUrl* url;
|
||||
rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, nsIUrl::GetIID(), (void**)&url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->Init(i_URL, i_BaseURL);
|
||||
|
||||
nsIUrl* realUrl = nsnull;
|
||||
|
||||
rv = url->QueryInterface(nsIUrl::GetIID(), (void**)&realUrl);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*o_Result= realUrl;
|
||||
NS_ADDREF(*o_Result);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::GetTransport(const char* i_Host,
|
||||
PRUint32& i_Port,
|
||||
nsITransport** o_pTrans)
|
||||
{
|
||||
// Check in the table...
|
||||
nsSocketKey key(i_Host, i_Port);
|
||||
nsITransport* trans = (nsITransport*) m_pTransportTable->Get(&key);
|
||||
if (trans)
|
||||
{
|
||||
*o_pTrans = trans;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Create a new one...
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = sts->CreateTransport(i_Host, i_Port, &trans);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Put it in the table...
|
||||
void* oldValue = m_pTransportTable->Put(&key, trans);
|
||||
NS_ASSERTION(oldValue == nsnull, "Race condition in transport table!");
|
||||
NS_ADDREF(trans);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::ReleaseTransport(const char* i_Host,
|
||||
PRUint32& i_Port,
|
||||
nsITransport* i_pTrans)
|
||||
{
|
||||
nsSocketKey key(i_Host, i_Port);
|
||||
nsITransport* value = (nsITransport*) m_pTransportTable->Remove(&key);
|
||||
if (value == nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_ASSERTION(i_pTrans == value, "m_pTransportTable is out of sync");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPHandler::FollowRedirects(PRBool bFollow)
|
||||
{
|
||||
//m_bFollowRedirects = bFollow;
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
/* -*- 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 _nsHTTPHandler_h_
|
||||
#define _nsHTTPHandler_h_
|
||||
|
||||
/*
|
||||
The nsHTTPHandler class is an example implementation of how a
|
||||
pluggable protocol would be written by an external party. As
|
||||
an example this class also uses the Proxy interface.
|
||||
|
||||
Since this is a completely different process boundary, I am
|
||||
keeping this as a singleton. It doesn't have to be that way.
|
||||
|
||||
Currently this is being built with the Netlib dll. But after
|
||||
the registration stuff that DP is working on gets completed
|
||||
this will move to the HTTP lib.
|
||||
|
||||
-Gagan Saksena 02/25/99
|
||||
*/
|
||||
//TODO turnon the proxy stuff as well.
|
||||
|
||||
#include "nsIHTTPHandler.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIProtocolConnection.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
//Forward decl.
|
||||
class nsHashtable;
|
||||
class nsITransport;
|
||||
|
||||
class nsHTTPHandler : public nsIHTTPHandler, public nsIProtocolHandler
|
||||
//, public nsIProxy
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//Functions from nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//Functions from nsIProtocolHandler
|
||||
/*
|
||||
GetDefaultPort returns the default port associated with this
|
||||
protocol.
|
||||
*/
|
||||
NS_IMETHOD GetDefaultPort(PRInt32 *result) const
|
||||
{
|
||||
static const PRInt32 defaultPort = 80;
|
||||
*result = defaultPort;
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
/*
|
||||
The GetScheme function uniquely identifies the scheme this handler
|
||||
is associated with.
|
||||
*/
|
||||
NS_IMETHOD GetScheme(const char* *o_Scheme) const
|
||||
{
|
||||
static const char* scheme = "http";
|
||||
*o_Scheme = scheme;
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
NS_IMETHOD MakeAbsoluteUrl(const char* i_URL,
|
||||
nsIURL* i_BaseURL,
|
||||
char* *o_Result) const;
|
||||
|
||||
NS_IMETHOD NewConnection(nsIURL* i_URL,
|
||||
nsISupports* i_eventSink,
|
||||
nsIEventQueue* i_eventQueue,
|
||||
nsIProtocolConnection* *o_Result);
|
||||
|
||||
NS_IMETHOD NewUrl(const char* i_URL,
|
||||
nsIURL* i_BaseUrl,
|
||||
nsIURL* *o_Result) const;
|
||||
|
||||
//Functions from nsIHTTPHandler
|
||||
|
||||
#if 0
|
||||
//Functions from nsIProxy
|
||||
/*
|
||||
Get and Set the Proxy Host
|
||||
*/
|
||||
NS_IMETHOD GetProxyHost(const char* *o_ProxyHost) const {return NS_ERROR_NOT_IMPLEMENTED;};
|
||||
NS_IMETHOD SetProxyHost(const char* i_ProxyHost) {return NS_ERROR_NOT_IMPLEMENTED;};
|
||||
|
||||
/*
|
||||
Get and Set the Proxy Port
|
||||
-1 on Set call indicates switch to default port
|
||||
*/
|
||||
NS_IMETHOD_(PRInt32)
|
||||
GetProxyPort(void) const {return NS_ERROR_NOT_IMPLEMENTED;};
|
||||
NS_IMETHOD SetProxyPort(PRInt32 i_ProxyPort) {return NS_ERROR_NOT_IMPLEMENTED;};
|
||||
|
||||
#endif
|
||||
// Follow the redirects automatically. This will trigger OnRedirect call on the sink
|
||||
NS_IMETHOD FollowRedirects(PRBool bFollow=PR_TRUE);
|
||||
|
||||
// Singleton function
|
||||
static nsHTTPHandler* GetInstance(void)
|
||||
{
|
||||
static nsHTTPHandler* pHandler = new nsHTTPHandler();
|
||||
return pHandler;
|
||||
};
|
||||
|
||||
/*
|
||||
Pull out an existing transport from the hashtable, or if none exists
|
||||
create one.
|
||||
*/
|
||||
NS_IMETHOD GetTransport(const char* i_Host, PRUint32& i_Port, nsITransport* *o_pTrans);
|
||||
/*
|
||||
Remove this transport from the hashtable.
|
||||
*/
|
||||
NS_IMETHOD ReleaseTransport(const char* i_Host, PRUint32& i_Port, nsITransport* i_pTrans);
|
||||
|
||||
protected:
|
||||
// None
|
||||
private:
|
||||
nsHTTPHandler(void);
|
||||
~nsHTTPHandler();
|
||||
|
||||
// This is the array of connections that the handler thread maintains to
|
||||
// verify unique requests.
|
||||
nsCOMPtr<nsISupportsArray> m_pConnections;
|
||||
nsHashtable* m_pTransportTable;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPHandler_h_ */
|
|
@ -0,0 +1,184 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
The nsHTTPHandlerFactory implementation. This was directly
|
||||
plagiarized from Chris Waterson the Great. So if you find
|
||||
a fault here... make sure you notify him as well.
|
||||
|
||||
-Gagan Saksena 03/25/99
|
||||
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIHTTPHandler.h"
|
||||
#include "nsHTTPCID.h"
|
||||
#include "nsHTTPHandlerFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsXPComFactory.h"
|
||||
#include "nsIProtocolHandler.h" // for NS_NETWORK_PROTOCOL_PROGID_PREFIX
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kHTTPHandlerCID, NS_HTTP_HANDLER_FACTORY_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsHTTPHandlerFactory::nsHTTPHandlerFactory(const nsCID &aClass,
|
||||
const char* className,
|
||||
const char* progID)
|
||||
: mClassID(aClass), mClassName(className), mProgID(progID)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsHTTPHandlerFactory::~nsHTTPHandlerFactory()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPHandlerFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsIFactory*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPHandlerFactory);
|
||||
NS_IMPL_RELEASE(nsHTTPHandlerFactory);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPHandlerFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kHTTPHandlerCID)) {
|
||||
if (NS_FAILED(rv = CreateOrGetHTTPHandler((nsIHTTPHandler**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
if (!inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(inst);
|
||||
*aResult = inst;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsHTTPHandlerFactory::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)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsHTTPHandlerFactory* factory = new nsHTTPHandlerFactory(aClass, aClassName, aProgID);
|
||||
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;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kHTTPHandlerCID,
|
||||
"HTTP Handler",
|
||||
NS_NETWORK_PROTOCOL_PROGID_PREFIX "http",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kHTTPHandlerCID, aPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* -*- 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"
|
||||
|
||||
class nsHTTPHandlerFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
nsHTTPHandlerFactory(const nsCID &aClass, const char* className, const char* progID);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~nsHTTPHandlerFactory();
|
||||
|
||||
protected:
|
||||
nsCID mClassID;
|
||||
const char* mClassName;
|
||||
const char* mProgID;
|
||||
|
||||
};
|
||||
|
|
@ -0,0 +1,742 @@
|
|||
/* -*- 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 "nsIUrl.h"
|
||||
#include "nsHTTPRequest.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsHeaderPair.h"
|
||||
#include "kHTTPHeaders.h"
|
||||
#include "nsHTTPEnums.h"
|
||||
|
||||
nsHTTPRequest::nsHTTPRequest(nsIUrl* i_pURL, HTTPMethod i_Method):
|
||||
m_pURI(i_pURL),
|
||||
m_Method(i_Method),
|
||||
m_pArray(new nsVoidArray()),
|
||||
m_Version(HTTP_ONE_ZERO)
|
||||
{
|
||||
Build();
|
||||
}
|
||||
|
||||
nsHTTPRequest::~nsHTTPRequest()
|
||||
{
|
||||
if (m_Request)
|
||||
{
|
||||
delete[] m_Request;
|
||||
m_Request = 0;
|
||||
}
|
||||
if (m_pArray)
|
||||
{
|
||||
delete m_pArray;
|
||||
m_pArray = 0;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPRequest);
|
||||
|
||||
nsresult
|
||||
nsHTTPRequest::Build()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTTPRequest::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(nsIHTTPRequest::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHTTPRequest*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIHTTPCommonHeaders::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHTTPCommonHeaders*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIHeader::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHeader*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(nsHTTPRequest);
|
||||
|
||||
//TODO make these inlines...
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetAllow(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ALLOW, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetAllow(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ALLOW, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentBase(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_BASE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentBase(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_BASE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentEncoding(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_ENCODING, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentEncoding(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_ENCODING, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentLanguage(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_LANGUAGE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentLanguage(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_LANGUAGE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentLength(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_LENGTH, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentLength(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_LENGTH, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentLocation(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_LOCATION, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentLocation(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_LOCATION, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentMD5(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_MD5, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentMD5(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_MD5, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentRange(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_RANGE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentRange(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_RANGE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentTransferEncoding(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_TRANSFER_ENCODING, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentTransferEncoding(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_TRANSFER_ENCODING, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetContentType(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_TYPE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetContentType(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_TYPE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetDerivedFrom(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_DERIVED_FROM, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetDerivedFrom(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_DERIVED_FROM, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetETag(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ETAG, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetETag(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ETAG, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetExpires(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_EXPIRES, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetExpires(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_EXPIRES, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetLastModified(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_LAST_MODIFIED, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetLastModified(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_LAST_MODIFIED, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetLink(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_LINK, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetLink(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_LINK, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetLinkMultiple(
|
||||
const char** *o_ValueArray,
|
||||
int count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetTitle(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_TITLE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetTitle(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_TITLE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetURI(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_URI, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetURI(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_URI, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetVersion(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_VERSION, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetVersion(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_VERSION, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetConnection(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONNECTION, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetConnection(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONNECTION, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetDate(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_DATE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetDate(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_DATE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetPragma(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_PRAGMA,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetPragma(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_PRAGMA,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetForwarded(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_FORWARDED,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetForwarded(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_FORWARDED,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetMessageID(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_MESSAGE_ID,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetMessageID(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_MESSAGE_ID,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetMIME(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_MIME,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetMIME(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_MIME,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetTrailer(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_TRAILER,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetTrailer(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_TRAILER,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetTransfer(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_TRANSFER,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetTransfer(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_TRANSFER,o_Value);
|
||||
}
|
||||
|
||||
// Methods from nsIHTTPRequest
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetAccept(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ACCEPT,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetAccept(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ACCEPT,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetAcceptChar(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ACCEPT_CHAR,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetAcceptChar(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ACCEPT_CHAR,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetAcceptEncoding(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ACCEPT_ENCODING,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetAcceptEncoding(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ACCEPT_ENCODING,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetAcceptLanguage(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ACCEPT_LANGUAGE,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetAcceptLanguage(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ACCEPT_LANGUAGE,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetAuthentication(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_AUTHENTICATION,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetAuthentication(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_AUTHENTICATION,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetExpect(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_EXPECT,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetExpect(const char** o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_EXPECT, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetFrom(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_FROM,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetFrom(const char** o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_FROM,o_Value);
|
||||
}
|
||||
|
||||
/*
|
||||
This is the actual Host for connection. Not necessarily the
|
||||
host in the url (as in the cases of proxy connection)
|
||||
*/
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetHost(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_HOST,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetHost(const char** o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_HOST, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfModifiedSince(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_MODIFIED_SINCE,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfModifiedSince(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_MODIFIED_SINCE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfMatch(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_MATCH,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfMatch(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_MATCH, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfMatchAny(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_MATCH_ANY,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfMatchAny(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_MATCH_ANY,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfNoneMatch(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_NONE_MATCH,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfNoneMatch(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_NONE_MATCH,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfNoneMatchAny(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_NONE_MATCH_ANY,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfNoneMatchAny(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_NONE_MATCH_ANY,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfRange(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_RANGE,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfRange(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_RANGE,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetIfUnmodifiedSince(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_IF_UNMODIFIED_SINCE,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetIfUnmodifiedSince(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_IF_UNMODIFIED_SINCE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetMaxForwards(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_MAX_FORWARDS,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetMaxForwards(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_MAX_FORWARDS,o_Value);
|
||||
}
|
||||
|
||||
/*
|
||||
Range information for byte-range requests
|
||||
may have an overloaded one. TODO later
|
||||
*/
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetRange(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_RANGE,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetRange(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_RANGE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetReferer(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_REFERER, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetReferer(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_REFERER, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetUserAgent(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_USER_AGENT, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetUserAgent(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_USER_AGENT, o_Value);
|
||||
}
|
||||
|
||||
// Finally our own methods...
|
||||
NS_METHOD
|
||||
nsHTTPRequest::Clone(const nsHTTPRequest* *o_Request) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetMethod(HTTPMethod i_Method)
|
||||
{
|
||||
m_Method = i_Method;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
HTTPMethod
|
||||
nsHTTPRequest::GetMethod(void) const
|
||||
{
|
||||
return m_Method;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetPriority()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetPriority()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetHeader(const char* i_Header, const char* i_Value)
|
||||
{
|
||||
if (i_Value)
|
||||
{
|
||||
//The tempValue gets copied so we can do away with it...
|
||||
nsString tempValue(i_Value);
|
||||
nsHeaderPair* pair = new nsHeaderPair(i_Header, &tempValue);
|
||||
if (pair)
|
||||
{
|
||||
//TODO set uniqueness? how...
|
||||
return m_pArray->AppendElement(pair);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This should delete any existing headers! TODO
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetHeader(const char* i_Header, const char* *o_Value) const
|
||||
{
|
||||
if (m_pArray && (0< m_pArray->Count()))
|
||||
{
|
||||
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
||||
{
|
||||
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray->ElementAt(i));
|
||||
if ((element->atom == NS_NewAtom(i_Header)) && o_Value)
|
||||
{
|
||||
*o_Value = (element->value) ? element->value->ToNewCString() : nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*o_Value = nsnull;
|
||||
return NS_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetHeaderMultiple(const char* i_Header,
|
||||
const char** *o_ValueArray,
|
||||
int o_Count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::SetHTTPVersion(HTTPVersion i_Version)
|
||||
{
|
||||
m_Version = i_Version;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPRequest::GetHTTPVersion(HTTPVersion* o_Version) const
|
||||
{
|
||||
*o_Version = m_Version;
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,271 @@
|
|||
/* -*- 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 _nsHTTPRequest_h_
|
||||
#define _nsHTTPRequest_h_
|
||||
|
||||
#include "nsIHTTPCommonHeaders.h"
|
||||
#include "nsIHTTPRequest.h"
|
||||
|
||||
class nsIUrl;
|
||||
class nsVoidArray;
|
||||
/*
|
||||
The nsHTTPRequest class is the request object created for each HTTP
|
||||
request before the connection. A request object may be cloned and
|
||||
saved for later reuse.
|
||||
|
||||
This class is internal to the protocol handler implementation and
|
||||
should theroetically not be used by the app or the core netlib.
|
||||
|
||||
-Gagan Saksena 03/29/99
|
||||
*/
|
||||
class nsHTTPRequest : public nsIHTTPRequest
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Constructor and destructor
|
||||
nsHTTPRequest(nsIUrl* i_URL=0, HTTPMethod i_Method=HM_GET);
|
||||
virtual ~nsHTTPRequest();
|
||||
|
||||
// Methods from nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// Methods from nsIHeader
|
||||
/*
|
||||
Set or Get a header on the request. Note that for the first iteration
|
||||
of this design, a set call will not replace an existing singleton
|
||||
header (like User-Agent) So calling this will only append the
|
||||
specified header to the request. Later on I would like to break
|
||||
headers into singleton and multi-types... And then search and
|
||||
replace an exising singleton header.
|
||||
|
||||
Similarly getting will for now only get the first occurence.
|
||||
TODO change to get the list.
|
||||
*/
|
||||
NS_IMETHOD SetHeader(const char* i_Header, const char* i_Value);
|
||||
NS_IMETHOD GetHeader(const char* i_Header, const char* *o_Value) const;
|
||||
//This will be a no-op initially
|
||||
NS_IMETHOD GetHeaderMultiple(
|
||||
const char* i_Header,
|
||||
const char** *o_ValueArray,
|
||||
int o_Count) const;
|
||||
|
||||
// Methods from nsIHTTPCommonHeaders
|
||||
NS_IMETHOD SetAllow(const char* i_Value);
|
||||
NS_IMETHOD GetAllow(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentBase(const char* i_Value);
|
||||
NS_IMETHOD GetContentBase(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentEncoding(const char* i_Value);
|
||||
NS_IMETHOD GetContentEncoding(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentLanguage(const char* i_Value);
|
||||
NS_IMETHOD GetContentLanguage(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentLength(const char* i_Value);
|
||||
NS_IMETHOD GetContentLength(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentLocation(const char* i_Value);
|
||||
NS_IMETHOD GetContentLocation(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentMD5(const char* i_Value);
|
||||
NS_IMETHOD GetContentMD5(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentRange(const char* i_Value);
|
||||
NS_IMETHOD GetContentRange(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentTransferEncoding(const char* i_Value);
|
||||
NS_IMETHOD GetContentTransferEncoding(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentType(const char* i_Value);
|
||||
NS_IMETHOD GetContentType(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetDerivedFrom(const char* i_Value);
|
||||
NS_IMETHOD GetDerivedFrom(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetETag(const char* i_Value);
|
||||
NS_IMETHOD GetETag(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetExpires(const char* i_Value);
|
||||
NS_IMETHOD GetExpires(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetLastModified(const char* i_Value);
|
||||
NS_IMETHOD GetLastModified(const char* *o_Value) const;
|
||||
|
||||
/*
|
||||
To set multiple link headers, call set link again.
|
||||
*/
|
||||
NS_IMETHOD SetLink(const char* i_Value);
|
||||
NS_IMETHOD GetLink(const char* *o_Value) const;
|
||||
NS_IMETHOD GetLinkMultiple(
|
||||
const char** *o_ValueArray,
|
||||
int count) const;
|
||||
|
||||
NS_IMETHOD SetTitle(const char* i_Value);
|
||||
NS_IMETHOD GetTitle(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetURI(const char* i_Value);
|
||||
NS_IMETHOD GetURI(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetVersion(const char* i_Value);
|
||||
NS_IMETHOD GetVersion(const char* *o_Value) const;
|
||||
|
||||
// Common Transaction headers
|
||||
NS_IMETHOD SetConnection(const char* i_Value);
|
||||
NS_IMETHOD GetConnection(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetDate(const char* i_Value);
|
||||
NS_IMETHOD GetDate(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetPragma(const char* i_Value);
|
||||
NS_IMETHOD GetPragma(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetForwarded(const char* i_Value);
|
||||
NS_IMETHOD GetForwarded(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetMessageID(const char* i_Value);
|
||||
NS_IMETHOD GetMessageID(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetMIME(const char* i_Value);
|
||||
NS_IMETHOD GetMIME(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetTrailer(const char* i_Value);
|
||||
NS_IMETHOD GetTrailer(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetTransfer(const char* i_Value);
|
||||
NS_IMETHOD GetTransfer(const char* *o_Value) const;
|
||||
|
||||
// Methods from nsIHTTPRequest
|
||||
NS_IMETHOD SetAccept(const char* i_Types);
|
||||
NS_IMETHOD GetAccept(const char* *o_Types) const;
|
||||
|
||||
NS_IMETHOD SetAcceptChar(const char* i_Chartype);
|
||||
NS_IMETHOD GetAcceptChar(const char* *o_Chartype) const;
|
||||
|
||||
NS_IMETHOD SetAcceptEncoding(const char* i_Encoding);
|
||||
NS_IMETHOD GetAcceptEncoding(const char* *o_Encoding) const;
|
||||
|
||||
NS_IMETHOD SetAcceptLanguage(const char* i_Lang);
|
||||
NS_IMETHOD GetAcceptLanguage(const char* *o_Lang) const;
|
||||
|
||||
NS_IMETHOD SetAuthentication(const char* i_Foo);
|
||||
NS_IMETHOD GetAuthentication(const char* *o_Foo) const;
|
||||
|
||||
NS_IMETHOD SetExpect(const char* i_Expect);
|
||||
NS_IMETHOD GetExpect(const char** o_Expect) const;
|
||||
|
||||
NS_IMETHOD SetFrom(const char* i_From);
|
||||
NS_IMETHOD GetFrom(const char** o_From) const;
|
||||
|
||||
/*
|
||||
This is the actual Host for connection. Not necessarily the
|
||||
host in the url (as in the cases of proxy connection)
|
||||
*/
|
||||
NS_IMETHOD SetHost(const char* i_Host);
|
||||
NS_IMETHOD GetHost(const char** o_Host) const;
|
||||
|
||||
NS_IMETHOD SetHTTPVersion(HTTPVersion i_Version);
|
||||
NS_IMETHOD GetHTTPVersion(HTTPVersion *o_Version) const;
|
||||
|
||||
NS_IMETHOD SetIfModifiedSince(const char* i_Value);
|
||||
NS_IMETHOD GetIfModifiedSince(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetIfMatch(const char* i_Value);
|
||||
NS_IMETHOD GetIfMatch(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetIfMatchAny(const char* i_Value);
|
||||
NS_IMETHOD GetIfMatchAny(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetIfNoneMatch(const char* i_Value);
|
||||
NS_IMETHOD GetIfNoneMatch(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetIfNoneMatchAny(const char* i_Value);
|
||||
NS_IMETHOD GetIfNoneMatchAny(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetIfRange(const char* i_Value);
|
||||
NS_IMETHOD GetIfRange(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetIfUnmodifiedSince(const char* i_Value);
|
||||
NS_IMETHOD GetIfUnmodifiedSince(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetMaxForwards(const char* i_Value);
|
||||
NS_IMETHOD GetMaxForwards(const char* *o_Value) const;
|
||||
|
||||
/*
|
||||
Range information for byte-range requests
|
||||
*/
|
||||
NS_IMETHOD SetRange(const char* i_Value);
|
||||
NS_IMETHOD GetRange(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetReferer(const char* i_Value);
|
||||
NS_IMETHOD GetReferer(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetUserAgent(const char* i_Value);
|
||||
NS_IMETHOD GetUserAgent(const char* *o_Value) const;
|
||||
|
||||
// Finally our own methods...
|
||||
/*
|
||||
Clone the current request for later use. Release it
|
||||
after you are done.
|
||||
*/
|
||||
NS_IMETHOD Clone(const nsHTTPRequest* *o_Copy) const;
|
||||
|
||||
NS_IMETHOD SetMethod(HTTPMethod i_Method);
|
||||
HTTPMethod GetMethod(void) const;
|
||||
|
||||
NS_IMETHOD SetPriority(); // TODO
|
||||
NS_IMETHOD GetPriority(); //TODO
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Build the actual request string based on the settings.
|
||||
NS_METHOD Build(void);
|
||||
|
||||
// Use a method string corresponding to the method.
|
||||
const char* MethodToString(HTTPMethod i_Method=HM_GET)
|
||||
{
|
||||
static const char methods[][TOTAL_NUMBER_OF_METHODS] =
|
||||
{
|
||||
"DELETE",
|
||||
"GET",
|
||||
"HEAD",
|
||||
"INDEX",
|
||||
"LINK",
|
||||
"OPTIONS",
|
||||
"POST",
|
||||
"PUT",
|
||||
"PATCH",
|
||||
"TRACE",
|
||||
"UNLINK"
|
||||
};
|
||||
|
||||
return methods[i_Method];
|
||||
}
|
||||
|
||||
nsIUrl* m_pURI;
|
||||
HTTPVersion m_Version;
|
||||
HTTPMethod m_Method;
|
||||
// The actual request string!
|
||||
char* m_Request;
|
||||
nsVoidArray* m_pArray;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPRequest_h_ */
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- 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 "nsIString.h"
|
||||
#include "nsHTTPRequestObserver.h"
|
||||
#include "nsHTTPResponseListener.h"
|
||||
#include "nsITransport.h"
|
||||
|
||||
nsHTTPRequestObserver::nsHTTPRequestObserver(nsITransport* i_pTransport) :
|
||||
m_pTransport(i_pTransport)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(m_pTransport);
|
||||
}
|
||||
|
||||
nsHTTPRequestObserver::~nsHTTPRequestObserver()
|
||||
{
|
||||
if (m_pTransport)
|
||||
NS_RELEASE(m_pTransport);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsHTTPRequestObserver,nsIStreamObserver::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPRequestObserver::OnStartBinding(nsISupports* /*i_pContext*/)
|
||||
{
|
||||
//TODO globally replace printf with trace calls.
|
||||
//printf("nsHTTPRequestObserver::OnStartBinding...\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPRequestObserver::OnStopBinding(nsISupports* i_pContext,
|
||||
nsresult iStatus,
|
||||
nsIString* i_pMsg)
|
||||
{
|
||||
//printf("nsHTTPRequestObserver::OnStopBinding...\n");
|
||||
// if we could write successfully...
|
||||
if (NS_SUCCEEDED(iStatus))
|
||||
{
|
||||
//Prepare to receive the response!
|
||||
nsHTTPResponseListener* pListener = new nsHTTPResponseListener();
|
||||
m_pTransport->AsyncRead(nsnull, nsnull /*gEventQ */, pListener);
|
||||
//TODO check this portion here...
|
||||
return pListener ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/*
|
||||
Somewhere here we need to send a message up the event sink
|
||||
that we successfully (or not) have sent request to the
|
||||
server. TODO
|
||||
*/
|
||||
return iStatus;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- 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 _nsHTTPRequestObserver_h_
|
||||
#define _nsHTTPRequestObserver_h_
|
||||
|
||||
#include "nsIStreamObserver.h"
|
||||
class nsITransport;
|
||||
class nsIString;
|
||||
|
||||
/*
|
||||
The nsHTTPRequestObserver class is the request writer observer that
|
||||
receives notifications of OnStartBinding and OnStopBinding as the
|
||||
request is being written out to the server. Each instance of this
|
||||
class is tied to the corresponding transport that it writes the
|
||||
request to.
|
||||
|
||||
The essential purpose of this class is to create the response listener
|
||||
once it is done writing a request and also notify the handler when
|
||||
this is done writing a request out. The latter could be used (later)
|
||||
to do pipelining.
|
||||
|
||||
This class is internal to the protocol handler implementation and
|
||||
should theroetically not be used by the app or the core netlib.
|
||||
|
||||
-Gagan Saksena 04/29/99
|
||||
*/
|
||||
class nsHTTPRequestObserver : public nsIStreamObserver
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
nsHTTPRequestObserver(nsITransport* i_pTransport);
|
||||
virtual ~nsHTTPRequestObserver();
|
||||
|
||||
// nsISupports functions
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
// nsIStreamObserver functions
|
||||
NS_IMETHOD OnStartBinding(nsISupports* context);
|
||||
|
||||
NS_IMETHOD OnStopBinding(nsISupports* context,
|
||||
nsresult aStatus,
|
||||
nsIString* aMsg);
|
||||
|
||||
protected:
|
||||
|
||||
nsITransport* m_pTransport;
|
||||
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPRequestObserver_h_ */
|
|
@ -0,0 +1,505 @@
|
|||
/* -*- 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 "nsHTTPResponse.h"
|
||||
#include "nsIUrl.h"
|
||||
#include "nsIHTTPConnection.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsHeaderPair.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "kHTTPHeaders.h"
|
||||
#include "plstr.h"
|
||||
|
||||
nsHTTPResponse::nsHTTPResponse(nsIHTTPConnection* i_pCon):
|
||||
m_pConn(dont_QueryInterface(i_pCon))
|
||||
{
|
||||
}
|
||||
|
||||
nsHTTPResponse::~nsHTTPResponse()
|
||||
{
|
||||
// m_pConn is released by nsCOMPtr.
|
||||
if (m_pStatusString)
|
||||
delete[] m_pStatusString;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPResponse);
|
||||
|
||||
nsresult
|
||||
nsHTTPResponse::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(nsIHTTPResponse::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHTTPResponse*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIHTTPCommonHeaders::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHTTPCommonHeaders*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIHeader::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIHeader*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_RELEASE(nsHTTPResponse);
|
||||
|
||||
//TODO make these inlines...
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetAllow(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ALLOW, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetAllow(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ALLOW, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentBase(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_BASE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentBase(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_BASE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentEncoding(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_ENCODING, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentEncoding(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_ENCODING, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentLanguage(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_LANGUAGE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentLanguage(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_LANGUAGE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentLength(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_LENGTH, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentLength(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_LENGTH, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentLocation(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_LOCATION, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentLocation(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_LOCATION, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentMD5(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_MD5, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentMD5(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_MD5, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentRange(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_RANGE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentRange(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_RANGE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentTransferEncoding(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_TRANSFER_ENCODING, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentTransferEncoding(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_TRANSFER_ENCODING, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetContentType(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONTENT_TYPE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentType(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONTENT_TYPE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetDerivedFrom(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_DERIVED_FROM, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetDerivedFrom(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_DERIVED_FROM, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetETag(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_ETAG, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetETag(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_ETAG, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetExpires(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_EXPIRES, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetExpires(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_EXPIRES, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetLastModified(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_LAST_MODIFIED, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetLastModified(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_LAST_MODIFIED, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetLink(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_LINK, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetLink(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_LINK, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetLinkMultiple(
|
||||
const char** *o_ValueArray,
|
||||
int count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetTitle(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_TITLE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetTitle(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_TITLE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetURI(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_URI, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetURI(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_URI, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetVersion(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_VERSION, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetVersion(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_VERSION, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetConnection(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_CONNECTION, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetConnection(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_CONNECTION, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetDate(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_DATE, i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetDate(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_DATE, o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetPragma(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_PRAGMA,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetPragma(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_PRAGMA,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetForwarded(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_FORWARDED,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetForwarded(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_FORWARDED,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetMessageID(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_MESSAGE_ID,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetMessageID(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_MESSAGE_ID,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetMIME(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_MIME,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetMIME(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_MIME,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetTrailer(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_TRAILER,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetTrailer(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_TRAILER,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetTransfer(const char* i_Value)
|
||||
{
|
||||
return SetHeader(kHH_TRANSFER,i_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetTransfer(const char* *o_Value) const
|
||||
{
|
||||
return GetHeader(kHH_TRANSFER,o_Value);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetContentLength(PRInt32* o_Value) const
|
||||
{
|
||||
if (o_Value)
|
||||
*o_Value = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetStatus(PRInt32* o_Value) const
|
||||
{
|
||||
if (o_Value)
|
||||
*o_Value = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetStatusString(const char* *o_String) const
|
||||
{
|
||||
if (o_String)
|
||||
*o_String = m_pStatusString;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetServer(const char* *o_String) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Finally our own methods...
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetHeader(const char* i_Header, const char* i_Value)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED; // and should not be used on responses
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetHeaderInternal(const char* i_Header, const char* i_Value)
|
||||
{
|
||||
if (i_Value)
|
||||
{
|
||||
//The tempValue gets copied so we can do away with it...
|
||||
nsString tempValue(i_Value);
|
||||
nsHeaderPair* pair = new nsHeaderPair(i_Header, &tempValue);
|
||||
if (pair)
|
||||
{
|
||||
//TODO set uniqueness? how...
|
||||
return m_pArray->AppendElement(pair);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This should delete any existing headers! TODO
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetHeader(const char* i_Header, const char* *o_Value) const
|
||||
{
|
||||
// TODO
|
||||
// Common out the headerpair array functionality from
|
||||
// request and put it in a class
|
||||
|
||||
if (m_pArray && (0< m_pArray->Count()))
|
||||
{
|
||||
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
||||
{
|
||||
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray->ElementAt(i));
|
||||
if ((element->atom == NS_NewAtom(i_Header)) && o_Value)
|
||||
{
|
||||
*o_Value = (element->value) ? element->value->ToNewCString() : nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*o_Value = nsnull;
|
||||
return NS_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::GetHeaderMultiple(const char* i_Header,
|
||||
const char** *o_ValueArray,
|
||||
int o_Count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetServerVersion(const char* i_Version)
|
||||
{
|
||||
// convert it to HTTP Version
|
||||
// TODO
|
||||
m_ServerVersion = HTTP_ONE_ZERO;
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTTPResponse::SetStatusString(const char* i_Status)
|
||||
{
|
||||
NS_ASSERTION(!m_pStatusString, "Overwriting status string!");
|
||||
int len = PL_strlen(i_Status);
|
||||
m_pStatusString = new char[len+1];
|
||||
PL_strncpy(m_pStatusString, i_Status, len);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
/* -*- 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 _nsHTTPResponse_h_
|
||||
#define _nsHTTPResponse_h_
|
||||
|
||||
#include "nsIHTTPCommonHeaders.h"
|
||||
#include "nsIHTTPResponse.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIHTTPConnection.h"
|
||||
|
||||
class nsIUrl;
|
||||
class nsVoidArray;
|
||||
|
||||
/*
|
||||
The nsHTTPResponse class is the response object created by the response
|
||||
listener as it reads in data from the input stream.
|
||||
|
||||
This class is internal to the protocol handler implementation and
|
||||
should theroetically not be used by the app or the core netlib.
|
||||
|
||||
-Gagan Saksena 03/29/99
|
||||
*/
|
||||
class nsHTTPResponse : public nsIHTTPResponse
|
||||
{
|
||||
|
||||
public:
|
||||
// Constructor and destructor
|
||||
nsHTTPResponse(nsIHTTPConnection* i_pConnection);
|
||||
virtual ~nsHTTPResponse();
|
||||
|
||||
// Methods from nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// Methods from nsIHeader
|
||||
/*
|
||||
Set or Get a header on the request. Note that for the first iteration
|
||||
of this design, a set call will not replace an existing singleton
|
||||
header (like User-Agent) So calling this will only append the
|
||||
specified header to the request. Later on I would like to break
|
||||
headers into singleton and multi-types... And then search and
|
||||
replace an exising singleton header.
|
||||
|
||||
Similarly getting will for now only get the first occurence.
|
||||
TODO change to get the list.
|
||||
*/
|
||||
NS_IMETHOD SetHeader(const char* i_Header, const char* i_Value);
|
||||
NS_IMETHOD GetHeader(const char* i_Header, const char* *o_Value) const;
|
||||
//This will be a no-op initially
|
||||
NS_IMETHOD GetHeaderMultiple(
|
||||
const char* i_Header,
|
||||
const char** *o_ValueArray,
|
||||
int o_Count) const;
|
||||
|
||||
// Methods from nsIHTTPCommonHeaders
|
||||
NS_IMETHOD SetAllow(const char* i_Value);
|
||||
NS_IMETHOD GetAllow(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentBase(const char* i_Value);
|
||||
NS_IMETHOD GetContentBase(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentEncoding(const char* i_Value);
|
||||
NS_IMETHOD GetContentEncoding(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentLanguage(const char* i_Value);
|
||||
NS_IMETHOD GetContentLanguage(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentLength(const char* i_Value);
|
||||
NS_IMETHOD GetContentLength(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentLocation(const char* i_Value);
|
||||
NS_IMETHOD GetContentLocation(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentMD5(const char* i_Value);
|
||||
NS_IMETHOD GetContentMD5(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentRange(const char* i_Value);
|
||||
NS_IMETHOD GetContentRange(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentTransferEncoding(const char* i_Value);
|
||||
NS_IMETHOD GetContentTransferEncoding(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetContentType(const char* i_Value);
|
||||
NS_IMETHOD GetContentType(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetDerivedFrom(const char* i_Value);
|
||||
NS_IMETHOD GetDerivedFrom(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetETag(const char* i_Value);
|
||||
NS_IMETHOD GetETag(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetExpires(const char* i_Value);
|
||||
NS_IMETHOD GetExpires(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetLastModified(const char* i_Value);
|
||||
NS_IMETHOD GetLastModified(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetLink(const char* i_Value);
|
||||
NS_IMETHOD GetLink(const char* *o_Value) const;
|
||||
NS_IMETHOD GetLinkMultiple(
|
||||
const char** *o_ValueArray,
|
||||
int count) const;
|
||||
|
||||
NS_IMETHOD SetTitle(const char* i_Value);
|
||||
NS_IMETHOD GetTitle(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetURI(const char* i_Value);
|
||||
NS_IMETHOD GetURI(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetVersion(const char* i_Value);
|
||||
NS_IMETHOD GetVersion(const char* *o_Value) const;
|
||||
|
||||
// Common Transaction headers
|
||||
NS_IMETHOD SetConnection(const char* i_Value);
|
||||
NS_IMETHOD GetConnection(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetDate(const char* i_Value);
|
||||
NS_IMETHOD GetDate(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetPragma(const char* i_Value);
|
||||
NS_IMETHOD GetPragma(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetForwarded(const char* i_Value);
|
||||
NS_IMETHOD GetForwarded(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetMessageID(const char* i_Value);
|
||||
NS_IMETHOD GetMessageID(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetMIME(const char* i_Value);
|
||||
NS_IMETHOD GetMIME(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetTrailer(const char* i_Value);
|
||||
NS_IMETHOD GetTrailer(const char* *o_Value) const;
|
||||
|
||||
NS_IMETHOD SetTransfer(const char* i_Value);
|
||||
NS_IMETHOD GetTransfer(const char* *o_Value) const;
|
||||
|
||||
// Stuff from nsIHTTPResponse
|
||||
NS_IMETHOD GetContentLength(PRInt32* o_Value) const;
|
||||
NS_IMETHOD GetStatus(PRInt32* o_Value) const;
|
||||
NS_IMETHOD GetStatusString(const char* *o_String) const;
|
||||
NS_IMETHOD GetServer(const char* *o_String) const;
|
||||
|
||||
// Finally our own methods...
|
||||
|
||||
NS_IMETHOD SetServerVersion(const char* i_ServerVersion);
|
||||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD SetHeaderInternal(const char* i_Header, const char* i_Value);
|
||||
NS_IMETHOD SetStatus(PRInt32 i_Value) { m_Status = i_Value; return NS_OK;};
|
||||
NS_IMETHOD SetStatusString(const char* i_Value);
|
||||
|
||||
char* m_Buffer; /* Used for holding header data */
|
||||
nsVoidArray* m_pArray;
|
||||
nsCOMPtr<nsIHTTPConnection> m_pConn;
|
||||
HTTPVersion m_ServerVersion;
|
||||
char* m_pStatusString;
|
||||
PRUint32 m_Status;
|
||||
|
||||
friend class nsHTTPResponseListener;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPResponse_h_ */
|
|
@ -0,0 +1,152 @@
|
|||
/* -*- 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 "nsIString.h"
|
||||
#include "nsHTTPResponseListener.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIHTTPConnection.h"
|
||||
#include "nsHTTPResponse.h"
|
||||
#include "nsIHTTPEventSink.h"
|
||||
#include "nsCRT.h"
|
||||
#include "stdio.h" //sscanf
|
||||
|
||||
static const int kMAX_FIRST_LINE_SIZE= 256;
|
||||
|
||||
nsHTTPResponseListener::nsHTTPResponseListener():
|
||||
m_pConnection(nsnull),
|
||||
m_bFirstLineParsed(PR_FALSE),
|
||||
m_bHeadersDone(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsHTTPResponseListener::~nsHTTPResponseListener()
|
||||
{
|
||||
if (m_pConnection)
|
||||
NS_RELEASE(m_pConnection);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsHTTPResponseListener,nsIStreamListener::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPResponseListener::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *i_pStream,
|
||||
PRUint32 i_SourceOffset,
|
||||
PRUint32 i_Length)
|
||||
{
|
||||
//move these to member variables later TODO
|
||||
static char extrabuffer[kMAX_FIRST_LINE_SIZE];
|
||||
static int extrabufferlen = 0;
|
||||
|
||||
NS_ASSERTION(i_pStream, "Fake stream!");
|
||||
//printf("nsHTTPResponseListener::OnDataAvailable...\n");
|
||||
/*
|
||||
Check its current state,
|
||||
if we have already found the end of headers mark,
|
||||
then just stream this on to the listener
|
||||
else read
|
||||
*/
|
||||
if (m_bHeadersDone)
|
||||
{
|
||||
// TODO push extrabuffer up the stream too.. How?
|
||||
|
||||
// Should I save this as a member variable? yes... todo
|
||||
nsIHTTPEventSink* pSink= nsnull;
|
||||
NS_VERIFY(m_pConnection->EventSink(&pSink), "No HTTP Event Sink!");
|
||||
return pSink->OnDataAvailable(context, i_pStream, i_SourceOffset, i_Length);
|
||||
}
|
||||
else if (!m_bFirstLineParsed)
|
||||
{
|
||||
//TODO optimize this further!
|
||||
char server_version[8]; // HTTP/1.1
|
||||
char buffer[kMAX_FIRST_LINE_SIZE];
|
||||
PRUint32 length;
|
||||
|
||||
nsresult stat = i_pStream->Read(buffer, kMAX_FIRST_LINE_SIZE, &length);
|
||||
NS_ASSERTION(buffer, "Argh...");
|
||||
|
||||
char* p = buffer;
|
||||
while ((*p != LF) && buffer+length > p)
|
||||
++p;
|
||||
|
||||
if (p != (buffer+length))
|
||||
{
|
||||
PRUint32 stat = 0;
|
||||
char stat_str[kMAX_FIRST_LINE_SIZE];
|
||||
*p = '\0';
|
||||
sscanf(buffer, "%8s %d %s", server_version, &stat, stat_str);
|
||||
m_pResponse->SetServerVersion(server_version);
|
||||
m_pResponse->SetStatus(stat);
|
||||
m_pResponse->SetStatusString(stat_str);
|
||||
p++;
|
||||
}
|
||||
|
||||
// we read extra so save it for the other headers
|
||||
if (buffer+length > p)
|
||||
{
|
||||
extrabufferlen = length - (buffer - p);
|
||||
PL_strncpy(extrabuffer, p, extrabufferlen);
|
||||
}
|
||||
m_bFirstLineParsed = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (extrabufferlen > 0)
|
||||
{
|
||||
// TODO - revive!
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPResponseListener::OnStartBinding(nsISupports* i_pContext)
|
||||
{
|
||||
//TODO globally replace printf with trace calls.
|
||||
//printf("nsHTTPResponseListener::OnStartBinding...\n");
|
||||
m_pConnection = NS_STATIC_CAST(nsIHTTPConnection*, i_pContext);
|
||||
NS_ADDREF(m_pConnection);
|
||||
// Set up the response
|
||||
m_pResponse = new nsHTTPResponse (m_pConnection);
|
||||
if (!m_pResponse)
|
||||
{
|
||||
NS_ERROR("Failed to create the response object!");
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(m_pResponse);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPResponseListener::OnStopBinding(nsISupports* i_pContext,
|
||||
nsresult i_Status,
|
||||
nsIString* i_pMsg)
|
||||
{
|
||||
//printf("nsHTTPResponseListener::OnStopBinding...\n");
|
||||
NS_ASSERTION(m_pResponse, "Response object vanished!");
|
||||
// Should I save this as a member variable? yes... todo
|
||||
nsIHTTPEventSink* pSink= nsnull;
|
||||
NS_VERIFY(m_pConnection->EventSink(&pSink), "No HTTP Event Sink!");
|
||||
nsresult rv = pSink->OnStopBinding(i_pContext, i_Status,i_pMsg);
|
||||
NS_RELEASE(m_pResponse);
|
||||
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/* -*- 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 _nsHTTPResponseListener_h_
|
||||
#define _nsHTTPResponseListener_h_
|
||||
|
||||
#include "nsIStreamListener.h"
|
||||
class nsITransport;
|
||||
class nsIString;
|
||||
class nsHTTPResponse;
|
||||
class nsIHTTPConnection;
|
||||
/*
|
||||
The nsHTTPResponseListener class is the response reader listener that
|
||||
receives notifications of OnStartBinding, OnDataAvailable and
|
||||
OnStopBinding as the data is received from the server. Each instance
|
||||
of this class is tied to the corresponding transport that it reads the
|
||||
response data stream from.
|
||||
|
||||
|
||||
The essential purpose of this class is to create the actual response
|
||||
based on the data that is coming off the net.
|
||||
|
||||
This class is internal to the protocol handler implementation and
|
||||
should theroetically not be used by the app or the core netlib.
|
||||
|
||||
-Gagan Saksena 04/29/99
|
||||
*/
|
||||
class nsHTTPResponseListener : public nsIStreamListener
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
nsHTTPResponseListener();
|
||||
virtual ~nsHTTPResponseListener();
|
||||
|
||||
// nsISupports functions
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
// nsIStreamListener functions
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
|
||||
NS_IMETHOD OnStartBinding(nsISupports* context);
|
||||
|
||||
NS_IMETHOD OnStopBinding(nsISupports* context,
|
||||
nsresult aStatus,
|
||||
nsIString* aMsg);
|
||||
|
||||
protected:
|
||||
PRBool m_bHeadersDone;
|
||||
PRBool m_bFirstLineParsed;
|
||||
nsHTTPResponse* m_pResponse;
|
||||
nsIHTTPConnection* m_pConnection;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPResponseListener_h_ */
|
|
@ -0,0 +1,94 @@
|
|||
/* -*- 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 "nsHeaderArray.h"
|
||||
#include "nscore.h"
|
||||
|
||||
nsHeaderArray::nsHeaderArray()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
m_pArray = new nsVoidArray();
|
||||
}
|
||||
|
||||
|
||||
nsHeaderArray::~nsHeaderArray()
|
||||
{
|
||||
if (m_pArray)
|
||||
{
|
||||
delete m_pArray;
|
||||
m_pArray = 0;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHeaderArray);
|
||||
NS_IMPL_RELEASE(nsHeaderArray);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHeaderArray::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (result == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(nsISupports::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsISupports*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (iid.Equals(nsICollection::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsICollection*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsICollection methods:
|
||||
|
||||
NS_IMETHODIMP_(PRUint32)
|
||||
nsHeaderArray::Count(void) const
|
||||
{
|
||||
return m_pArray->Count();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHeaderArray::AppendElement(nsISupports* i_HeaderPair)
|
||||
{
|
||||
return m_pArray->AppendElement(i_HeaderPair);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHeaderArray::RemoveElement(nsISupports* i_HeaderPair)
|
||||
{
|
||||
return m_pArray->RemoveElement(i_HeaderPair) ?
|
||||
NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
nsHeaderArray::Enumerate(nsIEnumerator* *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHeaderArray::Clear(void)
|
||||
{
|
||||
m_pArray->Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/* -*- 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 _nsHeaderArray_h_
|
||||
#define _nsHeaderArray_h_
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsICollection.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
/*
|
||||
The nsHeaderArray class is the array of elements of nsHeaderPair
|
||||
type.
|
||||
|
||||
This class is internal to the protocol handler implementation and
|
||||
should theroetically not be used by the app or the core netlib.
|
||||
|
||||
-Gagan Saksena 03/29/99
|
||||
*/
|
||||
class nsHeaderArray : public nsICollection
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Constructor and destructor
|
||||
nsHeaderArray();
|
||||
virtual ~nsHeaderArray();
|
||||
|
||||
// Methods from nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// Methods from nsICollection
|
||||
NS_IMETHOD AppendElement(nsISupports *aItem);
|
||||
|
||||
NS_IMETHOD Clear(void);
|
||||
|
||||
NS_IMETHOD_(PRUint32) Count(void) const;
|
||||
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result);
|
||||
|
||||
NS_IMETHOD RemoveElement(nsISupports *aItem);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
nsVoidArray* m_pArray;
|
||||
};
|
||||
|
||||
#endif /* _nsHeaderArray_h_ */
|
|
@ -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 _nsHeaderPair_h_
|
||||
#define _nsHeaderPair_h_
|
||||
|
||||
#include "nsIAtom.h"
|
||||
#include "nsString.h"
|
||||
|
||||
/*
|
||||
The nsHeaderPair is a struct for holding the atom corresponding to a header
|
||||
and the value associated with it. Note that this makes a copy of the value
|
||||
of the header.
|
||||
|
||||
This class is internal to the protocol handler implementation and
|
||||
should theroetically not be used by the app or the core netlib.
|
||||
|
||||
-Gagan Saksena 03/29/99
|
||||
*/
|
||||
|
||||
struct nsHeaderPair
|
||||
{
|
||||
// Converts header to an existing atom or creates a new one
|
||||
nsHeaderPair(const char* i_Header, const nsString* i_Value)
|
||||
{
|
||||
atom = NS_NewAtom(i_Header);
|
||||
NS_ASSERTION(atom, "Failed to create a new atom for nsHeaderPair!");
|
||||
if (i_Value)
|
||||
{
|
||||
value = new nsString(*i_Value);
|
||||
}
|
||||
};
|
||||
|
||||
~nsHeaderPair()
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
delete value;
|
||||
value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
nsIAtom* atom;
|
||||
nsString* value;
|
||||
};
|
||||
#endif /* _nsHeaderPair_h_ */
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- 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 _nsSocketKey_h_
|
||||
#define _nsSocketKey_h_
|
||||
|
||||
#include "nsHashtable.h" // also defines nsCStringKey
|
||||
#include "plstr.h"
|
||||
|
||||
class nsSocketKey : public nsCStringKey
|
||||
{
|
||||
|
||||
public:
|
||||
// Constructor and Destructor
|
||||
nsSocketKey(const char* i_Host, const PRInt32 i_port)
|
||||
: nsCStringKey(i_Host), m_Port(i_port)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~nsSocketKey(void)
|
||||
{
|
||||
}
|
||||
|
||||
nsHashKey* Clone(void) const
|
||||
{
|
||||
return new nsSocketKey(mStr, m_Port);
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey* i_Key) const
|
||||
{
|
||||
return (m_Port == ((nsSocketKey*)i_Key)->m_Port) &&
|
||||
nsCStringKey::Equals(i_Key);
|
||||
}
|
||||
|
||||
PRBool operator==(const nsSocketKey& i_Key) const
|
||||
{
|
||||
return Equals(&i_Key);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
nsSocketKey(const nsSocketKey& i_Key);
|
||||
nsSocketKey& operator=(const nsSocketKey& i_Key);
|
||||
|
||||
PRInt32 m_Port;
|
||||
};
|
||||
|
||||
#endif /* _nsSocketKey_h_ */
|
Загрузка…
Ссылка в новой задаче