Remove deprecated and unused network storage callbacks
[platform/upstream/connman.git] / src / storage.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "connman.h"
27
28 static GSList *storage_list = NULL;
29
30 static gint compare_priority(gconstpointer a, gconstpointer b)
31 {
32         const struct connman_storage *storage1 = a;
33         const struct connman_storage *storage2 = b;
34
35         return storage2->priority - storage1->priority;
36 }
37
38 /**
39  * connman_storage_register:
40  * @storage: storage module
41  *
42  * Register a new storage module
43  *
44  * Returns: %0 on success
45  */
46 int connman_storage_register(struct connman_storage *storage)
47 {
48         DBG("storage %p name %s", storage, storage->name);
49
50         storage_list = g_slist_insert_sorted(storage_list, storage,
51                                                         compare_priority);
52
53         return 0;
54 }
55
56 /**
57  * connman_storage_unregister:
58  * @storage: storage module
59  *
60  * Remove a previously registered storage module
61  */
62 void connman_storage_unregister(struct connman_storage *storage)
63 {
64         DBG("storage %p name %s", storage, storage->name);
65
66         storage_list = g_slist_remove(storage_list, storage);
67 }
68
69 GKeyFile *__connman_storage_open(void)
70 {
71         GKeyFile *keyfile;
72         gchar *pathname, *data = NULL;
73         gboolean result;
74         gsize length;
75
76         DBG("");
77
78         pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
79                                         __connman_profile_active_ident());
80         if (pathname == NULL)
81                 return NULL;
82
83         result = g_file_get_contents(pathname, &data, &length, NULL);
84
85         g_free(pathname);
86
87         if (result == FALSE)
88                 return NULL;
89
90         keyfile = g_key_file_new();
91
92         if (length > 0) {
93                 if (g_key_file_load_from_data(keyfile, data, length,
94                                                         0, NULL) == FALSE)
95                         goto done;
96         }
97
98 done:
99         g_free(data);
100
101         DBG("keyfile %p", keyfile);
102
103         return keyfile;
104 }
105
106 void __connman_storage_close(GKeyFile *keyfile, gboolean save)
107 {
108         gchar *pathname, *data = NULL;
109         gsize length = 0;
110
111         DBG("keyfile %p save %d", keyfile, save);
112
113         if (save == FALSE) {
114                 g_key_file_free(keyfile);
115                 return;
116         }
117
118         pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
119                                         __connman_profile_active_ident());
120         if (pathname == NULL)
121                 return;
122
123         data = g_key_file_to_data(keyfile, &length, NULL);
124
125         if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
126                 connman_error("Failed to store information");
127
128         g_free(data);
129
130         g_free(pathname);
131
132         g_key_file_free(keyfile);
133 }
134
135 int __connman_storage_load_global(void)
136 {
137         GSList *list;
138
139         DBG("");
140
141         for (list = storage_list; list; list = list->next) {
142                 struct connman_storage *storage = list->data;
143
144                 if (storage->global_load) {
145                         if (storage->global_load() == 0)
146                                 return 0;
147                 }
148         }
149
150         return -ENOENT;
151 }
152
153 int __connman_storage_save_global(void)
154 {
155         GSList *list;
156
157         DBG("");
158
159         for (list = storage_list; list; list = list->next) {
160                 struct connman_storage *storage = list->data;
161
162                 if (storage->global_save) {
163                         if (storage->global_save() == 0)
164                                 return 0;
165                 }
166         }
167
168         return -ENOENT;
169 }
170
171 int __connman_storage_load_device(struct connman_device *device)
172 {
173         GSList *list;
174
175         DBG("device %p", device);
176
177         for (list = storage_list; list; list = list->next) {
178                 struct connman_storage *storage = list->data;
179
180                 if (storage->device_load) {
181                         if (storage->device_load(device) == 0)
182                                 return 0;
183                 }
184         }
185
186         return -ENOENT;
187 }
188
189 int __connman_storage_save_device(struct connman_device *device)
190 {
191         GSList *list;
192
193         DBG("device %p", device);
194
195         for (list = storage_list; list; list = list->next) {
196                 struct connman_storage *storage = list->data;
197
198                 if (storage->device_save) {
199                         if (storage->device_save(device) == 0)
200                                 return 0;
201                 }
202         }
203
204         return -ENOENT;
205 }
206
207 int __connman_storage_load_service(struct connman_service *service)
208 {
209         GSList *list;
210
211         DBG("service %p", service);
212
213         for (list = storage_list; list; list = list->next) {
214                 struct connman_storage *storage = list->data;
215
216                 if (storage->service_load) {
217                         if (storage->service_load(service) == 0)
218                                 return 0;
219                 }
220         }
221
222         return -ENOENT;
223 }
224
225 int __connman_storage_save_service(struct connman_service *service)
226 {
227         GSList *list;
228
229         DBG("service %p", service);
230
231         for (list = storage_list; list; list = list->next) {
232                 struct connman_storage *storage = list->data;
233
234                 if (storage->service_save) {
235                         if (storage->service_save(service) == 0)
236                                 return 0;
237                 }
238         }
239
240         return -ENOENT;
241 }
242
243 int __connman_storage_init(void)
244 {
245         DBG("");
246
247         return 0;
248 }
249
250 void __connman_storage_cleanup(void)
251 {
252         DBG("");
253 }