コード例 #1
0
static GomDlnaPhotoItem *
photo_item_new (GVariant *var)
{
  GVariant *tmp;
  GomDlnaPhotoItem *photo;
  const gchar *str;

  photo = g_slice_new0 (GomDlnaPhotoItem);

  g_variant_lookup (var, "DisplayName", "&s", &str);
  photo->name = gom_filename_strip_extension (str);

  g_variant_lookup (var, "MIMEType", "&s", &str);
  photo->mimetype = g_strdup (str);

  g_variant_lookup (var, "Path", "&o", &str);
  photo->path = g_strdup (str);

  g_variant_lookup (var, "Type", "s", &str);
  photo->type = g_strdup (str);

  if (g_str_equal (photo->type, "container"))
    {
      photo->url = NULL;
      goto out;
    }

  g_variant_lookup (var, "URLs", "@as", &tmp);
  g_variant_get_child (tmp, 0, "&s", &str);
  photo->url = g_strdup (str);
  g_variant_unref (tmp);

 out:
  return photo;
}
コード例 #2
0
static void
parse_capabilities (NMSupplicantInterface *self, GVariant *capabilities)
{
	NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
	gboolean have_active = FALSE, have_ssid = FALSE;
	gint32 max_scan_ssids = -1;
	const char **array;

	g_return_if_fail (capabilities && g_variant_is_of_type (capabilities, G_VARIANT_TYPE_VARDICT));

	if (g_variant_lookup (capabilities, "Scan", "^a&s", &array)) {
		if (_nm_utils_string_in_list ("active", array))
			have_active = TRUE;
		if (_nm_utils_string_in_list ("ssid", array))
			have_ssid = TRUE;
		g_free (array);
	}

	if (g_variant_lookup (capabilities, "MaxScanSSID", "i", &max_scan_ssids)) {
		/* We need active scan and SSID probe capabilities to care about MaxScanSSIDs */
		if (max_scan_ssids > 0 && have_active && have_ssid) {
			/* wpa_supplicant's WPAS_MAX_SCAN_SSIDS value is 16, but for speed
			 * and to ensure we don't disclose too many SSIDs from the hidden
			 * list, we'll limit to 5.
			 */
			priv->max_scan_ssids = CLAMP (max_scan_ssids, 0, 5);
			nm_log_info (LOGD_SUPPLICANT, "(%s) supports %d scan SSIDs",
				         priv->dev, priv->max_scan_ssids);
		}
	}
}
コード例 #3
0
static void
pkg_diff_variant_print (GVariant *variant)
{
  g_autoptr(GVariant) details = NULL;
  const char *old_name, *old_evr, *old_arch;
  const char *new_name, *new_evr, *new_arch;
  gboolean have_old = FALSE;
  gboolean have_new = FALSE;

  details = g_variant_get_child_value (variant, 2);
  g_return_if_fail (details != NULL);

  have_old = g_variant_lookup (details,
                               "PreviousPackage", "(&s&s&s)",
                               &old_name, &old_evr, &old_arch);

  have_new = g_variant_lookup (details,
                               "NewPackage", "(&s&s&s)",
                               &new_name, &new_evr, &new_arch);

  if (have_old && have_new)
    {
      g_print ("!%s-%s-%s\n", old_name, old_evr, old_arch);
      g_print ("=%s-%s-%s\n", new_name, new_evr, new_arch);
    }
  else if (have_old)
    {
      g_print ("-%s-%s-%s\n", old_name, old_evr, old_arch);
    }
  else if (have_new)
    {
      g_print ("+%s-%s-%s\n", new_name, new_evr, new_arch);
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: gulafaran/spotifycli
int print_nowplaying(DBus * dbus) {
  GVariant *result, *props;
  gchar **artists = NULL, *artist = NULL, *title = NULL;

  result = g_dbus_connection_call_sync(dbus->bus, "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties",
      "Get", g_variant_new("(ss)", "org.mpris.MediaPlayer2.Player", "Metadata"), G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &dbus->error);

  if (!result) {
    g_warning("Failed to call Get: %s\n", dbus->error->message);
    g_error_free(dbus->error);
    return 1;
  }

  g_variant_get(result, "(v)", &props);
  g_variant_lookup(props, "xesam:artist", "^as", &artists);
  g_variant_lookup(props, "xesam:title", "s", &title);

  if (artists)
    artist = g_strjoinv(", ", artists);
  else
    artist = "(Unknown Artist)";

  if (!title)
    title = "(Unknown Song)";

  g_printf("%s – %s\n", artist, title);

  return 0;
}
コード例 #5
0
static void
cm_service_add (GUPnPConnmanManager *manager,
                GVariant            *dict,
                gchar               *path,
                guint               port)
{
        CMServiceState new_state;
        CMService      *cm_service;
        GVariant       *eth;
        gchar          *iface;
        gchar          *name;
        gchar          *state;

        iface   = NULL;
        name    = NULL;

        g_variant_lookup (dict, "Name", "s", &name);

        eth = g_variant_lookup_value (dict, "Ethernet", G_VARIANT_TYPE_VARDICT);

        if (eth != NULL) {
                g_variant_lookup (eth, "Interface", "s", &iface);
                g_variant_unref (eth);
        }

        new_state = CM_SERVICE_STATE_INACTIVE;

        if (g_variant_lookup (dict, "State", "&s", &state) != FALSE)
                if ((g_strcmp0 (state, "online") == 0) ||
                    (g_strcmp0 (state, "ready") == 0))
                        new_state = CM_SERVICE_STATE_ACTIVE;

        cm_service = cm_service_new (manager, NULL);

        cm_service->name    = name;
        cm_service->iface   = iface;
        cm_service->port    = port;
        cm_service->current = new_state;

        g_hash_table_insert (manager->priv->cm_services,
                             g_strdup (path),
                             cm_service);

        cm_service->cancellable = g_cancellable_new ();

        g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
                                  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
                                  G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                                  NULL,
                                  CM_DBUS_CONNMAN_NAME,
                                  path,
                                  CM_DBUS_SERVICE_INTERFACE,
                                  cm_service->cancellable,
                                  service_proxy_new_cb,
                                  manager);
}
コード例 #6
0
static void
cm_service_update (CMService *cm_service, GVariant *dict, guint port)
{
        CMServiceState new_state;
        GVariant       *eth;
        gchar          *iface;
        gchar          *name;
        gchar          *state;
        gboolean       is_name;
        gboolean       is_iface;

        is_iface = FALSE;
        iface    = NULL;
        name     = NULL;

        is_name = g_variant_lookup (dict, "Name", "s", &name);

        eth = g_variant_lookup_value (dict, "Ethernet", G_VARIANT_TYPE_VARDICT);

        if (eth != NULL) {
                is_iface = g_variant_lookup (eth, "Interface", "s", &iface);
                g_variant_unref (eth);
        }

        new_state = CM_SERVICE_STATE_INACTIVE;

        if (g_variant_lookup (dict, "State", "&s", &state) != FALSE)
                if ((g_strcmp0 (state, "online") == 0) ||
                    (g_strcmp0 (state, "ready") == 0))
                        new_state = CM_SERVICE_STATE_ACTIVE;

        if (is_name && (g_strcmp0 (cm_service->name, name) != 0)) {
                g_free (cm_service->name);
                cm_service->name = name;

                if (cm_service->context != NULL)
                        g_object_set (G_OBJECT (cm_service->context),
                                      "network",
                                      cm_service->name,
                                      NULL);
        }

        if (is_iface && (g_strcmp0 (cm_service->iface, iface) != 0)) {
                g_free (cm_service->iface);
                cm_service->iface = iface;

                if (cm_service->context != NULL) {
                        service_context_delete (cm_service);
                        service_context_create (cm_service);
                }
        }

        cm_service->port = port;
        service_context_update (cm_service, new_state);
}
コード例 #7
0
static gboolean
handle_resize (UDisksLogicalVolume   *_volume,
               GDBusMethodInvocation *invocation,
               guint64                new_size,
               GVariant              *options)
{
  GError *error = NULL;
  UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume);
  UDisksLinuxLogicalVolumeObject *object = NULL;
  UDisksDaemon *daemon;
  uid_t caller_uid;
  UDisksLinuxVolumeGroupObject *group_object;
  LVJobData data;

  if (!common_setup (volume, invocation, options,
                     N_("Authentication is required to resize a logical volume"),
                     &object, &daemon, &caller_uid, NULL))
    goto out;

  group_object = udisks_linux_logical_volume_object_get_volume_group (object);
  data.vg_name = udisks_linux_volume_group_object_get_name (group_object);
  data.lv_name = udisks_linux_logical_volume_object_get_name (object);
  data.new_lv_size = new_size;

  data.resize_fs = FALSE;
  data.force = FALSE;
  g_variant_lookup (options, "resize_fsys", "b", &(data.resize_fs));
  g_variant_lookup (options, "force", "b", &(data.force));

  if (!udisks_daemon_launch_threaded_job_sync (daemon,
                                               UDISKS_OBJECT (object),
                                               "lvm-lvol-resize",
                                               caller_uid,
                                               lvresize_job_func,
                                               &data,
                                               NULL, /* user_data_free_func */
                                               NULL, /* GCancellable */
                                               &error))
    {
      g_dbus_method_invocation_return_error (invocation,
                                             UDISKS_ERROR,
                                             UDISKS_ERROR_FAILED,
                                             "Error resizing logical volume: %s",
                                             error->message);
      goto out;
    }

  udisks_logical_volume_complete_resize (_volume, invocation);

 out:
  g_clear_object (&object);
  return TRUE;
}
コード例 #8
0
static void
poll_with_variant (GPid pid,
                   GVariant *info,
                   GError *error,
                   gpointer user_data)
{
    StoragedLinuxVolumeGroupObject *object = user_data;
    StoragedDaemon *daemon;
    GVariantIter *iter;
    gboolean needs_polling;

    if (pid != object->poll_pid)
    {
        g_object_unref (object);
        return;
    }

    object->poll_pid = 0;

    if (error)
    {
        storaged_warning ("Failed to poll LVM volume group %s: %s",
                          storaged_linux_volume_group_object_get_name (object),
                          error->message);
        g_object_unref (object);
        return;
    }

    daemon = storaged_linux_volume_group_object_get_daemon (object);

    storaged_linux_volume_group_update (STORAGED_LINUX_VOLUME_GROUP (object->iface_volume_group), info, &needs_polling);

    if (g_variant_lookup (info, "lvs", "aa{sv}", &iter))
    {
        GVariant *lv_info = NULL;
        while (g_variant_iter_loop (iter, "@a{sv}", &lv_info))
        {
            const gchar *name;
            StoragedLinuxLogicalVolumeObject *volume;

            g_variant_lookup (lv_info, "name", "&s", &name);
            update_operations (daemon, name, lv_info, &needs_polling);
            volume = g_hash_table_lookup (object->logical_volumes, name);
            if (volume)
                storaged_linux_logical_volume_object_update (volume, lv_info, &needs_polling);
        }
        g_variant_iter_free (iter);
    }

    g_object_unref (object);
}
コード例 #9
0
ファイル: photos-utils.c プロジェクト: uajain/gnome-photos
PhotosZoomEvent
photos_utils_get_zoom_event (GVariant *dictionary)
{
  GEnumClass *zoom_event_class = NULL;
  GEnumValue *event_value;
  PhotosZoomEvent ret_val = PHOTOS_ZOOM_EVENT_NONE;
  const gchar *event_str;

  g_return_val_if_fail (dictionary != NULL, PHOTOS_ZOOM_EVENT_NONE);
  g_return_val_if_fail (g_variant_is_of_type (dictionary, G_VARIANT_TYPE_VARDICT), PHOTOS_ZOOM_EVENT_NONE);

  if (!g_variant_lookup (dictionary, "event", "&s", &event_str))
    goto out;

  zoom_event_class = G_ENUM_CLASS (g_type_class_ref (PHOTOS_TYPE_ZOOM_EVENT));

  event_value = g_enum_get_value_by_nick (zoom_event_class, event_str);
  if (event_value == NULL)
    event_value = g_enum_get_value_by_name (zoom_event_class, event_str);
  if (event_value == NULL)
    goto out;

  ret_val = (PhotosZoomEvent) event_value->value;

 out:
  g_clear_pointer (&zoom_event_class, g_type_class_unref);
  g_return_val_if_fail (ret_val != PHOTOS_ZOOM_EVENT_NONE, PHOTOS_ZOOM_EVENT_NONE);
  return ret_val;
}
コード例 #10
0
static void
ip4_addresses_set (NMSetting  *setting,
                   GVariant   *connection_dict,
                   const char *property,
                   GVariant   *value)
{
	GPtrArray *addrs;
	GVariant *s_ip4;
	char **labels, *gateway = NULL;
	int i;

	if (!_nm_setting_use_legacy_property (setting, connection_dict, "addresses", "address-data"))
		return;

	addrs = nm_utils_ip4_addresses_from_variant (value, &gateway);

	s_ip4 = g_variant_lookup_value (connection_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
	if (g_variant_lookup (s_ip4, "address-labels", "^as", &labels)) {
		for (i = 0; i < addrs->len && labels[i]; i++)
			if (*labels[i])
				nm_ip_address_set_attribute (addrs->pdata[i], "label", g_variant_new_string (labels[i]));
		g_strfreev (labels);
	}
	g_variant_unref (s_ip4);

	g_object_set (setting,
	              NM_SETTING_IP_CONFIG_ADDRESSES, addrs,
	              NM_SETTING_IP_CONFIG_GATEWAY, gateway,
	              NULL);
	g_ptr_array_unref (addrs);
	g_free (gateway);
}
コード例 #11
0
static void
uoa_session_process_cb (GObject *source,
    GAsyncResult *res,
    gpointer user_data)
{
  SignonAuthSession *session = (SignonAuthSession *) source;
  GSimpleAsyncResult *result = user_data;
  GVariant *session_data;
  gchar *password;
  GError *error = NULL;

  session_data = signon_auth_session_process_finish (session, res, &error);
  if (error != NULL)
    {
      g_simple_async_result_take_error (result, error);
      goto out;
    }

  if (!g_variant_lookup (session_data, "Secret", "s", &password))
    {
      g_simple_async_result_set_error (result, TP_ERROR,
          TP_ERROR_DOES_NOT_EXIST, _("Password not found"));
      goto out;
    }

  g_simple_async_result_set_op_res_gpointer (result, password, g_free);

out:
  g_simple_async_result_complete (result);
  g_object_unref (result);
}
コード例 #12
0
static gboolean
handle_delete (UDisksLogicalVolume   *_volume,
               GDBusMethodInvocation *invocation,
               GVariant              *options)
{
  GError *error = NULL;
  UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume);
  UDisksLinuxLogicalVolumeObject *object = NULL;
  UDisksDaemon *daemon = NULL;
  uid_t caller_uid;
  gboolean teardown_flag = FALSE;
  UDisksLinuxVolumeGroupObject *group_object;
  LVJobData data;

  g_variant_lookup (options, "tear-down", "b", &teardown_flag);

  if (!common_setup (volume, invocation, options,
                     N_("Authentication is required to delete a logical volume"),
                     &object, &daemon, &caller_uid, NULL))
    goto out;

  if (teardown_flag &&
      !teardown_logical_volume (_volume,
                                daemon,
                                invocation,
                                options,
                                &error))
    {
      g_dbus_method_invocation_take_error (invocation, error);
      goto out;
    }

  group_object = udisks_linux_logical_volume_object_get_volume_group (object);
  data.vg_name = udisks_linux_volume_group_object_get_name (group_object);
  data.lv_name = udisks_linux_logical_volume_object_get_name (object);

  if (!udisks_daemon_launch_threaded_job_sync (daemon,
                                               UDISKS_OBJECT (object),
                                               "lvm-lvol-delete",
                                               caller_uid,
                                               lvremove_job_func,
                                               &data,
                                               NULL, /* user_data_free_func */
                                               NULL, /* GCancellable */
                                               &error))
    {
      g_dbus_method_invocation_return_error (invocation,
                                             UDISKS_ERROR,
                                             UDISKS_ERROR_FAILED,
                                             "Error deleting logical volume: %s",
                                             error->message);
      goto out;
    }

  udisks_logical_volume_complete_delete (_volume, invocation);

 out:
  g_clear_object (&object);
  return TRUE;
}
コード例 #13
0
static gboolean
set_ip_config_common (NMPPPManager *self,
                      GVariant *config_dict,
                      const char *iface_prop,
                      guint32 *out_mtu)
{
	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
	NMConnection *applied_connection;
	NMSettingPpp *s_ppp;
	const char *iface;

	if (!g_variant_lookup (config_dict, iface_prop, "&s", &iface)) {
		_LOGE ("no interface received!");
		return FALSE;
	}
	if (priv->ip_iface == NULL)
		priv->ip_iface = g_strdup (iface);

	/* Got successful IP config; obviously the secrets worked */
	applied_connection = nm_act_request_get_applied_connection (priv->act_req);
	g_object_set_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES, NULL);

	if (out_mtu) {
		/* Get any custom MTU */
		s_ppp = nm_connection_get_setting_ppp (applied_connection);
		*out_mtu = s_ppp ? nm_setting_ppp_get_mtu (s_ppp) : 0;
	}

	monitor_stats (self);
	return TRUE;
}
コード例 #14
0
/* Converts the named Interface Identifier item to an IPv6 LL address and
 * returns the IID.
 */
static gboolean
iid_value_to_ll6_addr (GVariant *dict,
                       const char *prop,
                       struct in6_addr *out_addr,
                       NMUtilsIPv6IfaceId *out_iid)
{
	guint64 iid;

	if (!g_variant_lookup (dict, prop, "t", &iid)) {
		_LOGD ("pppd plugin property '%s' missing or not a uint64", prop);
		return FALSE;
	}
	g_return_val_if_fail (iid != 0, FALSE);

	/* Construct an IPv6 LL address from the interface identifier.  See
	 * http://tools.ietf.org/html/rfc4291#section-2.5.1 (IPv6) and
	 * http://tools.ietf.org/html/rfc5072#section-4.1 (IPv6 over PPP).
	 */
	memset (out_addr->s6_addr, 0, sizeof (out_addr->s6_addr));
	out_addr->s6_addr16[0] = htons (0xfe80);
	memcpy (out_addr->s6_addr + 8, &iid, sizeof (iid));
	if (out_iid)
		nm_utils_ipv6_interface_identfier_get_from_addr (out_iid, out_addr);
	return TRUE;
}
コード例 #15
0
ファイル: main.c プロジェクト: mgrzeschik/rauc
static void on_installer_changed(GDBusProxy *proxy, GVariant *changed,
				 const gchar* const *invalidated,
				 gpointer data) {
	RaucInstallArgs *args = data;
	gchar *msg;

	if (invalidated && invalidated[0]) {
		g_warning("rauc service disappeared\n");
		g_mutex_lock(&args->status_mutex);
		args->status_result = 2;
		g_mutex_unlock(&args->status_mutex);
		args->cleanup(args);
		return;
	}

	g_mutex_lock(&args->status_mutex);
	if (g_variant_lookup(changed, "Operation", "s", &msg)) {
		g_queue_push_tail(&args->status_messages, g_strdup(msg));
	}
	g_mutex_unlock(&args->status_mutex);

	if (!g_queue_is_empty(&args->status_messages)) {
		args->notify(args);
	}
}
コード例 #16
0
static char *
get_option (GVariant *options, const char *key)
{
	GVariant *value;
	const guchar *bytes, *s;
	gsize len;
	char *converted, *d;

	if (!g_variant_lookup (options, key, "@ay", &value))
		return NULL;

	bytes = g_variant_get_fixed_array (value, &len, 1);

	/* Since the DHCP options come through environment variables, they should
	 * already be UTF-8 safe, but just make sure.
	 */
	converted = g_malloc (len + 1);
	for (s = bytes, d = converted; s < bytes + len; s++, d++) {
		/* Convert NULLs to spaces and non-ASCII characters to ? */
		if (*s == '\0')
			*d = ' ';
		else if (*s > 127)
			*d = '?';
		else
			*d = *s;
	}
	*d = '\0';
	g_variant_unref (value);

	return converted;
}
コード例 #17
0
ファイル: invocation.c プロジェクト: mvollmer/storaged
static PolkitCheckAuthorizationFlags
lookup_invocation_flags (GDBusMethodInvocation *invocation,
                         const GDBusMethodInfo *info)
{
  gboolean auth_no_user_interaction;
  GVariant *params;
  GVariant *options;
  gint i;

  auth_no_user_interaction = FALSE;

  /* Find an options, a{sv} */
  if (info->in_args)
    {
      for (i = 0; info->in_args[i] != NULL; i++)
        {
          if (g_str_equal (info->in_args[i]->name, "options") &&
              g_str_equal (info->in_args[i]->signature, "a{sv}"))
            {
              params = g_dbus_method_invocation_get_parameters (invocation);
              g_variant_get_child (params, i, "@a{sv}", &options);
              g_variant_lookup (options, "auth.no_user_interaction", "b",
                                &auth_no_user_interaction);
              g_variant_unref (options);
            }
        }
    }

  return auth_no_user_interaction ?
      POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE :
      POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION;
}
コード例 #18
0
static gboolean
has_passphrase_in_configuration (ChangePassphraseData *data)
{
  gboolean ret = FALSE;
  GVariantIter iter;
  const gchar *type;
  GVariant *details;

  g_variant_iter_init (&iter, udisks_block_get_configuration (data->block));
  while (g_variant_iter_next (&iter, "(&s@a{sv})", &type, &details))
    {
      if (g_strcmp0 (type, "crypttab") == 0)
        {
          const gchar *passphrase_path;
          if (g_variant_lookup (details, "passphrase-path", "^&ay", &passphrase_path) &&
              strlen (passphrase_path) > 0)
            {
              g_variant_unref (details);
              ret = TRUE;
              goto out;
            }
        }
      g_variant_unref (details);
    }
 out:
  return ret;
}
コード例 #19
0
static void emit_response (XdpImplFileChooser *object,
                           gboolean for_save,
                           const gchar *arg_destination,
                           const gchar *arg_handle,
                           guint arg_response,
                           const gchar *const *arg_uris,
                           GVariant *arg_options)
{
  g_autoptr(Request) request = lookup_request_by_handle (arg_handle);
  GVariantBuilder uris;
  GVariantBuilder results;
  g_autofree char *ruri = NULL;
  gboolean writable = TRUE;
  g_autoptr(GError) error = NULL;
  g_autoptr(GVariant) choices = NULL;
  int i;

  if (request == NULL)
    return;

  REQUEST_AUTOLOCK (request);

  if (!g_variant_lookup (arg_options, "b", "writable", &writable))
    writable = FALSE;

  g_variant_builder_init (&results, G_VARIANT_TYPE_VARDICT);

  choices = g_variant_lookup_value (arg_options, "choices", G_VARIANT_TYPE ("a(ss)"));
  if (choices)
    g_variant_builder_add (&results, "{sv}", "choices", choices);

  g_variant_builder_init (&uris, G_VARIANT_TYPE ("as"));

  for (i = 0; arg_uris[i] != NULL; i++)
    {
      const char *uri = arg_uris[i];
      ruri = register_document (uri, request->app_id, for_save, writable, &error);
      if (ruri == NULL)
        {
          g_warning ("Failed to register %s: %s\n", uri, error->message);
          g_clear_error (&error);
        }
      else
        {
          g_debug ("convert uri %s -> %s\n", uri, ruri);
          g_variant_builder_add (&uris, "s", ruri);
        }
    }

  g_variant_builder_add (&results, "{&sv}", "uris", g_variant_builder_end (&uris));

  if (request->exported)
    {
      xdp_request_emit_response (XDP_REQUEST (request),
                                 arg_response,
                                 g_variant_builder_end (&results));
      unregister_handle (arg_handle);
      request_unexport (request);
    }
}
コード例 #20
0
ファイル: volumegroup.c プロジェクト: carriercomm/storaged-1
static void
poll_with_variant (GPid pid,
                   GVariant *info,
                   GError *error,
                   gpointer user_data)
{
  StorageVolumeGroup *self = user_data;
  GVariantIter *iter;
  gboolean needs_polling;

  if (pid != self->poll_pid)
    {
      g_object_unref (self);
      return;
    }

  self->poll_pid = 0;

  if (error)
    {
      g_message ("Failed to poll LVM volume group %s: %s",
                 storage_volume_group_get_name (self), error->message);
      g_object_unref (self);
      return;
    }

  volume_group_update_props (self, info, &needs_polling);

  if (g_variant_lookup (info, "lvs", "aa{sv}", &iter))
    {
      GVariant *lv_info = NULL;
      while (g_variant_iter_loop (iter, "@a{sv}", &lv_info))
        {
          const gchar *name;
          StorageLogicalVolume *volume;

          g_variant_lookup (lv_info, "name", "&s", &name);
          update_operations (name, lv_info, &needs_polling);
          volume = g_hash_table_lookup (self->logical_volumes, name);
          if (volume)
            storage_logical_volume_update (volume, self, lv_info, &needs_polling);
        }
      g_variant_iter_free (iter);
    }

  g_object_unref (self);
}
コード例 #21
0
ファイル: volumegroup.c プロジェクト: carriercomm/storaged-1
static void
update_operations (const gchar *lv_name,
                   GVariant *lv_info,
                   gboolean *needs_polling_ret)
{
  const gchar *move_pv;
  guint64 copy_percent;

  if (lv_is_pvmove_volume (lv_name)
      && g_variant_lookup (lv_info, "move_pv", "&s", &move_pv)
      && g_variant_lookup (lv_info, "copy_percent", "t", &copy_percent))
    {
      update_progress_for_device ("lvm-vg-empty-device",
                                  move_pv,
                                  copy_percent/100000000.0);
      *needs_polling_ret = TRUE;
    }
}
コード例 #22
0
static void
object_manager_interfaces_added (GDBusProxy      *proxy,
                                 const char      *path,
                                 GVariant        *dict,
                                 NMBluez5Manager *self)
{
	if (g_variant_lookup (dict, BLUEZ5_DEVICE_INTERFACE, "a{sv}", NULL))
		device_added (proxy, path, self);
}
コード例 #23
0
ファイル: realms.c プロジェクト: pdonlon/cockpit
static void
on_realm_properties_changed (GDBusProxy *proxy,
                             GVariant *changed_properties,
                             const gchar * const *invalidated_properties,
                             gpointer user_data)
{
  RealmData *data = user_data;
  if (g_variant_lookup (changed_properties, "Configured", "&s", NULL))
    update_realm_configured (data);
}
コード例 #24
0
static void
response_cb (GDBusConnection  *connection,
             const gchar      *sender_name,
             const gchar      *object_path,
             const gchar      *interface_name,
             const gchar      *signal_name,
             GVariant         *parameters,
             gpointer          user_data)
{
  GtkFileChooserNative *self = user_data;
  FilechooserPortalData *data = self->mode_data;
  guint32 portal_response;
  int gtk_response;
  const char **uris;
  int i;
  GVariant *response_data;
  g_autoptr (GVariant) choices = NULL;

  g_variant_get (parameters, "(u@a{sv})", &portal_response, &response_data);
  g_variant_lookup (response_data, "uris", "^a&s", &uris);

  choices = g_variant_lookup_value (response_data, "choices", G_VARIANT_TYPE ("a(ss)"));
  if (choices)
    for (i = 0; i < g_variant_n_children (choices); i++)
      {
        const char *id;
        const char *selected;
        g_variant_get_child (choices, i, "(&s&s)", &id, &selected);
        gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (self), id, selected);
      }

  g_slist_free_full (self->custom_files, g_object_unref);
  self->custom_files = NULL;
  for (i = 0; uris[i]; i++)
    self->custom_files = g_slist_prepend (self->custom_files, g_file_new_for_uri (uris[i]));

  switch (portal_response)
    {
    case 0:
      gtk_response = GTK_RESPONSE_OK;
      break;
    case 1:
      gtk_response = GTK_RESPONSE_CANCEL;
      break;
    case 2:
    default:
      gtk_response = GTK_RESPONSE_DELETE_EVENT;
      break;
    }

  filechooser_portal_data_free (data);
  self->mode_data = NULL;

  _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (self), gtk_response);
}
コード例 #25
0
ファイル: volumegroup.c プロジェクト: carriercomm/storaged-1
/**
 * storage_volume_group_update:
 * @self: A #StorageVolumeGroup.
 * @object: The enclosing #StorageVolumeGroupObject instance.
 *
 * Updates the interface.
 */
static void
volume_group_update_props (StorageVolumeGroup *self,
                           GVariant *info,
                           gboolean *needs_polling_ret)
{
  LvmVolumeGroup *iface = LVM_VOLUME_GROUP (self);
  const gchar *str;
  guint64 num;

  if (g_variant_lookup (info, "uuid", "&s", &str))
    lvm_volume_group_set_uuid (iface, str);

  if (g_variant_lookup (info, "size", "t", &num))
    lvm_volume_group_set_size (iface, num);

  if (g_variant_lookup (info, "free-size", "t", &num))
    lvm_volume_group_set_free_size (iface, num);

  if (g_variant_lookup (info, "extent-size", "t", &num))
    lvm_volume_group_set_extent_size (iface, num);
}
コード例 #26
0
static void
on_get_secret_configuration_cb (GObject      *source_object,
                                GAsyncResult *res,
                                gpointer      user_data)
{
  ChangePassphraseData *data = user_data;
  GVariantIter iter;
  const gchar *type;
  GVariant *details;
  GVariant *configuration = NULL;
  GError *error;

  configuration = NULL;
  error = NULL;
  if (!udisks_block_call_get_secret_configuration_finish (UDISKS_BLOCK (source_object),
                                                          &configuration,
                                                          res,
                                                          &error))
    {
      gdu_utils_show_error (GTK_WINDOW (data->window),
                            _("Error retrieving configuration data"),
                            error);
      g_error_free (error);
      change_passphrase_data_free (data);
      goto out;
    }

  g_variant_iter_init (&iter, configuration);
  while (g_variant_iter_next (&iter, "(&s@a{sv})", &type, &details))
    {
      if (g_strcmp0 (type, "crypttab") == 0)
        {
          const gchar *passphrase_contents;
          data->crypttab_details = g_variant_ref (details);
          if (g_variant_lookup (details, "passphrase-contents", "^&ay", &passphrase_contents))
            {
              gtk_entry_set_text (GTK_ENTRY (data->existing_passphrase_entry), passphrase_contents);
              /* Don't focus on the "Existing passphrase" entry */
              gtk_editable_select_region (GTK_EDITABLE (data->existing_passphrase_entry), 0, 0);
              gtk_widget_grab_focus (data->passphrase_entry);
              run_dialog (data);
              goto out;
            }
        }
    }

  gdu_utils_show_error (GTK_WINDOW (data->window), _("/etc/crypttab configuration data is malformed"), NULL);
  change_passphrase_data_free (data);

 out:
  if (configuration != NULL)
    g_variant_unref (configuration);
}
コード例 #27
0
ファイル: entry.c プロジェクト: passy/libpam-policycache
/**
 * CacheEntryUnserialize:
 * @value: Serialized cache entry.
 * @error: (out)(allow-none): Error return location or #NULL.
 *
 * Returns: #CacheEntry instance with a reference count of one and attributes
 * filled in from parsing @value.
 */
CacheEntry *CacheEntryUnserialize(const gchar *value, GError **error) {
  GError *parse_error = NULL;
  GVariant *dict = NULL;
  CacheEntry *self = NULL;
  gint version = 0;
  const gchar *tmp_str = NULL;

  dict = g_variant_parse(
      G_VARIANT_TYPE_VARDICT, value, NULL, NULL, &parse_error);
  if (!dict) {
    g_assert(parse_error);
    g_set_error(error, CACHE_ENTRY_ERROR, CACHE_ENTRY_PARSE_ERROR,
                "Failed to parse cache entry: %s", parse_error->message);
    g_error_free(parse_error);
    return NULL;
  }


  g_variant_lookup(dict, "version", "i", &version);
  if (version != 1) {
    g_set_error(error, CACHE_ENTRY_ERROR, CACHE_ENTRY_PARSE_ERROR,
                "Entry version %d not supported", version);
    goto done;
  }

  // TODO(vonhollen): Check for all of the keys so we know each g_variant_lookup
  // will work, then add error handling to each CacheUtil*FromString() call.

  self = CacheEntryNew();
  g_variant_lookup(dict, "tries", "i", &self->tries);

  if (g_variant_lookup(dict, "algorithm", "&s", &tmp_str))
    CacheUtilHashalgFromString(tmp_str, &self->algorithm);

  if (g_variant_lookup(dict, "salt", "&s", &tmp_str))
    CacheUtilBytesFromString(tmp_str, &self->salt);
  if (g_variant_lookup(dict, "hash", "&s", &tmp_str))
    CacheUtilBytesFromString(tmp_str, &self->hash);

  if (g_variant_lookup(dict, "last_verified", "&s", &tmp_str))
    CacheUtilDatetimeFromString(tmp_str, &self->last_verified);
  if (g_variant_lookup(dict, "last_used", "&s", &tmp_str))
    CacheUtilDatetimeFromString(tmp_str, &self->last_used);
  if (g_variant_lookup(dict, "last_tried", "&s", &tmp_str))
    CacheUtilDatetimeFromString(tmp_str, &self->last_tried);

done:
  g_variant_unref(dict);
  return self;
}
コード例 #28
0
static gboolean
on_handle_get_password (GoaPasswordBased      *interface,
                        GDBusMethodInvocation *invocation,
                        const gchar           *id,
                        gpointer               user_data)
{
  GoaObject *object;
  GoaAccount *account;
  GoaProvider *provider;
  GError *error;
  GVariant *credentials;
  gchar *password;

  /* TODO: maybe log what app is requesting access */

  password = NULL;
  credentials = NULL;

  object = GOA_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (interface)));
  account = goa_object_peek_account (object);
  provider = goa_provider_get_for_provider_type (goa_account_get_provider_type (account));

  error = NULL;
  credentials = goa_utils_lookup_credentials_sync (provider,
                                                   object,
                                                   NULL, /* GCancellable* */
                                                   &error);
  if (credentials == NULL)
    {
      g_dbus_method_invocation_take_error (invocation, error);
      goto out;
    }

  if (!g_variant_lookup (credentials, "password", "s", &password))
    {
      g_dbus_method_invocation_return_error (invocation,
                                             GOA_ERROR,
                                             GOA_ERROR_FAILED, /* TODO: more specific */
                                             _("Did not find password with username `%s' in credentials"),
                                             id);
      goto out;
    }

  goa_password_based_complete_get_password (interface, invocation, password);

 out:
  g_free (password);
  if (credentials != NULL)
    g_variant_unref (credentials);
  g_object_unref (provider);
  return TRUE; /* invocation was handled */
}
コード例 #29
0
/**
 * ot_admin_checksum_version:
 * @checksum: A GVariant from an ostree checksum.
 *
 *
 * Get the version metadata string from a commit variant object, if it exists.
 *
 * Returns: A newly allocated string of the version, or %NULL is none
 */
char *
ot_admin_checksum_version (GVariant *checksum)
{
  g_autoptr(GVariant) metadata = NULL;
  const char *ret = NULL;

  metadata = g_variant_get_child_value (checksum, 0);

  if (!g_variant_lookup (metadata, "version", "&s", &ret))
    return NULL;

  return g_strdup (ret);
}
コード例 #30
0
ファイル: storageblock.c プロジェクト: humanux/cockpit
static const gchar *
variant_lookup (GVariant *dictionary,
                const gchar *key)
{
  const gchar *v;

  if (dictionary == NULL
      || !g_variant_lookup (dictionary, key, "^&ay", &v)
      || v[0] == '\0')
    return NULL;

  return v;
}