blob: 2986ba919bc45c786a54b3629dd14fc9f3899e61 [file] [log] [blame]
Darin Petkov083047b2011-06-23 20:42:48 -07001// 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 Petkov86964e02011-06-29 13:49:28 -070011#include "shill/crypto_provider.h"
Darin Petkov083047b2011-06-23 20:42:48 -070012#include "shill/glib.h"
13#include "shill/store_interface.h"
14
15namespace 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.
20class KeyFileStore : public StoreInterface {
21 public:
Darin Petkovb2841fd2011-06-30 12:54:12 -070022 explicit KeyFileStore(GLib *glib);
Darin Petkov083047b2011-06-23 20:42:48 -070023 virtual ~KeyFileStore();
24
25 void set_path(const FilePath &path) { path_ = path; }
26 const FilePath &path() const { return path_; }
27
Chris Masone9d779932011-08-25 16:33:41 -070028 // Opens the store. Returns true on success. This method must be
29 // invoked before using any of the getters or setters.
30 // This method does not complete gracefully if invoked on a store
31 // that has been opened already but not closed yet.
32 bool Open();
33
34 // Closes the store and flushes it to persistent storage. Returns true on
35 // success. Note that the store is considered closed even if Close returns
36 // false.
37 // This method does not complete gracefully if invoked on a store
38 // that has not been opened successfully or has been closed already.
39 bool Close();
40
Darin Petkov083047b2011-06-23 20:42:48 -070041 // Inherited from StoreInterface.
Darin Petkov083047b2011-06-23 20:42:48 -070042 virtual std::set<std::string> GetGroups();
43 virtual bool ContainsGroup(const std::string &group);
44 virtual bool DeleteKey(const std::string &group, const std::string &key);
45 virtual bool DeleteGroup(const std::string &group);
46 virtual bool GetString(const std::string &group,
47 const std::string &key,
48 std::string *value);
49 virtual bool SetString(const std::string &group,
50 const std::string &key,
51 const std::string &value);
52 virtual bool GetBool(const std::string &group,
53 const std::string &key,
54 bool *value);
55 virtual bool SetBool(const std::string &group,
56 const std::string &key,
57 bool value);
58 virtual bool GetInt(const std::string &group,
59 const std::string &key,
60 int *value);
61 virtual bool SetInt(const std::string &group,
62 const std::string &key,
63 int value);
Darin Petkovb2841fd2011-06-30 12:54:12 -070064 virtual bool GetStringList(const std::string &group,
65 const std::string &key,
66 std::vector<std::string> *value);
67 virtual bool SetStringList(const std::string &group,
68 const std::string &key,
69 const std::vector<std::string> &value);
Darin Petkov86964e02011-06-29 13:49:28 -070070 virtual bool GetCryptedString(const std::string &group,
71 const std::string &key,
72 std::string *value);
73 virtual bool SetCryptedString(const std::string &group,
74 const std::string &key,
75 const std::string &value);
Darin Petkov083047b2011-06-23 20:42:48 -070076 private:
77 FRIEND_TEST(KeyFileStoreTest, OpenClose);
78 FRIEND_TEST(KeyFileStoreTest, OpenFail);
79
80 void ReleaseKeyFile();
81
82 GLib *glib_;
Darin Petkov86964e02011-06-29 13:49:28 -070083 CryptoProvider crypto_;
Darin Petkov083047b2011-06-23 20:42:48 -070084 GKeyFile *key_file_;
85 FilePath path_;
Darin Petkov86964e02011-06-29 13:49:28 -070086
87 DISALLOW_COPY_AND_ASSIGN(KeyFileStore);
Darin Petkov083047b2011-06-23 20:42:48 -070088};
89
90} // namespace shill
91
92#endif // SHILL_KEY_FILE_STORE_