diff --git a/mozilla/network/module/nsINetService.h b/mozilla/network/module/nsINetService.h index 83f454f8388..dc735c27dc6 100644 --- a/mozilla/network/module/nsINetService.h +++ b/mozilla/network/module/nsINetService.h @@ -77,6 +77,24 @@ struct nsINetService : public nsISupports * @return Returns NS_OK if successful, or NS_FALSE if an error occurred. */ NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer)=0; + + /** + * Get the complete cookie string associated with the URL + * + * @param aURL The URL for which to get the cookie string + * @param aCookie The string object which will hold the result + * @return Returns NS_OK if successful, or NS_FALSE if an error occurred. + */ + NS_IMETHOD GetCookieString(nsIURL *aURL, nsString& aCookie)=0; + + /** + * Set the cookie string associated with the URL + * + * @param aURL The URL for which to set the cookie string + * @param aCookie The string to set + * @return Returns NS_OK if successful, or NS_FALSE if an error occurred. + */ + NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie)=0; }; diff --git a/mozilla/network/module/nsNetService.cpp b/mozilla/network/module/nsNetService.cpp index bff311ee9da..84146632356 100644 --- a/mozilla/network/module/nsNetService.cpp +++ b/mozilla/network/module/nsNetService.cpp @@ -28,6 +28,7 @@ extern "C" { #include "cvchunk.h" }; #include "netcache.h" +#include "cookies.h" #include "plstr.h" #include "nsString.h" @@ -402,6 +403,42 @@ nsNetlibService::SetContainerApplication(nsINetContainerApplication *aContainer) return NS_OK; } +NS_IMETHODIMP +nsNetlibService::GetCookieString(nsIURL *aURL, nsString& aCookie) +{ + // XXX How safe is it to create a stub context without a URL_Struct? + MWContext *stubContext = new_stub_context(nsnull); + + const char *spec = aURL->GetSpec(); + char *cookie = NET_GetCookie(stubContext, (char *)spec); + + if (nsnull != cookie) { + aCookie.SetString(cookie); + PR_FREEIF(cookie); + } + else { + aCookie.SetString(""); + } + + free_stub_context(stubContext); + return NS_OK; +} + +NS_IMETHODIMP +nsNetlibService::SetCookieString(nsIURL *aURL, const nsString& aCookie) +{ + // XXX How safe is it to create a stub context without a URL_Struct? + MWContext *stubContext = new_stub_context(nsnull); + + const char *spec = aURL->GetSpec(); + char *cookie = aCookie.ToNewCString(); + + NET_SetCookieString(stubContext, (char *)spec, cookie); + + PR_FREEIF(cookie); + free_stub_context(stubContext); + return NS_OK; +} extern "C" { diff --git a/mozilla/network/module/nsNetService.h b/mozilla/network/module/nsNetService.h index 47d53b0132b..40a133054ca 100644 --- a/mozilla/network/module/nsNetService.h +++ b/mozilla/network/module/nsNetService.h @@ -41,6 +41,9 @@ public: NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer); nsresult SetContainerApplication(nsINetContainerApplication *aContainer); + NS_IMETHOD GetCookieString(nsIURL *aURL, nsString& aCookie); + NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie); + protected: virtual ~nsNetlibService(); diff --git a/mozilla/network/module/nsStubContext.cpp b/mozilla/network/module/nsStubContext.cpp index 3a7b26f272f..96c131ce820 100644 --- a/mozilla/network/module/nsStubContext.cpp +++ b/mozilla/network/module/nsStubContext.cpp @@ -51,7 +51,7 @@ static nsIStreamListener *getStreamListener(URL_Struct *URL_s) { nsIStreamListener *res = NULL; - if (URL_s->fe_data) { + if (URL_s && URL_s->fe_data) { /* * Retrieve the nsConnectionInfo object from the fe_data field * of the URL_Struct...