Blame plugins/subman/gsd-subscription-manager.c

rpm-build e31b4e
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
rpm-build e31b4e
 *
rpm-build e31b4e
 * Copyright (C) 2019 Richard Hughes <richard@hughsie.com>
rpm-build 606484
 * Copyright (C) 2019 Kalev Lember <klember@redhat.com>
rpm-build e31b4e
 *
rpm-build e31b4e
 * This program is free software; you can redistribute it and/or modify
rpm-build e31b4e
 * it under the terms of the GNU General Public License as published by
rpm-build e31b4e
 * the Free Software Foundation; either version 2 of the License, or
rpm-build e31b4e
 * (at your option) any later version.
rpm-build e31b4e
 *
rpm-build e31b4e
 * This program is distributed in the hope that it will be useful,
rpm-build e31b4e
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build e31b4e
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rpm-build e31b4e
 * GNU General Public License for more details.
rpm-build e31b4e
 *
rpm-build e31b4e
 * You should have received a copy of the GNU General Public License
rpm-build e31b4e
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
rpm-build e31b4e
 *
rpm-build e31b4e
 */
rpm-build e31b4e
rpm-build e31b4e
#include "config.h"
rpm-build e31b4e
rpm-build e31b4e
#include <glib/gi18n.h>
rpm-build 01baf5
#include <gio/gunixinputstream.h>
rpm-build e31b4e
#include <gdk/gdk.h>
rpm-build e31b4e
#include <gtk/gtk.h>
rpm-build e31b4e
#include <json-glib/json-glib.h>
rpm-build e31b4e
#include <libnotify/notify.h>
rpm-build e31b4e
rpm-build e31b4e
#include "gnome-settings-profile.h"
rpm-build e31b4e
#include "gsd-subman-common.h"
rpm-build e31b4e
#include "gsd-subscription-manager.h"
rpm-build e31b4e
rpm-build e31b4e
#define GSD_DBUS_NAME "org.gnome.SettingsDaemon"
rpm-build e31b4e
#define GSD_DBUS_PATH "/org/gnome/SettingsDaemon"
rpm-build e31b4e
#define GSD_DBUS_BASE_INTERFACE "org.gnome.SettingsDaemon"
rpm-build e31b4e
rpm-build e31b4e
#define GSD_SUBSCRIPTION_DBUS_NAME		GSD_DBUS_NAME ".Subscription"
rpm-build e31b4e
#define GSD_SUBSCRIPTION_DBUS_PATH		GSD_DBUS_PATH "/Subscription"
rpm-build e31b4e
#define GSD_SUBSCRIPTION_DBUS_INTERFACE		GSD_DBUS_BASE_INTERFACE ".Subscription"
rpm-build e31b4e
rpm-build e31b4e
static const gchar introspection_xml[] =
rpm-build e31b4e
"<node>"
rpm-build e31b4e
"  <interface name='org.gnome.SettingsDaemon.Subscription'>"
rpm-build e31b4e
"    <method name='Register'>"
rpm-build e31b4e
"      <arg type='a{sv}' name='options' direction='in'/>"
rpm-build e31b4e
"    </method>"
rpm-build e31b4e
"    <method name='Unregister'/>"
rpm-build e57d63
"    <method name='Attach'/>"
rpm-build 606484
"    <property name='InstalledProducts' type='aa{sv}' access='read'/>"
rpm-build e31b4e
"    <property name='SubscriptionStatus' type='u' access='read'/>"
rpm-build e31b4e
"  </interface>"
rpm-build e31b4e
"</node>";
rpm-build e31b4e
rpm-build e31b4e
#define GSD_SUBSCRIPTION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SUBSCRIPTION_MANAGER, GsdSubscriptionManagerPrivate))
rpm-build e31b4e
rpm-build e31b4e
typedef enum {
rpm-build e31b4e
	_RHSM_INTERFACE_CONFIG,
rpm-build e31b4e
	_RHSM_INTERFACE_REGISTER_SERVER,
rpm-build e31b4e
	_RHSM_INTERFACE_ATTACH,
rpm-build e31b4e
	_RHSM_INTERFACE_ENTITLEMENT,
rpm-build e31b4e
	_RHSM_INTERFACE_PRODUCTS,
rpm-build e31b4e
	_RHSM_INTERFACE_CONSUMER,
rpm-build e31b4e
	_RHSM_INTERFACE_SYSPURPOSE,
rpm-build e31b4e
	_RHSM_INTERFACE_LAST
rpm-build e31b4e
} _RhsmInterface;
rpm-build e31b4e
rpm-build e31b4e
struct GsdSubscriptionManagerPrivate
rpm-build e31b4e
{
rpm-build e31b4e
	/* D-Bus */
rpm-build e31b4e
	guint		 name_id;
rpm-build e31b4e
	GDBusNodeInfo	*introspection_data;
rpm-build e31b4e
	GDBusConnection	*connection;
rpm-build e31b4e
	GCancellable	*bus_cancellable;
rpm-build e31b4e
rpm-build e31b4e
	GDBusProxy	*proxies[_RHSM_INTERFACE_LAST];
rpm-build e31b4e
	GHashTable	*config; 	/* str:str */
rpm-build 606484
	GPtrArray	*installed_products;
rpm-build e31b4e
	gchar		*address;
rpm-build e31b4e
rpm-build e31b4e
	GTimer		*timer_last_notified;
rpm-build e31b4e
	NotifyNotification	*notification_expired;
rpm-build e31b4e
	NotifyNotification	*notification_registered;
rpm-build e31b4e
	NotifyNotification	*notification_registration_required;
rpm-build e31b4e
	GsdSubmanSubscriptionStatus	 subscription_status;
rpm-build e31b4e
	GsdSubmanSubscriptionStatus	 subscription_status_last;
rpm-build e31b4e
};
rpm-build e31b4e
rpm-build e31b4e
enum {
rpm-build e31b4e
	PROP_0,
rpm-build e31b4e
};
rpm-build e31b4e
rpm-build e31b4e
static void     gsd_subscription_manager_class_init  (GsdSubscriptionManagerClass *klass);
rpm-build e31b4e
static void     gsd_subscription_manager_init        (GsdSubscriptionManager      *subscription_manager);
rpm-build e31b4e
static void     gsd_subscription_manager_finalize    (GObject             *object);
rpm-build e31b4e
rpm-build e31b4e
G_DEFINE_TYPE (GsdSubscriptionManager, gsd_subscription_manager, G_TYPE_OBJECT)
rpm-build e31b4e
rpm-build 606484
typedef struct
rpm-build 606484
{
rpm-build 606484
	gchar *product_name;
rpm-build 606484
	gchar *product_id;
rpm-build 606484
	gchar *version;
rpm-build 606484
	gchar *arch;
rpm-build 606484
	gchar *status;
rpm-build 606484
	gchar *starts;
rpm-build 606484
	gchar *ends;
rpm-build 606484
} ProductData;
rpm-build 606484
rpm-build 606484
static void
rpm-build 606484
product_data_free (ProductData *product)
rpm-build 606484
{
rpm-build 606484
	g_free (product->product_name);
rpm-build 606484
	g_free (product->product_id);
rpm-build 606484
	g_free (product->version);
rpm-build 606484
	g_free (product->arch);
rpm-build 606484
	g_free (product->status);
rpm-build 606484
	g_free (product->starts);
rpm-build 606484
	g_free (product->ends);
rpm-build 606484
	g_free (product);
rpm-build 606484
}
rpm-build 606484
rpm-build 606484
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ProductData, product_data_free);
rpm-build 606484
rpm-build e31b4e
static gpointer manager_object = NULL;
rpm-build e31b4e
rpm-build e31b4e
GQuark
rpm-build e31b4e
gsd_subscription_manager_error_quark (void)
rpm-build e31b4e
{
rpm-build e31b4e
	static GQuark quark = 0;
rpm-build e31b4e
	if (!quark)
rpm-build e31b4e
		quark = g_quark_from_static_string ("gsd_subscription_manager_error");
rpm-build e31b4e
	return quark;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build 606484
static GVariant *
rpm-build 606484
_make_installed_products_variant (GPtrArray *installed_products)
rpm-build 606484
{
rpm-build 606484
	GVariantBuilder builder;
rpm-build 606484
	g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
rpm-build 606484
rpm-build 606484
	for (guint i = 0; i < installed_products->len; i++) {
rpm-build 606484
		ProductData *product = g_ptr_array_index (installed_products, i);
rpm-build 606484
		g_auto(GVariantDict) dict;
rpm-build 606484
rpm-build 606484
		g_variant_dict_init (&dict, NULL);
rpm-build 606484
rpm-build 606484
		g_variant_dict_insert (&dict, "product-name", "s", product->product_name);
rpm-build 606484
		g_variant_dict_insert (&dict, "product-id", "s", product->product_id);
rpm-build 606484
		g_variant_dict_insert (&dict, "version", "s", product->version);
rpm-build 606484
		g_variant_dict_insert (&dict, "arch", "s", product->arch);
rpm-build 606484
		g_variant_dict_insert (&dict, "status", "s", product->status);
rpm-build 606484
		g_variant_dict_insert (&dict, "starts", "s", product->starts);
rpm-build 606484
		g_variant_dict_insert (&dict, "ends", "s", product->ends);
rpm-build 606484
rpm-build 606484
		g_variant_builder_add_value (&builder, g_variant_dict_end (&dict));
rpm-build 606484
	}
rpm-build 606484
rpm-build 606484
	return g_variant_builder_end (&builder);
rpm-build 606484
}
rpm-build 606484
rpm-build e31b4e
static void
rpm-build e31b4e
_emit_property_changed (GsdSubscriptionManager *manager,
rpm-build e31b4e
		        const gchar *property_name,
rpm-build e31b4e
		        GVariant *property_value)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	GVariantBuilder builder;
rpm-build e31b4e
	GVariantBuilder invalidated_builder;
rpm-build e31b4e
rpm-build e31b4e
	/* not yet connected */
rpm-build e31b4e
	if (priv->connection == NULL)
rpm-build e31b4e
		return;
rpm-build e31b4e
rpm-build e31b4e
	/* build the dict */
rpm-build e31b4e
	g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
rpm-build e31b4e
	g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
rpm-build e31b4e
	g_variant_builder_add (&builder,
rpm-build e31b4e
			       "{sv}",
rpm-build e31b4e
			       property_name,
rpm-build e31b4e
			       property_value);
rpm-build e31b4e
	g_dbus_connection_emit_signal (priv->connection,
rpm-build e31b4e
				       NULL,
rpm-build e31b4e
				       GSD_SUBSCRIPTION_DBUS_PATH,
rpm-build e31b4e
				       "org.freedesktop.DBus.Properties",
rpm-build e31b4e
				       "PropertiesChanged",
rpm-build e31b4e
				       g_variant_new ("(sa{sv}as)",
rpm-build e31b4e
				       GSD_SUBSCRIPTION_DBUS_INTERFACE,
rpm-build e31b4e
				       &builder,
rpm-build e31b4e
				       &invalidated_builder),
rpm-build e31b4e
				       NULL);
rpm-build e31b4e
	g_variant_builder_clear (&builder);
rpm-build e31b4e
	g_variant_builder_clear (&invalidated_builder);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build 606484
_client_installed_products_update (GsdSubscriptionManager *manager, GError **error)
rpm-build 606484
{
rpm-build 606484
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build 606484
	JsonNode *json_root;
rpm-build 606484
	JsonArray *json_products_array;
rpm-build 606484
	const gchar *json_txt = NULL;
rpm-build 606484
	g_autoptr(GVariant) val = NULL;
rpm-build 606484
	g_autoptr(JsonParser) json_parser = json_parser_new ();
rpm-build 606484
rpm-build 606484
	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_PRODUCTS],
rpm-build 606484
				      "ListInstalledProducts",
rpm-build 606484
				      g_variant_new ("(sa{sv}s)",
rpm-build 606484
						     ""   /* filter_string */,
rpm-build 606484
						     NULL /* proxy_options */,
rpm-build 0a02b3
						     "C.UTF-8"),
rpm-build 606484
				      G_DBUS_CALL_FLAGS_NONE,
rpm-build 606484
				      -1, NULL, error);
rpm-build 606484
	if (val == NULL)
rpm-build 606484
		return FALSE;
rpm-build 606484
	g_variant_get (val, "(&s)", &json_txt);
rpm-build 606484
	g_debug ("Products.ListInstalledProducts JSON: %s", json_txt);
rpm-build 606484
	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
rpm-build 606484
		return FALSE;
rpm-build 606484
	json_root = json_parser_get_root (json_parser);
rpm-build 606484
	json_products_array = json_node_get_array (json_root);
rpm-build 606484
	if (json_products_array == NULL) {
rpm-build 606484
		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
rpm-build 606484
			     "no InstalledProducts array in %s", json_txt);
rpm-build 606484
		return FALSE;
rpm-build 606484
	}
rpm-build 606484
rpm-build 606484
	g_ptr_array_set_size (priv->installed_products, 0);
rpm-build 606484
rpm-build 606484
	for (guint i = 0; i < json_array_get_length (json_products_array); i++) {
rpm-build 606484
		JsonArray *json_product = json_array_get_array_element (json_products_array, i);
rpm-build 606484
		g_autoptr(ProductData) product = g_new0 (ProductData, 1);
rpm-build 606484
rpm-build 606484
		if (json_product == NULL)
rpm-build 606484
			continue;
rpm-build 606484
		if (json_array_get_length (json_product) < 8) {
rpm-build 606484
			g_debug ("Unexpected number of array elements in InstalledProducts JSON");
rpm-build 606484
			continue;
rpm-build 606484
		}
rpm-build 606484
rpm-build 606484
		product->product_name = g_strdup (json_array_get_string_element (json_product, 0));
rpm-build 606484
		product->product_id = g_strdup (json_array_get_string_element (json_product, 1));
rpm-build 606484
		product->version = g_strdup (json_array_get_string_element (json_product, 2));
rpm-build 606484
		product->arch = g_strdup (json_array_get_string_element (json_product, 3));
rpm-build 606484
		product->status = g_strdup (json_array_get_string_element (json_product, 4));
rpm-build 606484
		product->starts = g_strdup (json_array_get_string_element (json_product, 6));
rpm-build 606484
		product->ends = g_strdup (json_array_get_string_element (json_product, 7));
rpm-build 606484
rpm-build 606484
		g_ptr_array_add (priv->installed_products, g_steal_pointer (&product));
rpm-build 606484
	}
rpm-build 606484
rpm-build 606484
	/* emit notification for g-c-c */
rpm-build 606484
	_emit_property_changed (manager, "InstalledProducts",
rpm-build 606484
			       _make_installed_products_variant (priv->installed_products));
rpm-build 606484
rpm-build 606484
	return TRUE;
rpm-build 606484
}
rpm-build 606484
rpm-build 606484
static gboolean
rpm-build e31b4e
_client_subscription_status_update (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build 0b84cd
	g_autoptr(GVariant) uuid = NULL;
rpm-build 0b84cd
	const gchar *uuid_txt = NULL;
rpm-build e31b4e
	JsonNode *json_root;
rpm-build e31b4e
	JsonObject *json_obj;
rpm-build e31b4e
	const gchar *json_txt = NULL;
rpm-build 0b84cd
	g_autoptr(GVariant) status = NULL;
rpm-build e31b4e
	g_autoptr(JsonParser) json_parser = json_parser_new ();
rpm-build e31b4e
rpm-build e31b4e
	/* save old value */
rpm-build e31b4e
	priv->subscription_status_last = priv->subscription_status;
rpm-build cf1ba9
	if (!_client_installed_products_update (manager, error))
rpm-build cf1ba9
		goto out;
rpm-build cf1ba9
rpm-build cf1ba9
	if (priv->installed_products->len == 0) {
rpm-build cf1ba9
		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS;
rpm-build cf1ba9
		goto out;
rpm-build cf1ba9
	}
rpm-build e31b4e
rpm-build 0b84cd
	uuid = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONSUMER],
rpm-build 0b84cd
				       "GetUuid",
rpm-build 0b84cd
				       g_variant_new ("(s)",
rpm-build 0b84cd
				                      "C.UTF-8"),
rpm-build 0b84cd
				       G_DBUS_CALL_FLAGS_NONE,
rpm-build 0b84cd
				       -1, NULL, error);
rpm-build 0b84cd
	if (uuid == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build 0b84cd
rpm-build 0b84cd
	g_variant_get (uuid, "(&s)", &uuid_txt);
rpm-build 0b84cd
rpm-build ffb7aa
	if (uuid_txt[0] == '\0') {
rpm-build ffb7aa
		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
rpm-build ffb7aa
		goto out;
rpm-build ffb7aa
	}
rpm-build ffb7aa
rpm-build 0b84cd
	status = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
rpm-build 0b84cd
				         "GetStatus",
rpm-build 0b84cd
				         g_variant_new ("(ss)",
rpm-build 0b84cd
						        "", /* assumed as 'now' */
rpm-build 0b84cd
						        "C.UTF-8"),
rpm-build 0b84cd
				         G_DBUS_CALL_FLAGS_NONE,
rpm-build 0b84cd
				         -1, NULL, error);
rpm-build 0b84cd
	if (status == NULL)
rpm-build 0b84cd
		return FALSE;
rpm-build 0b84cd
	g_variant_get (status, "(&s)", &json_txt);
rpm-build e31b4e
	g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
rpm-build e31b4e
	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	json_root = json_parser_get_root (json_parser);
rpm-build e31b4e
	json_obj = json_node_get_object (json_root);
rpm-build ffb7aa
rpm-build ffb7aa
	const gchar *status_id = NULL;
rpm-build ffb7aa
rpm-build ffb7aa
	if (json_object_has_member (json_obj, "status_id")) {
rpm-build ffb7aa
		status_id = json_object_get_string_member (json_obj, "status_id");
rpm-build ffb7aa
	}
rpm-build ffb7aa
rpm-build 0b84cd
	if (!json_object_has_member (json_obj, "valid")) {
rpm-build e31b4e
		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
rpm-build 0b84cd
			     "no Entitlement.GetStatus valid in %s", json_txt);
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build 0b84cd
	gboolean is_valid = json_object_get_boolean_member (json_obj, "valid");
rpm-build 0b84cd
rpm-build ffb7aa
	if (is_valid) {
rpm-build ffb7aa
		if (g_strcmp0 (status_id, "disabled") != 0) {
rpm-build 0b84cd
			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
rpm-build 0b84cd
		} else {
rpm-build ffb7aa
			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED;
rpm-build 0b84cd
		}
rpm-build ffb7aa
		goto out;
rpm-build 0b84cd
	}
rpm-build e31b4e
rpm-build ffb7aa
	for (guint i = 0; i < priv->installed_products->len; i++) {
rpm-build ffb7aa
		ProductData *product = g_ptr_array_index (priv->installed_products, i);
rpm-build ffb7aa
rpm-build ffb7aa
		if (g_strcmp0 (product->status, "subscribed") == 0) {
rpm-build ffb7aa
			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID;
rpm-build ffb7aa
			goto out;
rpm-build ffb7aa
		}
rpm-build ffb7aa
	}
rpm-build ffb7aa
rpm-build ffb7aa
	priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
rpm-build ffb7aa
rpm-build ffb7aa
out:
rpm-build e31b4e
	/* emit notification for g-c-c */
rpm-build e31b4e
	if (priv->subscription_status != priv->subscription_status_last) {
rpm-build e31b4e
		_emit_property_changed (manager, "SubscriptionStatus",
rpm-build e31b4e
				       g_variant_new_uint32 (priv->subscription_status));
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_syspurpose_update (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	JsonNode *json_root;
rpm-build e31b4e
	JsonObject *json_obj;
rpm-build e31b4e
	const gchar *json_txt = NULL;
rpm-build e31b4e
	g_autoptr(GVariant) val = NULL;
rpm-build e31b4e
	g_autoptr(JsonParser) json_parser = json_parser_new ();
rpm-build e31b4e
rpm-build e31b4e
	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_SYSPURPOSE],
rpm-build e31b4e
				      "GetSyspurpose",
rpm-build 0a02b3
				      g_variant_new ("(s)", "C.UTF-8"),
rpm-build e31b4e
				      G_DBUS_CALL_FLAGS_NONE,
rpm-build e31b4e
				      -1, NULL, error);
rpm-build e31b4e
	if (val == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	g_variant_get (val, "(&s)", &json_txt);
rpm-build e31b4e
	g_debug ("Syspurpose.GetSyspurpose JSON: %s", json_txt);
rpm-build e31b4e
	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	json_root = json_parser_get_root (json_parser);
rpm-build e31b4e
	json_obj = json_node_get_object (json_root);
rpm-build e31b4e
	if (!json_object_has_member (json_obj, "status")) {
rpm-build e31b4e
		g_debug ("Syspurpose.GetSyspurpose: Unknown");
rpm-build e31b4e
		return TRUE;
rpm-build e31b4e
	}
rpm-build e31b4e
	g_debug ("Syspurpose.GetSyspurpose: '%s", json_object_get_string_member (json_obj, "status"));
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_register_start (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	const gchar *address = NULL;
rpm-build e31b4e
	g_autoptr(GDBusProxy) proxy = NULL;
rpm-build e31b4e
	g_autoptr(GVariant) val = NULL;
rpm-build e31b4e
rpm-build e31b4e
	/* already started */
rpm-build e31b4e
	if (priv->address != NULL)
rpm-build e31b4e
		return TRUE;
rpm-build e31b4e
rpm-build e31b4e
	/* apparently: "we can't send registration credentials over the regular
rpm-build e31b4e
	 * system or session bus since those aren't really locked down..." */
rpm-build e31b4e
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
rpm-build e31b4e
					       G_DBUS_PROXY_FLAGS_NONE,
rpm-build e31b4e
					       NULL,
rpm-build e31b4e
					       "com.redhat.RHSM1",
rpm-build e31b4e
					       "/com/redhat/RHSM1/RegisterServer",
rpm-build e31b4e
					       "com.redhat.RHSM1.RegisterServer",
rpm-build e31b4e
					       NULL, error);
rpm-build e31b4e
	if (proxy == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	val = g_dbus_proxy_call_sync (proxy, "Start",
rpm-build 0a02b3
				      g_variant_new ("(s)", "C.UTF-8"),
rpm-build e31b4e
				      G_DBUS_CALL_FLAGS_NONE,
rpm-build e31b4e
				      -1, NULL, error);
rpm-build e31b4e
	if (val == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	g_variant_get (val, "(&s)", &address);
rpm-build e31b4e
	g_debug ("RegisterServer.Start: %s", address);
rpm-build e31b4e
	priv->address = g_strdup (address);
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_register_stop (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	g_autoptr(GDBusProxy) proxy = NULL;
rpm-build e31b4e
	g_autoptr(GVariant) val = NULL;
rpm-build e31b4e
rpm-build e31b4e
	/* already started */
rpm-build e31b4e
	if (priv->address == NULL)
rpm-build e31b4e
		return TRUE;
rpm-build e31b4e
rpm-build e31b4e
	/* stop registration server */
rpm-build e31b4e
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
rpm-build e31b4e
					       G_DBUS_PROXY_FLAGS_NONE,
rpm-build e31b4e
					       NULL,
rpm-build e31b4e
					       "com.redhat.RHSM1",
rpm-build e31b4e
					       "/com/redhat/RHSM1/RegisterServer",
rpm-build e31b4e
					       "com.redhat.RHSM1.RegisterServer",
rpm-build e31b4e
					       NULL, error);
rpm-build e31b4e
	if (proxy == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	val = g_dbus_proxy_call_sync (proxy, "Stop",
rpm-build 0a02b3
				      g_variant_new ("(s)", "C.UTF-8"),
rpm-build e31b4e
				      G_DBUS_CALL_FLAGS_NONE,
rpm-build e31b4e
				      -1, NULL, error);
rpm-build e31b4e
	if (val == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	g_clear_pointer (&priv->address, g_free);
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_subprocess_wait_check (GSubprocess *subprocess, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	gint rc;
rpm-build e31b4e
	if (!g_subprocess_wait (subprocess, NULL, error)) {
rpm-build e31b4e
		g_prefix_error (error, "failed to run pkexec: ");
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build e31b4e
	rc = g_subprocess_get_exit_status (subprocess);
rpm-build e31b4e
	if (rc != 0) {
rpm-build e31b4e
		GInputStream *istream = g_subprocess_get_stderr_pipe (subprocess);
rpm-build e31b4e
		gchar buf[1024] = { 0x0 };
rpm-build e31b4e
		gsize sz = 0;
rpm-build e31b4e
		g_input_stream_read_all (istream, buf, sizeof(buf) - 1, &sz, NULL, NULL);
rpm-build e31b4e
		if (sz == 0) {
rpm-build e31b4e
			g_set_error_literal (error, G_IO_ERROR, rc,
rpm-build e31b4e
					     "Failed to run helper without stderr");
rpm-build e31b4e
			return FALSE;
rpm-build e31b4e
		}
rpm-build e31b4e
		g_set_error_literal (error, G_IO_ERROR, rc, buf);
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
typedef enum {
rpm-build e31b4e
	_NOTIFY_EXPIRED,
rpm-build e31b4e
	_NOTIFY_REGISTRATION_REQUIRED,
rpm-build e31b4e
	_NOTIFY_REGISTERED
rpm-build e31b4e
} _NotifyKind;
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_show_notification (GsdSubscriptionManager *manager, _NotifyKind notify_kind)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	switch (notify_kind) {
rpm-build e31b4e
	case _NOTIFY_EXPIRED:
rpm-build e31b4e
		notify_notification_close (priv->notification_registered, NULL);
rpm-build e31b4e
		notify_notification_close (priv->notification_registration_required, NULL);
rpm-build e31b4e
		notify_notification_show (priv->notification_expired, NULL);
rpm-build e31b4e
		break;
rpm-build e31b4e
	case _NOTIFY_REGISTRATION_REQUIRED:
rpm-build e31b4e
		notify_notification_close (priv->notification_registered, NULL);
rpm-build e31b4e
		notify_notification_close (priv->notification_expired, NULL);
rpm-build e31b4e
		notify_notification_show (priv->notification_registration_required, NULL);
rpm-build e31b4e
		break;
rpm-build e31b4e
	case _NOTIFY_REGISTERED:
rpm-build e31b4e
		notify_notification_close (priv->notification_expired, NULL);
rpm-build e31b4e
		notify_notification_close (priv->notification_registration_required, NULL);
rpm-build e31b4e
		notify_notification_show (priv->notification_registered, NULL);
rpm-build e31b4e
		break;
rpm-build e31b4e
	default:
rpm-build e31b4e
		break;
rpm-build e31b4e
	}
rpm-build e31b4e
	g_timer_reset (priv->timer_last_notified);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_client_maybe__show_notification (GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
rpm-build e31b4e
	/* startup */
rpm-build e31b4e
	if (priv->subscription_status_last == GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN &&
rpm-build e31b4e
	    priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN) {
rpm-build e31b4e
		_show_notification (manager, _NOTIFY_REGISTRATION_REQUIRED);
rpm-build e31b4e
		return;
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	/* something changed */
rpm-build e31b4e
	if (priv->subscription_status_last != priv->subscription_status) {
rpm-build e31b4e
		g_debug ("transisition from subscription status '%s' to '%s'",
rpm-build e31b4e
			 gsd_subman_subscription_status_to_string (priv->subscription_status_last),
rpm-build e31b4e
			 gsd_subman_subscription_status_to_string (priv->subscription_status));
rpm-build e31b4e
rpm-build e31b4e
		/* needs registration */
rpm-build e31b4e
		if (priv->subscription_status_last == GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID &&
rpm-build e31b4e
		    priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID) {
rpm-build e31b4e
			_show_notification (manager, _NOTIFY_REGISTRATION_REQUIRED);
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
rpm-build e31b4e
		/* was unregistered */
rpm-build e31b4e
		if (priv->subscription_status_last == GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID &&
rpm-build e31b4e
		    priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN) {
rpm-build e31b4e
			_show_notification (manager, _NOTIFY_REGISTRATION_REQUIRED);
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
rpm-build e31b4e
		/* registered */
rpm-build e31b4e
		if (priv->subscription_status_last == GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN &&
rpm-build e31b4e
		    priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID &&
rpm-build e31b4e
		    g_timer_elapsed (priv->timer_last_notified, NULL) > 60) {
rpm-build e31b4e
			_show_notification (manager, _NOTIFY_REGISTERED);
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	/* nag again */
rpm-build e31b4e
	if (priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN &&
rpm-build e31b4e
	    g_timer_elapsed (priv->timer_last_notified, NULL) > 60 * 60 * 24) {
rpm-build e31b4e
		_show_notification (manager, _NOTIFY_REGISTRATION_REQUIRED);
rpm-build e31b4e
		return;
rpm-build e31b4e
	}
rpm-build e31b4e
	if (priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID &&
rpm-build e31b4e
	    g_timer_elapsed (priv->timer_last_notified, NULL) > 60 * 60 * 24) {
rpm-build e31b4e
		_show_notification (manager, _NOTIFY_EXPIRED);
rpm-build e31b4e
		return;
rpm-build e31b4e
	}
rpm-build e31b4e
	if (priv->subscription_status == GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID &&
rpm-build e31b4e
	    g_timer_elapsed (priv->timer_last_notified, NULL) > 60 * 60 * 24) {
rpm-build e31b4e
		_show_notification (manager, _NOTIFY_EXPIRED);
rpm-build e31b4e
		return;
rpm-build e31b4e
	}
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_register_with_keys (GsdSubscriptionManager *manager,
rpm-build e31b4e
				  const gchar *hostname,
rpm-build e31b4e
				  const gchar *organisation,
rpm-build e31b4e
				  const gchar *activation_key,
rpm-build e31b4e
				  GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	g_autoptr(GSubprocess) subprocess = NULL;
rpm-build 01baf5
	g_autoptr(GBytes) stdin_buf = g_bytes_new (activation_key, strlen (activation_key) + 1);
rpm-build 01baf5
	g_autoptr(GBytes) stderr_buf = NULL;
rpm-build 01baf5
	gint rc;
rpm-build e31b4e
rpm-build e31b4e
	/* apparently: "we can't send registration credentials over the regular
rpm-build e31b4e
	 * system or session bus since those aren't really locked down..." */
rpm-build e31b4e
	if (!_client_register_start (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
rpm-build 01baf5
	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
rpm-build e31b4e
				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
rpm-build e31b4e
				       "--kind", "register-with-key",
rpm-build e31b4e
				       "--address", priv->address,
rpm-build e31b4e
				       "--hostname", hostname,
rpm-build e31b4e
				       "--organisation", organisation,
rpm-build e31b4e
				       NULL);
rpm-build e31b4e
	if (subprocess == NULL) {
rpm-build e31b4e
		g_prefix_error (error, "failed to find pkexec: ");
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build 01baf5
rpm-build 01baf5
	if (!g_subprocess_communicate (subprocess, stdin_buf, NULL, NULL, &stderr_buf, error)) {
rpm-build 01baf5
		g_prefix_error (error, "failed to run pkexec: ");
rpm-build e31b4e
		return FALSE;
rpm-build 01baf5
	}
rpm-build 01baf5
rpm-build 01baf5
	rc = g_subprocess_get_exit_status (subprocess);
rpm-build 01baf5
	if (rc != 0) {
rpm-build 01baf5
		if (g_bytes_get_size (stderr_buf) == 0) {
rpm-build 01baf5
			g_set_error_literal (error, G_IO_ERROR, rc,
rpm-build 01baf5
			                     "Failed to run helper without stderr");
rpm-build 01baf5
			return FALSE;
rpm-build 01baf5
		}
rpm-build 01baf5
rpm-build 01baf5
		g_set_error (error, G_IO_ERROR, rc,
rpm-build 01baf5
			     "%.*s",
rpm-build b28a01
			     (int) g_bytes_get_size (stderr_buf),
rpm-build b28a01
			     (char *) g_bytes_get_data (stderr_buf, NULL));
rpm-build 01baf5
	}
rpm-build e31b4e
rpm-build e31b4e
	/* FIXME: also do on error? */
rpm-build e31b4e
	if (!_client_register_stop (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	if (!_client_subscription_status_update (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	_client_maybe__show_notification (manager);
rpm-build e31b4e
rpm-build e31b4e
	/* success */
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_register (GsdSubscriptionManager *manager,
rpm-build e31b4e
			 const gchar *hostname,
rpm-build e31b4e
			 const gchar *organisation,
rpm-build e31b4e
			 const gchar *username,
rpm-build e31b4e
			 const gchar *password,
rpm-build e31b4e
			 GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	g_autoptr(GSubprocess) subprocess = NULL;
rpm-build 01baf5
	g_autoptr(GBytes) stdin_buf = g_bytes_new (password, strlen (password) + 1);
rpm-build 01baf5
	g_autoptr(GBytes) stderr_buf = NULL;
rpm-build 01baf5
	gint rc;
rpm-build e31b4e
rpm-build e31b4e
	/* fallback */
rpm-build e31b4e
	if (organisation == NULL)
rpm-build e31b4e
		organisation = "";
rpm-build e31b4e
rpm-build e31b4e
	/* apparently: "we can't send registration credentials over the regular
rpm-build e31b4e
	 * system or session bus since those aren't really locked down..." */
rpm-build e31b4e
	if (!_client_register_start (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
rpm-build 01baf5
	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE,
rpm-build 01baf5
				       error,
rpm-build e31b4e
				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
rpm-build e31b4e
				       "--kind", "register-with-username",
rpm-build e31b4e
				       "--address", priv->address,
rpm-build e31b4e
				       "--hostname", hostname,
rpm-build e31b4e
				       "--organisation", organisation,
rpm-build e31b4e
				       "--username", username,
rpm-build e31b4e
				       NULL);
rpm-build e31b4e
	if (subprocess == NULL) {
rpm-build e31b4e
		g_prefix_error (error, "failed to find pkexec: ");
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build 01baf5
rpm-build 01baf5
	if (!g_subprocess_communicate (subprocess, stdin_buf, NULL, NULL, &stderr_buf, error)) {
rpm-build 01baf5
		g_prefix_error (error, "failed to run pkexec: ");
rpm-build e31b4e
		return FALSE;
rpm-build 01baf5
	}
rpm-build 01baf5
rpm-build 01baf5
	rc = g_subprocess_get_exit_status (subprocess);
rpm-build 01baf5
	if (rc != 0) {
rpm-build 01baf5
		if (g_bytes_get_size (stderr_buf) == 0) {
rpm-build 01baf5
			g_set_error_literal (error, G_IO_ERROR, rc,
rpm-build 01baf5
			                     "Failed to run helper without stderr");
rpm-build 01baf5
			return FALSE;
rpm-build 01baf5
		}
rpm-build 01baf5
rpm-build 01baf5
		g_set_error (error, G_IO_ERROR, rc,
rpm-build 01baf5
			     "%.*s",
rpm-build b28a01
			     (int) g_bytes_get_size (stderr_buf),
rpm-build b28a01
			     (char *) g_bytes_get_data (stderr_buf, NULL));
rpm-build 01baf5
	}
rpm-build e31b4e
rpm-build e31b4e
	/* FIXME: also do on error? */
rpm-build e31b4e
	if (!_client_register_stop (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	if (!_client_subscription_status_update (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	_client_maybe__show_notification (manager);
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_unregister (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	g_autoptr(GSubprocess) subprocess = NULL;
rpm-build e31b4e
rpm-build e31b4e
	/* apparently: "we can't send registration credentials over the regular
rpm-build e31b4e
	 * system or session bus since those aren't really locked down..." */
rpm-build e31b4e
	if (!_client_register_start (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
rpm-build e31b4e
	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
rpm-build e31b4e
				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
rpm-build e31b4e
				       "--kind", "unregister",
rpm-build e31b4e
				       NULL);
rpm-build e31b4e
	if (subprocess == NULL) {
rpm-build e31b4e
		g_prefix_error (error, "failed to find pkexec: ");
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build e31b4e
	if (!_client_subprocess_wait_check (subprocess, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	if (!_client_subscription_status_update (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build 606484
	if (!_client_installed_products_update (manager, error))
rpm-build 606484
		return FALSE;
rpm-build e31b4e
	_client_maybe__show_notification (manager);
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e57d63
_client_attach (GsdSubscriptionManager *manager,
rpm-build e57d63
		GError **error)
rpm-build e57d63
{
rpm-build e57d63
	g_autoptr(GSubprocess) subprocess = NULL;
rpm-build e57d63
	g_autoptr(GBytes) stderr_buf = NULL;
rpm-build e57d63
	gint rc;
rpm-build e57d63
rpm-build e57d63
	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
rpm-build e57d63
	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE,
rpm-build e57d63
				       error,
rpm-build e57d63
				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
rpm-build e57d63
				       "--kind", "auto-attach",
rpm-build e57d63
				       NULL);
rpm-build e57d63
	if (subprocess == NULL) {
rpm-build e57d63
		g_prefix_error (error, "failed to find pkexec: ");
rpm-build e57d63
		return FALSE;
rpm-build e57d63
	}
rpm-build e57d63
rpm-build e57d63
	if (!g_subprocess_communicate (subprocess, NULL, NULL, NULL, &stderr_buf, error)) {
rpm-build e57d63
		g_prefix_error (error, "failed to run pkexec: ");
rpm-build e57d63
		return FALSE;
rpm-build e57d63
	}
rpm-build e57d63
rpm-build e57d63
	rc = g_subprocess_get_exit_status (subprocess);
rpm-build e57d63
	if (rc != 0) {
rpm-build e57d63
		if (g_bytes_get_size (stderr_buf) == 0) {
rpm-build e57d63
			g_set_error_literal (error, G_IO_ERROR, rc,
rpm-build e57d63
			                     "Failed to run helper without stderr");
rpm-build e57d63
			return FALSE;
rpm-build e57d63
		}
rpm-build e57d63
rpm-build e57d63
		g_set_error (error, G_IO_ERROR, rc,
rpm-build e57d63
			     "%.*s",
rpm-build e57d63
			     (int) g_bytes_get_size (stderr_buf),
rpm-build e57d63
			     (char *) g_bytes_get_data (stderr_buf, NULL));
rpm-build e57d63
	}
rpm-build e57d63
rpm-build e57d63
	if (!_client_subscription_status_update (manager, error))
rpm-build e57d63
		return FALSE;
rpm-build e57d63
	_client_maybe__show_notification (manager);
rpm-build e57d63
	return TRUE;
rpm-build e57d63
}
rpm-build e57d63
rpm-build e57d63
static gboolean
rpm-build e31b4e
_client_update_config (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	g_autoptr(GVariant) val = NULL;
rpm-build e31b4e
	g_autoptr(GVariant) val_server = NULL;
rpm-build e31b4e
	g_autoptr(GVariantDict) dict = NULL;
rpm-build e31b4e
	GVariantIter iter;
rpm-build e31b4e
	gchar *key;
rpm-build e31b4e
	gchar *value;
rpm-build e31b4e
rpm-build e31b4e
	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONFIG],
rpm-build e31b4e
				      "GetAll",
rpm-build 0a02b3
				      g_variant_new ("(s)", "C.UTF-8"),
rpm-build e31b4e
				      G_DBUS_CALL_FLAGS_NONE,
rpm-build e31b4e
				      -1, NULL, error);
rpm-build e31b4e
	if (val == NULL)
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	dict = g_variant_dict_new (g_variant_get_child_value (val, 0));
rpm-build e31b4e
	val_server = g_variant_dict_lookup_value (dict, "server", G_VARIANT_TYPE("a{ss}"));
rpm-build e31b4e
	if (val_server != NULL) {
rpm-build e31b4e
		g_variant_iter_init (&iter, val_server);
rpm-build e31b4e
		while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
rpm-build e31b4e
			g_debug ("%s=%s", key, value);
rpm-build e31b4e
			g_hash_table_insert (priv->config,
rpm-build e31b4e
					     g_steal_pointer (&key),
rpm-build e31b4e
					     g_steal_pointer (&value));
rpm-build e31b4e
		}
rpm-build e31b4e
	}
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_subman_proxy_signal_cb (GDBusProxy *proxy,
rpm-build e31b4e
			 const gchar *sender_name,
rpm-build e31b4e
			 const gchar *signal_name,
rpm-build e31b4e
			 GVariant *parameters,
rpm-build e31b4e
			 GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	g_autoptr(GError) error = NULL;
rpm-build e31b4e
	if (!_client_syspurpose_update (manager, &error)) {
rpm-build e31b4e
		g_warning ("failed to update syspurpose: %s", error->message);
rpm-build e31b4e
		g_clear_error (&error);
rpm-build e31b4e
	}
rpm-build e31b4e
	if (!_client_subscription_status_update (manager, &error)) {
rpm-build e31b4e
		g_warning ("failed to update subscription status: %s", error->message);
rpm-build e31b4e
		g_clear_error (&error);
rpm-build e31b4e
	}
rpm-build e31b4e
	_client_maybe__show_notification (manager);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_client_unload (GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++)
rpm-build e31b4e
		g_clear_object (&priv->proxies[i]);
rpm-build e31b4e
	g_hash_table_unref (priv->config);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static const gchar *
rpm-build e31b4e
_rhsm_interface_to_string (_RhsmInterface kind)
rpm-build e31b4e
{
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_CONFIG)
rpm-build e31b4e
		return "Config";
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_REGISTER_SERVER)
rpm-build e31b4e
		return "RegisterServer";
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_ATTACH)
rpm-build e31b4e
		return "Attach";
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_ENTITLEMENT)
rpm-build e31b4e
		return "Entitlement";
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_PRODUCTS)
rpm-build e31b4e
		return "Products";
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_CONSUMER)
rpm-build e31b4e
		return "Consumer";
rpm-build e31b4e
	if (kind == _RHSM_INTERFACE_SYSPURPOSE)
rpm-build e31b4e
		return "Syspurpose";
rpm-build e31b4e
	return NULL;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
_client_load (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
rpm-build e31b4e
	priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
rpm-build e31b4e
rpm-build e31b4e
	/* connect to all the interfaces on the *different* objects :| */
rpm-build e31b4e
	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++) {
rpm-build e31b4e
		const gchar *kind = _rhsm_interface_to_string (i);
rpm-build e31b4e
		g_autofree gchar *opath = g_strdup_printf ("/com/redhat/RHSM1/%s", kind);
rpm-build e31b4e
		g_autofree gchar *iface = g_strdup_printf ("com.redhat.RHSM1.%s", kind);
rpm-build e31b4e
		priv->proxies[i] =
rpm-build e31b4e
			g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
rpm-build e31b4e
						       G_DBUS_PROXY_FLAGS_NONE,
rpm-build e31b4e
						       NULL,
rpm-build e31b4e
						       "com.redhat.RHSM1",
rpm-build e31b4e
						       opath, iface,
rpm-build e31b4e
						       NULL,
rpm-build e31b4e
						       error);
rpm-build e31b4e
		if (priv->proxies[i] == NULL)
rpm-build e31b4e
			return FALSE;
rpm-build e31b4e
		/* we want to get notified if the status of the system changes */
rpm-build e31b4e
		g_signal_connect (priv->proxies[i], "g-signal",
rpm-build e31b4e
				  G_CALLBACK (_subman_proxy_signal_cb), manager);
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	/* get initial status */
rpm-build e31b4e
	if (!_client_update_config (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	if (!_client_subscription_status_update (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	if (!_client_syspurpose_update (manager, error))
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
rpm-build e31b4e
	/* success */
rpm-build e31b4e
	return TRUE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
gboolean
rpm-build e31b4e
gsd_subscription_manager_start (GsdSubscriptionManager *manager, GError **error)
rpm-build e31b4e
{
rpm-build e31b4e
	gboolean ret;
rpm-build e31b4e
	g_debug ("Starting subscription manager");
rpm-build e31b4e
	gnome_settings_profile_start (NULL);
rpm-build e31b4e
	ret = _client_load (manager, error);
rpm-build e31b4e
	_client_maybe__show_notification (manager);
rpm-build e31b4e
	gnome_settings_profile_end (NULL);
rpm-build e31b4e
	return ret;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
void
rpm-build e31b4e
gsd_subscription_manager_stop (GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	g_debug ("Stopping subscription manager");
rpm-build e31b4e
	_client_unload (manager);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
gsd_subscription_manager_class_init (GsdSubscriptionManagerClass *klass)
rpm-build e31b4e
{
rpm-build e31b4e
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
rpm-build e31b4e
	object_class->finalize = gsd_subscription_manager_finalize;
rpm-build e31b4e
        notify_init ("gnome-settings-daemon");
rpm-build e31b4e
	g_type_class_add_private (klass, sizeof (GsdSubscriptionManagerPrivate));
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_launch_info_overview (void)
rpm-build e31b4e
{
rpm-build e31b4e
	const gchar *argv[] = { "gnome-control-center", "info-overview", NULL };
rpm-build e31b4e
	g_debug ("Running gnome-control-center info-overview");
rpm-build e31b4e
	g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH,
rpm-build e31b4e
		       NULL, NULL, NULL, NULL);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_notify_closed_cb (NotifyNotification *notification, gpointer user_data)
rpm-build e31b4e
{
rpm-build e31b4e
	/* FIXME: only launch when clicking on the main body, not the window close */
rpm-build e31b4e
	if (notify_notification_get_closed_reason (notification) == 0x400)
rpm-build e31b4e
		_launch_info_overview ();
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
_notify_clicked_cb (NotifyNotification *notification, char *action, gpointer user_data)
rpm-build e31b4e
{
rpm-build e31b4e
	_launch_info_overview ();
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
gsd_subscription_manager_init (GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv = GSD_SUBSCRIPTION_MANAGER_GET_PRIVATE (manager);
rpm-build e31b4e
rpm-build 606484
	priv->installed_products = g_ptr_array_new_with_free_func ((GDestroyNotify) product_data_free);
rpm-build e31b4e
	priv->timer_last_notified = g_timer_new ();
rpm-build e31b4e
rpm-build e31b4e
	/* expired */
rpm-build e31b4e
	priv->notification_expired =
rpm-build e31b4e
		notify_notification_new (_("Subscription Has Expired"),
rpm-build e31b4e
					 _("Add or renew a subscription to continue receiving software updates."),
rpm-build e31b4e
					 NULL);
rpm-build e31b4e
	notify_notification_set_app_name (priv->notification_expired, _("Subscription"));
rpm-build e31b4e
	notify_notification_set_hint_string (priv->notification_expired, "desktop-entry", "subman-panel");
rpm-build e31b4e
	notify_notification_set_hint_string (priv->notification_expired, "x-gnome-privacy-scope", "system");
rpm-build e31b4e
	notify_notification_set_urgency (priv->notification_expired, NOTIFY_URGENCY_CRITICAL);
rpm-build e31b4e
	notify_notification_add_action (priv->notification_expired,
rpm-build e31b4e
					"info-overview", _("Subscribe System…"),
rpm-build e31b4e
					_notify_clicked_cb,
rpm-build e31b4e
					manager, NULL);
rpm-build e31b4e
	g_signal_connect (priv->notification_expired, "closed",
rpm-build e31b4e
			  G_CALLBACK (_notify_closed_cb), manager);
rpm-build e31b4e
rpm-build e31b4e
	/* registered */
rpm-build e31b4e
	priv->notification_registered =
rpm-build e31b4e
		notify_notification_new (_("Registration Successful"),
rpm-build e31b4e
					 _("The system has been registered and software updates have been enabled."),
rpm-build e31b4e
					 NULL);
rpm-build e31b4e
	notify_notification_set_app_name (priv->notification_registered, _("Subscription"));
rpm-build e31b4e
	notify_notification_set_hint_string (priv->notification_registered, "desktop-entry", "subman-panel");
rpm-build e31b4e
	notify_notification_set_hint_string (priv->notification_registered, "x-gnome-privacy-scope", "system");
rpm-build e31b4e
	notify_notification_set_urgency (priv->notification_registered, NOTIFY_URGENCY_CRITICAL);
rpm-build e31b4e
	g_signal_connect (priv->notification_registered, "closed",
rpm-build e31b4e
			  G_CALLBACK (_notify_closed_cb), manager);
rpm-build e31b4e
rpm-build e31b4e
	/* registration required */
rpm-build e31b4e
	priv->notification_registration_required =
rpm-build e31b4e
		notify_notification_new (_("System Not Registered"),
rpm-build e31b4e
					 _("Please register your system to receive software updates."),
rpm-build e31b4e
					 NULL);
rpm-build e31b4e
	notify_notification_set_app_name (priv->notification_registration_required, _("Subscription"));
rpm-build e31b4e
	notify_notification_set_hint_string (priv->notification_registration_required, "desktop-entry", "subman-panel");
rpm-build e31b4e
	notify_notification_set_hint_string (priv->notification_registration_required, "x-gnome-privacy-scope", "system");
rpm-build e31b4e
	notify_notification_set_urgency (priv->notification_registration_required, NOTIFY_URGENCY_CRITICAL);
rpm-build e31b4e
	notify_notification_add_action (priv->notification_registration_required,
rpm-build e31b4e
					"info-overview", _("Register System…"),
rpm-build e31b4e
					_notify_clicked_cb,
rpm-build e31b4e
					manager, NULL);
rpm-build e31b4e
	g_signal_connect (priv->notification_registration_required, "closed",
rpm-build e31b4e
			  G_CALLBACK (_notify_closed_cb), manager);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
gsd_subscription_manager_finalize (GObject *object)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManager *manager;
rpm-build e31b4e
rpm-build e31b4e
	g_return_if_fail (object != NULL);
rpm-build e31b4e
	g_return_if_fail (GSD_IS_SUBSCRIPTION_MANAGER (object));
rpm-build e31b4e
rpm-build e31b4e
	manager = GSD_SUBSCRIPTION_MANAGER (object);
rpm-build e31b4e
rpm-build e31b4e
	gsd_subscription_manager_stop (manager);
rpm-build e31b4e
rpm-build e31b4e
	if (manager->priv->bus_cancellable != NULL) {
rpm-build e31b4e
		g_cancellable_cancel (manager->priv->bus_cancellable);
rpm-build e31b4e
		g_clear_object (&manager->priv->bus_cancellable);
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build 606484
	g_clear_pointer (&manager->priv->installed_products, g_ptr_array_unref);
rpm-build e31b4e
	g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref);
rpm-build e31b4e
	g_clear_object (&manager->priv->connection);
rpm-build e31b4e
	g_clear_object (&manager->priv->notification_expired);
rpm-build e31b4e
	g_clear_object (&manager->priv->notification_registered);
rpm-build e31b4e
	g_timer_destroy (manager->priv->timer_last_notified);
rpm-build e31b4e
rpm-build e31b4e
	if (manager->priv->name_id != 0) {
rpm-build e31b4e
		g_bus_unown_name (manager->priv->name_id);
rpm-build e31b4e
		manager->priv->name_id = 0;
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	G_OBJECT_CLASS (gsd_subscription_manager_parent_class)->finalize (object);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
handle_method_call (GDBusConnection       *connection,
rpm-build e31b4e
		    const gchar           *sender,
rpm-build e31b4e
		    const gchar           *object_path,
rpm-build e31b4e
		    const gchar           *interface_name,
rpm-build e31b4e
		    const gchar           *method_name,
rpm-build e31b4e
		    GVariant              *parameters,
rpm-build e31b4e
		    GDBusMethodInvocation *invocation,
rpm-build e31b4e
		    gpointer               user_data)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManager *manager = GSD_SUBSCRIPTION_MANAGER (user_data);
rpm-build e31b4e
	g_autoptr(GError) error = NULL;
rpm-build e31b4e
rpm-build e31b4e
	if (g_strcmp0 (method_name, "Register") == 0) {
rpm-build e31b4e
		const gchar *organisation = NULL;
rpm-build e31b4e
		const gchar *hostname = NULL;
rpm-build e31b4e
rpm-build e31b4e
		if (FALSE) {
rpm-build e31b4e
			g_dbus_method_invocation_return_error_literal (invocation,
rpm-build e31b4e
								       G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
rpm-build e31b4e
								       "Cannot register at this time");
rpm-build e31b4e
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
rpm-build e31b4e
		g_autoptr(GVariantDict) dict = g_variant_dict_new (g_variant_get_child_value (parameters, 0));
rpm-build e31b4e
rpm-build e31b4e
		const gchar *kind = NULL;
rpm-build e31b4e
		if (!g_variant_dict_lookup (dict, "kind", "&s", &kind)) {
rpm-build e31b4e
			g_dbus_method_invocation_return_error_literal (invocation,
rpm-build e31b4e
								       G_IO_ERROR, G_IO_ERROR_FAILED,
rpm-build e31b4e
								       "No kind specified");
rpm-build e31b4e
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
		if (g_strcmp0 (kind, "username") == 0) {
rpm-build e31b4e
			const gchar *username = NULL;
rpm-build e31b4e
			const gchar *password = NULL;
rpm-build e31b4e
			g_variant_dict_lookup (dict, "hostname", "&s", &hostname);
rpm-build e31b4e
			g_variant_dict_lookup (dict, "organisation", "&s", &organisation);
rpm-build e31b4e
			g_variant_dict_lookup (dict, "username", "&s", &username);
rpm-build e31b4e
			g_variant_dict_lookup (dict, "password", "&s", &password);
rpm-build e31b4e
			if (!_client_register (manager,
rpm-build e31b4e
						     hostname,
rpm-build e31b4e
						     organisation,
rpm-build e31b4e
						     username,
rpm-build e31b4e
						     password,
rpm-build e31b4e
						     &error)) {
rpm-build e31b4e
				g_dbus_method_invocation_return_gerror (invocation, error);
rpm-build e31b4e
				return;
rpm-build e31b4e
			}
rpm-build e31b4e
		} else if (g_strcmp0 (kind, "key") == 0) {
rpm-build e31b4e
			const gchar *activation_key = NULL;
rpm-build e31b4e
			g_variant_dict_lookup (dict, "hostname", "&s", &hostname);
rpm-build e31b4e
			g_variant_dict_lookup (dict, "organisation", "&s", &organisation);
rpm-build e31b4e
			g_variant_dict_lookup (dict, "activation-key", "&s", &activation_key);
rpm-build e31b4e
			if (!_client_register_with_keys (manager,
rpm-build e31b4e
							       hostname,
rpm-build e31b4e
							       organisation,
rpm-build e31b4e
							       activation_key,
rpm-build e31b4e
							       &error)) {
rpm-build e31b4e
				g_dbus_method_invocation_return_gerror (invocation, error);
rpm-build e31b4e
				return;
rpm-build e31b4e
			}
rpm-build e31b4e
		} else {
rpm-build e31b4e
			g_dbus_method_invocation_return_error_literal (invocation,
rpm-build e31b4e
								       G_IO_ERROR, G_IO_ERROR_FAILED,
rpm-build e31b4e
								       "Invalid kind specified");
rpm-build e31b4e
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
		g_dbus_method_invocation_return_value (invocation, NULL);
rpm-build e31b4e
	} else if (g_strcmp0 (method_name, "Unregister") == 0) {
rpm-build e31b4e
		if (!_client_unregister (manager, &error)) {
rpm-build e31b4e
			g_dbus_method_invocation_return_gerror (invocation, error);
rpm-build e31b4e
			return;
rpm-build e31b4e
		}
rpm-build e31b4e
		g_dbus_method_invocation_return_value (invocation, NULL);
rpm-build e57d63
	} else if (g_strcmp0 (method_name, "Attach") == 0) {
rpm-build e57d63
		if (!_client_attach (manager, &error)) {
rpm-build e57d63
			g_dbus_method_invocation_return_gerror (invocation, error);
rpm-build e57d63
			return;
rpm-build e57d63
		}
rpm-build e57d63
		g_dbus_method_invocation_return_value (invocation, NULL);
rpm-build e31b4e
	} else {
rpm-build e31b4e
		g_assert_not_reached ();
rpm-build e31b4e
	}
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static GVariant *
rpm-build e31b4e
handle_get_property (GDBusConnection *connection,
rpm-build e31b4e
		     const gchar *sender,
rpm-build e31b4e
		     const gchar *object_path,
rpm-build e31b4e
		     const gchar *interface_name,
rpm-build e31b4e
		     const gchar *property_name,
rpm-build e31b4e
		     GError **error, gpointer user_data)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManager *manager = GSD_SUBSCRIPTION_MANAGER (user_data);
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
rpm-build e31b4e
	if (g_strcmp0 (interface_name, GSD_SUBSCRIPTION_DBUS_INTERFACE) != 0) {
rpm-build e31b4e
		g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
rpm-build e31b4e
			     "No such interface: %s", interface_name);
rpm-build e31b4e
		return NULL;
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	if (g_strcmp0 (property_name, "SubscriptionStatus") == 0)
rpm-build e31b4e
		return g_variant_new_uint32 (priv->subscription_status);
rpm-build e31b4e
rpm-build 606484
	if (g_strcmp0 (property_name, "InstalledProducts") == 0)
rpm-build 606484
		return _make_installed_products_variant (priv->installed_products);
rpm-build 606484
rpm-build e31b4e
	g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
rpm-build e31b4e
		     "Failed to get property: %s", property_name);
rpm-build e31b4e
	return NULL;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static gboolean
rpm-build e31b4e
handle_set_property (GDBusConnection *connection,
rpm-build e31b4e
		     const gchar *sender,
rpm-build e31b4e
		     const gchar *object_path,
rpm-build e31b4e
		     const gchar *interface_name,
rpm-build e31b4e
		     const gchar *property_name,
rpm-build e31b4e
		     GVariant *value,
rpm-build e31b4e
		     GError **error, gpointer user_data)
rpm-build e31b4e
{
rpm-build e31b4e
	if (g_strcmp0 (interface_name, GSD_SUBSCRIPTION_DBUS_INTERFACE) != 0) {
rpm-build e31b4e
		g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
rpm-build e31b4e
			     "No such interface: %s", interface_name);
rpm-build e31b4e
		return FALSE;
rpm-build e31b4e
	}
rpm-build e31b4e
	g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
rpm-build e31b4e
		     "No such property: %s", property_name);
rpm-build e31b4e
	return FALSE;
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static const GDBusInterfaceVTable interface_vtable =
rpm-build e31b4e
{
rpm-build e31b4e
	handle_method_call,
rpm-build e31b4e
	handle_get_property,
rpm-build e31b4e
	handle_set_property
rpm-build e31b4e
};
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
name_lost_handler_cb (GDBusConnection *connection, const gchar *name, gpointer user_data)
rpm-build e31b4e
{
rpm-build e31b4e
	g_debug ("lost name, so exiting");
rpm-build e31b4e
	gtk_main_quit ();
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
	GDBusConnection *connection;
rpm-build e31b4e
	g_autoptr(GError) error = NULL;
rpm-build e31b4e
rpm-build e31b4e
	connection = g_bus_get_finish (res, &error);
rpm-build e31b4e
	if (connection == NULL) {
rpm-build e31b4e
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
rpm-build e31b4e
			g_warning ("Could not get session bus: %s", error->message);
rpm-build e31b4e
		return;
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	priv->connection = connection;
rpm-build e31b4e
	g_dbus_connection_register_object (connection,
rpm-build e31b4e
					   GSD_SUBSCRIPTION_DBUS_PATH,
rpm-build e31b4e
					   priv->introspection_data->interfaces[0],
rpm-build e31b4e
					   &interface_vtable,
rpm-build e31b4e
					   manager,
rpm-build e31b4e
					   NULL,
rpm-build e31b4e
					   NULL);
rpm-build e31b4e
	priv->name_id = g_bus_own_name_on_connection (connection,
rpm-build e31b4e
						      GSD_SUBSCRIPTION_DBUS_NAME,
rpm-build e31b4e
						      G_BUS_NAME_OWNER_FLAGS_NONE,
rpm-build e31b4e
						      NULL,
rpm-build e31b4e
						      name_lost_handler_cb,
rpm-build e31b4e
						      manager,
rpm-build e31b4e
						      NULL);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
static void
rpm-build e31b4e
register_manager_dbus (GsdSubscriptionManager *manager)
rpm-build e31b4e
{
rpm-build e31b4e
	GsdSubscriptionManagerPrivate *priv = manager->priv;
rpm-build e31b4e
rpm-build e31b4e
	priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
rpm-build e31b4e
	g_assert (priv->introspection_data != NULL);
rpm-build e31b4e
	priv->bus_cancellable = g_cancellable_new ();
rpm-build e31b4e
rpm-build e31b4e
	g_bus_get (G_BUS_TYPE_SESSION, priv->bus_cancellable,
rpm-build e31b4e
		   (GAsyncReadyCallback) on_bus_gotten, manager);
rpm-build e31b4e
}
rpm-build e31b4e
rpm-build e31b4e
GsdSubscriptionManager *
rpm-build e31b4e
gsd_subscription_manager_new (void)
rpm-build e31b4e
{
rpm-build e31b4e
	if (manager_object != NULL) {
rpm-build e31b4e
		g_object_ref (manager_object);
rpm-build e31b4e
	} else {
rpm-build e31b4e
		manager_object = g_object_new (GSD_TYPE_SUBSCRIPTION_MANAGER, NULL);
rpm-build e31b4e
		g_object_add_weak_pointer (manager_object,
rpm-build e31b4e
					   (gpointer *) &manager_object);
rpm-build e31b4e
		register_manager_dbus (manager_object);
rpm-build e31b4e
	}
rpm-build e31b4e
rpm-build e31b4e
	return GSD_SUBSCRIPTION_MANAGER (manager_object);
rpm-build e31b4e
}