Beautify...

This commit is contained in:
dp%netscape.com 1999-11-23 07:54:25 +00:00
parent add180df18
commit 0b38786a86

View File

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
@ -38,182 +38,188 @@ NS_IMPL_ISUPPORTS2(nsCookieHTTPNotify, nsIHTTPNotify, nsINetNotify);
///////////////////////////////////
// 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()
{
}
NS_METHOD
nsCookieHTTPNotify::Create(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))) {
nsCookieHTTPNotify::Create(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;
}
NS_RELEASE(inst);
return rv;
}
if (!inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = NULL;
}
NS_RELEASE(inst);
return rv;
}
///////////////////////////////////
// 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;
}
nsXPIDLCString url;
if (pURL == nsnull) {
NS_RELEASE(pHTTPConnection);
return rv;
}
rv = pURL->GetSpec(getter_Copies(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((char*)(const char*)url);
if (cookie == nsnull) {
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
return rv;
}
nsCOMPtr<nsIAtom> cookieHeader;
// XXX: Should cache this atom? HTTP atoms *msut* be lower case
cookieHeader = NS_NewAtom("cookie");
if (!cookieHeader) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
rv = pHTTPConnection->SetRequestHeader(cookieHeader, cookie);
}
if (NS_FAILED(rv)) {
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
return rv;
}
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
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;
nsCOMPtr<nsIAtom> header;
// XXX: Should cache this atom? HTTP atoms *msut* be lower case
header = NS_NewAtom("set-cookie");
if (!header) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
rv = pHTTPConnection->GetResponseHeader(header, &cookie);
}
if (NS_FAILED(rv)) {
NS_RELEASE(pHTTPConnection);
return rv;
}
if (cookie) {
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);
nsCRT::free(cookie);
return rv;
NS_RELEASE(pHTTPConnection);
return rv;
}
nsXPIDLCString url;
if (pURL == nsnull) {
NS_RELEASE(pHTTPConnection);
nsCRT::free(cookie);
return rv;
NS_RELEASE(pHTTPConnection);
return rv;
}
rv = pURL->GetSpec(getter_Copies(url));
if (NS_FAILED(rv)) {
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
nsCRT::free(cookie);
return rv;
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
return rv;
}
if (url == nsnull) {
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
nsCRT::free(cookie);
return rv;
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
return rv;
}
char *pDate = nsnull;
const char* cookie = ::COOKIE_GetCookie((char*)(const char*)url);
if (cookie == nsnull) {
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
return rv;
}
nsCOMPtr<nsIAtom> cookieHeader;
// XXX: Should cache this atom? HTTP atoms *msut* be lower case
header = NS_NewAtom("date");
if (!header) {
rv = NS_ERROR_OUT_OF_MEMORY;
cookieHeader = NS_NewAtom("cookie");
if (!cookieHeader) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
rv = pHTTPConnection->GetResponseHeader(header, &pDate);
rv = pHTTPConnection->SetRequestHeader(cookieHeader, cookie);
}
if (NS_SUCCEEDED(rv)) {
COOKIE_SetCookieStringFromHttp((char*)(const char*)url, cookie, pDate);
if(pDate) {
nsCRT::free(pDate);
}
if (NS_FAILED(rv)) {
NS_RELEASE(pURL);
NS_RELEASE(pHTTPConnection);
return rv;
}
NS_RELEASE(pURL);
nsCRT::free(cookie);
}
NS_RELEASE(pHTTPConnection);
return NS_OK;
NS_RELEASE(pHTTPConnection);
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;
nsCOMPtr<nsIAtom> header;
// XXX: Should cache this atom? HTTP atoms *msut* be lower case
header = NS_NewAtom("set-cookie");
if (!header) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
rv = pHTTPConnection->GetResponseHeader(header, &cookie);
}
if (NS_FAILED(rv)) {
NS_RELEASE(pHTTPConnection);
return rv;
}
if (cookie) {
nsIURI* pURL;
rv = pHTTPConnection->GetURI(&pURL);
if (NS_FAILED(rv)) {
NS_RELEASE(pHTTPConnection);
nsCRT::free(cookie);
return rv;
}
nsXPIDLCString url;
if (pURL == nsnull) {
NS_RELEASE(pHTTPConnection);
nsCRT::free(cookie);
return rv;
}
rv = pURL->GetSpec(getter_Copies(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;
// XXX: Should cache this atom? HTTP atoms *msut* be lower case
header = NS_NewAtom("date");
if (!header) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
rv = pHTTPConnection->GetResponseHeader(header, &pDate);
}
if (NS_SUCCEEDED(rv)) {
COOKIE_SetCookieStringFromHttp((char*)(const char*)url, cookie, pDate);
if(pDate) {
nsCRT::free(pDate);
}
}
NS_RELEASE(pURL);
nsCRT::free(cookie);
}
NS_RELEASE(pHTTPConnection);
return NS_OK;
}