assert(p);
t = pa_tagstruct_new(NULL, 0);
- assert(t);
pa_tagstruct_putu32(t, PA_COMMAND_PLAYBACK_STREAM_KILLED);
pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
pa_tagstruct_putu32(t, p->index);
assert(r);
t = pa_tagstruct_new(NULL, 0);
- assert(t);
pa_tagstruct_putu32(t, PA_COMMAND_RECORD_STREAM_KILLED);
pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
pa_tagstruct_putu32(t, r->index);
connection_free(c);
}
+#define CHECK_VALIDITY(pstream, expression, tag, error) do { \
+if (!(expression)) { \
+ pa_pstream_send_error((pstream), (tag), (error)); \
+ return; \
+} \
+} while(0);
+
+static pa_tagstruct *reply_new(uint32_t tag) {
+ pa_tagstruct *reply;
+
+ reply = pa_tagstruct_new(NULL, 0);
+ pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
+ pa_tagstruct_putu32(reply, tag);
+ return reply;
+}
+
static void command_create_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
struct connection *c = userdata;
struct playback_stream *s;
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, sink_index != PA_INVALID_INDEX || !sink_name || *sink_name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, map.channels == ss.channels && volume.channels == ss.channels, tag, PA_ERR_INVALID);
if (sink_index != PA_INVALID_INDEX)
sink = pa_idxset_get_by_index(c->protocol->core->sinks, sink_index);
else
sink = pa_namereg_get(c->protocol->core, sink_name, PA_NAMEREG_SINK, 1);
- if (!sink) {
- pa_log_warn(__FILE__": Can't find a suitable sink.\n");
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
-
- if (!(s = playback_stream_new(c, sink, &ss, &map, name, maxlength, tlength, prebuf, minreq, &volume, syncid))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
- return;
- }
+ CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
+
+ s = playback_stream_new(c, sink, &ss, &map, name, maxlength, tlength, prebuf, minreq, &volume, syncid);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_INVALID);
pa_sink_input_cork(s->sink_input, corked);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, s->index);
assert(s->sink_input);
pa_tagstruct_putu32(reply, s->sink_input->index);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
if (command == PA_COMMAND_DELETE_PLAYBACK_STREAM) {
struct playback_stream *s;
int corked;
assert(c && t && c->protocol && c->protocol->core);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
pa_tagstruct_get_channel_map(t, &map) < 0 ||
pa_tagstruct_getu32(t, &source_index) < 0 ||
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, source_index != PA_INVALID_INDEX || !source_name || *source_name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, map.channels == ss.channels, tag, PA_ERR_INVALID);
- if (source_index != (uint32_t) -1)
+ if (source_index != PA_INVALID_INDEX)
source = pa_idxset_get_by_index(c->protocol->core->sources, source_index);
else
source = pa_namereg_get(c->protocol->core, source_name, PA_NAMEREG_SOURCE, 1);
- if (!source) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
+
+ s = record_stream_new(c, source, &ss, &map, name, maxlength, fragment_size);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_INVALID);
- if (!(s = record_stream_new(c, source, &ss, &map, name, maxlength, fragment_size))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
- return;
- }
-
pa_source_output_cork(s->source_output, corked);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, s->index);
assert(s->source_output);
pa_tagstruct_putu32(reply, s->source_output->index);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
assert(c->protocol && c->protocol->core && c->protocol->core->mainloop);
c->protocol->core->mainloop->quit(c->protocol->core->mainloop, 0);
pa_pstream_send_simple_ack(c->pstream, tag); /* nonsense */
- return;
}
static void command_auth(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
}
pa_pstream_send_simple_ack(c->pstream, tag);
- return;
}
static void command_set_client_name(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
const char *name;
assert(c && t);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
+ CHECK_VALIDITY(c->pstream, name, tag, PA_ERR_INVALID);
+
pa_client_set_name(c->client, name);
pa_pstream_send_simple_ack(c->pstream, tag);
- return;
}
static void command_lookup(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
uint32_t idx = PA_IDXSET_INVALID;
assert(c && t);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name && *name, tag, PA_ERR_INVALID);
if (command == PA_COMMAND_LOOKUP_SINK) {
pa_sink *sink;
pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
else {
pa_tagstruct *reply;
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, idx);
pa_pstream_send_tagstruct(c->pstream, reply);
}
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->output_streams, idx)) || s->type != PLAYBACK_STREAM) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
-
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ s = pa_idxset_get_by_index(c->output_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == PLAYBACK_STREAM, tag, PA_ERR_NOENTITY);
+
s->drain_request = 0;
pa_memblockq_prebuf_disable(s->memblockq);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->total);
pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->total_size);
pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->allocated);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->output_streams, idx)) || s->type != PLAYBACK_STREAM) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ s = pa_idxset_get_by_index(c->output_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == PLAYBACK_STREAM, tag, PA_ERR_NOENTITY);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_put_usec(reply, pa_sink_input_get_latency(s->sink_input));
pa_tagstruct_put_usec(reply, pa_sink_get_latency(s->sink_input->sink));
pa_tagstruct_put_usec(reply, 0);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->record_streams, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ s = pa_idxset_get_by_index(c->record_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_put_usec(reply, pa_source_output_get_latency(s->source_output));
pa_tagstruct_put_usec(reply, s->source_output->source->monitor_of ? pa_sink_get_latency(s->source_output->source->monitor_of) : 0);
pa_tagstruct_put_usec(reply, pa_source_get_latency(s->source_output->source));
pa_pstream_send_tagstruct(c->pstream, reply);
}
-
static void command_create_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
struct connection *c = userdata;
struct upload_stream *s;
pa_tagstruct *reply;
assert(c && t && c->protocol && c->protocol->core);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
pa_tagstruct_get_channel_map(t, &map) < 0 ||
pa_tagstruct_getu32(t, &length) < 0 ||
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if ((length % pa_frame_size(&ss)) != 0 || length <= 0 || !*name) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, (length % pa_frame_size(&ss)) == 0 && length > 0, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, name && *name, tag, PA_ERR_INVALID);
- if (!(s = upload_stream_new(c, &ss, &map, name, length))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
- return;
- }
+ s = upload_stream_new(c, &ss, &map, name, length);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_INVALID);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, s->index);
pa_tagstruct_putu32(reply, length);
pa_pstream_send_tagstruct(c->pstream, reply);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- if (!(s = pa_idxset_get_by_index(c->output_streams, channel)) || (s->type != UPLOAD_STREAM)) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_EXIST);
- return;
- }
+ s = pa_idxset_get_by_index(c->output_streams, channel);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == UPLOAD_STREAM, tag, PA_ERR_NOENTITY);
pa_scache_add_item(c->protocol->core, s->name, &s->sample_spec, &s->channel_map, &s->memchunk, &idx);
pa_pstream_send_simple_ack(c->pstream, tag);
if (pa_tagstruct_getu32(t, &sink_index) < 0 ||
pa_tagstruct_gets(t, &sink_name) < 0 ||
pa_tagstruct_get_cvolume(t, &volume) < 0 ||
- pa_tagstruct_gets(t, &name) < 0 || !name ||
+ pa_tagstruct_gets(t, &name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, sink_index != PA_INVALID_INDEX || !sink_name || *sink_name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, name && *name, tag, PA_ERR_INVALID);
- if (sink_index != (uint32_t) -1)
+ if (sink_index != PA_INVALID_INDEX)
sink = pa_idxset_get_by_index(c->protocol->core->sinks, sink_index);
else
sink = pa_namereg_get(c->protocol->core, sink_name, PA_NAMEREG_SINK, 1);
- if (!sink) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
if (pa_scache_play_item(c->protocol->core, name, sink, &volume) < 0) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
const char *name;
assert(c && t);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name && *name, tag, PA_ERR_INVALID);
if (pa_scache_remove_item(c->protocol->core, name) < 0) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
assert(t && client);
pa_tagstruct_putu32(t, client->index);
pa_tagstruct_puts(t, client->name);
- pa_tagstruct_putu32(t, client->owner ? client->owner->index : (uint32_t) -1);
+ pa_tagstruct_putu32(t, client->owner ? client->owner->index : PA_INVALID_INDEX);
pa_tagstruct_puts(t, client->driver);
}
assert(t && s);
pa_tagstruct_putu32(t, s->index);
pa_tagstruct_puts(t, s->name);
- pa_tagstruct_putu32(t, s->owner ? s->owner->index : (uint32_t) -1);
- pa_tagstruct_putu32(t, s->client ? s->client->index : (uint32_t) -1);
+ pa_tagstruct_putu32(t, s->owner ? s->owner->index : PA_INVALID_INDEX);
+ pa_tagstruct_putu32(t, s->client ? s->client->index : PA_INVALID_INDEX);
pa_tagstruct_putu32(t, s->sink->index);
pa_tagstruct_put_sample_spec(t, &s->sample_spec);
pa_tagstruct_put_channel_map(t, &s->channel_map);
assert(t && s);
pa_tagstruct_putu32(t, s->index);
pa_tagstruct_puts(t, s->name);
- pa_tagstruct_putu32(t, s->owner ? s->owner->index : (uint32_t) -1);
- pa_tagstruct_putu32(t, s->client ? s->client->index : (uint32_t) -1);
+ pa_tagstruct_putu32(t, s->owner ? s->owner->index : PA_INVALID_INDEX);
+ pa_tagstruct_putu32(t, s->client ? s->client->index : PA_INVALID_INDEX);
pa_tagstruct_putu32(t, s->source->index);
pa_tagstruct_put_sample_spec(t, &s->sample_spec);
pa_tagstruct_put_channel_map(t, &s->channel_map);
protocol_error(c);
return;
}
-
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
if (command == PA_COMMAND_GET_SINK_INFO) {
- if (idx != (uint32_t) -1)
+ if (idx != PA_INVALID_INDEX)
sink = pa_idxset_get_by_index(c->protocol->core->sinks, idx);
else
sink = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SINK, 1);
} else if (command == PA_COMMAND_GET_SOURCE_INFO) {
- if (idx != (uint32_t) -1)
+ if (idx != PA_INVALID_INDEX)
source = pa_idxset_get_by_index(c->protocol->core->sources, idx);
else
source = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SOURCE, 1);
so = pa_idxset_get_by_index(c->protocol->core->source_outputs, idx);
else {
assert(command == PA_COMMAND_GET_SAMPLE_INFO);
- if (idx != (uint32_t) -1)
+ if (idx != PA_INVALID_INDEX)
sce = pa_idxset_get_by_index(c->protocol->core->scache, idx);
else
sce = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SAMPLE, 0);
return;
}
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
if (sink)
sink_fill_tagstruct(reply, sink);
else if (source)
protocol_error(c);
return;
}
-
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+
+ reply = reply_new(tag);
if (command == PA_COMMAND_GET_SINK_INFO_LIST)
i = c->protocol->core->sinks;
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_puts(reply, PACKAGE_NAME);
pa_tagstruct_puts(reply, PACKAGE_VERSION);
pa_tagstruct_puts(reply, pa_get_user_name(txt, sizeof(txt)));
assert(c && core);
t = pa_tagstruct_new(NULL, 0);
- assert(t);
pa_tagstruct_putu32(t, PA_COMMAND_SUBSCRIBE_EVENT);
pa_tagstruct_putu32(t, (uint32_t) -1);
pa_tagstruct_putu32(t, e);
protocol_error(c);
return;
}
-
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, (m & ~PA_SUBSCRIPTION_MASK_ALL) == 0, tag, PA_ERR_INVALID);
+
if (c->subscription)
pa_subscription_free(c->subscription);
pa_pstream_send_simple_ack(c->pstream, tag);
}
-static void command_set_volume(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
+static void command_set_volume(
+ PA_GCC_UNUSED pa_pdispatch *pd,
+ uint32_t command,
+ uint32_t tag,
+ pa_tagstruct *t,
+ void *userdata) {
+
struct connection *c = userdata;
uint32_t idx;
pa_cvolume volume;
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || *name, tag, PA_ERR_INVALID);
if (command == PA_COMMAND_SET_SINK_VOLUME) {
- if (idx != (uint32_t) -1)
+ if (idx != PA_INVALID_INDEX)
sink = pa_idxset_get_by_index(c->protocol->core->sinks, idx);
else
sink = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SINK, 1);
si = pa_idxset_get_by_index(c->protocol->core->sink_inputs, idx);
}
- if (!si && !sink && !source) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, si || sink || source, tag, PA_ERR_NOENTITY);
if (sink)
pa_sink_set_volume(sink, PA_MIXER_HARDWARE, &volume);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->output_streams, idx)) || s->type != PLAYBACK_STREAM) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
-
- fprintf(stderr, "Corking %i\n", b);
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX, tag, PA_ERR_INVALID);
+ s = pa_idxset_get_by_index(c->output_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == PLAYBACK_STREAM, tag, PA_ERR_NOENTITY);
pa_sink_input_cork(s->sink_input, b);
pa_memblockq_prebuf_force(s->memblockq);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->output_streams, idx)) || s->type != PLAYBACK_STREAM) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX, tag, PA_ERR_INVALID);
+ s = pa_idxset_get_by_index(c->output_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == PLAYBACK_STREAM, tag, PA_ERR_NOENTITY);
pa_memblockq_flush(s->memblockq);
s->underrun = 0;
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->output_streams, idx)) || s->type != PLAYBACK_STREAM) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX, tag, PA_ERR_INVALID);
+ s = pa_idxset_get_by_index(c->output_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == PLAYBACK_STREAM, tag, PA_ERR_NOENTITY);
switch (command) {
case PA_COMMAND_PREBUF_PLAYBACK_STREAM:
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->record_streams, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ s = pa_idxset_get_by_index(c->record_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
pa_source_output_cork(s->source_output, b);
pa_memblockq_prebuf_force(s->memblockq);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(s = pa_idxset_get_by_index(c->record_streams, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ s = pa_idxset_get_by_index(c->record_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
pa_memblockq_flush(s->memblockq);
pa_pstream_send_simple_ack(c->pstream, tag);
static void command_set_default_sink_or_source(PA_GCC_UNUSED pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
struct connection *c = userdata;
- uint32_t idx;
const char *s;
assert(c && t);
- if (pa_tagstruct_getu32(t, &idx) < 0 ||
- pa_tagstruct_gets(t, &s) < 0 || !s ||
+ if (pa_tagstruct_gets(t, &s) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, !s || *s, tag, PA_ERR_INVALID);
pa_namereg_set_default(c->protocol->core, s, command == PA_COMMAND_SET_DEFAULT_SOURCE ? PA_NAMEREG_SOURCE : PA_NAMEREG_SINK);
pa_pstream_send_simple_ack(c->pstream, tag);
assert(c && t);
if (pa_tagstruct_getu32(t, &idx) < 0 ||
- pa_tagstruct_gets(t, &name) < 0 || !name ||
+ pa_tagstruct_gets(t, &name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name, tag, PA_ERR_INVALID);
if (command == PA_COMMAND_SET_PLAYBACK_STREAM_NAME) {
struct playback_stream *s;
- if (!(s = pa_idxset_get_by_index(c->output_streams, idx)) || s->type != PLAYBACK_STREAM) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ s = pa_idxset_get_by_index(c->output_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
+ CHECK_VALIDITY(c->pstream, s->type == PLAYBACK_STREAM, tag, PA_ERR_NOENTITY);
pa_sink_input_set_name(s->sink_input, name);
} else {
struct record_stream *s;
- if (!(s = pa_idxset_get_by_index(c->record_streams, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ s = pa_idxset_get_by_index(c->record_streams, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
pa_source_output_set_name(s->source_output, name);
}
protocol_error(c);
return;
}
-
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
if (command == PA_COMMAND_KILL_CLIENT) {
pa_client *client;
- if (!(client = pa_idxset_get_by_index(c->protocol->core->clients, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
-
+ client = pa_idxset_get_by_index(c->protocol->core->clients, idx);
+ CHECK_VALIDITY(c->pstream, client, tag, PA_ERR_NOENTITY);
pa_client_kill(client);
+
} else if (command == PA_COMMAND_KILL_SINK_INPUT) {
pa_sink_input *s;
- if (!(s = pa_idxset_get_by_index(c->protocol->core->sink_inputs, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ s = pa_idxset_get_by_index(c->protocol->core->sink_inputs, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
pa_sink_input_kill(s);
} else {
assert(command == PA_COMMAND_KILL_SOURCE_OUTPUT);
- if (!(s = pa_idxset_get_by_index(c->protocol->core->source_outputs, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ s = pa_idxset_get_by_index(c->protocol->core->source_outputs, idx);
+ CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY);
pa_source_output_kill(s);
}
pa_tagstruct *reply;
assert(c && t);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_gets(t, &argument) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
-
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name && *name, tag, PA_ERR_INVALID);
if (!(m = pa_module_load(c->protocol->core, name, argument))) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_MODINITFAILED);
return;
}
- reply = pa_tagstruct_new(NULL, 0);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, m->index);
pa_pstream_send_tagstruct(c->pstream, reply);
}
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
- if (!(m = pa_idxset_get_by_index(c->protocol->core->modules, idx))) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ m = pa_idxset_get_by_index(c->protocol->core->modules, idx);
+ CHECK_VALIDITY(c->pstream, m, tag, PA_ERR_NOENTITY);
pa_module_unload_request(m);
pa_pstream_send_simple_ack(c->pstream, tag);
pa_tagstruct *reply;
assert(c && t);
- if (pa_tagstruct_gets(t, &name) < 0 || !name ||
- pa_tagstruct_getu32(t, &type) < 0 || type > 1 ||
- pa_tagstruct_gets(t, &module) < 0 || !module ||
+ if (pa_tagstruct_gets(t, &name) < 0 ||
+ pa_tagstruct_getu32(t, &type) < 0 ||
+ pa_tagstruct_gets(t, &module) < 0 ||
pa_tagstruct_gets(t, &argument) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name && *name, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, type == 0 || type == 1, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, module && *module, tag, PA_ERR_INVALID);
if (pa_autoload_add(c->protocol->core, name, type == 0 ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE, module, argument, &idx) < 0) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_EXIST);
return;
}
- reply = pa_tagstruct_new(NULL, 0);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
pa_tagstruct_putu32(reply, idx);
pa_pstream_send_tagstruct(c->pstream, reply);
}
if ((pa_tagstruct_getu32(t, &idx) < 0 &&
(pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_getu32(t, &type) < 0)) ||
- (!name && idx == PA_IDXSET_INVALID) ||
- (name && type > 1) ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name || idx != PA_IDXSET_INVALID, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || (*name && (type == 0 || type == 1)), tag, PA_ERR_INVALID);
if (name)
r = pa_autoload_remove_by_name(c->protocol->core, name, type == 0 ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE);
else
r = pa_autoload_remove_by_index(c->protocol->core, idx);
- if (r < 0) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, r >= 0, tag, PA_ERR_NOENTITY);
pa_pstream_send_simple_ack(c->pstream, tag);
}
if ((pa_tagstruct_getu32(t, &idx) < 0 &&
(pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_getu32(t, &type) < 0)) ||
- (!name && idx == PA_IDXSET_INVALID) ||
- (name && type > 1) ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
-
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+ CHECK_VALIDITY(c->pstream, name || idx != PA_IDXSET_INVALID, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, !name || (*name && (type == 0 || type == 1)), tag, PA_ERR_INVALID);
if (name)
a = pa_autoload_get_by_name(c->protocol->core, name, type == 0 ? PA_NAMEREG_SINK : PA_NAMEREG_SOURCE);
else
a = pa_autoload_get_by_index(c->protocol->core, idx);
- if (!a) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
- return;
- }
+ CHECK_VALIDITY(c->pstream, a, tag, PA_ERR_NOENTITY);
- reply = pa_tagstruct_new(NULL, 0);
- assert(reply);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
autoload_fill_tagstruct(reply, a);
pa_pstream_send_tagstruct(c->pstream, reply);
}
return;
}
- if (!c->authorized) {
- pa_pstream_send_error(c->pstream, tag, PA_ERR_ACCESS);
- return;
- }
+ CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- reply = pa_tagstruct_new(NULL, 0);
- pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
- pa_tagstruct_putu32(reply, tag);
+ reply = reply_new(tag);
if (c->protocol->core->autoload_hashmap) {
pa_autoload_entry *a;
return NULL;
}
- p = pa_xmalloc(sizeof(pa_protocol_native));
+ p = pa_xnew(pa_protocol_native, 1);
p->core = c;
p->module = m;
p->public = public;