network/module/Makefile -

1. 310133 - Added nsIRefreshUrl.h to the list of exports.

network/module/makefile.win -
1. 310133 - Added nsIRefreshUrl.h to the list of exports.

network/module/nsIHttpUrl.h -
1. 310133 - Extended the nsIHttpUrl interface to include the AddMimeHeader() method which adds an http header to the url.

network/module/nsHttpUrl.cpp -
310133 - 1. Added support for the AddMimeHeader() method so http urls can have headers added outside of the actual data retrieval in netlib. This method calls NET_ParseMimeHeader() directly.
2. Added a public member, a pointer to the netlib URL_Struct that was created for this nsHttpUrlImpl. This pointer is the link between netlib and the outside world; the adhesive agent between url structs and nsURLImpls.

network/module/nsNetStream.h -
1. 310133 - Added a public memeber variable to nsConnectionInfo. It's a bool that tells us whether or not a redirect has occurred.

network/module/nsNetStream.cpp -
1. 310133 - Added initialization (FALSE) of new redirect member.

network/module/nsNetStubs.cpp -
1. 310133 - Implemented FE_SetRefreshURLTimer(). This function is called from NET_GetURL() when we recognize that we have a url to refresh.

network/module/nsStubContext.cpp -
1. 310133 - Added check to see if we're redirecting in stub_complete() which gets called when a stream completes. If we are, we don't want to release/destroy the pConsumer, this will happen in nsNetService's bam_exit_routine().

network/module/nsNetService.cpp -
1. 310133 - added nsConnectionInfo->redirect check in bam_exit_routine() so we give the consumer a successful binding event if the consumer is still around. This is iffy.


git-svn-id: svn://10.0.0.236/trunk@7956 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
valeski%netscape.com
1998-08-13 20:10:49 +00:00
parent 3deae00620
commit 09a03524ca
9 changed files with 142 additions and 12 deletions

View File

@@ -37,12 +37,13 @@ REQUIRES = raptor js dbm nspr security pref xpcom util img \
EXPORTS = nsIStreamListener.h \
nsINetService.h \
nsINetSupport.h \
nsINetSupport.h \
nsIURL.h \
nsIRelatedLinks.h \
nsIPostToServer.h \
nsIHttpUrl.h \
nsINetContainerApplication.h \
nsIRefreshUrl.h \
$(NULL)
include $(DEPTH)/config/config.mk

View File

@@ -24,12 +24,13 @@ IGNORE_MANIFEST = 1
MODULE = netlib
EXPORTS = nsIStreamListener.h \
nsINetService.h \
nsINetSupport.h \
nsINetSupport.h \
nsIURL.h \
nsIPostToServer.h \
nsIHttpUrl.h \
nsIRelatedLinks.h \
nsINetContainerApplication.h \
nsIRefreshUrl.h \
$(NULL)
DIRS = tests

View File

@@ -28,6 +28,8 @@
#include "prmem.h"
#include "plstr.h"
MWContext *new_stub_context(URL_Struct *URL_s);
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
@@ -57,6 +59,12 @@ public:
NS_IMETHOD SendData(const char *aBuffer, PRInt32 aLength);
NS_IMETHOD SendDataFromFile(const char *aFile);
/* Handle http-equiv meta tags. */
NS_IMETHOD AddMimeHeader(const char *name, const char *value);
/* Here's our link to the netlib world.... */
URL_Struct *m_URL_s;
/* nsIHttpUrl interface... */
@@ -81,6 +89,7 @@ nsHttpUrlImpl::nsHttpUrlImpl(nsISupports* outer)
m_PostType = Send_None;
m_PostBuffer = nsnull;
m_PostBufferLength = 0;
m_URL_s = nsnull;
}
nsHttpUrlImpl::~nsHttpUrlImpl()
@@ -132,6 +141,9 @@ NS_METHOD nsHttpUrlImpl::InitializeURLInfo(URL_Struct *URL_s)
{
nsresult result = NS_OK;
/* Hook us up with the world. */
m_URL_s = URL_s;
if (Send_None != m_PostType) {
/* Free any existing POST data hanging off the URL_Struct */
if (nsnull != URL_s->post_data) {
@@ -213,6 +225,59 @@ done:
}
NS_METHOD nsHttpUrlImpl::AddMimeHeader(const char *name, const char *value)
{
MWContext *stubContext=NULL;
char *aName=NULL;
char *aVal=NULL;
PRBool addColon=TRUE;
PRInt32 len=0;
NS_PRECONDITION((name != nsnull) && ((*name) != nsnull), "Bad name");
NS_PRECONDITION((value != nsnull) && ((*value) != nsnull), "Bad value");
if(!name
|| !*name
|| !value
|| !*value)
return NS_FALSE;
// Make sure we've got a colon on the end of the header name
if(PL_strchr(name, ':'))
addColon=FALSE;
/* Bring in our own copies of the data. */
if(addColon)
aName = (char*)PR_Malloc(PL_strlen(name)+2); // add extra byte for colon
else
aName = (char*)PR_Malloc(PL_strlen(name)+1);
if(!aName)
return NS_ERROR_OUT_OF_MEMORY;
aVal = (char*)PR_Malloc(PL_strlen(value)+1);
if(!aVal)
return NS_ERROR_OUT_OF_MEMORY;
PL_strcpy(aName, name);
if(addColon) {
PL_strcat(aName, ":");
}
PL_strcpy(aVal, value);
stubContext = new_stub_context(m_URL_s);
/* Make the real call to NET_ParseMimeHeader, passing in the dummy bam context. */
NET_ParseMimeHeader(FO_CACHE_AND_NGLAYOUT,
stubContext,
m_URL_s,
aName,
aVal,
TRUE);
return NS_OK;
}
nsresult nsHttpUrlImpl::PostFile(const char *aFile)
{
nsresult result = NS_OK;

View File

@@ -35,6 +35,19 @@
struct nsIHttpUrl : public nsISupports
{
/**
* Parse the mime header into the url struct.
* This method is intended to be used when an HTML META tag is encoutered
* with the type http-equiv. In this case, the http-equiv header should
* be added to the url in netlib, immediately after the http-equiv meta
* tag is encoutered.
*
* @param shell The shell loading this url.
* @param url The url to parse the mime header into.
* @param name The name of the mime header.
* @param value The value of the mime header.
*/
NS_IMETHOD AddMimeHeader(const char *name, const char *value) = 0;
};

View File

@@ -123,7 +123,7 @@ nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp)
NET_ChunkedDecoderStream);
mPollingTimer = nsnull;
RL_Init();
mContainer = aContainerApp;
@@ -493,10 +493,6 @@ void nsNetlibService::NetPollSocketsCallback(nsITimer* aTimer, void* aClosure)
}
}
extern "C" {
static nsNetlibService *pNetlib = NULL;
@@ -587,7 +583,18 @@ static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id
if (pConn->pConsumer) {
nsAutoString status;
pConn->pConsumer->OnStopBinding(pConn->pURL, NS_BINDING_FAILED, status);
/* If we were redirected, the Data Consumer will still be
* around (not released in the stream completion routine.
* In this case we want to notify the consumer that the
* binding completed. This leaves a hole: when we're
* redirected, and we're in this if statement because
* the stream was never "competed". */
if (pConn->redirect) {
pConn->pConsumer->OnStopBinding(pConn->pURL, NS_BINDING_SUCCEEDED, status);
} else {
pConn->pConsumer->OnStopBinding(pConn->pURL, NS_BINDING_FAILED, status);
}
pConn->pConsumer->Release();
pConn->pConsumer = NULL;
}

View File

@@ -43,6 +43,7 @@ nsConnectionInfo::nsConnectionInfo(nsIURL *aURL,
pURL = aURL;
pNetStream = aStream;
pConsumer = aNotify;
redirect = PR_FALSE;
if (NULL != pURL) {
pURL->AddRef();

View File

@@ -45,6 +45,7 @@ public:
nsIURL *pURL;
nsNetlibStream *pNetStream;
nsIStreamListener *pConsumer;
PRBool redirect;
};

View File

@@ -25,6 +25,9 @@
#include "libevent.h"
#include "mkgeturl.h"
#include "net.h"
#include "nsIRefreshUrl.h"
#include "nsString.h"
#include "nsNetStream.h"
extern "C" {
#include "secnav.h"
@@ -362,8 +365,40 @@ char *WH_FilePlatformName(const char *pName)
// 05-03-96 modified to use new API outside of idle loop.
//
void FE_SetRefreshURLTimer(MWContext *pContext, uint32 ulSeconds, char *pRefreshUrl)
NS_DEFINE_IID(kRefreshURLIID, NS_IREFRESHURL_IID);
void FE_SetRefreshURLTimer(MWContext *pContext, uint32 seconds, char *pRefreshURL)
{
nsresult rv;
nsIRefreshUrl* IRefreshURL=nsnull;
nsString refreshURL(pRefreshURL);
nsConnectionInfo* pConn;
NS_PRECONDITION((pRefreshURL != nsnull), "Null pointer...");
NS_PRECONDITION((pContext != nsnull), "Null pointer...");
NS_PRECONDITION((pContext->modular_data != nsnull), "Null pointer...");
NS_PRECONDITION((pContext->modular_data->fe_data != nsnull), "Null pointer...");
// Get the nsConnectionInfo out of the context.
// modular_data points to a URL_Struct.
pConn = (nsConnectionInfo*) pContext->modular_data->fe_data;
NS_PRECONDITION((pConn->pConsumer != nsnull), "Null pointer...");
if (pConn->pConsumer) {
rv = pConn->pConsumer->QueryInterface(kRefreshURLIID, (void**)&IRefreshURL);
if(rv == NS_OK) {
nsIURL* aURL;
rv = NS_NewURL(&aURL, refreshURL);
if(rv == NS_OK) {
IRefreshURL->RefreshURL(aURL, seconds*1000, FALSE);
NS_RELEASE(IRefreshURL);
}
}
}
MOZ_FUNCTION_STUB;
}

View File

@@ -491,13 +491,19 @@ void stub_complete(NET_StreamClass *stream)
pConn->pNetStream->Release();
pConn->pNetStream = NULL;
/* Notify the Data Consumer that the Binding has completed... */
if (pConn->pConsumer) {
nsAutoString status;
pConn->pConsumer->OnStopBinding(pConn->pURL, NS_BINDING_SUCCEEDED, status);
pConn->pConsumer->Release();
pConn->pConsumer = NULL;
/* If we're redirecting, we don't want to release/null the pConsumer. */
if (URL_s->refresh_url) {
pConn->redirect = PR_TRUE;
} else {
pConn->pConsumer->OnStopBinding(pConn->pURL, NS_BINDING_SUCCEEDED, status);
pConn->pConsumer->Release();
pConn->pConsumer = NULL;
}
}
/* Release the URL_Struct hanging off of the data_object */