From 09a03524ca09ecff7a49899c701d72c237cab906 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Thu, 13 Aug 1998 20:10:49 +0000 Subject: [PATCH] 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 --- mozilla/network/module/Makefile | 3 +- mozilla/network/module/makefile.win | 3 +- mozilla/network/module/nsHttpUrl.cpp | 65 ++++++++++++++++++++++++ mozilla/network/module/nsIHttpUrl.h | 13 +++++ mozilla/network/module/nsNetService.cpp | 19 ++++--- mozilla/network/module/nsNetStream.cpp | 1 + mozilla/network/module/nsNetStream.h | 1 + mozilla/network/module/nsNetStubs.cpp | 37 +++++++++++++- mozilla/network/module/nsStubContext.cpp | 12 +++-- 9 files changed, 142 insertions(+), 12 deletions(-) diff --git a/mozilla/network/module/Makefile b/mozilla/network/module/Makefile index 3d8298cd7ba..f73ad39f421 100644 --- a/mozilla/network/module/Makefile +++ b/mozilla/network/module/Makefile @@ -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 diff --git a/mozilla/network/module/makefile.win b/mozilla/network/module/makefile.win index 04a8197a2c3..df7c1d4e9a2 100644 --- a/mozilla/network/module/makefile.win +++ b/mozilla/network/module/makefile.win @@ -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 diff --git a/mozilla/network/module/nsHttpUrl.cpp b/mozilla/network/module/nsHttpUrl.cpp index 1860f7755a9..e493d2d0ab1 100644 --- a/mozilla/network/module/nsHttpUrl.cpp +++ b/mozilla/network/module/nsHttpUrl.cpp @@ -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; diff --git a/mozilla/network/module/nsIHttpUrl.h b/mozilla/network/module/nsIHttpUrl.h index 03e37ec22dd..938d73aadd6 100644 --- a/mozilla/network/module/nsIHttpUrl.h +++ b/mozilla/network/module/nsIHttpUrl.h @@ -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; }; diff --git a/mozilla/network/module/nsNetService.cpp b/mozilla/network/module/nsNetService.cpp index 5cbe8917ceb..c9b1211bd20 100644 --- a/mozilla/network/module/nsNetService.cpp +++ b/mozilla/network/module/nsNetService.cpp @@ -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; } diff --git a/mozilla/network/module/nsNetStream.cpp b/mozilla/network/module/nsNetStream.cpp index 1de3472c7ed..d5163db1c18 100644 --- a/mozilla/network/module/nsNetStream.cpp +++ b/mozilla/network/module/nsNetStream.cpp @@ -43,6 +43,7 @@ nsConnectionInfo::nsConnectionInfo(nsIURL *aURL, pURL = aURL; pNetStream = aStream; pConsumer = aNotify; + redirect = PR_FALSE; if (NULL != pURL) { pURL->AddRef(); diff --git a/mozilla/network/module/nsNetStream.h b/mozilla/network/module/nsNetStream.h index 97387ab476f..d07fdb7567e 100644 --- a/mozilla/network/module/nsNetStream.h +++ b/mozilla/network/module/nsNetStream.h @@ -45,6 +45,7 @@ public: nsIURL *pURL; nsNetlibStream *pNetStream; nsIStreamListener *pConsumer; + PRBool redirect; }; diff --git a/mozilla/network/module/nsNetStubs.cpp b/mozilla/network/module/nsNetStubs.cpp index 059ad28df4d..158bbc49f7c 100644 --- a/mozilla/network/module/nsNetStubs.cpp +++ b/mozilla/network/module/nsNetStubs.cpp @@ -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; } diff --git a/mozilla/network/module/nsStubContext.cpp b/mozilla/network/module/nsStubContext.cpp index 317abdc1f93..7d525556dff 100644 --- a/mozilla/network/module/nsStubContext.cpp +++ b/mozilla/network/module/nsStubContext.cpp @@ -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 */