-static void command_add_autoload(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
- pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
- const char *name, *module, *argument;
- uint32_t type;
- uint32_t idx;
- pa_tagstruct *reply;
-
- pa_native_connection_assert_ref(c);
- pa_assert(t);
-
- 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;
- }
-
- CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, name && *name && pa_utf8_valid(name), tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, type == 0 || type == 1, tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, module && *module && pa_utf8_valid(module), tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, !argument || pa_utf8_valid(argument), 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 = reply_new(tag);
- pa_tagstruct_putu32(reply, idx);
- pa_pstream_send_tagstruct(c->pstream, reply);
-}
-
-static void command_remove_autoload(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
- pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
- const char *name = NULL;
- uint32_t type, idx = PA_IDXSET_INVALID;
- int r;
-
- pa_native_connection_assert_ref(c);
- pa_assert(t);
-
- if ((pa_tagstruct_getu32(t, &idx) < 0 &&
- (pa_tagstruct_gets(t, &name) < 0 ||
- pa_tagstruct_getu32(t, &type) < 0)) ||
- !pa_tagstruct_eof(t)) {
- protocol_error(c);
- 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 && pa_utf8_valid(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);
-
- CHECK_VALIDITY(c->pstream, r >= 0, tag, PA_ERR_NOENTITY);
-
- pa_pstream_send_simple_ack(c->pstream, tag);
-}
-
-static void autoload_fill_tagstruct(pa_tagstruct *t, const pa_autoload_entry *e) {
- pa_assert(t && e);
-
- pa_tagstruct_putu32(t, e->index);
- pa_tagstruct_puts(t, e->name);
- pa_tagstruct_putu32(t, e->type == PA_NAMEREG_SINK ? 0U : 1U);
- pa_tagstruct_puts(t, e->module);
- pa_tagstruct_puts(t, e->argument);
-}
-
-static void command_get_autoload_info(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
- pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
- const pa_autoload_entry *a = NULL;
- uint32_t type, idx;
- const char *name;
- pa_tagstruct *reply;
-
- pa_native_connection_assert_ref(c);
- pa_assert(t);
-
- if ((pa_tagstruct_getu32(t, &idx) < 0 &&
- (pa_tagstruct_gets(t, &name) < 0 ||
- pa_tagstruct_getu32(t, &type) < 0)) ||
- !pa_tagstruct_eof(t)) {
- protocol_error(c);
- 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) && pa_utf8_valid(name)), 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);
-
- CHECK_VALIDITY(c->pstream, a, tag, PA_ERR_NOENTITY);
-
- reply = reply_new(tag);
- autoload_fill_tagstruct(reply, a);
- pa_pstream_send_tagstruct(c->pstream, reply);
-}
-
-static void command_get_autoload_info_list(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
- pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
- pa_tagstruct *reply;
-
- pa_native_connection_assert_ref(c);
- pa_assert(t);
-
- if (!pa_tagstruct_eof(t)) {
- protocol_error(c);
- return;
- }
-
- CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
-
- reply = reply_new(tag);
-
- if (c->protocol->core->autoload_hashmap) {
- pa_autoload_entry *a;
- void *state = NULL;
-
- while ((a = pa_hashmap_iterate(c->protocol->core->autoload_hashmap, &state, NULL)))
- autoload_fill_tagstruct(reply, a);
- }
-
- pa_pstream_send_tagstruct(c->pstream, reply);
-}
-