示例#1
0
static void playerctl_player_properties_changed_callback (GDBusProxy *_proxy, GVariant *changed_properties, const gchar *const *invalidated_properties, gpointer user_data)
{
  OrgMprisMediaPlayer2Player *proxy;

  PlayerctlPlayer *self = user_data;
  proxy = ORG_MPRIS_MEDIA_PLAYER2_PLAYER(_proxy);

  GVariant *metadata = g_variant_lookup_value(changed_properties, "Metadata", NULL);
  GVariant *playback_status = g_variant_lookup_value(changed_properties, "PlaybackStatus", NULL);

  if (metadata) {
    g_signal_emit(self, connection_signals[METADATA], 0, metadata);
  }

  if (playback_status) {
    const gchar *status_str = g_variant_get_string(playback_status, NULL);

    if (g_strcmp0(status_str, "Playing") == 0)
      g_signal_emit(self, connection_signals[PLAY], 0);
    else if (g_strcmp0(status_str, "Paused") == 0)
      g_signal_emit(self, connection_signals[PAUSE], 0);
    else if (g_strcmp0(status_str, "Stopped") == 0)
      g_signal_emit(self, connection_signals[STOP], 0);

  }

  for (int i = 0; invalidated_properties[i] != NULL; i += 1) {
    if (g_strcmp0(invalidated_properties[i], "PlaybackStatus") == 0) {
      g_signal_emit(self, connection_signals[EXIT], 0);
      break;
    }
  }
}
void DeviceOptions::bind_samplerate(const QString &name,
	GVariant *const gvar_list)
{
	GVariant *gvar_list_samplerates;

	assert(gvar_list);

	if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list,
			"samplerate-steps", G_VARIANT_TYPE("at"))))
	{
		gsize num_elements;
		const uint64_t *const elements =
			(const uint64_t *)g_variant_get_fixed_array(
				gvar_list_samplerates, &num_elements, sizeof(uint64_t));

		assert(num_elements == 3);

		_properties.push_back(boost::shared_ptr<Property>(
			new Double(name, 0, QObject::tr("Hz"),
				make_pair((double)elements[0], (double)elements[1]),
						(double)elements[2],
				bind(samplerate_double_getter, _sdi),
				bind(samplerate_double_setter, _sdi, _1))));

		g_variant_unref(gvar_list_samplerates);
	}
	else if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list,
			"samplerates", G_VARIANT_TYPE("at"))))
	{
		bind_enum(name, SR_CONF_SAMPLERATE,
			gvar_list_samplerates, print_samplerate);
		g_variant_unref(gvar_list_samplerates);
	}
}
示例#3
0
文件: connman.c 项目: Ezio-PS/movian
/**
 *  Popup an request to the user on behalf of connman
 */
static GVariant *
agent_request_input(connman_service_t *cs, GVariant *req,
		    GDBusMethodInvocation *inv)
{
  TRACE(TRACE_INFO, "CONNMAN", "Requesting credentials for %s", cs->cs_path);

  TRACE(TRACE_DEBUG, "CONNMAN", "RequestInput: %s",
	g_variant_print(req, TRUE));

  prop_t *p = prop_create_root(NULL);

  prop_set(p, "type",   PROP_SET_STRING, "auth");
  prop_set(p, "id",     PROP_SET_STRING, cs->cs_path);
  prop_set(p, "source", PROP_SET_STRING, "Network");


  GVariant *prev = g_variant_lookup_value(req, "PreviousPassphrase", NULL);

  if(prev) {
    prop_set(p, "reason", PROP_SET_STRING, "Password incorrect");
  } else {
    prop_set(p, "reason", PROP_SET_STRING, "Password needed");
  }

  GVariant *identity = g_variant_lookup_value(req, "Identity", NULL);

  cs->cs_input_req_want_identity = identity != NULL;
  prop_set(p, "disableUsername", PROP_SET_INT, !cs->cs_input_req_want_identity);

  prop_set(p, "disableDomain", PROP_SET_INT, 1);

  prop_t *r = prop_create(p, "eventSink");

  cs->cs_input_req_sub =
    prop_subscribe(0,
		   PROP_TAG_CALLBACK_EVENT, input_req_event, cs,
		   PROP_TAG_NAMED_ROOT, r, "popup",
		   PROP_TAG_COURIER, connman_courier,
		   NULL);

  cs->cs_input_req_prop = p;

  /* Will show the popup */
  if(prop_set_parent(p, prop_create(prop_get_global(), "popups"))) {
    /* popuproot is a zombie, this is an error */
    abort();
  }

  cs->cs_input_req_inv = inv;
  g_object_ref(G_OBJECT(inv));

  return NULL;
}
示例#4
0
文件: setup.c 项目: ueno/ibus-m17n
static void
load_choice (GVariant    *values,
             GtkComboBox *combo,
             const gchar *name,
             gint         defval)
{
    GVariant *value;
    gint ivalue, index;
    GtkCellRenderer *renderer;

    renderer = gtk_cell_renderer_text_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo),
                                    renderer, "text", 0, NULL);

    ivalue = defval;
    value = g_variant_lookup_value (values, name, G_VARIANT_TYPE_INT32);
    if (value != NULL) {
        ivalue = g_variant_get_int32 (value);
        g_variant_unref (value);
    }
    
    index = get_combo_box_index_by_value (GTK_COMBO_BOX (combo), ivalue);
    gtk_combo_box_set_active (GTK_COMBO_BOX (combo), index);
}
示例#5
0
文件: connman.c 项目: Ezio-PS/movian
static void
connman_getpropreties(GDBusProxy *connman)
{
  GError *err = NULL;


  GVariant *v = g_dbus_proxy_call_sync(connman, "GetProperties", NULL,
				       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);

  if(v == NULL) {
    TRACE(TRACE_ERROR, "CONNMAN", "Unable to GetProperties -- %s",
	  err->message);
    g_error_free(err);
    return;
  }

  GVariant *dict = g_variant_get_child_value(v, 0);
  if(dict != NULL) {
    GVariant *state = g_variant_lookup_value(dict, "State", NULL);
    if(state != NULL) {
      const gchar *val = g_variant_get_string(state, NULL);
      prop_set_string(net_state, val);
    }
  }
  g_variant_unref(v);
}
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);
}
示例#7
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);
    }
}
示例#8
0
gboolean
g_variant_lookup (GVariant    *dictionary,
                  const gchar *key,
                  const gchar *format_string,
                  ...)
{
  GVariantType *type;
  GVariant *value;

  /* flatten */
  g_variant_get_data (dictionary);

  type = g_variant_type_new (format_string);
  value = g_variant_lookup_value (dictionary, key, type);
  g_variant_type_free (type);

  if (value)
    {
      va_list ap;

      va_start (ap, format_string);
      g_variant_get_va (value, format_string, NULL, &ap);
      g_variant_unref (value);
      va_end (ap);

      return TRUE;
    }

  else
    return FALSE;
}
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);
}
示例#10
0
文件: setup.c 项目: ueno/ibus-m17n
static void
load_color (GVariant        *values,
            GtkToggleButton *togglebutton,
            GtkColorButton  *colorbutton,
            const gchar     *name,
            GdkColor        *defval)
{
    GVariant *value;
    gboolean bvalue;
    GdkColor cvalue;

    memcpy (&cvalue, defval, sizeof (GdkColor));

    bvalue = FALSE;
    value = g_variant_lookup_value (values, name, G_VARIANT_TYPE_STRING);
    if (value != NULL) {
        const gchar *color = g_variant_get_string (value, NULL);
        if (g_strcmp0 (color, "none") != 0 &&
            gdk_color_parse (color, &cvalue))
            bvalue = TRUE;
        g_variant_unref (value);
    }

    gtk_toggle_button_set_active (togglebutton, bvalue);
    gtk_widget_set_sensitive (GTK_WIDGET (colorbutton), bvalue);
    gtk_color_button_set_color (GTK_COLOR_BUTTON (colorbutton), &cvalue);
}
示例#11
0
/* ---------------------------------------------------------------------------------------------------- */
int get_object(GDBusProxy *proxy, GPIO* gpio, object_info* obj_info)
{
	g_print("Checking Presence: %s\n",gpio->name);
 	GError *error;
	GVariant *parm;
	GVariant *result;

	error = NULL;
	parm = g_variant_new("(ss)","GPIO_PRESENT",gpio->name);
	result = g_dbus_proxy_call_sync (proxy,
                                   "getObjectFromId",
				   parm,
                                   G_DBUS_CALL_FLAGS_NONE,
                                   -1,
                                   NULL,
                                   &error);
	g_assert_no_error (error);
	const gchar* bus_name;
	const gchar* obj_path;
	gsize bus_name_size;
	gsize obj_path_size;
	GVariantIter *iter = g_variant_iter_new(result);
	GVariant* dict = g_variant_iter_next_value(iter);

	GVariant* b = g_variant_lookup_value(dict,"bus_name",(const GVariantType *) "s");
	bus_name = g_variant_get_string(b,&bus_name_size);
	GVariant* o = g_variant_lookup_value(dict,"obj_path",(const GVariantType *) "s");
	obj_path = g_variant_get_string(o,&obj_path_size);

	int rc = 0;
	if (bus_name_size ==  0 || obj_path_size == 0) {
		g_print("ERROR: gpio %s not found in lookup\n",gpio->name);
		rc = 1;

	} else {
		obj_info->bus_name = bus_name;
		obj_info->path = obj_path;
	}
	g_variant_unref(b);
	g_variant_unref(o);
	g_variant_unref(dict);
	g_variant_unref(result);

	return rc;
}
示例#12
0
文件: services.c 项目: imace/cockpit
static void
copy_entry (GVariantBuilder *dest,
            GVariant *src,
            const gchar *key)
{
  gs_unref_variant GVariant *val = g_variant_lookup_value (src, key, NULL);
  if (val)
    g_variant_builder_add (dest, "{sv}", key, val);
}
示例#13
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);
}
示例#14
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);
}
示例#15
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);
}
示例#16
0
/*****************************************************************************
 * neardal_tag_prv_read_properties: Get Neard Tag Properties
 ****************************************************************************/
static errorCode_t neardal_tag_prv_read_properties(TagProp *tagProp)
{
	errorCode_t	err		= NEARDAL_SUCCESS;
	GVariant	*tmp		= NULL;
	GVariant	*tmpOut		= NULL;
	gsize		len;

	NEARDAL_TRACEIN();
	NEARDAL_ASSERT_RET(tagProp != NULL, NEARDAL_ERROR_INVALID_PARAMETER);
	NEARDAL_ASSERT_RET(tagProp->proxy != NULL
			  , NEARDAL_ERROR_GENERAL_ERROR);

	tmp = g_datalist_get_data(&(neardalMgr.dbus_data), tagProp->name);
	if (tmp == NULL) {
		err = NEARDAL_ERROR_NO_TAG;
		NEARDAL_TRACE_ERR("Unable to read tag's properties\n");
		goto exit;
	}
	NEARDAL_TRACEF("Reading:\n%s\n", g_variant_print(tmp, TRUE));

	tmpOut = g_variant_lookup_value(tmp, "TagType", G_VARIANT_TYPE_ARRAY);
	if (tmpOut != NULL) {
		tagProp->tagType = g_variant_dup_strv(tmpOut, &len);
		tagProp->tagTypeLen = len;
		if (len == 0) {
			g_strfreev(tagProp->tagType);
			tagProp->tagType = NULL;
		}
	}

	tmpOut = g_variant_lookup_value(tmp, "Type", G_VARIANT_TYPE_STRING);
	if (tmpOut != NULL)
		tagProp->type = g_variant_dup_string(tmpOut, NULL);

	tmpOut = g_variant_lookup_value(tmp, "ReadOnly",
					G_VARIANT_TYPE_BOOLEAN);
	if (tmpOut != NULL)
		tagProp->readOnly = g_variant_get_boolean(tmpOut);

exit:
	return err;
}
static void
properties_changed_cb (GDBusProxy *proxy,
                       GVariant *changed_properties,
                       GStrv invalidated_properties,
                       EmpathyWebcredentialsMonitor *self)
{
    if (g_variant_lookup_value (changed_properties, FAILURES_PROP, NULL) == NULL)
        return;

    update_failures (self);
}
示例#18
0
static gboolean on_PushOOB(neardalHandoverAgent	*handoverAgent
			   , GDBusMethodInvocation	*invocation
			   , GVariant			*values
			   , gpointer			user_data)
{
	neardal_handover_agent_t	*agent_data	= user_data;
	gconstpointer			value;
	const gchar* 		blobKeys[] = {"EIR", "nokia.com:bt", "WSC", NULL};
	gchar	   			*blob		= NULL;
	gsize	   			blobLen		= 0;
	guint 				counter;

	(void) handoverAgent;       /* Avoid warning */
	(void) invocation;      /* Avoid warning */

	NEARDAL_TRACEIN();
	NEARDAL_TRACEF("%s\n", g_variant_print(values, TRUE));

	if (agent_data != NULL) {
		NEARDAL_TRACEF("handoverAgent pid=%d, obj path is : %s\n"
			      , agent_data->pid
			      , agent_data->objPath);
		if (agent_data->cb_oob_push_agent != NULL) {
			GVariant	*tmpOut	 = NULL;

			for(counter = 0; blobKeys[counter] != NULL; counter++) {
				tmpOut = g_variant_lookup_value(values, blobKeys[counter],
								G_VARIANT_TYPE_ARRAY);
				if (tmpOut != NULL) {
					value = g_variant_get_data(tmpOut);
					blobLen = g_variant_get_size(tmpOut);

					if (blobLen > 0) {
						blob = g_try_malloc0(blobLen);
						if (blob != NULL)
							memcpy(blob, value
							      , blobLen);
					}
					break;
				}
			}
 			(agent_data->cb_oob_push_agent)(
							(unsigned char *) blob
						       , blobLen
						, agent_data->user_data);
 			if (invocation != NULL)
 				neardal_handover_agent_complete_push_oob(handoverAgent, invocation);
		}
	}

	return TRUE;
}
示例#19
0
/**
 * playerctl_player_print_metadata_prop:
 * @self: a #PlayerctlPlayer
 * @property: (allow-none): the property from the metadata to print
 * @err: (allow-none): the location of a GError or NULL
 *
 * Gets the artist from the metadata of the current track, or empty string if
 * no track is playing.
 *
 * Returns: (transfer full): The artist from the metadata of the current track
 */
gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self, gchar *property, GError **err)
{
  GVariant *prop_variant;
  const gchar **prop_strv;
  GString *prop;
  GVariant *metadata;
  GError *tmp_error = NULL;

  g_return_val_if_fail(err == NULL || *err == NULL, NULL);

  if (self->priv->init_error != NULL) {
    g_propagate_error(err, g_error_copy(self->priv->init_error));
    return NULL;
  }

  metadata = org_mpris_media_player2_player_get_metadata(self->priv->proxy);
  if (!metadata)
    return g_strdup("");

  if (!property)
    return g_variant_print(metadata, FALSE);

  prop_variant = g_variant_lookup_value(metadata, property, NULL);

  if (!prop_variant)
    return g_strdup("");

  prop = g_string_new("");

  if (g_variant_is_of_type(prop_variant, G_VARIANT_TYPE_STRING_ARRAY)) {
    gsize prop_count;
    prop_strv = g_variant_get_strv(prop_variant, &prop_count);

    for (int i = 0; i < prop_count; i += 1) {
      g_string_append(prop, prop_strv[i]);

      if (i != prop_count - 1) {
        g_string_append(prop, ", ");
      }
    }

    g_free(prop_strv);
  } else if (g_variant_is_of_type(prop_variant, G_VARIANT_TYPE_STRING)) {
    g_string_append(prop, g_variant_get_string(prop_variant, NULL));
  } else {
    prop = g_variant_print_string(prop_variant, prop, FALSE);
  }

  return g_string_free(prop, FALSE);
}
示例#20
0
static gboolean
do_print_metadata_key (OstreeRepo     *repo,
                       const char     *resolved_rev,
                       gboolean        detached,
                       const char     *key,
                       GError        **error)
{
  gboolean ret = FALSE;
  gs_unref_variant GVariant *value = NULL;
  gs_unref_variant GVariant *commit = NULL;
  gs_unref_variant GVariant *metadata = NULL;

  if (!detached)
    {
      if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
                                     resolved_rev, &commit, error))
        goto out;
      /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
      metadata = g_variant_get_child_value (commit, 0);
    }
  else
    {
      if (!ostree_repo_read_commit_detached_metadata (repo, resolved_rev, &metadata,
                                                      NULL, error))
        goto out;
      if (metadata == NULL)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                       "No detached metadata for commit %s", resolved_rev);
          goto out;
        }
    }
  
  value = g_variant_lookup_value (metadata, key, NULL);
  if (!value)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                   "No such metadata key '%s'", key);
      goto out;
    }

  ot_dump_variant (value);

  ret = TRUE;
 out:
  return ret;
}
示例#21
0
static char *
systemd_unit_property(const char *obj, const gchar * iface, const char *name)
{
    GError *error = NULL;
    GDBusProxy *proxy;
    GVariant *asv = NULL;
    GVariant *value = NULL;
    GVariant *_ret = NULL;
    char *output = NULL;

    crm_trace("Calling GetAll on %s", obj);
    proxy = get_proxy(obj, BUS_PROPERTY_IFACE);

    if (!proxy) {
        return NULL;
    }

    _ret = g_dbus_proxy_call_sync(proxy, "GetAll", g_variant_new("(s)", iface),
                                  G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);

    if (error) {
        crm_err("Cannot get properties for %s: %s", g_dbus_proxy_get_object_path(proxy),
                error->message);
        g_error_free(error);
        g_object_unref(proxy);
        return NULL;
    }
    crm_debug("Call to GetAll passed: type '%s' %d\n", g_variant_get_type_string(_ret),
             g_variant_n_children(_ret));

    asv = g_variant_get_child_value(_ret, 0);
    crm_trace("asv type '%s' %d\n", g_variant_get_type_string(asv), g_variant_n_children(asv));

    value = g_variant_lookup_value(asv, name, NULL);
    if (value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
        crm_info("Got value '%s' for %s[%s]", g_variant_get_string(value, NULL), obj, name);
        output = g_variant_dup_string(value, NULL);

    } else {
        crm_info("No value for %s[%s]", obj, name);
    }

    g_object_unref(proxy);
    g_variant_unref(_ret);
    return output;
}
static GSList *
add_domains (GSList *items,
             GVariant *dict,
             const char *prefix,
             const char four_or_six)
{
	GVariant *val;

	/* Search domains */
	val = g_variant_lookup_value (dict, "domains", G_VARIANT_TYPE_STRING_ARRAY);
	if (val) {
		items = _list_append_val_strv (items, g_variant_dup_strv (val, NULL),
		                               "%sIP%c_DOMAINS=", prefix, four_or_six);
		g_variant_unref (val);
	}
	return items;
}
示例#23
0
void
xdp_filter_options (GVariant *options,
                    GVariantBuilder *filtered,
                    XdpOptionKey *supported_options,
                    int n_supported_options)
{
  GVariant *value;
  int i;

  for (i = 0; i < n_supported_options; i++)
    {
      value = g_variant_lookup_value (options,
                                      supported_options[i].key,
                                      supported_options[i].type);
      if (value)
         g_variant_builder_add (filtered, "{sv}", supported_options[i].key, value);
    }
}
示例#24
0
void
copy_options (GVariant *arg_options,
              GVariantBuilder *options,
              OptionKey *supported_options,
              int n_supported_options)
{
  GVariant *value;
  int i;

  for (i = 0; i < n_supported_options; i++)
    {
      value = g_variant_lookup_value (arg_options,
                                      supported_options[i].key,
                                      supported_options[i].type);
      if (value)
         g_variant_builder_add (options, "{sv}", supported_options[i].key, value);
    }
}
static gboolean
metadata_version_unique (OstreeRepo  *repo,
                         const char  *checksum,
                         const char  *version,
                         GError     **error)
{
  gs_unref_variant GVariant *variant = NULL;
  gs_unref_variant GVariant *metadata = NULL;
  gs_unref_variant GVariant *value = NULL;
  gs_free gchar *parent = NULL;

  if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum,
                                 &variant, error))
    {
      if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
        {
          g_clear_error (error);
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Do not have full history to validate version metadata is unique.");
        }
      goto out;
    }

  metadata = g_variant_get_child_value (variant, 0);
  if ((value = g_variant_lookup_value (metadata, "version", NULL)))
    if (g_str_equal (version, g_variant_get_string (value, NULL)))
      {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "Version already specified in commit %s", checksum);
        goto out;
      }
  
  if (!(parent = ostree_commit_get_parent (variant)))
    return TRUE;
  
  return metadata_version_unique (repo, parent, version, error);

 out:
  return FALSE;
}
示例#26
0
static void
prepare_print_response (GDBusConnection *connection,
                        const char      *sender_name,
                        const char      *object_path,
                        const char      *interface_name,
                        const char      *signal_name,
                        GVariant        *parameters,
                        gpointer         data)
{
  PortalData *portal = data;
  guint32 response;
  GVariant *options;

  if (portal->response_signal_id != 0)
    {
      g_dbus_connection_signal_unsubscribe (connection,
                                            portal->response_signal_id);
      portal->response_signal_id = 0;
    }

  g_variant_get (parameters, "(u@a{sv})", &response, &options);

  portal->do_print = (response == 0);

  if (portal->do_print)
    {
      GVariant *v;
      GtkPrintSettings *settings;
      GtkPageSetup *page_setup;
      GtkPrinter *printer;
      char *filename;
      char *uri;
      int fd;

      portal->result = GTK_PRINT_OPERATION_RESULT_APPLY;

      v = g_variant_lookup_value (options, "settings", G_VARIANT_TYPE_VARDICT);
      settings = gtk_print_settings_new_from_gvariant (v);
      g_variant_unref (v);

      v = g_variant_lookup_value (options, "page-setup", G_VARIANT_TYPE_VARDICT);
      page_setup = gtk_page_setup_new_from_gvariant (v);
      g_variant_unref (v);

      g_variant_lookup (options, "token", "u", &portal->token);

      printer = find_file_printer ();

      fd = g_file_open_tmp ("gtkprintXXXXXX", &filename, NULL);
      uri = g_filename_to_uri (filename, NULL, NULL);
      gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
      g_free (uri);
      close (fd);

      finish_print (portal, printer, page_setup, settings);
      g_free (filename);
    }
  else
    portal->result = GTK_PRINT_OPERATION_RESULT_CANCEL;

  if (portal->loop)
    g_main_loop_quit (portal->loop);
}
示例#27
0
文件: connman.c 项目: Ezio-PS/movian
static connman_service_t *
update_service(GVariant *v, const char *path, connman_service_t *after)
{
  connman_service_t *cs = connman_service_find(path);

  if(cs == NULL) {

    GError *err = NULL;
    GDBusProxy *proxy =
      g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
				    G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START ,
				    NULL,
				    "net.connman",
				    path,
				    "net.connman.Service",
				    NULL,
				    &err);
    if(proxy == NULL) {
      TRACE(TRACE_ERROR, "CONNMAN", "Unable to connect to service %s -- %s",
	    path, err->message);
      g_error_free(err);
      return NULL;
    }

    cs = calloc(1, sizeof(connman_service_t));
    cs->cs_refcount = 1;
    cs->cs_proxy = proxy;

    if(after == NULL) {
      TAILQ_INSERT_HEAD(&connman_services, cs, cs_link);
    } else {
      TAILQ_INSERT_AFTER(&connman_services, after, cs, cs_link);
    }

    connman_service_t *next = TAILQ_NEXT(cs, cs_link);

    cs->cs_prop = prop_create_root(path);
    cs->cs_path = strdup(path);

    cs->cs_sub =
      prop_subscribe(0,
		     PROP_TAG_CALLBACK_EVENT, connman_service_event, cs,
		     PROP_TAG_ROOT, cs->cs_prop,
		     PROP_TAG_COURIER, connman_courier,
		     NULL);

    g_signal_connect(G_OBJECT(cs->cs_proxy), "g-signal",
		     G_CALLBACK(connman_svc_signal), cs);

    // Insert at correct position

    if(prop_set_parent_ex(cs->cs_prop, service_nodes,
			  next ? next->cs_prop : NULL, NULL))
      abort();

    prop_t *m = prop_create(cs->cs_prop, "metadata");
    prop_link(prop_create(m, "name"), prop_create(m, "title"));
    prop_set(cs->cs_prop, "type", PROP_SET_STRING, "network");

  } else {

    // Possibly move

    TAILQ_REMOVE(&connman_services, cs, cs_link);

    if(after == NULL) {
      TAILQ_INSERT_HEAD(&connman_services, cs, cs_link);
    } else {
      TAILQ_INSERT_AFTER(&connman_services, after, cs, cs_link);
    }

    connman_service_t *next = TAILQ_NEXT(cs, cs_link);

    prop_move(cs->cs_prop, next ? next->cs_prop : NULL);
  }

  // Update metadata

  prop_set_from_vardict(v, prop_create(cs->cs_prop, "metadata"));

  GVariant *name = g_variant_lookup_value(v, "Name", NULL);
  const gchar *val = name ? g_variant_get_string(name, NULL) : NULL;
  if(val)
    mystrset(&cs->cs_name, val);
  return cs;
}
static void
props_changed_cb (GDBusProxy *proxy,
                  GVariant *changed_properties,
                  GStrv invalidated_properties,
                  gpointer user_data)
{
	NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data);
	NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
	const char *s, **array, **iter;
	gboolean b = FALSE;
	gint32 i32;
	GVariant *v;

	g_object_freeze_notify (G_OBJECT (self));

	if (g_variant_lookup (changed_properties, "Scanning", "b", &b))
		set_scanning (self, b);

	if (   g_variant_lookup (changed_properties, "State", "&s", &s)
	    && priv->state >= NM_SUPPLICANT_INTERFACE_STATE_READY) {
		/* Only transition to actual wpa_supplicant interface states (ie,
		 * anything > READY) after the NMSupplicantInterface has had a
		 * chance to initialize, which is signalled by entering the READY
		 * state.
		 */
		set_state_from_string (self, s);
	}

	if (g_variant_lookup (changed_properties, "BSSs", "^a&s", &array)) {
		iter = array;
		while (*iter)
			handle_new_bss (self, *iter++);
		g_free (array);
	}

	if (g_variant_lookup (changed_properties, "CurrentBSS", "&o", &s)) {
		if (strcmp (s, "/") == 0)
			s = NULL;
		if (g_strcmp0 (s, priv->current_bss) != 0) {
			g_free (priv->current_bss);
			priv->current_bss = g_strdup (s);
			g_object_notify (G_OBJECT (self), NM_SUPPLICANT_INTERFACE_CURRENT_BSS);
		}
	}

	v = g_variant_lookup_value (changed_properties, "Capabilities", G_VARIANT_TYPE_VARDICT);
	if (v) {
		parse_capabilities (self, v);
		g_variant_unref (v);
	}

	if (g_variant_lookup (changed_properties, "DisconnectReason", "i", &i32)) {
		/* Disconnect reason is currently only given for deauthentication events,
		 * not disassociation; currently they are IEEE 802.11 "reason codes",
		 * defined by (IEEE 802.11-2007, 7.3.1.7, Table 7-22).  Any locally caused
		 * deauthentication will be negative, while authentications caused by the
		 * AP will be positive.
		 */
		priv->disconnect_reason = i32;
		if (priv->disconnect_reason != 0) {
			nm_log_warn (LOGD_SUPPLICANT, "Connection disconnected (reason %d)",
				         priv->disconnect_reason);
		}
	}

	g_object_thaw_notify (G_OBJECT (self));
}
示例#29
0
/* Returns a new floating variant (essentially a fixed-up copy of @value) */
static GVariant *
_my_replace (GVariant *value)
{
  GVariant *ret;
  const gchar *dbus_type;

  if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARDICT) &&
      g_variant_lookup (value, "_dbus_type", "&s", &dbus_type))
    {
      GVariant *passed_value;
      passed_value = g_variant_lookup_value (value, "value", NULL);
      if (passed_value != NULL)
        {
          JsonNode *serialized;
          GError *error;

          serialized = json_gvariant_serialize (passed_value);
          error = NULL;
          ret = json_gvariant_deserialize (serialized,
                                           dbus_type,
                                           &error);
          json_node_free (serialized);
          if (ret == NULL)
            {
              /*
               * HACK: Work around bug in JSON-glib, see:
               * https://bugzilla.gnome.org/show_bug.cgi?id=724319
               */
              if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_INVALID_DATA &&
                  g_variant_is_of_type (passed_value, G_VARIANT_TYPE_INT64) &&
                  g_strcmp0 (dbus_type, "d") == 0)
                {
                  ret = g_variant_new_double (g_variant_get_int64 (passed_value));
                  g_clear_error (&error);
                }
              else
                {
                  g_warning ("Error converting JSON to requested type %s: %s (%s, %d)",
                             dbus_type,
                             error->message, g_quark_to_string (error->domain), error->code);
                  g_error_free (error);
                  ret = g_variant_ref (value);
                }
            }
        }
      else
        {
          g_warning ("Malformed _dbus_type vardict");
          ret = g_variant_ref (value);
        }
    }
  else if (g_variant_is_container (value))
    {
      GVariantBuilder builder;
      GVariantIter iter;
      GVariant *child;

      g_variant_builder_init (&builder, g_variant_get_type (value));

      g_variant_iter_init (&iter, value);
      while ((child = g_variant_iter_next_value (&iter)) != NULL)
        {
          g_variant_builder_add_value (&builder, _my_replace (child));
          g_variant_unref (child);
        }
      ret = g_variant_builder_end (&builder);
    }
  else
    {
      ret = g_variant_ref (value);
    }
  return ret;
}
/**
 * ostree_repo_static_delta_execute_offline:
 * @self: Repo
 * @dir_or_file: Path to a directory containing static delta data, or directly to the superblock
 * @skip_validation: If %TRUE, assume data integrity
 * @cancellable: Cancellable
 * @error: Error
 *
 * Given a directory representing an already-downloaded static delta
 * on disk, apply it, generating a new commit.  The directory must be
 * named with the form "FROM-TO", where both are checksums, and it
 * must contain a file named "superblock", along with at least one part.
 */
gboolean
ostree_repo_static_delta_execute_offline (OstreeRepo                    *self,
                                          GFile                         *dir_or_file,
                                          gboolean                       skip_validation,
                                          GCancellable                  *cancellable,
                                          GError                      **error)
{
  gboolean ret = FALSE;
  guint i, n;
  const char *dir_or_file_path = NULL;
  glnx_fd_close int meta_fd = -1;
  glnx_fd_close int dfd = -1;
  g_autoptr(GVariant) meta = NULL;
  g_autoptr(GVariant) headers = NULL;
  g_autoptr(GVariant) metadata = NULL;
  g_autoptr(GVariant) fallback = NULL;
  g_autofree char *to_checksum = NULL;
  g_autofree char *from_checksum = NULL;
  g_autofree char *basename = NULL;

  dir_or_file_path = gs_file_get_path_cached (dir_or_file);

  /* First, try opening it as a directory */
  dfd = glnx_opendirat_with_errno (AT_FDCWD, dir_or_file_path, TRUE);
  if (dfd < 0)
    {
      if (errno != ENOTDIR)
        {
          glnx_set_error_from_errno (error);
          goto out;
        }
      else
        {
          g_autofree char *dir = dirname (g_strdup (dir_or_file_path));
          basename = g_path_get_basename (dir_or_file_path);

          if (!glnx_opendirat (AT_FDCWD, dir, TRUE, &dfd, error))
            goto out;
        }
    }
  else
    basename = g_strdup ("superblock");

  meta_fd = openat (dfd, basename, O_RDONLY | O_CLOEXEC);
  if (meta_fd < 0)
    {
      glnx_set_error_from_errno (error);
      goto out;
    }
  
  if (!ot_util_variant_map_fd (meta_fd, 0, G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT),
                               FALSE, &meta, error))
    goto out;

  /* Parsing OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */

  metadata = g_variant_get_child_value (meta, 0);

  /* Write the to-commit object */
  {
    g_autoptr(GVariant) to_csum_v = NULL;
    g_autoptr(GVariant) from_csum_v = NULL;
    g_autoptr(GVariant) to_commit = NULL;
    gboolean have_to_commit;
    gboolean have_from_commit;

    to_csum_v = g_variant_get_child_value (meta, 3);
    if (!ostree_validate_structureof_csum_v (to_csum_v, error))
      goto out;
    to_checksum = ostree_checksum_from_bytes_v (to_csum_v);

    from_csum_v = g_variant_get_child_value (meta, 2);
    if (g_variant_n_children (from_csum_v) > 0)
      {
        if (!ostree_validate_structureof_csum_v (from_csum_v, error))
          goto out;
        from_checksum = ostree_checksum_from_bytes_v (from_csum_v);

        if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT, from_checksum,
                                     &have_from_commit, cancellable, error))
          goto out;

        if (!have_from_commit)
          {
            g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                         "Commit %s, which is the delta source, is not in repository", from_checksum);
            goto out;
          }
      }

    if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT, to_checksum,
                                 &have_to_commit, cancellable, error))
      goto out;
    
    if (!have_to_commit)
      {
        g_autofree char *detached_path = _ostree_get_relative_static_delta_path (from_checksum, to_checksum, "commitmeta");
        g_autoptr(GVariant) detached_data = NULL;

        detached_data = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE("a{sv}"));
        if (detached_data && !ostree_repo_write_commit_detached_metadata (self,
                                                                          to_checksum,
                                                                          detached_data,
                                                                          cancellable,
                                                                          error))
          goto out;

        to_commit = g_variant_get_child_value (meta, 4);
        if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT,
                                         to_checksum, to_commit, NULL,
                                         cancellable, error))
          goto out;
      }
  }

  fallback = g_variant_get_child_value (meta, 7);
  if (g_variant_n_children (fallback) > 0)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Cannot execute delta offline: contains nonempty http fallback entries");
      goto out;
    }

  headers = g_variant_get_child_value (meta, 6);
  n = g_variant_n_children (headers);
  for (i = 0; i < n; i++)
    {
      guint32 version;
      guint64 size;
      guint64 usize;
      const guchar *csum;
      char checksum[OSTREE_SHA256_STRING_LEN+1];
      gboolean have_all;
      g_autoptr(GInputStream) part_in = NULL;
      g_autoptr(GVariant) inline_part_data = NULL;
      g_autoptr(GVariant) header = NULL;
      g_autoptr(GVariant) csum_v = NULL;
      g_autoptr(GVariant) objects = NULL;
      g_autoptr(GVariant) part = NULL;
      g_autofree char *deltapart_path = NULL;
      OstreeStaticDeltaOpenFlags delta_open_flags = 
        skip_validation ? OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM : 0;

      header = g_variant_get_child_value (headers, i);
      g_variant_get (header, "(u@aytt@ay)", &version, &csum_v, &size, &usize, &objects);

      if (version > OSTREE_DELTAPART_VERSION)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Delta part has too new version %u", version);
          goto out;
        }

      if (!_ostree_repo_static_delta_part_have_all_objects (self, objects, &have_all,
                                                            cancellable, error))
        goto out;

      /* If we already have these objects, don't bother executing the
       * static delta.
       */
      if (have_all)
        continue;

      csum = ostree_checksum_bytes_peek_validate (csum_v, error);
      if (!csum)
        goto out;
      ostree_checksum_inplace_from_bytes (csum, checksum);

      deltapart_path =
        _ostree_get_relative_static_delta_part_path (from_checksum, to_checksum, i);

      inline_part_data = g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE("(yay)"));
      if (inline_part_data)
        {
          g_autoptr(GBytes) inline_part_bytes = g_variant_get_data_as_bytes (inline_part_data);
          part_in = g_memory_input_stream_new_from_bytes (inline_part_bytes);

          /* For inline parts, we don't checksum, because it's
           * included with the metadata, so we're not trying to
           * protect against MITM or such.  Non-security related
           * checksums should be done at the underlying storage layer.
           */
          delta_open_flags |= OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM;

          if (!_ostree_static_delta_part_open (part_in, inline_part_bytes, 
                                               delta_open_flags,
                                               NULL,
                                               &part,
                                               cancellable, error))
            goto out;
        }
      else
        {
          g_autofree char *relpath = g_strdup_printf ("%u", i); /* TODO avoid malloc here */
          glnx_fd_close int part_fd = openat (dfd, relpath, O_RDONLY | O_CLOEXEC);
          if (part_fd < 0)
            {
              glnx_set_error_from_errno (error);
              g_prefix_error (error, "Opening deltapart '%s': ", deltapart_path);
              goto out;
            }

          part_in = g_unix_input_stream_new (part_fd, FALSE);

          if (!_ostree_static_delta_part_open (part_in, NULL, 
                                               delta_open_flags,
                                               checksum,
                                               &part,
                                               cancellable, error))
            goto out;
        }

      if (!_ostree_static_delta_part_execute (self, objects, part, skip_validation,
                                              NULL, cancellable, error))
        {
          g_prefix_error (error, "Executing delta part %i: ", i);
          goto out;
        }
    }

  ret = TRUE;
 out:
  return ret;
}