|
|
baf615 |
From 86048b515f2f2edcea0f2aab2abf5e15f7b777d6 Mon Sep 17 00:00:00 2001
|
|
|
baf615 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
baf615 |
Date: Tue, 3 Oct 2017 09:58:42 -0400
|
|
|
baf615 |
Subject: [PATCH 08/13] lib: factor user loading functions into helpers
|
|
|
baf615 |
|
|
|
baf615 |
Right now, we process ListCachedUser results open coded.
|
|
|
baf615 |
|
|
|
baf615 |
This commit moves the processing to helper functions.
|
|
|
baf615 |
---
|
|
|
baf615 |
src/libaccountsservice/act-user-manager.c | 85 +++++++++++++++++--------------
|
|
|
baf615 |
1 file changed, 48 insertions(+), 37 deletions(-)
|
|
|
baf615 |
|
|
|
baf615 |
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
index 30bbd78..556b070 100644
|
|
|
baf615 |
--- a/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
+++ b/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
@@ -1473,124 +1473,135 @@ find_user_in_accounts_service (ActUserManager *manager,
|
|
|
baf615 |
switch (request->type) {
|
|
|
baf615 |
case ACT_USER_MANAGER_FETCH_USER_FROM_USERNAME_REQUEST:
|
|
|
baf615 |
accounts_accounts_call_find_user_by_name (manager->priv->accounts_proxy,
|
|
|
baf615 |
request->username,
|
|
|
baf615 |
NULL,
|
|
|
baf615 |
on_find_user_by_name_finished,
|
|
|
baf615 |
request);
|
|
|
baf615 |
break;
|
|
|
baf615 |
case ACT_USER_MANAGER_FETCH_USER_FROM_ID_REQUEST:
|
|
|
baf615 |
accounts_accounts_call_find_user_by_id (manager->priv->accounts_proxy,
|
|
|
baf615 |
request->uid,
|
|
|
baf615 |
NULL,
|
|
|
baf615 |
on_find_user_by_id_finished,
|
|
|
baf615 |
request);
|
|
|
baf615 |
break;
|
|
|
baf615 |
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
set_is_loaded (ActUserManager *manager,
|
|
|
baf615 |
gboolean is_loaded)
|
|
|
baf615 |
{
|
|
|
baf615 |
if (manager->priv->is_loaded != is_loaded) {
|
|
|
baf615 |
manager->priv->is_loaded = is_loaded;
|
|
|
baf615 |
g_object_notify (G_OBJECT (manager), "is-loaded");
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
-on_list_cached_users_finished (GObject *object,
|
|
|
baf615 |
- GAsyncResult *result,
|
|
|
baf615 |
- gpointer data)
|
|
|
baf615 |
+load_user_paths (ActUserManager *manager,
|
|
|
baf615 |
+ const char * const * user_paths)
|
|
|
baf615 |
{
|
|
|
baf615 |
- AccountsAccounts *proxy = ACCOUNTS_ACCOUNTS (object);
|
|
|
baf615 |
- ActUserManager *manager = data;
|
|
|
baf615 |
- gchar **user_paths;
|
|
|
baf615 |
- GError *error = NULL;
|
|
|
baf615 |
-
|
|
|
baf615 |
- manager->priv->listing_cached_users = FALSE;
|
|
|
baf615 |
- if (!accounts_accounts_call_list_cached_users_finish (proxy, &user_paths, result, &error)) {
|
|
|
baf615 |
- g_debug ("ActUserManager: ListCachedUsers failed: %s", error->message);
|
|
|
baf615 |
- g_error_free (error);
|
|
|
baf615 |
-
|
|
|
baf615 |
- g_object_unref (manager->priv->accounts_proxy);
|
|
|
baf615 |
- manager->priv->accounts_proxy = NULL;
|
|
|
baf615 |
-
|
|
|
baf615 |
- g_debug ("ActUserManager: unrefing manager owned by failed ListCachedUsers call");
|
|
|
baf615 |
- g_object_unref (manager);
|
|
|
baf615 |
- return;
|
|
|
baf615 |
- }
|
|
|
baf615 |
-
|
|
|
baf615 |
/* We now have a batch of unloaded users that we know about. Once that initial
|
|
|
baf615 |
* batch is loaded up, we can mark the manager as loaded.
|
|
|
baf615 |
*
|
|
|
baf615 |
* (see on_new_user_loaded)
|
|
|
baf615 |
*/
|
|
|
baf615 |
- if (g_strv_length (user_paths) > 0) {
|
|
|
baf615 |
+ if (g_strv_length ((char **) user_paths) > 0) {
|
|
|
baf615 |
int i;
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: ListCachedUsers finished, will set loaded property after list is fully loaded");
|
|
|
baf615 |
for (i = 0; user_paths[i] != NULL; i++) {
|
|
|
baf615 |
ActUser *user;
|
|
|
baf615 |
|
|
|
baf615 |
user = add_new_user_for_object_path (user_paths[i], manager);
|
|
|
baf615 |
if (!manager->priv->is_loaded) {
|
|
|
baf615 |
manager->priv->new_users_inhibiting_load = g_slist_prepend (manager->priv->new_users_inhibiting_load, user);
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_debug ("ActUserManager: ListCachedUsers finished with empty list, maybe setting loaded property now");
|
|
|
baf615 |
maybe_set_is_loaded (manager);
|
|
|
baf615 |
}
|
|
|
baf615 |
+}
|
|
|
baf615 |
|
|
|
baf615 |
- g_strfreev (user_paths);
|
|
|
baf615 |
+static void
|
|
|
baf615 |
+load_included_usernames (ActUserManager *manager)
|
|
|
baf615 |
+{
|
|
|
baf615 |
+ GSList *l;
|
|
|
baf615 |
|
|
|
baf615 |
/* Add users who are specifically included */
|
|
|
baf615 |
- if (manager->priv->include_usernames != NULL) {
|
|
|
baf615 |
- GSList *l;
|
|
|
baf615 |
-
|
|
|
baf615 |
- for (l = manager->priv->include_usernames; l != NULL; l = l->next) {
|
|
|
baf615 |
- ActUser *user;
|
|
|
baf615 |
+ for (l = manager->priv->include_usernames; l != NULL; l = l->next) {
|
|
|
baf615 |
+ ActUser *user;
|
|
|
baf615 |
|
|
|
baf615 |
- g_debug ("ActUserManager: Adding included user %s", (char *)l->data);
|
|
|
baf615 |
- /*
|
|
|
baf615 |
- * The call to act_user_manager_get_user will add the user if it is
|
|
|
baf615 |
- * valid and not already in the hash.
|
|
|
baf615 |
- */
|
|
|
baf615 |
- user = act_user_manager_get_user (manager, l->data);
|
|
|
baf615 |
- if (user == NULL) {
|
|
|
baf615 |
- g_debug ("ActUserManager: unable to lookup user '%s'", (char *)l->data);
|
|
|
baf615 |
- }
|
|
|
baf615 |
+ g_debug ("ActUserManager: Adding included user %s", (char *)l->data);
|
|
|
baf615 |
+ /*
|
|
|
baf615 |
+ * The call to act_user_manager_get_user will add the user if it is
|
|
|
baf615 |
+ * valid and not already in the hash.
|
|
|
baf615 |
+ */
|
|
|
baf615 |
+ user = act_user_manager_get_user (manager, l->data);
|
|
|
baf615 |
+ if (user == NULL) {
|
|
|
baf615 |
+ g_debug ("ActUserManager: unable to lookup user '%s'", (char *)l->data);
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
+}
|
|
|
baf615 |
+
|
|
|
baf615 |
+static void
|
|
|
baf615 |
+on_list_cached_users_finished (GObject *object,
|
|
|
baf615 |
+ GAsyncResult *result,
|
|
|
baf615 |
+ gpointer data)
|
|
|
baf615 |
+{
|
|
|
baf615 |
+ AccountsAccounts *proxy = ACCOUNTS_ACCOUNTS (object);
|
|
|
baf615 |
+ ActUserManager *manager = data;
|
|
|
baf615 |
+ gchar **user_paths;
|
|
|
baf615 |
+ GError *error = NULL;
|
|
|
baf615 |
+
|
|
|
baf615 |
+ manager->priv->listing_cached_users = FALSE;
|
|
|
baf615 |
+
|
|
|
baf615 |
+ if (!accounts_accounts_call_list_cached_users_finish (proxy, &user_paths, result, &error)) {
|
|
|
baf615 |
+ g_debug ("ActUserManager: ListCachedUsers failed: %s", error->message);
|
|
|
baf615 |
+ g_error_free (error);
|
|
|
baf615 |
+
|
|
|
baf615 |
+ g_object_unref (manager->priv->accounts_proxy);
|
|
|
baf615 |
+ manager->priv->accounts_proxy = NULL;
|
|
|
baf615 |
+
|
|
|
baf615 |
+ g_debug ("ActUserManager: unrefing manager owned by failed ListCachedUsers call");
|
|
|
baf615 |
+ g_object_unref (manager);
|
|
|
baf615 |
+ return;
|
|
|
baf615 |
+ }
|
|
|
baf615 |
+
|
|
|
baf615 |
+ load_user_paths (manager, (const char * const *) user_paths);
|
|
|
baf615 |
+ g_strfreev (user_paths);
|
|
|
baf615 |
+
|
|
|
baf615 |
+ load_included_usernames (manager);
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: unrefing manager owned by finished ListCachedUsers call");
|
|
|
baf615 |
g_object_unref (manager);
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
on_get_x11_display_finished (GObject *object,
|
|
|
baf615 |
GAsyncResult *result,
|
|
|
baf615 |
gpointer data)
|
|
|
baf615 |
{
|
|
|
baf615 |
ConsoleKitSession *proxy = CONSOLE_KIT_SESSION (object);
|
|
|
baf615 |
ActUserManagerNewSession *new_session = data;
|
|
|
baf615 |
GError *error = NULL;
|
|
|
baf615 |
char *x11_display;
|
|
|
baf615 |
|
|
|
baf615 |
new_session->pending_calls--;
|
|
|
baf615 |
|
|
|
baf615 |
if (new_session->cancellable == NULL || g_cancellable_is_cancelled (new_session->cancellable)) {
|
|
|
baf615 |
unload_new_session (new_session);
|
|
|
baf615 |
return;
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
if (!console_kit_session_call_get_x11_display_finish (proxy, &x11_display, result, &error)) {
|
|
|
baf615 |
if (error != NULL) {
|
|
|
baf615 |
g_debug ("Failed to get the x11 display of session '%s': %s",
|
|
|
baf615 |
new_session->id, error->message);
|
|
|
baf615 |
g_error_free (error);
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_debug ("Failed to get the x11 display of session '%s'",
|
|
|
baf615 |
new_session->id);
|
|
|
baf615 |
--
|
|
|
baf615 |
2.14.1
|
|
|
baf615 |
|