blob: 02c104f0e309fc651fef82636ac95b3243ed8e95 [file] [log] [blame]
Richard Hughes980ef142017-06-16 12:45:27 +01001/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
4 *
Mario Limonciello51308e62018-05-28 20:05:46 -05005 * SPDX-License-Identifier: LGPL-2.1+
Richard Hughes980ef142017-06-16 12:45:27 +01006 */
7
8#include "config.h"
9
Richard Hughes1fd3ecf2018-04-16 10:53:46 +010010#include <appstream-glib.h>
Richard Hughes980ef142017-06-16 12:45:27 +010011#include <glib-object.h>
12#include <gio/gio.h>
Richard Hughes1fd3ecf2018-04-16 10:53:46 +010013#include <glib/gi18n.h>
Richard Hughes980ef142017-06-16 12:45:27 +010014
Richard Hughes4be17d12018-05-30 20:36:29 +010015#include "fu-common.h"
Richard Hughes980ef142017-06-16 12:45:27 +010016#include "fu-config.h"
17
Richard Hughes1fd3ecf2018-04-16 10:53:46 +010018#include "fwupd-common.h"
Richard Hughes4c369702017-06-16 15:31:38 +010019#include "fwupd-error.h"
20#include "fwupd-remote-private.h"
21
Richard Hughes980ef142017-06-16 12:45:27 +010022static void fu_config_finalize (GObject *obj);
23
24struct _FuConfig
25{
26 GObject parent_instance;
27 GKeyFile *keyfile;
Richard Hughes4c369702017-06-16 15:31:38 +010028 GPtrArray *remotes;
29 GPtrArray *monitors;
Richard Hughes980ef142017-06-16 12:45:27 +010030 GPtrArray *blacklist_devices;
31 GPtrArray *blacklist_plugins;
Richard Hughesc7bbbc22018-01-02 22:22:25 +000032 guint64 archive_size_max;
Richard Hughes1fd3ecf2018-04-16 10:53:46 +010033 AsStore *store_remotes;
34 GHashTable *os_release;
Richard Hughes980ef142017-06-16 12:45:27 +010035};
36
37G_DEFINE_TYPE (FuConfig, fu_config, G_TYPE_OBJECT)
38
Richard Hughes4c369702017-06-16 15:31:38 +010039static GPtrArray *
40fu_config_get_config_paths (void)
41{
42 GPtrArray *paths = g_ptr_array_new_with_free_func (g_free);
43 const gchar *remotes_dir;
44 const gchar *system_prefixlibdir = "/usr/lib/fwupd";
Richard Hughes4be17d12018-05-30 20:36:29 +010045 g_autofree gchar *configdir = NULL;
Richard Hughes4c369702017-06-16 15:31:38 +010046
47 /* only set by the self test program */
48 remotes_dir = g_getenv ("FU_SELF_TEST_REMOTES_DIR");
49 if (remotes_dir != NULL) {
50 g_ptr_array_add (paths, g_strdup (remotes_dir));
51 return paths;
52 }
53
54 /* use sysconfig, and then fall back to /etc */
Richard Hughes4be17d12018-05-30 20:36:29 +010055 configdir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG);
56 if (g_file_test (configdir, G_FILE_TEST_EXISTS))
57 g_ptr_array_add (paths, g_steal_pointer (&configdir));
Richard Hughes4c369702017-06-16 15:31:38 +010058
59 /* add in system-wide locations */
60 if (g_file_test (system_prefixlibdir, G_FILE_TEST_EXISTS))
61 g_ptr_array_add (paths, g_strdup (system_prefixlibdir));
62
63 return paths;
64}
65
66static void
67fu_config_monitor_changed_cb (GFileMonitor *monitor,
68 GFile *file,
69 GFile *other_file,
70 GFileMonitorEvent event_type,
71 gpointer user_data)
72{
73 FuConfig *self = FU_CONFIG (user_data);
74 g_autoptr(GError) error = NULL;
75 g_autofree gchar *filename = g_file_get_path (file);
76 g_debug ("%s changed, reloading all configs", filename);
77 if (!fu_config_load (self, &error))
78 g_warning ("failed to rescan config: %s", error->message);
79}
80
Richard Hughesfeb80272017-06-16 20:24:24 +010081static guint64
82fu_config_get_remote_mtime (FuConfig *self, FwupdRemote *remote)
83{
Richard Hughesfeb80272017-06-16 20:24:24 +010084 g_autoptr(GFile) file = NULL;
85 g_autoptr(GFileInfo) info = NULL;
86
Richard Hughescda1cdf2017-06-16 21:49:35 +010087 file = g_file_new_for_path (fwupd_remote_get_filename_cache (remote));
Richard Hughesfeb80272017-06-16 20:24:24 +010088 if (!g_file_query_exists (file, NULL))
89 return G_MAXUINT64;
90 info = g_file_query_info (file,
91 G_FILE_ATTRIBUTE_TIME_MODIFIED,
92 G_FILE_QUERY_INFO_NONE,
93 NULL, NULL);
94 if (info == NULL)
95 return G_MAXUINT64;
96 return g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
97}
98
Richard Hughes4c369702017-06-16 15:31:38 +010099static gboolean
Richard Hughescda1cdf2017-06-16 21:49:35 +0100100fu_config_add_inotify (FuConfig *self, const gchar *filename, GError **error)
101{
102 GFileMonitor *monitor;
103 g_autoptr(GFile) file = g_file_new_for_path (filename);
104
105 /* set up a notify watch */
106 monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, error);
107 if (monitor == NULL)
108 return FALSE;
109 g_signal_connect (monitor, "changed",
110 G_CALLBACK (fu_config_monitor_changed_cb), self);
111 g_ptr_array_add (self->monitors, monitor);
112 return TRUE;
113}
114
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100115static GString *
116fu_config_get_remote_agreement_default (FwupdRemote *self, GError **error)
117{
118 GString *str = g_string_new (NULL);
119
120 /* this is designed as a fallback; the actual warning should ideally
121 * come from the LVFS instance that is serving the remote */
122 g_string_append_printf (str, "%s\n",
123 /* TRANSLATORS: show the user a warning */
124 _("Your distributor may not have verified any of "
125 "the firmware updates for compatibility with your "
126 "system or connected devices."));
127 g_string_append_printf (str, "%s\n",
128 /* TRANSLATORS: show the user a warning */
129 _("Enabling this remote is done at your own risk."));
130 return str;
131}
132
133static GString *
134fu_config_get_remote_agreement_for_app (FwupdRemote *self, AsApp *app, GError **error)
135{
136#if AS_CHECK_VERSION(0,7,8)
137 const gchar *tmp = NULL;
138 AsAgreement *agreement;
139 AsAgreementSection *section;
140
141 /* get the default agreement section */
142 agreement = as_app_get_agreement_default (app);
143 if (agreement == NULL) {
144 g_set_error_literal (error,
145 FWUPD_ERROR,
146 FWUPD_ERROR_NOT_FOUND,
147 "No agreement found");
148 return NULL;
149 }
150 section = as_agreement_get_section_default (agreement);
151 if (section == NULL) {
152 g_set_error_literal (error,
153 FWUPD_ERROR,
154 FWUPD_ERROR_NOT_FOUND,
155 "No default section for agreement found");
156 return NULL;
157 }
158 tmp = as_agreement_section_get_description (section, NULL);
159 if (tmp == NULL) {
160 g_set_error_literal (error,
161 FWUPD_ERROR,
162 FWUPD_ERROR_NOT_FOUND,
163 "No description found in agreement section");
164 return NULL;
165 }
166 return g_string_new (tmp);
167#else
168 AsFormat *format;
169 GNode *n;
170 g_autoptr(AsNode) root = NULL;
171 g_autoptr(GFile) file = NULL;
172
173 /* parse the XML file */
174 format = as_app_get_format_default (app);
175 if (format == NULL) {
176 g_set_error_literal (error,
177 FWUPD_ERROR,
178 FWUPD_ERROR_NOT_FOUND,
179 "No format for Metainfo file");
180 return NULL;
181 }
182 file = g_file_new_for_path (as_format_get_filename (format));
183 root = as_node_from_file (file, AS_NODE_FROM_XML_FLAG_NONE, NULL, error);
184 if (root == NULL)
185 return NULL;
186
187 /* manually find the first agreement section */
188 n = as_node_find (root, "component/agreement/agreement_section/description");
189 if (n == NULL) {
190 g_set_error_literal (error,
191 FWUPD_ERROR,
192 FWUPD_ERROR_NOT_FOUND,
193 "No agreement description found");
194 return NULL;
195 }
196 return as_node_to_xml (n->children, AS_NODE_TO_XML_FLAG_INCLUDE_SIBLINGS);
197#endif
198}
199
200static gchar *
201fu_config_build_remote_component_id (FwupdRemote *remote)
202{
203 return g_strdup_printf ("org.freedesktop.fwupd.remotes.%s",
204 fwupd_remote_get_id (remote));
205}
206
Richard Hughescda1cdf2017-06-16 21:49:35 +0100207static gboolean
Richard Hughes4c369702017-06-16 15:31:38 +0100208fu_config_add_remotes_for_path (FuConfig *self, const gchar *path, GError **error)
209{
210 const gchar *tmp;
211 g_autofree gchar *path_remotes = NULL;
212 g_autoptr(GDir) dir = NULL;
213
214 path_remotes = g_build_filename (path, "remotes.d", NULL);
215 if (!g_file_test (path_remotes, G_FILE_TEST_EXISTS))
216 return TRUE;
Richard Hughese7b902e2018-03-05 16:50:35 +0000217 if (!fu_config_add_inotify (self, path_remotes, error))
218 return FALSE;
Richard Hughes4c369702017-06-16 15:31:38 +0100219 dir = g_dir_open (path_remotes, 0, error);
220 if (dir == NULL)
221 return FALSE;
222 while ((tmp = g_dir_read_name (dir)) != NULL) {
Richard Hughes4c369702017-06-16 15:31:38 +0100223 g_autofree gchar *filename = g_build_filename (path_remotes, tmp, NULL);
224 g_autoptr(FwupdRemote) remote = fwupd_remote_new ();
Richard Hughescda1cdf2017-06-16 21:49:35 +0100225
Richard Hughes49938e62017-09-16 13:24:41 +0100226 /* skip invalid files */
227 if (!g_str_has_suffix (tmp, ".conf")) {
228 g_debug ("skipping invalid file %s", filename);
229 continue;
230 }
231
Richard Hughescda1cdf2017-06-16 21:49:35 +0100232 /* load from keyfile */
Richard Hughes49938e62017-09-16 13:24:41 +0100233 g_debug ("loading config from %s", filename);
Richard Hughes4c369702017-06-16 15:31:38 +0100234 if (!fwupd_remote_load_from_filename (remote, filename,
Richard Hughes49938e62017-09-16 13:24:41 +0100235 NULL, error)) {
236 g_prefix_error (error, "failed to load %s: ", filename);
Richard Hughes4c369702017-06-16 15:31:38 +0100237 return FALSE;
Richard Hughes49938e62017-09-16 13:24:41 +0100238 }
Richard Hughescda1cdf2017-06-16 21:49:35 +0100239
240 /* watch the config file and the XML file itself */
241 if (!fu_config_add_inotify (self, filename, error))
242 return FALSE;
243 if (!fu_config_add_inotify (self, fwupd_remote_get_filename_cache (remote), error))
244 return FALSE;
245
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100246 /* try to find a custom agreement, falling back to a generic warning */
247 if (fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_DOWNLOAD) {
248 g_autoptr(GString) agreement_markup = NULL;
249 g_autofree gchar *component_id = fu_config_build_remote_component_id (remote);
250 AsApp *app = as_store_get_app_by_id (self->store_remotes, component_id);
251 if (app != NULL) {
252 agreement_markup = fu_config_get_remote_agreement_for_app (remote, app, error);
253 } else {
254 agreement_markup = fu_config_get_remote_agreement_default (remote, error);
255 }
256 if (agreement_markup == NULL)
257 return FALSE;
258
259 /* replace any dynamic values from os-release */
Richard Hughesf674bc92018-05-30 10:32:21 +0100260 tmp = g_hash_table_lookup (self->os_release, "NAME");
261 if (tmp == NULL)
262 tmp = "this distribution";
263 as_utils_string_replace (agreement_markup, "$OS_RELEASE:NAME$", tmp);
264 tmp = g_hash_table_lookup (self->os_release, "BUG_REPORT_URL");
265 if (tmp == NULL)
266 tmp = "https://github.com/hughsie/fwupd/issues";
267 as_utils_string_replace (agreement_markup, "$OS_RELEASE:BUG_REPORT_URL$", tmp);
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100268 fwupd_remote_set_agreement (remote, agreement_markup->str);
269 }
270
Richard Hughescda1cdf2017-06-16 21:49:35 +0100271 /* set mtime */
Richard Hughesfeb80272017-06-16 20:24:24 +0100272 fwupd_remote_set_mtime (remote, fu_config_get_remote_mtime (self, remote));
Richard Hughes4c369702017-06-16 15:31:38 +0100273 g_ptr_array_add (self->remotes, g_steal_pointer (&remote));
Richard Hughes4c369702017-06-16 15:31:38 +0100274 }
275 return TRUE;
276}
277
278static gint
279fu_config_remote_sort_cb (gconstpointer a, gconstpointer b)
280{
281 FwupdRemote *remote_a = *((FwupdRemote **) a);
282 FwupdRemote *remote_b = *((FwupdRemote **) b);
283
284 /* use priority first */
285 if (fwupd_remote_get_priority (remote_a) < fwupd_remote_get_priority (remote_b))
286 return 1;
287 if (fwupd_remote_get_priority (remote_a) > fwupd_remote_get_priority (remote_b))
288 return -1;
289
290 /* fall back to name */
291 return g_strcmp0 (fwupd_remote_get_id (remote_a),
292 fwupd_remote_get_id (remote_b));
293}
294
295static FwupdRemote *
296fu_config_get_remote_by_id_noref (GPtrArray *remotes, const gchar *remote_id)
297{
298 for (guint i = 0; i < remotes->len; i++) {
299 FwupdRemote *remote = g_ptr_array_index (remotes, i);
300 if (g_strcmp0 (remote_id, fwupd_remote_get_id (remote)) == 0)
301 return remote;
302 }
303 return NULL;
304}
305
306static guint
307fu_config_remotes_depsolve_with_direction (FuConfig *self, gint inc)
308{
309 guint cnt = 0;
310 for (guint i = 0; i < self->remotes->len; i++) {
311 FwupdRemote *remote = g_ptr_array_index (self->remotes, i);
312 gchar **order = inc < 0 ? fwupd_remote_get_order_after (remote) :
313 fwupd_remote_get_order_before (remote);
314 if (order == NULL)
315 continue;
316 for (guint j = 0; order[j] != NULL; j++) {
317 FwupdRemote *remote2;
318 if (g_strcmp0 (order[j], fwupd_remote_get_id (remote)) == 0) {
Richard Hughes3cca1c62017-07-21 13:38:20 +0100319 g_debug ("ignoring self-dep remote %s", order[j]);
Richard Hughes4c369702017-06-16 15:31:38 +0100320 continue;
321 }
322 remote2 = fu_config_get_remote_by_id_noref (self->remotes, order[j]);
323 if (remote2 == NULL) {
Richard Hughes3cca1c62017-07-21 13:38:20 +0100324 g_debug ("ignoring unfound remote %s", order[j]);
Richard Hughes4c369702017-06-16 15:31:38 +0100325 continue;
326 }
327 if (fwupd_remote_get_priority (remote) > fwupd_remote_get_priority (remote2))
328 continue;
329 g_debug ("ordering %s=%s+%i",
330 fwupd_remote_get_id (remote),
331 fwupd_remote_get_id (remote2),
332 inc);
333 fwupd_remote_set_priority (remote, fwupd_remote_get_priority (remote2) + inc);
334
335 /* increment changes counter */
336 cnt++;
337 }
338 }
339 return cnt;
340}
341
342static gboolean
343fu_config_load_remotes (FuConfig *self, GError **error)
344{
345 guint depsolve_check;
346 g_autoptr(GPtrArray) paths = NULL;
347
348 /* get a list of all config paths */
349 paths = fu_config_get_config_paths ();
350 if (paths->len == 0) {
351 g_set_error_literal (error,
352 FWUPD_ERROR,
353 FWUPD_ERROR_NOT_FOUND,
354 "No search paths found");
355 return FALSE;
356 }
357
358 /* look for all remotes */
359 for (guint i = 0; i < paths->len; i++) {
360 const gchar *path = g_ptr_array_index (paths, i);
361 g_debug ("using config path of %s", path);
362 if (!fu_config_add_remotes_for_path (self, path, error))
363 return FALSE;
364 }
365
366 /* depsolve */
367 for (depsolve_check = 0; depsolve_check < 100; depsolve_check++) {
368 guint cnt = 0;
369 cnt += fu_config_remotes_depsolve_with_direction (self, 1);
370 cnt += fu_config_remotes_depsolve_with_direction (self, -1);
371 if (cnt == 0)
372 break;
373 }
374 if (depsolve_check == 100) {
375 g_set_error_literal (error,
376 FWUPD_ERROR,
377 FWUPD_ERROR_INTERNAL,
378 "Cannot depsolve remotes ordering");
379 return FALSE;
380 }
381
382 /* order these by priority, then name */
383 g_ptr_array_sort (self->remotes, fu_config_remote_sort_cb);
384
385 /* success */
386 return TRUE;
387}
388
Mario Limonciellod82e3b52018-05-22 10:18:27 -0500389static gboolean
390fu_config_load_from_file (FuConfig *self, const gchar *config_file,
391 GError **error)
Richard Hughes980ef142017-06-16 12:45:27 +0100392{
Richard Hughes4c369702017-06-16 15:31:38 +0100393 GFileMonitor *monitor;
Richard Hughes321f77a2018-02-14 10:25:53 +0000394 guint64 archive_size_max;
Richard Hughes980ef142017-06-16 12:45:27 +0100395 g_auto(GStrv) devices = NULL;
396 g_auto(GStrv) plugins = NULL;
Richard Hughes4c369702017-06-16 15:31:38 +0100397 g_autoptr(GFile) file = NULL;
Richard Hughes980ef142017-06-16 12:45:27 +0100398
Richard Hughes4c369702017-06-16 15:31:38 +0100399 /* ensure empty in case we're called from a monitor change */
400 g_ptr_array_set_size (self->blacklist_devices, 0);
401 g_ptr_array_set_size (self->blacklist_plugins, 0);
402 g_ptr_array_set_size (self->monitors, 0);
403 g_ptr_array_set_size (self->remotes, 0);
404
Richard Hughes980ef142017-06-16 12:45:27 +0100405 g_debug ("loading config values from %s", config_file);
406 if (!g_key_file_load_from_file (self->keyfile, config_file,
407 G_KEY_FILE_NONE, error))
408 return FALSE;
409
Richard Hughes4c369702017-06-16 15:31:38 +0100410 /* set up a notify watch */
411 file = g_file_new_for_path (config_file);
412 monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, error);
413 if (monitor == NULL)
414 return FALSE;
415 g_signal_connect (monitor, "changed",
416 G_CALLBACK (fu_config_monitor_changed_cb), self);
417 g_ptr_array_add (self->monitors, monitor);
418
Richard Hughes980ef142017-06-16 12:45:27 +0100419 /* get blacklisted devices */
420 devices = g_key_file_get_string_list (self->keyfile,
421 "fwupd",
422 "BlacklistDevices",
423 NULL, /* length */
424 NULL);
425 if (devices != NULL) {
426 for (guint i = 0; devices[i] != NULL; i++) {
427 g_ptr_array_add (self->blacklist_devices,
428 g_strdup (devices[i]));
429 }
430 }
431
432 /* get blacklisted plugins */
433 plugins = g_key_file_get_string_list (self->keyfile,
434 "fwupd",
435 "BlacklistPlugins",
436 NULL, /* length */
437 NULL);
438 if (plugins != NULL) {
439 for (guint i = 0; plugins[i] != NULL; i++) {
440 g_ptr_array_add (self->blacklist_plugins,
441 g_strdup (plugins[i]));
442 }
443 }
444
Richard Hughesc7bbbc22018-01-02 22:22:25 +0000445 /* get maximum archive size, defaulting to something sane */
Richard Hughes321f77a2018-02-14 10:25:53 +0000446 archive_size_max = g_key_file_get_uint64 (self->keyfile,
447 "fwupd",
448 "ArchiveSizeMax",
449 NULL);
450 if (archive_size_max > 0)
451 self->archive_size_max = archive_size_max *= 0x100000;
Mario Limonciellod82e3b52018-05-22 10:18:27 -0500452 return TRUE;
453}
454
455gboolean
456fu_config_load (FuConfig *self, GError **error)
457{
Richard Hughes4be17d12018-05-30 20:36:29 +0100458 g_autofree gchar *datadir = NULL;
459 g_autofree gchar *configdir = NULL;
Mario Limonciellod82e3b52018-05-22 10:18:27 -0500460 g_autofree gchar *metainfo_path = NULL;
461 g_autofree gchar *config_file = NULL;
462
463 g_return_val_if_fail (FU_IS_CONFIG (self), FALSE);
464
465 /* load the main daemon config file */
Richard Hughes4be17d12018-05-30 20:36:29 +0100466 configdir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG);
467 config_file = g_build_filename (configdir, "daemon.conf", NULL);
Mario Limonciellod82e3b52018-05-22 10:18:27 -0500468 if (g_file_test (config_file, G_FILE_TEST_EXISTS)) {
469 if (!fu_config_load_from_file (self, config_file, error))
470 return FALSE;
471 } else {
472 g_warning ("Daemon configuration %s not found", config_file);
473 }
Richard Hughesc7bbbc22018-01-02 22:22:25 +0000474
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100475 /* load AppStream about the remotes */
476 self->os_release = fwupd_get_os_release (error);
477 if (self->os_release == NULL)
478 return FALSE;
479 as_store_add_filter (self->store_remotes, AS_APP_KIND_SOURCE);
Richard Hughes4be17d12018-05-30 20:36:29 +0100480 datadir = fu_common_get_path (FU_PATH_KIND_DATADIR_PKG);
481 metainfo_path = g_build_filename (datadir, "metainfo", NULL);
Richard Hughes9b7ad9a2018-05-15 21:51:30 +0100482 if (g_file_test (metainfo_path, G_FILE_TEST_EXISTS)) {
483 if (!as_store_load_path (self->store_remotes,
484 metainfo_path,
485 NULL, /* cancellable */
486 error))
487 return FALSE;
488 }
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100489
Richard Hughes4c369702017-06-16 15:31:38 +0100490 /* load remotes */
491 if (!fu_config_load_remotes (self, error))
492 return FALSE;
493
494 /* success */
Richard Hughes980ef142017-06-16 12:45:27 +0100495 return TRUE;
496}
497
498GPtrArray *
Richard Hughes4c369702017-06-16 15:31:38 +0100499fu_config_get_remotes (FuConfig *self)
500{
501 g_return_val_if_fail (FU_IS_CONFIG (self), NULL);
502 return self->remotes;
503}
504
Richard Hughes5935ebd2017-06-16 15:40:31 +0100505FwupdRemote *
506fu_config_get_remote_by_id (FuConfig *self, const gchar *remote_id)
507{
508 g_return_val_if_fail (FU_IS_CONFIG (self), NULL);
509 return fu_config_get_remote_by_id_noref (self->remotes, remote_id);
510}
511
Richard Hughes4c369702017-06-16 15:31:38 +0100512GPtrArray *
Richard Hughes980ef142017-06-16 12:45:27 +0100513fu_config_get_blacklist_devices (FuConfig *self)
514{
515 g_return_val_if_fail (FU_IS_CONFIG (self), NULL);
516 return self->blacklist_devices;
517}
518
Richard Hughesc7bbbc22018-01-02 22:22:25 +0000519guint64
520fu_config_get_archive_size_max (FuConfig *self)
521{
522 g_return_val_if_fail (FU_IS_CONFIG (self), 0);
523 return self->archive_size_max;
524}
525
Richard Hughes980ef142017-06-16 12:45:27 +0100526GPtrArray *
527fu_config_get_blacklist_plugins (FuConfig *self)
528{
529 g_return_val_if_fail (FU_IS_CONFIG (self), NULL);
530 return self->blacklist_plugins;
531}
532
Richard Hughes980ef142017-06-16 12:45:27 +0100533static void
534fu_config_class_init (FuConfigClass *klass)
535{
536 GObjectClass *object_class = G_OBJECT_CLASS (klass);
537 object_class->finalize = fu_config_finalize;
538}
539
540static void
541fu_config_init (FuConfig *self)
542{
Richard Hughesc7bbbc22018-01-02 22:22:25 +0000543 self->archive_size_max = 512 * 0x100000;
Richard Hughes980ef142017-06-16 12:45:27 +0100544 self->keyfile = g_key_file_new ();
545 self->blacklist_devices = g_ptr_array_new_with_free_func (g_free);
546 self->blacklist_plugins = g_ptr_array_new_with_free_func (g_free);
Richard Hughes4c369702017-06-16 15:31:38 +0100547 self->remotes = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
548 self->monitors = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100549 self->store_remotes = as_store_new ();
Richard Hughes980ef142017-06-16 12:45:27 +0100550}
551
552static void
553fu_config_finalize (GObject *obj)
554{
555 FuConfig *self = FU_CONFIG (obj);
556
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100557 if (self->os_release != NULL)
558 g_hash_table_unref (self->os_release);
Richard Hughes980ef142017-06-16 12:45:27 +0100559 g_key_file_unref (self->keyfile);
560 g_ptr_array_unref (self->blacklist_devices);
561 g_ptr_array_unref (self->blacklist_plugins);
Richard Hughes4c369702017-06-16 15:31:38 +0100562 g_ptr_array_unref (self->remotes);
563 g_ptr_array_unref (self->monitors);
Richard Hughes1fd3ecf2018-04-16 10:53:46 +0100564 g_object_unref (self->store_remotes);
Richard Hughes980ef142017-06-16 12:45:27 +0100565
566 G_OBJECT_CLASS (fu_config_parent_class)->finalize (obj);
567}
568
569FuConfig *
570fu_config_new (void)
571{
572 FuConfig *self;
573 self = g_object_new (FU_TYPE_CONFIG, NULL);
574 return FU_CONFIG (self);
575}