Added methods to nsINetService to get and set cookie string for a URL

This commit is contained in:
vidur%netscape.com 1998-07-25 00:32:32 +00:00
Родитель 92e85525b5
Коммит 5639f27847
4 изменённых файлов: 59 добавлений и 1 удалений

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

@ -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;
};

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

@ -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" {

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

@ -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();

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

@ -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...