/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
// HttpLog.h should generally be included first #include"HttpLog.h"
if (!node) { // create a new entry node and set the given entry auto node = UniquePtr<nsHttpAuthNode>(new nsHttpAuthNode);
LOG((" new nsHttpAuthNode %p for key='%s'", node.get(), key.get()));
rv = node->SetAuthEntry(path, realm, creds, challenge, ident, metadata); if (NS_FAILED(rv)) { return rv;
}
bool nsHttpAuthIdentity::Equals(const nsHttpAuthIdentity& ident) const { // we could probably optimize this with a single loop, but why bother? return mUser == ident.mUser && mPass == ident.mPass &&
mDomain == ident.mDomain;
}
nsresult nsHttpAuthEntry::AddPath(const nsACString& aPath) { for (constauto& p : mPaths) { if (StringBeginsWith(aPath, p)) { return NS_OK; // subpath already exists in the list
}
}
mPaths.AppendElement(aPath); return NS_OK;
}
nsresult nsHttpAuthEntry::Set(const nsACString& path, const nsACString& realm, const nsACString& creds, const nsACString& chall, const nsHttpAuthIdentity* ident,
nsISupports* metadata) { if (ident) {
mIdent = *ident;
} elseif (mIdent.IsEmpty()) { // If we are not given an identity and our cached identity has not been // initialized yet (so is currently empty), initialize it now by // filling it with nulls. We need to do that because consumers expect // that mIdent is initialized after this function returns.
mIdent.Clear();
}
nsresult rv = AddPath(path); if (NS_FAILED(rv)) { return rv;
}
nsHttpAuthEntry* nsHttpAuthNode::LookupEntryByPath(const nsACString& aPath) { // 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. for (uint32_t i = 0; i < mList.Length(); ++i) { constauto& entry = mList[i];
for (constauto& entryPath : entry->mPaths) { // proxy auth entries have no path, so require exact match on // empty path string. if (entryPath.IsEmpty()) { if (aPath.IsEmpty()) { return entry.get();
}
} elseif (StringBeginsWith(aPath, entryPath)) { return entry.get();
}
}
} return nullptr;
}
nsHttpAuthEntry* nsHttpAuthNode::LookupEntryByRealm(const nsACString& realm) { auto itr = LookupEntryItrByRealm(realm); if (itr != mList.cend()) { return itr->get();
}
return nullptr;
}
nsresult nsHttpAuthNode::SetAuthEntry(const nsACString& path, const nsACString& realm, const nsACString& creds, const nsACString& challenge, const nsHttpAuthIdentity* ident,
nsISupports* metadata) { // look for an entry with a matching realm
nsHttpAuthEntry* entry = LookupEntryByRealm(realm); if (!entry) { // We want the latest identity be at the begining of the list so that // the newest working credentials are sent first on new requests. // Changing a realm is sometimes used to "timeout" authrozization.
mList.InsertElementAt(
0, WrapUnique(new nsHttpAuthEntry(path, realm, creds, challenge, ident,
metadata)));
} else { // update the entry...
nsresult rv = entry->Set(path, realm, creds, challenge, ident, metadata);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
void nsHttpAuthNode::ClearAuthEntry(const nsACString& realm) { auto idx = LookupEntryItrByRealm(realm); if (idx != mList.cend()) {
mList.RemoveElementAt(idx);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.