mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
dbus: Do message argument type checking early, centrally.
This commit is contained in:
parent
7bc8a793b8
commit
0e096632c5
11 changed files with 470 additions and 641 deletions
|
|
@ -43,7 +43,7 @@ static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userd
|
||||||
static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_profiles(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_profiles(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_active_profile(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_active_profile(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_property_list(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_property_list(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
||||||
static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
@ -322,7 +322,7 @@ static void handle_get_active_profile(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &active_profile);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &active_profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_card *c = userdata;
|
pa_dbusiface_card *c = userdata;
|
||||||
const char *new_active_path;
|
const char *new_active_path;
|
||||||
pa_dbusiface_card_profile *new_active;
|
pa_dbusiface_card_profile *new_active;
|
||||||
|
|
@ -330,11 +330,9 @@ static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_OBJECT_PATH, &new_active_path) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!c->active_profile) {
|
if (!c->active_profile) {
|
||||||
pa_assert(pa_hashmap_isempty(c->profiles));
|
pa_assert(pa_hashmap_isempty(c->profiles));
|
||||||
|
|
||||||
|
|
@ -344,6 +342,8 @@ static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbus_message_iter_get_basic(iter, &new_active_path);
|
||||||
|
|
||||||
if (!(new_active = pa_hashmap_get(c->profiles, new_active_path))) {
|
if (!(new_active = pa_hashmap_get(c->profiles, new_active_path))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such profile.", new_active_path);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such profile.", new_active_path);
|
||||||
return;
|
return;
|
||||||
|
|
@ -430,7 +430,6 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
|
|
||||||
static void handle_get_profile_by_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_get_profile_by_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_card *c = userdata;
|
pa_dbusiface_card *c = userdata;
|
||||||
DBusError error;
|
|
||||||
const char *profile_name = NULL;
|
const char *profile_name = NULL;
|
||||||
pa_dbusiface_card_profile *profile = NULL;
|
pa_dbusiface_card_profile *profile = NULL;
|
||||||
const char *profile_path = NULL;
|
const char *profile_path = NULL;
|
||||||
|
|
@ -439,13 +438,7 @@ static void handle_get_profile_by_name(DBusConnection *conn, DBusMessage *msg, v
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &profile_name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &profile_name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(profile = pa_hashmap_get(c->profiles, profile_name))) {
|
if (!(profile = pa_hashmap_get(c->profiles, profile_name))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such profile on card %s.", profile_name, c->card->name);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such profile on card %s.", profile_name, c->card->name);
|
||||||
|
|
|
||||||
|
|
@ -339,16 +339,12 @@ static void handle_update_properties(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter)) {
|
pa_assert_se(dbus_message_iter_init(msg, &msg_iter));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &update_mode) < 0)
|
dbus_message_iter_get_basic(&msg_iter, &update_mode);
|
||||||
goto finish;
|
|
||||||
|
|
||||||
if (!(update_mode == PA_UPDATE_SET || update_mode == PA_UPDATE_MERGE || update_mode == PA_UPDATE_REPLACE)) {
|
if (!(update_mode == PA_UPDATE_SET || update_mode == PA_UPDATE_MERGE || update_mode == PA_UPDATE_REPLACE)) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid update mode: %u", update_mode);
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid update mode: %u", update_mode);
|
||||||
|
|
@ -368,7 +364,6 @@ static void handle_remove_properties(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
pa_dbusiface_client *c = userdata;
|
pa_dbusiface_client *c = userdata;
|
||||||
char **keys = NULL;
|
char **keys = NULL;
|
||||||
int n_keys = 0;
|
int n_keys = 0;
|
||||||
DBusError error;
|
|
||||||
pa_bool_t changed = FALSE;
|
pa_bool_t changed = FALSE;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|
@ -376,18 +371,12 @@ static void handle_remove_properties(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
|
||||||
|
|
||||||
if (pa_dbus_protocol_get_client(c->dbus_protocol, conn) != c->client) {
|
if (pa_dbus_protocol_get_client(c->dbus_protocol, conn) != c->client) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_ACCESS_DENIED, "Client tried to modify the property list of another client.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_ACCESS_DENIED, "Client tried to modify the property list of another client.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &keys, &n_keys, DBUS_TYPE_INVALID)) {
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &keys, &n_keys, DBUS_TYPE_INVALID));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < n_keys; ++i)
|
for (i = 0; i < n_keys; ++i)
|
||||||
changed |= pa_proplist_unset(c->client->proplist, keys[i]) >= 0;
|
changed |= pa_proplist_unset(c->client->proplist, keys[i]) >= 0;
|
||||||
|
|
|
||||||
|
|
@ -57,18 +57,18 @@ static void handle_get_is_local(DBusConnection *conn, DBusMessage *msg, void *us
|
||||||
static void handle_get_username(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_username(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_hostname(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_hostname(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_default_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_default_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_default_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_default_channels(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_default_sample_format(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_default_sample_format(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_default_sample_format(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_default_sample_format(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_default_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_default_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_cards(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_cards(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_fallback_sink(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_fallback_sink(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_fallback_source(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_fallback_source(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_playback_streams(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_playback_streams(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_record_streams(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_record_streams(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_samples(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_samples(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
@ -428,30 +428,32 @@ static void handle_get_default_channels(DBusConnection *conn, DBusMessage *msg,
|
||||||
pa_xfree(default_channels);
|
pa_xfree(default_channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_default_channels(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_default_channels(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
|
DBusMessageIter array_iter;
|
||||||
pa_channel_map new_channel_map;
|
pa_channel_map new_channel_map;
|
||||||
dbus_uint32_t *default_channels;
|
const dbus_uint32_t *default_channels;
|
||||||
unsigned n_channels;
|
int n_channels;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
pa_channel_map_init(&new_channel_map);
|
pa_channel_map_init(&new_channel_map);
|
||||||
|
|
||||||
if (pa_dbus_get_fixed_array_set_property_arg(conn, msg, DBUS_TYPE_UINT32, &default_channels, &n_channels) < 0)
|
dbus_message_iter_recurse(iter, &array_iter);
|
||||||
return;
|
dbus_message_iter_get_fixed_array(&array_iter, &default_channels, &n_channels);
|
||||||
|
|
||||||
if (n_channels <= 0) {
|
if (n_channels <= 0) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Empty channel array.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Empty channel array.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_channels > PA_CHANNELS_MAX) {
|
if (n_channels > (int) PA_CHANNELS_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
"Too many channels: %u. The maximum number of channels is %u.", n_channels, PA_CHANNELS_MAX);
|
"Too many channels: %i. The maximum number of channels is %u.", n_channels, PA_CHANNELS_MAX);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,16 +487,16 @@ static void handle_get_default_sample_format(DBusConnection *conn, DBusMessage *
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &default_sample_format);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &default_sample_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_default_sample_format(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_default_sample_format(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
dbus_uint32_t default_sample_format;
|
dbus_uint32_t default_sample_format;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_UINT32, &default_sample_format) < 0)
|
dbus_message_iter_get_basic(iter, &default_sample_format);
|
||||||
return;
|
|
||||||
|
|
||||||
if (default_sample_format >= PA_SAMPLE_MAX) {
|
if (default_sample_format >= PA_SAMPLE_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample format.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample format.");
|
||||||
|
|
@ -519,16 +521,16 @@ static void handle_get_default_sample_rate(DBusConnection *conn, DBusMessage *ms
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &default_sample_rate);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &default_sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
dbus_uint32_t default_sample_rate;
|
dbus_uint32_t default_sample_rate;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_UINT32, &default_sample_rate) < 0)
|
dbus_message_iter_get_basic(iter, &default_sample_rate);
|
||||||
return;
|
|
||||||
|
|
||||||
if (default_sample_rate <= 0 || default_sample_rate > PA_RATE_MAX) {
|
if (default_sample_rate <= 0 || default_sample_rate > PA_RATE_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample rate.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample rate.");
|
||||||
|
|
@ -639,13 +641,14 @@ static void handle_get_fallback_sink(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &object_path);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &object_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
pa_dbusiface_device *fallback_sink;
|
pa_dbusiface_device *fallback_sink;
|
||||||
const char *object_path;
|
const char *object_path;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
if (!c->fallback_sink) {
|
if (!c->fallback_sink) {
|
||||||
|
|
@ -654,8 +657,7 @@ static void handle_set_fallback_sink(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_OBJECT_PATH, &object_path) < 0)
|
dbus_message_iter_get_basic(iter, &object_path);
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(fallback_sink = pa_hashmap_get(c->sinks_by_path, object_path))) {
|
if (!(fallback_sink = pa_hashmap_get(c->sinks_by_path, object_path))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such sink.", object_path);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such sink.", object_path);
|
||||||
|
|
@ -727,13 +729,14 @@ static void handle_get_fallback_source(DBusConnection *conn, DBusMessage *msg, v
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &object_path);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &object_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
pa_dbusiface_device *fallback_source;
|
pa_dbusiface_device *fallback_source;
|
||||||
const char *object_path;
|
const char *object_path;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
if (!c->fallback_source) {
|
if (!c->fallback_source) {
|
||||||
|
|
@ -742,8 +745,7 @@ static void handle_set_fallback_source(DBusConnection *conn, DBusMessage *msg, v
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_OBJECT_PATH, &object_path) < 0)
|
dbus_message_iter_get_basic(iter, &object_path);
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(fallback_source = pa_hashmap_get(c->sources_by_path, object_path))) {
|
if (!(fallback_source = pa_hashmap_get(c->sources_by_path, object_path))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such source.", object_path);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such source.", object_path);
|
||||||
|
|
@ -1117,19 +1119,12 @@ static void handle_get_card_by_name(DBusConnection *conn, DBusMessage *msg, void
|
||||||
pa_card *card;
|
pa_card *card;
|
||||||
pa_dbusiface_card *dbus_card;
|
pa_dbusiface_card *dbus_card;
|
||||||
const char *object_path;
|
const char *object_path;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &card_name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &card_name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(card = pa_namereg_get(c->core, card_name, PA_NAMEREG_CARD))) {
|
if (!(card = pa_namereg_get(c->core, card_name, PA_NAMEREG_CARD))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such card.");
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such card.");
|
||||||
|
|
@ -1149,19 +1144,12 @@ static void handle_get_sink_by_name(DBusConnection *conn, DBusMessage *msg, void
|
||||||
pa_sink *sink;
|
pa_sink *sink;
|
||||||
pa_dbusiface_device *dbus_sink;
|
pa_dbusiface_device *dbus_sink;
|
||||||
const char *object_path;
|
const char *object_path;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &sink_name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &sink_name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(sink = pa_namereg_get(c->core, sink_name, PA_NAMEREG_SINK))) {
|
if (!(sink = pa_namereg_get(c->core, sink_name, PA_NAMEREG_SINK))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such sink.", sink_name);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such sink.", sink_name);
|
||||||
|
|
@ -1181,19 +1169,12 @@ static void handle_get_source_by_name(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
pa_source *source;
|
pa_source *source;
|
||||||
pa_dbusiface_device *dbus_source;
|
pa_dbusiface_device *dbus_source;
|
||||||
const char *object_path;
|
const char *object_path;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &source_name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &source_name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(source = pa_namereg_get(c->core, source_name, PA_NAMEREG_SOURCE))) {
|
if (!(source = pa_namereg_get(c->core, source_name, PA_NAMEREG_SOURCE))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such source.", source_name);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such source.", source_name);
|
||||||
|
|
@ -1213,19 +1194,12 @@ static void handle_get_sample_by_name(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
pa_scache_entry *sample;
|
pa_scache_entry *sample;
|
||||||
pa_dbusiface_sample *dbus_sample;
|
pa_dbusiface_sample *dbus_sample;
|
||||||
const char *object_path;
|
const char *object_path;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &sample_name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &sample_name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(sample = pa_namereg_get(c->core, sample_name, PA_NAMEREG_SAMPLE))) {
|
if (!(sample = pa_namereg_get(c->core, sample_name, PA_NAMEREG_SAMPLE))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such sample.");
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such sample.");
|
||||||
|
|
@ -1242,17 +1216,18 @@ static void handle_get_sample_by_name(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
DBusMessageIter msg_iter;
|
DBusMessageIter msg_iter;
|
||||||
|
DBusMessageIter array_iter;
|
||||||
const char *name;
|
const char *name;
|
||||||
dbus_uint32_t sample_format;
|
dbus_uint32_t sample_format;
|
||||||
dbus_uint32_t sample_rate;
|
dbus_uint32_t sample_rate;
|
||||||
const dbus_uint32_t *channels;
|
const dbus_uint32_t *channels;
|
||||||
unsigned n_channels;
|
int n_channels;
|
||||||
const dbus_uint32_t *default_volume;
|
const dbus_uint32_t *default_volume;
|
||||||
unsigned n_volume_entries;
|
int n_volume_entries;
|
||||||
pa_proplist *property_list;
|
pa_proplist *property_list;
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
unsigned data_length;
|
int data_length;
|
||||||
unsigned i;
|
int i;
|
||||||
pa_sample_spec ss;
|
pa_sample_spec ss;
|
||||||
pa_channel_map map;
|
pa_channel_map map;
|
||||||
pa_memchunk chunk;
|
pa_memchunk chunk;
|
||||||
|
|
@ -1267,31 +1242,29 @@ static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *u
|
||||||
|
|
||||||
chunk.memblock = NULL;
|
chunk.memblock = NULL;
|
||||||
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter)) {
|
pa_assert_se(dbus_message_iter_init(msg, &msg_iter));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
dbus_message_iter_get_basic(&msg_iter, &name);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_STRING, &name) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_get_basic(&msg_iter, &sample_format);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &sample_format) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_get_basic(&msg_iter, &sample_rate);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &sample_rate) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_recurse(&msg_iter, &array_iter);
|
||||||
|
dbus_message_iter_get_fixed_array(&array_iter, &channels, &n_channels);
|
||||||
|
|
||||||
if (pa_dbus_get_fixed_array_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &channels, &n_channels) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_recurse(&msg_iter, &array_iter);
|
||||||
|
dbus_message_iter_get_fixed_array(&array_iter, &default_volume, &n_volume_entries);
|
||||||
if (pa_dbus_get_fixed_array_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &default_volume, &n_volume_entries) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pa_dbus_get_fixed_array_arg(conn, msg, &msg_iter, DBUS_TYPE_BYTE, &data, &data_length) < 0)
|
dbus_message_iter_recurse(&msg_iter, &array_iter);
|
||||||
goto finish;
|
dbus_message_iter_get_fixed_array(&array_iter, &data, &data_length);
|
||||||
|
|
||||||
if (sample_format >= PA_SAMPLE_MAX) {
|
if (sample_format >= PA_SAMPLE_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample format.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample format.");
|
||||||
|
|
@ -1303,14 +1276,14 @@ static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *u
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_channels == 0) {
|
if (n_channels <= 0) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Empty channel map.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Empty channel map.");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_channels > PA_CHANNELS_MAX) {
|
if (n_channels > (int) PA_CHANNELS_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
"Too many channels: %u. The maximum is %u.", n_channels, PA_CHANNELS_MAX);
|
"Too many channels: %i. The maximum is %u.", n_channels, PA_CHANNELS_MAX);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1323,13 +1296,14 @@ static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *u
|
||||||
|
|
||||||
if (n_volume_entries != 0 && n_volume_entries != n_channels) {
|
if (n_volume_entries != 0 && n_volume_entries != n_channels) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
"The channels and default_volume arguments have different number of elements.");
|
"The channels and default_volume arguments have different number of elements (%i and %i, resp).",
|
||||||
|
n_channels, n_volume_entries);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n_volume_entries; ++i) {
|
for (i = 0; i < n_volume_entries; ++i) {
|
||||||
if (default_volume[i] > PA_VOLUME_MAX) {
|
if (default_volume[i] > PA_VOLUME_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid volume.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid volume: %u.", default_volume[i]);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1340,7 +1314,9 @@ static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *u
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_length > PA_SCACHE_ENTRY_SIZE_MAX) {
|
if (data_length > PA_SCACHE_ENTRY_SIZE_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too big sample.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Too big sample: %i bytes. The maximum sample length is %u bytes.",
|
||||||
|
data_length, PA_SCACHE_ENTRY_SIZE_MAX);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1348,9 +1324,13 @@ static void handle_upload_sample(DBusConnection *conn, DBusMessage *msg, void *u
|
||||||
ss.rate = sample_rate;
|
ss.rate = sample_rate;
|
||||||
ss.channels = n_channels;
|
ss.channels = n_channels;
|
||||||
|
|
||||||
|
pa_assert(pa_sample_spec_valid(&ss));
|
||||||
|
|
||||||
if (!pa_frame_aligned(data_length, &ss)) {
|
if (!pa_frame_aligned(data_length, &ss)) {
|
||||||
|
char buf[PA_SAMPLE_SPEC_SNPRINT_MAX];
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
"The sample length in bytes doesn't align with the sample format and channels.");
|
"The sample length (%i bytes) doesn't align with the sample format and channels (%s).",
|
||||||
|
data_length, pa_sample_spec_snprint(buf, sizeof(buf), &ss));
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1414,15 +1394,15 @@ static void handle_load_module(DBusConnection *conn, DBusMessage *msg, void *use
|
||||||
DBusMessageIter msg_iter;
|
DBusMessageIter msg_iter;
|
||||||
DBusMessageIter dict_iter;
|
DBusMessageIter dict_iter;
|
||||||
DBusMessageIter dict_entry_iter;
|
DBusMessageIter dict_entry_iter;
|
||||||
char *name;
|
char *name = NULL;
|
||||||
const char *key;
|
const char *key = NULL;
|
||||||
const char *value;
|
const char *value = NULL;
|
||||||
char *escaped_value;
|
char *escaped_value = NULL;
|
||||||
pa_strbuf *arg_buffer = NULL;
|
pa_strbuf *arg_buffer = NULL;
|
||||||
pa_module *module;
|
char *arg_string = NULL;
|
||||||
pa_dbusiface_module *dbus_module;
|
pa_module *module = NULL;
|
||||||
const char *object_path;
|
pa_dbusiface_module *dbus_module = NULL;
|
||||||
int arg_type;
|
const char *object_path = NULL;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
|
@ -1433,35 +1413,12 @@ static void handle_load_module(DBusConnection *conn, DBusMessage *msg, void *use
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter)) {
|
pa_assert_se(dbus_message_iter_init(msg, &msg_iter));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
dbus_message_iter_get_basic(&msg_iter, &name);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_STRING, &name) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&msg_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_ARRAY) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
|
||||||
"Too few arguments. A dictionary from strings to strings was expected.");
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
|
||||||
"Wrong argument type: '%c'. An dictionary from strings to strings was expected.",
|
|
||||||
(char) arg_type);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_element_type(&msg_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_DICT_ENTRY) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
|
||||||
"Wrong array element type: '%c'. A dict entry (string to string) was expected.", (char) arg_type);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_buffer = pa_strbuf_new();
|
arg_buffer = pa_strbuf_new();
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
dbus_message_iter_recurse(&msg_iter, &dict_iter);
|
dbus_message_iter_recurse(&msg_iter, &dict_iter);
|
||||||
|
|
||||||
while (dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID) {
|
while (dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID) {
|
||||||
|
|
@ -1470,41 +1427,26 @@ static void handle_load_module(DBusConnection *conn, DBusMessage *msg, void *use
|
||||||
|
|
||||||
dbus_message_iter_recurse(&dict_iter, &dict_entry_iter);
|
dbus_message_iter_recurse(&dict_iter, &dict_entry_iter);
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&dict_entry_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_STRING) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
|
||||||
"Wrong dict key type: '%c'. A string was expected.", (char) arg_type);
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_get_basic(&dict_entry_iter, &key);
|
dbus_message_iter_get_basic(&dict_entry_iter, &key);
|
||||||
dbus_message_iter_next(&dict_entry_iter);
|
|
||||||
|
|
||||||
if (strlen(key) <= 0 || !pa_ascii_valid(key) || contains_space(key)) {
|
if (strlen(key) <= 0 || !pa_ascii_valid(key) || contains_space(key)) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid module argument name: %s", key);
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid module argument name: %s", key);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&dict_entry_iter);
|
pa_assert_se(dbus_message_iter_next(&dict_entry_iter));
|
||||||
if (arg_type != DBUS_TYPE_STRING) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Dict value missing.");
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
|
||||||
"Wrong dict value type: '%c'. A string was expected.", (char) arg_type);
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_get_basic(&dict_entry_iter, &value);
|
dbus_message_iter_get_basic(&dict_entry_iter, &value);
|
||||||
|
|
||||||
dbus_message_iter_next(&dict_iter);
|
|
||||||
|
|
||||||
escaped_value = pa_escape(value, "\"");
|
escaped_value = pa_escape(value, "\"");
|
||||||
pa_strbuf_printf(arg_buffer, "%s=\"%s\"", key, escaped_value);
|
pa_strbuf_printf(arg_buffer, "%s=\"%s\"", key, escaped_value);
|
||||||
pa_xfree(escaped_value);
|
pa_xfree(escaped_value);
|
||||||
|
|
||||||
|
dbus_message_iter_next(&dict_iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(module = pa_module_load(c->core, name, pa_strbuf_tostring(arg_buffer)))) {
|
arg_string = pa_strbuf_tostring(arg_buffer);
|
||||||
|
|
||||||
|
if (!(module = pa_module_load(c->core, name, arg_string))) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "Failed to load module.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "Failed to load module.");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
@ -1519,6 +1461,8 @@ static void handle_load_module(DBusConnection *conn, DBusMessage *msg, void *use
|
||||||
finish:
|
finish:
|
||||||
if (arg_buffer)
|
if (arg_buffer)
|
||||||
pa_strbuf_free(arg_buffer);
|
pa_strbuf_free(arg_buffer);
|
||||||
|
|
||||||
|
pa_xfree(arg_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_exit(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_exit(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
|
|
@ -1543,47 +1487,32 @@ static void handle_listen_for_signal(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
const char *signal;
|
const char *signal;
|
||||||
char **objects = NULL;
|
char **objects = NULL;
|
||||||
int n_objects;
|
int n_objects;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL,
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error,
|
|
||||||
DBUS_TYPE_STRING, &signal,
|
DBUS_TYPE_STRING, &signal,
|
||||||
DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objects, &n_objects,
|
DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objects, &n_objects,
|
||||||
DBUS_TYPE_INVALID)) {
|
DBUS_TYPE_INVALID));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_dbus_protocol_add_signal_listener(c->dbus_protocol, conn, *signal ? signal : NULL, objects, n_objects);
|
pa_dbus_protocol_add_signal_listener(c->dbus_protocol, conn, *signal ? signal : NULL, objects, n_objects);
|
||||||
|
|
||||||
pa_dbus_send_empty_reply(conn, msg);
|
pa_dbus_send_empty_reply(conn, msg);
|
||||||
|
|
||||||
finish:
|
|
||||||
dbus_free_string_array(objects);
|
dbus_free_string_array(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_stop_listening_for_signal(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_stop_listening_for_signal(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_core *c = userdata;
|
pa_dbusiface_core *c = userdata;
|
||||||
const char *signal;
|
const char *signal;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &signal, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &signal, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_dbus_protocol_remove_signal_listener(c->dbus_protocol, conn, *signal ? signal : NULL);
|
pa_dbus_protocol_remove_signal_listener(c->dbus_protocol, conn, *signal ? signal : NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,13 @@ static void handle_get_sample_format(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_has_flat_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_has_flat_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_has_convertible_to_decibel_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_has_convertible_to_decibel_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_base_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_base_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_volume_steps(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_volume_steps(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_has_hardware_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_has_hardware_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_has_hardware_mute(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_has_hardware_mute(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_configured_latency(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_configured_latency(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
@ -60,7 +60,7 @@ static void handle_get_is_network_device(DBusConnection *conn, DBusMessage *msg,
|
||||||
static void handle_get_state(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_state(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_ports(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_ports(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_active_port(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_active_port(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_active_port(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_active_port(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_property_list(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_property_list(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
||||||
static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
@ -408,16 +408,18 @@ static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_UINT32, volume, d->volume.channels);
|
pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_UINT32, volume, d->volume.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_device *d = userdata;
|
pa_dbusiface_device *d = userdata;
|
||||||
unsigned device_channels = 0;
|
DBusMessageIter array_iter;
|
||||||
|
int device_channels = 0;
|
||||||
dbus_uint32_t *volume = NULL;
|
dbus_uint32_t *volume = NULL;
|
||||||
unsigned n_volume_entries = 0;
|
int n_volume_entries = 0;
|
||||||
pa_cvolume new_vol;
|
pa_cvolume new_vol;
|
||||||
unsigned i = 0;
|
int i = 0;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
pa_cvolume_init(&new_vol);
|
pa_cvolume_init(&new_vol);
|
||||||
|
|
@ -426,12 +428,12 @@ static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
|
|
||||||
new_vol.channels = device_channels;
|
new_vol.channels = device_channels;
|
||||||
|
|
||||||
if (pa_dbus_get_fixed_array_set_property_arg(conn, msg, DBUS_TYPE_UINT32, &volume, &n_volume_entries) < 0)
|
dbus_message_iter_recurse(iter, &array_iter);
|
||||||
return;
|
dbus_message_iter_get_fixed_array(&array_iter, &volume, &n_volume_entries);
|
||||||
|
|
||||||
if (n_volume_entries != device_channels) {
|
if (n_volume_entries != device_channels) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
"Expected %u volume entries, got %u.", device_channels, n_volume_entries);
|
"Expected %u volume entries, got %i.", device_channels, n_volume_entries);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -515,16 +517,16 @@ static void handle_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *us
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_BOOLEAN, &d->is_muted);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_BOOLEAN, &d->is_muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_device *d = userdata;
|
pa_dbusiface_device *d = userdata;
|
||||||
dbus_bool_t is_muted = FALSE;
|
dbus_bool_t is_muted = FALSE;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_BOOLEAN, &is_muted) < 0)
|
dbus_message_iter_get_basic(iter, &is_muted);
|
||||||
return;
|
|
||||||
|
|
||||||
if (d->type == DEVICE_TYPE_SINK)
|
if (d->type == DEVICE_TYPE_SINK)
|
||||||
pa_sink_set_mute(d->sink, is_muted, TRUE);
|
pa_sink_set_mute(d->sink, is_muted, TRUE);
|
||||||
|
|
@ -722,7 +724,7 @@ static void handle_get_active_port(DBusConnection *conn, DBusMessage *msg, void
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &active_port);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &active_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_active_port(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_active_port(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_device *d = userdata;
|
pa_dbusiface_device *d = userdata;
|
||||||
const char *new_active_path;
|
const char *new_active_path;
|
||||||
pa_dbusiface_device_port *new_active;
|
pa_dbusiface_device_port *new_active;
|
||||||
|
|
@ -730,11 +732,9 @@ static void handle_set_active_port(DBusConnection *conn, DBusMessage *msg, void
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_OBJECT_PATH, &new_active_path) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!d->active_port) {
|
if (!d->active_port) {
|
||||||
pa_assert(pa_hashmap_isempty(d->ports));
|
pa_assert(pa_hashmap_isempty(d->ports));
|
||||||
|
|
||||||
|
|
@ -747,8 +747,10 @@ static void handle_set_active_port(DBusConnection *conn, DBusMessage *msg, void
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbus_message_iter_get_basic(iter, &new_active_path);
|
||||||
|
|
||||||
if (!(new_active = pa_hashmap_get(d->ports, new_active_path))) {
|
if (!(new_active = pa_hashmap_get(d->ports, new_active_path))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "%s: No such port.", new_active_path);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such port: %s", new_active_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -923,19 +925,12 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
static void handle_suspend(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_suspend(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_device *d = userdata;
|
pa_dbusiface_device *d = userdata;
|
||||||
dbus_bool_t suspend = FALSE;
|
dbus_bool_t suspend = FALSE;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &suspend, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_BOOLEAN, &suspend, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((d->type == DEVICE_TYPE_SINK) && (pa_sink_suspend(d->sink, suspend, PA_SUSPEND_USER) < 0)) {
|
if ((d->type == DEVICE_TYPE_SINK) && (pa_sink_suspend(d->sink, suspend, PA_SUSPEND_USER) < 0)) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "Internal error in PulseAudio: pa_sink_suspend() failed.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "Internal error in PulseAudio: pa_sink_suspend() failed.");
|
||||||
|
|
@ -950,7 +945,6 @@ static void handle_suspend(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
|
|
||||||
static void handle_get_port_by_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_get_port_by_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_device *d = userdata;
|
pa_dbusiface_device *d = userdata;
|
||||||
DBusError error;
|
|
||||||
const char *port_name = NULL;
|
const char *port_name = NULL;
|
||||||
pa_dbusiface_device_port *port = NULL;
|
pa_dbusiface_device_port *port = NULL;
|
||||||
const char *port_path = NULL;
|
const char *port_path = NULL;
|
||||||
|
|
@ -959,13 +953,7 @@ static void handle_get_port_by_name(DBusConnection *conn, DBusMessage *msg, void
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &port_name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &port_name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(port = pa_hashmap_get(d->ports, port_name))) {
|
if (!(port = pa_hashmap_get(d->ports, port_name))) {
|
||||||
if (d->type == DEVICE_TYPE_SINK)
|
if (d->type == DEVICE_TYPE_SINK)
|
||||||
|
|
|
||||||
|
|
@ -359,14 +359,10 @@ static void handle_play(DBusConnection *conn, DBusMessage *msg, void *userdata)
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter)) {
|
pa_assert_se(dbus_message_iter_init(msg, &msg_iter));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
dbus_message_iter_get_basic(&msg_iter, &volume);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &volume) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -405,17 +401,13 @@ static void handle_play_to_sink(DBusConnection *conn, DBusMessage *msg, void *us
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter)) {
|
pa_assert_se(dbus_message_iter_init(msg, &msg_iter));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
dbus_message_iter_get_basic(&msg_iter, &sink_path);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_OBJECT_PATH, &sink_path) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_get_basic(&msg_iter, &volume);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_UINT32, &volume) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
if (!(property_list = pa_dbus_get_proplist_arg(conn, msg, &msg_iter)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,9 @@ static void handle_get_sample_format(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_channels(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_get_buffer_latency(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_buffer_latency(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_device_latency(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_device_latency(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_get_resample_method(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_get_resample_method(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
@ -343,16 +343,18 @@ static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_UINT32, volume, s->volume.channels);
|
pa_dbus_send_basic_array_variant_reply(conn, msg, DBUS_TYPE_UINT32, volume, s->volume.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_stream *s = userdata;
|
pa_dbusiface_stream *s = userdata;
|
||||||
unsigned stream_channels = 0;
|
DBusMessageIter array_iter;
|
||||||
|
int stream_channels = 0;
|
||||||
dbus_uint32_t *volume = NULL;
|
dbus_uint32_t *volume = NULL;
|
||||||
unsigned n_volume_entries = 0;
|
int n_volume_entries = 0;
|
||||||
pa_cvolume new_vol;
|
pa_cvolume new_vol;
|
||||||
unsigned i = 0;
|
int i = 0;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_RECORD) {
|
if (s->type == STREAM_TYPE_RECORD) {
|
||||||
|
|
@ -366,8 +368,8 @@ static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
|
|
||||||
new_vol.channels = stream_channels;
|
new_vol.channels = stream_channels;
|
||||||
|
|
||||||
if (pa_dbus_get_fixed_array_set_property_arg(conn, msg, DBUS_TYPE_UINT32, &volume, &n_volume_entries) < 0)
|
dbus_message_iter_recurse(iter, &array_iter);
|
||||||
return;
|
dbus_message_iter_get_fixed_array(&array_iter, &volume, &n_volume_entries);
|
||||||
|
|
||||||
if (n_volume_entries != stream_channels) {
|
if (n_volume_entries != stream_channels) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
|
@ -403,16 +405,16 @@ static void handle_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *us
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_BOOLEAN, &s->is_muted);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_BOOLEAN, &s->is_muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_set_is_muted(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
pa_dbusiface_stream *s = userdata;
|
pa_dbusiface_stream *s = userdata;
|
||||||
dbus_bool_t is_muted = FALSE;
|
dbus_bool_t is_muted = FALSE;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_BOOLEAN, &is_muted) < 0)
|
dbus_message_iter_get_basic(iter, &is_muted);
|
||||||
return;
|
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_RECORD) {
|
if (s->type == STREAM_TYPE_RECORD) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "Record streams don't have mute.");
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "Record streams don't have mute.");
|
||||||
|
|
@ -575,19 +577,12 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
static void handle_move(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_move(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_stream *s = userdata;
|
pa_dbusiface_stream *s = userdata;
|
||||||
const char *device = NULL;
|
const char *device = NULL;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &device, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK) {
|
if (s->type == STREAM_TYPE_PLAYBACK) {
|
||||||
pa_sink *sink = pa_dbusiface_core_get_sink(s->core, device);
|
pa_sink *sink = pa_dbusiface_core_get_sink(s->core, device);
|
||||||
|
|
|
||||||
|
|
@ -167,11 +167,11 @@ static void handle_get_entry_by_name(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
static void handle_entry_get_index(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_get_index(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_entry_get_name(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_get_name(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_entry_get_device(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_get_device(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_entry_set_device(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_set_device(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_entry_get_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_get_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_entry_set_volume(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
static void handle_entry_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_get_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
static void handle_entry_set_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_set_is_muted(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
|
|
||||||
static void handle_entry_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
static void handle_entry_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
||||||
|
|
@ -326,18 +326,20 @@ static void dbus_entry_free(struct dbus_entry *de) {
|
||||||
|
|
||||||
/* Reads an array [(UInt32, UInt32)] from the iterator. The struct items are
|
/* Reads an array [(UInt32, UInt32)] from the iterator. The struct items are
|
||||||
* are a channel position and a volume value, respectively. The result is
|
* are a channel position and a volume value, respectively. The result is
|
||||||
* stored in the map and vol arguments. If the volume can't be read from the
|
* stored in the map and vol arguments. The iterator must point to a "a(uu)"
|
||||||
* iterator, an error reply is sent and a negative number is returned. In case
|
* element. If the data is invalid, an error reply is sent and a negative
|
||||||
* of a failure we make no guarantees about the state of map and vol. In case
|
* number is returned. In case of a failure we make no guarantees about the
|
||||||
* of an empty array the channels field of both map and vol are set to 0. */
|
* state of map and vol. In case of an empty array the channels field of both
|
||||||
|
* map and vol are set to 0. This function calls dbus_message_iter_next(iter)
|
||||||
|
* before returning. */
|
||||||
static int get_volume_arg(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, pa_channel_map *map, pa_cvolume *vol) {
|
static int get_volume_arg(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, pa_channel_map *map, pa_cvolume *vol) {
|
||||||
DBusMessageIter array_iter;
|
DBusMessageIter array_iter;
|
||||||
DBusMessageIter struct_iter;
|
DBusMessageIter struct_iter;
|
||||||
int arg_type;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(iter);
|
pa_assert(iter);
|
||||||
|
pa_assert(pa_streq(dbus_message_iter_get_signature(iter), "a(uu)"));
|
||||||
pa_assert(map);
|
pa_assert(map);
|
||||||
pa_assert(vol);
|
pa_assert(vol);
|
||||||
|
|
||||||
|
|
@ -347,21 +349,6 @@ static int get_volume_arg(DBusConnection *conn, DBusMessage *msg, DBusMessageIte
|
||||||
map->channels = 0;
|
map->channels = 0;
|
||||||
vol->channels = 0;
|
vol->channels = 0;
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(iter);
|
|
||||||
if (arg_type != DBUS_TYPE_ARRAY) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments. An array was expected.");
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Wrong argument type: '%c'. An array was expected.", (char) arg_type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_element_type(iter);
|
|
||||||
if (arg_type != DBUS_TYPE_STRUCT) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Wrong array element type: '%c'. A struct was expected.", (char) arg_type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_recurse(iter, &array_iter);
|
dbus_message_iter_recurse(iter, &array_iter);
|
||||||
|
|
||||||
while (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID) {
|
while (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID) {
|
||||||
|
|
@ -370,29 +357,14 @@ static int get_volume_arg(DBusConnection *conn, DBusMessage *msg, DBusMessageIte
|
||||||
|
|
||||||
dbus_message_iter_recurse(&array_iter, &struct_iter);
|
dbus_message_iter_recurse(&array_iter, &struct_iter);
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&struct_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_UINT32) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Wrong channel position type: '%c'. An unsigned 32-bit integer was expected.", (char) arg_type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_get_basic(&struct_iter, &chan_pos);
|
dbus_message_iter_get_basic(&struct_iter, &chan_pos);
|
||||||
dbus_message_iter_next(&struct_iter);
|
|
||||||
|
|
||||||
if (chan_pos >= PA_CHANNEL_POSITION_MAX) {
|
if (chan_pos >= PA_CHANNEL_POSITION_MAX) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid channel position: %u", chan_pos);
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid channel position: %u", chan_pos);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&struct_iter);
|
pa_assert_se(dbus_message_iter_next(&struct_iter));
|
||||||
if (arg_type != DBUS_TYPE_UINT32) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Channel volume missing.");
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Wrong volume value type: '%c'. An unsigned 32-bit integer was expected.", (char) arg_type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_get_basic(&struct_iter, &chan_vol);
|
dbus_message_iter_get_basic(&struct_iter, &chan_vol);
|
||||||
|
|
||||||
if (chan_vol > PA_VOLUME_MAX) {
|
if (chan_vol > PA_VOLUME_MAX) {
|
||||||
|
|
@ -612,40 +584,35 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
static void handle_add_entry(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_add_entry(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
struct userdata *u = userdata;
|
struct userdata *u = userdata;
|
||||||
DBusMessageIter msg_iter;
|
DBusMessageIter msg_iter;
|
||||||
const char *name;
|
const char *name = NULL;
|
||||||
const char *device;
|
const char *device = NULL;
|
||||||
pa_channel_map map;
|
pa_channel_map map;
|
||||||
pa_cvolume vol;
|
pa_cvolume vol;
|
||||||
dbus_bool_t muted;
|
dbus_bool_t muted = FALSE;
|
||||||
dbus_bool_t apply_immediately;
|
dbus_bool_t apply_immediately = FALSE;
|
||||||
pa_datum key;
|
pa_datum key;
|
||||||
pa_datum value;
|
pa_datum value;
|
||||||
struct dbus_entry *dbus_entry;
|
struct dbus_entry *dbus_entry = NULL;
|
||||||
struct entry *e;
|
struct entry *e = NULL;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(u);
|
pa_assert(u);
|
||||||
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter)) {
|
pa_assert_se(dbus_message_iter_init(msg, &msg_iter));
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
dbus_message_iter_get_basic(&msg_iter, &name);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_STRING, &name) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_get_basic(&msg_iter, &device);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_STRING, &device) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
if (get_volume_arg(conn, msg, &msg_iter, &map, &vol) < 0)
|
if (get_volume_arg(conn, msg, &msg_iter, &map, &vol) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_BOOLEAN, &muted) < 0)
|
dbus_message_iter_get_basic(&msg_iter, &muted);
|
||||||
return;
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(conn, msg, &msg_iter, DBUS_TYPE_BOOLEAN, &apply_immediately) < 0)
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
return;
|
dbus_message_iter_get_basic(&msg_iter, &apply_immediately);
|
||||||
|
|
||||||
if (!*name) {
|
if (!*name) {
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "An empty string was given as the entry name.");
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "An empty string was given as the entry name.");
|
||||||
|
|
@ -714,19 +681,12 @@ static void handle_get_entry_by_name(DBusConnection *conn, DBusMessage *msg, voi
|
||||||
struct userdata *u = userdata;
|
struct userdata *u = userdata;
|
||||||
const char *name;
|
const char *name;
|
||||||
struct dbus_entry *de;
|
struct dbus_entry *de;
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(u);
|
pa_assert(u);
|
||||||
|
|
||||||
dbus_error_init(&error);
|
pa_assert_se(dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", error.message);
|
|
||||||
dbus_error_free(&error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(de = pa_hashmap_get(u->dbus_entries, name))) {
|
if (!(de = pa_hashmap_get(u->dbus_entries, name))) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such stream restore entry.");
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NOT_FOUND, "No such stream restore entry.");
|
||||||
|
|
@ -774,7 +734,7 @@ static void handle_entry_get_device(DBusConnection *conn, DBusMessage *msg, void
|
||||||
pa_xfree(e);
|
pa_xfree(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_entry_set_device(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_entry_set_device(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
struct dbus_entry *de = userdata;
|
struct dbus_entry *de = userdata;
|
||||||
const char *device;
|
const char *device;
|
||||||
struct entry *e;
|
struct entry *e;
|
||||||
|
|
@ -782,10 +742,10 @@ static void handle_entry_set_device(DBusConnection *conn, DBusMessage *msg, void
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(de);
|
pa_assert(de);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_STRING, &device) < 0)
|
dbus_message_iter_get_basic(iter, &device);
|
||||||
return;
|
|
||||||
|
|
||||||
pa_assert_se(e = read_entry(de->userdata, de->entry_name));
|
pa_assert_se(e = read_entry(de->userdata, de->entry_name));
|
||||||
|
|
||||||
|
|
@ -835,25 +795,19 @@ static void handle_entry_get_volume(DBusConnection *conn, DBusMessage *msg, void
|
||||||
pa_xfree(e);
|
pa_xfree(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_entry_set_volume(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_entry_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
struct dbus_entry *de = userdata;
|
struct dbus_entry *de = userdata;
|
||||||
DBusMessageIter msg_iter;
|
|
||||||
pa_channel_map map;
|
pa_channel_map map;
|
||||||
pa_cvolume vol;
|
pa_cvolume vol;
|
||||||
struct entry *e;
|
struct entry *e = NULL;
|
||||||
pa_bool_t updated;
|
pa_bool_t updated = FALSE;
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(de);
|
pa_assert(de);
|
||||||
|
|
||||||
/* Skip the interface and property name arguments. */
|
if (get_volume_arg(conn, msg, iter, &map, &vol) < 0)
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter) || !dbus_message_iter_next(&msg_iter) || !dbus_message_iter_next(&msg_iter)) {
|
|
||||||
pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get_volume_arg(conn, msg, &msg_iter, &map, &vol) < 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pa_assert_se(e = read_entry(de->userdata, de->entry_name));
|
pa_assert_se(e = read_entry(de->userdata, de->entry_name));
|
||||||
|
|
@ -901,7 +855,7 @@ static void handle_entry_get_is_muted(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
pa_xfree(e);
|
pa_xfree(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_entry_set_is_muted(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_entry_set_is_muted(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata) {
|
||||||
struct dbus_entry *de = userdata;
|
struct dbus_entry *de = userdata;
|
||||||
pa_bool_t muted;
|
pa_bool_t muted;
|
||||||
struct entry *e;
|
struct entry *e;
|
||||||
|
|
@ -909,10 +863,10 @@ static void handle_entry_set_is_muted(DBusConnection *conn, DBusMessage *msg, vo
|
||||||
|
|
||||||
pa_assert(conn);
|
pa_assert(conn);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
|
pa_assert(iter);
|
||||||
pa_assert(de);
|
pa_assert(de);
|
||||||
|
|
||||||
if (pa_dbus_get_basic_set_property_arg(conn, msg, DBUS_TYPE_BOOLEAN, &muted) < 0)
|
dbus_message_iter_get_basic(iter, &muted);
|
||||||
return;
|
|
||||||
|
|
||||||
pa_assert_se(e = read_entry(de->userdata, de->entry_name));
|
pa_assert_se(e = read_entry(de->userdata, de->entry_name));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,10 @@ pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, pa_bool
|
||||||
return pconn;
|
return pconn;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing(pa_mainloop_api *m, pa_bool_t use_rtclock, DBusConnection *conn) {
|
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing(
|
||||||
|
pa_mainloop_api *m,
|
||||||
|
pa_bool_t use_rtclock,
|
||||||
|
DBusConnection *conn) {
|
||||||
pa_dbus_wrap_connection *pconn;
|
pa_dbus_wrap_connection *pconn;
|
||||||
|
|
||||||
pa_assert(m);
|
pa_assert(m);
|
||||||
|
|
@ -522,7 +525,10 @@ void pa_dbus_send_basic_variant_reply(DBusConnection *c, DBusMessage *in_reply_t
|
||||||
|
|
||||||
pa_assert_se((reply = dbus_message_new_method_return(in_reply_to)));
|
pa_assert_se((reply = dbus_message_new_method_return(in_reply_to)));
|
||||||
dbus_message_iter_init_append(reply, &msg_iter);
|
dbus_message_iter_init_append(reply, &msg_iter);
|
||||||
pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_VARIANT, signature_from_basic_type(type), &variant_iter));
|
pa_assert_se(dbus_message_iter_open_container(&msg_iter,
|
||||||
|
DBUS_TYPE_VARIANT,
|
||||||
|
signature_from_basic_type(type),
|
||||||
|
&variant_iter));
|
||||||
pa_assert_se(dbus_message_iter_append_basic(&variant_iter, type, data));
|
pa_assert_se(dbus_message_iter_append_basic(&variant_iter, type, data));
|
||||||
pa_assert_se(dbus_message_iter_close_container(&msg_iter, &variant_iter));
|
pa_assert_se(dbus_message_iter_close_container(&msg_iter, &variant_iter));
|
||||||
pa_assert_se(dbus_connection_send(c, reply, NULL));
|
pa_assert_se(dbus_connection_send(c, reply, NULL));
|
||||||
|
|
@ -548,7 +554,12 @@ static unsigned basic_type_size(int type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_dbus_send_basic_array_variant_reply(DBusConnection *c, DBusMessage *in_reply_to, int item_type, void *array, unsigned n) {
|
void pa_dbus_send_basic_array_variant_reply(
|
||||||
|
DBusConnection *c,
|
||||||
|
DBusMessage *in_reply_to,
|
||||||
|
int item_type,
|
||||||
|
void *array,
|
||||||
|
unsigned n) {
|
||||||
DBusMessage *reply = NULL;
|
DBusMessage *reply = NULL;
|
||||||
DBusMessageIter msg_iter;
|
DBusMessageIter msg_iter;
|
||||||
|
|
||||||
|
|
@ -641,7 +652,12 @@ void pa_dbus_append_basic_variant_dict_entry(DBusMessageIter *dict_iter, const c
|
||||||
pa_assert_se(dbus_message_iter_close_container(dict_iter, &dict_entry_iter));
|
pa_assert_se(dbus_message_iter_close_container(dict_iter, &dict_entry_iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_dbus_append_basic_array_variant_dict_entry(DBusMessageIter *dict_iter, const char *key, int item_type, const void *array, unsigned n) {
|
void pa_dbus_append_basic_array_variant_dict_entry(
|
||||||
|
DBusMessageIter *dict_iter,
|
||||||
|
const char *key,
|
||||||
|
int item_type,
|
||||||
|
const void *array,
|
||||||
|
unsigned n) {
|
||||||
DBusMessageIter dict_entry_iter;
|
DBusMessageIter dict_entry_iter;
|
||||||
|
|
||||||
pa_assert(dict_iter);
|
pa_assert(dict_iter);
|
||||||
|
|
@ -711,156 +727,18 @@ void pa_dbus_append_proplist_variant_dict_entry(DBusMessageIter *dict_iter, cons
|
||||||
pa_assert_se(dbus_message_iter_close_container(dict_iter, &dict_entry_iter));
|
pa_assert_se(dbus_message_iter_close_container(dict_iter, &dict_entry_iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_dbus_get_basic_set_property_arg(DBusConnection *c, DBusMessage *msg, int type, void *data) {
|
|
||||||
DBusMessageIter msg_iter;
|
|
||||||
DBusMessageIter variant_iter;
|
|
||||||
|
|
||||||
pa_assert(c);
|
|
||||||
pa_assert(msg);
|
|
||||||
pa_assert(dbus_type_is_basic(type));
|
|
||||||
pa_assert(data);
|
|
||||||
|
|
||||||
/* Skip the interface and property name arguments. */
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter) || !dbus_message_iter_next(&msg_iter) || !dbus_message_iter_next(&msg_iter)) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_VARIANT) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Message argument isn't a variant.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_recurse(&msg_iter, &variant_iter);
|
|
||||||
|
|
||||||
if (pa_dbus_get_basic_arg(c, msg, &variant_iter, type, data) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pa_dbus_get_fixed_array_set_property_arg(DBusConnection *c, DBusMessage *msg, int item_type, void *data, unsigned *n) {
|
|
||||||
DBusMessageIter msg_iter;
|
|
||||||
DBusMessageIter variant_iter;
|
|
||||||
|
|
||||||
pa_assert(c);
|
|
||||||
pa_assert(msg);
|
|
||||||
pa_assert(dbus_type_is_fixed(item_type));
|
|
||||||
pa_assert(data);
|
|
||||||
pa_assert(n);
|
|
||||||
|
|
||||||
/* Skip the interface and property name arguments. */
|
|
||||||
if (!dbus_message_iter_init(msg, &msg_iter) || !dbus_message_iter_next(&msg_iter) || !dbus_message_iter_next(&msg_iter)) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_VARIANT) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Message argument isn't a variant.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_recurse(&msg_iter, &variant_iter);
|
|
||||||
|
|
||||||
if (pa_dbus_get_fixed_array_arg(c, msg, &variant_iter, item_type, data, n) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pa_dbus_get_basic_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter, int type, void *data) {
|
|
||||||
int arg_type;
|
|
||||||
|
|
||||||
pa_assert(c);
|
|
||||||
pa_assert(msg);
|
|
||||||
pa_assert(iter);
|
|
||||||
pa_assert(dbus_type_is_basic(type));
|
|
||||||
pa_assert(data);
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(iter);
|
|
||||||
if (arg_type != type) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments. D-Bus type '%c' expected.", (char) type);
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong argument type: '%c'. Expected type '%c'.", (char) arg_type, (char) type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_get_basic(iter, data);
|
|
||||||
|
|
||||||
dbus_message_iter_next(iter);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pa_dbus_get_fixed_array_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter, int item_type, void *array, unsigned *n) {
|
|
||||||
DBusMessageIter array_iter;
|
|
||||||
int signed_n;
|
|
||||||
int arg_type;
|
|
||||||
int element_type;
|
|
||||||
|
|
||||||
pa_assert(c);
|
|
||||||
pa_assert(msg);
|
|
||||||
pa_assert(iter);
|
|
||||||
pa_assert(dbus_type_is_fixed(item_type));
|
|
||||||
pa_assert(array);
|
|
||||||
pa_assert(n);
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(iter);
|
|
||||||
if (arg_type != DBUS_TYPE_ARRAY) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments. An array of type '%c' was expected.", (char) item_type);
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong argument type: '%c'. An array of type '%c' was expected.", (char) arg_type, (char) item_type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
element_type = dbus_message_iter_get_element_type(iter);
|
|
||||||
if (element_type != item_type) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong array element type: '%c'. Element type '%c' was expected.", (char) element_type, (char) item_type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_recurse(iter, &array_iter);
|
|
||||||
|
|
||||||
dbus_message_iter_get_fixed_array(&array_iter, array, &signed_n);
|
|
||||||
|
|
||||||
dbus_message_iter_next(iter);
|
|
||||||
|
|
||||||
pa_assert(signed_n >= 0);
|
|
||||||
|
|
||||||
*n = signed_n;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa_proplist *pa_dbus_get_proplist_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter) {
|
pa_proplist *pa_dbus_get_proplist_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter) {
|
||||||
DBusMessageIter dict_iter;
|
DBusMessageIter dict_iter;
|
||||||
DBusMessageIter dict_entry_iter;
|
DBusMessageIter dict_entry_iter;
|
||||||
int arg_type;
|
|
||||||
pa_proplist *proplist = NULL;
|
pa_proplist *proplist = NULL;
|
||||||
const char *key;
|
const char *key = NULL;
|
||||||
const uint8_t *value;
|
const uint8_t *value = NULL;
|
||||||
int value_length;
|
int value_length = 0;
|
||||||
|
|
||||||
pa_assert(c);
|
pa_assert(c);
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(iter);
|
pa_assert(iter);
|
||||||
|
pa_assert(pa_streq(dbus_message_iter_get_signature(iter), "a{say}"));
|
||||||
arg_type = dbus_message_iter_get_arg_type(iter);
|
|
||||||
if (arg_type != DBUS_TYPE_ARRAY) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Too few arguments. An array was expected.");
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong argument type: '%c'. An array was expected.", (char) arg_type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_element_type(iter);
|
|
||||||
if (arg_type != DBUS_TYPE_DICT_ENTRY) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong array element type: '%c'. A dictionary entry was expected.", (char) arg_type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
proplist = pa_proplist_new();
|
proplist = pa_proplist_new();
|
||||||
|
|
||||||
|
|
@ -869,32 +747,11 @@ pa_proplist *pa_dbus_get_proplist_arg(DBusConnection *c, DBusMessage *msg, DBusM
|
||||||
while (dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID) {
|
while (dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID) {
|
||||||
dbus_message_iter_recurse(&dict_iter, &dict_entry_iter);
|
dbus_message_iter_recurse(&dict_iter, &dict_entry_iter);
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&dict_entry_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_STRING) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong dict key type: '%c'. A string was expected.", (char) arg_type);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_message_iter_get_basic(&dict_entry_iter, &key);
|
dbus_message_iter_get_basic(&dict_entry_iter, &key);
|
||||||
dbus_message_iter_next(&dict_entry_iter);
|
dbus_message_iter_next(&dict_entry_iter);
|
||||||
|
|
||||||
if (strlen(key) <= 0 || !pa_ascii_valid(key)) {
|
if (strlen(key) <= 0 || !pa_ascii_valid(key)) {
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Invalid property list key.");
|
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Invalid property list key: '%s'.", key);
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_arg_type(&dict_entry_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_ARRAY) {
|
|
||||||
if (arg_type == DBUS_TYPE_INVALID)
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Dict value missing.");
|
|
||||||
else
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong dict value type: '%c'. An array was expected.", (char) arg_type);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg_type = dbus_message_iter_get_element_type(&dict_entry_iter);
|
|
||||||
if (arg_type != DBUS_TYPE_BYTE) {
|
|
||||||
pa_dbus_send_error(c, msg, DBUS_ERROR_INVALID_ARGS, "Wrong dict value item type: '%c'. A byte was expected.", (char) arg_type);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,10 @@
|
||||||
typedef struct pa_dbus_wrap_connection pa_dbus_wrap_connection;
|
typedef struct pa_dbus_wrap_connection pa_dbus_wrap_connection;
|
||||||
|
|
||||||
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *mainloop, pa_bool_t use_rtclock, DBusBusType type, DBusError *error);
|
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *mainloop, pa_bool_t use_rtclock, DBusBusType type, DBusError *error);
|
||||||
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing(pa_mainloop_api *mainloop, pa_bool_t use_rtclock, DBusConnection *conn);
|
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing(
|
||||||
|
pa_mainloop_api *mainloop,
|
||||||
|
pa_bool_t use_rtclock,
|
||||||
|
DBusConnection *conn);
|
||||||
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* conn);
|
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* conn);
|
||||||
|
|
||||||
DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *conn);
|
DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *conn);
|
||||||
|
|
@ -63,36 +66,41 @@ void pa_dbus_sync_pending_list(pa_dbus_pending **p);
|
||||||
void pa_dbus_free_pending_list(pa_dbus_pending **p);
|
void pa_dbus_free_pending_list(pa_dbus_pending **p);
|
||||||
|
|
||||||
/* Sends an error message as the reply to the given message. */
|
/* Sends an error message as the reply to the given message. */
|
||||||
void pa_dbus_send_error(DBusConnection *c, DBusMessage *in_reply_to, const char *name, const char *format, ...) PA_GCC_PRINTF_ATTR(4, 5);
|
void pa_dbus_send_error(
|
||||||
|
DBusConnection *c,
|
||||||
|
DBusMessage *in_reply_to,
|
||||||
|
const char *name,
|
||||||
|
const char *format, ...) PA_GCC_PRINTF_ATTR(4, 5);
|
||||||
|
|
||||||
void pa_dbus_send_empty_reply(DBusConnection *c, DBusMessage *in_reply_to);
|
void pa_dbus_send_empty_reply(DBusConnection *c, DBusMessage *in_reply_to);
|
||||||
void pa_dbus_send_basic_value_reply(DBusConnection *c, DBusMessage *in_reply_to, int type, void *data);
|
void pa_dbus_send_basic_value_reply(DBusConnection *c, DBusMessage *in_reply_to, int type, void *data);
|
||||||
void pa_dbus_send_basic_variant_reply(DBusConnection *c, DBusMessage *in_reply_to, int type, void *data);
|
void pa_dbus_send_basic_variant_reply(DBusConnection *c, DBusMessage *in_reply_to, int type, void *data);
|
||||||
void pa_dbus_send_basic_array_variant_reply(DBusConnection *c, DBusMessage *in_reply_to, int item_type, void *array, unsigned n);
|
void pa_dbus_send_basic_array_variant_reply(
|
||||||
|
DBusConnection *c,
|
||||||
|
DBusMessage *in_reply_to,
|
||||||
|
int item_type,
|
||||||
|
void *array,
|
||||||
|
unsigned n);
|
||||||
void pa_dbus_send_proplist_variant_reply(DBusConnection *c, DBusMessage *in_reply_to, pa_proplist *proplist);
|
void pa_dbus_send_proplist_variant_reply(DBusConnection *c, DBusMessage *in_reply_to, pa_proplist *proplist);
|
||||||
|
|
||||||
void pa_dbus_append_basic_array(DBusMessageIter *iter, int item_type, const void *array, unsigned n);
|
void pa_dbus_append_basic_array(DBusMessageIter *iter, int item_type, const void *array, unsigned n);
|
||||||
void pa_dbus_append_basic_array_variant(DBusMessageIter *iter, int item_type, const void *array, unsigned n);
|
void pa_dbus_append_basic_array_variant(DBusMessageIter *iter, int item_type, const void *array, unsigned n);
|
||||||
void pa_dbus_append_basic_variant(DBusMessageIter *iter, int type, void *data);
|
void pa_dbus_append_basic_variant(DBusMessageIter *iter, int type, void *data);
|
||||||
void pa_dbus_append_basic_variant_dict_entry(DBusMessageIter *dict_iter, const char *key, int type, void *data);
|
void pa_dbus_append_basic_variant_dict_entry(DBusMessageIter *dict_iter, const char *key, int type, void *data);
|
||||||
void pa_dbus_append_basic_array_variant_dict_entry(DBusMessageIter *dict_iter, const char *key, int item_type, const void *array, unsigned n);
|
void pa_dbus_append_basic_array_variant_dict_entry(
|
||||||
|
DBusMessageIter *dict_iter,
|
||||||
|
const char *key,
|
||||||
|
int item_type,
|
||||||
|
const void *array,
|
||||||
|
unsigned n);
|
||||||
void pa_dbus_append_proplist(DBusMessageIter *iter, pa_proplist *proplist);
|
void pa_dbus_append_proplist(DBusMessageIter *iter, pa_proplist *proplist);
|
||||||
void pa_dbus_append_proplist_variant(DBusMessageIter *iter, pa_proplist *proplist);
|
void pa_dbus_append_proplist_variant(DBusMessageIter *iter, pa_proplist *proplist);
|
||||||
void pa_dbus_append_proplist_variant_dict_entry(DBusMessageIter *dict_iter, const char *key, pa_proplist *proplist);
|
void pa_dbus_append_proplist_variant_dict_entry(DBusMessageIter *dict_iter, const char *key, pa_proplist *proplist);
|
||||||
|
|
||||||
/* Helper functions for extracting the value argument of a Set call. If the
|
/* Returns a new proplist that the caller has to free. If the proplist contains
|
||||||
* message is invalid, an error reply is sent and a negative number is
|
* invalid keys, an error reply is sent and NULL is returned. The iterator must
|
||||||
* returned. */
|
* point to "a{say}" element. This function calls dbus_message_iter_next(iter)
|
||||||
int pa_dbus_get_basic_set_property_arg(DBusConnection *c, DBusMessage *msg, int type, void *data);
|
* before returning. */
|
||||||
int pa_dbus_get_fixed_array_set_property_arg(DBusConnection *c, DBusMessage *msg, int item_type, void *data, unsigned *n);
|
|
||||||
|
|
||||||
/* If the arguments can't be read from the iterator, an error reply is sent and
|
|
||||||
* a negative number is returned. */
|
|
||||||
int pa_dbus_get_basic_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter, int type, void *data);
|
|
||||||
int pa_dbus_get_fixed_array_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter, int item_type, void *array, unsigned *n);
|
|
||||||
|
|
||||||
/* Returns a new proplist that the caller has to free. If the proplist can't be
|
|
||||||
* read from the iterator, an error reply is sent and NULL is returned. */
|
|
||||||
pa_proplist *pa_dbus_get_proplist_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter);
|
pa_proplist *pa_dbus_get_proplist_arg(DBusConnection *c, DBusMessage *msg, DBusMessageIter *iter);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -257,37 +257,90 @@ static void update_introspection(struct object_entry *oe) {
|
||||||
oe->introspection = pa_strbuf_tostring_free(buf);
|
oe->introspection = pa_strbuf_tostring_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return value of find_handler() and its subfunctions. */
|
||||||
enum find_result_t {
|
enum find_result_t {
|
||||||
FOUND_METHOD,
|
/* The received message is a valid .Get call. */
|
||||||
FOUND_GET_PROPERTY,
|
FOUND_GET_PROPERTY,
|
||||||
|
|
||||||
|
/* The received message is a valid .Set call. */
|
||||||
FOUND_SET_PROPERTY,
|
FOUND_SET_PROPERTY,
|
||||||
|
|
||||||
|
/* The received message is a valid .GetAll call. */
|
||||||
FOUND_GET_ALL,
|
FOUND_GET_ALL,
|
||||||
PROPERTY_ACCESS_DENIED,
|
|
||||||
NO_SUCH_METHOD,
|
/* The received message is a valid method call. */
|
||||||
|
FOUND_METHOD,
|
||||||
|
|
||||||
|
/* The interface of the received message hasn't been registered for the
|
||||||
|
* destination object. */
|
||||||
|
NO_SUCH_INTERFACE,
|
||||||
|
|
||||||
|
/* No property handler was found for the received .Get or .Set call. */
|
||||||
NO_SUCH_PROPERTY,
|
NO_SUCH_PROPERTY,
|
||||||
INVALID_MESSAGE_ARGUMENTS
|
|
||||||
|
/* The interface argument of a property call didn't match any registered
|
||||||
|
* interface. */
|
||||||
|
NO_SUCH_PROPERTY_INTERFACE,
|
||||||
|
|
||||||
|
/* The received message called .Get or .Set for a property whose access
|
||||||
|
* mode doesn't match the call. */
|
||||||
|
PROPERTY_ACCESS_DENIED,
|
||||||
|
|
||||||
|
/* The new value signature of a .Set call didn't match the expexted
|
||||||
|
* signature. */
|
||||||
|
INVALID_PROPERTY_SIG,
|
||||||
|
|
||||||
|
/* No method handler was found for the received message. */
|
||||||
|
NO_SUCH_METHOD,
|
||||||
|
|
||||||
|
/* The signature of the received message didn't match the expected
|
||||||
|
* signature. Despite the name, this can also be returned for a property
|
||||||
|
* call if its message signature is invalid. */
|
||||||
|
INVALID_METHOD_SIG
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum find_result_t find_handler_by_property(struct object_entry *obj_entry,
|
/* Data for resolving the correct reaction to a received message. */
|
||||||
DBusMessage *msg,
|
struct call_info {
|
||||||
const char *property,
|
DBusMessage *message; /* The received message. */
|
||||||
struct interface_entry **iface_entry,
|
struct object_entry *obj_entry;
|
||||||
pa_dbus_property_handler **property_handler) {
|
const char *interface; /* Destination interface name (extracted from the message). */
|
||||||
|
struct interface_entry *iface_entry;
|
||||||
|
|
||||||
|
const char *property; /* Property name (extracted from the message). */
|
||||||
|
const char *property_interface; /* The interface argument of a property call is stored here. */
|
||||||
|
pa_dbus_property_handler *property_handler;
|
||||||
|
const char *expected_property_sig; /* Property signature from the introspection data. */
|
||||||
|
const char *property_sig; /* The signature of the new value in the received .Set message. */
|
||||||
|
DBusMessageIter variant_iter; /* Iterator pointing to the beginning of the new value variant of a .Set call. */
|
||||||
|
|
||||||
|
const char *method; /* Method name (extracted from the message). */
|
||||||
|
pa_dbus_method_handler *method_handler;
|
||||||
|
const char *expected_method_sig; /* Method signature from the introspection data. */
|
||||||
|
const char *method_sig; /* The signature of the received message. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Called when call_info->property has been set and the property interface has
|
||||||
|
* not been given. In case of a Set call, call_info->property_sig is also set,
|
||||||
|
* which is checked against the expected value in this function. */
|
||||||
|
static enum find_result_t find_handler_by_property(struct call_info *call_info) {
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
|
|
||||||
pa_assert(obj_entry);
|
pa_assert(call_info);
|
||||||
pa_assert(msg);
|
|
||||||
pa_assert(property);
|
|
||||||
pa_assert(iface_entry);
|
|
||||||
pa_assert(property_handler);
|
|
||||||
|
|
||||||
PA_HASHMAP_FOREACH(*iface_entry, obj_entry->interfaces, state) {
|
PA_HASHMAP_FOREACH(call_info->iface_entry, call_info->obj_entry->interfaces, state) {
|
||||||
if ((*property_handler = pa_hashmap_get((*iface_entry)->property_handlers, property))) {
|
if ((call_info->property_handler = pa_hashmap_get(call_info->iface_entry->property_handlers, call_info->property))) {
|
||||||
if (dbus_message_has_member(msg, "Get"))
|
if (pa_streq(call_info->method, "Get"))
|
||||||
return (*property_handler)->get_cb ? FOUND_GET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
return call_info->property_handler->get_cb ? FOUND_GET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
||||||
else if (dbus_message_has_member(msg, "Set"))
|
|
||||||
return (*property_handler)->set_cb ? FOUND_SET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
else if (pa_streq(call_info->method, "Set")) {
|
||||||
|
call_info->expected_property_sig = call_info->property_handler->type;
|
||||||
|
|
||||||
|
if (pa_streq(call_info->property_sig, call_info->expected_property_sig))
|
||||||
|
return call_info->property_handler->set_cb ? FOUND_SET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
||||||
else
|
else
|
||||||
|
return INVALID_PROPERTY_SIG;
|
||||||
|
|
||||||
|
} else
|
||||||
pa_assert_not_reached();
|
pa_assert_not_reached();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -295,120 +348,138 @@ static enum find_result_t find_handler_by_property(struct object_entry *obj_entr
|
||||||
return NO_SUCH_PROPERTY;
|
return NO_SUCH_PROPERTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum find_result_t find_handler_by_method(struct object_entry *obj_entry,
|
static enum find_result_t find_handler_by_method(struct call_info *call_info) {
|
||||||
const char *method,
|
|
||||||
struct interface_entry **iface_entry,
|
|
||||||
pa_dbus_method_handler **method_handler) {
|
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
|
|
||||||
pa_assert(obj_entry);
|
pa_assert(call_info);
|
||||||
pa_assert(method);
|
|
||||||
pa_assert(iface_entry);
|
|
||||||
pa_assert(method_handler);
|
|
||||||
|
|
||||||
PA_HASHMAP_FOREACH(*iface_entry, obj_entry->interfaces, state) {
|
PA_HASHMAP_FOREACH(call_info->iface_entry, call_info->obj_entry->interfaces, state) {
|
||||||
if ((*method_handler = pa_hashmap_get((*iface_entry)->method_handlers, method)))
|
if ((call_info->method_handler = pa_hashmap_get(call_info->iface_entry->method_handlers, call_info->method)))
|
||||||
return FOUND_METHOD;
|
return FOUND_METHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO_SUCH_METHOD;
|
return NO_SUCH_METHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum find_result_t find_handler_from_properties_call(struct object_entry *obj_entry,
|
static enum find_result_t find_handler_from_properties_call(struct call_info *call_info) {
|
||||||
DBusMessage *msg,
|
pa_assert(call_info);
|
||||||
struct interface_entry **iface_entry,
|
|
||||||
pa_dbus_property_handler **property_handler,
|
|
||||||
const char **attempted_property) {
|
|
||||||
const char *interface;
|
|
||||||
|
|
||||||
pa_assert(obj_entry);
|
if (pa_streq(call_info->method, "GetAll")) {
|
||||||
pa_assert(msg);
|
call_info->expected_method_sig = "s";
|
||||||
pa_assert(iface_entry);
|
if (!pa_streq(call_info->method_sig, call_info->expected_method_sig))
|
||||||
|
return INVALID_METHOD_SIG;
|
||||||
|
|
||||||
if (dbus_message_has_member(msg, "GetAll")) {
|
pa_assert_se(dbus_message_get_args(call_info->message, NULL,
|
||||||
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID))
|
DBUS_TYPE_STRING, &call_info->property_interface,
|
||||||
return INVALID_MESSAGE_ARGUMENTS;
|
DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
if (*interface) {
|
if (*call_info->property_interface) {
|
||||||
if ((*iface_entry = pa_hashmap_get(obj_entry->interfaces, interface)))
|
if ((call_info->iface_entry = pa_hashmap_get(call_info->obj_entry->interfaces, call_info->property_interface)))
|
||||||
return FOUND_GET_ALL;
|
return FOUND_GET_ALL;
|
||||||
else {
|
|
||||||
return NO_SUCH_METHOD; /* XXX: NO_SUCH_INTERFACE or something like that might be more accurate. */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pa_assert_se((*iface_entry = pa_hashmap_first(obj_entry->interfaces)));
|
|
||||||
return FOUND_GET_ALL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, attempted_property, DBUS_TYPE_INVALID))
|
|
||||||
return INVALID_MESSAGE_ARGUMENTS;
|
|
||||||
|
|
||||||
if (*interface) {
|
|
||||||
if ((*iface_entry = pa_hashmap_get(obj_entry->interfaces, interface)) &&
|
|
||||||
(*property_handler = pa_hashmap_get((*iface_entry)->property_handlers, *attempted_property))) {
|
|
||||||
if (dbus_message_has_member(msg, "Get"))
|
|
||||||
return (*property_handler)->get_cb ? FOUND_GET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
|
||||||
else if (dbus_message_has_member(msg, "Set"))
|
|
||||||
return (*property_handler)->set_cb ? FOUND_SET_PROPERTY : PROPERTY_ACCESS_DENIED;
|
|
||||||
else
|
else
|
||||||
pa_assert_not_reached();
|
return NO_SUCH_PROPERTY_INTERFACE;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pa_assert_se(call_info->iface_entry = pa_hashmap_first(call_info->obj_entry->interfaces));
|
||||||
|
return FOUND_GET_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (pa_streq(call_info->method, "Get")) {
|
||||||
|
call_info->expected_method_sig = "ss";
|
||||||
|
if (!pa_streq(call_info->method_sig, call_info->expected_method_sig))
|
||||||
|
return INVALID_METHOD_SIG;
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_get_args(call_info->message, NULL,
|
||||||
|
DBUS_TYPE_STRING, &call_info->property_interface,
|
||||||
|
DBUS_TYPE_STRING, &call_info->property,
|
||||||
|
DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
|
if (*call_info->property_interface) {
|
||||||
|
if (!(call_info->iface_entry = pa_hashmap_get(call_info->obj_entry->interfaces, call_info->property_interface)))
|
||||||
|
return NO_SUCH_PROPERTY_INTERFACE;
|
||||||
|
else if ((call_info->property_handler =
|
||||||
|
pa_hashmap_get(call_info->iface_entry->property_handlers, call_info->property)))
|
||||||
|
return FOUND_GET_PROPERTY;
|
||||||
|
else
|
||||||
|
return NO_SUCH_PROPERTY;
|
||||||
|
|
||||||
|
} else
|
||||||
|
return find_handler_by_property(call_info);
|
||||||
|
|
||||||
|
} else if (pa_streq(call_info->method, "Set")) {
|
||||||
|
DBusMessageIter msg_iter;
|
||||||
|
|
||||||
|
call_info->expected_method_sig = "ssv";
|
||||||
|
if (!pa_streq(call_info->method_sig, call_info->expected_method_sig))
|
||||||
|
return INVALID_METHOD_SIG;
|
||||||
|
|
||||||
|
pa_assert_se(dbus_message_iter_init(call_info->message, &msg_iter));
|
||||||
|
|
||||||
|
dbus_message_iter_get_basic(&msg_iter, &call_info->property_interface);
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
|
dbus_message_iter_get_basic(&msg_iter, &call_info->property);
|
||||||
|
pa_assert_se(dbus_message_iter_next(&msg_iter));
|
||||||
|
|
||||||
|
dbus_message_iter_recurse(&msg_iter, &call_info->variant_iter);
|
||||||
|
|
||||||
|
call_info->property_sig = dbus_message_iter_get_signature(&call_info->variant_iter);
|
||||||
|
|
||||||
|
if (*call_info->property_interface) {
|
||||||
|
if (!(call_info->iface_entry = pa_hashmap_get(call_info->obj_entry->interfaces, call_info->property_interface)))
|
||||||
|
return NO_SUCH_PROPERTY_INTERFACE;
|
||||||
|
|
||||||
|
else if ((call_info->property_handler =
|
||||||
|
pa_hashmap_get(call_info->iface_entry->property_handlers, call_info->property))) {
|
||||||
|
call_info->expected_property_sig = call_info->property_handler->type;
|
||||||
|
|
||||||
|
if (pa_streq(call_info->property_sig, call_info->expected_property_sig))
|
||||||
|
return FOUND_SET_PROPERTY;
|
||||||
|
else
|
||||||
|
return INVALID_PROPERTY_SIG;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
return NO_SUCH_PROPERTY;
|
return NO_SUCH_PROPERTY;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
return find_handler_by_property(obj_entry, msg, *attempted_property, iface_entry, property_handler);
|
return find_handler_by_property(call_info);
|
||||||
}
|
|
||||||
|
} else
|
||||||
|
pa_assert_not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum find_result_t find_handler(struct object_entry *obj_entry,
|
static enum find_result_t find_handler(struct call_info *call_info) {
|
||||||
DBusMessage *msg,
|
pa_assert(call_info);
|
||||||
struct interface_entry **iface_entry,
|
|
||||||
pa_dbus_method_handler **method_handler,
|
|
||||||
pa_dbus_property_handler **property_handler,
|
|
||||||
const char **attempted_property) {
|
|
||||||
const char *interface;
|
|
||||||
|
|
||||||
pa_assert(obj_entry);
|
if (call_info->interface) {
|
||||||
pa_assert(msg);
|
if (pa_streq(call_info->interface, DBUS_INTERFACE_PROPERTIES))
|
||||||
pa_assert(iface_entry);
|
return find_handler_from_properties_call(call_info);
|
||||||
pa_assert(method_handler);
|
|
||||||
pa_assert(property_handler);
|
|
||||||
pa_assert(attempted_property);
|
|
||||||
|
|
||||||
*iface_entry = NULL;
|
else if (!(call_info->iface_entry = pa_hashmap_get(call_info->obj_entry->interfaces, call_info->interface)))
|
||||||
*method_handler = NULL;
|
return NO_SUCH_INTERFACE;
|
||||||
|
|
||||||
if (dbus_message_has_interface(msg, DBUS_INTERFACE_PROPERTIES))
|
else if ((call_info->method_handler = pa_hashmap_get(call_info->iface_entry->method_handlers, call_info->method)))
|
||||||
return find_handler_from_properties_call(obj_entry, msg, iface_entry, property_handler, attempted_property);
|
|
||||||
|
|
||||||
else if ((interface = dbus_message_get_interface(msg))) {
|
|
||||||
if ((*iface_entry = pa_hashmap_get(obj_entry->interfaces, interface)) &&
|
|
||||||
(*method_handler = pa_hashmap_get((*iface_entry)->method_handlers, dbus_message_get_member(msg))))
|
|
||||||
return FOUND_METHOD;
|
return FOUND_METHOD;
|
||||||
else {
|
|
||||||
pa_log("Message has unknown interface or there's no method handler.");
|
else
|
||||||
return NO_SUCH_METHOD;
|
return NO_SUCH_METHOD;
|
||||||
}
|
|
||||||
|
|
||||||
} else { /* The method call doesn't contain an interface. */
|
} else { /* The method call doesn't contain an interface. */
|
||||||
if (dbus_message_has_member(msg, "Get") || dbus_message_has_member(msg, "Set") || dbus_message_has_member(msg, "GetAll")) {
|
if (pa_streq(call_info->method, "Get") || pa_streq(call_info->method, "Set") || pa_streq(call_info->method, "GetAll")) {
|
||||||
if (find_handler_by_method(obj_entry, dbus_message_get_member(msg), iface_entry, method_handler) == FOUND_METHOD)
|
if (find_handler_by_method(call_info) == FOUND_METHOD)
|
||||||
return FOUND_METHOD; /* The object has a method named Get, Set or GetAll in some other interface than .Properties. */
|
/* The object has a method named Get, Set or GetAll in some other interface than .Properties. */
|
||||||
|
return FOUND_METHOD;
|
||||||
else
|
else
|
||||||
/* Assume this is a .Properties call. */
|
/* Assume this is a .Properties call. */
|
||||||
return find_handler_from_properties_call(obj_entry, msg, iface_entry, property_handler, attempted_property);
|
return find_handler_from_properties_call(call_info);
|
||||||
|
|
||||||
} else /* This is not a .Properties call. */
|
} else /* This is not a .Properties call. */
|
||||||
return find_handler_by_method(obj_entry, dbus_message_get_member(msg), iface_entry, method_handler);
|
return find_handler_by_method(call_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DBusHandlerResult handle_message_cb(DBusConnection *connection, DBusMessage *message, void *user_data) {
|
static DBusHandlerResult handle_message_cb(DBusConnection *connection, DBusMessage *message, void *user_data) {
|
||||||
pa_dbus_protocol *p = user_data;
|
pa_dbus_protocol *p = user_data;
|
||||||
struct object_entry *obj_entry = NULL;
|
struct call_info call_info;
|
||||||
struct interface_entry *iface_entry = NULL;
|
|
||||||
pa_dbus_method_handler *method_handler = NULL;
|
|
||||||
pa_dbus_property_handler *property_handler = NULL;
|
|
||||||
const char *attempted_property = NULL;
|
|
||||||
|
|
||||||
pa_assert(connection);
|
pa_assert(connection);
|
||||||
pa_assert(message);
|
pa_assert(message);
|
||||||
|
|
@ -423,49 +494,72 @@ static DBusHandlerResult handle_message_cb(DBusConnection *connection, DBusMessa
|
||||||
dbus_message_get_interface(message),
|
dbus_message_get_interface(message),
|
||||||
dbus_message_get_member(message));
|
dbus_message_get_member(message));
|
||||||
|
|
||||||
pa_assert_se((obj_entry = pa_hashmap_get(p->objects, dbus_message_get_path(message))));
|
call_info.message = message;
|
||||||
|
pa_assert_se(call_info.obj_entry = pa_hashmap_get(p->objects, dbus_message_get_path(message)));
|
||||||
|
call_info.interface = dbus_message_get_interface(message);
|
||||||
|
pa_assert_se(call_info.method = dbus_message_get_member(message));
|
||||||
|
pa_assert_se(call_info.method_sig = dbus_message_get_signature(message));
|
||||||
|
|
||||||
if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") ||
|
if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") ||
|
||||||
(!dbus_message_get_interface(message) && dbus_message_has_member(message, "Introspect"))) {
|
(!dbus_message_get_interface(message) && dbus_message_has_member(message, "Introspect"))) {
|
||||||
pa_dbus_send_basic_value_reply(connection, message, DBUS_TYPE_STRING, &obj_entry->introspection);
|
pa_dbus_send_basic_value_reply(connection, message, DBUS_TYPE_STRING, &call_info.obj_entry->introspection);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (find_handler(obj_entry, message, &iface_entry, &method_handler, &property_handler, &attempted_property)) {
|
switch (find_handler(&call_info)) {
|
||||||
case FOUND_METHOD:
|
|
||||||
method_handler->receive_cb(connection, message, iface_entry->userdata);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FOUND_GET_PROPERTY:
|
case FOUND_GET_PROPERTY:
|
||||||
property_handler->get_cb(connection, message, iface_entry->userdata);
|
call_info.property_handler->get_cb(connection, message, call_info.iface_entry->userdata);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOUND_SET_PROPERTY:
|
case FOUND_SET_PROPERTY:
|
||||||
property_handler->set_cb(connection, message, iface_entry->userdata);
|
call_info.property_handler->set_cb(connection, message, &call_info.variant_iter, call_info.iface_entry->userdata);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FOUND_METHOD:
|
||||||
|
call_info.method_handler->receive_cb(connection, message, call_info.iface_entry->userdata);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOUND_GET_ALL:
|
case FOUND_GET_ALL:
|
||||||
if (iface_entry->get_all_properties_cb)
|
if (call_info.iface_entry->get_all_properties_cb)
|
||||||
iface_entry->get_all_properties_cb(connection, message, iface_entry->userdata);
|
call_info.iface_entry->get_all_properties_cb(connection, message, call_info.iface_entry->userdata);
|
||||||
/* TODO: Write an else branch where a dummy response is sent. */
|
else {
|
||||||
|
DBusMessage *dummy_reply = NULL;
|
||||||
|
DBusMessageIter msg_iter;
|
||||||
|
DBusMessageIter dict_iter;
|
||||||
|
|
||||||
|
pa_assert_se(dummy_reply = dbus_message_new_method_return(message));
|
||||||
|
dbus_message_iter_init_append(dummy_reply, &msg_iter);
|
||||||
|
pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter));
|
||||||
|
pa_assert_se(dbus_message_iter_close_container(&msg_iter, &dict_iter));
|
||||||
|
pa_assert_se(dbus_connection_send(connection, dummy_reply, NULL));
|
||||||
|
dbus_message_unref(dummy_reply);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROPERTY_ACCESS_DENIED:
|
case PROPERTY_ACCESS_DENIED:
|
||||||
pa_dbus_send_error(connection, message, DBUS_ERROR_ACCESS_DENIED, "%s access denied for property %s", dbus_message_get_member(message), attempted_property);
|
pa_dbus_send_error(connection, message, DBUS_ERROR_ACCESS_DENIED,
|
||||||
|
"%s access denied for property %s", call_info.method, call_info.property);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NO_SUCH_METHOD:
|
case NO_SUCH_METHOD:
|
||||||
pa_dbus_send_error(connection, message, DBUS_ERROR_UNKNOWN_METHOD, "%s: No such method", dbus_message_get_member(message));
|
pa_dbus_send_error(connection, message, DBUS_ERROR_UNKNOWN_METHOD, "No such method: %s", call_info.method);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NO_SUCH_PROPERTY:
|
case NO_SUCH_PROPERTY:
|
||||||
pa_dbus_send_error(connection, message, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s: No such property", attempted_property);
|
pa_dbus_send_error(connection, message, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "No such property: %s", call_info.property);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INVALID_MESSAGE_ARGUMENTS:
|
case INVALID_METHOD_SIG:
|
||||||
pa_dbus_send_error(connection, message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments for %s", dbus_message_get_member(message));
|
pa_dbus_send_error(connection, message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Invalid signature for method %s: '%s'. Expected '%s'.",
|
||||||
|
call_info.method, call_info.method_sig, call_info.expected_method_sig);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case INVALID_PROPERTY_SIG:
|
||||||
|
pa_dbus_send_error(connection, message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Invalid signature for property %s: '%s'. Expected '%s'.",
|
||||||
|
call_info.property, call_info.property_sig, call_info.expected_property_sig);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
pa_assert_not_reached();
|
pa_assert_not_reached();
|
||||||
}
|
}
|
||||||
|
|
@ -821,7 +915,12 @@ pa_client *pa_dbus_protocol_get_client(pa_dbus_protocol *p, DBusConnection *conn
|
||||||
return conn_entry->client;
|
return conn_entry->client;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_dbus_protocol_add_signal_listener(pa_dbus_protocol *p, DBusConnection *conn, const char *signal, char **objects, unsigned n_objects) {
|
void pa_dbus_protocol_add_signal_listener(
|
||||||
|
pa_dbus_protocol *p,
|
||||||
|
DBusConnection *conn,
|
||||||
|
const char *signal,
|
||||||
|
char **objects,
|
||||||
|
unsigned n_objects) {
|
||||||
struct connection_entry *conn_entry;
|
struct connection_entry *conn_entry;
|
||||||
pa_idxset *object_set;
|
pa_idxset *object_set;
|
||||||
char *object_path;
|
char *object_path;
|
||||||
|
|
@ -981,7 +1080,12 @@ int pa_dbus_protocol_unregister_extension(pa_dbus_protocol *p, const char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_hook_slot *pa_dbus_protocol_hook_connect(pa_dbus_protocol *p, pa_dbus_protocol_hook_t hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data) {
|
pa_hook_slot *pa_dbus_protocol_hook_connect(
|
||||||
|
pa_dbus_protocol *p,
|
||||||
|
pa_dbus_protocol_hook_t hook,
|
||||||
|
pa_hook_priority_t prio,
|
||||||
|
pa_hook_cb_t cb,
|
||||||
|
void *data) {
|
||||||
pa_assert(p);
|
pa_assert(p);
|
||||||
pa_assert(hook < PA_DBUS_PROTOCOL_HOOK_MAX);
|
pa_assert(hook < PA_DBUS_PROTOCOL_HOOK_MAX);
|
||||||
pa_assert(cb);
|
pa_assert(cb);
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,19 @@ void pa_dbus_protocol_unref(pa_dbus_protocol *p);
|
||||||
* message isn't a good idea; if you can't handle the message, reply with an
|
* message isn't a good idea; if you can't handle the message, reply with an
|
||||||
* error.
|
* error.
|
||||||
*
|
*
|
||||||
|
* The message signature is already checked against the introspection data, so
|
||||||
|
* you don't have to do that yourself.
|
||||||
|
*
|
||||||
* All messages are method calls. */
|
* All messages are method calls. */
|
||||||
typedef void (*pa_dbus_receive_cb_t)(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
typedef void (*pa_dbus_receive_cb_t)(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||||
|
|
||||||
|
/* A specialized version of pa_dbus_receive_cb_t: the additional iterator
|
||||||
|
* argument points to the element inside the new value variant.
|
||||||
|
*
|
||||||
|
* The new value signature is checked against the introspection data, so you
|
||||||
|
* don't have to do that yourself. */
|
||||||
|
typedef void (*pa_dbus_set_property_cb_t)(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata);
|
||||||
|
|
||||||
typedef struct pa_dbus_arg_info {
|
typedef struct pa_dbus_arg_info {
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *type;
|
const char *type;
|
||||||
|
|
@ -85,7 +95,7 @@ typedef struct pa_dbus_property_handler {
|
||||||
/* The access mode for the property is determined by checking whether
|
/* The access mode for the property is determined by checking whether
|
||||||
* get_cb or set_cb is NULL. */
|
* get_cb or set_cb is NULL. */
|
||||||
pa_dbus_receive_cb_t get_cb;
|
pa_dbus_receive_cb_t get_cb;
|
||||||
pa_dbus_receive_cb_t set_cb;
|
pa_dbus_set_property_cb_t set_cb;
|
||||||
} pa_dbus_property_handler;
|
} pa_dbus_property_handler;
|
||||||
|
|
||||||
typedef struct pa_dbus_interface_info {
|
typedef struct pa_dbus_interface_info {
|
||||||
|
|
@ -140,7 +150,12 @@ pa_client *pa_dbus_protocol_get_client(pa_dbus_protocol *p, DBusConnection *conn
|
||||||
* only signals from the given objects are delivered. If this function is
|
* only signals from the given objects are delivered. If this function is
|
||||||
* called multiple time for the same connection and signal, the latest call
|
* called multiple time for the same connection and signal, the latest call
|
||||||
* always replaces the previous object list. */
|
* always replaces the previous object list. */
|
||||||
void pa_dbus_protocol_add_signal_listener(pa_dbus_protocol *p, DBusConnection *conn, const char *signal, char **objects, unsigned n_objects);
|
void pa_dbus_protocol_add_signal_listener(
|
||||||
|
pa_dbus_protocol *p,
|
||||||
|
DBusConnection *conn,
|
||||||
|
const char *signal,
|
||||||
|
char **objects,
|
||||||
|
unsigned n_objects);
|
||||||
|
|
||||||
/* Disables the delivery of the signal for the given connection. The connection
|
/* Disables the delivery of the signal for the given connection. The connection
|
||||||
* must have been registered. If signal is NULL, all signals are disabled. If
|
* must have been registered. If signal is NULL, all signals are disabled. If
|
||||||
|
|
@ -192,6 +207,11 @@ typedef enum pa_dbus_protocol_hook {
|
||||||
PA_DBUS_PROTOCOL_HOOK_MAX
|
PA_DBUS_PROTOCOL_HOOK_MAX
|
||||||
} pa_dbus_protocol_hook_t;
|
} pa_dbus_protocol_hook_t;
|
||||||
|
|
||||||
pa_hook_slot *pa_dbus_protocol_hook_connect(pa_dbus_protocol *p, pa_dbus_protocol_hook_t hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data);
|
pa_hook_slot *pa_dbus_protocol_hook_connect(
|
||||||
|
pa_dbus_protocol *p,
|
||||||
|
pa_dbus_protocol_hook_t hook,
|
||||||
|
pa_hook_priority_t prio,
|
||||||
|
pa_hook_cb_t cb,
|
||||||
|
void *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue