2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsHttpAuthCache.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
GetAuthKey(const char *scheme, const char *host, PRInt32 port, nsCString &key)
|
|
|
|
{
|
|
|
|
key.Assign(scheme);
|
|
|
|
key.AppendLiteral("://");
|
|
|
|
key.Append(host);
|
|
|
|
key.Append(':');
|
|
|
|
key.AppendInt(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the two strings are equal or both empty. an empty string
|
|
|
|
// is either null or zero length.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
StrEquivalent(const PRUnichar *a, const PRUnichar *b)
|
|
|
|
{
|
|
|
|
static const PRUnichar emptyStr[] = {0};
|
|
|
|
|
|
|
|
if (!a)
|
|
|
|
a = emptyStr;
|
|
|
|
if (!b)
|
|
|
|
b = emptyStr;
|
|
|
|
|
|
|
|
return nsCRT::strcmp(a, b) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpAuthCache <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsHttpAuthCache::nsHttpAuthCache()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mDB(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpAuthCache::~nsHttpAuthCache()
|
|
|
|
{
|
|
|
|
if (mDB)
|
|
|
|
ClearAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthCache::Init()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(!mDB, NS_ERROR_ALREADY_INITIALIZED);
|
|
|
|
|
|
|
|
LOG(("nsHttpAuthCache::Init\n"));
|
|
|
|
|
|
|
|
mDB = PL_NewHashTable(128, (PLHashFunction) PL_HashString,
|
|
|
|
(PLHashComparator) PL_CompareStrings,
|
|
|
|
(PLHashComparator) 0, &gHashAllocOps, this);
|
|
|
|
if (!mDB)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthCache::GetAuthEntryForPath(const char *scheme,
|
|
|
|
const char *host,
|
|
|
|
PRInt32 port,
|
|
|
|
const char *path,
|
|
|
|
nsHttpAuthEntry **entry)
|
|
|
|
{
|
|
|
|
LOG(("nsHttpAuthCache::GetAuthEntryForPath [key=%s://%s:%d path=%s]\n",
|
|
|
|
scheme, host, port, path));
|
|
|
|
|
|
|
|
nsCAutoString key;
|
|
|
|
nsHttpAuthNode *node = LookupAuthNode(scheme, host, port, key);
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*entry = node->LookupEntryByPath(path);
|
|
|
|
return *entry ? NS_OK : NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthCache::GetAuthEntryForDomain(const char *scheme,
|
|
|
|
const char *host,
|
|
|
|
PRInt32 port,
|
|
|
|
const char *realm,
|
|
|
|
nsHttpAuthEntry **entry)
|
|
|
|
|
|
|
|
{
|
|
|
|
LOG(("nsHttpAuthCache::GetAuthEntryForDomain [key=%s://%s:%d realm=%s]\n",
|
|
|
|
scheme, host, port, realm));
|
|
|
|
|
|
|
|
nsCAutoString key;
|
|
|
|
nsHttpAuthNode *node = LookupAuthNode(scheme, host, port, key);
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*entry = node->LookupEntryByRealm(realm);
|
|
|
|
return *entry ? NS_OK : NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthCache::SetAuthEntry(const char *scheme,
|
|
|
|
const char *host,
|
|
|
|
PRInt32 port,
|
|
|
|
const char *path,
|
|
|
|
const char *realm,
|
|
|
|
const char *creds,
|
|
|
|
const char *challenge,
|
2010-02-06 07:06:48 -08:00
|
|
|
const nsHttpAuthIdentity *ident,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupports *metadata)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsHttpAuthCache::SetAuthEntry [key=%s://%s:%d realm=%s path=%s metadata=%x]\n",
|
|
|
|
scheme, host, port, realm, path, metadata));
|
|
|
|
|
|
|
|
if (!mDB) {
|
|
|
|
rv = Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString key;
|
|
|
|
nsHttpAuthNode *node = LookupAuthNode(scheme, host, port, key);
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
// create a new entry node and set the given entry
|
|
|
|
node = new nsHttpAuthNode();
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
rv = node->SetAuthEntry(path, realm, creds, challenge, ident, metadata);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
delete node;
|
|
|
|
else
|
|
|
|
PL_HashTableAdd(mDB, nsCRT::strdup(key.get()), node);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node->SetAuthEntry(path, realm, creds, challenge, ident, metadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpAuthCache::ClearAuthEntry(const char *scheme,
|
|
|
|
const char *host,
|
|
|
|
PRInt32 port,
|
|
|
|
const char *realm)
|
|
|
|
{
|
|
|
|
if (!mDB)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCAutoString key;
|
|
|
|
GetAuthKey(scheme, host, port, key);
|
|
|
|
PL_HashTableRemove(mDB, key.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthCache::ClearAll()
|
|
|
|
{
|
|
|
|
LOG(("nsHttpAuthCache::ClearAll\n"));
|
|
|
|
|
|
|
|
if (mDB) {
|
|
|
|
PL_HashTableDestroy(mDB);
|
|
|
|
mDB = 0;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpAuthCache <private>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsHttpAuthNode *
|
|
|
|
nsHttpAuthCache::LookupAuthNode(const char *scheme,
|
|
|
|
const char *host,
|
|
|
|
PRInt32 port,
|
|
|
|
nsCString &key)
|
|
|
|
{
|
|
|
|
if (!mDB)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetAuthKey(scheme, host, port, key);
|
|
|
|
|
|
|
|
return (nsHttpAuthNode *) PL_HashTableLookup(mDB, key.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nsHttpAuthCache::AllocTable(void *self, PRSize size)
|
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpAuthCache::FreeTable(void *self, void *item)
|
|
|
|
{
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLHashEntry *
|
|
|
|
nsHttpAuthCache::AllocEntry(void *self, const void *key)
|
|
|
|
{
|
|
|
|
return (PLHashEntry *) malloc(sizeof(PLHashEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpAuthCache::FreeEntry(void *self, PLHashEntry *he, PRUintn flag)
|
|
|
|
{
|
|
|
|
if (flag == HT_FREE_VALUE) {
|
|
|
|
// this would only happen if PL_HashTableAdd were to replace an
|
|
|
|
// existing entry in the hash table, but we _always_ do a lookup
|
|
|
|
// before adding a new entry to avoid this case.
|
|
|
|
NS_NOTREACHED("should never happen");
|
|
|
|
}
|
|
|
|
else if (flag == HT_FREE_ENTRY) {
|
|
|
|
// three wonderful flavors of freeing memory ;-)
|
|
|
|
delete (nsHttpAuthNode *) he->value;
|
|
|
|
nsCRT::free((char *) he->key);
|
|
|
|
free(he);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PLHashAllocOps nsHttpAuthCache::gHashAllocOps =
|
|
|
|
{
|
|
|
|
nsHttpAuthCache::AllocTable,
|
|
|
|
nsHttpAuthCache::FreeTable,
|
|
|
|
nsHttpAuthCache::AllocEntry,
|
|
|
|
nsHttpAuthCache::FreeEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpAuthIdentity
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthIdentity::Set(const PRUnichar *domain,
|
|
|
|
const PRUnichar *user,
|
|
|
|
const PRUnichar *pass)
|
|
|
|
{
|
|
|
|
PRUnichar *newUser, *newPass, *newDomain;
|
|
|
|
|
2012-05-30 10:43:39 -07:00
|
|
|
int domainLen = domain ? NS_strlen(domain) : 0;
|
|
|
|
int userLen = user ? NS_strlen(user) : 0;
|
|
|
|
int passLen = pass ? NS_strlen(pass) : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
int len = userLen + 1 + passLen + 1 + domainLen + 1;
|
|
|
|
newUser = (PRUnichar *) malloc(len * sizeof(PRUnichar));
|
|
|
|
if (!newUser)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
memcpy(newUser, user, userLen * sizeof(PRUnichar));
|
|
|
|
newUser[userLen] = 0;
|
|
|
|
|
|
|
|
newPass = &newUser[userLen + 1];
|
|
|
|
if (pass)
|
|
|
|
memcpy(newPass, pass, passLen * sizeof(PRUnichar));
|
|
|
|
newPass[passLen] = 0;
|
|
|
|
|
|
|
|
newDomain = &newPass[passLen + 1];
|
|
|
|
if (domain)
|
|
|
|
memcpy(newDomain, domain, domainLen * sizeof(PRUnichar));
|
|
|
|
newDomain[domainLen] = 0;
|
|
|
|
|
|
|
|
// wait until the end to clear member vars in case input params
|
|
|
|
// reference our members!
|
|
|
|
if (mUser)
|
|
|
|
free(mUser);
|
|
|
|
mUser = newUser;
|
|
|
|
mPass = newPass;
|
|
|
|
mDomain = newDomain;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpAuthIdentity::Clear()
|
|
|
|
{
|
|
|
|
if (mUser) {
|
|
|
|
free(mUser);
|
2012-07-30 07:20:58 -07:00
|
|
|
mUser = nullptr;
|
|
|
|
mPass = nullptr;
|
|
|
|
mDomain = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHttpAuthIdentity::Equals(const nsHttpAuthIdentity &ident) const
|
|
|
|
{
|
|
|
|
// we could probably optimize this with a single loop, but why bother?
|
|
|
|
return StrEquivalent(mUser, ident.mUser) &&
|
|
|
|
StrEquivalent(mPass, ident.mPass) &&
|
|
|
|
StrEquivalent(mDomain, ident.mDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpAuthEntry
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsHttpAuthEntry::~nsHttpAuthEntry()
|
|
|
|
{
|
|
|
|
if (mRealm)
|
|
|
|
free(mRealm);
|
|
|
|
|
|
|
|
while (mRoot) {
|
|
|
|
nsHttpAuthPath *ap = mRoot;
|
|
|
|
mRoot = mRoot->mNext;
|
|
|
|
free(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthEntry::AddPath(const char *aPath)
|
|
|
|
{
|
|
|
|
// null path matches empty path
|
|
|
|
if (!aPath)
|
|
|
|
aPath = "";
|
|
|
|
|
|
|
|
nsHttpAuthPath *tempPtr = mRoot;
|
|
|
|
while (tempPtr) {
|
|
|
|
const char *curpath = tempPtr->mPath;
|
2012-02-18 05:47:01 -08:00
|
|
|
if (strncmp(aPath, curpath, strlen(curpath)) == 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK; // subpath already exists in the list
|
|
|
|
|
|
|
|
tempPtr = tempPtr->mNext;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Append the aPath
|
|
|
|
nsHttpAuthPath *newAuthPath;
|
2012-02-18 05:47:01 -08:00
|
|
|
int newpathLen = strlen(aPath);
|
2007-03-22 10:30:00 -07:00
|
|
|
newAuthPath = (nsHttpAuthPath *) malloc(sizeof(nsHttpAuthPath) + newpathLen);
|
|
|
|
if (!newAuthPath)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
memcpy(newAuthPath->mPath, aPath, newpathLen+1);
|
2012-07-30 07:20:58 -07:00
|
|
|
newAuthPath->mNext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!mRoot)
|
|
|
|
mRoot = newAuthPath; //first entry
|
|
|
|
else
|
|
|
|
mTail->mNext = newAuthPath; // Append newAuthPath
|
|
|
|
|
|
|
|
//update the tail pointer.
|
|
|
|
mTail = newAuthPath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthEntry::Set(const char *path,
|
|
|
|
const char *realm,
|
|
|
|
const char *creds,
|
|
|
|
const char *chall,
|
2010-02-06 07:06:48 -08:00
|
|
|
const nsHttpAuthIdentity *ident,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupports *metadata)
|
|
|
|
{
|
|
|
|
char *newRealm, *newCreds, *newChall;
|
|
|
|
|
2012-02-18 05:47:01 -08:00
|
|
|
int realmLen = realm ? strlen(realm) : 0;
|
|
|
|
int credsLen = creds ? strlen(creds) : 0;
|
|
|
|
int challLen = chall ? strlen(chall) : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
int len = realmLen + 1 + credsLen + 1 + challLen + 1;
|
|
|
|
newRealm = (char *) malloc(len);
|
|
|
|
if (!newRealm)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (realm)
|
|
|
|
memcpy(newRealm, realm, realmLen);
|
|
|
|
newRealm[realmLen] = 0;
|
|
|
|
|
|
|
|
newCreds = &newRealm[realmLen + 1];
|
|
|
|
if (creds)
|
|
|
|
memcpy(newCreds, creds, credsLen);
|
|
|
|
newCreds[credsLen] = 0;
|
|
|
|
|
|
|
|
newChall = &newCreds[credsLen + 1];
|
|
|
|
if (chall)
|
|
|
|
memcpy(newChall, chall, challLen);
|
|
|
|
newChall[challLen] = 0;
|
|
|
|
|
2010-10-01 15:18:55 -07:00
|
|
|
nsresult rv = NS_OK;
|
2010-02-06 07:06:48 -08:00
|
|
|
if (ident) {
|
|
|
|
rv = mIdent.Set(*ident);
|
|
|
|
}
|
|
|
|
else if (mIdent.IsEmpty()) {
|
2011-02-05 16:04:14 -08:00
|
|
|
// If we are not given an identity and our cached identity has not been
|
|
|
|
// initialized yet (so is currently empty), initialize it now by
|
2010-02-06 07:06:48 -08:00
|
|
|
// filling it with nulls. We need to do that because consumers expect
|
|
|
|
// that mIdent is initialized after this function returns.
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = mIdent.Set(nullptr, nullptr, nullptr);
|
2010-02-06 07:06:48 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
free(newRealm);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = AddPath(path);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
free(newRealm);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait until the end to clear member vars in case input params
|
|
|
|
// reference our members!
|
|
|
|
if (mRealm)
|
|
|
|
free(mRealm);
|
|
|
|
|
|
|
|
mRealm = newRealm;
|
|
|
|
mCreds = newCreds;
|
|
|
|
mChallenge = newChall;
|
|
|
|
mMetaData = metadata;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpAuthNode
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsHttpAuthNode::nsHttpAuthNode()
|
|
|
|
{
|
|
|
|
LOG(("Creating nsHttpAuthNode @%x\n", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpAuthNode::~nsHttpAuthNode()
|
|
|
|
{
|
|
|
|
LOG(("Destroying nsHttpAuthNode @%x\n", this));
|
|
|
|
|
|
|
|
mList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpAuthEntry *
|
|
|
|
nsHttpAuthNode::LookupEntryByPath(const char *path)
|
|
|
|
{
|
|
|
|
nsHttpAuthEntry *entry;
|
|
|
|
|
|
|
|
// null path matches empty path
|
|
|
|
if (!path)
|
|
|
|
path = "";
|
|
|
|
|
|
|
|
// look for an entry that either matches or contains this directory.
|
|
|
|
// ie. we'll give out credentials if the given directory is a sub-
|
|
|
|
// directory of an existing entry.
|
2009-02-22 17:05:28 -08:00
|
|
|
for (PRUint32 i=0; i<mList.Length(); ++i) {
|
|
|
|
entry = mList[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHttpAuthPath *authPath = entry->RootPath();
|
|
|
|
while (authPath) {
|
|
|
|
const char *entryPath = authPath->mPath;
|
|
|
|
// proxy auth entries have no path, so require exact match on
|
|
|
|
// empty path string.
|
|
|
|
if (entryPath[0] == '\0') {
|
|
|
|
if (path[0] == '\0')
|
|
|
|
return entry;
|
|
|
|
}
|
2012-02-18 05:47:01 -08:00
|
|
|
else if (strncmp(path, entryPath, strlen(entryPath)) == 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return entry;
|
|
|
|
|
|
|
|
authPath = authPath->mNext;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpAuthEntry *
|
|
|
|
nsHttpAuthNode::LookupEntryByRealm(const char *realm)
|
|
|
|
{
|
|
|
|
nsHttpAuthEntry *entry;
|
|
|
|
|
|
|
|
// null realm matches empty realm
|
|
|
|
if (!realm)
|
|
|
|
realm = "";
|
|
|
|
|
|
|
|
// look for an entry that matches this realm
|
2009-02-22 17:05:28 -08:00
|
|
|
PRUint32 i;
|
|
|
|
for (i=0; i<mList.Length(); ++i) {
|
|
|
|
entry = mList[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
if (strcmp(realm, entry->Realm()) == 0)
|
|
|
|
return entry;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpAuthNode::SetAuthEntry(const char *path,
|
|
|
|
const char *realm,
|
|
|
|
const char *creds,
|
|
|
|
const char *challenge,
|
2010-02-06 07:06:48 -08:00
|
|
|
const nsHttpAuthIdentity *ident,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupports *metadata)
|
|
|
|
{
|
|
|
|
// look for an entry with a matching realm
|
|
|
|
nsHttpAuthEntry *entry = LookupEntryByRealm(realm);
|
|
|
|
if (!entry) {
|
|
|
|
entry = new nsHttpAuthEntry(path, realm, creds, challenge, ident, metadata);
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mList.AppendElement(entry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// update the entry...
|
|
|
|
entry->Set(path, realm, creds, challenge, ident, metadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpAuthNode::ClearAuthEntry(const char *realm)
|
|
|
|
{
|
|
|
|
nsHttpAuthEntry *entry = LookupEntryByRealm(realm);
|
|
|
|
if (entry) {
|
|
|
|
mList.RemoveElement(entry); // double search OK
|
|
|
|
}
|
|
|
|
}
|