Exemple #1
0
/**
 * get @a property via @a dbus_connection .
 * org.freedesktop.DBus.Properties
 * Get (String interface, String propname) -> (Variant value)
 */
static int networkmanager_get_property(DBusConnection* dbus_connection, networkmanager_property* property)
{
	DBusMessage* msg;
    DBusMessageIter iter, iter_variant;
	DBusPendingCall* pending;
	int success;
    char* value_str_ptr;

	msg = dbus_message_new_method_call(
									  "org.freedesktop.NetworkManager",
									  property->dbus_path,
									  "org.freedesktop.DBus.Properties",
									  "Get"
									  );

	if(msg == NULL)
	{
		printf("networkmanager_get_property msg error\n");
		return 0;
	}

    dbus_message_iter_init_append(msg, &iter);
    dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property->dbus_interface);
	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property->dbus_property_name);

	// send dbus message
	// -1 is the default time out. Other time outs can be configured in milli seconds.
	success = dbus_connection_send_with_reply(dbus_connection, msg, &pending, -1);
	if(!success)
	{
		printf("networkmanager_get_property dbus send error\n");
		return 0;
	}
	if(pending == NULL)
	{
		printf ("networkmanager_get_property dbus calling error\n");
		return 0;
	}

	dbus_connection_flush(dbus_connection);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	dbus_pending_call_unref(pending);

	if(msg == NULL)
	{
		printf("networkmanager_get_property msg error 2\n");
		return 0;
	}

	if(!dbus_message_iter_init(msg, &iter))
	{
		printf("networkmanager_get_property dbus_message_iter_init error\n");
		dbus_message_unref(msg);
		return 0;
	}

	if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT)
	{
		dbus_message_iter_recurse(&iter, &iter_variant);
		if(dbus_message_iter_get_arg_type(&iter_variant) == DBUS_TYPE_STRING)
		{
			dbus_message_iter_get_basic(&iter_variant, &value_str_ptr);
			strncpy(property->value_string, value_str_ptr, property->value_string_len);
			printf("networkmanager_get_property %s %s: %s\n", property->dbus_path, property->dbus_property_name, value_str_ptr);
		}
		else if(dbus_message_iter_get_arg_type(&iter_variant) == DBUS_TYPE_UINT32)
		{
			dbus_message_iter_get_basic(&iter_variant, &property->value_int);
			printf("networkmanager_get_property %s %s: %i\n", property->dbus_path, property->dbus_property_name, property->value_int);
		}
		else
		{
			printf("networkmanager_get_property dbus_message_iter_get_arg_type error\n");
			dbus_message_unref(msg);
			return 0;
		}
	}
	else
	{
		printf("networkmanager_get_property dbus_message_iter_get_arg_type not variant error\n");
		dbus_message_unref(msg);
		return 0;
	}

	dbus_message_unref(msg);

	return 1;
}
Exemple #2
0
static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
{
	DBusMessageIter iter, dict;
	const char *reason, *key, *value;
	char *addressv4 = NULL, *netmask = NULL, *gateway = NULL;
	char *ifname = NULL, *nameservers = NULL;
	struct connman_ipaddress *ipaddress = NULL;

	dbus_message_iter_init(msg, &iter);

	dbus_message_iter_get_basic(&iter, &reason);
	dbus_message_iter_next(&iter);

	if (!provider) {
		connman_error("No provider found");
		return VPN_STATE_FAILURE;
	}

	if (strcmp(reason, "auth failed") == 0) {
		DBG("authentication failure");

		vpn_provider_set_string(provider, "L2TP.User", NULL);
		vpn_provider_set_string(provider, "L2TP.Password", NULL);

		return VPN_STATE_AUTH_FAILURE;
	}

	if (strcmp(reason, "connect"))
		return VPN_STATE_DISCONNECT;

	dbus_message_iter_recurse(&iter, &dict);

	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry;

		dbus_message_iter_recurse(&dict, &entry);
		dbus_message_iter_get_basic(&entry, &key);
		dbus_message_iter_next(&entry);
		dbus_message_iter_get_basic(&entry, &value);

		DBG("%s = %s", key, value);

		if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
			addressv4 = g_strdup(value);

		if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
			netmask = g_strdup(value);

		if (!strcmp(key, "INTERNAL_IP4_DNS"))
			nameservers = g_strdup(value);

		if (!strcmp(key, "INTERNAL_IFNAME"))
			ifname = g_strdup(value);

		dbus_message_iter_next(&dict);
	}

	if (vpn_set_ifname(provider, ifname) < 0) {
		g_free(ifname);
		g_free(addressv4);
		g_free(netmask);
		g_free(nameservers);
		return VPN_STATE_FAILURE;
	}

	if (addressv4)
		ipaddress = connman_ipaddress_alloc(AF_INET);

	g_free(ifname);

	if (!ipaddress) {
		connman_error("No IP address for provider");
		g_free(addressv4);
		g_free(netmask);
		g_free(nameservers);
		return VPN_STATE_FAILURE;
	}

	value = vpn_provider_get_string(provider, "HostIP");
	if (value) {
		vpn_provider_set_string(provider, "Gateway", value);
		gateway = g_strdup(value);
	}

	if (addressv4)
		connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
					gateway);

	vpn_provider_set_ipaddress(provider, ipaddress);
	vpn_provider_set_nameservers(provider, nameservers);

	g_free(addressv4);
	g_free(netmask);
	g_free(gateway);
	g_free(nameservers);
	connman_ipaddress_free(ipaddress);

	return VPN_STATE_CONNECT;
}
Exemple #3
0
static void properties_reply(DBusPendingCall *call, void *user_data)
{
	struct supplicant_task *task = user_data;
	struct supplicant_result result;
	struct connman_network *network;
	DBusMessage *reply;
	DBusMessageIter array, dict;
	unsigned char strength;
	unsigned short channel, frequency;
	const char *mode, *security;
	char *group = NULL;

	reply = dbus_pending_call_steal_reply(call);
	if (reply == NULL) {
		_DBG_SUPPLICANT("task %p no reply", task);
		get_properties(task);
		return;
	}

	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
		_DBG_SUPPLICANT("task %p ERROR", task);
		dbus_message_unref(reply);
		get_properties(task);
		return;
	}

	memset(&result, 0, sizeof(result));
	result.frequency = -1;
	result.quality = -1;
	result.level = 0;
	result.noise = 0;

	dbus_message_iter_init(reply, &array);

	dbus_message_iter_recurse(&array, &dict);

	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;
		const char *key;

		dbus_message_iter_recurse(&dict, &entry);
		dbus_message_iter_get_basic(&entry, &key);

		dbus_message_iter_next(&entry);

		dbus_message_iter_recurse(&entry, &value);

		//type = dbus_message_iter_get_arg_type(&value);
		//dbus_message_iter_get_basic(&value, &val);

		/* 
		 * bssid        : a (97)
		 * ssid         : a (97)
		 * wpaie        : a (97)
		 * rsnie        : a (97)
		 * wpsie        : a (97)
		 * frequency    : i (105)
		 * capabilities : q (113)
		 * quality      : i (105)
		 * noise        : i (105)
		 * level        : i (105)
		 * maxrate      : i (105)
		 */

		if (g_str_equal(key, "bssid") == TRUE)
			extract_addr(&value, &result);
		else if (g_str_equal(key, "ssid") == TRUE)
			extract_ssid(&value, &result);
		else if (g_str_equal(key, "wpaie") == TRUE)
			extract_wpaie(&value, &result);
		else if (g_str_equal(key, "rsnie") == TRUE)
			extract_rsnie(&value, &result);
		else if (g_str_equal(key, "wpsie") == TRUE)
			extract_wpsie(&value, &result);
		else if (g_str_equal(key, "capabilities") == TRUE)
			extract_capabilites(&value, &result);
		else if (g_str_equal(key, "frequency") == TRUE)
			dbus_message_iter_get_basic(&value, &result.frequency);
		else if (g_str_equal(key, "quality") == TRUE)
			dbus_message_iter_get_basic(&value, &result.quality);
		else if (g_str_equal(key, "noise") == TRUE)
			dbus_message_iter_get_basic(&value, &result.noise);
		else if (g_str_equal(key, "level") == TRUE)
			dbus_message_iter_get_basic(&value, &result.level);
		else if (g_str_equal(key, "maxrate") == TRUE)
			dbus_message_iter_get_basic(&value, &result.maxrate);

		dbus_message_iter_next(&dict);
	}

	if (result.path == NULL)
		goto done;

	if (result.path[0] == '\0')
		goto done;

	if (result.frequency > 0 && result.frequency < 14)
		result.frequency = 2407 + (5 * result.frequency);
	else if (result.frequency == 14)
		result.frequency = 2484;

	strength = calculate_strength(task, &result);
	channel  = calculate_channel(&result);

	frequency = (result.frequency < 0) ? 0 : result.frequency;

	if (result.has_rsn == TRUE)
		security = "rsn";
	else if (result.has_wpa == TRUE)
		security = "wpa";
	else if (result.has_wep == TRUE)
		security = "wep";
	else
		security = "none";

	mode = (result.adhoc == TRUE) ? "adhoc" : "managed";

	group = build_group(result.path, result.name,
					result.ssid, result.ssid_len,
							mode, security);

	network = connman_device_get_network(task->device, result.path);
	if (network == NULL) {
		int index;

		network = connman_network_create(result.path,
						CONNMAN_NETWORK_TYPE_WIFI);
		if (network == NULL) {
			_DBG_SUPPLICANT("cannot create network %s",
				result.name);
			goto done;
		}

		index = connman_device_get_index(task->device);
		connman_network_set_index(network, index);

		connman_network_set_protocol(network,
						CONNMAN_NETWORK_PROTOCOL_IP);

		connman_network_set_address(network, result.addr,
							result.addr_len);

		if (connman_device_add_network(task->device, network) < 0) {
			_DBG_SUPPLICANT("cannot add network %s", result.name);
			connman_network_unref(network);
			goto done;
		}

		_DBG_SUPPLICANT("add %s (%s %s) signal %d (%s) freq %u path %s",
				result.name, mode, security, strength,
				(result.has_wps == TRUE) ? "WPS" : "no WPS",
				frequency, result.path);
	}

	connman_network_set_scangen(network, task->scangen);

	if (result.name != NULL && result.name[0] != '\0')
		connman_network_set_name(network, result.name);

	connman_network_set_blob(network, "WiFi.SSID",
						result.ssid, result.ssid_len);

	connman_network_set_string(network, "WiFi.Mode", mode);

	connman_network_set_available(network, TRUE);
	connman_network_set_strength(network, strength);

	connman_network_set_uint16(network, "Frequency", frequency);
	connman_network_set_uint16(network, "WiFi.Channel", channel);
	connman_network_set_string(network, "WiFi.Security", security);

	if (result.ssid != NULL)
		connman_network_set_group(network, group);

done:
	g_free(group);

	g_free(result.path);
	g_free(result.addr);
	g_free(result.name);
	g_free(result.ssid);

	dbus_message_unref(reply);

	get_properties(task);
}
static void request_input_passphrase_reply(DBusMessage *reply, void *user_data)
{
	struct request_input_reply *passphrase_reply = user_data;
	bool values_received = false;
	bool wps = false;
	const char *error = NULL;
	char *identity = NULL;
	char *passphrase = NULL;
	char *wpspin = NULL;
	char *key;
	char *name = NULL;
	int name_len = 0;
	DBusMessageIter iter, dict;

	if (!reply)
		goto out;

	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
		error = dbus_message_get_error_name(reply);
		goto done;
	}

	if (!check_reply_has_dict(reply))
		goto done;

	values_received = true;

	dbus_message_iter_init(reply, &iter);
	dbus_message_iter_recurse(&iter, &dict);
	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;

		dbus_message_iter_recurse(&dict, &entry);
		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
			break;

		dbus_message_iter_get_basic(&entry, &key);

		if (g_str_equal(key, "Identity")) {
			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			dbus_message_iter_get_basic(&value, &identity);

		} else if (g_str_equal(key, "Passphrase")) {
			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			dbus_message_iter_get_basic(&value, &passphrase);

		} else if (g_str_equal(key, "WPS")) {
			wps = true;

			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			dbus_message_iter_get_basic(&value, &wpspin);
			break;
		} else if (g_str_equal(key, "Name")) {
			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			dbus_message_iter_get_basic(&value, &name);
			name_len = strlen(name);
		} else if (g_str_equal(key, "SSID")) {
			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			if (dbus_message_iter_get_arg_type(&value)
							!= DBUS_TYPE_VARIANT)
				break;
			if (dbus_message_iter_get_element_type(&value)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_get_fixed_array(&value, &name,
							&name_len);
		}
		dbus_message_iter_next(&dict);
	}

done:
	passphrase_reply->callback(passphrase_reply->service, values_received,
				name, name_len,
				identity, passphrase,
				wps, wpspin, error,
				passphrase_reply->user_data);

out:
	g_free(passphrase_reply);
}
static DBusHandlerResult info(DBusConnection *c, DBusMessage * msg, void *data)
{
    int              driver    = -1;
    int              connected = -1;
    int             *valueptr  = &driver;
    int              value     = -1;
    DBusMessageIter  msgit;
    DBusMessageIter  devit;
    char            *string;
    char            *end;
    char            *device;
    gboolean         is_info;

    (void) c;
    (void) data;

    /* This is an example of what we should get:

       string "connected"
       string "1"
       array [
          string "fmtx"
       ]

    */

    is_info = dbus_message_is_signal(msg, "com.nokia.policy", "info");
    if (!is_info)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    OHM_DEBUG(DBG_INFO, "received an info message");

    dbus_message_iter_init(msg, &msgit);

    for (;;) {
        if (dbus_message_iter_get_arg_type(&msgit) != DBUS_TYPE_STRING)
            goto done;

        dbus_message_iter_get_basic(&msgit, (void *)&string);

        if (!strcmp(string, "media"))
            goto not_our_signal;

        if (!strcmp(string, "driver")) {
            valueptr = &driver;

            if (!dbus_message_iter_next(&msgit))
                goto done;
        }
        else if (!strcmp(string, "connected")) {
            valueptr = &connected;

            if (!dbus_message_iter_next(&msgit))
                goto done;
        }
        else {
            value = strtol(string, &end, 10);

            if (*end == '\0' && (value == 0 || value == 1)) {
                *valueptr = value;
                break;
            }

            goto done;
        }
    }

    if (!dbus_message_iter_next(&msgit) ||
        dbus_message_iter_get_arg_type(&msgit) != DBUS_TYPE_ARRAY)
        goto done;

    dbus_message_iter_recurse(&msgit, &devit);

    do {
        if (dbus_message_iter_get_arg_type(&devit) != DBUS_TYPE_STRING)
            continue;

        dbus_message_iter_get_basic(&devit, (void *)&device);

        OHM_DEBUG(DBG_INFO, "device: '%s', driver: '%d', connected: '%d'",
                  device ? device : "NULL", driver, connected);
        if (!is_spurious_event(device, driver, connected))
            dres_accessory_request(device, driver, connected);

    } while (dbus_message_iter_next(&devit));

    dres_all();

 done:
 not_our_signal:
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
int
ac_manage_exec_extend_command(DBusConnection *connection, 
                                            unsigned int command_type, 
                                            char *command, 
                                            struct command_return_s **command_return) {

    if(NULL == connection || NULL == command || NULL == command_return)
        return AC_MANAGE_INPUT_TYPE_ERROR;

    char *comm = command;  
  
    *command_return = NULL;    
    struct command_return_s *end_return = NULL;
    
	DBusMessage *query, *reply;
	DBusError err;
	DBusMessageIter	 iter;

	int ret = AC_MANAGE_DBUS_ERROR;
    int moreReturn = 0;
    char *returnStr = NULL;

	query = dbus_message_new_method_call(AC_MANAGE_DBUS_DBUSNAME, 
										AC_MANAGE_DBUS_OBJPATH,
										AC_MANAGE_DBUS_INTERFACE,
										AC_MANAGE_DBUS_EXTEND_COMMAND_EXEC);

    dbus_error_init(&err);

    dbus_message_append_args(query,
                            DBUS_TYPE_UINT32, &command_type,
                            DBUS_TYPE_STRING, &comm,
                            DBUS_TYPE_INVALID);

    reply = dbus_connection_send_with_reply_and_block(connection, query, -1, &err);

    dbus_message_unref(query);

    if(NULL == reply) {
        if(dbus_error_is_set(&err)) {
            dbus_error_free(&err);
        }
        return AC_MANAGE_DBUS_ERROR;
    }
    
	dbus_message_iter_init(reply, &iter);
	dbus_message_iter_get_basic(&iter, &ret);
	
    dbus_message_iter_next(&iter);  
	dbus_message_iter_get_basic(&iter, &moreReturn);

    while(AC_MANAGE_SUCCESS == ret && moreReturn) {
    
        dbus_message_iter_next(&iter);  
        dbus_message_iter_get_basic(&iter, &returnStr);

        dbus_message_iter_next(&iter);  
        dbus_message_iter_get_basic(&iter, &moreReturn);

        struct command_return_s *temp_return = (struct command_return_s *)malloc(sizeof(struct command_return_s));
        if(NULL == temp_return) {
            dbus_message_unref(reply);
            syslog(LOG_WARNING, "ac_manage_exec_extend_command: malloc temp_return fail!\n");
            return AC_MANAGE_MALLOC_ERROR;
        }
        memset(temp_return, 0, sizeof(struct command_return_s));
        
        strncpy(temp_return->returnString, returnStr, sizeof(temp_return->returnString) - 1);

        if(NULL == *command_return) {
            *command_return = temp_return;
        }
        else {
            end_return->next = temp_return;
        }
        
        end_return = temp_return;
    }
    
    dbus_message_unref(reply);
    
    return ret;
}
Exemple #7
0
static void Crash(DBusMessage* signal)
{
    int r;
    DBusMessageIter in_iter;
    dbus_message_iter_init(signal, &in_iter);

    /* 1st param: package */
    const char* package_name = NULL;
    r = load_charp(&in_iter, &package_name);

    /* 2nd param: dir */
//dir parameter is not used for now, use is planned in the future
    if (r != ABRT_DBUS_MORE_FIELDS)
    {
        error_msg("dbus signal %s: parameter type mismatch", __func__);
        return;
    }
    const char* dir = NULL;
    r = load_charp(&in_iter, &dir);

    /* Optional 3rd param: uid */
    const char* uid_str = NULL;
    if (r == ABRT_DBUS_MORE_FIELDS)
    {
        r = load_charp(&in_iter, &uid_str);
    }
    if (r != ABRT_DBUS_LAST_FIELD)
    {
        error_msg("dbus signal %s: parameter type mismatch", __func__);
        return;
    }

    if (uid_str != NULL)
    {
        char *end;
        errno = 0;
        unsigned long uid_num = strtoul(uid_str, &end, 10);
        if (errno || *end != '\0' || uid_num != getuid())
        {
            return;
        }
    }

    const char* message = _("A crash in the %s package has been detected");
    if (package_name[0] == '\0')
        message = _("A crash has been detected");
    init_applet();
    //applet->AddEvent(uid, package_name);
    set_icon_tooltip(applet, message, package_name);
    show_icon(applet);

    /* If this crash seems to be repeating, do not annoy user with popup dialog.
     * (The icon in the tray is not suppressed)
     */
    static time_t last_time = 0;
    static char* last_package_name = NULL;
    static char* last_dir = NULL;
    time_t cur_time = time(NULL);
    if (last_package_name && strcmp(last_package_name, package_name) == 0
            && last_dir && strcmp(last_dir, dir) == 0
            && (unsigned)(cur_time - last_time) < 2 * 60 * 60
       ) {
        log_msg("repeated crash in %s, not showing the notification", package_name);
        return;
    }
    last_time = cur_time;
    free(last_package_name);
    last_package_name = xstrdup(package_name);
    free(last_dir);
    last_dir = xstrdup(dir);

    show_crash_notification(applet, dir, message, package_name);
}
Exemple #8
0
static DBusHandlerResult
request_navit_set_attr(DBusConnection *connection, DBusMessage *message)
{
    struct navit *navit;
	DBusMessageIter iter, iterattr;
    struct attr attr;
    char *attr_type;

	navit = object_get_from_message(message, "navit");
	if (! navit)
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    dbus_message_iter_init(message, &iter);
    dbus_message_iter_get_basic(&iter, &attr_type);
    attr.type = attr_from_name(attr_type); 
    dbg(0, "attr value: 0x%x string: %s\n", attr.type, attr_type);
    
    if (attr.type == attr_none)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    
    dbus_message_iter_next(&iter);
    dbus_message_iter_recurse(&iter, &iterattr);
    dbg(0, "seems valid. signature: %s\n", dbus_message_iter_get_signature(&iterattr));
    
    if (attr.type > attr_type_item_begin && attr.type < attr_type_item_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if (attr.type > attr_type_int_begin && attr.type < attr_type_boolean_begin) {
        if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_INT32)
        {
            dbus_message_iter_get_basic(&iterattr, &attr.u.num);
            if (navit_set_attr(navit, &attr))
                return empty_reply(connection, message);
        }
    }
    else if(attr.type > attr_type_boolean_begin && attr.type < attr_type_int_end) {
        if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_BOOLEAN)
        {
            dbus_message_iter_get_basic(&iterattr, &attr.u.num);
            if (navit_set_attr(navit, &attr))
                return empty_reply(connection, message);
        }
    }
#if 0
    else if(attr.type > attr_type_string_begin && attr.type < attr_type_string_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_special_begin && attr.type < attr_type_special_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_double_begin && attr.type < attr_type_double_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_geo_begin && attr.type < attr_type_coord_geo_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_color_begin && attr.type < attr_type_color_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_object_begin && attr.type < attr_type_object_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_begin && attr.type < attr_type_coord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_pcoord_begin && attr.type < attr_type_pcoord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_callback_begin && attr.type < attr_type_callback_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
#endif
    else {
        dbg(0, "zomg really unhandled111\n");
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }
    
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Exemple #9
0
GList *
upstart_job_listall(void)
{
    GList *units = NULL;
    DBusMessageIter args;
    DBusMessageIter unit;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    const char *method = "GetAllJobs";
    DBusError error;
    int lpc = 0;

    if (upstart_init() == FALSE) {
        return NULL;
    }

/*
  com.ubuntu.Upstart0_6.GetAllJobs (out <Array of ObjectPath> jobs)
*/

    dbus_error_init(&error);
    msg = dbus_message_new_method_call(BUS_NAME, // target for the method call
                                       BUS_PATH, // object to call on
                                       UPSTART_06_API, // interface to call on
                                       method); // method name
    CRM_ASSERT(msg != NULL);

    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, DBUS_TIMEOUT_USE_DEFAULT);
    dbus_message_unref(msg);

    if (dbus_error_is_set(&error)) {
        crm_err("Call to %s failed: %s", method, error.message);
        dbus_error_free(&error);
        return NULL;

    } else if (!dbus_message_iter_init(reply, &args)) {
        crm_err("Call to %s failed: Message has no arguments", method);
        dbus_message_unref(reply);
        return NULL;
    }

    if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_ARRAY, __FUNCTION__, __LINE__)) {
        crm_err("Call to %s failed: Message has invalid arguments", method);
        dbus_message_unref(reply);
        return NULL;
    }

    dbus_message_iter_recurse(&args, &unit);
    while (dbus_message_iter_get_arg_type (&unit) != DBUS_TYPE_INVALID) {
        DBusBasicValue value;
        const char *job = NULL;
        char *path = NULL;

        if(!pcmk_dbus_type_check(reply, &unit, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
            continue;
        }

        dbus_message_iter_get_basic(&unit, &value);

        if(value.str) {
            int llpc = 0;
            path = value.str;
            job = value.str;
            while (path[llpc] != 0) {
                if (path[llpc] == '/') {
                    job = path + llpc + 1;
                }
                llpc++;
            }
            lpc++;
            crm_trace("%s -> %s", path, job);
            units = g_list_append(units, fix_upstart_name(job));
        }
        dbus_message_iter_next (&unit);
    }

    dbus_message_unref(reply);
    crm_trace("Found %d upstart jobs", lpc);
    return units;
}
Exemple #10
0
/**
 * add connection settings to network manager
 */
int qaul_network_settings_add(DBusConnection* dbus_connection, qaul_dbus_connection_settings* settings, qaul_dbus_device_properties* device)
{
	DBusMessage* msg;
	DBusMessageIter iter;
	DBusMessageIter iter_array[7];
	char uuid[37];
	const char* connection_path_ptr;
	dbus_uint32_t wlan_channel_ui32;

	printf("qaul_network_settings_add\n");

	msg = dbus_message_new_method_call(
							"org.freedesktop.NetworkManager",
							"/org/freedesktop/NetworkManager/Settings",
							"org.freedesktop.NetworkManager.Settings",
							"AddConnection"
							);

	if(msg == NULL)
	{
		printf("qaul_network_settings_add msg error\n");
		return 0;
	}

	const char* connection_str = "connection";
	const char* connection_keys[]   = {"id",      "type", "uuid", "zone"};
	const char* connection_values[] = {"qaul.net", NULL,   NULL,  "public"};

	// connection uuid
	qaul_dbus_create_uuid(uuid);
	connection_values[2] = uuid;
	printf("uuid: %s\n", uuid);

	// configure settings type & structure
	if(device->type == 2)
	{
		connection_values[1] = "802-11-wireless";
	}
	else if(device->type == 1)
	{
		connection_values[1] = "802-3-ethernet";
	}

	dbus_message_iter_init_append(msg, &iter);

	// configure connection settings
	if(!(
		   dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sa{sv}}", &iter_array[0])
		&& dbus_message_iter_open_container(&iter_array[0], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[1])
		&& dbus_message_iter_append_basic(&iter_array[1], DBUS_TYPE_STRING, &connection_str)
		&& dbus_message_iter_open_container(&iter_array[1], DBUS_TYPE_ARRAY, "{sv}", &iter_array[2])
		&& qaul_dbus_append_dict_entry(&iter_array[2], connection_keys[0], DBUS_TYPE_STRING, &connection_values[0])
		&& qaul_dbus_append_dict_entry(&iter_array[2], connection_keys[1], DBUS_TYPE_STRING, &connection_values[1])
		&& qaul_dbus_append_dict_entry(&iter_array[2], connection_keys[2], DBUS_TYPE_STRING, &connection_values[2])
		&& qaul_dbus_append_dict_entry(&iter_array[2], connection_keys[3], DBUS_TYPE_STRING, &connection_values[3])
		&& dbus_message_iter_close_container(&iter_array[1], &iter_array[2])
		&& dbus_message_iter_close_container(&iter_array[0], &iter_array[1])
		))
	{
		printf("qaul_network_settings_add append connection settings error\n");
		return 0;
	}

	// configure wireless device
	if(device->type == 2)
	{
		const char* wlan = connection_values[1];
		const char* wlan_keys[]   = {"ssid", "mode", "band", "channel"};
		const char* wlan_values[] = {NULL,  "adhoc", "bg"};
		wlan_channel_ui32 = settings->wifi_channel +0;

		if(!(
			   dbus_message_iter_open_container(&iter_array[0], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[1])
			&& dbus_message_iter_append_basic(&iter_array[1], DBUS_TYPE_STRING, &wlan)
			&& dbus_message_iter_open_container(&iter_array[1], DBUS_TYPE_ARRAY, "{sv}", &iter_array[2])

			// add hardware MAC address
			&& qaul_dbus_append_device_mac(&iter_array[2], device)

			// SSID dict entry as byte array
			&& dbus_message_iter_open_container(&iter_array[2], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[3])
			&& dbus_message_iter_append_basic(&iter_array[3], DBUS_TYPE_STRING, &wlan_keys[0])
			&& dbus_message_iter_open_container(&iter_array[3], DBUS_TYPE_VARIANT, "ay", &iter_array[4])
			&& dbus_message_iter_open_container(&iter_array[4], DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &iter_array[5])
			&& qaul_dbus_append_ssid(&iter_array[5], settings->wifi_ssid)
			&& dbus_message_iter_close_container(&iter_array[4], &iter_array[5])
			&& dbus_message_iter_close_container(&iter_array[3], &iter_array[4])
			&& dbus_message_iter_close_container(&iter_array[2], &iter_array[3])

			// end SSID dict entry
			&& qaul_dbus_append_dict_entry(&iter_array[2], wlan_keys[1], DBUS_TYPE_STRING, &wlan_values[1])
			&& qaul_dbus_append_dict_entry(&iter_array[2], wlan_keys[2], DBUS_TYPE_STRING, &wlan_values[2])
			&& qaul_dbus_append_dict_entry(&iter_array[2], wlan_keys[3], DBUS_TYPE_UINT32, &wlan_channel_ui32)
			&& dbus_message_iter_close_container(&iter_array[1], &iter_array[2])
			&& dbus_message_iter_close_container(&iter_array[0], &iter_array[1])
		))
		{
			printf("qaul_network_settings_add append wireless error\n");
			return 0;
		}
	}
	// configure Ethernet device
	else if(device->type == 1)
	{
		const char* ethernet = connection_values[1];

		if(!(
			   dbus_message_iter_open_container(&iter_array[0], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[1])
			&& dbus_message_iter_append_basic(&iter_array[1], DBUS_TYPE_STRING, &ethernet)
			&& dbus_message_iter_open_container(&iter_array[1], DBUS_TYPE_ARRAY, "{sv}", &iter_array[2])

			// add hardware MAC address
			&& qaul_dbus_append_device_mac(&iter_array[2], device)

			&& dbus_message_iter_close_container(&iter_array[1], &iter_array[2])
			&& dbus_message_iter_close_container(&iter_array[0], &iter_array[1])
		))
		{
			printf("qaul_network_settings_add append Ethernet error\n");
			return 0;
		}
	}

	// configure IP
	// check available settings:
	// http://sourcecodebrowser.com/network-manager/0.8/nm-setting-ip4-config_8h.html
	const char* ipv4 = "ipv4";
	const char* ipv4_method_key = "method";
	const char* ipv4_method_value = "manual";
	const char* ipv4_addresses = "addresses";
	dbus_uint32_t ipv4_address_ip;
	dbus_uint32_t ipv4_address_gateway;
	inet_pton(AF_INET, settings->ipv4_address, &ipv4_address_ip);
	inet_pton(AF_INET, settings->ipv4_gateway, &ipv4_address_gateway);
	dbus_uint32_t ipv4_address_netmask = settings->ipv4_netmask +0;
	const char* ipv4_dns = "dns";
	dbus_uint32_t ipv4_dns_ip1;
	dbus_uint32_t ipv4_dns_ip2;
	inet_pton(AF_INET, settings->ipv4_dns1, &ipv4_dns_ip1);
	inet_pton(AF_INET, settings->ipv4_dns2, &ipv4_dns_ip2);

	if(!(
		// append IP settings
		   dbus_message_iter_open_container(&iter_array[0], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[1])
		&& dbus_message_iter_append_basic(&iter_array[1], DBUS_TYPE_STRING, &ipv4)
		&& dbus_message_iter_open_container(&iter_array[1], DBUS_TYPE_ARRAY, "{sv}", &iter_array[2])

		// append IP method
		&& qaul_dbus_append_dict_entry(&iter_array[2], ipv4_method_key, DBUS_TYPE_STRING, &ipv4_method_value)

		// append IP addresses
		&& dbus_message_iter_open_container(&iter_array[2], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[3])
		&& dbus_message_iter_append_basic(&iter_array[3], DBUS_TYPE_STRING, &ipv4_addresses)
		&& dbus_message_iter_open_container(&iter_array[3], DBUS_TYPE_VARIANT, "aau", &iter_array[4])
		// append IP address
		&& dbus_message_iter_open_container(&iter_array[4], DBUS_TYPE_ARRAY, "au", &iter_array[5])
		&& dbus_message_iter_open_container(&iter_array[5], DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32_AS_STRING, &iter_array[6])

		// append IP
		&& dbus_message_iter_append_basic(&iter_array[6], DBUS_TYPE_UINT32, &ipv4_address_ip)
		// append IP netmask
		&& dbus_message_iter_append_basic(&iter_array[6], DBUS_TYPE_UINT32, &ipv4_address_netmask)
		// append IP gateway
		&& dbus_message_iter_append_basic(&iter_array[6], DBUS_TYPE_UINT32, &ipv4_address_gateway)

		&& dbus_message_iter_close_container(&iter_array[5], &iter_array[6])
		&& dbus_message_iter_close_container(&iter_array[4], &iter_array[5])
		&& dbus_message_iter_close_container(&iter_array[3], &iter_array[4])
		&& dbus_message_iter_close_container(&iter_array[2], &iter_array[3])

		// append DNS settings
		&& dbus_message_iter_open_container(&iter_array[2], DBUS_TYPE_DICT_ENTRY, NULL, &iter_array[3])
		&& dbus_message_iter_append_basic(&iter_array[3], DBUS_TYPE_STRING, &ipv4_dns)
		&& dbus_message_iter_open_container(&iter_array[3], DBUS_TYPE_VARIANT, "au", &iter_array[4])
		&& dbus_message_iter_open_container(&iter_array[4], DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32_AS_STRING, &iter_array[5])

		// append first DNS address
		&& dbus_message_iter_append_basic(&iter_array[5], DBUS_TYPE_UINT32, &ipv4_dns_ip1)
		// append second DNS address
		&& dbus_message_iter_append_basic(&iter_array[5], DBUS_TYPE_UINT32, &ipv4_dns_ip2)

		&& dbus_message_iter_close_container(&iter_array[4], &iter_array[5])
		&& dbus_message_iter_close_container(&iter_array[3], &iter_array[4])
		&& dbus_message_iter_close_container(&iter_array[2], &iter_array[3])

		// close IP settings
		&& dbus_message_iter_close_container(&iter_array[1], &iter_array[2])
		&& dbus_message_iter_close_container(&iter_array[0], &iter_array[1])
	))
	{
		printf("qaul_network_settings_add append DNS error\n");
		return 0;
	}

	// close settings
	if(!(
		dbus_message_iter_close_container(&iter, &iter_array[0])
	))
	{
		printf("qaul_network_settings_add close settings error\n");
		return 0;
	}

	if (!networkmanager_dbus_send(&msg, dbus_connection))
	{
		printf("qaul_network_settings_add networkmanager_dbus_send error\n");
		return 0;
	}

	if (!dbus_message_iter_init(msg, &iter)
	  || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
	{
		printf("qaul_network_settings_add != DBUS_TYPE_OBJECT_PATH error (%i), DBUS_TYPE_STRING %i \n", dbus_message_iter_get_arg_type(&iter), DBUS_TYPE_STRING);
		if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
		{
			dbus_message_iter_get_basic(&iter, &connection_path_ptr);
			printf("qaul_network_settings_add error: %s\n", connection_path_ptr);
		}
		dbus_message_unref(msg);
		return 0;
	}

	dbus_message_iter_get_basic(&iter, &connection_path_ptr);
	strncpy(settings->dbus_connection_path, connection_path_ptr, sizeof(settings->dbus_connection_path));

	dbus_message_unref(msg);

	return 1;
}
Exemple #11
0
static DBusHandlerResult
request_navit_get_attr(DBusConnection *connection, DBusMessage *message)
{
    struct navit *navit;
    DBusMessageIter iter;
    char * attr_type = NULL;
    struct attr attr;
    navit = object_get_from_message(message, "navit");
    if (! navit)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    dbus_message_iter_init(message, &iter);
    dbus_message_iter_get_basic(&iter, &attr_type);
    attr.type = attr_from_name(attr_type); 
    dbg(0, "attr value: 0x%x string: %s\n", attr.type, attr_type);

    if (attr.type == attr_none)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    
    if (attr.type > attr_type_item_begin && attr.type < attr_type_item_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if (attr.type > attr_type_int_begin && attr.type < attr_type_boolean_begin)
    {
        dbg(0, "int detected\n");
        if(navit_get_attr(navit, attr.type, &attr, NULL)) {
            dbg(0, "%s = %i\n", attr_type, attr.u.num);
            return reply_simple_as_variant(connection, message, attr.u.num, DBUS_TYPE_INT32);
        }
    }

    else if(attr.type > attr_type_boolean_begin && attr.type < attr_type_int_end)
    {
        dbg(0, "bool detected\n");
        if(navit_get_attr(navit, attr.type, &attr, NULL)) {
            dbg(0, "%s = %i\n", attr_type, attr.u.num);
            return reply_simple_as_variant(connection, message, attr.u.num, DBUS_TYPE_BOOLEAN);
        }
    }

    else if(attr.type > attr_type_string_begin && attr.type < attr_type_string_end)
    {
        dbg(0, "string detected\n");
        if(navit_get_attr(navit, attr.type, &attr, NULL)) {
            dbg(0, "%s = %s\n", attr_type, &attr.u.layout);
            return reply_simple_as_variant(connection, message, &attr.u.layout, DBUS_TYPE_STRING);
        }
    }

#if 0
    else if(attr.type > attr_type_special_begin && attr.type < attr_type_special_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_double_begin && attr.type < attr_type_double_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_geo_begin && attr.type < attr_type_coord_geo_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_color_begin && attr.type < attr_type_color_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_object_begin && attr.type < attr_type_object_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_coord_begin && attr.type < attr_type_coord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_pcoord_begin && attr.type < attr_type_pcoord_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    else if(attr.type > attr_type_callback_begin && attr.type < attr_type_callback_end)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
#endif
    else {
        dbg(0, "zomg really unhandled111\n");
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }

    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Exemple #12
0
/**
 * find the first wifi device
 *
 * @retval 1 wifi device found, properties set
 * @retval 0 no wifi device found, properties not set
 */
int qaul_network_find_wifi(DBusConnection* dbus_connection, qaul_dbus_device_properties* device)
{
	DBusMessage* msg;
	DBusMessageIter iter, iter_array;
	int current_type;
	const char* device_path_ptr;

	printf("qaul_network_find_wifi\n");

	msg = networkmanager_dbus_method_call("GetDevices");
	if(msg == NULL)
		return 0;

	dbus_message_iter_init_append(msg, &iter);
	if(!networkmanager_dbus_send(&msg, dbus_connection))
	{
		printf("qaul_network_find_wifi networkmanager_dbus_send error\n");
		return 0;
	}
	if(!dbus_message_iter_init(msg, &iter)
		|| dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
	{
		printf("qaul_network_find_wifi dbus_message_iter_init | DBUS_TYPE_ARRAY error\n");
		dbus_message_unref(msg);
		return 0;
	}

	// loop recursively over the array
	dbus_message_iter_recurse (&iter, &iter_array);
	while((current_type = dbus_message_iter_get_arg_type(&iter_array)) != DBUS_TYPE_INVALID)
	{
		if(current_type == DBUS_TYPE_OBJECT_PATH)
		{
			dbus_message_iter_get_basic(&iter_array, &device_path_ptr);
			strncpy(device->dbus_device_path, device_path_ptr, sizeof(device->dbus_device_path));

			// get interface name, type
			// dbus low level: dbus_message_new_method_call interface:"org.freedesktop.DBus.Properties" method:"Get" property:"(String)Interface, (UInt32)DeviceType"
			if(networkmanager_device_properties(dbus_connection, device))
			{
				if(device->type == 2 && device->state > 20)
				{
					printf("qaul_network_find_wifi wifi found: %s\n", device->interface);
					dbus_message_unref(msg);
					return 1;
				}
			}
			else
				printf("qaul_network_find_wifi networkmanager_device_get_property failed for %s\n", device->dbus_device_path);
		}
		else
			printf("qaul_network_find_wifi Unknown current type [%i]\n", current_type);

		dbus_message_iter_next(&iter_array);
	}
	dbus_message_unref(msg);

	printf("qaul_network_find_wifi no wifi device found\n");

	return 0;
}
Exemple #13
0
/**
 * Write a Json configuration to @a json_txt of available network devices.
 * Only Wifi and Ethernet devices are represented as the other device cannot be
 * configured at the moment. @a json_txt needs to be a pointer ot a char buffer
 * of the size MAX_JSON_LEN +1.
 *
 * @retval 1 success
 * @retval 2 error
 *
 * https://developer.gnome.org/NetworkManager/unstable/spec.html
 * GetDevices() → ao
 *
 * Dbus messages:
 * http://dbus.freedesktop.org/doc/api/html/group__DBusMessage.html
 * DBUS_EXPORT int dbus_message_iter_get_arg_type(DBusMessageIter * iter)
 */
int qaul_network_devices_json(DBusConnection* dbus_connection, char* json_txt)
{
	DBusMessage* msg;
	DBusMessageIter iter, iter_array;
	int current_type, json_pos, i;
	const char* device_path_ptr;
	qaul_dbus_device_properties device;

	printf("qaul_network_devices_json\n");

	i = 0;
	msg = networkmanager_dbus_method_call("GetDevices");
	if(msg == NULL)
		return 0;

	dbus_message_iter_init_append(msg, &iter);
	if(!networkmanager_dbus_send(&msg, dbus_connection))
	{
		printf("qaul_network_devices_json networkmanager_dbus_send error\n");
		return 0;
	}
	if(!dbus_message_iter_init(msg, &iter)
		|| dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
	{
		printf("qaul_network_devices_json dbus_message_iter_init | DBUS_TYPE_ARRAY error\n");
		dbus_message_unref(msg);
		return 0;
	}

	// loop recursively over the array
	json_pos = 0;
	strncpy(json_txt +json_pos, "", MAX_JSON_LEN -json_pos);
	dbus_message_iter_recurse (&iter, &iter_array);
	while((current_type = dbus_message_iter_get_arg_type(&iter_array)) != DBUS_TYPE_INVALID)
	{
		if(current_type == DBUS_TYPE_OBJECT_PATH)
		{
			dbus_message_iter_get_basic(&iter_array, &device_path_ptr);
			strncpy(device.dbus_device_path, device_path_ptr, sizeof(device.dbus_device_path));

			// get interface name and interface type
			// dbus low level: dbus_message_new_method_call interface:"org.freedesktop.DBus.Properties" method:"Get" property:"(String)Interface, (UInt32)DeviceType"
			if(networkmanager_device_properties(dbus_connection, &device))
			{
				// only wifi and ethernet connections can be handled at the moment
				if(device.type == 2 || device.type == 1)
				{
					if(i > 0)
					{
						json_pos = strlen(json_txt);
						strncpy(json_txt +json_pos, ",", MAX_JSON_LEN -json_pos);
					}
					i++;

					// write to json
					json_pos = strlen(json_txt);
					strncpy(json_txt +json_pos, "{\"name\":\"", MAX_JSON_LEN -json_pos);
					json_pos = strlen(json_txt);
					strncpy(json_txt +json_pos, device.interface, MAX_JSON_LEN -json_pos);
					json_pos = strlen(json_txt);

					if(device.type == 2)
					{
						strncpy(json_txt +json_pos, "\",\"ui_name\":\"WIFI (", MAX_JSON_LEN -json_pos);
						json_pos = strlen(json_txt);
						strncpy(json_txt +json_pos, device.interface, MAX_JSON_LEN -json_pos);
						json_pos = strlen(json_txt);
						strncpy(json_txt +json_pos, ")\",\"type\":1", MAX_JSON_LEN -json_pos);
					}
					else if(device.type == 1)
					{
						strncpy(json_txt +json_pos, "\",\"ui_name\":\"ETHERNET (", MAX_JSON_LEN -json_pos);
						json_pos = strlen(json_txt);
						strncpy(json_txt +json_pos, device.interface, MAX_JSON_LEN -json_pos);
						json_pos = strlen(json_txt);
						strncpy(json_txt +json_pos, ")\",\"type\":2", MAX_JSON_LEN -json_pos);
					}

					json_pos = strlen(json_txt);
					strncpy(json_txt +json_pos, "}", MAX_JSON_LEN -json_pos);
				}
			}
			else
				printf("qaul_network_devices_json networkmanager_device_get_property failed\n");
		}
		else
			printf("qaul_network_devices_json Unknown current type [%i]\n", current_type);

		dbus_message_iter_next(&iter_array);
	}
	dbus_message_unref(msg);

	return 1;
}
Exemple #14
0
/**
 * get all properties of @a dbus_device_path as @a value struct via dbus @a connection
 *
 * network manager dbus methods are documented here:
 * https://developer.gnome.org/NetworkManager/unstable/spec.html#org.freedesktop.NetworkManager.Device
 */
static int networkmanager_device_properties(DBusConnection* dbus_connection, qaul_dbus_device_properties* device)
{
	DBusMessage* msg;
    DBusMessageIter iter, iter_array, iter_dict, iter_prop;
	DBusPendingCall* pending;
	int success, set_Type, set_Interface, set_State, current_type;
    char* property_ptr;
    char* key_ptr;
	networkmanager_property device_property;

    const char* dbus_interface = "org.freedesktop.NetworkManager.Device";

    // reset values
    set_Type = 0;
    set_Interface = 0;
    set_State = 0;
    device->type = 0;
    device->state = 0;
    strncpy(device->interface, "", sizeof(device->interface));

	msg = dbus_message_new_method_call(
									  "org.freedesktop.NetworkManager",
									  device->dbus_device_path,
									  "org.freedesktop.DBus.Properties",
									  "GetAll"
									  );

	if(msg == NULL)
	{
		printf("networkmanager_device_properties msg error\n");
		return 0;
	}

    dbus_message_iter_init_append(msg, &iter);
    dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &dbus_interface);

	// send dbus message
	// -1 is the default time out. Other time outs can be configured in milli seconds.
	success = dbus_connection_send_with_reply(dbus_connection, msg, &pending, -1);
	if(!success)
	{
		printf("networkmanager_device_properties dbus send error\n");
		return 0;
	}
	if(pending == NULL)
	{
		printf ("networkmanager_device_properties dbus calling error\n");
		return 0;
	}

	dbus_connection_flush(dbus_connection);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	dbus_pending_call_unref(pending);

	if(msg == NULL)
	{
		printf("networkmanager_device_properties msg error 2\n");
		return 0;
	}

	if(!dbus_message_iter_init(msg, &iter))
	{
		printf("networkmanager_device_properties dbus_message_iter_init error\n");
		dbus_message_unref(msg);
		return 0;
	}
	if(dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
	{
		printf("networkmanager_device_properties dbus_message_iter_get_arg_type return is not a DBUS_TYPE_ARRAY %i\n", dbus_message_iter_get_arg_type(&iter));
		if(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
		{
			dbus_message_iter_get_basic(&iter, &property_ptr);
			printf("networkmanager_device_properties error msg: %s\n", property_ptr);
		}
		dbus_message_unref(msg);
		return 0;
	}

	// loop over the array
	dbus_message_iter_recurse(&iter, &iter_array);
	while((current_type = dbus_message_iter_get_arg_type(&iter_array)) != DBUS_TYPE_INVALID)
	{
		// check if it is a dict entry
		if(dbus_message_iter_get_arg_type(&iter_array) == DBUS_TYPE_DICT_ENTRY)
		{
			dbus_message_iter_recurse(&iter_array, &iter_dict);
			// get key
			dbus_message_iter_get_basic(&iter_dict, &key_ptr);
			// get property
			if(dbus_message_iter_next(&iter_dict))
			{
				dbus_message_iter_recurse(&iter_dict, &iter_prop);
				if (strcmp(key_ptr, "Interface") == 0)
				{
					if(dbus_message_iter_get_arg_type(&iter_prop) == DBUS_TYPE_STRING)
					{
						dbus_message_iter_get_basic(&iter_prop, &property_ptr);
						strncpy(device->interface, property_ptr, sizeof(device->interface));
						printf("networkmanager_device_get_property interface %s\n", property_ptr);
						set_Interface = 1;
					}
					else
						printf("networkmanager_device_properties Interface not DBUS_TYPE_STRING %i\n", dbus_message_iter_get_arg_type(&iter_prop));
				}
				else if(strcmp(key_ptr, "DeviceType") == 0)
				{
					if(dbus_message_iter_get_arg_type(&iter_prop) == DBUS_TYPE_UINT32)
					{
						dbus_message_iter_get_basic(&iter_prop, &device->type);
						printf("networkmanager_device_get_property DeviceType %i\n", device->type);
						set_Type = 1;
					}
					else
						printf("networkmanager_device_properties DeviceType not DBUS_TYPE_UINT32 %i\n", dbus_message_iter_get_arg_type(&iter_prop));
				}
				else if(strcmp(key_ptr, "State") == 0)
				{
					if(dbus_message_iter_get_arg_type(&iter_prop) == DBUS_TYPE_UINT32)
					{
						dbus_message_iter_get_basic(&iter_prop, &device->state);
						printf("networkmanager_device_get_property State %i\n", device->state);
						set_State = 1;
					}
					else
						printf("networkmanager_device_properties state not DBUS_TYPE_UINT32 %i\n", dbus_message_iter_get_arg_type(&iter_prop));
				}
			}
		}
		dbus_message_iter_next(&iter_array);
	}
	dbus_message_unref(msg);

	// store dbus path
	printf("networkmanager_device_properties device_property.dbus_path\n");
	device_property.dbus_path = device->dbus_device_path;

	printf("networkmanager_device_properties device_property.dbus_interface\n");
	if(device->type == 2)
		device_property.dbus_interface = "org.freedesktop.NetworkManager.Device.Wireless";
	else if(device->type == 1)
		device_property.dbus_interface = "org.freedesktop.NetworkManager.Device.Wired";
	else device_property.dbus_interface = "";

	// retrieve Hardware address property only for known device types
	if(device->type == 1 || device->type == 2)
	{
		printf("networkmanager_device_properties device->mac\n");
		device_property.dbus_property_name = "PermHwAddress";
		device_property.value_string = device->mac;
		device_property.value_string_len = sizeof(device->mac);
	}

	if(strlen(device_property.dbus_interface)>0)
	{
		if(!networkmanager_get_property(dbus_connection, &device_property))
			printf("qaul_network_device_get_by_interface get %s property error\n", device_property.dbus_property_name);
	}
	else
		printf("qaul_network_device_get_by_interface no supported type for Hardware MAC address\n");

	if(!set_Type)
		printf("networkmanager_device_properties Device type not set.\n");
	if(!set_Interface)
		printf("networkmanager_device_properties Interface name not set\n");
	if(!set_State)
		printf("networkmanager_device_properties Device state not set\n");

	return 1;
}
Exemple #15
0
static void get_connections_reply(DBusPendingCall *call, void *user_data)
{
	DBusMessage *reply;
	DBusError error;
	DBusMessageIter array, dict;
	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
		DBUS_STRUCT_BEGIN_CHAR_AS_STRING
		DBUS_TYPE_OBJECT_PATH_AS_STRING
		DBUS_TYPE_ARRAY_AS_STRING
		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
		DBUS_TYPE_STRING_AS_STRING
		DBUS_TYPE_VARIANT_AS_STRING
		DBUS_DICT_ENTRY_END_CHAR_AS_STRING
		DBUS_STRUCT_END_CHAR_AS_STRING;

	if (dbus_pending_call_get_completed(call) == FALSE)
		return;

	DBG("");

	reply = dbus_pending_call_steal_reply(call);

	dbus_error_init(&error);

	if (dbus_set_error_from_message(&error, reply) == TRUE) {
		connman_error("%s", error.message);
		dbus_error_free(&error);
		goto done;
	}

	if (dbus_message_has_signature(reply, signature) == FALSE) {
		connman_error("vpnd signature \"%s\" does not match "
							"expected \"%s\"",
			dbus_message_get_signature(reply), signature);
		goto done;
	}

	if (dbus_message_iter_init(reply, &array) == FALSE)
		goto done;

	dbus_message_iter_recurse(&array, &dict);

	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
		DBusMessageIter value, properties;
		const char *path;

		dbus_message_iter_recurse(&dict, &value);
		dbus_message_iter_get_basic(&value, &path);

		dbus_message_iter_next(&value);
		dbus_message_iter_recurse(&value, &properties);

		add_connection(path, &properties, user_data);

		dbus_message_iter_next(&dict);
	}

done:
	dbus_message_unref(reply);

	dbus_pending_call_unref(call);
}
Exemple #16
0
static DBusMessage *properties_set(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct generic_data *data = user_data;
	DBusMessageIter iter, sub;
	struct interface_data *iface;
	const GDBusPropertyTable *property;
	const char *name, *interface;
	struct property_data *propdata;

	if (!dbus_message_iter_init(message, &iter))
		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
							"No arguments given");

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
					"Invalid argument type: '%c'",
					dbus_message_iter_get_arg_type(&iter));

	dbus_message_iter_get_basic(&iter, &interface);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
					"Invalid argument type: '%c'",
					dbus_message_iter_get_arg_type(&iter));

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
					"Invalid argument type: '%c'",
					dbus_message_iter_get_arg_type(&iter));

	dbus_message_iter_recurse(&iter, &sub);

	iface = find_interface(data->interfaces, interface);
	if (iface == NULL)
		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
					"No such interface '%s'", interface);

	property = find_property(iface->properties, name);
	if (property == NULL)
		return g_dbus_create_error(message,
						DBUS_ERROR_UNKNOWN_PROPERTY,
						"No such property '%s'", name);

	if (property->set == NULL)
		return g_dbus_create_error(message,
					DBUS_ERROR_PROPERTY_READ_ONLY,
					"Property '%s' is not writable", name);

	if (property->exists != NULL &&
			!property->exists(property, iface->user_data))
		return g_dbus_create_error(message,
						DBUS_ERROR_UNKNOWN_PROPERTY,
						"No such property '%s'", name);

	propdata = g_new(struct property_data, 1);
	propdata->id = next_pending_property++;
	propdata->message = dbus_message_ref(message);
	propdata->conn = connection;
	pending_property_set = g_slist_prepend(pending_property_set, propdata);

	property->set(property, &sub, propdata->id, iface->user_data);

	return NULL;
}
Exemple #17
0
static void configuration_create_reply(DBusPendingCall *call, void *user_data)
{
	DBusMessage *reply;
	DBusError error;
	DBusMessageIter iter;
	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
	const char *path;
	char *ident;
	struct connection_data *data;
	struct config_create_data *cb_data = user_data;

	if (dbus_pending_call_get_completed(call) == FALSE)
		return;

	DBG("user %p", cb_data);

	reply = dbus_pending_call_steal_reply(call);

	dbus_error_init(&error);

	if (dbus_set_error_from_message(&error, reply) == TRUE) {
		connman_error("dbus error: %s", error.message);
		dbus_error_free(&error);
		goto done;
	}

	if (dbus_message_has_signature(reply, signature) == FALSE) {
		connman_error("vpn configuration signature \"%s\" does not "
						"match expected \"%s\"",
			dbus_message_get_signature(reply), signature);
		goto done;
	}

	if (dbus_message_iter_init(reply, &iter) == FALSE)
		goto done;

	dbus_message_iter_get_basic(&iter, &path);

	/*
	 * Then try to connect the VPN as expected by ConnectProvider API
	 */
	ident = get_ident(path);

	data = g_hash_table_lookup(vpn_connections, ident);
	if (data == NULL) {
		/*
		 * Someone removed the data. We cannot really continue.
		 */
		DBG("Pending data not found for %s, cannot continue!", ident);
	} else {
		data->call = NULL;
		data->connect_pending = TRUE;

		if (data->cb_data == NULL)
			data->cb_data = cb_data;
		else
			DBG("Connection callback data already in use!");

		/*
		 * Connection is created in add_connections() after
		 * we have received the ConnectionAdded signal.
		 */

		DBG("cb %p msg %p", data->cb_data,
			data->cb_data ? data->cb_data->message : NULL);
	}

done:
	dbus_message_unref(reply);

	dbus_pending_call_unref(call);
}
Exemple #18
0
static void get_properties_update_fact_cb (DBusPendingCall *pending, void *user_data)
{
    DBusMessage *reply = NULL;
    DBusMessageIter iter, array_iter, dict_iter, variant_iter, uuid_iter;
    gchar **dbus_data = user_data;
    gchar *path = dbus_data[0];
    gchar *interface = dbus_data[1];
    gboolean is_hfp = FALSE, is_hsp = FALSE;
    OhmFact *bt_connected = NULL;

    g_free(dbus_data);

    if (pending == NULL) 
        goto error;

    reply = dbus_pending_call_steal_reply(pending);
    dbus_pending_call_unref(pending);
    pending = NULL;

    if (reply == NULL) {
        goto error;
    }

    if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
        goto error;
    }

    dbus_message_iter_init(reply, &iter);

    if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
        goto error;
    }

    dbus_message_iter_recurse(&iter, &array_iter);

    while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_DICT_ENTRY) {

        /* the arg type will be DBUS_TYPE_INVALID at the end of the
         * array */

        gchar *key = NULL;
        int type;

        /* process the dicts */
        dbus_message_iter_recurse(&array_iter, &dict_iter);

        /* key must be string */
        if (dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_STRING) {
            goto error;
        }
        dbus_message_iter_get_basic(&dict_iter, &key);

        /* go on to the value */
        dbus_message_iter_next(&dict_iter);

        dbus_message_iter_recurse(&dict_iter, &variant_iter);
        type = dbus_message_iter_get_arg_type(&variant_iter);

        if (strcmp(key, "UUIDs") == 0) {

            if (type == DBUS_TYPE_ARRAY) {
                dbus_message_iter_recurse(&variant_iter, &uuid_iter);
                while (dbus_message_iter_get_arg_type(&uuid_iter) == DBUS_TYPE_STRING) {
                    gchar *uuid = NULL;

                    dbus_message_iter_get_basic(&uuid_iter, &uuid);

                    if (!uuid)
                        break;

                    else if (strcmp(uuid, HFP_UUID) == 0) {
                        is_hfp = TRUE;
                    }
                    else if (strcmp(uuid, HSP_UUID) == 0) {
                        is_hsp = TRUE;
                    }
                    dbus_message_iter_next(&uuid_iter);
                }
            }
            else {
                OHM_DEBUG(DBG_BT, "Error: type '%u'\n",
                        dbus_message_iter_get_arg_type(&dict_iter));
            }
        }
        dbus_message_iter_next(&array_iter);
    }

    /* get the BT fact */
    OHM_DEBUG(DBG_BT, "Device %s %s HFP support",
            path, is_hfp ? "has" : "has not");

    OHM_DEBUG(DBG_BT, "Device %s %s HSP support",
            path, is_hsp ? "has" : "has not");

    if ((bt_connected = bt_get_connected(path)) != NULL) {

        GValue *gval_state = ohm_fact_get(bt_connected, BT_TYPE_HSP);
        GValue *gval_prev_state = ohm_fact_get(bt_connected, "bthsp_prev_state");
        const gchar *state = NULL, *prev_state = NULL;
        gboolean run_dres;

        define_hfp_status(bt_connected, is_hfp);
        define_hsp_status(bt_connected, is_hsp);

        if (gval_state != NULL &&
                G_VALUE_TYPE(gval_state) == G_TYPE_STRING) {
            state = g_value_get_string(gval_state);
        }

        if (gval_prev_state != NULL &&
                G_VALUE_TYPE(gval_prev_state) == G_TYPE_STRING) {
            prev_state = g_value_get_string(gval_prev_state);
        }

        OHM_DEBUG(DBG_BT, "running state transition from %s to %s from HFP/HSP status cb",
                prev_state ? prev_state : "NULL", state ? state : "NULL");

        run_dres = bt_state_transition(BT_TYPE_HSP, path, 
                map_to_state(prev_state), map_to_state(state));

        dres_all();
    }

error:

    if (reply)
        dbus_message_unref (reply);

    g_free(path);
    g_free(interface);

    return;
}
void VolumeBarLogic::initValues ()
{
    DBusMessage *msg;
    DBusMessage *reply;
    DBusError    error;

    dbus_error_init (&error);

    msg = dbus_message_new_method_call (VOLUME_SV,
                                        VOLUME_PATH,
                                        "org.freedesktop.DBus.Properties",
                                        "GetAll");
    const char *volume_if = VOLUME_IF;
    dbus_message_append_args (msg,
                              DBUS_TYPE_STRING, &volume_if,
                              DBUS_TYPE_INVALID);

    reply =
        dbus_connection_send_with_reply_and_block (
                        dbus_conn, msg, -1, &error);

    DBUS_ERR_CHECK (error);

    dbus_message_unref (msg);

    if (reply && (dbus_message_get_type (reply) ==
                  DBUS_MESSAGE_TYPE_METHOD_RETURN)) {
        DBusMessageIter iter;
        dbus_message_iter_init (reply, &iter);
        // Recurse into the array [array of dicts]
        while (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
            DBusMessageIter dict_entry;
            dbus_message_iter_recurse (&iter, &dict_entry);

            // Recurse into the dict [ dict_entry (string, variant(int)) ]
            while (dbus_message_iter_get_arg_type (&dict_entry) != DBUS_TYPE_INVALID) {
                DBusMessageIter in_dict;
                // Recurse into the dict_entry [ string, variant(int) ]
                dbus_message_iter_recurse (&dict_entry, &in_dict);
                {
                  char *prop_name = NULL;
                  // Get the string value, "property name"
                  dbus_message_iter_get_basic (&in_dict, &prop_name);

                  dbus_message_iter_next (&in_dict);

                  DBusMessageIter variant;
                  // Recurese into the variant [ variant(int) ]
                  dbus_message_iter_recurse (&in_dict, &variant);

                  quint32 value;
                  // Get the variant value which is uint32
                  dbus_message_iter_get_basic (&variant, &value);

                  if (prop_name &&
                      strcmp (prop_name, "StepCount") == 0)
                    currentmax = value;
                  else if (prop_name &&
                           strcmp (prop_name, "CurrentStep") == 0)
                    currentvolume = value;
                }

                dbus_message_iter_next (&dict_entry);
            }
            dbus_message_iter_next (&iter);
        }
    }

    if (reply)
        dbus_message_unref (reply);

    addSignalMatch ();
}
Exemple #20
0
static void get_properties_cb (DBusPendingCall *pending, void *user_data)
{

    DBusMessage *reply = NULL;
    DBusMessageIter iter, array_iter, dict_iter, variant_iter, uuid_iter;
    gchar **dbus_data = user_data;
    gchar *path = dbus_data[0];
    gchar *interface = dbus_data[1];
    gboolean is_hsp = FALSE, is_a2dp = FALSE, is_hfp = FALSE;
    gchar *state = NULL;

    g_free(dbus_data);

    if (pending == NULL) 
        goto error;

    reply = dbus_pending_call_steal_reply(pending);
    dbus_pending_call_unref(pending);
    pending = NULL;

    if (reply == NULL) {
        goto error;
    }

    if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
        goto error;
    }

    dbus_message_iter_init(reply, &iter);

    if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
        goto error;
    }

    dbus_message_iter_recurse(&iter, &array_iter);

    while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_DICT_ENTRY) {

        /* the arg type will be DBUS_TYPE_INVALID at the end of the
         * array */

        gchar *key = NULL;
        int type;

        /* process the dicts */
        dbus_message_iter_recurse(&array_iter, &dict_iter);

        /* key must be string */
        if (dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_STRING) {
            goto error;
        }
        dbus_message_iter_get_basic(&dict_iter, &key);

        /* go on to the value */
        dbus_message_iter_next(&dict_iter);

        dbus_message_iter_recurse(&dict_iter, &variant_iter);
        type = dbus_message_iter_get_arg_type(&variant_iter);

        if (strcmp(key, "UUIDs") == 0) {

            if (type == DBUS_TYPE_ARRAY) {
                dbus_message_iter_recurse(&variant_iter, &uuid_iter);
                while (dbus_message_iter_get_arg_type(&uuid_iter) == DBUS_TYPE_STRING) {
                    gchar *uuid = NULL;

                    dbus_message_iter_get_basic(&uuid_iter, &uuid);

                    if (!uuid)
                        break;

                    if (strcmp(uuid, HSP_UUID) == 0) {
                        is_hsp = TRUE;
                    }
                    else if (strcmp(uuid, HFP_UUID) == 0) {
                        is_hfp = TRUE;
                    }
                    else if (strcmp(uuid, A2DP_UUID) == 0) {
                        is_a2dp = TRUE;
                    }
                    dbus_message_iter_next(&uuid_iter);
                }
            }
            else {
                OHM_DEBUG(DBG_BT, "Error: type '%u'\n", dbus_message_iter_get_arg_type(&dict_iter));
            }
        }
        else if (strcmp(key, "State") == 0) {
            if (type == DBUS_TYPE_STRING) {
                dbus_message_iter_get_basic(&variant_iter, &state);
            }
        }
#if 0
        else if (strcmp(key, "Connected") == 0) {
            if (type == DBUS_TYPE_BOOLEAN) {
                dbus_message_iter_get_basic(&variant_iter, &is_connected);
            }
        }
#endif
        else {
            /* OHM_DEBUG(DBG_BT, "Non-handled key '%s'\n", key); */
        }

        dbus_message_iter_next(&array_iter);
    }

    OHM_DEBUG(DBG_BT, "Device '%s' (%s): has_a2dp=%i, has_hsp=%i, has_hfp=%i, state=%s\n",
            path, interface, is_a2dp, is_hsp, is_hfp, state ? state : "to be queried");

    /* now the beef: if an audio device was there, let's mark it
     * present */

    if (strcmp(interface, BT_INTERFACE_DEVICE) == 0) {
        if (is_a2dp) {
            get_properties(path, BT_INTERFACE_A2DP, get_properties_cb);
        }
        if (is_hsp || is_hfp) {
            get_properties(path, BT_INTERFACE_HSP, get_properties_cb);
        }
    }

    else if (strcmp(interface, BT_INTERFACE_HSP) == 0 &&
            state != NULL) {
        bt_state_changed(BT_TYPE_HSP, path, state);
    }
    else if (strcmp(interface, BT_INTERFACE_A2DP) == 0 &&
            state != NULL) {
        bt_state_changed(BT_TYPE_A2DP, path, state);
    }

error:

    if (reply)
        dbus_message_unref (reply);

    g_free(path);
    g_free(interface);

    return;
}
/*
 * Here we register our desktop autostart id mate-session style
 * session manager via DBus.
 */
void
gkd_dbus_session_init (DBusConnection *conn)
{
	DBusMessageIter args;
	DBusMessage *msg;
	DBusMessage *reply;
	DBusError derr = { 0 };
	const gchar *app_id = "mate-keyring-daemon";
	const gchar *client_id;

	client_id = g_getenv ("DESKTOP_AUTOSTART_ID");
	if (!client_id)
		return;

	msg = dbus_message_new_method_call (SERVICE_SESSION_MANAGER,
	                                    PATH_SESSION_MANAGER,
	                                    IFACE_SESSION_MANAGER,
	                                    "RegisterClient");
	g_return_if_fail (msg);

	dbus_message_iter_init_append (msg, &args);
	if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &app_id) ||
	    !dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &client_id))
		g_return_if_reached ();

	/* Send message and get a handle for a reply */
	reply = dbus_connection_send_with_reply_and_block (conn, msg, 1000, &derr);
	dbus_message_unref (msg);

	if (!reply) {
		g_message ("couldn't register in session: %s", derr.message);
		dbus_error_free (&derr);
		return;
	}

	/* Get out our client path */
	if (!dbus_message_iter_init (reply, &args) ||
	    dbus_message_iter_get_arg_type (&args) != DBUS_TYPE_OBJECT_PATH) {
		g_message ("invalid register response from session");
	} else {
		dbus_message_iter_get_basic (&args, &client_session_path);
		client_session_path = g_strdup (client_session_path);
	}

	dbus_message_unref (reply);

	/*
	 * Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
	 * use the same client id.
	 */
	g_unsetenv ("DESKTOP_AUTOSTART_ID");

	/*
	 * Now we register for DBus signals on that client session path
	 * These are fired specifically for us.
	 */
	client_session_rule = g_strdup_printf("type='signal',"
	                                      "interface='org.mate.SessionManager.ClientPrivate',"
	                                      "path='%s'",
	                                      client_session_path);
	dbus_bus_add_match (conn, client_session_rule, &derr);

	if(dbus_error_is_set(&derr)) {
		g_message ("couldn't listen for signals in session: %s", derr.message);
		dbus_error_free (&derr);
		g_free (client_session_rule);
		client_session_rule = NULL;
		return;
	}

	dbus_connection_add_filter (conn, signal_filter, NULL, NULL);
}
Exemple #22
0
static DBusMessage *modem_set_property(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct ofono_modem *modem = data;
	DBusMessageIter iter, var;
	const char *name;

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return __ofono_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return __ofono_error_invalid_args(msg);

	if (powering_down == TRUE)
		return __ofono_error_failed(msg);

	dbus_message_iter_recurse(&iter, &var);

	if (g_str_equal(name, "Online"))
		return set_property_online(modem, msg, &var);

	if (g_str_equal(name, "Powered") == TRUE) {
		ofono_bool_t powered;
		int err;

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &powered);

		if (modem->pending != NULL)
			return __ofono_error_busy(msg);

		if (modem->powered == powered)
			return dbus_message_new_method_return(msg);

		if (ofono_modem_get_emergency_mode(modem) == TRUE)
			return __ofono_error_emergency_active(msg);

		if (modem->lockdown)
			return __ofono_error_access_denied(msg);

		err = set_powered(modem, powered);
		if (err < 0) {
			if (err != -EINPROGRESS)
				return __ofono_error_failed(msg);

			modem->pending = dbus_message_ref(msg);
			modem->timeout = g_timeout_add_seconds(20,
						set_powered_timeout, modem);
			return NULL;
		}

		g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);

		ofono_dbus_signal_property_changed(conn, modem->path,
						OFONO_MODEM_INTERFACE,
						"Powered", DBUS_TYPE_BOOLEAN,
						&powered);

		if (powered) {
			modem_change_state(modem, MODEM_STATE_PRE_SIM);

			/* Force SIM Ready for devies with no sim atom */
			if (modem_has_sim(modem) == FALSE)
				sim_state_watch(OFONO_SIM_STATE_READY, modem);
		} else {
			set_online(modem, FALSE);
			modem_change_state(modem, MODEM_STATE_POWER_OFF);
		}

		return NULL;
	}

	if (g_str_equal(name, "Lockdown"))
		return set_property_lockdown(modem, msg, &var);

	return __ofono_error_invalid_args(msg);
}
gchar *
gsm_consolekit_get_current_session_type (GsmConsolekit *manager)
{
        GError *gerror;
	DBusConnection *connection;
	DBusError error;
	DBusMessage *message = NULL;
	DBusMessage *reply = NULL;
	gchar *session_id;
	gchar *ret;
	DBusMessageIter iter;
	const char *value;

	session_id = NULL;
	ret = NULL;
        gerror = NULL;

        if (!gsm_consolekit_ensure_ck_connection (manager, &gerror)) {
                g_warning ("Could not connect to ConsoleKit: %s",
                           gerror->message);
                g_error_free (gerror);
		goto out;
        }

	connection = dbus_g_connection_get_connection (manager->priv->dbus_connection);
	if (!get_current_session_id (connection, &session_id)) {
		goto out;
	}

	dbus_error_init (&error);
	message = dbus_message_new_method_call (CK_NAME,
						session_id,
						CK_SESSION_INTERFACE,
						"GetSessionType");
	if (message == NULL) {
		goto out;
	}

	reply = dbus_connection_send_with_reply_and_block (connection,
							   message,
							   -1,
							   &error);

	if (reply == NULL) {
		if (dbus_error_is_set (&error)) {
			g_warning ("Unable to determine session type: %s", error.message);
			dbus_error_free (&error);
		}
		goto out;
	}

	dbus_message_iter_init (reply, &iter);
	dbus_message_iter_get_basic (&iter, &value);
	ret = g_strdup (value);

out:
	if (message != NULL) {
		dbus_message_unref (message);
	}
	if (reply != NULL) {
		dbus_message_unref (reply);
	}
	g_free (session_id);

	return ret;
}
Exemple #24
0
static
DBusHandlerResult
profile_tracker_filter(DBusConnection *conn,
                       DBusMessage *msg,
                       void *user_data)
{
  (void)conn; (void)user_data;

  DBusHandlerResult   result    = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
  const char         *interface = dbus_message_get_interface(msg);
  const char         *member    = dbus_message_get_member(msg);
  const char         *object    = dbus_message_get_path(msg);
  int                 type      = dbus_message_get_type(msg);

#if 0
  const char         *typename  = "UNKNOWN";
  switch( type )
  {
  case DBUS_MESSAGE_TYPE_INVALID:       typename = "INVALID"; break;
  case DBUS_MESSAGE_TYPE_METHOD_CALL:   typename = "M-CALL"; break;
  case DBUS_MESSAGE_TYPE_METHOD_RETURN: typename = "M-RET"; break;
  case DBUS_MESSAGE_TYPE_ERROR:         typename = "ERROR"; break;
  case DBUS_MESSAGE_TYPE_SIGNAL:        typename = "SIGNAL"; break;
  }
  log_debug("%s: %s, %s, %s\n", typename, interface, object, member);
#endif

  if( !interface || !member || !object )
  {
    goto cleanup;
  }

  if( type == DBUS_MESSAGE_TYPE_SIGNAL &&
      !strcmp(interface, PROFILED_SERVICE) &&
      !strcmp(object, PROFILED_PATH) &&
      !strcmp(member, PROFILED_CHANGED) )
  {
    DBusMessageIter iter;
    DBusMessageIter item;

    int         changed = 0;
    int         active  = 0;
    const char *profile = 0;

    dbus_message_iter_init(msg, &iter);

    if( decode_bool(&iter, &changed) || decode_bool(&iter, &active) ||
        decode_string(&iter, &profile) )
    {
      goto cleanup;
    }

    if( changed != 0 )
    {
      profile_track_profile(profile);
    }

    dbus_message_iter_recurse(&iter, &item);

    const char *key, *val, *type;

    while( decode_triplet(&item, &key,&val,&type) == 0 )
    {
      if( active != 0 )
      {
        profile_track_active(profile, key,val,type);
      }
      else
      {
        profile_track_change(profile, key,val,type);
      }
    }
  }

  cleanup:

  return result;
}
Exemple #25
0
/**
 * Call a method on a remote object
 */
void send_method_call(const char* param) 
{
   DBusMessage* msg;
   DBusMessageIter args;
   DBusPendingCall* pending;
   int ret;
   double level;

   printf("Calling remote method with %s\n", param);

   // create a new method call and check for errors
   msg = dbus_message_new_method_call( SERVER_BUS_NAME , // target for the method call
                                       BUS_METHODS_OBJECT, // object to call on
                                       SERVER_METHOD_INTERFACE, // interface to call on
                                       param); // method name
   if (NULL == msg) { 
      fprintf(stderr, "Message Null\n");
      exit(1);
   }

   // append arguments
   dbus_message_iter_init_append(msg, &args);
   if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &param)) {
      fprintf(stderr, "Out Of Memory!\n"); 
      exit(1);
   }
   
   // send message and get a handle for a reply
   if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
      fprintf(stderr, "Out Of Memory!\n"); 
      exit(1);
   }
   if (NULL == pending) { 
      fprintf(stderr, "Pending Call Null\n"); 
      exit(1); 
   }
   dbus_connection_flush(conn);
   
   printf("Request Sent\n");
   
   // free message
   dbus_message_unref(msg);
   
   // block until we recieve a reply
   dbus_pending_call_block(pending);

   // get the reply message
   msg = dbus_pending_call_steal_reply(pending);
   if (NULL == msg) {
      fprintf(stderr, "Reply Null\n"); 
      exit(1); 
   }
   // free the pending message handle
   dbus_pending_call_unref(pending);

   printf("Got Reply: \n");

   // read the parameters
   if (!dbus_message_iter_init(msg, &args))
      fprintf(stderr, "Message has no arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);
  
   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);
  
   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);
  
   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n"); 
   else if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&args)) 
      fprintf(stderr, "Argument is not double!\n"); 
   else
      dbus_message_iter_get_basic(&args, &level);
	printf("%lf\n", level);
   
   // free reply and close connection
   dbus_message_unref(msg);   
}
DBusHandlerResult
my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object,
                                        NihDBusMessage *message)
{
	DBusMessageIter    iter;
	DBusMessage *      reply;
	MyMethodStructure *structure;
	DBusMessageIter    structure_iter;
	const char *       structure_item0;
	uint32_t           structure_item1;

	nih_assert (object != NULL);
	nih_assert (message != NULL);

	/* Iterate the arguments to the message and demarshal into arguments
	 * for our own function call.
	 */
	dbus_message_iter_init (message->message, &iter);

	if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
		reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
		                                "Invalid arguments to Method method");
		if (! reply)
			return DBUS_HANDLER_RESULT_NEED_MEMORY;

		if (! dbus_connection_send (message->connection, reply, NULL)) {
			dbus_message_unref (reply);
			return DBUS_HANDLER_RESULT_NEED_MEMORY;
		}

		dbus_message_unref (reply);
		return DBUS_HANDLER_RESULT_HANDLED;
	}

	/* Call the handler function */
	nih_error_push_context ();
	if (my_method (object->data, message, &structure) < 0) {
		NihError *err;

		err = nih_error_get ();
		if (err->number == ENOMEM) {
			nih_free (err);
			nih_error_pop_context ();

			return DBUS_HANDLER_RESULT_NEED_MEMORY;
		} else if (err->number == NIH_DBUS_ERROR) {
			NihDBusError *dbus_err = (NihDBusError *)err;

			reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
			nih_free (err);
			nih_error_pop_context ();

			NIH_MUST (dbus_connection_send (message->connection, reply, NULL));

			dbus_message_unref (reply);
			return DBUS_HANDLER_RESULT_HANDLED;
		} else {
			reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
			nih_free (err);
			nih_error_pop_context ();

			NIH_MUST (dbus_connection_send (message->connection, reply, NULL));

			dbus_message_unref (reply);
			return DBUS_HANDLER_RESULT_HANDLED;
		}
	}
	nih_error_pop_context ();

	/* If the sender doesn't care about a reply, don't bother wasting
	 * effort constructing and sending one.
	 */
	if (dbus_message_get_no_reply (message->message))
		return DBUS_HANDLER_RESULT_HANDLED;

	do {
		__label__ enomem;

		/* Construct the reply message. */
		reply = dbus_message_new_method_return (message->message);
		if (! reply)
			goto enomem;

		dbus_message_iter_init_append (reply, &iter);

		/* Marshal a structure onto the message */
		if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) {
			dbus_message_unref (reply);
			reply = NULL;
			goto enomem;
		}

		structure_item0 = structure->item0;

		/* Marshal a char * onto the message */
		if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) {
			dbus_message_iter_abandon_container (&iter, &structure_iter);
			dbus_message_unref (reply);
			reply = NULL;
			goto enomem;
		}

		structure_item1 = structure->item1;

		/* Marshal a uint32_t onto the message */
		if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) {
			dbus_message_iter_abandon_container (&iter, &structure_iter);
			dbus_message_unref (reply);
			reply = NULL;
			goto enomem;
		}

		if (! dbus_message_iter_close_container (&iter, &structure_iter)) {
			dbus_message_unref (reply);
			reply = NULL;
			goto enomem;
		}
	enomem: __attribute__ ((unused));
	} while (! reply);

	/* Send the reply, appending it to the outgoing queue. */
	NIH_MUST (dbus_connection_send (message->connection, reply, NULL));

	dbus_message_unref (reply);

	return DBUS_HANDLER_RESULT_HANDLED;
}
Exemple #27
0
static void request_input_reply(DBusMessage *reply, void *user_data)
{
	struct request_input_reply *l2tp_reply = user_data;
	const char *error = NULL;
	char *username = NULL, *password = NULL;
	char *key;
	DBusMessageIter iter, dict;

	DBG("provider %p", l2tp_reply->provider);

	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
		error = dbus_message_get_error_name(reply);
		goto done;
	}

	if (!vpn_agent_check_reply_has_dict(reply))
		goto done;

	dbus_message_iter_init(reply, &iter);
	dbus_message_iter_recurse(&iter, &dict);
	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;
		const char *str;

		dbus_message_iter_recurse(&dict, &entry);
		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
			break;

		dbus_message_iter_get_basic(&entry, &key);

		if (g_str_equal(key, "Username")) {
			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			if (dbus_message_iter_get_arg_type(&value)
							!= DBUS_TYPE_STRING)
				break;
			dbus_message_iter_get_basic(&value, &str);
			username = g_strdup(str);
		}

		if (g_str_equal(key, "Password")) {
			dbus_message_iter_next(&entry);
			if (dbus_message_iter_get_arg_type(&entry)
							!= DBUS_TYPE_VARIANT)
				break;
			dbus_message_iter_recurse(&entry, &value);
			if (dbus_message_iter_get_arg_type(&value)
							!= DBUS_TYPE_STRING)
				break;
			dbus_message_iter_get_basic(&value, &str);
			password = g_strdup(str);
		}

		dbus_message_iter_next(&dict);
	}

done:
	l2tp_reply->callback(l2tp_reply->provider, username, password, error,
				l2tp_reply->user_data);

	g_free(username);
	g_free(password);

	g_free(l2tp_reply);
}
Exemple #28
0
static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
{
	DBusMessage *new_msg = NULL;
	DBusPendingCall *call;
	DBusMessageIter iter, array, new_iter, new_dict;
	const char *type = NULL, *name = NULL;
	const char *host = NULL, *domain = NULL;
	char *ident, *me = NULL;
	int err = 0;
	dbus_bool_t result;
	struct connection_data *data;
	struct config_create_data *user_data = NULL;
	GSList *networks = NULL;

	/*
	 * We copy the old message data into new message. We cannot
	 * just use the old message as is because the user route
	 * information is not in the same format in vpnd.
	 */
	new_msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
	dbus_message_iter_init_append(new_msg, &new_iter);
	connman_dbus_dict_open(&new_iter, &new_dict);

	dbus_message_iter_init(msg, &iter);
	dbus_message_iter_recurse(&iter, &array);

	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;
		void *item_value;
		const char *key;
		int value_type;

		dbus_message_iter_recurse(&array, &entry);
		dbus_message_iter_get_basic(&entry, &key);

		dbus_message_iter_next(&entry);
		dbus_message_iter_recurse(&entry, &value);

		value_type = dbus_message_iter_get_arg_type(&value);
		item_value = NULL;

		switch (value_type) {
		case DBUS_TYPE_STRING:
			dbus_message_iter_get_basic(&value, &item_value);

			if (g_str_equal(key, "Type") == TRUE) {
				type = (const char *)item_value;
			} else if (g_str_equal(key, "Name") == TRUE) {
				name = (const char *)item_value;
			} else if (g_str_equal(key, "Host") == TRUE) {
				host = (const char *)item_value;
			} else if (g_str_equal(key, "VPN.Domain") == TRUE) {
				domain = (const char *)item_value;
			}

			DBG("%s %s", key, (char *)item_value);

			if (item_value != NULL)
				connman_dbus_dict_append_basic(&new_dict, key,
						value_type, &item_value);
			break;
		case DBUS_TYPE_ARRAY:
			if (g_str_equal(key, "Networks") == TRUE) {
				networks = get_user_networks(&value);
				connman_dbus_dict_append_array(&new_dict,
							"UserRoutes",
							DBUS_TYPE_DICT_ENTRY,
							append_routes,
							networks);
			}
			break;
		}

		dbus_message_iter_next(&array);
	}

	connman_dbus_dict_close(&new_iter, &new_dict);

	DBG("VPN type %s name %s host %s domain %s networks %p",
		type, name, host, domain, networks);

	if (host == NULL || domain == NULL) {
		err = -EINVAL;
		goto done;
	}

	if (type == NULL || name == NULL) {
		err = -EOPNOTSUPP;
		goto done;
	}

	ident = g_strdup_printf("%s_%s", host, domain);
	set_dbus_ident(ident);

	DBG("ident %s", ident);

	data = g_hash_table_lookup(vpn_connections, ident);
	if (data != NULL) {
		if (data->call != NULL || data->cb_data != NULL) {
			DBG("create configuration call already pending");
			err = -EINPROGRESS;
			goto done;
		}
	} else {
		char *path = g_strdup_printf("%s/connection/%s", VPN_PATH,
								ident);
		data = create_connection_data(path);
		g_free(path);

		if (data == NULL) {
			err = -ENOMEM;
			goto done;
		}

		g_hash_table_insert(vpn_connections, g_strdup(ident), data);
	}

	/*
	 * User called net.connman.Manager.ConnectProvider if we are here.
	 * So use the data from original message in the new msg.
	 */
	me = g_strdup(dbus_message_get_destination(msg));

	dbus_message_set_interface(new_msg, VPN_MANAGER_INTERFACE);
	dbus_message_set_path(new_msg, "/");
	dbus_message_set_destination(new_msg, VPN_SERVICE);
	dbus_message_set_sender(new_msg, me);
	dbus_message_set_member(new_msg, "Create");

	user_data = g_try_new0(struct config_create_data, 1);
	if (user_data == NULL) {
		err = -ENOMEM;
		goto done;
	}

	user_data->callback = callback;
	user_data->message = dbus_message_ref(msg);
	user_data->path = NULL;

	DBG("cb %p msg %p", user_data, msg);

	result = dbus_connection_send_with_reply(connection, new_msg,
						&call, DBUS_TIMEOUT);
	if (result == FALSE || call == NULL) {
		err = -EIO;
		goto done;
	}

	dbus_pending_call_set_notify(call, configuration_create_reply,
							user_data, NULL);
	data->call = call;

done:
	if (new_msg != NULL)
		dbus_message_unref(new_msg);

	if (networks != NULL)
		g_slist_free_full(networks, destroy_route);

	g_free(me);
	return err;
}
Exemple #29
0
static void get_properties(DBusConnection *conn)
{
    DBusError err;
    DBusMessage *msg;
    DBusMessageIter iter, dict, dict_key, dict_value;
    dbus_bool_t bValue;
    dbus_uint32_t iValue;

    char key[255];
    char value[255];
    char *ckey;
    char *cValue;
    // int i = 0;

    dbus_error_init(&err);

    msg = dbus_message_new_method_call(DBUS_NAME,DBUS_PATH, DBUS_INTERFACE_APAPTER,
                                       "GetProperties");
    if (msg == NULL)
    {
        printf("%s %d msg is null\n", __func__, __LINE__);
        exit(1);
    }

    msg = excute_method_a(conn, msg);

    dbus_message_iter_init(msg, &iter);
    dbus_message_iter_recurse(&iter, &dict);

    do
    {
        memset(key, 0, 255);
        memset(value, 0, 255);

        dbus_message_iter_recurse(&dict, &dict_key);
        dbus_message_iter_get_basic(&dict_key, &ckey);

        strcpy(key, ckey);

        // printf("%s %d key:%s\n", __func__, __LINE__, key);

        if (!strcmp(key, "Name"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &cValue);
            strcpy(value, cValue);
            printf("%s:  %s\n", key, value);
        }
        else if(!strcmp(key, "Address"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &cValue);
            strcpy(value, cValue);
            printf("%s:  %s\n", key, value);
        }
        //Discoverable
        else if(!strcmp(key, "Discoverable"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //DiscoverableTimeout
        else if(!strcmp(key, "DiscoverableTimeout"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &iValue);
            printf("%s:  %d\n", key, iValue);
        }
        //Discovering
        else if(!strcmp(key, "Discovering"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //Pairable
        else if(!strcmp(key, "Pairable"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //PairableTimeout
        else if(!strcmp(key, "PairableTimeout"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &iValue);
            printf("%s:  %d\n", key, iValue);
        }
        //Powerd
        else if(!strcmp(key, "Powered"))
        {
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_get_basic(&dict_value, &bValue);
            printf("%s:  %d\n", key, bValue);
        }
        //Devices
        else if(!strcmp(key, "Devices"))
        {
            DBusMessageIter device_array;
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_recurse(&dict_value, &device_array);

            if (dbus_message_iter_get_arg_type(&device_array) != DBUS_TYPE_OBJECT_PATH)
            {
                printf("%s:  0\n", key);
                continue;
            }

            // i = 0;
            do
            {
                dbus_message_iter_get_basic(&device_array, &cValue);
                strcpy(value, cValue);
                // printf("%s %d %s %d: %s\n", __func__, __LINE__, key, ++i, value);
            } while (dbus_message_iter_next(&device_array));

        }
        //UUIDs
        else if(!strcmp(key, "UUIDs"))
        {
            DBusMessageIter device_array;
            dbus_message_iter_next(&dict_key);
            dbus_message_iter_recurse(&dict_key, &dict_value);
            dbus_message_iter_recurse(&dict_value, &device_array);

            do
            {
                dbus_message_iter_get_basic(&device_array, &cValue);
            } while(dbus_message_iter_next(&device_array));
        }
        else
        {
            printf("%s: Not to supported \n",key);
        }

    } while (dbus_message_iter_next(&dict));

    dbus_error_free(&err);
}
static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m, void *userdata) {
    pa_bluetooth_backend *b = userdata;
    pa_bluetooth_device *d;
    pa_bluetooth_transport *t;
    pa_bluetooth_profile_t p;
    DBusMessage *r;
    int fd;
    const char *sender, *path, PA_UNUSED *handler;
    DBusMessageIter arg_i;
    char *pathfd;
    struct transport_rfcomm *trfc;

    if (!dbus_message_iter_init(m, &arg_i) || !pa_streq(dbus_message_get_signature(m), "oha{sv}")) {
        pa_log_error("Invalid signature found in NewConnection");
        goto fail;
    }

    handler = dbus_message_get_path(m);
    pa_assert(pa_streq(handler, HSP_AG_PROFILE));

    pa_assert(dbus_message_iter_get_arg_type(&arg_i) == DBUS_TYPE_OBJECT_PATH);
    dbus_message_iter_get_basic(&arg_i, &path);

    d = pa_bluetooth_discovery_get_device_by_path(b->discovery, path);
    if (d == NULL) {
        pa_log_error("Device doesnt exist for %s", path);
        goto fail;
    }

    pa_assert_se(dbus_message_iter_next(&arg_i));

    pa_assert(dbus_message_iter_get_arg_type(&arg_i) == DBUS_TYPE_UNIX_FD);
    dbus_message_iter_get_basic(&arg_i, &fd);

    pa_log_debug("dbus: NewConnection path=%s, fd=%d", path, fd);

    sender = dbus_message_get_sender(m);

    p = PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT;
    pathfd = pa_sprintf_malloc ("%s/fd%d", path, fd);
    d->transports[p] = t = pa_bluetooth_transport_new(d, sender, pathfd, p, NULL, 0);
    pa_xfree(pathfd);

    t->acquire = bluez5_sco_acquire_cb;
    t->release = bluez5_sco_release_cb;
    t->destroy = transport_destroy;
    t->set_speaker_gain = set_speaker_gain;
    t->set_microphone_gain = set_microphone_gain;

    trfc = pa_xnew0(struct transport_rfcomm, 1);
    trfc->rfcomm_fd = fd;
    trfc->mainloop = b->core->mainloop;
    trfc->rfcomm_io = trfc->mainloop->io_new(b->core->mainloop, fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP,
        rfcomm_io_callback, t);
    t->userdata =  trfc;

    pa_bluetooth_transport_put(t);

    pa_log_debug("Transport %s available for profile %s", t->path, pa_bluetooth_profile_to_string(t->profile));

    pa_assert_se(r = dbus_message_new_method_return(m));

    return r;

fail:
    pa_assert_se(r = dbus_message_new_error(m, "org.bluez.Error.InvalidArguments", "Unable to handle new connection"));
    return r;
}