blob: b448256e91ed05f56ef5825461aaca4117d15676 [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
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 Petkovb2841fd2011-06-30 12:54:12 -070053 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 Petkov86964e02011-06-29 13:49:28 -070059 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 Petkov083047b2011-06-23 20:42:48 -070065 private:
66 FRIEND_TEST(KeyFileStoreTest, OpenClose);
67 FRIEND_TEST(KeyFileStoreTest, OpenFail);
68
69 void ReleaseKeyFile();
70
71 GLib *glib_;
Darin Petkov86964e02011-06-29 13:49:28 -070072 CryptoProvider crypto_;
Darin Petkov083047b2011-06-23 20:42:48 -070073 GKeyFile *key_file_;
74 FilePath path_;
Darin Petkov86964e02011-06-29 13:49:28 -070075
76 DISALLOW_COPY_AND_ASSIGN(KeyFileStore);
Darin Petkov083047b2011-06-23 20:42:48 -070077};
78
79} // namespace shill
80
81#endif // SHILL_KEY_FILE_STORE_