зеркало из https://github.com/mozilla/pjs.git
major cleanup of cookie code
This commit is contained in:
Родитель
b172e081e6
Коммит
23a42d37fd
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -29,62 +29,13 @@
|
|||
#define NS_COOKIE NS_IMPORT
|
||||
#endif
|
||||
|
||||
|
||||
/* removes all cookies structs from the cookie list */
|
||||
extern void
|
||||
NET_RemoveAllCookies(void);
|
||||
|
||||
extern char *
|
||||
NET_GetCookie(char * address);
|
||||
|
||||
extern void
|
||||
NET_SetCookieString(char * cur_url,
|
||||
char * set_cookie_header);
|
||||
|
||||
/* saves out the HTTP cookies to disk
|
||||
*
|
||||
* on entry pass in the name of the file to save
|
||||
*
|
||||
* returns 0 on success -1 on failure.
|
||||
*
|
||||
*/
|
||||
extern int NET_SaveCookies(char * filename);
|
||||
|
||||
/* reads HTTP cookies from disk
|
||||
*
|
||||
* on entry pass in the name of the file to read
|
||||
*
|
||||
* returns 0 on success -1 on failure.
|
||||
*
|
||||
*/
|
||||
extern int NET_ReadCookies(char * filename);
|
||||
|
||||
|
||||
/* This sets the module local cookie pref variables
|
||||
* and registers the callbacks
|
||||
*/
|
||||
extern char * COOKIE_GetCookie(char * address);
|
||||
extern void COOKIE_SetCookieString(char * cur_url, char * set_cookie_header);
|
||||
extern int COOKIE_ReadCookies();
|
||||
extern void COOKIE_RegisterCookiePrefCallbacks(void);
|
||||
|
||||
|
||||
/* wrapper of NET_SetCookieString for netlib use. We need outformat and url_struct to determine
|
||||
* whether we're dealing with inline cookies
|
||||
*/
|
||||
|
||||
extern void
|
||||
NET_SetCookieStringFromHttp(char * cur_url,
|
||||
char * set_cookie_header, char * server_date);
|
||||
|
||||
extern void
|
||||
COOKIE_DisplayCookieInfoAsHTML();
|
||||
|
||||
extern void
|
||||
COOKIE_GetCookieListForViewer (nsString& aCookieList);
|
||||
|
||||
extern void
|
||||
COOKIE_GetPermissionListForViewer (nsString& aPermissionList);
|
||||
|
||||
extern void
|
||||
COOKIE_CookieViewerReturn(nsAutoString results);
|
||||
|
||||
extern void COOKIE_SetCookieStringFromHttp(char * cur_url, char * set_cookie_header, char * server_date);
|
||||
extern void COOKIE_GetCookieListForViewer (nsString& aCookieList);
|
||||
extern void COOKIE_GetPermissionListForViewer (nsString& aPermissionList);
|
||||
extern void COOKIE_CookieViewerReturn(nsAutoString results);
|
||||
|
||||
#endif /* COOKIES_H */
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// nsISupports
|
||||
|
||||
|
@ -32,177 +31,141 @@ NS_IMPL_ISUPPORTS(nsCookieHTTPNotify, nsIHTTPNotify::GetIID());
|
|||
///////////////////////////////////
|
||||
// nsCookieHTTPNotify Implementation
|
||||
|
||||
NS_COOKIE nsresult NS_NewCookieHTTPNotify(nsIHTTPNotify** aHTTPNotify)
|
||||
{
|
||||
if (aHTTPNotify == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsCookieHTTPNotify* it = new nsCookieHTTPNotify();
|
||||
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(nsIHTTPNotify::GetIID(), (void **) aHTTPNotify);
|
||||
NS_COOKIE nsresult NS_NewCookieHTTPNotify(nsIHTTPNotify** aHTTPNotify) {
|
||||
if (aHTTPNotify == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsCookieHTTPNotify* it = new nsCookieHTTPNotify();
|
||||
if (it == 0) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(nsIHTTPNotify::GetIID(), (void **) aHTTPNotify);
|
||||
}
|
||||
|
||||
nsCookieHTTPNotify::nsCookieHTTPNotify()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
nsCookieHTTPNotify::nsCookieHTTPNotify() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCookieHTTPNotify::~nsCookieHTTPNotify()
|
||||
{
|
||||
|
||||
nsCookieHTTPNotify::~nsCookieHTTPNotify() {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// nsIHTTPNotify
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIHTTPChannel* pHTTPConnection= nsnull;
|
||||
|
||||
if (aContext) {
|
||||
rv = aContext->QueryInterface(nsIHTTPChannel::GetIID(),
|
||||
(void**)&pHTTPConnection);
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsIURI* pURL;
|
||||
rv = pHTTPConnection->GetURI(&pURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
char *url;
|
||||
if (pURL == nsnull) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = pURL->GetSpec(&url);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (url == nsnull) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
const char* cookie = ::NET_GetCookie(url);
|
||||
|
||||
if (cookie == nsnull) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(url);
|
||||
return rv;
|
||||
}
|
||||
rv = pHTTPConnection->SetRequestHeader("Cookie", cookie);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext) {
|
||||
nsresult rv;
|
||||
nsIHTTPChannel* pHTTPConnection= nsnull;
|
||||
if (aContext) {
|
||||
rv = aContext->QueryInterface(nsIHTTPChannel::GetIID(), (void**)&pHTTPConnection);
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
nsIURI* pURL;
|
||||
rv = pHTTPConnection->GetURI(&pURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
char *url;
|
||||
if (pURL == nsnull) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
rv = pURL->GetSpec(&url);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
if (url == nsnull) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
const char* cookie = ::COOKIE_GetCookie(url);
|
||||
if (cookie == nsnull) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(url);
|
||||
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
rv = pHTTPConnection->SetRequestHeader("Cookie", cookie);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(url);
|
||||
return rv;
|
||||
}
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(url);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIHTTPChannel* pHTTPConnection= nsnull;
|
||||
|
||||
if (aContext) {
|
||||
rv = aContext->QueryInterface(nsIHTTPChannel::GetIID(),
|
||||
(void**)&pHTTPConnection);
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
||||
char* cookie;
|
||||
rv = pHTTPConnection->GetResponseHeader("Set-Cookie", &cookie);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (cookie) {
|
||||
printf("\nRecieving ... %s\n", cookie);
|
||||
nsIURI* pURL;
|
||||
rv = pHTTPConnection->GetURI(&pURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
char *url;
|
||||
if (pURL == nsnull) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = pURL->GetSpec(&url);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (url == nsnull) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *pDate = nsnull;
|
||||
rv = pHTTPConnection->GetResponseHeader("Date", &pDate);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if(pDate) {
|
||||
NET_SetCookieStringFromHttp(url, cookie, pDate);
|
||||
nsCRT::free(pDate);
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(pURL);
|
||||
nsCRT::free(url);
|
||||
nsCRT::free(cookie);
|
||||
}
|
||||
|
||||
nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext) {
|
||||
nsresult rv;
|
||||
nsIHTTPChannel* pHTTPConnection= nsnull;
|
||||
if (aContext) {
|
||||
rv = aContext->QueryInterface(nsIHTTPChannel::GetIID(), (void**)&pHTTPConnection);
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
char* cookie;
|
||||
rv = pHTTPConnection->GetResponseHeader("Set-Cookie", &cookie);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
if (cookie) {
|
||||
printf("\nRecieving ... %s\n", cookie);
|
||||
nsIURI* pURL;
|
||||
rv = pHTTPConnection->GetURI(&pURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
char *url;
|
||||
if (pURL == nsnull) {
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
rv = pURL->GetSpec(&url);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
if (url == nsnull) {
|
||||
NS_RELEASE(pURL);
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
nsCRT::free(cookie);
|
||||
return rv;
|
||||
}
|
||||
char *pDate = nsnull;
|
||||
rv = pHTTPConnection->GetResponseHeader("Date", &pDate);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if(pDate) {
|
||||
COOKIE_SetCookieStringFromHttp(url, cookie, pDate);
|
||||
nsCRT::free(pDate);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(pURL);
|
||||
nsCRT::free(url);
|
||||
nsCRT::free(cookie);
|
||||
}
|
||||
NS_RELEASE(pHTTPConnection);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -211,52 +174,40 @@ nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext)
|
|||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsCookieHTTPNotifyFactory, kIFactoryIID);
|
||||
|
||||
nsCookieHTTPNotifyFactory::nsCookieHTTPNotifyFactory(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
nsCookieHTTPNotifyFactory::nsCookieHTTPNotifyFactory(void) {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCookieHTTPNotifyFactory::~nsCookieHTTPNotifyFactory(void)
|
||||
{
|
||||
|
||||
nsCookieHTTPNotifyFactory::~nsCookieHTTPNotifyFactory(void) {
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieHTTPNotifyFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
nsIHTTPNotify* inst = nsnull;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&inst)))
|
||||
return rv;
|
||||
|
||||
if (!inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
nsCookieHTTPNotifyFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
|
||||
if (! aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
*aResult = nsnull;
|
||||
nsresult rv;
|
||||
nsIHTTPNotify* inst = nsnull;
|
||||
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&inst))) {
|
||||
return rv;
|
||||
}
|
||||
if (!inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieHTTPNotifyFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
nsCookieHTTPNotifyFactory::LockFactory(PRBool aLock) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,21 +27,19 @@
|
|||
{ 0x6bc1f522, 0x1f45, 0x11d3, { 0x8a, 0xd4, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } };
|
||||
|
||||
|
||||
class nsCookieHTTPNotify : public nsIHTTPNotify
|
||||
{
|
||||
class nsCookieHTTPNotify : public nsIHTTPNotify {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIHttpNotify methods:
|
||||
NS_IMETHOD ModifyRequest(nsISupports *aContext);
|
||||
NS_IMETHOD AsyncExamineResponse(nsISupports *aContext);
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIHttpNotify methods:
|
||||
NS_IMETHOD ModifyRequest(nsISupports *aContext);
|
||||
NS_IMETHOD AsyncExamineResponse(nsISupports *aContext);
|
||||
|
||||
// nsCookieHTTPNotify methods:
|
||||
nsCookieHTTPNotify();
|
||||
virtual ~nsCookieHTTPNotify();
|
||||
// nsCookieHTTPNotify methods:
|
||||
nsCookieHTTPNotify();
|
||||
virtual ~nsCookieHTTPNotify();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -50,24 +48,17 @@ private:
|
|||
class nsCookieHTTPNotifyFactory : public nsIFactory {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods:
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
// nsCookieHTTPNotifyFactory methods:
|
||||
|
||||
nsCookieHTTPNotifyFactory(void);
|
||||
virtual ~nsCookieHTTPNotifyFactory(void);
|
||||
// nsIFactory methods:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
// nsCookieHTTPNotifyFactory methods:
|
||||
nsCookieHTTPNotifyFactory(void);
|
||||
virtual ~nsCookieHTTPNotifyFactory(void);
|
||||
};
|
||||
|
||||
extern NS_EXPORT nsresult NS_NewCookieHTTPNotify(nsIHTTPNotify** aHTTPNotify);
|
||||
|
||||
|
||||
#endif /* nsCookieHTTPNotify_h___ */
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsCookie.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kICookieServiceIID, NS_ICOOKIESERVICE_IID);
|
||||
|
||||
|
@ -35,37 +34,31 @@ static NS_DEFINE_CID(kNetModuleMgrCID, NS_NETMODULEMGR_CID);
|
|||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_IID(kCookieHTTPNotifyCID, NS_COOKIEHTTPNOTIFY_CID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsCookieService : public nsICookieService {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICookieService
|
||||
static nsresult GetCookieService(nsICookieService** aCookieService);
|
||||
|
||||
|
||||
NS_IMETHOD GetCookieString(nsIURI *aURL, nsString& aCookie);
|
||||
NS_IMETHOD SetCookieString(nsIURI *aURL, const nsString& aCookie);
|
||||
// nsICookieService
|
||||
static nsresult GetCookieService(nsICookieService** aCookieService);
|
||||
|
||||
NS_IMETHOD Cookie_DisplayCookieInfoAsHTML();
|
||||
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results);
|
||||
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList);
|
||||
NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList);
|
||||
NS_IMETHOD GetCookieString(nsIURI *aURL, nsString& aCookie);
|
||||
NS_IMETHOD SetCookieString(nsIURI *aURL, const nsString& aCookie);
|
||||
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results);
|
||||
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList);
|
||||
NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList);
|
||||
|
||||
nsCookieService();
|
||||
virtual ~nsCookieService(void);
|
||||
nsCookieService();
|
||||
virtual ~nsCookieService(void);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
nsIHTTPNotify *mCookieHTTPNotify;
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsIHTTPNotify *mCookieHTTPNotify;
|
||||
nsresult Init();
|
||||
};
|
||||
|
||||
static nsCookieService* gCookieService = nsnull; // The one-and-only CookieService
|
||||
|
@ -75,290 +68,232 @@ static nsCookieService* gCookieService = nsnull; // The one-and-only CookieServi
|
|||
class nsCookieServiceFactory : public nsIFactory {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods:
|
||||
// nsIFactory methods:
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
// nsCookieService methods:
|
||||
|
||||
nsCookieServiceFactory(void);
|
||||
virtual ~nsCookieServiceFactory(void);
|
||||
// nsCookieService methods:
|
||||
|
||||
nsCookieServiceFactory(void);
|
||||
virtual ~nsCookieServiceFactory(void);
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookieService Implementation
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCookieService, kICookieServiceIID);
|
||||
|
||||
NS_EXPORT nsresult NS_NewCookieService(nsICookieService** aCookieService)
|
||||
{
|
||||
return nsCookieService::GetCookieService(aCookieService);
|
||||
NS_EXPORT nsresult NS_NewCookieService(nsICookieService** aCookieService) {
|
||||
return nsCookieService::GetCookieService(aCookieService);
|
||||
}
|
||||
|
||||
nsCookieService::nsCookieService()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mCookieHTTPNotify = nsnull;
|
||||
|
||||
Init();
|
||||
nsCookieService::nsCookieService() {
|
||||
NS_INIT_REFCNT();
|
||||
mCookieHTTPNotify = nsnull;
|
||||
Init();
|
||||
}
|
||||
|
||||
nsCookieService::~nsCookieService(void)
|
||||
{
|
||||
gCookieService = nsnull;
|
||||
nsCookieService::~nsCookieService(void) {
|
||||
gCookieService = nsnull;
|
||||
}
|
||||
|
||||
nsresult nsCookieService::GetCookieService(nsICookieService** aCookieService)
|
||||
{
|
||||
if (! gCookieService) {
|
||||
nsCookieService* it = new nsCookieService();
|
||||
if (! it)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
gCookieService = it;
|
||||
nsresult nsCookieService::GetCookieService(nsICookieService** aCookieService) {
|
||||
if (! gCookieService) {
|
||||
nsCookieService* it = new nsCookieService();
|
||||
if (! it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_ADDREF(gCookieService);
|
||||
*aCookieService = gCookieService;
|
||||
return NS_OK;
|
||||
gCookieService = it;
|
||||
}
|
||||
NS_ADDREF(gCookieService);
|
||||
*aCookieService = gCookieService;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsCookieService::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsINetModuleMgr, pNetModuleMgr, kNetModuleMgrCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIEventQueue* eventQ;
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&mCookieHTTPNotify)))
|
||||
return rv;
|
||||
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_PROGID, eventQ, mCookieHTTPNotify, &kCookieHTTPNotifyCID);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_PROGID, eventQ, mCookieHTTPNotify, &kCookieHTTPNotifyCID);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
COOKIE_RegisterCookiePrefCallbacks();
|
||||
|
||||
return rv;
|
||||
nsresult nsCookieService::Init() {
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsINetModuleMgr, pNetModuleMgr, kNetModuleMgrCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
nsIEventQueue* eventQ;
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&mCookieHTTPNotify))) {
|
||||
return rv;
|
||||
}
|
||||
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_PROGID, eventQ, mCookieHTTPNotify, &kCookieHTTPNotifyCID);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_PROGID, eventQ, mCookieHTTPNotify, &kCookieHTTPNotifyCID);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
COOKIE_RegisterCookiePrefCallbacks();
|
||||
COOKIE_ReadCookies();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::GetCookieString(nsIURI *aURL, nsString& aCookie)
|
||||
{
|
||||
|
||||
char *spec = NULL;
|
||||
nsresult result = aURL->GetSpec(&spec);
|
||||
NS_ASSERTION(result == NS_OK, "deal with this");
|
||||
char *cookie = NET_GetCookie((char *)spec);
|
||||
|
||||
if (nsnull != cookie) {
|
||||
aCookie.SetString(cookie);
|
||||
nsCRT::free(cookie);
|
||||
}
|
||||
else {
|
||||
aCookie.SetString("");
|
||||
}
|
||||
nsCRT::free(spec);
|
||||
|
||||
return NS_OK;
|
||||
nsCookieService::GetCookieString(nsIURI *aURL, nsString& aCookie) {
|
||||
char *spec = NULL;
|
||||
nsresult result = aURL->GetSpec(&spec);
|
||||
NS_ASSERTION(result == NS_OK, "deal with this");
|
||||
char *cookie = COOKIE_GetCookie((char *)spec);
|
||||
if (nsnull != cookie) {
|
||||
aCookie.SetString(cookie);
|
||||
nsCRT::free(cookie);
|
||||
} else {
|
||||
aCookie.SetString("");
|
||||
}
|
||||
nsCRT::free(spec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::SetCookieString(nsIURI *aURL, const nsString& aCookie)
|
||||
{
|
||||
char *spec = NULL;
|
||||
nsresult result = aURL->GetSpec(&spec);
|
||||
NS_ASSERTION(result == NS_OK, "deal with this");
|
||||
char *cookie = aCookie.ToNewCString();
|
||||
|
||||
NET_SetCookieString((char *)spec, cookie);
|
||||
|
||||
nsCRT::free(spec);
|
||||
delete []cookie;
|
||||
return NS_OK;
|
||||
nsCookieService::SetCookieString(nsIURI *aURL, const nsString& aCookie) {
|
||||
char *spec = NULL;
|
||||
nsresult result = aURL->GetSpec(&spec);
|
||||
NS_ASSERTION(result == NS_OK, "deal with this");
|
||||
char *cookie = aCookie.ToNewCString();
|
||||
COOKIE_SetCookieString((char *)spec, cookie);
|
||||
nsCRT::free(spec);
|
||||
delete []cookie;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::Cookie_DisplayCookieInfoAsHTML(){
|
||||
::COOKIE_DisplayCookieInfoAsHTML();
|
||||
return NS_OK;
|
||||
NS_IMETHODIMP nsCookieService::Cookie_CookieViewerReturn(nsAutoString results) {
|
||||
::COOKIE_CookieViewerReturn(results);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_CookieViewerReturn(nsAutoString results){
|
||||
::COOKIE_CookieViewerReturn(results);
|
||||
return NS_OK;
|
||||
NS_IMETHODIMP nsCookieService::Cookie_GetCookieListForViewer(nsString& aCookieList) {
|
||||
::COOKIE_GetCookieListForViewer(aCookieList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_GetCookieListForViewer(nsString& aCookieList){
|
||||
::COOKIE_GetCookieListForViewer(aCookieList);
|
||||
return NS_OK;
|
||||
NS_IMETHODIMP nsCookieService::Cookie_GetPermissionListForViewer(nsString& aPermissionList) {
|
||||
::COOKIE_GetPermissionListForViewer(aPermissionList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_GetPermissionListForViewer(nsString& aPermissionList){
|
||||
::COOKIE_GetPermissionListForViewer(aPermissionList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookieServiceFactory Implementation
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsCookieServiceFactory, kIFactoryIID);
|
||||
|
||||
nsCookieServiceFactory::nsCookieServiceFactory(void)
|
||||
{
|
||||
nsCookieServiceFactory::nsCookieServiceFactory(void) {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCookieServiceFactory::~nsCookieServiceFactory(void)
|
||||
{
|
||||
|
||||
nsCookieServiceFactory::~nsCookieServiceFactory(void) {
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieServiceFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
nsICookieService* inst = nsnull;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewCookieService(&inst)))
|
||||
return rv;
|
||||
|
||||
if (!inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
nsCookieServiceFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
|
||||
if (! aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
*aResult = nsnull;
|
||||
nsresult rv;
|
||||
nsICookieService* inst = nsnull;
|
||||
if (NS_FAILED(rv = NS_NewCookieService(&inst))) {
|
||||
return rv;
|
||||
}
|
||||
if (!inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieServiceFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
nsCookieServiceFactory::LockFactory(PRBool aLock) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DLL Entry Points:
|
||||
|
||||
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* servMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aClass.Equals(kCookieServiceCID)) {
|
||||
nsCookieServiceFactory *factory = new nsCookieServiceFactory();
|
||||
|
||||
if (factory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
NSGetFactory(
|
||||
nsISupports* servMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory) {
|
||||
if (! aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aClass.Equals(kCookieServiceCID)) {
|
||||
nsCookieServiceFactory *factory = new nsCookieServiceFactory();
|
||||
if (factory == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (aClass.Equals(kCookieHTTPNotifyCID)) {
|
||||
nsCookieHTTPNotifyFactory *factory = new nsCookieHTTPNotifyFactory();
|
||||
|
||||
if (factory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aClass.Equals(kCookieHTTPNotifyCID)) {
|
||||
nsCookieHTTPNotifyFactory *factory = new nsCookieHTTPNotifyFactory();
|
||||
if (factory == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* serviceMgr)
|
||||
{
|
||||
return PR_FALSE;
|
||||
NSCanUnload(nsISupports* serviceMgr) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSRegisterSelf(nsISupports* serviceMgr, const char* aPath)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::RegisterComponent(kCookieServiceCID,
|
||||
"CookieService",
|
||||
NS_COOKIESERVICE_PROGID,
|
||||
aPath,PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
rv = nsComponentManager::RegisterComponent(kCookieHTTPNotifyCID,
|
||||
"CookieHTTPNotifyService",
|
||||
"component://netscape/cookie-http-notify",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
NSRegisterSelf(nsISupports* serviceMgr, const char* aPath) {
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::RegisterComponent(kCookieServiceCID, "CookieService", NS_COOKIESERVICE_PROGID, aPath,PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = nsComponentManager::RegisterComponent(kCookieHTTPNotifyCID, "CookieHTTPNotifyService", "component://netscape/cookie-http-notify", aPath, PR_TRUE, PR_TRUE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSUnregisterSelf(nsISupports* serviceMgr, const char* aPath)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = nsComponentManager::UnregisterComponent(kCookieServiceCID, aPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsComponentManager::UnregisterComponent(kCookieHTTPNotifyCID, aPath);
|
||||
|
||||
NSUnregisterSelf(nsISupports* serviceMgr, const char* aPath) {
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::UnregisterComponent(kCookieServiceCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = nsComponentManager::UnregisterComponent(kCookieHTTPNotifyCID, aPath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,47 +27,43 @@
|
|||
#define NS_ICOOKIESERVICE_IID \
|
||||
{ 0xab397772, 0x12d3, 0x11d3, { 0x8a, 0xd1, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } };
|
||||
|
||||
|
||||
// {AB397774-12D3-11d3-8AD1-00105A1B8860}
|
||||
#define NS_COOKIESERVICE_CID \
|
||||
{ 0xab397774, 0x12d3, 0x11d3, { 0x8a, 0xd1, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } };
|
||||
|
||||
|
||||
class nsICookieService : public nsISupports {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ICOOKIESERVICE_IID; return iid; }
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ICOOKIESERVICE_IID; return iid; }
|
||||
|
||||
/**
|
||||
* 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(nsIURI *aURL, nsString& aCookie)=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(nsIURI *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(nsIURI *aURL, const 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(nsIURI *aURL, const nsString& aCookie)=0;
|
||||
|
||||
|
||||
NS_IMETHOD Cookie_DisplayCookieInfoAsHTML()=0;
|
||||
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results)=0;
|
||||
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList)=0;
|
||||
NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList)=0;
|
||||
|
||||
/*
|
||||
* Interface routines for cookie viewer
|
||||
*/
|
||||
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results)=0;
|
||||
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList)=0;
|
||||
NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList)=0;
|
||||
};
|
||||
|
||||
|
||||
/* ProgID prefixes for Cookie DLL registration. */
|
||||
#define NS_COOKIESERVICE_PROGID "component:||netscape|cookie"
|
||||
|
||||
|
||||
#endif /* nsICookieService_h__ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче