Package Kit, WebPositive: Standardize string hashes.
Use either HashString or BString::HashValue (both of which currently use the "modified hashpjw".)
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
#include <util/OpenHashTable.h>
|
#include <util/OpenHashTable.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -18,9 +19,6 @@ namespace BHPKG {
|
|||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
uint32 hash_string(const char* string);
|
|
||||||
|
|
||||||
|
|
||||||
struct CachedString {
|
struct CachedString {
|
||||||
char* string;
|
char* string;
|
||||||
int32 index;
|
int32 index;
|
||||||
@@ -57,7 +55,7 @@ struct CachedStringHashDefinition {
|
|||||||
|
|
||||||
size_t HashKey(const char* key) const
|
size_t HashKey(const char* key) const
|
||||||
{
|
{
|
||||||
return hash_string(key);
|
return BString::HashValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Hash(const CachedString* value) const
|
size_t Hash(const CachedString* value) const
|
||||||
|
|||||||
@@ -1813,7 +1813,7 @@ BrowserWindow::AuthenticationChallenge(BString message, BString& inOutUser,
|
|||||||
= CredentialsStorage::SessionInstance();
|
= CredentialsStorage::SessionInstance();
|
||||||
|
|
||||||
// TODO: Using the message as key here is not so smart.
|
// TODO: Using the message as key here is not so smart.
|
||||||
HashKeyString key(message);
|
HashString key(message);
|
||||||
|
|
||||||
if (failureCount == 0) {
|
if (failureCount == 0) {
|
||||||
if (persistentStorage->Contains(key)) {
|
if (persistentStorage->Contains(key)) {
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ CredentialsStorage::PersistentInstance()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CredentialsStorage::Contains(const HashKeyString& key)
|
CredentialsStorage::Contains(const HashString& key)
|
||||||
{
|
{
|
||||||
BAutolock _(this);
|
BAutolock _(this);
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ CredentialsStorage::Contains(const HashKeyString& key)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CredentialsStorage::PutCredentials(const HashKeyString& key,
|
CredentialsStorage::PutCredentials(const HashString& key,
|
||||||
const Credentials& credentials)
|
const Credentials& credentials)
|
||||||
{
|
{
|
||||||
BAutolock _(this);
|
BAutolock _(this);
|
||||||
@@ -177,7 +177,7 @@ CredentialsStorage::PutCredentials(const HashKeyString& key,
|
|||||||
|
|
||||||
|
|
||||||
Credentials
|
Credentials
|
||||||
CredentialsStorage::GetCredentials(const HashKeyString& key)
|
CredentialsStorage::GetCredentials(const HashString& key)
|
||||||
{
|
{
|
||||||
BAutolock _(this);
|
BAutolock _(this);
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ CredentialsStorage::_SaveSettings() const
|
|||||||
const CredentialMap::Entry& entry = iterator.Next();
|
const CredentialMap::Entry& entry = iterator.Next();
|
||||||
if (entry.value.Archive(&credentialsArchive) != B_OK
|
if (entry.value.Archive(&credentialsArchive) != B_OK
|
||||||
|| credentialsArchive.AddString("key",
|
|| credentialsArchive.AddString("key",
|
||||||
entry.key.value) != B_OK) {
|
entry.key.GetString()) != B_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (settingsArchive.AddMessage("credentials",
|
if (settingsArchive.AddMessage("credentials",
|
||||||
|
|||||||
@@ -6,11 +6,13 @@
|
|||||||
#ifndef CREDENTIAL_STORAGE_H
|
#ifndef CREDENTIAL_STORAGE_H
|
||||||
#define CREDENTIAL_STORAGE_H
|
#define CREDENTIAL_STORAGE_H
|
||||||
|
|
||||||
#include "HashKeys.h"
|
|
||||||
#include "HashMap.h"
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include "HashMap.h"
|
||||||
|
#include "HashString.h"
|
||||||
|
|
||||||
|
|
||||||
class BFile;
|
class BFile;
|
||||||
class BMessage;
|
class BMessage;
|
||||||
@@ -48,10 +50,10 @@ public:
|
|||||||
static CredentialsStorage* SessionInstance();
|
static CredentialsStorage* SessionInstance();
|
||||||
static CredentialsStorage* PersistentInstance();
|
static CredentialsStorage* PersistentInstance();
|
||||||
|
|
||||||
bool Contains(const HashKeyString& key);
|
bool Contains(const BPrivate::HashString& key);
|
||||||
status_t PutCredentials(const HashKeyString& key,
|
status_t PutCredentials(const HashString& key,
|
||||||
const Credentials& credentials);
|
const Credentials& credentials);
|
||||||
Credentials GetCredentials(const HashKeyString& key);
|
Credentials GetCredentials(const HashString& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CredentialsStorage(bool persistent);
|
CredentialsStorage(bool persistent);
|
||||||
@@ -63,7 +65,7 @@ private:
|
|||||||
uint32 mode) const;
|
uint32 mode) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef HashMap<HashKeyString, Credentials> CredentialMap;
|
typedef HashMap<HashString, Credentials> CredentialMap;
|
||||||
CredentialMap fCredentialMap;
|
CredentialMap fCredentialMap;
|
||||||
|
|
||||||
static CredentialsStorage sPersistentInstance;
|
static CredentialsStorage sPersistentInstance;
|
||||||
@@ -74,4 +76,3 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
#endif // CREDENTIAL_STORAGE_H
|
#endif // CREDENTIAL_STORAGE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010, Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
|
|
||||||
* Copyright 2004-2007, Ingo Weinhold <ingo_weinhold@gmx.de>. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
#ifndef HASH_KEYS_H
|
|
||||||
#define HASH_KEYS_H
|
|
||||||
|
|
||||||
#include <String.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// TODO: Move here from HashMap.h and adapt all clients.
|
|
||||||
// HashKey32
|
|
||||||
template<typename Value>
|
|
||||||
struct HashKey32 {
|
|
||||||
HashKey32() {}
|
|
||||||
HashKey32(const Value& value) : value(value) {}
|
|
||||||
|
|
||||||
uint32 GetHashCode() const
|
|
||||||
{
|
|
||||||
return (uint32)value;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashKey32<Value> operator=(const HashKey32<Value>& other)
|
|
||||||
{
|
|
||||||
value = other.value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const HashKey32<Value>& other) const
|
|
||||||
{
|
|
||||||
return (value == other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const HashKey32<Value>& other) const
|
|
||||||
{
|
|
||||||
return (value != other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Value value;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// HashKey64
|
|
||||||
template<typename Value>
|
|
||||||
struct HashKey64 {
|
|
||||||
HashKey64() {}
|
|
||||||
HashKey64(const Value& value) : value(value) {}
|
|
||||||
|
|
||||||
uint32 GetHashCode() const
|
|
||||||
{
|
|
||||||
uint64 v = (uint64)value;
|
|
||||||
return (uint32)(v >> 32) ^ (uint32)v;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashKey64<Value> operator=(const HashKey64<Value>& other)
|
|
||||||
{
|
|
||||||
value = other.value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const HashKey64<Value>& other) const
|
|
||||||
{
|
|
||||||
return (value == other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const HashKey64<Value>& other) const
|
|
||||||
{
|
|
||||||
return (value != other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Value value;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct HashKeyString {
|
|
||||||
HashKeyString() {}
|
|
||||||
HashKeyString(const BString& value) : value(value) {}
|
|
||||||
HashKeyString(const char* string) : value(string) {}
|
|
||||||
|
|
||||||
uint32 GetHashCode() const
|
|
||||||
{
|
|
||||||
// from the Dragon Book: a slightly modified hashpjw()
|
|
||||||
uint32 hash = 0;
|
|
||||||
const char* string = value.String();
|
|
||||||
if (string != NULL) {
|
|
||||||
for (; *string; string++) {
|
|
||||||
uint32 g = hash & 0xf0000000;
|
|
||||||
if (g != 0)
|
|
||||||
hash ^= g >> 24;
|
|
||||||
hash = (hash << 4) + *string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashKeyString operator=(const HashKeyString& other)
|
|
||||||
{
|
|
||||||
value = other.value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const HashKeyString& other) const
|
|
||||||
{
|
|
||||||
return (value == other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const HashKeyString& other) const
|
|
||||||
{
|
|
||||||
return (value != other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
BString value;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
using BPrivate::HashKeyString;
|
|
||||||
|
|
||||||
#endif // HASH_KEYS_H
|
|
||||||
@@ -260,7 +260,7 @@ private:
|
|||||||
|
|
||||||
size_t HashKey(const char* key) const
|
size_t HashKey(const char* key) const
|
||||||
{
|
{
|
||||||
return string_hash(key);
|
return BString::HashValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Hash(const Entry* value) const
|
size_t Hash(const Entry* value) const
|
||||||
|
|||||||
@@ -14,26 +14,6 @@ namespace BHPKG {
|
|||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
// from the Dragon Book: a slightly modified hashpjw()
|
|
||||||
uint32
|
|
||||||
hash_string(const char* string)
|
|
||||||
{
|
|
||||||
if (string == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
uint32 h = 0;
|
|
||||||
|
|
||||||
for (; *string; string++) {
|
|
||||||
uint32 g = h & 0xf0000000;
|
|
||||||
if (g)
|
|
||||||
h ^= g >> 24;
|
|
||||||
h = (h << 4) + *string;
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
StringCache::StringCache()
|
StringCache::StringCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user