static NMSettingUpdateSecretResult
update_secret_dict (NMSetting *setting,
                    GVariant *secrets,
                    GError **error)
{
	NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
	GVariantIter iter;
	const char *name, *value;
	NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED;

	g_return_val_if_fail (secrets != NULL, NM_SETTING_UPDATE_SECRET_ERROR);

	/* Make sure the items are valid */
	g_variant_iter_init (&iter, secrets);
	while (g_variant_iter_next (&iter, "{&s&s}", &name, &value)) {
		if (!name || !strlen (name)) {
			g_set_error_literal (error, NM_CONNECTION_ERROR,
			                     NM_CONNECTION_ERROR_INVALID_SETTING,
			                     _("setting contained a secret with an empty name"));
			g_prefix_error (error, "%s: ", NM_SETTING_VPN_SETTING_NAME);
			return NM_SETTING_UPDATE_SECRET_ERROR;
		}

		if (!value || !strlen (value)) {
			g_set_error (error, NM_CONNECTION_ERROR,
			             NM_CONNECTION_ERROR_INVALID_PROPERTY,
			             _("secret value was empty"));
			g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, name);
			return NM_SETTING_UPDATE_SECRET_ERROR;
		}
	}

	/* Now add the items to the settings' secrets list */
	g_variant_iter_init (&iter, secrets);
	while (g_variant_iter_next (&iter, "{&s&s}", &name, &value)) {
		if (value == NULL) {
			g_warn_if_fail (value != NULL);
			continue;
		}
		if (strlen (value) == 0) {
			g_warn_if_fail (strlen (value) > 0);
			continue;
		}

		if (g_strcmp0 (g_hash_table_lookup (priv->secrets, name), value) == 0)
			continue;

		g_hash_table_insert (priv->secrets, g_strdup (name), g_strdup (value));
		result = NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED;
	}

	return result;
}
static gboolean
get_sessions (gpointer user_data)
{
    GVariant     *var;
    GVariantIter *iter;
    GError       *error = NULL;
    gchar        *path = NULL;

    g_print ("calling GetSessions\n");
    var = g_dbus_proxy_call_sync (manager, "GetSessions", g_variant_new ("()"), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, &error);
    if (var == NULL) {
        g_print ("returned NULL\t");

        if (error)
            g_print ("error %s", error->message);

        g_print ("\n");
        g_clear_error (&error);
        return FALSE;
    }

    g_variant_get (var, "(ao)", &iter);
    while (g_variant_iter_next (iter, "o", &path))
    {
        validate_stuff (path);
    }
    g_variant_iter_free (iter);
    g_variant_unref (var);

    return FALSE;
}
static void
_get_properties_for_passphrase_cb (GObject      *obj,
                                   GAsyncResult *res,
                                   gpointer      user_data)
{
    MtnConnmanService *service;
    GError *error;
    GVariant *var;

    service = MTN_CONNMAN_SERVICE (obj);

    error = NULL;
    var = g_dbus_proxy_call_finish (G_DBUS_PROXY (obj), res, &error);
    if (!var) {
        g_warning ("Connman Service.GetProperties failed: %s", 
                   error->message);
        g_error_free (error);
    } else {
        GVariant *value;
        char *key;
        GVariantIter *iter;
        
        g_variant_get (var, "(a{sv})", &iter);
        while (g_variant_iter_next (iter, "{sv}", &key, &value)) {
            if (g_strcmp0 (key, "Passphrase") == 0 ||
                g_strcmp0 (key, "PassphraseRequired") == 0) {
                mtn_connman_service_handle_new_property (service,
                                                         key, value);
            }
        }
        g_variant_iter_free (iter);
        g_variant_unref (var);
    }
}
Exemple #4
0
/**
 * fu_util_print_metadata:
 **/
static void
fu_util_print_metadata (GVariant *val)
{
	GVariant *variant;
	const gchar *key;
	const gchar *type;
	guint i;
	_cleanup_variant_iter_free_ GVariantIter *iter = NULL;

	g_variant_get (val, "(a{sv})", &iter);
	while (g_variant_iter_next (iter, "{&sv}", &key, &variant)) {
		g_print ("%s", key);
		for (i = strlen (key); i < 15; i++)
			g_print (" ");
		type = g_variant_get_type_string (variant);
		if (g_strcmp0 (type, "s") == 0) {
			g_print ("%s\n", g_variant_get_string (variant, NULL));
		} else if (g_strcmp0 (type, "b") == 0) {
			g_print ("%s\n", g_variant_get_boolean (variant) ? "True" : "False");
		} else if (g_strcmp0 (type, "t") == 0) {
			g_print ("%" G_GUINT64_FORMAT "\n", g_variant_get_uint64 (variant));
		} else {
			g_print ("???? [%s]\n", type);
		}
		g_variant_unref (variant);
	}
}
static void
get_managed_objects_cb (GDBusProxy *proxy,
                        GAsyncResult *res,
                        NMBluez5Manager *self)
{
	GVariant *variant, *ifaces;
	GVariantIter i;
	GError *error = NULL;
	const char *path;

	variant = _nm_dbus_proxy_call_finish (proxy, res,
	                                      G_VARIANT_TYPE ("(a{oa{sa{sv}}})"),
	                                      &error);
	if (!variant) {
		if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD))
			nm_log_warn (LOGD_BT, "Couldn't get managed objects: not running Bluez5?");
		else {
			g_dbus_error_strip_remote_error (error);
			nm_log_warn (LOGD_BT, "Couldn't get managed objects: %s", error->message);
		}
		g_clear_error (&error);
		return;
	}
	g_variant_iter_init (&i, g_variant_get_child_value (variant, 0));
	while ((g_variant_iter_next (&i, "{&o*}", &path, &ifaces))) {
		if (g_variant_lookup_value (ifaces, BLUEZ5_DEVICE_INTERFACE,
		                            G_VARIANT_TYPE_DICTIONARY)) {
			device_added (proxy, path, self);
		}
		g_variant_unref (ifaces);
	}

	g_variant_unref (variant);
}
Exemple #6
0
static void
get_next_discover_info (struct DiscoverData *data)
{
  g_clear_object (&(data->cur_proxy));

  if (g_variant_iter_next (data->object_paths, "&o", &(data->cur_path)))
    {
      g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
                                0,
                                NULL,
                                "org.freedesktop.realmd",
                                data->cur_path,
                                "org.freedesktop.realmd.Realm",
                                NULL,
                                on_proxy_ready_for_discover_info,
                                data);
    }
  else
    {
      cockpit_realms_complete_discover (COCKPIT_REALMS (data->realms), data->invocation,
                                        data->name? data->name : "", g_variant_builder_end (&(data->all_details)));
      g_variant_iter_free (data->object_paths);
      g_free (data);
    }
}
gboolean
gkd_secret_property_parse_all (GVariant *array,
			       const gchar *interface,
			       GckBuilder *builder)
{
	CK_ATTRIBUTE_TYPE attr_type;
	const char *name;
	DataType data_type;
	GVariantIter iter;
	GVariant *variant;

	g_return_val_if_fail (array != NULL, FALSE);
	g_return_val_if_fail (builder != NULL, FALSE);

	g_variant_iter_init (&iter, array);

	while (g_variant_iter_next (&iter, "{&sv}", &name, &variant)) {
		/* Property interface.name */
		if (!property_to_attribute (name, interface, &attr_type, &data_type))
			return FALSE;

		/* Property value */
		if (!iter_get_variant (variant, data_type, attr_type, builder)) {
			g_variant_unref (variant);
			return FALSE;
		}

		g_variant_unref (variant);
	}

	return TRUE;
}
static gboolean
iter_get_fields (GVariant *variant,
		 gulong attr_type,
		 GckBuilder *builder)
{
	GString *result;
	const gchar *key, *value;
	GVariantIter iter;

	g_assert (variant != NULL);
	g_assert (builder != NULL);

	g_return_val_if_fail (g_variant_type_is_array (g_variant_get_type (variant)), FALSE);

	result = g_string_new ("");
	g_variant_iter_init (&iter, variant);

	while (g_variant_iter_next (&iter, "{&s&s}", &key, &value)) {
		/* Key */
		g_string_append (result, key);
		g_string_append_c (result, '\0');

		/* Value */
		g_string_append (result, value);
		g_string_append_c (result, '\0');
	}

	gck_builder_add_data (builder, attr_type, (const guchar *)result->str, result->len);
	g_string_free (result, TRUE);
	return TRUE;
}
static void
g_properties_changed (GDBusProxy         *proxy,
                      GVariant           *changed_properties,
                      const gchar * const *invalidated_properties)
{
  guint n;
  const gchar *key;
  GVariantIter *iter;
  const gchar *gname;

  g_variant_get (changed_properties, "a{sv}", &iter);
  while (g_variant_iter_next (iter, "{&sv}", &key, NULL))
    {
      gname = lookup_property_gname_from_property_name (key);
      if (gname != NULL)
	g_object_notify (G_OBJECT (proxy), gname);
    }

  for (n = 0; invalidated_properties[n] != NULL; n++)
    {
      gname = lookup_property_gname_from_property_name (invalidated_properties[n]);
      if (gname != NULL)
	g_object_notify (G_OBJECT (proxy), gname);
    }

}
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;
}
Exemple #11
0
/**
 * fu_util_get_updates_internal:
 **/
static GPtrArray *
fu_util_get_updates_internal (FuUtilPrivate *priv, GError **error)
{
	GVariantIter *iter_device;
	GPtrArray *devices = NULL;
	FuDevice *dev;
	gchar *id;
	_cleanup_variant_iter_free_ GVariantIter *iter = NULL;

	g_dbus_proxy_call (priv->proxy,
			   "GetUpdates",
			   NULL,
			   G_DBUS_CALL_FLAGS_NONE,
			   -1,
			   NULL,
			   fu_util_get_devices_cb, priv);
	g_main_loop_run (priv->loop);
	if (priv->val == NULL) {
		g_propagate_error (error, priv->error);
		return NULL;
	}

	/* parse */
	g_variant_get (priv->val, "(a{sa{sv}})", &iter);
	devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
	while (g_variant_iter_next (iter, "{&sa{sv}}", &id, &iter_device)) {
		dev = fu_device_new ();
		fu_device_set_id (dev, id);
		fu_device_set_metadata_from_iter (dev, iter_device);
		g_ptr_array_add (devices, dev);
		g_variant_iter_free (iter_device);
	}
	return devices;
}
Exemple #12
0
/**
 * fcitx_kbd_get_layouts_nofree: (rename-to fcitx_kbd_get_layouts)
 * @kbd: A #FcitxKbd
 *
 * Get Fcitx all im list
 *
 * Returns: (transfer full) (element-type FcitxLayoutItem): A #FcitxLayoutItem
 *List
 * Rename to: fcitx_kbd_get_layouts
 **/
FCITX_EXPORT_API
GPtrArray *fcitx_kbd_get_layouts_nofree(FcitxKbd *kbd) {
    GError *error = NULL;
    GVariant *variant = g_dbus_proxy_call_sync(
        G_DBUS_PROXY(kbd), "GetLayouts", NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START,
        -1, NULL, &error);

    GPtrArray *array = NULL;

    if (error) {
        g_warning("%s", error->message);
        g_error_free(error);
    } else if (variant) {
        array = g_ptr_array_new();
        GVariantIter *iter;
        gchar *layout, *kbdvariant, *name, *langcode;
        g_variant_get(variant, "(a(ssss))", &iter);
        while (g_variant_iter_next(iter, "(ssss)", &layout, &kbdvariant, &name,
                                   &langcode, NULL)) {
            FcitxLayoutItem *item = g_malloc0(sizeof(FcitxLayoutItem));
            item->layout = layout;
            item->variant = kbdvariant;
            item->name = name;
            item->langcode = langcode;
            g_ptr_array_add(array, item);
        }
        g_variant_iter_free(iter);
    }

    return array;
}
Exemple #13
0
static void
g_menu_exporter_unsubscribe (GMenuExporter *exporter,
                             const gchar   *sender,
                             GVariant      *group_ids)
{
  GMenuExporterRemote *remote;
  GVariantIter iter;
  guint32 id;

  if (sender != NULL)
    remote = g_hash_table_lookup (exporter->remotes, sender);
  else
    remote = exporter->peer_remote;

  if (remote == NULL)
    return;

  g_variant_iter_init (&iter, group_ids);
  while (g_variant_iter_next (&iter, "u", &id))
    g_menu_exporter_remote_unsubscribe (remote, id);

  if (!g_menu_exporter_remote_has_subscriptions (remote))
    {
      if (sender != NULL)
        g_hash_table_remove (exporter->remotes, sender);
      else
        g_clear_pointer (&exporter->peer_remote, g_menu_exporter_remote_free);
    }
}
Exemple #14
0
static void
_fcitx_client_g_signal(GDBusProxy *proxy,
                       gchar      *sender_name,
                       gchar      *signal_name,
                       GVariant   *parameters,
                       gpointer    user_data)
{
    FCITX_UNUSED(proxy);
    FCITX_UNUSED(sender_name);
    if (strcmp(signal_name, "EnableIM") == 0) {
        g_signal_emit(user_data, signals[ENABLE_IM_SIGNAL], 0);
    }
    else if (strcmp(signal_name, "CloseIM") == 0) {
        g_signal_emit(user_data, signals[CLOSE_IM_SIGNAL], 0);
    }
    else if (strcmp(signal_name, "CommitString") == 0) {
        const gchar* data = NULL;
        g_variant_get(parameters, "(s)", &data);
        if (data) {
            g_signal_emit(user_data, signals[COMMIT_STRING_SIGNAL], 0, data);
        }
    }
    else if (strcmp(signal_name, "ForwardKey") == 0) {
        guint32 key, state;
        gint32 type;
        g_variant_get(parameters, "(uui)", &key, &state, &type);
        g_signal_emit(user_data, signals[FORWARD_KEY_SIGNAL], 0, key, state, type);
    }
    else if (strcmp(signal_name, "DeleteSurroundingText") == 0) {
        guint32 nchar;
        gint32 offset;
        g_variant_get(parameters, "(iu)", &offset, &nchar);
        g_signal_emit(user_data, signals[DELETE_SURROUNDING_TEXT_SIGNAL], 0, offset, nchar);
    }
    else if (strcmp(signal_name, "UpdateClientSideUI") == 0) {
        const gchar* auxup, *auxdown, *preedit, *candidate, *imname;
        int cursor;
        g_variant_get(parameters, "(sssssi)", &auxup, &auxdown, &preedit, &candidate, &imname, &cursor);
        g_signal_emit(user_data, signals[UPDATE_CLIENT_SIDE_UI_SIGNAL], 0, auxup, auxdown, preedit, candidate, imname, cursor);
    }
    else if (strcmp(signal_name, "UpdateFormattedPreedit") == 0) {
        int cursor_pos;
        GPtrArray* array = g_ptr_array_new_with_free_func(_item_free);
        GVariantIter* iter;
        g_variant_get(parameters, "(a(si)i)", &iter, &cursor_pos);

        gchar* string;
        int type;
        while (g_variant_iter_next(iter, "(si)", &string, &type, NULL)) {
            FcitxPreeditItem* item = g_malloc0(sizeof(FcitxPreeditItem));
            item->string = strdup(string);
            item->type = type;
            g_ptr_array_add(array, item);
            g_free(string);
        }
        g_variant_iter_free(iter);
        g_signal_emit(user_data, signals[UPDATED_FORMATTED_PREEDIT_SIGNAL], 0, array, cursor_pos);
        g_ptr_array_free(array, TRUE);
    }
}
Exemple #15
0
static ActionInfo *
action_info_new_from_iter (GVariantIter *iter)
{
  const gchar *param_str;
  ActionInfo *info;
  gboolean enabled;
  GVariant *state;
  gchar *name;

  if (!g_variant_iter_next (iter, "{s(b&g@av)}", &name,
                            &enabled, &param_str, &state))
    return NULL;

  info = g_slice_new (ActionInfo);
  info->name = name;
  info->enabled = enabled;

  if (g_variant_n_children (state))
    g_variant_get_child (state, 0, "v", &info->state);
  else
    info->state = NULL;
  g_variant_unref (state);

  if (param_str[0])
    info->parameter_type = g_variant_type_copy ((GVariantType *) param_str);
  else
    info->parameter_type = NULL;

  return info;
}
GtkFileFilter *
gtk_file_filter_from_gvariant (GVariant *variant)
{
  GtkFileFilter *filter;
  GVariantIter *iter;
  const char *name;
  int type;
  char *tmp;

  filter = gtk_file_filter_new ();

  g_variant_get (variant, "(&sa(us))", &name, &iter);

  gtk_file_filter_set_name (filter, name);

  while (g_variant_iter_next (iter, "(u&s)", &type, &tmp))
    {
      switch (type)
        {
        case 0:
          gtk_file_filter_add_pattern (filter, tmp);
          break;
        case 1:
          gtk_file_filter_add_mime_type (filter, tmp);
          break;
        default:
          break;
       }
    }
  g_variant_iter_free (iter);

  return filter;
}
Exemple #17
0
static void fcitx_input_method_g_properties_changed(
    GDBusProxy *proxy, GVariant *changed_properties,
    const gchar *const *invalidated_properties) {
    FcitxInputMethod *user = FCITX_INPUT_METHOD(proxy);
    GVariantIter *iter;
    const gchar *key;

    if (changed_properties != NULL) {
        g_variant_get(changed_properties, "a{sv}", &iter);
        while (g_variant_iter_next(iter, "{&sv}", &key, NULL)) {
            if (g_strcmp0(key, "IMList") == 0)
                g_signal_emit(user, signals[IMLIST_CHANGED_SIGNAL], 0);
            else if (g_strcmp0(key, "CurrentIM") == 0)
                g_object_notify_by_pspec(G_OBJECT(user),
                                         properties[PROP_CURRENT_IM]);
        }
        g_variant_iter_free(iter);
    }

    if (invalidated_properties != NULL) {
        const gchar *const *item = invalidated_properties;
        while (*item) {
            if (g_strcmp0(*item, "IMList") == 0)
                g_signal_emit(user, signals[IMLIST_CHANGED_SIGNAL], 0);
            else if (g_strcmp0(*item, "CurrentIM") == 0)
                g_object_notify_by_pspec(G_OBJECT(user),
                                         properties[PROP_CURRENT_IM]);
            item++;
        }
    }
}
Exemple #18
0
static GVariant *
g_menu_exporter_subscribe (GMenuExporter *exporter,
                           const gchar   *sender,
                           GVariant      *group_ids)
{
  GMenuExporterRemote *remote;
  GVariantBuilder builder;
  GVariantIter iter;
  guint32 id;

  remote = g_hash_table_lookup (exporter->remotes, sender);

  if (remote == NULL)
    {
      guint watch_id;

      watch_id = g_bus_watch_name_on_connection (exporter->connection, sender, G_BUS_NAME_WATCHER_FLAGS_NONE,
                                                 NULL, g_menu_exporter_name_vanished, exporter, NULL);
      remote = g_menu_exporter_remote_new (exporter, watch_id);
      g_hash_table_insert (exporter->remotes, g_strdup (sender), remote);
    }

  g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a(uuaa{sv}))"));

  g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(uuaa{sv})"));

  g_variant_iter_init (&iter, group_ids);
  while (g_variant_iter_next (&iter, "u", &id))
    g_menu_exporter_remote_subscribe (remote, id, &builder);

  g_variant_builder_close (&builder);

  return g_variant_builder_end (&builder);
}
Exemple #19
0
GVariant* GnomeGrabber::Impl::onShellMethodCall(std::string const& method, GVariant* parameters)
{
  LOG_DEBUG(logger) << "Called method '" << method << "'";

  if (method == "GrabAccelerators")
  {
    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a(su))")))
    {
      GVariant* variant;
      GVariantBuilder builder;
      GVariantIter* iterator;
      gchar const* accelerator;
      guint flags;

      g_variant_builder_init(&builder, G_VARIANT_TYPE("au"));
      g_variant_get(parameters, "(a(su))", &iterator);

      while (g_variant_iter_next(iterator, "(&su)", &accelerator, &flags))
        g_variant_builder_add(&builder, "u", grabAccelerator(accelerator, flags));

      g_variant_iter_free(iterator);
      variant = g_variant_builder_end(&builder);
      return g_variant_new_tuple(&variant, 1);
    }
    else
      LOG_WARN(logger) << "Expected arguments of type (a(su))";
  }
  else if (method == "GrabAccelerator")
  {
    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(su)")))
    {
      GVariant* variant;
      gchar const* accelerator;
      guint flags;

      g_variant_get(parameters, "(&su)", &accelerator, &flags);
      variant = g_variant_new_uint32(grabAccelerator(accelerator, flags));
      return g_variant_new_tuple(&variant, 1);
    }
    else
      LOG_WARN(logger) << "Expected arguments of type (su)";
  }
  else if (method == "UngrabAccelerator")
  {
    if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(u)")))
    {
      GVariant* variant;
      guint action;

      g_variant_get(parameters, "(u)", &action);
      variant = g_variant_new_boolean(removeAction(action));
      return g_variant_new_tuple(&variant, 1);
    }
    else
      LOG_WARN(logger) << "Expected arguments of type (u)";
  }

  return nullptr;
}
Exemple #20
0
static gboolean
handle_get_crypto_passphrase (CockpitStorageBlock *object,
                              GDBusMethodInvocation *invocation)
{
  StorageBlock *block = STORAGE_BLOCK(object);
  GError *error = NULL;

  if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN))
    return TRUE;

  GVariantBuilder options;
  g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}"));

  GVariant *conf = NULL;
  if (!udisks_block_call_get_secret_configuration_sync (block->udisks_block,
                                                        g_variant_builder_end (&options),
                                                        &conf,
                                                        NULL,
                                                        &error))
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_error_free (error);
      return TRUE;
    }

  GVariantIter iter;
  g_variant_iter_init (&iter, conf);
  const gchar *type;
  GVariant *details;
  while (g_variant_iter_next (&iter, "(&s*)", &type, &details))
    {
      if (strcmp (type, "crypttab") == 0)
        {
          const gchar *phrase = variant_lookup (details, "passphrase-contents");
          if (phrase)
            {
              gs_free gchar *phrase_locale = g_locale_to_utf8 (phrase, -1, NULL, NULL, NULL);
              if (phrase_locale)
                cockpit_storage_block_complete_get_crypto_passphrase (object, invocation,
                                                                      phrase_locale);
              else
                g_dbus_method_invocation_return_error (invocation,
                                                       COCKPIT_ERROR,
                                                       COCKPIT_ERROR_FAILED,
                                                       "Can't convert passphrase into UTF8");
              g_variant_unref (details);
              return TRUE;
            }
        }
      g_variant_unref (details);
    }

  cockpit_storage_block_complete_get_crypto_passphrase (object, invocation, "");
  return TRUE;
}
BT_EXPORT_API int bluetooth_telephony_is_nrec_enabled(gboolean *status)
{
	GVariant *reply = NULL;
	GError *err = NULL;
	GVariantIter *reply_iter;
	GDBusConnection *connection;
	GVariant *value;
	gchar *key;
	GHashTable *list_hash = NULL;
	BT_DBG("+");

	BT_TELEPHONY_CHECK_INITIALIZED();
	BT_TELEPHONY_CHECK_ENABLED();
	connection = _bt_init_system_gdbus_conn();
	if (status == NULL)
		return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;

	reply = g_dbus_connection_call_sync(connection,
					HFP_AGENT_SERVICE,
					HFP_AGENT_PATH,
					HFP_AGENT_INTERFACE,
					"GetProperties",
					NULL,
					G_VARIANT_TYPE("(a{sv})"),
					G_DBUS_CALL_FLAGS_NONE,
					-1,
					NULL,
					&err);
	if (err) {
		BT_ERR("GetProperties GDBus error: %s", err->message);
		g_clear_error(&err);
		return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
	}

	if (!reply) {
		BT_ERR("Error returned in method call\n");
		return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
	}
	g_variant_get(reply, "(a{sv})", &reply_iter);
	list_hash = g_hash_table_new_full(g_str_hash,
					g_str_equal,
					NULL,
					NULL);

	while (g_variant_iter_next(reply_iter, "{sv}", &key, &value)) {
		BT_DBG("key is %s", key);
		g_hash_table_insert(list_hash, key, value);
	}

	value = g_hash_table_lookup(list_hash, "nrec");
	if (value != NULL) {
		*status = g_variant_get_boolean(value);
		BT_DBG("NREC status = [%d]", *status);
	}
	g_hash_table_destroy(list_hash);
	BT_DBG("-");
	return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
void
storage_mdraid_update (StorageMDRaid *mdraid)
{
    UDisksMDRaid *udisks_mdraid = mdraid->udisks_mdraid;
    CockpitStorageMDRaid *iface = COCKPIT_STORAGE_MDRAID (mdraid);
    StorageProvider *provider = storage_object_get_provider (mdraid->object);
    UDisksClient *udisks_client = storage_provider_get_udisks_client (provider);

    cockpit_storage_mdraid_set_uuid (iface, udisks_mdraid_get_uuid (udisks_mdraid));
    cockpit_storage_mdraid_set_name (iface, udisks_mdraid_get_name (udisks_mdraid));
    cockpit_storage_mdraid_set_level (iface, udisks_mdraid_get_level (udisks_mdraid));
    cockpit_storage_mdraid_set_num_devices (iface, udisks_mdraid_get_num_devices (udisks_mdraid));
    cockpit_storage_mdraid_set_size (iface, udisks_mdraid_get_size (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_action (iface, udisks_mdraid_get_sync_action (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_completed (iface, udisks_mdraid_get_sync_completed (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_rate (iface, udisks_mdraid_get_sync_rate (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_remaining_time (iface, udisks_mdraid_get_sync_remaining_time (udisks_mdraid));
    cockpit_storage_mdraid_set_degraded (iface, udisks_mdraid_get_degraded (udisks_mdraid));
    {
        gs_free gchar *loc = g_locale_to_utf8 (udisks_mdraid_get_bitmap_location (udisks_mdraid),
                                               -1, NULL, NULL, NULL);
        cockpit_storage_mdraid_set_bitmap_location (iface, loc);
    }
    cockpit_storage_mdraid_set_chunk_size (iface, udisks_mdraid_get_chunk_size (udisks_mdraid));

    GVariantBuilder devices;
    g_variant_builder_init (&devices, G_VARIANT_TYPE("a(oiast)"));

    GVariantIter iter;
    gint disk_slot;
    const gchar *disk_block_objpath;
    gs_unref_variant GVariant *disk_states = NULL;
    guint64 disk_num_errors;
    g_variant_iter_init (&iter, udisks_mdraid_get_active_devices (udisks_mdraid));
    while (g_variant_iter_next (&iter, "(&oi@asta{sv})",
                                &disk_block_objpath,
                                &disk_slot,
                                &disk_states,
                                &disk_num_errors,
                                NULL))
    {
        UDisksObject *udisks_object;
        UDisksBlock *udisks_block;
        StorageObject *object;

        if ((udisks_object = udisks_client_peek_object (udisks_client, disk_block_objpath))
                && (udisks_block = udisks_object_peek_block (udisks_object))
                && (object = storage_provider_lookup_for_udisks_block (provider, udisks_block)))
        {
            g_variant_builder_add (&devices, "(oi@ast)",
                                   g_dbus_object_get_object_path (G_DBUS_OBJECT(object)),
                                   disk_slot,
                                   disk_states,
                                   disk_num_errors);
        }
    }
    cockpit_storage_mdraid_set_active_devices (iface, g_variant_builder_end (&devices));
}
MMLocationGpsRaw *
mm_location_gps_raw_new_from_dictionary (GVariant *dictionary,
                                         GError **error)
{
    GError *inner_error = NULL;
    MMLocationGpsRaw *self;
    GVariantIter iter;
    gchar *key;
    GVariant *value;

    self = mm_location_gps_raw_new ();
    if (!dictionary)
        return self;

    if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) {
        g_set_error (error,
                     MM_CORE_ERROR,
                     MM_CORE_ERROR_INVALID_ARGS,
                     "Cannot create GPS RAW location from dictionary: "
                     "invalid variant type received");
        g_object_unref (self);
        return NULL;
    }

    g_variant_iter_init (&iter, dictionary);
    while (!inner_error &&
           g_variant_iter_next (&iter, "{sv}", &key, &value)) {
        if (g_str_equal (key, PROPERTY_UTC_TIME))
            self->priv->utc_time = g_variant_dup_string (value, NULL);
        else if (g_str_equal (key, PROPERTY_LONGITUDE))
            self->priv->longitude = g_variant_get_double (value);
        else if (g_str_equal (key, PROPERTY_LATITUDE))
            self->priv->latitude = g_variant_get_double (value);
        else if (g_str_equal (key, PROPERTY_ALTITUDE))
            self->priv->altitude = g_variant_get_double (value);
        g_free (key);
        g_variant_unref (value);
    }

    /* If any of the mandatory parameters is missing, cleanup */
    if (!self->priv->utc_time ||
        self->priv->longitude == MM_LOCATION_LONGITUDE_UNKNOWN ||
        self->priv->latitude == MM_LOCATION_LATITUDE_UNKNOWN) {
        g_set_error (error,
                     MM_CORE_ERROR,
                     MM_CORE_ERROR_INVALID_ARGS,
                     "Cannot create GPS RAW location from dictionary: "
                     "mandatory parameters missing "
                     "(utc-time: %s, longitude: %s, latitude: %s)",
                     self->priv->utc_time ? "yes" : "missing",
                     (self->priv->longitude != MM_LOCATION_LONGITUDE_UNKNOWN) ? "yes" : "missing",
                     (self->priv->latitude != MM_LOCATION_LATITUDE_UNKNOWN) ? "yes" : "missing");
        g_clear_object (&self);
    }

    return self;
}
Exemple #24
0
static gboolean
mtn_connman_initable_init_sync (GInitable     *initable,
                                GCancellable  *cancellable,
                                GError       **error)
{
    GInitableIface *iface_class, *parent_iface_class;
    GVariant *var, *value;
    GVariantIter *iter;
    char *key;
    MtnConnman *connman;

    connman = MTN_CONNMAN (initable);

    /* Chain up the old method */
    iface_class = G_INITABLE_GET_IFACE (initable);
    parent_iface_class = g_type_interface_peek_parent (iface_class);
    if (!parent_iface_class->init (initable, cancellable, error)) {
        return FALSE;
    }

    g_signal_connect (connman, "notify::g-name-owner",
                      G_CALLBACK (_name_owner_notify_cb), NULL);

    var = g_dbus_proxy_call_sync (G_DBUS_PROXY (connman),
                                  "GetProperties",
                                  NULL,
                                  G_DBUS_CALL_FLAGS_NONE,
                                  -1,
                                  NULL,
                                  error);
    if (!var) {
        return FALSE;
    }

    g_variant_get (var, "(a{sv})", &iter);
    while (g_variant_iter_next (iter, "{sv}", &key, &value)) {
        g_hash_table_insert (connman->priv->properties,
                             key, value);
    }
    g_variant_iter_free (iter);
    g_variant_unref (var);

    var = g_dbus_proxy_call_sync (G_DBUS_PROXY (connman),
                                  "GetServices",
                                  NULL,
                                  G_DBUS_CALL_FLAGS_NONE,
                                  -1,
                                  NULL,
                                  error);
    if (!var) {
        return FALSE;
    }

    connman->priv->services = var;

    return TRUE;
}
static void
add_interface (JsonBuilder *builder,
               GDBusInterface *interface,
               GVariant *changed_properties)
{
  gchar *s;

  json_builder_set_member_name (builder, g_dbus_proxy_get_interface_name (G_DBUS_PROXY (interface)));
  json_builder_begin_object (builder);

  if (changed_properties == NULL)
    {
      gchar **properties;
      guint n;

      properties = g_dbus_proxy_get_cached_property_names (G_DBUS_PROXY (interface));
      for (n = 0; properties != NULL && properties[n] != NULL; n++)
        {
          const gchar *property_name = properties[n];
          GVariant *value;
          value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (interface), property_name);
          if (value != NULL)
            {
              s = g_strconcat ("dbus_prop_", property_name, NULL);
              json_builder_set_member_name (builder, s);
              g_free (s);
              _json_builder_add_gvariant (builder, value);
              g_variant_unref (value);
            }
        }
      g_strfreev (properties);

      if (properties == NULL)
        {
          json_builder_set_member_name (builder, "HackEmpty");
          json_builder_add_string_value (builder, "HackEmpty");
        }
    }
  else
    {
      GVariantIter iter;
      const gchar *property_name;
      GVariant *value;
      g_variant_iter_init (&iter, changed_properties);
      while (g_variant_iter_next (&iter, "{&sv}", &property_name, &value))
        {
          s = g_strconcat ("dbus_prop_", property_name, NULL);
          json_builder_set_member_name (builder, property_name);
          g_free (s);
          _json_builder_add_gvariant (builder, value);
          g_variant_unref (value);
        }
    }

  json_builder_end_object (builder);
}
Exemple #26
0
/**
 * fwupd_result_from_variant_iter:
 **/
static void
fwupd_result_from_variant_iter (FwupdResult *result, GVariantIter *iter)
{
	GVariant *value;
	const gchar *key;
	while (g_variant_iter_next (iter, "{&sv}", &key, &value)) {
		fwupd_result_from_kv (result, key, value);
		g_variant_unref (value);
	}
}
Exemple #27
0
static void
fwupd_release_set_from_variant_iter (FwupdRelease *release, GVariantIter *iter)
{
	GVariant *value;
	const gchar *key;
	while (g_variant_iter_next (iter, "{&sv}", &key, &value)) {
		fwupd_release_from_key_value (release, key, value);
		g_variant_unref (value);
	}
}
void
storage_provider_load_remembered_configs (StorageProvider *provider)
{
  gchar *info_data;
  gsize info_size;
  GError *error = NULL;

  g_mutex_lock (&provider->remembered_configs_mutex);

  if (!g_file_get_contents (PACKAGE_LOCALSTATE_DIR "/lib/cockpit/hidden-configs",
                            &info_data, &info_size,
                            &error))
    {
      if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
        g_warning ("Can't load hidden configs: %s", error->message);
      g_clear_error (&error);
      g_mutex_unlock (&provider->remembered_configs_mutex);
      return;
    }

  gs_unref_variant GVariant *info = g_variant_new_from_data (G_VARIANT_TYPE ("a{sa{sv}}"),
                                                             info_data, info_size, TRUE,
                                                             g_free, NULL);

  GVariantIter parent_iter, *child_iter;
  const gchar *parent_path, *child_path;
  GVariant *config;

  g_hash_table_remove_all (provider->remembered_configs);
  g_variant_iter_init (&parent_iter, info);
  while (g_variant_iter_next (&parent_iter, "{&sa{sv}}", &parent_path, &child_iter))
    {
      while (g_variant_iter_next (child_iter, "{&sv}", &child_path, &config))
        {
          remember_config_inlock (provider, parent_path, child_path, config);
          g_variant_unref (config);
        }
      g_variant_iter_free (child_iter);
    }
  provider->remembered_configs_need_save = FALSE;

  g_mutex_unlock (&provider->remembered_configs_mutex);
}
static void
change_passphrase_cb (GObject      *source_object,
                      GAsyncResult *res,
                      gpointer      user_data)
{
  ChangePassphraseData *data = user_data;
  GError *error;

  error = NULL;
  if (!udisks_encrypted_call_change_passphrase_finish (UDISKS_ENCRYPTED (source_object),
                                                       res,
                                                       &error))
    {
      gdu_utils_show_error (GTK_WINDOW (data->window), _("Error changing passphrase"), error);
      g_error_free (error);
    }

  /* Update the system-level configuration, if applicable */
  if (data->has_passphrase_in_configuration)
    {
      GVariantBuilder builder;
      GVariantIter iter;
      const gchar *key;
      GVariant *value;

      g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
      g_variant_iter_init (&iter, data->crypttab_details);
      while (g_variant_iter_next (&iter, "{sv}", &key, &value))
        {
          if (g_strcmp0 (key, "passphrase-contents") == 0)
            {
              g_variant_builder_add (&builder, "{sv}", "passphrase-contents",
                                     g_variant_new_bytestring (gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry))));
            }
          else
            {
              g_variant_builder_add (&builder, "{sv}", key, value);
            }
          g_variant_unref (value);
        }

      udisks_block_call_update_configuration_item (data->block,
                                                   g_variant_new ("(s@a{sv})", "crypttab", data->crypttab_details),
                                                   g_variant_new ("(sa{sv})", "crypttab", &builder),
                                                   g_variant_new ("a{sv}", NULL), /* options */
                                                   NULL, /* cancellable */
                                                   update_configuration_item_cb,
                                                   data);

    }
  else
    {
      change_passphrase_data_free (data);
    }
}
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);
}