[gnome-online-accounts/wip/rishi/templates: 3/5] daemon: Reduce one level of indentation
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/wip/rishi/templates: 3/5] daemon: Reduce one level of indentation
- Date: Fri, 26 Aug 2016 14:12:30 +0000 (UTC)
commit 8117634f4d2dd41c7d08f473a92f645a7d92b1fb
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Aug 26 15:34:01 2016 +0200
daemon: Reduce one level of indentation
The function is quite long, and an extra level of indentation makes it
even harder to read.
src/daemon/goadaemon.c | 174 ++++++++++++++++++++++++------------------------
1 files changed, 86 insertions(+), 88 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index cc5cf38..ef81d85 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -455,6 +455,11 @@ add_config_file (GoaDaemon *self,
{
GKeyFile *key_file;
GError *error;
+ gboolean needs_update = FALSE;
+ gchar **groups;
+ const char *guid;
+ gsize num_groups;
+ guint n;
key_file = g_key_file_new ();
@@ -472,113 +477,106 @@ add_config_file (GoaDaemon *self,
}
g_error_free (error);
g_key_file_unref (key_file);
+ return;
}
- else
+
+ guid = g_dbus_connection_get_guid (self->connection);
+ groups = g_key_file_get_groups (key_file, &num_groups);
+ for (n = 0; n < num_groups; n++)
{
- gboolean needs_update = FALSE;
- gchar **groups;
- const char *guid;
- gsize num_groups;
- guint n;
-
- guid = g_dbus_connection_get_guid (self->connection);
- groups = g_key_file_get_groups (key_file, &num_groups);
- for (n = 0; n < num_groups; n++)
+ if (g_str_has_prefix (groups[n], "Account "))
{
- if (g_str_has_prefix (groups[n], "Account "))
- {
- gboolean is_temporary;
- char *session_id;
+ gboolean is_temporary;
+ char *session_id;
- is_temporary = g_key_file_get_boolean (key_file,
- groups[n],
- "IsTemporary",
- NULL);
+ is_temporary = g_key_file_get_boolean (key_file,
+ groups[n],
+ "IsTemporary",
+ NULL);
- if (is_temporary)
+ if (is_temporary)
+ {
+ session_id = g_key_file_get_string (key_file,
+ groups[n],
+ "SessionId",
+ NULL);
+
+ /* discard temporary accounts from older sessions */
+ if (session_id != NULL &&
+ g_strcmp0 (session_id, guid) != 0)
{
- session_id = g_key_file_get_string (key_file,
- groups[n],
- "SessionId",
- NULL);
-
- /* discard temporary accounts from older sessions */
- if (session_id != NULL &&
- g_strcmp0 (session_id, guid) != 0)
+ GoaProvider *provider = NULL;
+ const gchar *id;
+ gchar *provider_type = NULL;
+
+ g_debug ("ignoring account \"%s\" in file %s because it's stale",
+ groups[n], path);
+
+ id = group_to_id (groups[n]);
+ if (id == NULL)
+ {
+ g_warning ("Unable to get account ID from group: %s", groups[n]);
+ goto cleanup_and_continue;
+ }
+
+ provider_type = g_key_file_get_string (key_file, groups[n], "Provider", NULL);
+ if (provider_type != NULL)
+ provider = goa_provider_get_for_provider_type (provider_type);
+
+ if (provider == NULL)
+ {
+ g_warning ("Unsupported account type %s for ID %s (no provider)", provider_type, id);
+ goto cleanup_and_continue;
+ }
+
+ needs_update = g_key_file_remove_group (key_file, groups[n], NULL);
+
+ error = NULL;
+ if (!goa_utils_delete_credentials_for_id_sync (provider, id, NULL, &error))
{
- GoaProvider *provider = NULL;
- const gchar *id;
- gchar *provider_type = NULL;
-
- g_debug ("ignoring account \"%s\" in file %s because it's stale",
- groups[n], path);
-
- id = group_to_id (groups[n]);
- if (id == NULL)
- {
- g_warning ("Unable to get account ID from group: %s", groups[n]);
- goto cleanup_and_continue;
- }
-
- provider_type = g_key_file_get_string (key_file, groups[n], "Provider", NULL);
- if (provider_type != NULL)
- provider = goa_provider_get_for_provider_type (provider_type);
-
- if (provider == NULL)
- {
- g_warning ("Unsupported account type %s for ID %s (no provider)", provider_type,
id);
- goto cleanup_and_continue;
- }
-
- needs_update = g_key_file_remove_group (key_file, groups[n], NULL);
-
- error = NULL;
- if (!goa_utils_delete_credentials_for_id_sync (provider, id, NULL, &error))
- {
- g_warning ("Unable to clean-up stale keyring entries: %s", error->message);
- g_error_free (error);
- goto cleanup_and_continue;
- }
-
- cleanup_and_continue:
- g_clear_object (&provider);
- g_free (groups[n]);
- g_free (provider_type);
- g_free (session_id);
- continue;
+ g_warning ("Unable to clean-up stale keyring entries: %s", error->message);
+ g_error_free (error);
+ goto cleanup_and_continue;
}
+
+ cleanup_and_continue:
+ g_clear_object (&provider);
+ g_free (groups[n]);
+ g_free (provider_type);
g_free (session_id);
+ continue;
}
- else
- {
- needs_update = g_key_file_remove_key (key_file, groups[n], "SessionId", NULL);
- }
-
- g_hash_table_insert (group_name_to_key_file_data,
- groups[n], /* steals string */
- key_file_data_new (key_file, path));
+ g_free (session_id);
}
else
{
- g_warning ("Unexpected group \"%s\" in file %s", groups[n], path);
- g_free (groups[n]);
+ needs_update = g_key_file_remove_key (key_file, groups[n], "SessionId", NULL);
}
- }
- g_free (groups);
- if (needs_update)
+ g_hash_table_insert (group_name_to_key_file_data,
+ groups[n], /* steals string */
+ key_file_data_new (key_file, path));
+ }
+ else
{
- error = NULL;
- if (!g_key_file_save_to_file (key_file, path, &error))
- {
- g_prefix_error (&error, "Error writing key-value-file %s: ", path);
- g_warning ("%s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
- g_error_free (error);
- }
+ g_warning ("Unexpected group \"%s\" in file %s", groups[n], path);
+ g_free (groups[n]);
}
+ }
+ g_free (groups);
- *key_files_to_free = g_list_prepend (*key_files_to_free, key_file);
+ if (needs_update)
+ {
+ error = NULL;
+ if (!g_key_file_save_to_file (key_file, path, &error))
+ {
+ g_prefix_error (&error, "Error writing key-value-file %s: ", path);
+ g_warning ("%s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ }
}
+
+ *key_files_to_free = g_list_prepend (*key_files_to_free, key_file);
}
/* ---------------------------------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]