Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_KEY_FILE_STORE_ |
| 6 | #define SHILL_KEY_FILE_STORE_ |
| 7 | |
| 8 | #include <base/file_path.h> |
| 9 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 10 | |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 11 | #include "shill/crypto_provider.h" |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 12 | #include "shill/glib.h" |
| 13 | #include "shill/store_interface.h" |
| 14 | |
| 15 | namespace shill { |
| 16 | |
| 17 | // A key file store implementation of the store interface. See |
| 18 | // http://www.gtk.org/api/2.6/glib/glib-Key-value-file-parser.html for details |
| 19 | // of the key file format. |
| 20 | class KeyFileStore : public StoreInterface { |
| 21 | public: |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 22 | explicit KeyFileStore(GLib *glib); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 23 | virtual ~KeyFileStore(); |
| 24 | |
| 25 | void set_path(const FilePath &path) { path_ = path; } |
| 26 | const FilePath &path() const { return path_; } |
| 27 | |
| 28 | // Inherited from StoreInterface. |
| 29 | virtual bool Open(); |
| 30 | virtual bool Close(); |
| 31 | virtual std::set<std::string> GetGroups(); |
| 32 | virtual bool ContainsGroup(const std::string &group); |
| 33 | virtual bool DeleteKey(const std::string &group, const std::string &key); |
| 34 | virtual bool DeleteGroup(const std::string &group); |
| 35 | virtual bool GetString(const std::string &group, |
| 36 | const std::string &key, |
| 37 | std::string *value); |
| 38 | virtual bool SetString(const std::string &group, |
| 39 | const std::string &key, |
| 40 | const std::string &value); |
| 41 | virtual bool GetBool(const std::string &group, |
| 42 | const std::string &key, |
| 43 | bool *value); |
| 44 | virtual bool SetBool(const std::string &group, |
| 45 | const std::string &key, |
| 46 | bool value); |
| 47 | virtual bool GetInt(const std::string &group, |
| 48 | const std::string &key, |
| 49 | int *value); |
| 50 | virtual bool SetInt(const std::string &group, |
| 51 | const std::string &key, |
| 52 | int value); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 53 | virtual bool GetStringList(const std::string &group, |
| 54 | const std::string &key, |
| 55 | std::vector<std::string> *value); |
| 56 | virtual bool SetStringList(const std::string &group, |
| 57 | const std::string &key, |
| 58 | const std::vector<std::string> &value); |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 59 | virtual bool GetCryptedString(const std::string &group, |
| 60 | const std::string &key, |
| 61 | std::string *value); |
| 62 | virtual bool SetCryptedString(const std::string &group, |
| 63 | const std::string &key, |
| 64 | const std::string &value); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 65 | private: |
| 66 | FRIEND_TEST(KeyFileStoreTest, OpenClose); |
| 67 | FRIEND_TEST(KeyFileStoreTest, OpenFail); |
| 68 | |
| 69 | void ReleaseKeyFile(); |
| 70 | |
| 71 | GLib *glib_; |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 72 | CryptoProvider crypto_; |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 73 | GKeyFile *key_file_; |
| 74 | FilePath path_; |
Darin Petkov | 86964e0 | 2011-06-29 13:49:28 -0700 | [diff] [blame] | 75 | |
| 76 | DISALLOW_COPY_AND_ASSIGN(KeyFileStore); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace shill |
| 80 | |
| 81 | #endif // SHILL_KEY_FILE_STORE_ |