mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
dbus-protocol: Implement TCP server startup.
This commit is contained in:
parent
123c6a3c6f
commit
3c6a0acc98
3 changed files with 42 additions and 15 deletions
|
|
@ -120,14 +120,11 @@ static DBusHandlerResult handle_get_address(DBusConnection *conn, DBusMessage *m
|
||||||
return DBUS_HANDLER_RESULT_HANDLED;
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_client_conf_free(conf);
|
|
||||||
|
|
||||||
if (conf->default_dbus_server) {
|
if (conf->default_dbus_server) {
|
||||||
if (!(address = dbus_address_escape_value(conf->default_dbus_server)))
|
address = pa_xstrdup(conf->default_dbus_server);
|
||||||
goto oom;
|
|
||||||
} else {
|
} else {
|
||||||
if (!(address = pa_get_dbus_address_from_server_type(sl->core->server_type))) {
|
if (!(address = pa_get_dbus_address_from_server_type(sl->core->server_type))) {
|
||||||
if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, "get_dbus_server_from_type() failed.")))
|
if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, "PulseAudio internal error: get_dbus_server_from_type() failed.")))
|
||||||
goto fail;
|
goto fail;
|
||||||
if (!dbus_connection_send(conn, reply, NULL))
|
if (!dbus_connection_send(conn, reply, NULL))
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
@ -144,10 +141,8 @@ static DBusHandlerResult handle_get_address(DBusConnection *conn, DBusMessage *m
|
||||||
if (!dbus_connection_send(conn, reply, NULL))
|
if (!dbus_connection_send(conn, reply, NULL))
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
||||||
pa_log_debug("handle_get_dbus_address(): Sent reply with address '%s'.", address);
|
pa_client_conf_free(conf);
|
||||||
|
|
||||||
pa_xfree(address);
|
pa_xfree(address);
|
||||||
|
|
||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
|
||||||
return DBUS_HANDLER_RESULT_HANDLED;
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ load-module module-detect
|
||||||
load-module module-esound-protocol-unix
|
load-module module-esound-protocol-unix
|
||||||
.endif
|
.endif
|
||||||
.ifexists module-dbus-protocol@PA_SOEXT@
|
.ifexists module-dbus-protocol@PA_SOEXT@
|
||||||
load-module module-dbus-protocol
|
### If you want to allow TCP connections, set access to "remote" or "local,remote".
|
||||||
|
load-module module-dbus-protocol access=local
|
||||||
.endif
|
.endif
|
||||||
load-module module-native-protocol-unix
|
load-module module-native-protocol-unix
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,11 @@ PA_MODULE_VERSION(PACKAGE_VERSION);
|
||||||
|
|
||||||
#define CLEANUP_INTERVAL 10 /* seconds */
|
#define CLEANUP_INTERVAL 10 /* seconds */
|
||||||
|
|
||||||
|
enum server_type {
|
||||||
|
SERVER_TYPE_LOCAL,
|
||||||
|
SERVER_TYPE_TCP
|
||||||
|
};
|
||||||
|
|
||||||
struct server;
|
struct server;
|
||||||
struct connection;
|
struct connection;
|
||||||
|
|
||||||
|
|
@ -75,6 +80,7 @@ struct userdata {
|
||||||
|
|
||||||
struct server {
|
struct server {
|
||||||
struct userdata *userdata;
|
struct userdata *userdata;
|
||||||
|
enum server_type type;
|
||||||
DBusServer *dbus_server;
|
DBusServer *dbus_server;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -114,6 +120,12 @@ static void client_kill_cb(pa_client *c) {
|
||||||
pa_log_info("Connection killed.");
|
pa_log_info("Connection killed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static dbus_bool_t user_check_cb(DBusConnection *connection, unsigned long uid, void *data) {
|
||||||
|
pa_log_debug("Allowing connection by user %lu.", uid);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Called by D-Bus when a new client connection is received. */
|
/* Called by D-Bus when a new client connection is received. */
|
||||||
static void connection_new_cb(DBusServer *dbus_server, DBusConnection *new_connection, void *data) {
|
static void connection_new_cb(DBusServer *dbus_server, DBusConnection *new_connection, void *data) {
|
||||||
struct server *s = data;
|
struct server *s = data;
|
||||||
|
|
@ -131,8 +143,17 @@ static void connection_new_cb(DBusServer *dbus_server, DBusConnection *new_conne
|
||||||
client = pa_client_new(s->userdata->module->core, &new_data);
|
client = pa_client_new(s->userdata->module->core, &new_data);
|
||||||
pa_client_new_data_done(&new_data);
|
pa_client_new_data_done(&new_data);
|
||||||
|
|
||||||
if (!client)
|
if (!client) {
|
||||||
|
dbus_connection_close(new_connection);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->type == SERVER_TYPE_TCP) {
|
||||||
|
/* FIXME: Here we allow anyone from anywhere to access the server,
|
||||||
|
* anonymously. Access control should be configurable. */
|
||||||
|
dbus_connection_set_unix_user_function(new_connection, user_check_cb, NULL, NULL);
|
||||||
|
dbus_connection_set_allow_anonymous(new_connection, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
c = pa_xnew(struct connection, 1);
|
c = pa_xnew(struct connection, 1);
|
||||||
c->server = s;
|
c->server = s;
|
||||||
|
|
@ -334,7 +355,7 @@ static void server_free(struct server *s) {
|
||||||
pa_xfree(s);
|
pa_xfree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct server *start_server(struct userdata *u, const char *address) {
|
static struct server *start_server(struct userdata *u, const char *address, enum server_type type) {
|
||||||
/* XXX: We assume that when we unref the DBusServer instance at module
|
/* XXX: We assume that when we unref the DBusServer instance at module
|
||||||
* shutdown, nobody else holds any references to it. If we stop assuming
|
* shutdown, nobody else holds any references to it. If we stop assuming
|
||||||
* that someday, dbus_server_set_new_connection_function,
|
* that someday, dbus_server_set_new_connection_function,
|
||||||
|
|
@ -390,7 +411,7 @@ static struct server *start_local_server(struct userdata *u) {
|
||||||
|
|
||||||
address = pa_get_dbus_address_from_server_type(u->module->core->server_type);
|
address = pa_get_dbus_address_from_server_type(u->module->core->server_type);
|
||||||
|
|
||||||
s = start_server(u, address); /* May return NULL */
|
s = start_server(u, address, SERVER_TYPE_LOCAL); /* May return NULL */
|
||||||
|
|
||||||
pa_xfree(address);
|
pa_xfree(address);
|
||||||
|
|
||||||
|
|
@ -398,8 +419,18 @@ static struct server *start_local_server(struct userdata *u) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct server *start_tcp_server(struct userdata *u) {
|
static struct server *start_tcp_server(struct userdata *u) {
|
||||||
pa_log("start_tcp_server(): Not implemented!");
|
struct server *s = NULL;
|
||||||
return NULL;
|
char *address = NULL;
|
||||||
|
|
||||||
|
pa_assert(u);
|
||||||
|
|
||||||
|
address = pa_sprintf_malloc("tcp:host=127.0.0.1,port=%u", u->tcp_port);
|
||||||
|
|
||||||
|
s = start_server(u, address, SERVER_TYPE_TCP); /* May return NULL */
|
||||||
|
|
||||||
|
pa_xfree(address);
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_access_arg(pa_modargs *ma, pa_bool_t *local_access, pa_bool_t *remote_access) {
|
static int get_access_arg(pa_modargs *ma, pa_bool_t *local_access, pa_bool_t *remote_access) {
|
||||||
|
|
@ -420,7 +451,7 @@ static int get_access_arg(pa_modargs *ma, pa_bool_t *local_access, pa_bool_t *re
|
||||||
*remote_access = TRUE;
|
*remote_access = TRUE;
|
||||||
} else if (!strcmp(value, "local,remote")) {
|
} else if (!strcmp(value, "local,remote")) {
|
||||||
*local_access = TRUE;
|
*local_access = TRUE;
|
||||||
*local_access = TRUE;
|
*remote_access = TRUE;
|
||||||
} else
|
} else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue