[pulseaudio-discuss] [RFC v0 2/3] bluetooth: Replace deprecated ListAdapters()

Tanu Kaskinen tanuk at iki.fi
Wed Jul 25 22:59:15 PDT 2012


On Wed, 2012-07-25 at 16:29 +0200, Mikel Astiz wrote:
> +static int parse_manager_property(pa_bluetooth_discovery *y, DBusMessageIter *i) {
> +    const char *key;
> +    DBusMessageIter variant_i;
> +
> +    pa_assert(y);
> +
> +    key = check_variant_property(i);
> +    if (key == NULL)
> +	return -1;

The same tab (see my previous message) spotted here too.

> +
> +    dbus_message_iter_recurse(i, &variant_i);
> +
> +    switch (dbus_message_iter_get_arg_type(&variant_i)) {
> +
> +        case DBUS_TYPE_ARRAY: {
> +
> +            DBusMessageIter ai;
> +            dbus_message_iter_recurse(&variant_i, &ai);
> +
> +            if (dbus_message_iter_get_arg_type(&ai) == DBUS_TYPE_OBJECT_PATH &&
> +                pa_streq(key, "Adapters")) {
> +
> +                while (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_INVALID) {
> +                    const char *value;
> +
> +                    dbus_message_iter_get_basic(&ai, &value);
> +
> +                    found_adapter(y, value);
> +
> +                    if (!dbus_message_iter_next(&ai))
> +                        break;

No need to check dbus_message_iter_next() return value here. The loop
will terminate anyway, because dbus_message_iter_get_arg_type() will
return DBUS_TYPE_INVALID.

> @@ -430,7 +472,8 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) {
>      /* We don't use p->call_data here right-away since the device
>       * might already be invalidated at this point */
>  
> -    if (!(d = pa_hashmap_get(y->devices, dbus_message_get_path(p->message))))
> +    d = pa_hashmap_get(y->devices, dbus_message_get_path(p->message));
> +    if (d == NULL && !dbus_message_has_interface(p->message, "org.bluez.Manager"))
>          return;
>  
>      pa_assert(p->call_data == d);
> @@ -469,7 +512,11 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) {
>  
>              dbus_message_iter_recurse(&element_i, &dict_i);
>  
> -            if (dbus_message_has_interface(p->message, "org.bluez.Device")) {
> +            if (dbus_message_has_interface(p->message, "org.bluez.Manager")) {
> +                if (parse_manager_property(y, &dict_i) < 0)
> +                    goto finish;
> +
> +            } else if (dbus_message_has_interface(p->message, "org.bluez.Device")) {
>                  if (parse_device_property(y, d, &dict_i) < 0)
>                      goto finish;
>  
> @@ -501,7 +548,8 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) {
>      }
>  
>  finish:
> -    run_callback(y, d, FALSE);
> +    if (d != NULL)
> +        run_callback(y, d, FALSE);

We don't want to call run_callback() when we have processed Manager
properties, but the "d != NULL" check doesn't check that. It checks that
did the message come from an object path that has previously been
associated with a device. If we get Manager properties from a device
object, then run_callback() will be called. It of course also means that
bluetoothd is broken, but we should protect us against broken
bluetoothd.

-- 
Tanu



More information about the pulseaudio-discuss mailing list