Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 2 | * Copyright (C) 2017 Richard Hughes <richard@hughsie.com> |
| 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | b08e7bc | 2018-09-11 10:51:13 +0100 | [diff] [blame] | 7 | #define G_LOG_DOMAIN "FuConfig" |
| 8 | |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 9 | #include "config.h" |
| 10 | |
| 11 | #include <glib-object.h> |
| 12 | #include <gio/gio.h> |
| 13 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 14 | #include "fu-common.h" |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 15 | #include "fu-config.h" |
| 16 | |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 17 | enum { |
| 18 | SIGNAL_CHANGED, |
| 19 | SIGNAL_LAST |
| 20 | }; |
| 21 | |
| 22 | static guint signals[SIGNAL_LAST] = { 0 }; |
| 23 | |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 24 | static void fu_config_finalize (GObject *obj); |
| 25 | |
| 26 | struct _FuConfig |
| 27 | { |
| 28 | GObject parent_instance; |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 29 | GFileMonitor *monitor; |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 30 | GPtrArray *disabled_devices; /* (element-type utf-8) */ |
| 31 | GPtrArray *disabled_plugins; /* (element-type utf-8) */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 32 | GPtrArray *approved_firmware; /* (element-type utf-8) */ |
Richard Hughes | 3120683 | 2020-07-27 15:31:11 +0100 | [diff] [blame] | 33 | GPtrArray *blocked_firmware; /* (element-type utf-8) */ |
Richard Hughes | b856f0b | 2021-01-28 10:59:49 +0000 | [diff] [blame] | 34 | GPtrArray *uri_schemes; /* (element-type utf-8) */ |
Richard Hughes | c7bbbc2 | 2018-01-02 22:22:25 +0000 | [diff] [blame] | 35 | guint64 archive_size_max; |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 36 | guint idle_timeout; |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 37 | gchar *config_file; |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 38 | gboolean update_motd; |
Mario Limonciello | 4fa95a7 | 2020-03-28 10:50:57 -0500 | [diff] [blame] | 39 | gboolean enumerate_all_devices; |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | G_DEFINE_TYPE (FuConfig, fu_config, G_TYPE_OBJECT) |
| 43 | |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 44 | static void |
| 45 | fu_config_emit_changed (FuConfig *self) |
| 46 | { |
| 47 | g_debug ("::configuration changed"); |
| 48 | g_signal_emit (self, signals[SIGNAL_CHANGED], 0); |
| 49 | } |
| 50 | |
Richard Hughes | 4c36970 | 2017-06-16 15:31:38 +0100 | [diff] [blame] | 51 | static gboolean |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 52 | fu_config_reload (FuConfig *self, GError **error) |
Richard Hughes | cda1cdf | 2017-06-16 21:49:35 +0100 | [diff] [blame] | 53 | { |
Richard Hughes | 321f77a | 2018-02-14 10:25:53 +0000 | [diff] [blame] | 54 | guint64 archive_size_max; |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 55 | guint idle_timeout; |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 56 | g_auto(GStrv) approved_firmware = NULL; |
Richard Hughes | 3120683 | 2020-07-27 15:31:11 +0100 | [diff] [blame] | 57 | g_auto(GStrv) blocked_firmware = NULL; |
Richard Hughes | b856f0b | 2021-01-28 10:59:49 +0000 | [diff] [blame] | 58 | g_auto(GStrv) uri_schemes = NULL; |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 59 | g_auto(GStrv) devices = NULL; |
| 60 | g_auto(GStrv) plugins = NULL; |
Mario Limonciello | 38027e6 | 2019-04-17 15:16:07 +0100 | [diff] [blame] | 61 | g_autofree gchar *domains = NULL; |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 62 | g_autoptr(GKeyFile) keyfile = g_key_file_new (); |
Mario Limonciello | 3dbb92e | 2020-03-30 12:07:18 -0500 | [diff] [blame] | 63 | g_autoptr(GError) error_update_motd = NULL; |
Mario Limonciello | 4fa95a7 | 2020-03-28 10:50:57 -0500 | [diff] [blame] | 64 | g_autoptr(GError) error_enumerate_all = NULL; |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 65 | |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 66 | g_debug ("loading config values from %s", self->config_file); |
| 67 | if (!g_key_file_load_from_file (keyfile, self->config_file, |
| 68 | G_KEY_FILE_NONE, error)) |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 69 | return FALSE; |
| 70 | |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 71 | /* get disabled devices */ |
| 72 | g_ptr_array_set_size (self->disabled_devices, 0); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 73 | devices = g_key_file_get_string_list (keyfile, |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 74 | "fwupd", |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 75 | "DisabledDevices", |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 76 | NULL, /* length */ |
| 77 | NULL); |
| 78 | if (devices != NULL) { |
| 79 | for (guint i = 0; devices[i] != NULL; i++) { |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 80 | g_ptr_array_add (self->disabled_devices, |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 81 | g_strdup (devices[i])); |
| 82 | } |
| 83 | } |
| 84 | |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 85 | /* get disabled plugins */ |
| 86 | g_ptr_array_set_size (self->disabled_plugins, 0); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 87 | plugins = g_key_file_get_string_list (keyfile, |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 88 | "fwupd", |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 89 | "DisabledPlugins", |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 90 | NULL, /* length */ |
| 91 | NULL); |
| 92 | if (plugins != NULL) { |
| 93 | for (guint i = 0; plugins[i] != NULL; i++) { |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 94 | g_ptr_array_add (self->disabled_plugins, |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 95 | g_strdup (plugins[i])); |
| 96 | } |
| 97 | } |
| 98 | |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 99 | /* get approved firmware */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 100 | g_ptr_array_set_size (self->approved_firmware, 0); |
| 101 | approved_firmware = g_key_file_get_string_list (keyfile, |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 102 | "fwupd", |
| 103 | "ApprovedFirmware", |
| 104 | NULL, /* length */ |
| 105 | NULL); |
| 106 | if (approved_firmware != NULL) { |
| 107 | for (guint i = 0; approved_firmware[i] != NULL; i++) { |
| 108 | g_ptr_array_add (self->approved_firmware, |
| 109 | g_strdup (approved_firmware[i])); |
| 110 | } |
| 111 | } |
| 112 | |
Richard Hughes | 3120683 | 2020-07-27 15:31:11 +0100 | [diff] [blame] | 113 | /* get blocked firmware */ |
| 114 | g_ptr_array_set_size (self->blocked_firmware, 0); |
| 115 | blocked_firmware = g_key_file_get_string_list (keyfile, |
| 116 | "fwupd", |
| 117 | "BlockedFirmware", |
| 118 | NULL, /* length */ |
| 119 | NULL); |
| 120 | if (blocked_firmware != NULL) { |
| 121 | for (guint i = 0; blocked_firmware[i] != NULL; i++) { |
| 122 | g_ptr_array_add (self->blocked_firmware, |
| 123 | g_strdup (blocked_firmware[i])); |
| 124 | } |
| 125 | } |
| 126 | |
Richard Hughes | b856f0b | 2021-01-28 10:59:49 +0000 | [diff] [blame] | 127 | /* get download schemes */ |
| 128 | g_ptr_array_set_size (self->uri_schemes, 0); |
| 129 | uri_schemes = g_key_file_get_string_list (keyfile, |
| 130 | "fwupd", |
| 131 | "UriSchemes", |
| 132 | NULL, /* length */ |
| 133 | NULL); |
| 134 | if (uri_schemes != NULL) { |
| 135 | for (guint i = 0; uri_schemes[i] != NULL; i++) { |
| 136 | g_ptr_array_add (self->uri_schemes, |
| 137 | g_strdup (uri_schemes[i])); |
| 138 | } |
| 139 | } |
| 140 | if (self->uri_schemes->len == 0) { |
| 141 | g_ptr_array_add (self->uri_schemes, g_strdup ("file")); |
| 142 | g_ptr_array_add (self->uri_schemes, g_strdup ("https")); |
| 143 | g_ptr_array_add (self->uri_schemes, g_strdup ("http")); |
| 144 | g_ptr_array_add (self->uri_schemes, g_strdup ("ipfs")); |
| 145 | } |
| 146 | |
Richard Hughes | c7bbbc2 | 2018-01-02 22:22:25 +0000 | [diff] [blame] | 147 | /* get maximum archive size, defaulting to something sane */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 148 | archive_size_max = g_key_file_get_uint64 (keyfile, |
Richard Hughes | 321f77a | 2018-02-14 10:25:53 +0000 | [diff] [blame] | 149 | "fwupd", |
| 150 | "ArchiveSizeMax", |
| 151 | NULL); |
Richard Hughes | 68175e9 | 2021-01-14 09:43:33 +0000 | [diff] [blame] | 152 | if (archive_size_max > 0) { |
Mario Limonciello | 27fd95a | 2020-08-10 10:02:24 -0500 | [diff] [blame] | 153 | self->archive_size_max = archive_size_max * 0x100000; |
Richard Hughes | 68175e9 | 2021-01-14 09:43:33 +0000 | [diff] [blame] | 154 | } else { |
| 155 | guint64 memory_size = fu_common_get_memory_size (); |
| 156 | g_autofree gchar *str = NULL; |
| 157 | if (memory_size > 0) { |
| 158 | self->archive_size_max = MAX (memory_size / 4, G_MAXSIZE); |
| 159 | str = g_format_size (self->archive_size_max); |
| 160 | g_debug ("using autodetected max archive size %s", str); |
| 161 | } else { |
| 162 | self->archive_size_max = 512 * 0x100000; |
| 163 | str = g_format_size (self->archive_size_max); |
| 164 | g_debug ("using fallback max archive size %s", str); |
| 165 | } |
| 166 | } |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 167 | |
| 168 | /* get idle timeout */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 169 | idle_timeout = g_key_file_get_uint64 (keyfile, |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 170 | "fwupd", |
| 171 | "IdleTimeout", |
| 172 | NULL); |
| 173 | if (idle_timeout > 0) |
| 174 | self->idle_timeout = idle_timeout; |
Mario Limonciello | 38027e6 | 2019-04-17 15:16:07 +0100 | [diff] [blame] | 175 | |
| 176 | /* get the domains to run in verbose */ |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 177 | domains = g_key_file_get_string (keyfile, |
Mario Limonciello | 38027e6 | 2019-04-17 15:16:07 +0100 | [diff] [blame] | 178 | "fwupd", |
| 179 | "VerboseDomains", |
| 180 | NULL); |
| 181 | if (domains != NULL && domains[0] != '\0') |
| 182 | g_setenv ("FWUPD_VERBOSE", domains, TRUE); |
| 183 | |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 184 | /* whether to update the motd on changes */ |
| 185 | self->update_motd = g_key_file_get_boolean (keyfile, |
| 186 | "fwupd", |
| 187 | "UpdateMotd", |
Mario Limonciello | 3dbb92e | 2020-03-30 12:07:18 -0500 | [diff] [blame] | 188 | &error_update_motd); |
| 189 | if (!self->update_motd && error_update_motd != NULL) { |
| 190 | g_debug ("failed to read UpdateMotd key: %s", error_update_motd->message); |
| 191 | self->update_motd = TRUE; |
| 192 | } |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 193 | |
Mario Limonciello | 4fa95a7 | 2020-03-28 10:50:57 -0500 | [diff] [blame] | 194 | /* whether to only show supported devices for some plugins */ |
| 195 | self->enumerate_all_devices = g_key_file_get_boolean (keyfile, |
| 196 | "fwupd", |
| 197 | "EnumerateAllDevices", |
| 198 | &error_enumerate_all); |
| 199 | /* if error parsing or missing, we want to default to true */ |
| 200 | if (!self->enumerate_all_devices && error_enumerate_all != NULL) { |
| 201 | g_debug ("failed to read EnumerateAllDevices key: %s", error_enumerate_all->message); |
| 202 | self->enumerate_all_devices = TRUE; |
| 203 | } |
| 204 | |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 205 | return TRUE; |
| 206 | } |
| 207 | |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 208 | static void |
| 209 | fu_config_monitor_changed_cb (GFileMonitor *monitor, |
| 210 | GFile *file, |
| 211 | GFile *other_file, |
| 212 | GFileMonitorEvent event_type, |
| 213 | gpointer user_data) |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 214 | { |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 215 | FuConfig *self = FU_CONFIG (user_data); |
| 216 | g_autoptr(GError) error = NULL; |
| 217 | g_debug ("%s changed, reloading all configs", self->config_file); |
| 218 | if (!fu_config_reload (self, &error)) |
| 219 | g_warning ("failed to rescan daemon config: %s", error->message); |
| 220 | fu_config_emit_changed (self); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 223 | gboolean |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 224 | fu_config_set_key_value (FuConfig *self, const gchar *key, const gchar *value, GError **error) |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 225 | { |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 226 | g_autoptr(GKeyFile) keyfile = g_key_file_new (); |
| 227 | if (!g_key_file_load_from_file (keyfile, self->config_file, |
| 228 | G_KEY_FILE_KEEP_COMMENTS, error)) |
| 229 | return FALSE; |
| 230 | g_key_file_set_string (keyfile, "fwupd", key, value); |
| 231 | if (!g_key_file_save_to_file (keyfile, self->config_file, error)) |
| 232 | return FALSE; |
| 233 | return fu_config_reload (self, error); |
| 234 | } |
| 235 | |
| 236 | gboolean |
| 237 | fu_config_load (FuConfig *self, GError **error) |
| 238 | { |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 239 | g_autofree gchar *configdir = NULL; |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 240 | g_autoptr(GFile) file = NULL; |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 241 | |
| 242 | g_return_val_if_fail (FU_IS_CONFIG (self), FALSE); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 243 | g_return_val_if_fail (self->config_file == NULL, FALSE); |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 244 | |
| 245 | /* load the main daemon config file */ |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 246 | configdir = fu_common_get_path (FU_PATH_KIND_SYSCONFDIR_PKG); |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 247 | self->config_file = g_build_filename (configdir, "daemon.conf", NULL); |
| 248 | if (g_file_test (self->config_file, G_FILE_TEST_EXISTS)) { |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 249 | if (!fu_config_reload (self, error)) |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 250 | return FALSE; |
| 251 | } else { |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 252 | g_warning ("Daemon configuration %s not found", self->config_file); |
Mario Limonciello | d82e3b5 | 2018-05-22 10:18:27 -0500 | [diff] [blame] | 253 | } |
Richard Hughes | c7bbbc2 | 2018-01-02 22:22:25 +0000 | [diff] [blame] | 254 | |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 255 | /* set up a notify watch */ |
| 256 | file = g_file_new_for_path (self->config_file); |
| 257 | self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, error); |
| 258 | if (self->monitor == NULL) |
Richard Hughes | 1fd3ecf | 2018-04-16 10:53:46 +0100 | [diff] [blame] | 259 | return FALSE; |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 260 | g_signal_connect (self->monitor, "changed", |
| 261 | G_CALLBACK (fu_config_monitor_changed_cb), self); |
Richard Hughes | 4c36970 | 2017-06-16 15:31:38 +0100 | [diff] [blame] | 262 | |
| 263 | /* success */ |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 264 | return TRUE; |
| 265 | } |
| 266 | |
Richard Hughes | 75b965d | 2018-11-15 13:51:21 +0000 | [diff] [blame] | 267 | guint |
| 268 | fu_config_get_idle_timeout (FuConfig *self) |
| 269 | { |
| 270 | g_return_val_if_fail (FU_IS_CONFIG (self), 0); |
| 271 | return self->idle_timeout; |
| 272 | } |
| 273 | |
Richard Hughes | 4c36970 | 2017-06-16 15:31:38 +0100 | [diff] [blame] | 274 | GPtrArray * |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 275 | fu_config_get_disabled_devices (FuConfig *self) |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 276 | { |
| 277 | g_return_val_if_fail (FU_IS_CONFIG (self), NULL); |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 278 | return self->disabled_devices; |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Richard Hughes | 3120683 | 2020-07-27 15:31:11 +0100 | [diff] [blame] | 281 | GPtrArray * |
| 282 | fu_config_get_blocked_firmware (FuConfig *self) |
| 283 | { |
| 284 | g_return_val_if_fail (FU_IS_CONFIG (self), NULL); |
| 285 | return self->blocked_firmware; |
| 286 | } |
| 287 | |
Richard Hughes | b856f0b | 2021-01-28 10:59:49 +0000 | [diff] [blame] | 288 | guint |
| 289 | fu_config_get_uri_scheme_prio (FuConfig *self, const gchar *scheme) |
| 290 | { |
| 291 | #if GLIB_CHECK_VERSION(2,54,0) |
| 292 | guint idx = G_MAXUINT; |
| 293 | g_ptr_array_find_with_equal_func (self->uri_schemes, |
| 294 | scheme, g_str_equal, &idx); |
| 295 | return idx; |
| 296 | #else |
| 297 | for (guint i = 0; i < self->uri_schemes->len; i++) |
| 298 | const gchar *scheme_tmp = g_ptr_array_index (self->uri_schemes, i); |
| 299 | if (g_str_equal (scheme_tmp, scheme)) |
| 300 | return i; |
| 301 | } |
| 302 | return G_MAXUINT; |
| 303 | #endif |
| 304 | } |
| 305 | |
Richard Hughes | c7bbbc2 | 2018-01-02 22:22:25 +0000 | [diff] [blame] | 306 | guint64 |
| 307 | fu_config_get_archive_size_max (FuConfig *self) |
| 308 | { |
| 309 | g_return_val_if_fail (FU_IS_CONFIG (self), 0); |
| 310 | return self->archive_size_max; |
| 311 | } |
| 312 | |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 313 | GPtrArray * |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 314 | fu_config_get_disabled_plugins (FuConfig *self) |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 315 | { |
| 316 | g_return_val_if_fail (FU_IS_CONFIG (self), NULL); |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 317 | return self->disabled_plugins; |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 320 | GPtrArray * |
| 321 | fu_config_get_approved_firmware (FuConfig *self) |
| 322 | { |
| 323 | g_return_val_if_fail (FU_IS_CONFIG (self), NULL); |
| 324 | return self->approved_firmware; |
| 325 | } |
| 326 | |
Mario Limonciello | d81ea2e | 2020-01-13 14:11:43 -0600 | [diff] [blame] | 327 | gboolean |
| 328 | fu_config_get_update_motd (FuConfig *self) |
| 329 | { |
| 330 | g_return_val_if_fail (FU_IS_CONFIG (self), FALSE); |
| 331 | return self->update_motd; |
| 332 | } |
| 333 | |
Mario Limonciello | 4fa95a7 | 2020-03-28 10:50:57 -0500 | [diff] [blame] | 334 | gboolean |
| 335 | fu_config_get_enumerate_all_devices (FuConfig *self) |
| 336 | { |
| 337 | g_return_val_if_fail (FU_IS_CONFIG (self), FALSE); |
| 338 | return self->enumerate_all_devices; |
| 339 | } |
| 340 | |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 341 | static void |
| 342 | fu_config_class_init (FuConfigClass *klass) |
| 343 | { |
| 344 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 345 | object_class->finalize = fu_config_finalize; |
Mario Limonciello | 263cab9 | 2019-08-20 17:16:00 -0500 | [diff] [blame] | 346 | |
| 347 | signals[SIGNAL_CHANGED] = |
| 348 | g_signal_new ("changed", |
| 349 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
| 350 | 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, |
| 351 | G_TYPE_NONE, 0); |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static void |
| 355 | fu_config_init (FuConfig *self) |
| 356 | { |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 357 | self->disabled_devices = g_ptr_array_new_with_free_func (g_free); |
| 358 | self->disabled_plugins = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 359 | self->approved_firmware = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 3120683 | 2020-07-27 15:31:11 +0100 | [diff] [blame] | 360 | self->blocked_firmware = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | b856f0b | 2021-01-28 10:59:49 +0000 | [diff] [blame] | 361 | self->uri_schemes = g_ptr_array_new_with_free_func (g_free); |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static void |
| 365 | fu_config_finalize (GObject *obj) |
| 366 | { |
| 367 | FuConfig *self = FU_CONFIG (obj); |
| 368 | |
Richard Hughes | 0b6f583 | 2020-09-01 20:15:02 +0100 | [diff] [blame] | 369 | if (self->monitor != NULL) { |
| 370 | g_file_monitor_cancel (self->monitor); |
Richard Hughes | d1808aa | 2019-12-10 15:20:30 +0000 | [diff] [blame] | 371 | g_object_unref (self->monitor); |
Richard Hughes | 0b6f583 | 2020-09-01 20:15:02 +0100 | [diff] [blame] | 372 | } |
Richard Hughes | 85226fd | 2020-06-30 14:43:48 +0100 | [diff] [blame] | 373 | g_ptr_array_unref (self->disabled_devices); |
| 374 | g_ptr_array_unref (self->disabled_plugins); |
Richard Hughes | 8dd4c1c | 2019-03-03 18:27:57 +0000 | [diff] [blame] | 375 | g_ptr_array_unref (self->approved_firmware); |
Richard Hughes | 3120683 | 2020-07-27 15:31:11 +0100 | [diff] [blame] | 376 | g_ptr_array_unref (self->blocked_firmware); |
Richard Hughes | b856f0b | 2021-01-28 10:59:49 +0000 | [diff] [blame] | 377 | g_ptr_array_unref (self->uri_schemes); |
Mario Limonciello | bfcf75b | 2019-04-17 15:05:39 +0100 | [diff] [blame] | 378 | g_free (self->config_file); |
Richard Hughes | 980ef14 | 2017-06-16 12:45:27 +0100 | [diff] [blame] | 379 | |
| 380 | G_OBJECT_CLASS (fu_config_parent_class)->finalize (obj); |
| 381 | } |
| 382 | |
| 383 | FuConfig * |
| 384 | fu_config_new (void) |
| 385 | { |
| 386 | FuConfig *self; |
| 387 | self = g_object_new (FU_TYPE_CONFIG, NULL); |
| 388 | return FU_CONFIG (self); |
| 389 | } |