Пример #1
0
static const gchar *lookup(GVariant *dictionary, const gchar *lookup_key, const gchar *default_value)
{
    GVariantIter dictionary_iter;
    g_variant_iter_init(&dictionary_iter, dictionary);
    const char *key = NULL;
    GVariant *value = NULL;
    while (g_variant_iter_loop(&dictionary_iter, "{s@v}", &key, &value)) {
        if(strcmp(key, lookup_key) != 0)
            continue;
        GVariant *unboxed = g_variant_get_variant(value);
        if(strcmp(g_variant_get_type_string(unboxed), "s") == 0) {
            return g_variant_get_string(unboxed, NULL);
        } else if(strcmp(g_variant_get_type_string(unboxed), "ay") != 0) {
            return g_variant_print(unboxed, FALSE);
        } else if(g_variant_n_children(unboxed) < 256) { // skip preview
            gchar *buffer = (gchar *)malloc(256+1);
            int i=0;
            guchar c;
            GVariantIter char_iter;
            g_variant_iter_init(&char_iter, unboxed);
            while (g_variant_iter_loop(&char_iter, "y", &c)) {
                buffer[i] = c;
                ++i;
            }
            buffer[i] = 0;
            return buffer;
        }
    }
    return default_value;
}
Пример #2
0
static gboolean
gkd_secret_item_skeleton_set_property_dbus (GDBusConnection *connection,
					    const gchar *sender,
					    const gchar *object_path,
					    const gchar *interface_name,
					    const gchar *property_name,
					    GVariant *value,
					    GError **error,
					    gpointer user_data)
{
	GkdSecretItemSkeleton *self = (GkdSecretItemSkeleton *) user_data;
	GckObject *object;

	object = secret_objects_lookup_gck_object_for_path (self->objects, sender, object_path, error);
	if (!object)
		return FALSE;

	if (!object_property_set (self->objects, object, property_name, value, error)) {
		g_object_unref (object);
		return FALSE;
	}

	if (g_strcmp0 (property_name, "Attributes") == 0) {
		gkd_exported_item_set_attributes (GKD_EXPORTED_ITEM (self),
						  g_variant_get_variant (value));
	} else if (g_strcmp0 (property_name, "Label") == 0) {
		gkd_exported_item_set_label (GKD_EXPORTED_ITEM (self),
					     g_variant_get_string (value, NULL));
	}

	gkd_secret_objects_emit_item_changed (self->objects, object);
	g_object_unref (object);

	return TRUE;
}
Пример #3
0
static void
bluez_handle_disconnect(GDBusConnection       *connection,
                    const gchar           *sender,
                    const gchar           *object_path,
                    const gchar           *interface_name,
                    const gchar           *signal_name,
                    GVariant              *parameters,
                    gpointer               user_data)
{
    // check if parameter is valid and is the parameter we were looking for
    if( !(g_variant_type_equal(g_variant_get_type(parameters), "(sv)") &&
          g_variant_n_children(parameters) == 2) )
        return;

    GVariant* name = g_variant_get_child_value(parameters, 0);
    GVariant* value = g_variant_get_variant(g_variant_get_child_value(parameters, 1));

    if( !(g_strcmp0(g_variant_get_string(name, NULL), "Connected") == 0 &&
          g_variant_type_equal(g_variant_get_type(value), G_VARIANT_TYPE_BOOLEAN) ) )
        return;

    gboolean connected = g_variant_get_boolean(value);
    g_printf("Connected: %d\n", connected);

    if(!connected)
    {
        gchar* device_path = (gchar*)user_data;
        gchar* service_path = g_strconcat(device_path, "/service0007", NULL);

        bluez_unregister_watcher(connection, service_path);
        bluez_register_watcher(connection, service_path);
    }
}
gboolean connman_manager_update_technologies (ConnmanManager *manager)
{
  GVariant *props = connman_manager_get_properties(manager);
  gsize i;
  
  for (i = 0; i < g_variant_n_children(props); i++)
    {
      GVariant *prop = g_variant_get_child_value(props, i);
      GVariant *key_v = g_variant_get_child_value(prop, 0);
      const gchar *key = g_variant_get_string(key_v, NULL);

      if (g_str_equal(key, "Technologies"))
        {
          GVariant *v = g_variant_get_child_value(prop, 1);
          GVariant *array = g_variant_get_variant(v);
          gsize j;

          for (j = 0; j <  g_variant_n_children(array); j++)
            {
              GVariant *item = g_variant_get_child_value(array, j);
              const gchar *path = g_variant_get_string(item, NULL);
              ConnmanTechnology *technology;
             
              technology = connman_technology_new(manager->bus_type, path);
              manager->technologies = g_slist_append(manager->technologies,
                                                     technology);
            }
        }
    }

  return TRUE;
}
Пример #5
0
unsigned char bluez_characteristic_extract_value(GVariant* variant)
{
    GVariant* var_array = g_variant_get_child_value(variant, 0);

    for(unsigned int i = 0; i < g_variant_n_children(var_array); i++)
    {
        GVariant* var_child = g_variant_get_child_value(var_array, i);

        if(g_variant_n_children(var_child) == 2)
        {
            GVariant* var_id = g_variant_get_child_value(var_child, 0);

            if(g_variant_type_equal(g_variant_get_type(var_id), G_VARIANT_TYPE_STRING) &&
               g_strcmp0(g_variant_get_string(var_id, NULL), "Value") == 0)
            {
                GVariant* inner_var = g_variant_get_child_value(var_child, 1);

                if( g_variant_type_equal(g_variant_get_type(inner_var), G_VARIANT_TYPE_VARIANT) )
                {
                    GVariant* var_value = g_variant_get_variant(inner_var);
                    if( g_variant_type_equal(g_variant_get_type(var_value), G_VARIANT_TYPE_BYTESTRING) )
                    {
                        GVariant* var_byte = g_variant_get_child_value(var_value, 0);
                        return g_variant_get_byte(var_byte);
                    }
                }
            }
        }

        g_variant_unref(var_child);
    }

    return 0;
}
Пример #6
0
GVariant *
g_variant_lookup_value (GVariant           *dictionary,
                        const gchar        *key,
                        const GVariantType *expected_type)
{
  GVariantIter iter;
  GVariant *entry;
  GVariant *value;

  g_return_val_if_fail (g_variant_is_of_type (dictionary,
                                              G_VARIANT_TYPE ("a{s*}")) ||
                        g_variant_is_of_type (dictionary,
                                              G_VARIANT_TYPE ("a{o*}")),
                        NULL);

  g_variant_iter_init (&iter, dictionary);

  while ((entry = g_variant_iter_next_value (&iter)))
    {
      GVariant *entry_key;
      gboolean matches;

      entry_key = g_variant_get_child_value (entry, 0);
      matches = strcmp (g_variant_get_string (entry_key, NULL), key) == 0;
      g_variant_unref (entry_key);

      if (matches)
        break;

      g_variant_unref (entry);
    }

  if (entry == NULL)
    return NULL;

  value = g_variant_get_child_value (entry, 1);
  g_variant_unref (entry);

  if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT))
    {
      GVariant *tmp;

      tmp = g_variant_get_variant (value);
      g_variant_unref (value);

      if (expected_type && !g_variant_is_of_type (tmp, expected_type))
        {
          g_variant_unref (tmp);
          tmp = NULL;
        }

      value = tmp;
    }

  g_return_val_if_fail (expected_type == NULL || value == NULL ||
                        g_variant_is_of_type (value, expected_type), NULL);

  return value;
}
ConnmanService *connman_service_new(GVariant *variant)
{
  ConnmanService *service = g_object_new(CONNMAN_TYPE_SERVICE, NULL);
  GVariant *child = g_variant_get_child_value(variant, 0);
  GVariant *attrs;
  gsize i;

  service->object_path = g_variant_dup_string(child, NULL);
  attrs = g_variant_get_child_value(variant, 1);

  for (i = 0; i < g_variant_n_children(attrs); i++)
    {
      GVariant *attr = g_variant_get_child_value(attrs, i);
      GVariant *key_v = g_variant_get_child_value(attr, 0);
      GVariant *val_v = g_variant_get_child_value(attr, 1);
      GVariant *val = g_variant_get_variant(val_v);
      const gchar *key = g_variant_get_string(key_v, NULL);

      if (g_str_equal(key, "Name"))
        service->name =  g_variant_dup_string(val, NULL);

      if (g_str_equal(key, "Type"))
        {
          const gchar *v = g_variant_get_string(val, NULL);
          
          if (g_str_equal(v, "wifi"))
            service->type = CONNMAN_SERVICE_TYPE_WIFI;
          
          if (g_str_equal(v, "ethernet"))
            service->type = CONNMAN_SERVICE_TYPE_ETHERNET;
        }

      if (g_str_equal(key, "LoginRequired"))
        service->login_required = g_variant_get_boolean(val);

      if (g_str_equal(key, "PassphraseRequired"))
        service->passphrase_required = g_variant_get_boolean(val);

      if (g_str_equal(key, "AutoConnect"))
        service->auto_connect = g_variant_get_boolean(val);
      
      if (g_str_equal(key, "Immutable"))
        service->immutable = g_variant_get_boolean(val);
      
      if (g_str_equal(key, "Favorite"))
        service->favorite = g_variant_get_boolean(val);
      
      if (g_str_equal(key, "Strength"))
        service->strength = g_variant_get_byte(val);
    }

  g_message("new service %p: '%s' (%d)", service, service->name, service->type);

  return service;
}
Пример #8
0
static void assign_current_cellular_service(struct ofono_wan_data *od, const gchar *path, GVariant *properties)
{
	GVariant *property = 0, *prop_name = 0, *prop_value = 0;
	gsize n = 0;
	const gchar *name = 0;
	bool favorite = false;

	if (!path) {
		if (od->current_service_watch)
			g_signal_handler_disconnect(od->current_service_proxy,
								od->current_service_watch);

		if (od->current_service_proxy)
			g_object_unref(od->current_service_proxy);


		od->current_service_path = NULL;
		od->current_service_proxy = 0;
		od->current_service_watch = 0;

		return;
	}

	od->current_service_path = g_strdup(path);

	od->current_service_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
															  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
															  NULL, "net.connman",
															  path, "net.connman.Service",
															  NULL, NULL);

	od->current_service_watch = g_signal_connect(od->current_service_proxy, "g-signal",
												 G_CALLBACK(current_service_signal_cb), od);

	for (n = 0; n < g_variant_n_children(properties); n++) {
		property = g_variant_get_child_value(properties, n);

		prop_name = g_variant_get_child_value(property, 0);
		prop_value = g_variant_get_child_value(property, 1);

		name = g_variant_get_string(prop_name, NULL);

		if (g_strcmp0(name, "Favorite") == 0) {
			favorite = g_variant_get_boolean(g_variant_get_variant(prop_value));

			if (!favorite) {
				g_message("[WAN] Found a not yet configured cellular service; connecting to it for the first time");
				switch_current_service_state(od, true, cellular_service_setup_cb, od);
			}
		}

		handle_current_service_property(od, name, prop_value);
	}
}
Пример #9
0
void
prop_set_from_tuple(GVariant *v, prop_t *parent)
{
  const char *key =
    g_variant_get_string(g_variant_get_child_value(v, 0), NULL);
  GVariant *value = g_variant_get_variant(g_variant_get_child_value(v, 1));

  char *k = mystrdupa(key);
  fixup_title(k);
  prop_set_from_gvariant(value, prop_create(parent, k));
}
void connman_service_update_properties(connman_service_t *service, GVariant *properties)
{
	if(NULL == service || NULL == properties)
		return;

	gsize i;
	
	for (i = 0; i < g_variant_n_children(properties); i++)
	{
		GVariant *property = g_variant_get_child_value(properties, i);
		GVariant *key_v = g_variant_get_child_value(property, 0);
		GVariant *val_v = g_variant_get_child_value(property, 1);
		GVariant *val = g_variant_get_variant(val_v);
		const gchar *key = g_variant_get_string(key_v, NULL);
		if (g_str_equal(key, "Name"))
		{
			g_free(service->name);
			service->name =  g_variant_dup_string(val, NULL);
		}
		else if (g_str_equal(key, "Type"))
		{
			const gchar *v = g_variant_get_string(val, NULL);

			if (g_str_equal(v, "wifi"))
				service->type = CONNMAN_SERVICE_TYPE_WIFI;

			if (g_str_equal(v, "ethernet"))
				service->type = CONNMAN_SERVICE_TYPE_ETHERNET;
		}
		else if (g_str_equal(key, "State"))
		{
			g_free(service->state);
			service->state =  g_variant_dup_string(val, NULL);
			// Only a hidden service gets added as a new service with "association" state
			if(g_str_equal(service->state, "association"))
				service->hidden = TRUE;
		}
		else if (g_str_equal(key, "Strength"))
			service->strength = g_variant_get_byte(val);
		else if(g_str_equal(key, "Security"))
		{
			g_strfreev(service->security);
			service->security = g_variant_dup_strv(val, NULL);
		}
		else if (g_str_equal(key, "AutoConnect"))
			service->auto_connect = g_variant_get_boolean(val);
		else if (g_str_equal(key, "Immutable"))
			service->immutable = g_variant_get_boolean(val);
		else if (g_str_equal(key, "Favorite"))
			service->favorite = g_variant_get_boolean(val);
	}
}
static void
property_changed_cb(ConnmanInterfaceService *proxy, gchar * property, GVariant *v,
              connman_service_t      *service)
{
	/* Invoke function pointers only for state changed */
	if(g_str_equal(property, "State") == FALSE)
		return;
	g_free(service->state);
	service->state = g_variant_dup_string(g_variant_get_variant(v), NULL);

	if(NULL != service->handle_state_change_fn)
		(service->handle_state_change_fn)((gpointer)service, service->state);
}
Пример #12
0
static void
build_json_variant (JsonBuilder *builder,
                    GVariant *value)
{
  GVariant *child;

  child = g_variant_get_variant (value);
  json_builder_begin_object (builder);

  build_json_with_sig (builder, child);

  json_builder_end_object (builder);
  g_variant_unref (child);
}
QVariant gvariantToQVariant(GVariant *value)
{
	GVariantClass c = g_variant_classify(value);
	if(c == G_VARIANT_CLASS_BOOLEAN)
		return QVariant((bool) g_variant_get_boolean(value));

	else if(c == G_VARIANT_CLASS_BYTE)
		return QVariant((char) g_variant_get_byte(value));

	else if(c == G_VARIANT_CLASS_INT16)
		return QVariant((int) g_variant_get_int16(value));

	else if(c == G_VARIANT_CLASS_UINT16)
		return QVariant((unsigned int) g_variant_get_uint16(value));

	else if(c == G_VARIANT_CLASS_INT32)
		return QVariant((int) g_variant_get_int32(value));

	else if(c ==  G_VARIANT_CLASS_UINT32)
		return QVariant((unsigned int) g_variant_get_uint32(value));

	else if(c == G_VARIANT_CLASS_INT64)
		return QVariant((long long) g_variant_get_int64(value));

	else if(c == G_VARIANT_CLASS_UINT64)
		return QVariant((unsigned long long) g_variant_get_uint64(value));

	else if(c == G_VARIANT_CLASS_DOUBLE)
		return QVariant(g_variant_get_double(value));

	else if(c == G_VARIANT_CLASS_STRING)
		return QVariant(g_variant_get_string(value, NULL));

	else if(c == G_VARIANT_CLASS_ARRAY)
	{
		gsize dictsize = g_variant_n_children(value);
		QVariantList list;
		for (int i=0;i<dictsize;i++)
		{
			GVariant *childvariant = g_variant_get_child_value(value,i);
			GVariant *innervariant = g_variant_get_variant(childvariant);
			list.append(gvariantToQVariant(innervariant));
		}
		return list;
	}

	else
		return QVariant::Invalid;

}
static void on_response_sap_transfer_apdu(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
	GError *error = NULL;
	GDBusConnection *conn = NULL;
	GVariant *dbus_result;

	GVariantIter *iter = NULL;
	GVariant *param_gv = NULL;
	GVariant *inner_gv = NULL;
	guchar rt_i;
	int i = 0;

	struct tapi_resp_data *evt_cb_data = user_data;
	TelSimSapResultCode_t result = TAPI_SIM_SAP_RESULT_CODE_OK;
	TelSapApduData_t r_apdu;

	dbg("Func Entrance");
	memset(&r_apdu, 0, sizeof(TelSapApduData_t));

	conn = G_DBUS_CONNECTION (source_object);
	dbus_result = g_dbus_connection_call_finish(conn, res, &error);

	if (dbus_result) {
		/*	dbg("dbus_result type_format(%s)", g_variant_get_type_string(dbus_result));*/
		g_variant_get(dbus_result, "(i@v)", &result, &param_gv);
		inner_gv = g_variant_get_variant(param_gv);

		g_variant_get(inner_gv, "ay", &iter);
		while (g_variant_iter_loop(iter, "y", &rt_i)) {
			r_apdu.apdu_data[i] = rt_i;
			i++;
		}
		r_apdu.apdu_len = (int) i;
		g_variant_iter_free(iter);
		g_variant_unref(inner_gv);
		g_variant_unref(param_gv);
		/*		for(i=0; i < (int)r_apdu.apdu_len; i++)
		 dbg("apdu[%d][0x%02x]",i, r_apdu.apdu_data[i]);*/
	}
	else {
		result = TAPI_SIM_SAP_RESULT_CODE_DATA_NOT_AVAILABLE;
		dbg( "g_dbus_conn failed. error (%s)", error->message);
		g_error_free(error);
	}
	if (evt_cb_data->cb_fn) {
		evt_cb_data->cb_fn(evt_cb_data->handle, result, (void*)&r_apdu, evt_cb_data->user_data);
	}

	free(evt_cb_data);
}
Пример #15
0
glib::Variant get_variant(GVariant *variant_)
{
  Variant value;

  if (!variant_)
    return value;

  if (g_variant_is_of_type(variant_, G_VARIANT_TYPE_VARIANT))
  {
    value = Variant(g_variant_get_variant(variant_), StealRef());
  }
  else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE("(v)")))
  {
    g_variant_get(variant_, "(v)", &value);
  }

  return value;
}
Пример #16
0
static void handle_current_service_property(struct ofono_wan_data *od, const gchar *name, GVariant *value)
{
	GVariant *state_v = 0;
	const gchar *state = 0;
	gboolean wan_disable_before = od->wan_disabled;

	if (g_strcmp0(name, "State") == 0) {
		state_v = g_variant_get_variant(value);
		state = g_variant_get_string(state_v, NULL);

		if (g_strcmp0(state, "ready") == 0 || g_strcmp0(state, "online") == 0)
			od->wan_disabled = FALSE;
		else
			od->wan_disabled = TRUE;

		g_variant_unref(state_v);
	}

	if (od->wan_disabled != wan_disable_before)
		send_status_update_cb(od);
}
Пример #17
0
gboolean connman_manager_is_online (ConnmanManager *manager)
{
  GVariant *props = connman_manager_get_properties(manager);
  gsize i;
  
  for (i = 0; i < g_variant_n_children(props); i++)
    {
      GVariant *prop = g_variant_get_child_value(props, i);
      GVariant *key_v = g_variant_get_child_value(prop, 0);
      const gchar *key = g_variant_get_string(key_v, NULL);

      if (g_str_equal(key, "OfflineMode"))
        {
          GVariant *v = g_variant_get_child_value(prop, 1);
          GVariant *va = g_variant_get_variant(v);
          gboolean offline = g_variant_get_boolean(va);

          return !offline;
        }
    }

  return FALSE;
}
Пример #18
0
static gboolean
service_method_open_session (GkdExportedService *skeleton,
			     GDBusMethodInvocation *invocation,
			     gchar *algorithm,
			     GVariant *input,
			     GkdSecretService *self)
{
	GkdSecretSession *session;
	GVariant *output = NULL;
	gchar *result = NULL;
	GError *error = NULL;
	const gchar *caller;
	GVariant *input_payload;

	caller = g_dbus_method_invocation_get_sender (invocation);

	/* Now we can create a session with this information */
	session = gkd_secret_session_new (self, caller);
	input_payload = g_variant_get_variant (input);
	gkd_secret_session_handle_open (session, algorithm, input_payload,
					&output, &result,
					&error);
	g_variant_unref (input_payload);

	if (error != NULL) {
		g_dbus_method_invocation_take_error (invocation, error);
	} else {
		gkd_secret_service_publish_dispatch (self, caller,
						     GKD_SECRET_DISPATCH (session));
		gkd_exported_service_complete_open_session (skeleton, invocation, output, result);
		g_free (result);
	}

	g_object_unref (session);
	return TRUE;
}
Пример #19
0
/*****************************************************************************
 * neardal_adp_prv_cb_property_changed: Callback called when a NFC tag
 * is found
 ****************************************************************************/
static void neardal_adp_prv_cb_property_changed(OrgNeardAdapter *proxy,
						const gchar *arg_unnamed_arg0,
						GVariant *arg_unnamed_arg1,
						void        *user_data)
{
	AdpProp		*adpProp	= NULL;
	errorCode_t	err		= NEARDAL_ERROR_NO_TAG;
	char		*dbusObjPath	= NULL;
	void		*clientValue	= NULL;
	TagProp		*tagProp	= NULL;
	DevProp		*devProp	= NULL;
	gchar		**array		= NULL;
	GVariant	*gvalue		= NULL;
	gsize		mode_len;

	(void) proxy; /* remove warning */
	(void) user_data; /* remove warning */
	NEARDAL_TRACEIN();
	NEARDAL_ASSERT(arg_unnamed_arg0 != NULL);

	neardal_mgr_prv_get_adapter_from_proxy(proxy, &adpProp);
	if (adpProp == NULL) {
		err = NEARDAL_ERROR_GENERAL_ERROR;
		goto exit;
	}

	gvalue = g_variant_get_variant(arg_unnamed_arg1);
	if (gvalue == NULL) {
		err = NEARDAL_ERROR_GENERAL_ERROR;
		goto exit;
	}

	NEARDAL_TRACEF(" arg_unnamed_arg0 : %s\n", arg_unnamed_arg0);

	if (!strcmp(arg_unnamed_arg0, "Mode")) {
		if (adpProp->mode != NULL) {
			g_free(adpProp->mode);
			adpProp->mode = NULL;
		}

		adpProp->mode = g_strdup(g_variant_get_string(gvalue, &mode_len));
		clientValue = adpProp->mode;
		NEARDAL_TRACEF("neardalMgr.mode=%s\n", adpProp->mode);
	}

	if (!strcmp(arg_unnamed_arg0, "Polling")) {
		adpProp->polling = g_variant_get_boolean(gvalue);
		clientValue = GUINT_TO_POINTER(adpProp->polling);
		NEARDAL_TRACEF("neardalMgr.polling=%d\n", adpProp->polling);
	}

	if (!strcmp(arg_unnamed_arg0, "Powered")) {
		adpProp->powered = g_variant_get_boolean(gvalue);
		clientValue = GINT_TO_POINTER(adpProp->powered);
		NEARDAL_TRACEF("neardalMgr.powered=%d\n", adpProp->powered);
	}

	if (!strcmp(arg_unnamed_arg0, "Tags")) {
		gsize tmpLen;

		array = g_variant_dup_objv(gvalue, &tmpLen);
		adpProp->tagNb = tmpLen;
		if (adpProp->tagNb <= 0) {	/* Remove all tags */
			GList *node = NULL;
			NEARDAL_TRACEF(
				"Tag array empty! Removing all tags\n");
			while (g_list_length(adpProp->tagList)) {
				node = g_list_first(adpProp->tagList);
				tagProp = (TagProp *) node->data;
				neardal_adp_prv_cb_tag_lost(tagProp->proxy,
							       tagProp->name,
							       tagProp->parent);
			}
			g_strfreev(array);

			err = NEARDAL_SUCCESS;
			goto exit;
		}

		/* Extract the tags arrays List from the GValue */
		err = NEARDAL_ERROR_NO_ADAPTER;
		tmpLen = 0;
		while (tmpLen < adpProp->tagNb) {
			/* Getting last tag (tags list not updated with
			 * tags lost */
			dbusObjPath = g_strdup(array[tmpLen++]);

			/* TODO : for Neard Workaround, emulate 'TagFound'
			 * signals */
			err = neardal_adp_prv_get_tag(adpProp,
							     dbusObjPath,
							     &tagProp);
			clientValue = dbusObjPath;
			if (err == NEARDAL_ERROR_NO_TAG) {
				neardal_adp_prv_cb_tag_found(NULL,
								dbusObjPath,
								adpProp);
				err = NEARDAL_SUCCESS;
			}
		}
		g_strfreev(array);
		array = NULL;
	}

	if (!strcmp(arg_unnamed_arg0, "Devices")) {
		gsize tmpLen;

		array = g_variant_dup_objv(gvalue, &tmpLen);
		adpProp->devNb = tmpLen;
		if (adpProp->devNb <= 0) {	/* Remove all devs */
			GList *node = NULL;
			NEARDAL_TRACEF(
				"Dev array empty! Removing all devs\n");
			while (g_list_length(adpProp->devList)) {
				node = g_list_first(adpProp->devList);
				devProp = (DevProp *) node->data;
				neardal_adp_prv_cb_dev_lost(NULL,
							       devProp->name,
							       devProp->parent);
			}
			g_strfreev(array);

			err = NEARDAL_SUCCESS;
			goto exit;
		}

		/* Extract the devs arrays List from the GValue */
		err = NEARDAL_ERROR_NO_ADAPTER;
		tmpLen = 0;
		while (tmpLen < adpProp->devNb) {
			/* Getting last dev (devs list not updated with
			 * devs lost */
			dbusObjPath = g_strdup(array[tmpLen++]);

			/* TODO : for Neard Workaround, emulate 'DevFound'
			 * signals */
			err = neardal_adp_prv_get_dev(adpProp,
						      dbusObjPath,
						      &devProp);
			if (err == NEARDAL_ERROR_NO_DEV) {
				clientValue = dbusObjPath;
				neardal_adp_prv_cb_dev_found(NULL,
							     dbusObjPath,
							     adpProp);
				err = NEARDAL_SUCCESS;
			}
		}
		g_strfreev(array);
		array = NULL;
	}

	if (neardalMgr.cb.adp_prop_changed != NULL)
		(neardalMgr.cb.adp_prop_changed)(adpProp->name,
						  (char *) arg_unnamed_arg0,
						  clientValue,
					neardalMgr.cb.adp_prop_changed_ud);
	return;

exit:
	if (err != NEARDAL_SUCCESS)
		NEARDAL_TRACEF("Exit with error code %d:%s\n", err,
			      neardal_error_get_text(err));
	return;
}
gboolean connman_service_get_ipinfo(connman_service_t *service)
{
	if(NULL == service)
		return FALSE;

	GError *error = NULL;
	GVariant *properties;
	gsize i;

	connman_interface_service_call_get_properties_sync(service->remote, &properties, NULL, &error);
	if (error)
	{
		WCA_LOG_CRITICAL("Error: %s", error->message);
		g_error_free(error);
		return FALSE;
	}

	for (i = 0; i < g_variant_n_children(properties); i++)
	{
		GVariant *property = g_variant_get_child_value(properties, i);
		GVariant *key_v = g_variant_get_child_value(property, 0);
		const gchar *key = g_variant_get_string(key_v, NULL);

		if (g_str_equal(key, "Ethernet"))
		{
			GVariant *v = g_variant_get_child_value(property, 1);
			GVariant *va = g_variant_get_child_value(v, 0);
			gsize j;
			for(j = 0; j < g_variant_n_children(va); j++)
	  		{
				GVariant *ethernet = g_variant_get_child_value(va, j);
				GVariant *ekey_v = g_variant_get_child_value(ethernet, 0);
				const gchar *ekey = g_variant_get_string(ekey_v, NULL);

				if(g_str_equal(ekey, "Interface"))
				{
					GVariant *ifacev = g_variant_get_child_value(ethernet, 1);
					GVariant *ifaceva = g_variant_get_variant(ifacev);
					g_free(service->ipinfo.iface);
					service->ipinfo.iface = g_variant_dup_string(ifaceva, NULL);
				}
	  		}
		}
		if(g_str_equal(key, "IPv4"))
		{
			GVariant *v = g_variant_get_child_value(property, 1);
			GVariant *va = g_variant_get_child_value(v, 0);
			gsize j;
			for(j = 0; j < g_variant_n_children(va); j++)
			{
				GVariant *ipv4 = g_variant_get_child_value(va, j);
				GVariant *ikey_v = g_variant_get_child_value(ipv4, 0);
				const gchar *ikey = g_variant_get_string(ikey_v, NULL);
				if(g_str_equal(ikey, "Method"))
				{
					GVariant *netmaskv = g_variant_get_child_value(ipv4, 1);
					GVariant *netmaskva = g_variant_get_variant(netmaskv);
					g_free(service->ipinfo.ipv4.method);
					service->ipinfo.ipv4.method = g_variant_dup_string(netmaskva, NULL);
				}
				if(g_str_equal(ikey, "Netmask"))
				{
					GVariant *netmaskv = g_variant_get_child_value(ipv4, 1);
					GVariant *netmaskva = g_variant_get_variant(netmaskv);
					g_free(service->ipinfo.ipv4.netmask);
					service->ipinfo.ipv4.netmask = g_variant_dup_string(netmaskva, NULL);
				}
				if(g_str_equal(ikey, "Address"))
				{
					GVariant *addressv = g_variant_get_child_value(ipv4, 1);
					GVariant *addressva = g_variant_get_variant(addressv);
					g_free(service->ipinfo.ipv4.address);
					service->ipinfo.ipv4.address = g_variant_dup_string(addressva, NULL);
				}
				if(g_str_equal(ikey, "Gateway"))
				{
					GVariant *gatewayv = g_variant_get_child_value(ipv4, 1);
					GVariant *gatewayva = g_variant_get_variant(gatewayv);
					g_free(service->ipinfo.ipv4.gateway);
					service->ipinfo.ipv4.gateway = g_variant_dup_string(gatewayva, NULL);
				}
			  }
			}
		if(g_str_equal(key, "Nameservers"))
		{
			GVariant *v = g_variant_get_child_value(property, 1);
			GVariant *va = g_variant_get_child_value(v, 0);
			g_strfreev(service->ipinfo.dns);
			service->ipinfo.dns = g_variant_dup_strv(va, NULL);
		}
	}
	return TRUE;
}
Пример #21
0
static JsonBuilder *
_json_builder_add_gvariant (JsonBuilder *builder,
                            GVariant *value)
{
  g_return_val_if_fail (JSON_IS_BUILDER (builder), builder);

  g_variant_ref_sink (value);

  switch (g_variant_classify (value))
    {
    case G_VARIANT_CLASS_BOOLEAN:
      json_builder_add_boolean_value (builder, g_variant_get_boolean (value));
      break;

    case G_VARIANT_CLASS_BYTE:
      json_builder_add_int_value (builder, g_variant_get_byte (value));
      break;

    case G_VARIANT_CLASS_INT16:
      json_builder_add_int_value (builder, g_variant_get_int16 (value));
      break;

    case G_VARIANT_CLASS_UINT16:
      json_builder_add_int_value (builder, g_variant_get_uint16 (value));
      break;

    case G_VARIANT_CLASS_INT32:
      json_builder_add_int_value (builder, g_variant_get_int32 (value));
      break;

    case G_VARIANT_CLASS_UINT32:
      json_builder_add_int_value (builder, g_variant_get_uint32 (value));
      break;

    case G_VARIANT_CLASS_INT64:
      json_builder_add_int_value (builder, g_variant_get_int64 (value));
      break;

    case G_VARIANT_CLASS_UINT64:
      json_builder_add_int_value (builder, g_variant_get_uint64 (value));
      break;

    case G_VARIANT_CLASS_HANDLE:
      json_builder_add_int_value (builder, g_variant_get_handle (value));
      break;

    case G_VARIANT_CLASS_DOUBLE:
      json_builder_add_double_value (builder, g_variant_get_double (value));
      break;

    case G_VARIANT_CLASS_STRING:      /* explicit fall-through */
    case G_VARIANT_CLASS_OBJECT_PATH: /* explicit fall-through */
    case G_VARIANT_CLASS_SIGNATURE:
      json_builder_add_string_value (builder, g_variant_get_string (value, NULL));
      break;

     /* TODO: */
    case G_VARIANT_CLASS_VARIANT:
      {
        GVariant *child;
        child = g_variant_get_variant (value);
        _json_builder_add_gvariant (builder, child);
        g_variant_unref (child);
      }
      break;

    case G_VARIANT_CLASS_MAYBE:
      g_assert_not_reached ();
      break;

    case G_VARIANT_CLASS_ARRAY:
      {
        const GVariantType *type;
        const GVariantType *element_type;

        type = g_variant_get_type (value);
        element_type = g_variant_type_element (type);
        if (g_variant_type_is_dict_entry (element_type))
          {
            GVariantIter iter;
            GVariant *child;

            json_builder_begin_object (builder);

            g_variant_iter_init (&iter, value);
            while ((child = g_variant_iter_next_value (&iter)) != NULL)
              {
                _json_builder_add_gvariant (builder, child);
                g_variant_unref (child);
              }

            json_builder_end_object (builder);
          }
        else
          {
            GVariantIter iter;
            GVariant *child;

            json_builder_begin_array (builder);

            g_variant_iter_init (&iter, value);
            while ((child = g_variant_iter_next_value (&iter)) != NULL)
              {
                _json_builder_add_gvariant (builder, child);
                g_variant_unref (child);
              }

            json_builder_end_array (builder);
          }
      }
      break;

    case G_VARIANT_CLASS_TUPLE:
      {
        GVariantIter iter;
        GVariant *child;

        json_builder_begin_array (builder);

        g_variant_iter_init (&iter, value);
        while ((child = g_variant_iter_next_value (&iter)) != NULL)
          {
            _json_builder_add_gvariant (builder, child);
            g_variant_unref (child);
          }

        json_builder_end_array (builder);
      }
      break;

    case G_VARIANT_CLASS_DICT_ENTRY:
      {
        GVariant *dict_key;
        GVariant *dict_value;
        gchar *dict_key_string;

        dict_key = g_variant_get_child_value (value, 0);
        dict_value = g_variant_get_child_value (value, 1);

        if (g_variant_is_of_type (dict_key, G_VARIANT_TYPE("s")))
          dict_key_string = g_variant_dup_string (dict_key, NULL);
        else
          dict_key_string = g_variant_print (dict_key, FALSE);

        json_builder_set_member_name (builder, dict_key_string);
        _json_builder_add_gvariant (builder, dict_value);
        g_free (dict_key_string);

        g_variant_unref (dict_key);
        g_variant_unref (dict_value);
      }
      break;
    }

  g_variant_unref (value);

  return builder;
}
Пример #22
0
static void property_changed_cb(void *object, const gchar *name, GVariant *value, gpointer user_data)
{
	struct ofono_base *base = user_data;

	base->funcs->update_property(name, g_variant_get_variant(value), base->user_data);
}
static gboolean
find_server (GVariant * varray, slmock_server_t * server)
{
	int ichild;
	for (ichild = 0; ichild < g_variant_n_children(varray); ichild++) {
		GVariant * child = g_variant_get_child_value(varray, ichild);
		gboolean test = FALSE;

		GVariant * type = g_variant_get_child_value(child, 0);
		test = g_strcmp0(g_variant_get_string(type, NULL), server->type) == 0;
		g_variant_unref(type);
		if (!test) {
			g_variant_unref(child);
			continue;
		}

		GVariant * name = g_variant_get_child_value(child, 1);
		test = g_strcmp0(g_variant_get_string(name, NULL), server->name) == 0;
		g_variant_unref(name);
		if (!test) {
			g_variant_unref(child);
			continue;
		}

		GVariant * uri = g_variant_get_child_value(child, 2);
		test = g_strcmp0(g_variant_get_string(uri, NULL), server->uri) == 0;
		g_variant_unref(uri);
		if (!test) {
			g_variant_unref(child);
			continue;
		}

		GVariant * last_used = g_variant_get_child_value(child, 3);
		test = g_variant_get_boolean(last_used) == server->last_used;
		g_variant_unref(last_used);
		if (!test) {
			g_variant_unref(child);
			continue;
		}

		gboolean match_username = FALSE;
		gboolean match_password = FALSE;
		gboolean match_domain = FALSE;

		GVariant * props = g_variant_get_child_value(child, 4);
		int iprop;
		for (iprop = 0; iprop < g_variant_n_children(props); iprop++) {
			GVariant * prop = g_variant_get_child_value(props, iprop);

			GVariant * prop_type = g_variant_get_child_value(prop, 0);
			GVariant * prop_value_wrap = g_variant_get_child_value(prop, 2);
			GVariant * prop_value = g_variant_get_variant(prop_value_wrap);

			if (g_strcmp0(g_variant_get_string(prop_type, NULL), "username") == 0) {
				if (g_strcmp0(g_variant_get_string(prop_value, NULL), server->username) == 0) {
					match_username = TRUE;
				}
			} else if (g_strcmp0(g_variant_get_string(prop_type, NULL), "password") == 0) {
				if (g_strcmp0(g_variant_get_string(prop_value, NULL), server->password) == 0) {
					match_password = TRUE;
				}
			} else if (g_strcmp0(g_variant_get_string(prop_type, NULL), "domain") == 0) {
				if (g_strcmp0(g_variant_get_string(prop_value, NULL), server->domain) == 0) {
					match_domain = TRUE;
				}
			}

			g_variant_unref(prop_value);
			g_variant_unref(prop_value_wrap);
			g_variant_unref(prop_type);
			g_variant_unref(prop);
		}
		g_variant_unref(props);

		g_variant_unref(child);

		if (match_username && match_password && match_domain) {
			return TRUE;
		} else {
			continue;
		}
	}

	return FALSE;
}
Пример #24
0
static gint64
arv_rtkit_get_int_property (GDBusConnection *connection, const char* propname, GError **error) {

	GDBusMessage *message;
	GDBusMessage *reply;
	GError *local_error = NULL;
	GVariant *body;
	GVariant *parameter;
	GVariant *variant;
	const GVariantType *variant_type;
	gint64 value;

	message = g_dbus_message_new_method_call (RTKIT_SERVICE_NAME,
						  RTKIT_OBJECT_PATH,
						  "org.freedesktop.DBus.Properties",
						  "Get");
	g_dbus_message_set_body (message, g_variant_new ("(ss)", "org.freedesktop.RealtimeKit1", propname));

	reply = g_dbus_connection_send_message_with_reply_sync (connection, message,
								G_DBUS_SEND_MESSAGE_FLAGS_NONE, 1000, NULL, NULL,
								&local_error);
	g_object_unref (message);

	if (local_error != NULL) {
		g_propagate_error (error, local_error);
		return 0;
	}

	if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
		local_error = g_error_new (ARV_RTKIT_ERROR, ARV_RTKIT_ERROR_PERMISSION_DENIED,
					   "%s", g_dbus_message_get_error_name (reply));
		g_propagate_error (error, local_error);
		g_object_unref (reply);
		return 0;
	}

	if (!g_variant_type_equal ("v", g_dbus_message_get_signature (reply))) {
		local_error = g_error_new (ARV_RTKIT_ERROR, ARV_RTKIT_ERROR_WRONG_REPLY,
					   "Invalid reply signature");
		g_propagate_error (error, local_error);
		g_object_unref (reply);
		return 0;
	}

	body = g_dbus_message_get_body (reply);
	parameter = g_variant_get_child_value (body, 0);
	variant = g_variant_get_variant (parameter);

	variant_type = g_variant_get_type (variant);

	if (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT32))
		value = g_variant_get_int32 (variant);
	else if (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT64))
		value = g_variant_get_int64 (variant);
	else
		value = 0;

	g_variant_unref (parameter);
	g_variant_unref (variant);
	g_object_unref (reply);

	return value;
}
Пример #25
0
JSValueRef dbus_to_js(JSContextRef ctx, GVariant *dbus)
{
    JSValueRef jsvalue = NULL;
    GVariantClass type = g_variant_classify(dbus);
    switch (type) {
        case G_VARIANT_CLASS_STRING:
        case G_VARIANT_CLASS_OBJECT_PATH:
        case G_VARIANT_CLASS_SIGNATURE:
            {
                JSStringRef js_string = JSStringCreateWithUTF8CString(g_variant_get_string(dbus, NULL));
                jsvalue = JSValueMakeString(ctx, js_string);
                JSStringRelease(js_string);
                return jsvalue;
            }
        case G_VARIANT_CLASS_BYTE:
            return JSValueMakeNumber(ctx, g_variant_get_byte(dbus));
        case G_VARIANT_CLASS_DOUBLE:
            return JSValueMakeNumber(ctx, g_variant_get_double(dbus));
        case G_VARIANT_CLASS_INT16:
            return JSValueMakeNumber(ctx, g_variant_get_int16(dbus));
        case G_VARIANT_CLASS_UINT16:
            return JSValueMakeNumber(ctx, g_variant_get_uint16(dbus));
        case G_VARIANT_CLASS_INT32:
            return JSValueMakeNumber(ctx, g_variant_get_int32(dbus));
        case G_VARIANT_CLASS_UINT32:
            return JSValueMakeNumber(ctx, g_variant_get_uint32(dbus));
        case G_VARIANT_CLASS_INT64:
            return JSValueMakeNumber(ctx, g_variant_get_int64(dbus));
        case G_VARIANT_CLASS_UINT64:
            return JSValueMakeNumber(ctx, g_variant_get_uint64(dbus));
        case G_VARIANT_CLASS_BOOLEAN:
            return JSValueMakeBoolean(ctx, g_variant_get_boolean(dbus));
        case G_VARIANT_CLASS_HANDLE:
            g_warning("didn't support FD type");
            return JSValueMakeNumber(ctx, g_variant_get_uint32(dbus));
        case G_VARIANT_CLASS_VARIANT:
            {
                GVariant* v = g_variant_get_variant(dbus);
                jsvalue = dbus_to_js(ctx, v);
                g_variant_unref(v);
                return jsvalue;
            }

        case G_VARIANT_CLASS_DICT_ENTRY:
            /*g_assert_not_reached();*/
            break;

        case G_VARIANT_CLASS_ARRAY:
            {
                if (g_variant_type_is_dict_entry(g_variant_type_element(g_variant_get_type(dbus)))) {
                    jsvalue = JSObjectMake(ctx, NULL, NULL);
                    for (size_t i=0; i<g_variant_n_children(dbus); i++) {
                        GVariant *dic = g_variant_get_child_value(dbus, i);
                        GVariant *key= g_variant_get_child_value (dic, 0);
                        GVariant *value = g_variant_get_child_value (dic, 1);

                        JSValueRef js_key = dbus_to_js(ctx, key);
                        JSValueRef js_value = dbus_to_js(ctx, value);

                        JSStringRef key_str = JSValueToStringCopy(ctx, js_key, NULL);
                        JSObjectSetProperty(ctx, (JSObjectRef)jsvalue, key_str, js_value, 0, NULL);
                        JSStringRelease(key_str);

                        g_variant_unref(key);
                        g_variant_unref(value);
                        g_variant_unref(dic);
                    }
                    return jsvalue;
                } else {
                    int n = g_variant_n_children(dbus);
                    JSValueRef *args = g_new(JSValueRef, n);
                    for (int i=0; i < n; i++) {
                        GVariant* v = g_variant_get_child_value(dbus, i);
                        args[i] = dbus_to_js(ctx, v);
                        g_variant_unref(v);
                    }
                    jsvalue = JSObjectMakeArray(ctx, n, args, NULL);
                    g_free(args);
                    return jsvalue;
                }
            }
        case G_VARIANT_CLASS_TUPLE:
            {
                int n = g_variant_n_children(dbus);
                jsvalue = JSObjectMakeArray(ctx, 0, NULL, NULL);
                for (int i=0; i < n; i++) {
                    GVariant* v = g_variant_get_child_value(dbus, i);
                    JSObjectSetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, dbus_to_js(ctx, v), NULL);
                    g_variant_unref(v);
                }
                return jsvalue;
            }
        case G_VARIANT_CLASS_MAYBE:
            g_assert_not_reached();
    }
    g_warning("didn't support signature type:%c", type);
    return JSValueMakeUndefined(ctx);
}
Пример #26
0
int
main (int    argc,
      char **argv)
{
  GError *local_error = NULL;
  GError **error = NULL;
  GCancellable *cancellable = NULL;
  gs_unref_variant GVariant *user_list = NULL;
  gs_unref_variant GVariant *root_account_reply = NULL;
  gs_unref_object GDBusProxy *accountsservice = NULL;
  gs_unref_object GDBusProxy *root_account_properties = NULL;
  gs_unref_variant GVariant *root_account_locked_reply = NULL;
  gs_unref_variant GVariant *root_account_locked_property = NULL;
  gs_unref_variant GVariant *root_account_locked_value = NULL;
  gs_unref_object GFile *initial_setup_done_file = NULL;
  const char *root_account_path = NULL;
  gboolean have_user_accounts;
  gboolean root_is_locked;

#if 0
  bindtextdomain (PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (PACKAGE, "UTF-8");
  textdomain (PACKAGE);
#endif

  initial_setup_done_file = g_file_new_for_path ("/var/initial-setup-done");

  if (g_file_query_exists (initial_setup_done_file, NULL))
    goto out;
  
  accountsservice = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, NULL,
                                                   "org.freedesktop.Accounts",
                                                   "/org/freedesktop/Accounts",
                                                   "org.freedesktop.Accounts",
                                                   cancellable,
                                                   error);
  if (!accountsservice)
    goto out;

  user_list = g_dbus_proxy_call_sync (accountsservice, "ListCachedUsers",
                                      NULL, 0, -1, cancellable, error);
  if (!user_list)
    goto out;
  
  have_user_accounts = g_variant_n_children (user_list) > 0;
  
  root_account_reply = g_dbus_proxy_call_sync (accountsservice,
                                               "FindUserById",
                                               g_variant_new ("(t)", (guint64)0),
                                               0, -1,
                                               cancellable, error);
  if (!root_account_reply)
    goto out;
  if (!g_variant_is_of_type (root_account_reply, G_VARIANT_TYPE ("(o)")))
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Unexpected return type from FindUserById");
      goto out;
    }
  g_variant_get (root_account_reply, "(&o)", &root_account_path);

  root_account_properties =
    g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, NULL,
                                   g_dbus_proxy_get_name_owner (accountsservice),
                                   root_account_path,
                                   "org.freedesktop.DBus.Properties",
                                   cancellable,
                                   error);
  if (!root_account_properties)
    goto out;
  
  root_account_locked_reply =
    g_dbus_proxy_call_sync (root_account_properties,
                            "Get", g_variant_new ("(ss)", "org.freedesktop.Accounts.User", "Locked"),
                            0, -1, cancellable, error);
  if (!root_account_locked_reply)
    goto out;
  if (!g_variant_is_of_type (root_account_locked_reply, G_VARIANT_TYPE ("(v)")))
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Unexpected return type from property Get");
      goto out;
    }
  g_variant_get (root_account_locked_reply, "(v)", &root_account_locked_value);
  root_account_locked_property = g_variant_get_variant (root_account_locked_value);
  if (!g_variant_is_of_type (root_account_locked_property, G_VARIANT_TYPE ("b")))
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Unexpected non-boolean value for Locked");
      goto out;
    }
  
  root_is_locked = g_variant_get_boolean (root_account_locked_property);

  if (!(have_user_accounts && root_is_locked))
    {
      if (!do_initial_setup (cancellable, error))
        goto out;
    }

  if (!g_file_replace_contents (initial_setup_done_file, "", 0, NULL, FALSE,
                                G_FILE_CREATE_REPLACE_DESTINATION, NULL,
                                cancellable, error))
    goto out;

  gs_log_structured_print_id_v (INITIAL_SETUP_DONE_MSGID,
                                "Initial setup complete");
  
 out:
  if (local_error != NULL)
    {
      g_printerr ("error: %s\n", local_error->message);
      g_error_free (local_error);
      return 1;
    }
  return 0;
}