repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / webpositive / CredentialsStorage.h
blob26767ae62d852d79e4415c05f511f4ea63546ce0
1 /*
2 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6 #ifndef CREDENTIAL_STORAGE_H
7 #define CREDENTIAL_STORAGE_H
9 #include "HashKeys.h"
10 #include "HashMap.h"
11 #include <Locker.h>
12 #include <String.h>
15 class BFile;
16 class BMessage;
17 class BString;
20 class Credentials {
21 public:
22 Credentials();
23 Credentials(const BString& username,
24 const BString& password);
25 Credentials(
26 const Credentials& other);
27 Credentials(const BMessage* archive);
28 ~Credentials();
30 status_t Archive(BMessage* archive) const;
32 Credentials& operator=(const Credentials& other);
34 bool operator==(const Credentials& other) const;
35 bool operator!=(const Credentials& other) const;
37 const BString& Username() const;
38 const BString& Password() const;
40 private:
41 BString fUsername;
42 BString fPassword;
46 class CredentialsStorage : public BLocker {
47 public:
48 static CredentialsStorage* SessionInstance();
49 static CredentialsStorage* PersistentInstance();
51 bool Contains(const HashKeyString& key);
52 status_t PutCredentials(const HashKeyString& key,
53 const Credentials& credentials);
54 Credentials GetCredentials(const HashKeyString& key);
56 private:
57 CredentialsStorage(bool persistent);
58 virtual ~CredentialsStorage();
60 void _LoadSettings();
61 void _SaveSettings() const;
62 bool _OpenSettingsFile(BFile& file,
63 uint32 mode) const;
65 private:
66 typedef HashMap<HashKeyString, Credentials> CredentialMap;
67 CredentialMap fCredentialMap;
69 static CredentialsStorage sPersistentInstance;
70 static CredentialsStorage sSessionInstance;
71 bool fSettingsLoaded;
72 bool fPersistent;
76 #endif // CREDENTIAL_STORAGE_H