Merge branch 'master' of git://git.0pointer.de/pulseaudio

This commit is contained in:
Colin Guthrie 2008-08-03 19:56:49 +01:00
commit 5744237a06
44 changed files with 1568 additions and 815 deletions

View file

@ -79,7 +79,7 @@ New opcodes for notifications:
PA_COMMAND_PLAYBACK_STREAM_MOVED PA_COMMAND_PLAYBACK_STREAM_MOVED
PA_COMMAND_CAPTURE_STREAM_MOVED PA_COMMAND_CAPTURE_STREAM_MOVED
### v13, implemented by >= 0.9.11 ### v13, implemented by >= 0.9.11
New fields for PA_COMMAND_CREATE_PLAYBACK_STREAM, PA_COMMAND_CREATE_RECORD_STREAM request at the end: New fields for PA_COMMAND_CREATE_PLAYBACK_STREAM, PA_COMMAND_CREATE_RECORD_STREAM request at the end:
@ -134,3 +134,9 @@ PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR at the end:
new message: new message:
PA_COMMAND_STARTED PA_COMMAND_STARTED
### v14, implemented by >= 0.9.12
new message:
PA_COMMAND_EXTENSION

View file

@ -35,7 +35,7 @@ AC_SUBST(PA_MAJORMINOR, "PA_MAJOR.PA_MINOR")
AC_SUBST(PACKAGE_URL, [http://pulseaudio.org/]) AC_SUBST(PACKAGE_URL, [http://pulseaudio.org/])
AC_SUBST(PA_API_VERSION, 12) AC_SUBST(PA_API_VERSION, 12)
AC_SUBST(PA_PROTOCOL_VERSION, 13) AC_SUBST(PA_PROTOCOL_VERSION, 14)
# The stable ABI for client applications, for the version info x:y:z # The stable ABI for client applications, for the version info x:y:z
# always will hold y=z # always will hold y=z

View file

@ -686,7 +686,7 @@ noinst_HEADERS = \
pulsecore/pid.h \ pulsecore/pid.h \
pulsecore/play-memchunk.h \ pulsecore/play-memchunk.h \
pulsecore/play-memblockq.h \ pulsecore/play-memblockq.h \
pulsecore/props.h \ pulsecore/shared.h \
pulsecore/queue.h \ pulsecore/queue.h \
pulsecore/random.h \ pulsecore/random.h \
pulsecore/resampler.h \ pulsecore/resampler.h \
@ -758,7 +758,7 @@ libpulsecore_la_SOURCES += \
pulsecore/play-memchunk.c pulsecore/play-memchunk.h \ pulsecore/play-memchunk.c pulsecore/play-memchunk.h \
pulsecore/play-memblockq.c pulsecore/play-memblockq.h \ pulsecore/play-memblockq.c pulsecore/play-memblockq.h \
pulsecore/poll.c pulsecore/poll.h \ pulsecore/poll.c pulsecore/poll.h \
pulsecore/props.c pulsecore/props.h \ pulsecore/shared.c pulsecore/shared.h \
pulsecore/queue.c pulsecore/queue.h \ pulsecore/queue.c pulsecore/queue.h \
pulsecore/random.c pulsecore/random.h \ pulsecore/random.c pulsecore/random.h \
pulsecore/resampler.c pulsecore/resampler.h \ pulsecore/resampler.c pulsecore/resampler.h \
@ -827,7 +827,7 @@ noinst_HEADERS += \
pulsecore/pstream-util.h \ pulsecore/pstream-util.h \
pulsecore/pdispatch.h \ pulsecore/pdispatch.h \
pulsecore/authkey.h \ pulsecore/authkey.h \
pulsecore/authkey-prop.h \ pulsecore/auth-cookie.h \
pulsecore/strlist.h \ pulsecore/strlist.h \
pulsecore/protocol-simple.h \ pulsecore/protocol-simple.h \
pulsecore/esound.h \ pulsecore/esound.h \
@ -857,7 +857,7 @@ modlibexec_LTLIBRARIES = \
libpstream-util.la \ libpstream-util.la \
libpdispatch.la \ libpdispatch.la \
libauthkey.la \ libauthkey.la \
libauthkey-prop.la \ libauth-cookie.la \
libstrlist.la \ libstrlist.la \
libprotocol-simple.la \ libprotocol-simple.la \
libprotocol-http.la \ libprotocol-http.la \
@ -958,7 +958,7 @@ libprotocol_http_la_LIBADD = $(AM_LIBADD) libsocket-server.la libioline.la libpu
libprotocol_native_la_SOURCES = pulsecore/protocol-native.c pulsecore/protocol-native.h pulsecore/native-common.h libprotocol_native_la_SOURCES = pulsecore/protocol-native.c pulsecore/protocol-native.h pulsecore/native-common.h
libprotocol_native_la_LDFLAGS = -avoid-version libprotocol_native_la_LDFLAGS = -avoid-version
libprotocol_native_la_LIBADD = $(AM_LIBADD) libsocket-server.la libpstream.la libpstream-util.la libpdispatch.la libtagstruct.la libauthkey.la libauthkey-prop.la libstrlist.la libpulsecore.la libiochannel.la libipacl.la libprotocol_native_la_LIBADD = $(AM_LIBADD) libsocket-server.la libpstream.la libpstream-util.la libpdispatch.la libtagstruct.la libauthkey.la libauth-cookie.la libstrlist.la libpulsecore.la libiochannel.la libipacl.la
libtagstruct_la_SOURCES = pulsecore/tagstruct.c pulsecore/tagstruct.h libtagstruct_la_SOURCES = pulsecore/tagstruct.c pulsecore/tagstruct.h
libtagstruct_la_LDFLAGS = -avoid-version libtagstruct_la_LDFLAGS = -avoid-version
@ -972,9 +972,9 @@ libauthkey_la_SOURCES = pulsecore/authkey.c pulsecore/authkey.h
libauthkey_la_LDFLAGS = -avoid-version libauthkey_la_LDFLAGS = -avoid-version
libauthkey_la_LIBADD = $(AM_LIBADD) libpulsecore.la libauthkey_la_LIBADD = $(AM_LIBADD) libpulsecore.la
libauthkey_prop_la_SOURCES = pulsecore/authkey-prop.c pulsecore/authkey-prop.h libauth_cookie_la_SOURCES = pulsecore/auth-cookie.c pulsecore/auth-cookie.h
libauthkey_prop_la_LDFLAGS = -avoid-version libauth_cookie_la_LDFLAGS = -avoid-version
libauthkey_prop_la_LIBADD = $(AM_LIBADD) libpulsecore.la libauth_cookie_la_LIBADD = $(AM_LIBADD) libpulsecore.la
libsocket_util_la_SOURCES = \ libsocket_util_la_SOURCES = \
pulsecore/inet_ntop.c pulsecore/inet_ntop.h \ pulsecore/inet_ntop.c pulsecore/inet_ntop.h \
@ -1339,11 +1339,11 @@ module_match_la_LIBADD = $(AM_LIBADD) libpulsecore.la
module_tunnel_sink_la_SOURCES = modules/module-tunnel.c module_tunnel_sink_la_SOURCES = modules/module-tunnel.c
module_tunnel_sink_la_CFLAGS = -DTUNNEL_SINK=1 $(AM_CFLAGS) module_tunnel_sink_la_CFLAGS = -DTUNNEL_SINK=1 $(AM_CFLAGS)
module_tunnel_sink_la_LDFLAGS = -module -avoid-version module_tunnel_sink_la_LDFLAGS = -module -avoid-version
module_tunnel_sink_la_LIBADD = $(AM_LIBADD) libpulsecore.la libsocket-client.la libpstream.la libpstream-util.la libpdispatch.la libtagstruct.la libauthkey.la libauthkey-prop.la libsocket-util.la libiochannel.la module_tunnel_sink_la_LIBADD = $(AM_LIBADD) libpulsecore.la libsocket-client.la libpstream.la libpstream-util.la libpdispatch.la libtagstruct.la libauthkey.la libauth-cookie.la libsocket-util.la libiochannel.la
module_tunnel_source_la_SOURCES = modules/module-tunnel.c module_tunnel_source_la_SOURCES = modules/module-tunnel.c
module_tunnel_source_la_LDFLAGS = -module -avoid-version module_tunnel_source_la_LDFLAGS = -module -avoid-version
module_tunnel_source_la_LIBADD = $(AM_LIBADD) libpulsecore.la libsocket-client.la libpstream.la libpstream-util.la libpdispatch.la libtagstruct.la libauthkey.la libauthkey-prop.la libsocket-util.la libiochannel.la module_tunnel_source_la_LIBADD = $(AM_LIBADD) libpulsecore.la libsocket-client.la libpstream.la libpstream-util.la libpdispatch.la libtagstruct.la libauthkey.la libauth-cookie.la libsocket-util.la libiochannel.la
# X11 # X11
@ -1355,7 +1355,7 @@ module_x11_bell_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA
module_x11_publish_la_SOURCES = modules/module-x11-publish.c module_x11_publish_la_SOURCES = modules/module-x11-publish.c
module_x11_publish_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) module_x11_publish_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
module_x11_publish_la_LDFLAGS = -module -avoid-version module_x11_publish_la_LDFLAGS = -module -avoid-version
module_x11_publish_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) libx11wrap.la libauthkey.la libauthkey-prop.la libx11prop.la libstrlist.la libpulsecore.la module_x11_publish_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) libx11wrap.la libauthkey.la libauth-cookie.la libx11prop.la libstrlist.la libpulsecore.la
module_x11_xsmp_la_SOURCES = modules/module-x11-xsmp.c module_x11_xsmp_la_SOURCES = modules/module-x11-xsmp.c
module_x11_xsmp_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) module_x11_xsmp_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
@ -1512,8 +1512,8 @@ module_hal_detect_la_CFLAGS = $(AM_CFLAGS) $(HAL_CFLAGS)
module_console_kit_la_SOURCES = modules/module-console-kit.c module_console_kit_la_SOURCES = modules/module-console-kit.c
module_console_kit_la_LDFLAGS = -module -avoid-version module_console_kit_la_LDFLAGS = -module -avoid-version
module_console_kit_la_LIBADD = $(AM_LIBADD) $(HAL_LIBS) libpulsecore.la libdbus-util.la module_console_kit_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore.la libdbus-util.la
module_console_kit_la_CFLAGS = $(AM_CFLAGS) $(HAL_CFLAGS) module_console_kit_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
# GConf support # GConf support
module_gconf_la_SOURCES = modules/gconf/module-gconf.c module_gconf_la_SOURCES = modules/gconf/module-gconf.c

View file

@ -109,6 +109,14 @@ void pa_limit_caps(void) {
void pa_drop_caps(void) { void pa_drop_caps(void) {
cap_t caps; cap_t caps;
#ifndef __OPTIMIZE__
/* Valgrind doesn't not know set_caps, so we bypass it here -- but
* only in development builts.*/
if (getenv("VALGRIND") && !pa_have_caps())
return;
#endif
pa_assert_se(prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0) == 0); pa_assert_se(prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0) == 0);
pa_assert_se(caps = cap_init()); pa_assert_se(caps = cap_init());
@ -123,7 +131,12 @@ pa_bool_t pa_have_caps(void) {
cap_t caps; cap_t caps;
cap_flag_value_t flag = CAP_CLEAR; cap_flag_value_t flag = CAP_CLEAR;
#ifdef __OPTIMIZE__
pa_assert_se(caps = cap_get_proc()); pa_assert_se(caps = cap_get_proc());
#else
if (!(caps = cap_get_proc()))
return FALSE;
#endif
pa_assert_se(cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &flag) >= 0); pa_assert_se(cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &flag) >= 0);
pa_assert_se(cap_free(caps) == 0); pa_assert_se(cap_free(caps) == 0);

View file

@ -54,6 +54,11 @@ int pa_polkit_check(const char *action_id) {
goto finish; goto finish;
} }
/* There seems to be a bug in some versions of D-Bus that causes
* dbus_shutdown() to call exit() when a connection without this
* flag disabled was created during runtime.*/
dbus_connection_set_exit_on_disconnect(bus, FALSE);
if (!(caller = polkit_caller_new_from_pid(bus, getpid(), &dbus_error))) { if (!(caller = polkit_caller_new_from_pid(bus, getpid(), &dbus_error))) {
pa_log_error("Cannot get caller from PID: %s", dbus_error.message); pa_log_error("Cannot get caller from PID: %s", dbus_error.message);
goto finish; goto finish;

View file

@ -27,7 +27,7 @@
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include "dbus-util.h" #include "dbus-util.h"
@ -254,7 +254,7 @@ static pa_dbus_connection* pa_dbus_connection_new(pa_core* c, DBusConnection *co
pconn->connection = conn; pconn->connection = conn;
pconn->dispatch_event = c->mainloop->defer_new(c->mainloop, dispatch_cb, conn); pconn->dispatch_event = c->mainloop->defer_new(c->mainloop, dispatch_cb, conn);
pa_property_set(c, name, pconn); pa_shared_set(c, name, pconn);
return pconn; return pconn;
} }
@ -282,7 +282,7 @@ void pa_dbus_connection_unref(pa_dbus_connection *c) {
} }
/* already disconnected, just free */ /* already disconnected, just free */
pa_property_remove(c->core, c->property_name); pa_shared_remove(c->core, c->property_name);
c->core->mainloop->defer_free(c->dispatch_event); c->core->mainloop->defer_free(c->dispatch_event);
dbus_connection_unref(c->connection); dbus_connection_unref(c->connection);
pa_xfree(c); pa_xfree(c);
@ -309,7 +309,7 @@ pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *err
pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER); pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);
if ((pconn = pa_property_get(c, prop_name[type]))) if ((pconn = pa_shared_get(c, prop_name[type])))
return pa_dbus_connection_ref(pconn); return pa_dbus_connection_ref(pconn);
if (!(conn = dbus_bus_get_private(type, error))) if (!(conn = dbus_bus_get_private(type, error)))

View file

@ -1148,7 +1148,7 @@ int pa__init(pa_module*m) {
} }
if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) { if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) {
pa_log("Failed to parse timer_scheduling argument."); pa_log("Failed to parse tsched argument.");
goto fail; goto fail;
} }

View file

@ -158,7 +158,7 @@ int pa__init(pa_module *m) {
pa_assert(m); pa_assert(m);
u = pa_xnew0(struct userdata, 1); m->userdata = u = pa_xnew0(struct userdata, 1);
u->core = m->core; u->core = m->core;
if (!(u->sink_filename = pa_state_path(DEFAULT_SINK_FILE))) if (!(u->sink_filename = pa_state_path(DEFAULT_SINK_FILE)))

View file

@ -56,9 +56,11 @@ PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers
PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(TRUE); PA_MODULE_LOAD_ONCE(TRUE);
#if defined(HAVE_ALSA) && defined(HAVE_OSS) #if defined(HAVE_ALSA) && defined(HAVE_OSS)
PA_MODULE_USAGE("api=<alsa or oss>"); PA_MODULE_USAGE("api=<alsa or oss> "
"tsched=<enable system timer based scheduling mode?>");
#elif defined(HAVE_ALSA) #elif defined(HAVE_ALSA)
PA_MODULE_USAGE("api=<alsa>"); PA_MODULE_USAGE("api=<alsa> "
"tsched=<enable system timer based scheduling mode?>");
#elif defined(HAVE_OSS) #elif defined(HAVE_OSS)
PA_MODULE_USAGE("api=<oss>"); PA_MODULE_USAGE("api=<oss>");
#endif #endif
@ -67,7 +69,7 @@ struct device {
uint32_t index; uint32_t index;
char *udi; char *udi;
char *sink_name, *source_name; char *sink_name, *source_name;
int acl_race_fix; pa_bool_t acl_race_fix;
}; };
struct userdata { struct userdata {
@ -76,6 +78,9 @@ struct userdata {
pa_dbus_connection *connection; pa_dbus_connection *connection;
pa_hashmap *devices; pa_hashmap *devices;
const char *capability; const char *capability;
#ifdef HAVE_ALSA
pa_bool_t use_tsched;
#endif
}; };
struct timerdata { struct timerdata {
@ -88,6 +93,9 @@ struct timerdata {
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
"api", "api",
#ifdef HAVE_ALSA
"tsched",
#endif
NULL NULL
}; };
@ -189,12 +197,12 @@ static pa_module* hal_device_load_alsa(struct userdata *u, const char *udi, char
*sink_name = pa_sprintf_malloc("alsa_output.%s", strip_udi(udi)); *sink_name = pa_sprintf_malloc("alsa_output.%s", strip_udi(udi));
module_name = "module-alsa-sink"; module_name = "module-alsa-sink";
args = pa_sprintf_malloc("device_id=%u sink_name=%s", card, *sink_name); args = pa_sprintf_malloc("device_id=%u sink_name=%s tsched=%i", card, *sink_name, (int) u->use_tsched);
} else { } else {
*source_name = pa_sprintf_malloc("alsa_input.%s", strip_udi(udi)); *source_name = pa_sprintf_malloc("alsa_input.%s", strip_udi(udi));
module_name = "module-alsa-source"; module_name = "module-alsa-source";
args = pa_sprintf_malloc("device_id=%u source_name=%s", card, *source_name); args = pa_sprintf_malloc("device_id=%u source_name=%s tsched=%i", card, *source_name, (int) u->use_tsched);
} }
pa_log_debug("Loading %s with arguments '%s'", module_name, args); pa_log_debug("Loading %s with arguments '%s'", module_name, args);
@ -329,7 +337,7 @@ static struct device* hal_device_add(struct userdata *u, const char *udi) {
return NULL; return NULL;
d = pa_xnew(struct device, 1); d = pa_xnew(struct device, 1);
d->acl_race_fix = 0; d->acl_race_fix = FALSE;
d->udi = pa_xstrdup(udi); d->udi = pa_xstrdup(udi);
d->index = m->index; d->index = m->index;
d->sink_name = sink_name; d->sink_name = sink_name;
@ -560,9 +568,9 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
udi = dbus_message_get_path(message); udi = dbus_message_get_path(message);
if ((d = pa_hashmap_get(u->devices, udi))) { if ((d = pa_hashmap_get(u->devices, udi))) {
int send_acl_race_fix_message = 0; pa_bool_t send_acl_race_fix_message = FALSE;
d->acl_race_fix = 0; d->acl_race_fix = FALSE;
if (d->sink_name) { if (d->sink_name) {
pa_sink *sink; pa_sink *sink;
@ -575,12 +583,12 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
if (pa_sink_suspend(sink, 0) >= 0) if (pa_sink_suspend(sink, 0) >= 0)
pa_scache_play_item_by_name(u->core, "pulse-access", d->sink_name, FALSE, PA_VOLUME_NORM, NULL, NULL); pa_scache_play_item_by_name(u->core, "pulse-access", d->sink_name, FALSE, PA_VOLUME_NORM, NULL, NULL);
else else
d->acl_race_fix = 1; d->acl_race_fix = TRUE;
} else if (!prev_suspended && suspend) { } else if (!prev_suspended && suspend) {
/* suspend */ /* suspend */
if (pa_sink_suspend(sink, 1) >= 0) if (pa_sink_suspend(sink, 1) >= 0)
send_acl_race_fix_message = 1; send_acl_race_fix_message = TRUE;
} }
} }
} }
@ -594,12 +602,12 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
if (prev_suspended && !suspend) { if (prev_suspended && !suspend) {
/* resume */ /* resume */
if (pa_source_suspend(source, 0) < 0) if (pa_source_suspend(source, 0) < 0)
d->acl_race_fix = 1; d->acl_race_fix = TRUE;
} else if (!prev_suspended && suspend) { } else if (!prev_suspended && suspend) {
/* suspend */ /* suspend */
if (pa_source_suspend(source, 0) >= 0) if (pa_source_suspend(source, 0) >= 0)
send_acl_race_fix_message = 1; send_acl_race_fix_message = TRUE;
} }
} }
} }
@ -631,7 +639,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
if ((d = pa_hashmap_get(u->devices, udi)) && d->acl_race_fix) { if ((d = pa_hashmap_get(u->devices, udi)) && d->acl_race_fix) {
pa_log_debug("Got dirty give up message for '%s', trying resume ...", udi); pa_log_debug("Got dirty give up message for '%s', trying resume ...", udi);
d->acl_race_fix = 0; d->acl_race_fix = FALSE;
if (d->sink_name) { if (d->sink_name) {
pa_sink *sink; pa_sink *sink;
@ -724,6 +732,7 @@ int pa__init(pa_module*m) {
int n = 0; int n = 0;
pa_modargs *ma; pa_modargs *ma;
const char *api; const char *api;
pa_bool_t use_tsched = TRUE;
pa_assert(m); pa_assert(m);
@ -734,6 +743,11 @@ int pa__init(pa_module*m) {
goto fail; goto fail;
} }
if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) {
pa_log("Failed to parse tsched argument.");
goto fail;
}
if ((api = pa_modargs_get_value(ma, "api", NULL))) { if ((api = pa_modargs_get_value(ma, "api", NULL))) {
int good = 0; int good = 0;
@ -775,6 +789,9 @@ int pa__init(pa_module*m) {
u->connection = conn; u->connection = conn;
u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
u->capability = api; u->capability = api;
#ifdef HAVE_ALSA
u->use_tsched = use_tsched;
#endif
m->userdata = u; m->userdata = u;
#ifdef HAVE_ALSA #ifdef HAVE_ALSA

View file

@ -42,8 +42,6 @@ PA_MODULE_LOAD_ONCE(TRUE);
static const char* const valid_modargs[] = { static const char* const valid_modargs[] = {
"fd", "fd",
"public",
"cookie",
NULL, NULL,
}; };
@ -51,6 +49,7 @@ int pa__init(pa_module*m) {
pa_iochannel *io; pa_iochannel *io;
pa_modargs *ma; pa_modargs *ma;
int fd, r = -1; int fd, r = -1;
pa_native_options *options = NULL;
pa_assert(m); pa_assert(m);
@ -64,12 +63,17 @@ int pa__init(pa_module*m) {
goto finish; goto finish;
} }
options = pa_native_options_new();
options->module = m;
options->auth_anonymous = TRUE;
io = pa_iochannel_new(m->core->mainloop, fd, fd); io = pa_iochannel_new(m->core->mainloop, fd, fd);
if (!(m->userdata = pa_protocol_native_new_iochannel(m->core, io, m, ma))) { m->userdata = pa_native_protocol_get(m->core);
pa_iochannel_free(io);
goto finish; pa_native_protocol_connect(m->userdata, io, options);
}
pa_native_options_unref(options);
r = 0; r = 0;
@ -77,11 +81,17 @@ finish:
if (ma) if (ma)
pa_modargs_free(ma); pa_modargs_free(ma);
if (options)
pa_native_options_unref(options);
return r; return r;
} }
void pa__done(pa_module*m) { void pa__done(pa_module*m) {
pa_assert(m); pa_assert(m);
pa_protocol_native_free(m->userdata); if (m->userdata) {
pa_native_protocol_disconnect(m->userdata, m);
pa_native_protocol_unref(m->userdata);
}
} }

View file

@ -62,19 +62,19 @@
#endif #endif
#if defined(USE_PROTOCOL_SIMPLE) #if defined(USE_PROTOCOL_SIMPLE)
#include <pulsecore/protocol-simple.h> # include <pulsecore/protocol-simple.h>
#define protocol_new pa_protocol_simple_new # define TCPWRAP_SERVICE "pulseaudio-simple"
#define protocol_free pa_protocol_simple_free # define IPV4_PORT 4711
#define TCPWRAP_SERVICE "pulseaudio-simple" # define UNIX_SOCKET "simple"
#define IPV4_PORT 4711 # define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
#define UNIX_SOCKET "simple"
#define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record", # if defined(USE_TCP_SOCKETS)
#if defined(USE_TCP_SOCKETS) # include "module-simple-protocol-tcp-symdef.h"
#include "module-simple-protocol-tcp-symdef.h" # else
#else # include "module-simple-protocol-unix-symdef.h"
#include "module-simple-protocol-unix-symdef.h" # endif
#endif
PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION); PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE("rate=<sample rate> " PA_MODULE_USAGE("rate=<sample rate> "
"format=<sample format> " "format=<sample format> "
"channels=<number of channels> " "channels=<number of channels> "
@ -84,96 +84,96 @@ PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION);
"record=<enable record?> " "record=<enable record?> "
SOCKET_USAGE); SOCKET_USAGE);
#elif defined(USE_PROTOCOL_CLI) #elif defined(USE_PROTOCOL_CLI)
#include <pulsecore/protocol-cli.h> # include <pulsecore/protocol-cli.h>
#define protocol_new pa_protocol_cli_new # define TCPWRAP_SERVICE "pulseaudio-cli"
#define protocol_free pa_protocol_cli_free # define IPV4_PORT 4712
#define TCPWRAP_SERVICE "pulseaudio-cli" # define UNIX_SOCKET "cli"
#define IPV4_PORT 4712 # define MODULE_ARGUMENTS
#define UNIX_SOCKET "cli"
#define MODULE_ARGUMENTS # ifdef USE_TCP_SOCKETS
#ifdef USE_TCP_SOCKETS # include "module-cli-protocol-tcp-symdef.h"
#include "module-cli-protocol-tcp-symdef.h" # else
#else # include "module-cli-protocol-unix-symdef.h"
#include "module-cli-protocol-unix-symdef.h" # endif
#endif
PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION); PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE(SOCKET_USAGE); PA_MODULE_USAGE(SOCKET_USAGE);
#elif defined(USE_PROTOCOL_HTTP) #elif defined(USE_PROTOCOL_HTTP)
#include <pulsecore/protocol-http.h> # include <pulsecore/protocol-http.h>
#define protocol_new pa_protocol_http_new # define TCPWRAP_SERVICE "pulseaudio-http"
#define protocol_free pa_protocol_http_free # define IPV4_PORT 4714
#define TCPWRAP_SERVICE "pulseaudio-http" # define UNIX_SOCKET "http"
#define IPV4_PORT 4714 # define MODULE_ARGUMENTS
#define UNIX_SOCKET "http"
#define MODULE_ARGUMENTS # ifdef USE_TCP_SOCKETS
#ifdef USE_TCP_SOCKETS # include "module-http-protocol-tcp-symdef.h"
#include "module-http-protocol-tcp-symdef.h" # else
#else # include "module-http-protocol-unix-symdef.h"
#include "module-http-protocol-unix-symdef.h" # endif
#endif
PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION); PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION);
PA_MODULE_USAGE(SOCKET_USAGE); PA_MODULE_USAGE(SOCKET_USAGE);
#elif defined(USE_PROTOCOL_NATIVE) #elif defined(USE_PROTOCOL_NATIVE)
#include <pulsecore/protocol-native.h> # include <pulsecore/protocol-native.h>
#define protocol_new pa_protocol_native_new # define TCPWRAP_SERVICE "pulseaudio-native"
#define protocol_free pa_protocol_native_free # define IPV4_PORT PA_NATIVE_DEFAULT_PORT
#define TCPWRAP_SERVICE "pulseaudio-native" # define UNIX_SOCKET PA_NATIVE_DEFAULT_UNIX_SOCKET
#define IPV4_PORT PA_NATIVE_DEFAULT_PORT # define MODULE_ARGUMENTS_COMMON "cookie", "auth-cookie", "auth-cookie-enabled", "auth-anonymous",
#define UNIX_SOCKET PA_NATIVE_DEFAULT_UNIX_SOCKET
#define MODULE_ARGUMENTS_COMMON "cookie", "auth-anonymous",
#ifdef USE_TCP_SOCKETS
#include "module-native-protocol-tcp-symdef.h"
#else
#include "module-native-protocol-unix-symdef.h"
#endif
#if defined(HAVE_CREDS) && !defined(USE_TCP_SOCKETS) # ifdef USE_TCP_SOCKETS
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable", # include "module-native-protocol-tcp-symdef.h"
#define AUTH_USAGE "auth-group=<system group to allow access> auth-group-enable=<enable auth by UNIX group?> " # else
#elif defined(USE_TCP_SOCKETS) # include "module-native-protocol-unix-symdef.h"
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl", # endif
#define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
#else # if defined(HAVE_CREDS) && !defined(USE_TCP_SOCKETS)
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON # define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable",
#define AUTH_USAGE # define AUTH_USAGE "auth-group=<system group to allow access> auth-group-enable=<enable auth by UNIX group?> "
#endif # elif defined(USE_TCP_SOCKETS)
# define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
# define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
# else
# define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
# define AUTH_USAGE
# endif
PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION); PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> " PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
"cookie=<path to cookie file> " "auth-cookie=<path to cookie file> "
"auth-cookie-enabled=<enable cookie authentification? "
AUTH_USAGE AUTH_USAGE
SOCKET_USAGE); SOCKET_USAGE);
#elif defined(USE_PROTOCOL_ESOUND) #elif defined(USE_PROTOCOL_ESOUND)
#include <pulsecore/protocol-esound.h> # include <pulsecore/protocol-esound.h>
#include <pulsecore/esound.h> # include <pulsecore/esound.h>
#define protocol_new pa_protocol_esound_new # define TCPWRAP_SERVICE "esound"
#define protocol_free pa_protocol_esound_free # define IPV4_PORT ESD_DEFAULT_PORT
#define TCPWRAP_SERVICE "esound" # define MODULE_ARGUMENTS_COMMON "sink", "source", "auth-anonymous", "cookie", "auth-cookie", "auth-cookie-enabled"
#define IPV4_PORT ESD_DEFAULT_PORT
#define MODULE_ARGUMENTS_COMMON "sink", "source", "auth-anonymous", "cookie",
#ifdef USE_TCP_SOCKETS
#include "module-esound-protocol-tcp-symdef.h"
#else
#include "module-esound-protocol-unix-symdef.h"
#endif
#if defined(USE_TCP_SOCKETS) # ifdef USE_TCP_SOCKETS
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl", # include "module-esound-protocol-tcp-symdef.h"
#define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> " # else
#else # include "module-esound-protocol-unix-symdef.h"
#define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON # endif
#define AUTH_USAGE
#endif # if defined(USE_TCP_SOCKETS)
# define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-ip-acl",
# define AUTH_USAGE "auth-ip-acl=<IP address ACL to allow access> "
# else
# define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
# define AUTH_USAGE
# endif
PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION); PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION);
PA_MODULE_USAGE("sink=<sink to connect to> " PA_MODULE_USAGE("sink=<sink to connect to> "
"source=<source to connect to> " "source=<source to connect to> "
"auth-anonymous=<don't verify cookies?> " "auth-anonymous=<don't verify cookies?> "
"cookie=<path to cookie file> " "auth-cookie=<path to cookie file> "
"auth-cookie-enabled=<enable cookie authentification? "
AUTH_USAGE AUTH_USAGE
SOCKET_USAGE); SOCKET_USAGE);
#else #else
#error "Broken build system" # error "Broken build system"
#endif #endif
PA_MODULE_LOAD_ONCE(FALSE); PA_MODULE_LOAD_ONCE(FALSE);
@ -192,37 +192,103 @@ static const char* const valid_modargs[] = {
}; };
struct userdata { struct userdata {
#if defined(USE_TCP_SOCKETS) pa_module *module;
void *protocol_ipv4;
void *protocol_ipv6; #if defined(USE_PROTOCOL_SIMPLE)
pa_simple_protocol *simple_protocol;
pa_simple_options *simple_options;
#elif defined(USE_PROTOCOL_CLI)
pa_cli_protocol *cli_protocol;
#elif defined(USE_PROTOCOL_HTTP)
pa_http_protocol *http_protocol;
#elif defined(USE_PROTOCOL_NATIVE)
pa_native_protocol *native_protocol;
pa_native_options *native_options;
#else #else
void *protocol_unix; pa_esound_protocol *esound_protocol;
pa_esound_options *esound_options;
#endif
#if defined(USE_TCP_SOCKETS)
pa_socket_server *socket_server_ipv4;
pa_socket_server *socket_server_ipv6;
#else
pa_socket_server *socket_server_unix;
char *socket_path; char *socket_path;
#endif #endif
}; };
static void socket_server_on_connection_cb(pa_socket_server*s, pa_iochannel *io, void *userdata) {
struct userdata *u = userdata;
pa_assert(s);
pa_assert(io);
pa_assert(u);
#if defined(USE_PROTOCOL_SIMPLE)
pa_simple_protocol_connect(u->simple_protocol, io, u->simple_options);
#elif defined(USE_PROTOCOL_CLI)
pa_cli_protocol_connect(u->cli_protocol, io, u->module);
#elif defined(USE_PROTOCOL_HTTP)
pa_http_protocol_connect(u->http_protocol, io, u->module);
#elif defined(USE_PROTOCOL_NATIVE)
pa_native_protocol_connect(u->native_protocol, io, u->native_options);
#else
pa_esound_protocol_connect(u->esound_protocol, io, u->esound_options);
#endif
}
int pa__init(pa_module*m) { int pa__init(pa_module*m) {
pa_modargs *ma = NULL; pa_modargs *ma = NULL;
int ret = -1;
struct userdata *u = NULL; struct userdata *u = NULL;
#if defined(USE_TCP_SOCKETS) #if defined(USE_TCP_SOCKETS)
pa_socket_server *s_ipv4 = NULL, *s_ipv6 = NULL;
uint32_t port = IPV4_PORT; uint32_t port = IPV4_PORT;
const char *listen_on; const char *listen_on;
#else #else
pa_socket_server *s;
int r; int r;
#endif #endif
#if defined(USE_PROTOCOL_NATIVE)
char t[256];
#endif
pa_assert(m); pa_assert(m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
pa_log("Failed to parse module arguments"); pa_log("Failed to parse module arguments");
goto finish; goto fail;
} }
u = pa_xnew0(struct userdata, 1); u = pa_xnew0(struct userdata, 1);
u->module = m;
#if defined(USE_PROTOCOL_SIMPLE)
u->simple_protocol = pa_simple_protocol_get(m->core);
u->simple_options = pa_simple_options_new();
if (pa_simple_options_parse(u->simple_options, m->core, ma) < 0)
goto fail;
u->simple_options->module = m;
#elif defined(USE_PROTOCOL_CLI)
u->cli_protocol = pa_cli_protocol_get(m->core);
#elif defined(USE_PROTOCOL_HTTP)
u->http_protocol = pa_http_protocol_get(m->core);
#elif defined(USE_PROTOCOL_NATIVE)
u->native_protocol = pa_native_protocol_get(m->core);
u->native_options = pa_native_options_new();
if (pa_native_options_parse(u->native_options, m->core, ma) < 0)
goto fail;
u->native_options->module = m;
#else
u->esound_protocol = pa_esound_protocol_get(m->core);
u->esound_options = pa_esound_options_new();
if (pa_esound_options_parse(u->esound_options, m->core, ma) < 0)
goto fail;
u->esound_options->module = m;
#endif
#if defined(USE_TCP_SOCKETS) #if defined(USE_TCP_SOCKETS)
if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) { if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
@ -233,38 +299,30 @@ int pa__init(pa_module*m) {
listen_on = pa_modargs_get_value(ma, "listen", NULL); listen_on = pa_modargs_get_value(ma, "listen", NULL);
if (listen_on) { if (listen_on) {
s_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE); u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);
s_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE); u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);
} else { } else {
s_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, port, TCPWRAP_SERVICE); u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, port, TCPWRAP_SERVICE);
s_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, port, TCPWRAP_SERVICE); u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, port, TCPWRAP_SERVICE);
} }
if (!s_ipv4 && !s_ipv6) if (!u->socket_server_ipv4 && !u->socket_server_ipv6)
goto fail; goto fail;
if (s_ipv4) if (u->socket_server_ipv4)
u->protocol_ipv4 = protocol_new(m->core, s_ipv4, m, ma); pa_socket_server_set_callback(u->socket_server_ipv4, socket_server_on_connection_cb, u);
if (s_ipv6) if (u->socket_server_ipv6)
u->protocol_ipv6 = protocol_new(m->core, s_ipv6, m, ma); pa_socket_server_set_callback(u->socket_server_ipv6, socket_server_on_connection_cb, u);
if (!u->protocol_ipv4 && !u->protocol_ipv6)
goto fail;
if (s_ipv6)
pa_socket_server_unref(s_ipv6);
if (s_ipv6)
pa_socket_server_unref(s_ipv4);
#else #else
#if defined(USE_PROTOCOL_ESOUND) # if defined(USE_PROTOCOL_ESOUND)
#if defined(USE_PER_USER_ESOUND_SOCKET) # if defined(USE_PER_USER_ESOUND_SOCKET)
u->socket_path = pa_sprintf_malloc("/tmp/.esd-%lu/socket", (unsigned long) getuid()); u->socket_path = pa_sprintf_malloc("/tmp/.esd-%lu/socket", (unsigned long) getuid());
#else # else
u->socket_path = pa_xstrdup("/tmp/.esd/socket"); u->socket_path = pa_xstrdup("/tmp/.esd/socket");
#endif # endif
/* This socket doesn't reside in our own runtime dir but in /* This socket doesn't reside in our own runtime dir but in
* /tmp/.esd/, hence we have to create the dir first */ * /tmp/.esd/, hence we have to create the dir first */
@ -274,12 +332,12 @@ int pa__init(pa_module*m) {
goto fail; goto fail;
} }
#else # else
if (!(u->socket_path = pa_runtime_path(pa_modargs_get_value(ma, "socket", UNIX_SOCKET)))) { if (!(u->socket_path = pa_runtime_path(pa_modargs_get_value(ma, "socket", UNIX_SOCKET)))) {
pa_log("Failed to generate socket path."); pa_log("Failed to generate socket path.");
goto fail; goto fail;
} }
#endif # endif
if ((r = pa_unix_socket_remove_stale(u->socket_path)) < 0) { if ((r = pa_unix_socket_remove_stale(u->socket_path)) < 0) {
pa_log("Failed to remove stale UNIX socket '%s': %s", u->socket_path, pa_cstrerror(errno)); pa_log("Failed to remove stale UNIX socket '%s': %s", u->socket_path, pa_cstrerror(errno));
@ -287,53 +345,44 @@ int pa__init(pa_module*m) {
} else if (r > 0) } else if (r > 0)
pa_log_info("Removed stale UNIX socket '%s'.", u->socket_path); pa_log_info("Removed stale UNIX socket '%s'.", u->socket_path);
if (!(s = pa_socket_server_new_unix(m->core->mainloop, u->socket_path))) if (!(u->socket_server_unix = pa_socket_server_new_unix(m->core->mainloop, u->socket_path)))
goto fail; goto fail;
if (!(u->protocol_unix = protocol_new(m->core, s, m, ma))) pa_socket_server_set_callback(u->socket_server_unix, socket_server_on_connection_cb, u);
goto fail;
pa_socket_server_unref(s); #endif
#if defined(USE_PROTOCOL_NATIVE)
# if defined(USE_TCP_SOCKETS)
if (u->socket_server_ipv4)
if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
pa_native_protocol_add_server_string(u->native_protocol, t);
if (u->socket_server_ipv6)
if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
pa_native_protocol_add_server_string(u->native_protocol, t);
# else
if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
pa_native_protocol_add_server_string(u->native_protocol, t);
# endif
#endif #endif
m->userdata = u; m->userdata = u;
ret = 0;
finish:
if (ma) if (ma)
pa_modargs_free(ma); pa_modargs_free(ma);
return ret; return 0;
fail: fail:
if (u) {
#if defined(USE_TCP_SOCKETS)
if (u->protocol_ipv4)
protocol_free(u->protocol_ipv4);
if (u->protocol_ipv6)
protocol_free(u->protocol_ipv6);
#else
if (u->protocol_unix)
protocol_free(u->protocol_unix);
pa_xfree(u->socket_path);
#endif
pa_xfree(u); if (ma)
} pa_modargs_free(ma);
#if defined(USE_TCP_SOCKETS) pa__done(m);
if (s_ipv4)
pa_socket_server_unref(s_ipv4);
if (s_ipv6)
pa_socket_server_unref(s_ipv6);
#else
if (s)
pa_socket_server_unref(s);
#endif
goto finish; return -1;
} }
void pa__done(pa_module*m) { void pa__done(pa_module*m) {
@ -343,22 +392,72 @@ void pa__done(pa_module*m) {
u = m->userdata; u = m->userdata;
#if defined(USE_TCP_SOCKETS) #if defined(USE_PROTOCOL_SIMPLE)
if (u->protocol_ipv4) if (u->simple_protocol) {
protocol_free(u->protocol_ipv4); pa_simple_protocol_disconnect(u->simple_protocol, u->module);
if (u->protocol_ipv6) pa_simple_protocol_unref(u->simple_protocol);
protocol_free(u->protocol_ipv6); }
#else if (u->simple_options)
if (u->protocol_unix) pa_simple_options_unref(u->simple_options);
protocol_free(u->protocol_unix); #elif defined(USE_PROTOCOL_CLI)
if (u->cli_protocol) {
pa_cli_protocol_disconnect(u->cli_protocol, u->module);
pa_cli_protocol_unref(u->cli_protocol);
}
#elif defined(USE_PROTOCOL_HTTP)
if (u->http_protocol) {
pa_http_protocol_disconnect(u->http_protocol, u->module);
pa_http_protocol_unref(u->http_protocol);
}
#elif defined(USE_PROTOCOL_NATIVE)
if (u->native_protocol) {
#if defined(USE_PROTOCOL_ESOUND) && !defined(USE_PER_USER_ESOUND_SOCKET) char t[256];
# if defined(USE_TCP_SOCKETS)
if (u->socket_server_ipv4)
if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
pa_native_protocol_remove_server_string(u->native_protocol, t);
if (u->socket_server_ipv6)
if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
pa_native_protocol_remove_server_string(u->native_protocol, t);
# else
if (u->socket_server_unix)
if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
pa_native_protocol_remove_server_string(u->native_protocol, t);
# endif
pa_native_protocol_disconnect(u->native_protocol, u->module);
pa_native_protocol_unref(u->native_protocol);
}
if (u->native_options)
pa_native_options_unref(u->native_options);
#else
if (u->esound_protocol) {
pa_esound_protocol_disconnect(u->esound_protocol, u->module);
pa_esound_protocol_unref(u->esound_protocol);
}
if (u->esound_options)
pa_esound_options_unref(u->esound_options);
#endif
#if defined(USE_TCP_SOCKETS)
if (u->socket_server_ipv4)
pa_socket_server_unref(u->socket_server_ipv4);
if (u->socket_server_ipv6)
pa_socket_server_unref(u->socket_server_ipv6);
#else
if (u->socket_server_unix)
pa_socket_server_unref(u->socket_server_unix);
# if defined(USE_PROTOCOL_ESOUND) && !defined(USE_PER_USER_ESOUND_SOCKET)
if (u->socket_path) { if (u->socket_path) {
char *p = pa_parent_dir(u->socket_path); char *p = pa_parent_dir(u->socket_path);
rmdir(p); rmdir(p);
pa_xfree(p); pa_xfree(p);
} }
#endif # endif
pa_xfree(u->socket_path); pa_xfree(u->socket_path);
#endif #endif

View file

@ -45,16 +45,15 @@
#include <pulsecore/pdispatch.h> #include <pulsecore/pdispatch.h>
#include <pulsecore/pstream.h> #include <pulsecore/pstream.h>
#include <pulsecore/pstream-util.h> #include <pulsecore/pstream-util.h>
#include <pulsecore/authkey.h>
#include <pulsecore/socket-client.h> #include <pulsecore/socket-client.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include <pulsecore/authkey-prop.h>
#include <pulsecore/time-smoother.h> #include <pulsecore/time-smoother.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/rtclock.h> #include <pulsecore/rtclock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/proplist-util.h> #include <pulsecore/proplist-util.h>
#include <pulsecore/auth-cookie.h>
#ifdef TUNNEL_SINK #ifdef TUNNEL_SINK
#include "module-tunnel-sink-symdef.h" #include "module-tunnel-sink-symdef.h"
@ -185,7 +184,7 @@ struct userdata {
pa_source *source; pa_source *source;
#endif #endif
uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH]; pa_auth_cookie *auth_cookie;
uint32_t version; uint32_t version;
uint32_t ctag; uint32_t ctag;
@ -204,8 +203,6 @@ struct userdata {
pa_time_event *time_event; pa_time_event *time_event;
pa_bool_t auth_cookie_in_property;
pa_smoother *smoother; pa_smoother *smoother;
char *device_description; char *device_description;
@ -1588,7 +1585,8 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata
pa_tagstruct_putu32(t, PA_COMMAND_AUTH); pa_tagstruct_putu32(t, PA_COMMAND_AUTH);
pa_tagstruct_putu32(t, tag = u->ctag++); pa_tagstruct_putu32(t, tag = u->ctag++);
pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION); pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION);
pa_tagstruct_put_arbitrary(t, u->auth_cookie, sizeof(u->auth_cookie));
pa_tagstruct_put_arbitrary(t, pa_auth_cookie_read(u->auth_cookie, PA_NATIVE_COOKIE_LENGTH), PA_NATIVE_COOKIE_LENGTH);
#ifdef HAVE_CREDS #ifdef HAVE_CREDS
{ {
@ -1658,33 +1656,6 @@ static int sink_set_mute(pa_sink *sink) {
#endif #endif
/* Called from main context */
static int load_key(struct userdata *u, const char*fn) {
pa_assert(u);
u->auth_cookie_in_property = FALSE;
if (!fn && pa_authkey_prop_get(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0) {
pa_log_debug("Using already loaded auth cookie.");
pa_authkey_prop_ref(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
u->auth_cookie_in_property = 1;
return 0;
}
if (!fn)
fn = PA_NATIVE_COOKIE_FILE;
if (pa_authkey_load_auto(fn, u->auth_cookie, sizeof(u->auth_cookie)) < 0)
return -1;
pa_log_debug("Loading cookie from disk.");
if (pa_authkey_prop_put(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0)
u->auth_cookie_in_property = TRUE;
return 0;
}
int pa__init(pa_module*m) { int pa__init(pa_module*m) {
pa_modargs *ma = NULL; pa_modargs *ma = NULL;
struct userdata *u = NULL; struct userdata *u = NULL;
@ -1722,7 +1693,6 @@ int pa__init(pa_module*m) {
u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC*2, TRUE, 10); u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC*2, TRUE, 10);
u->ctag = 1; u->ctag = 1;
u->device_index = u->channel = PA_INVALID_INDEX; u->device_index = u->channel = PA_INVALID_INDEX;
u->auth_cookie_in_property = FALSE;
u->time_event = NULL; u->time_event = NULL;
u->ignore_latency_before = 0; u->ignore_latency_before = 0;
u->transport_usec = 0; u->transport_usec = 0;
@ -1733,7 +1703,7 @@ int pa__init(pa_module*m) {
u->rtpoll = pa_rtpoll_new(); u->rtpoll = pa_rtpoll_new();
pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
if (load_key(u, pa_modargs_get_value(ma, "cookie", NULL)) < 0) if (!(u->auth_cookie = pa_auth_cookie_get(u->core, pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), PA_NATIVE_COOKIE_LENGTH)))
goto fail; goto fail;
if (!(u->server_name = pa_xstrdup(pa_modargs_get_value(ma, "server", NULL)))) { if (!(u->server_name = pa_xstrdup(pa_modargs_get_value(ma, "server", NULL)))) {
@ -1911,8 +1881,8 @@ void pa__done(pa_module*m) {
if (u->client) if (u->client)
pa_socket_client_unref(u->client); pa_socket_client_unref(u->client);
if (u->auth_cookie_in_property) if (u->auth_cookie)
pa_authkey_prop_unref(m->core, PA_NATIVE_COOKIE_PROPERTY_NAME); pa_auth_cookie_unref(u->auth_cookie);
if (u->smoother) if (u->smoother)
pa_smoother_free(u->smoother); pa_smoother_free(u->smoother);

View file

@ -43,11 +43,11 @@
#include <pulsecore/x11wrap.h> #include <pulsecore/x11wrap.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/native-common.h> #include <pulsecore/native-common.h>
#include <pulsecore/authkey-prop.h> #include <pulsecore/auth-cookie.h>
#include <pulsecore/authkey.h>
#include <pulsecore/x11prop.h> #include <pulsecore/x11prop.h>
#include <pulsecore/strlist.h> #include <pulsecore/strlist.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include <pulsecore/protocol-native.h>
#include "module-x11-publish-symdef.h" #include "module-x11-publish-symdef.h"
@ -68,15 +68,48 @@ static const char* const valid_modargs[] = {
struct userdata { struct userdata {
pa_core *core; pa_core *core;
pa_module *module; pa_module *module;
pa_native_protocol *protocol;
char *id; char *id;
uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH]; pa_auth_cookie *auth_cookie;
pa_bool_t auth_cookie_in_property;
pa_x11_wrapper *x11_wrapper; pa_x11_wrapper *x11_wrapper;
pa_x11_client *x11_client; pa_x11_client *x11_client;
pa_hook_slot *hook_slot;
}; };
static void publish_servers(struct userdata *u, pa_strlist *l) {
if (l) {
char *s;
l = pa_strlist_reverse(l);
s = pa_strlist_tostring(l);
l = pa_strlist_reverse(l);
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER", s);
pa_xfree(s);
} else
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER");
}
static pa_hook_result_t servers_changed_cb(void *hook_data, void *call_data, void *slot_data) {
pa_strlist *servers = call_data;
struct userdata *u = slot_data;
char t[256];
pa_assert(u);
if (!pa_x11_get_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id)) {
pa_log_warn("PulseAudio information vanished from X11!");
return PA_HOOK_OK;
}
publish_servers(u, servers);
return PA_HOOK_OK;
}
static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) { static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
@ -96,40 +129,12 @@ static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) {
pa_module_unload_request(u->module); pa_module_unload_request(u->module);
} }
static int load_key(struct userdata *u, const char*fn) {
pa_assert(u);
u->auth_cookie_in_property = FALSE;
if (!fn && pa_authkey_prop_get(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0) {
pa_log_debug("using already loaded auth cookie.");
pa_authkey_prop_ref(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
u->auth_cookie_in_property = 1;
return 0;
}
if (!fn)
fn = PA_NATIVE_COOKIE_FILE;
if (pa_authkey_load_auto(fn, u->auth_cookie, sizeof(u->auth_cookie)) < 0)
return -1;
pa_log_debug("Loading cookie from disk.");
if (pa_authkey_prop_put(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0)
u->auth_cookie_in_property = TRUE;
return 0;
}
int pa__init(pa_module*m) { int pa__init(pa_module*m) {
struct userdata *u; struct userdata *u;
pa_modargs *ma = NULL; pa_modargs *ma = NULL;
char hn[256], un[128]; char hn[256], un[128];
char hx[PA_NATIVE_COOKIE_LENGTH*2+1]; char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
const char *t; const char *t;
char *s;
pa_strlist *l;
pa_assert(m); pa_assert(m);
@ -141,40 +146,36 @@ int pa__init(pa_module*m) {
m->userdata = u = pa_xnew(struct userdata, 1); m->userdata = u = pa_xnew(struct userdata, 1);
u->core = m->core; u->core = m->core;
u->module = m; u->module = m;
u->protocol = pa_native_protocol_get(m->core);
u->id = NULL; u->id = NULL;
u->auth_cookie_in_property = FALSE; u->auth_cookie = NULL;
u->x11_client = NULL; u->x11_client = NULL;
u->x11_wrapper = NULL; u->x11_wrapper = NULL;
if (load_key(u, pa_modargs_get_value(ma, "cookie", NULL)) < 0) u->hook_slot = pa_hook_connect(pa_native_protocol_servers_changed(u->protocol), PA_HOOK_NORMAL, servers_changed_cb, u);
if (!(u->auth_cookie = pa_auth_cookie_get(m->core, pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), PA_NATIVE_COOKIE_LENGTH)))
goto fail; goto fail;
if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL)))) if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
goto fail; goto fail;
if (!(l = pa_property_get(m->core, PA_NATIVE_SERVER_PROPERTY_NAME)))
goto fail;
l = pa_strlist_reverse(l);
s = pa_strlist_tostring(l);
l = pa_strlist_reverse(l);
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER", s);
pa_xfree(s);
if (!pa_get_fqdn(hn, sizeof(hn)) || !pa_get_user_name(un, sizeof(un))) if (!pa_get_fqdn(hn, sizeof(hn)) || !pa_get_user_name(un, sizeof(un)))
goto fail; goto fail;
u->id = pa_sprintf_malloc("%s@%s/%u", un, hn, (unsigned) getpid()); u->id = pa_sprintf_malloc("%s@%s/%u", un, hn, (unsigned) getpid());
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", u->id); pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", u->id);
publish_servers(u, pa_native_protocol_servers(u->protocol));
if ((t = pa_modargs_get_value(ma, "source", NULL))) if ((t = pa_modargs_get_value(ma, "source", NULL)))
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SOURCE", t); pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SOURCE", t);
if ((t = pa_modargs_get_value(ma, "sink", NULL))) if ((t = pa_modargs_get_value(ma, "sink", NULL)))
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SINK", t); pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SINK", t);
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_COOKIE", pa_hexstr(u->auth_cookie, sizeof(u->auth_cookie), hx, sizeof(hx))); pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_COOKIE",
pa_hexstr(pa_auth_cookie_read(u->auth_cookie, PA_NATIVE_COOKIE_LENGTH), PA_NATIVE_COOKIE_LENGTH, hx, sizeof(hx)));
u->x11_client = pa_x11_client_new(u->x11_wrapper, NULL, x11_kill_cb, u); u->x11_client = pa_x11_client_new(u->x11_wrapper, NULL, x11_kill_cb, u);
@ -220,8 +221,14 @@ void pa__done(pa_module*m) {
pa_x11_wrapper_unref(u->x11_wrapper); pa_x11_wrapper_unref(u->x11_wrapper);
} }
if (u->auth_cookie_in_property) if (u->auth_cookie)
pa_authkey_prop_unref(m->core, PA_NATIVE_COOKIE_PROPERTY_NAME); pa_auth_cookie_unref(u->auth_cookie);
if (u->hook_slot)
pa_hook_slot_free(u->hook_slot);
if (u->protocol)
pa_native_protocol_unref(u->protocol);
pa_xfree(u->id); pa_xfree(u->id);
pa_xfree(u); pa_xfree(u);

View file

@ -352,6 +352,7 @@ enum {
PA_ERR_TOOLARGE, /**< Data too large */ PA_ERR_TOOLARGE, /**< Data too large */
PA_ERR_NOTSUPPORTED, /**< Operation not supported \since 0.9.5 */ PA_ERR_NOTSUPPORTED, /**< Operation not supported \since 0.9.5 */
PA_ERR_UNKNOWN, /**< The error code was unknown to the client */ PA_ERR_UNKNOWN, /**< The error code was unknown to the client */
PA_ERR_NOEXTENSION, /**< Extension does not exist. \since 0.9.12 */
PA_ERR_MAX /**< Not really an error but the first invalid error code */ PA_ERR_MAX /**< Not really an error but the first invalid error code */
}; };

View file

@ -57,7 +57,10 @@ const char*pa_strerror(int error) {
[PA_ERR_BADSTATE] = "Bad state", [PA_ERR_BADSTATE] = "Bad state",
[PA_ERR_NODATA] = "No data", [PA_ERR_NODATA] = "No data",
[PA_ERR_VERSION] = "Incompatible protocol version", [PA_ERR_VERSION] = "Incompatible protocol version",
[PA_ERR_TOOLARGE] = "Too large" [PA_ERR_TOOLARGE] = "Too large",
[PA_ERR_NOTSUPPORTED] = "Not supported",
[PA_ERR_UNKNOWN] = "Unknown error code",
[PA_ERR_NOEXTENSION] = "No such extension"
}; };
if (error < 0 || error >= PA_ERR_MAX) if (error < 0 || error >= PA_ERR_MAX)

109
src/pulsecore/auth-cookie.c Normal file
View file

@ -0,0 +1,109 @@
/***
This file is part of PulseAudio.
Copyright 2008 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulsecore/refcnt.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-util.h>
#include <pulsecore/shared.h>
#include <pulsecore/authkey.h>
#include "auth-cookie.h"
struct pa_auth_cookie {
PA_REFCNT_DECLARE;
pa_core *core;
char *name;
size_t size;
};
pa_auth_cookie* pa_auth_cookie_get(pa_core *core, const char *cn, size_t size) {
pa_auth_cookie *c;
char *t;
pa_assert(core);
pa_assert(size > 0);
t = pa_sprintf_malloc("auth-cookie%s%s", cn ? "@" : "", cn ? cn : "");
if ((c = pa_shared_get(core, t))) {
pa_xfree(t);
if (c->size != size)
return NULL;
return pa_auth_cookie_ref(c);
}
c = pa_xmalloc(PA_ALIGN(sizeof(pa_auth_cookie)) + size);
PA_REFCNT_INIT(c);
c->core = core;
c->name = t;
c->size = size;
pa_assert_se(pa_shared_set(core, t, c) >= 0);
if (pa_authkey_load_auto(cn, (uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie)), size) < 0) {
pa_auth_cookie_unref(c);
return NULL;
}
return c;
}
pa_auth_cookie* pa_auth_cookie_ref(pa_auth_cookie *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
PA_REFCNT_INC(c);
return c;
}
void pa_auth_cookie_unref(pa_auth_cookie *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
if (PA_REFCNT_DEC(c) > 0)
return;
pa_assert_se(pa_shared_remove(c->core, c->name) >= 0);
pa_xfree(c->name);
pa_xfree(c);
}
const uint8_t* pa_auth_cookie_read(pa_auth_cookie *c, size_t size) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
pa_assert(c->size == size);
return (const uint8_t*) c + PA_ALIGN(sizeof(pa_auth_cookie));
}

View file

@ -0,0 +1,35 @@
#ifndef fooauthcookiehfoo
#define fooauthcookiehfoo
/***
This file is part of PulseAudio.
Copyright 2008 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#include <pulsecore/core.h>
typedef struct pa_auth_cookie pa_auth_cookie;
pa_auth_cookie* pa_auth_cookie_get(pa_core *c, const char *cn, size_t size);
pa_auth_cookie* pa_auth_cookie_ref(pa_auth_cookie *c);
void pa_auth_cookie_unref(pa_auth_cookie *c);
const uint8_t* pa_auth_cookie_read(pa_auth_cookie *, size_t size);
#endif

View file

@ -27,7 +27,7 @@
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/refcnt.h> #include <pulsecore/refcnt.h>
@ -47,7 +47,7 @@ int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
pa_assert(data); pa_assert(data);
pa_assert(len > 0); pa_assert(len > 0);
if (!(a = pa_property_get(c, name))) if (!(a = pa_shared_get(c, name)))
return -1; return -1;
pa_assert(a->length == len); pa_assert(a->length == len);
@ -62,7 +62,7 @@ int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t l
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
if (pa_property_get(c, name)) if (pa_shared_get(c, name))
return -1; return -1;
a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len); a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len);
@ -70,7 +70,7 @@ int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t l
a->length = len; a->length = len;
memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len); memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len);
pa_property_set(c, name, a); pa_shared_set(c, name, a);
return 0; return 0;
} }
@ -81,7 +81,7 @@ void pa_authkey_prop_ref(pa_core *c, const char *name) {
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
a = pa_property_get(c, name); a = pa_shared_get(c, name);
pa_assert(a); pa_assert(a);
pa_assert(PA_REFCNT_VALUE(a) >= 1); pa_assert(PA_REFCNT_VALUE(a) >= 1);
PA_REFCNT_INC(a); PA_REFCNT_INC(a);
@ -93,14 +93,12 @@ void pa_authkey_prop_unref(pa_core *c, const char *name) {
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
a = pa_property_get(c, name); a = pa_shared_get(c, name);
pa_assert(a); pa_assert(a);
pa_assert(PA_REFCNT_VALUE(a) >= 1); pa_assert(PA_REFCNT_VALUE(a) >= 1);
if (PA_REFCNT_DEC(a) <= 0) { if (PA_REFCNT_DEC(a) <= 0) {
pa_property_remove(c, name); pa_shared_remove(c, name);
pa_xfree(a); pa_xfree(a);
} }
} }

View file

@ -49,7 +49,7 @@
#include <pulsecore/play-memchunk.h> #include <pulsecore/play-memchunk.h>
#include <pulsecore/autoload.h> #include <pulsecore/autoload.h>
#include <pulsecore/sound-file-stream.h> #include <pulsecore/sound-file-stream.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
@ -110,7 +110,7 @@ static int pa_cli_command_autoload_list(pa_core *c, pa_tokenizer *t, pa_strbuf *
static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_list_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_list_shared_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_move_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_move_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_move_source_output(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_move_source_output(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_vacuum(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_vacuum(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
@ -160,7 +160,7 @@ static const struct command commands[] = {
{ "remove-autoload-sink", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a sink (args: name)"*/, 2}, { "remove-autoload-sink", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a sink (args: name)"*/, 2},
{ "remove-autoload-source", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a source (args: name)"*/, 2}, { "remove-autoload-source", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a source (args: name)"*/, 2},
{ "dump", pa_cli_command_dump, "Dump daemon configuration", 1}, { "dump", pa_cli_command_dump, "Dump daemon configuration", 1},
{ "list-props", pa_cli_command_list_props, NULL, 1}, { "shared", pa_cli_command_list_shared_props, NULL, 1},
{ "move-sink-input", pa_cli_command_move_sink_input, "Move sink input to another sink (args: index, sink)", 3}, { "move-sink-input", pa_cli_command_move_sink_input, "Move sink input to another sink (args: index, sink)", 3},
{ "move-source-output", pa_cli_command_move_source_output, "Move source output to another source (args: index, source)", 3}, { "move-source-output", pa_cli_command_move_source_output, "Move source output to another source (args: index, source)", 3},
{ "vacuum", pa_cli_command_vacuum, NULL, 1}, { "vacuum", pa_cli_command_vacuum, NULL, 1},
@ -996,13 +996,13 @@ static int pa_cli_command_autoload_list(pa_core *c, pa_tokenizer *t, pa_strbuf *
return 0; return 0;
} }
static int pa_cli_command_list_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) { static int pa_cli_command_list_shared_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
pa_core_assert_ref(c); pa_core_assert_ref(c);
pa_assert(t); pa_assert(t);
pa_assert(buf); pa_assert(buf);
pa_assert(fail); pa_assert(fail);
pa_property_dump(c, buf); pa_shared_dump(c, buf);
return 0; return 0;
} }

View file

@ -52,7 +52,7 @@ struct pa_cli {
pa_core *core; pa_core *core;
pa_ioline *line; pa_ioline *line;
void (*eof_callback)(pa_cli *c, void *userdata); pa_cli_eof_cb_t eof_callback;
void *userdata; void *userdata;
pa_client *client; pa_client *client;
@ -107,12 +107,11 @@ static void client_kill(pa_client *client) {
pa_assert_se(c = client->userdata); pa_assert_se(c = client->userdata);
pa_log_debug("CLI client killed."); pa_log_debug("CLI client killed.");
if (c->defer_kill) if (c->defer_kill)
c->kill_requested = TRUE; c->kill_requested = TRUE;
else { else if (c->eof_callback)
if (c->eof_callback) c->eof_callback(c, c->userdata);
c->eof_callback(c, c->userdata);
}
} }
static void line_callback(pa_ioline *line, const char *s, void *userdata) { static void line_callback(pa_ioline *line, const char *s, void *userdata) {
@ -125,6 +124,7 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
if (!s) { if (!s) {
pa_log_debug("CLI got EOF from user."); pa_log_debug("CLI got EOF from user.");
if (c->eof_callback) if (c->eof_callback)
c->eof_callback(c, c->userdata); c->eof_callback(c, c->userdata);
@ -145,9 +145,15 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
pa_ioline_puts(line, PROMPT); pa_ioline_puts(line, PROMPT);
} }
void pa_cli_set_eof_callback(pa_cli *c, void (*cb)(pa_cli*c, void *userdata), void *userdata) { void pa_cli_set_eof_callback(pa_cli *c, pa_cli_eof_cb_t cb, void *userdata) {
pa_assert(c); pa_assert(c);
c->eof_callback = cb; c->eof_callback = cb;
c->userdata = userdata; c->userdata = userdata;
} }
pa_module *pa_cli_get_module(pa_cli *c) {
pa_assert(c);
return c->client->module;
}

View file

@ -28,11 +28,15 @@
typedef struct pa_cli pa_cli; typedef struct pa_cli pa_cli;
typedef void (*pa_cli_eof_cb_t)(pa_cli *c, void *userdata);
/* Create a new command line session on the specified io channel owned by the specified module */ /* Create a new command line session on the specified io channel owned by the specified module */
pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m); pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m);
void pa_cli_free(pa_cli *cli); void pa_cli_free(pa_cli *cli);
/* Set a callback function that is called whenever the command line session is terminated */ /* Set a callback function that is called whenever the command line session is terminated */
void pa_cli_set_eof_callback(pa_cli *cli, void (*cb)(pa_cli*c, void *userdata), void *userdata); void pa_cli_set_eof_callback(pa_cli *cli, pa_cli_eof_cb_t cb, void *userdata);
pa_module *pa_cli_get_module(pa_cli *c);
#endif #endif

View file

@ -39,7 +39,7 @@
#include <pulsecore/core-scache.h> #include <pulsecore/core-scache.h>
#include <pulsecore/autoload.h> #include <pulsecore/autoload.h>
#include <pulsecore/core-subscribe.h> #include <pulsecore/core-subscribe.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include <pulsecore/random.h> #include <pulsecore/random.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
@ -141,7 +141,7 @@ pa_core* pa_core_new(pa_mainloop_api *m, int shared) {
for (j = 0; j < PA_CORE_HOOK_MAX; j++) for (j = 0; j < PA_CORE_HOOK_MAX; j++)
pa_hook_init(&c->hooks[j], c); pa_hook_init(&c->hooks[j], c);
pa_property_init(c); pa_shared_init(c);
pa_random(&c->cookie, sizeof(c->cookie)); pa_random(&c->cookie, sizeof(c->cookie));
@ -149,6 +149,8 @@ pa_core* pa_core_new(pa_mainloop_api *m, int shared) {
pa_check_signal_is_blocked(SIGPIPE); pa_check_signal_is_blocked(SIGPIPE);
#endif #endif
pa_core_check_quit(c);
return c; return c;
} }
@ -189,10 +191,10 @@ static void core_free(pa_object *o) {
pa_silence_cache_done(&c->silence_cache); pa_silence_cache_done(&c->silence_cache);
pa_mempool_free(c->mempool); pa_mempool_free(c->mempool);
pa_property_cleanup(c); pa_shared_cleanup(c);
for (j = 0; j < PA_CORE_HOOK_MAX; j++) for (j = 0; j < PA_CORE_HOOK_MAX; j++)
pa_hook_free(&c->hooks[j]); pa_hook_done(&c->hooks[j]);
pa_xfree(c); pa_xfree(c);
} }

View file

@ -94,7 +94,7 @@ struct pa_core {
pa_idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules, *scache, *autoload_idxset; pa_idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules, *scache, *autoload_idxset;
/* Some hashmaps for all sorts of entities */ /* Some hashmaps for all sorts of entities */
pa_hashmap *namereg, *autoload_hashmap, *properties; pa_hashmap *namereg, *autoload_hashmap, *shared;
/* The name of the default sink/source */ /* The name of the default sink/source */
char *default_source_name, *default_sink_name; char *default_source_name, *default_sink_name;

View file

@ -44,7 +44,7 @@ static void slot_free(pa_hook *hook, pa_hook_slot *slot) {
pa_xfree(slot); pa_xfree(slot);
} }
void pa_hook_free(pa_hook *hook) { void pa_hook_done(pa_hook *hook) {
pa_assert(hook); pa_assert(hook);
pa_assert(hook->n_firing == 0); pa_assert(hook->n_firing == 0);

View file

@ -64,7 +64,7 @@ struct pa_hook {
}; };
void pa_hook_init(pa_hook *hook, void *data); void pa_hook_init(pa_hook *hook, void *data);
void pa_hook_free(pa_hook *hook); void pa_hook_done(pa_hook *hook);
pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data); pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data);
void pa_hook_slot_free(pa_hook_slot *slot); void pa_hook_slot_free(pa_hook_slot *slot);

View file

@ -322,8 +322,7 @@ int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *r
if (pa_modargs_get_sample_spec(ma, &ss) < 0) if (pa_modargs_get_sample_spec(ma, &ss) < 0)
return -1; return -1;
if (!pa_channel_map_init_auto(&map, ss.channels, def)) pa_channel_map_init_extend(&map, ss.channels, def);
map.channels = 0;
if (pa_modargs_get_channel_map(ma, NULL, &map) < 0) if (pa_modargs_get_channel_map(ma, NULL, &map) < 0)
return -1; return -1;

View file

@ -76,6 +76,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
m = pa_xnew(pa_module, 1); m = pa_xnew(pa_module, 1);
m->name = pa_xstrdup(name); m->name = pa_xstrdup(name);
m->argument = pa_xstrdup(argument); m->argument = pa_xstrdup(argument);
m->load_once = FALSE;
if (!(m->dl = lt_dlopenext(name))) { if (!(m->dl = lt_dlopenext(name))) {
pa_log("Failed to open module \"%s\": %s", name, lt_dlerror()); pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());
@ -84,7 +85,9 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
if ((load_once = (pa_bool_t (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) { if ((load_once = (pa_bool_t (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) {
if (load_once() && c->modules) { m->load_once = load_once();
if (m->load_once && c->modules) {
pa_module *i; pa_module *i;
uint32_t idx; uint32_t idx;
/* OK, the module only wants to be loaded once, let's make sure it is */ /* OK, the module only wants to be loaded once, let's make sure it is */

View file

@ -43,10 +43,12 @@ struct pa_module {
void *userdata; void *userdata;
int n_used; int n_used;
pa_bool_t auto_unload;
time_t last_used_time;
pa_bool_t unload_requested; pa_bool_t auto_unload:1;
pa_bool_t load_once:1;
pa_bool_t unload_requested:1;
time_t last_used_time;
}; };
pa_module* pa_module_load(pa_core *c, const char *name, const char*argument); pa_module* pa_module_load(pa_core *c, const char *name, const char*argument);

View file

@ -137,7 +137,7 @@ enum {
PA_COMMAND_PLAYBACK_STREAM_MOVED, PA_COMMAND_PLAYBACK_STREAM_MOVED,
PA_COMMAND_RECORD_STREAM_MOVED, PA_COMMAND_RECORD_STREAM_MOVED,
/* Supported since protocol v13 (0.9.10) */ /* Supported since protocol v13 (0.9.11) */
PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST, PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST,
PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST, PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST,
PA_COMMAND_UPDATE_CLIENT_PROPLIST, PA_COMMAND_UPDATE_CLIENT_PROPLIST,
@ -148,6 +148,9 @@ enum {
/* SERVER->CLIENT */ /* SERVER->CLIENT */
PA_COMMAND_STARTED, PA_COMMAND_STARTED,
/* Supported since protocol v14 (0.9.12) */
PA_COMMAND_EXTENSION,
PA_COMMAND_MAX PA_COMMAND_MAX
}; };
@ -161,7 +164,6 @@ enum {
#define PA_NATIVE_DEFAULT_UNIX_SOCKET "native" #define PA_NATIVE_DEFAULT_UNIX_SOCKET "native"
PA_C_DECL_END PA_C_DECL_END
#endif #endif

View file

@ -30,34 +30,41 @@
#include <pulsecore/cli.h> #include <pulsecore/cli.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/shared.h>
#include "protocol-cli.h" #include "protocol-cli.h"
/* Don't allow more than this many concurrent connections */ /* Don't allow more than this many concurrent connections */
#define MAX_CONNECTIONS 25 #define MAX_CONNECTIONS 25
struct pa_protocol_cli { struct pa_cli_protocol {
pa_module *module; PA_REFCNT_DECLARE;
pa_core *core; pa_core *core;
pa_socket_server*server;
pa_idxset *connections; pa_idxset *connections;
}; };
static void cli_eof_cb(pa_cli*c, void*userdata) { static void cli_unlink(pa_cli_protocol *p, pa_cli *c) {
pa_protocol_cli *p = userdata;
pa_assert(p); pa_assert(p);
pa_assert(c);
pa_idxset_remove_by_data(p->connections, c, NULL); pa_idxset_remove_by_data(p->connections, c, NULL);
pa_cli_free(c); pa_cli_free(c);
} }
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) { static void cli_eof_cb(pa_cli*c, void*userdata) {
pa_protocol_cli *p = userdata; pa_cli_protocol *p = userdata;
pa_assert(p);
cli_unlink(p, c);
}
void pa_cli_protocol_connect(pa_cli_protocol *p, pa_iochannel *io, pa_module *m) {
pa_cli *c; pa_cli *c;
pa_assert(s);
pa_assert(io);
pa_assert(p); pa_assert(p);
pa_assert(io);
pa_assert(m);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@ -65,39 +72,71 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
return; return;
} }
c = pa_cli_new(p->core, io, p->module); c = pa_cli_new(p->core, io, m);
pa_cli_set_eof_callback(c, cli_eof_cb, p); pa_cli_set_eof_callback(c, cli_eof_cb, p);
pa_idxset_put(p->connections, c, NULL); pa_idxset_put(p->connections, c, NULL);
} }
pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) { void pa_cli_protocol_disconnect(pa_cli_protocol *p, pa_module *m) {
pa_protocol_cli* p; pa_cli *c;
void *state = NULL;
pa_core_assert_ref(core); pa_assert(p);
pa_assert(server); pa_assert(m);
p = pa_xnew(pa_protocol_cli, 1); while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
p->module = m; if (pa_cli_get_module(c) == m)
p->core = core; cli_unlink(p, c);
p->server = pa_socket_server_ref(server); }
static pa_cli_protocol* cli_protocol_new(pa_core *c) {
pa_cli_protocol *p;
pa_assert(c);
p = pa_xnew(pa_cli_protocol, 1);
PA_REFCNT_INIT(p);
p->core = c;
p->connections = pa_idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
pa_socket_server_set_callback(p->server, on_connection, p); pa_assert_se(pa_shared_set(c, "cli-protocol", p) >= 0);
return p; return p;
} }
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) { pa_cli_protocol* pa_cli_protocol_get(pa_core *c) {
pa_assert(p); pa_cli_protocol *p;
pa_cli_free(p); if ((p = pa_shared_get(c, "cli-protocol")))
return pa_cli_protocol_ref(p);
return cli_protocol_new(c);
} }
void pa_protocol_cli_free(pa_protocol_cli *p) { pa_cli_protocol* pa_cli_protocol_ref(pa_cli_protocol *p) {
pa_assert(p); pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
PA_REFCNT_INC(p);
return p;
}
void pa_cli_protocol_unref(pa_cli_protocol *p) {
pa_cli *c;
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
if (PA_REFCNT_DEC(p) > 0)
return;
while ((c = pa_idxset_first(p->connections, NULL)))
cli_unlink(p, c);
pa_idxset_free(p->connections, NULL, NULL);
pa_assert_se(pa_shared_remove(p->core, "cli-protocol") >= 0);
pa_idxset_free(p->connections, free_connection, NULL);
pa_socket_server_unref(p->server);
pa_xfree(p); pa_xfree(p);
} }

View file

@ -27,9 +27,12 @@
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
typedef struct pa_protocol_cli pa_protocol_cli; typedef struct pa_cli_protocol pa_cli_protocol;
pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa_module *m, pa_modargs *ma); pa_cli_protocol* pa_cli_protocol_get(pa_core *core);
void pa_protocol_cli_free(pa_protocol_cli *n); pa_cli_protocol* pa_cli_protocol_ref(pa_cli_protocol *p);
void pa_cli_protocol_unref(pa_cli_protocol *p);
void pa_cli_protocol_connect(pa_cli_protocol *p, pa_iochannel *io, pa_module *m);
void pa_cli_protocol_disconnect(pa_cli_protocol *o, pa_module *m);
#endif #endif

View file

@ -52,6 +52,7 @@
#include <pulsecore/ipacl.h> #include <pulsecore/ipacl.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/shared.h>
#include "endianmacros.h" #include "endianmacros.h"
@ -83,7 +84,8 @@ typedef struct connection {
uint32_t index; uint32_t index;
pa_bool_t dead; pa_bool_t dead;
pa_protocol_esound *protocol; pa_esound_protocol *protocol;
pa_esound_options *options;
pa_iochannel *io; pa_iochannel *io;
pa_client *client; pa_client *client;
pa_bool_t authorized, swap_byte_order; pa_bool_t authorized, swap_byte_order;
@ -120,17 +122,12 @@ PA_DECLARE_CLASS(connection);
#define CONNECTION(o) (connection_cast(o)) #define CONNECTION(o) (connection_cast(o))
static PA_DEFINE_CHECK_TYPE(connection, pa_msgobject); static PA_DEFINE_CHECK_TYPE(connection, pa_msgobject);
struct pa_protocol_esound { struct pa_esound_protocol {
pa_module *module; PA_REFCNT_DECLARE;
pa_core *core;
pa_bool_t public;
pa_socket_server *server;
pa_idxset *connections;
char *sink_name, *source_name; pa_core *core;
pa_idxset *connections;
unsigned n_player; unsigned n_player;
uint8_t esd_key[ESD_KEY_LEN];
pa_ip_acl *auth_ip_acl;
}; };
enum { enum {
@ -213,6 +210,11 @@ static void connection_unlink(connection *c) {
if (!c->protocol) if (!c->protocol)
return; return;
if (c->options) {
pa_esound_options_unref(c->options);
c->options = NULL;
}
if (c->sink_input) { if (c->sink_input) {
pa_sink_input_unlink(c->sink_input); pa_sink_input_unlink(c->sink_input);
pa_sink_input_unref(c->sink_input); pa_sink_input_unref(c->sink_input);
@ -340,17 +342,22 @@ static int esd_proto_connect(connection *c, PA_GCC_UNUSED esd_proto_t request, c
pa_assert(data); pa_assert(data);
pa_assert(length == (ESD_KEY_LEN + sizeof(uint32_t))); pa_assert(length == (ESD_KEY_LEN + sizeof(uint32_t)));
if (!c->authorized) { if (!c->authorized && c->options->auth_cookie) {
if (memcmp(data, c->protocol->esd_key, ESD_KEY_LEN) != 0) { const uint8_t*key;
pa_log("kicked client with invalid authorization key.");
return -1;
}
c->authorized = TRUE; if ((key = pa_auth_cookie_read(c->options->auth_cookie, ESD_KEY_LEN)))
if (c->auth_timeout_event) { if (memcmp(data, key, ESD_KEY_LEN) == 0)
c->protocol->core->mainloop->time_free(c->auth_timeout_event); c->authorized = TRUE;
c->auth_timeout_event = NULL; }
}
if (!c->authorized) {
pa_log("Kicked client with invalid authorization key.");
return -1;
}
if (c->auth_timeout_event) {
c->protocol->core->mainloop->time_free(c->auth_timeout_event);
c->auth_timeout_event = NULL;
} }
data = (const char*)data + ESD_KEY_LEN; data = (const char*)data + ESD_KEY_LEN;
@ -395,9 +402,9 @@ static int esd_proto_stream_play(connection *c, PA_GCC_UNUSED esd_proto_t reques
CHECK_VALIDITY(pa_sample_spec_valid(&ss), "Invalid sample specification"); CHECK_VALIDITY(pa_sample_spec_valid(&ss), "Invalid sample specification");
if (c->protocol->sink_name) { if (c->options->default_sink) {
sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1); sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK, 1);
CHECK_VALIDITY(sink, "No such sink: %s", c->protocol->sink_name); CHECK_VALIDITY(sink, "No such sink: %s", c->options->default_sink);
} }
pa_strlcpy(name, data, sizeof(name)); pa_strlcpy(name, data, sizeof(name));
@ -412,7 +419,7 @@ static int esd_proto_stream_play(connection *c, PA_GCC_UNUSED esd_proto_t reques
pa_sink_input_new_data_init(&sdata); pa_sink_input_new_data_init(&sdata);
sdata.driver = __FILE__; sdata.driver = __FILE__;
sdata.module = c->protocol->module; sdata.module = c->options->module;
sdata.client = c->client; sdata.client = c->client;
sdata.sink = sink; sdata.sink = sink;
pa_proplist_update(sdata.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_proplist_update(sdata.proplist, PA_UPDATE_MERGE, c->client->proplist);
@ -483,7 +490,7 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
if (request == ESD_PROTO_STREAM_MON) { if (request == ESD_PROTO_STREAM_MON) {
pa_sink* sink; pa_sink* sink;
if (!(sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1))) { if (!(sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK, 1))) {
pa_log("no such sink."); pa_log("no such sink.");
return -1; return -1;
} }
@ -495,8 +502,8 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
} else { } else {
pa_assert(request == ESD_PROTO_STREAM_REC); pa_assert(request == ESD_PROTO_STREAM_REC);
if (c->protocol->source_name) { if (c->options->default_source) {
if (!(source = pa_namereg_get(c->protocol->core, c->protocol->source_name, PA_NAMEREG_SOURCE, 1))) { if (!(source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE, 1))) {
pa_log("no such source."); pa_log("no such source.");
return -1; return -1;
} }
@ -515,7 +522,7 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
pa_source_output_new_data_init(&sdata); pa_source_output_new_data_init(&sdata);
sdata.driver = __FILE__; sdata.driver = __FILE__;
sdata.module = c->protocol->module; sdata.module = c->options->module;
sdata.client = c->client; sdata.client = c->client;
sdata.source = source; sdata.source = source;
pa_proplist_update(sdata.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_proplist_update(sdata.proplist, PA_UPDATE_MERGE, c->client->proplist);
@ -562,7 +569,7 @@ static int esd_proto_get_latency(connection *c, PA_GCC_UNUSED esd_proto_t reques
pa_assert(!data); pa_assert(!data);
pa_assert(length == 0); pa_assert(length == 0);
if (!(sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1))) if (!(sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK, 1)))
latency = 0; latency = 0;
else { else {
double usec = pa_sink_get_latency(sink); double usec = pa_sink_get_latency(sink);
@ -583,7 +590,7 @@ static int esd_proto_server_info(connection *c, PA_GCC_UNUSED esd_proto_t reques
pa_assert(data); pa_assert(data);
pa_assert(length == sizeof(int32_t)); pa_assert(length == sizeof(int32_t));
if ((sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1))) { if ((sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK, 1))) {
rate = sink->sample_spec.rate; rate = sink->sample_spec.rate;
format = format_native2esd(&sink->sample_spec); format = format_native2esd(&sink->sample_spec);
} }
@ -858,7 +865,7 @@ static int esd_proto_sample_free_or_play(connection *c, esd_proto_t request, con
if (request == ESD_PROTO_SAMPLE_PLAY) { if (request == ESD_PROTO_SAMPLE_PLAY) {
pa_sink *sink; pa_sink *sink;
if ((sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1))) if ((sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK, 1)))
if (pa_scache_play_item(c->protocol->core, name, sink, PA_VOLUME_NORM, c->client->proplist, NULL) >= 0) if (pa_scache_play_item(c->protocol->core, name, sink, PA_VOLUME_NORM, c->client->proplist, NULL) >= 0)
ok = idx + 1; ok = idx + 1;
} else { } else {
@ -1350,7 +1357,7 @@ static pa_usec_t source_output_get_latency_cb(pa_source_output *o) {
return pa_bytes_to_usec(pa_memblockq_get_length(c->output_memblockq), &c->source_output->sample_spec); return pa_bytes_to_usec(pa_memblockq_get_length(c->output_memblockq), &c->source_output->sample_spec);
} }
/*** socket server callback ***/ /*** entry points ***/
static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
connection *c = CONNECTION(userdata); connection *c = CONNECTION(userdata);
@ -1364,14 +1371,13 @@ static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timev
connection_unlink(c); connection_unlink(c);
} }
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) { void pa_esound_protocol_connect(pa_esound_protocol *p, pa_iochannel *io, pa_esound_options *o) {
connection *c; connection *c;
pa_protocol_esound *p = userdata;
char cname[256], pname[128]; char cname[256], pname[128];
pa_assert(s);
pa_assert(io);
pa_assert(p); pa_assert(p);
pa_assert(io);
pa_assert(o);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@ -1390,11 +1396,12 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_snprintf(cname, sizeof(cname), "EsounD client (%s)", pname); pa_snprintf(cname, sizeof(cname), "EsounD client (%s)", pname);
c->client = pa_client_new(p->core, __FILE__, cname); c->client = pa_client_new(p->core, __FILE__, cname);
pa_proplist_sets(c->client->proplist, "esound-protocol.peer", pname); pa_proplist_sets(c->client->proplist, "esound-protocol.peer", pname);
c->client->module = p->module; c->client->module = o->module;
c->client->kill = client_kill_cb; c->client->kill = client_kill_cb;
c->client->userdata = c; c->client->userdata = c;
c->authorized = !!p->public; c->options = pa_esound_options_ref(o);
c->authorized = FALSE;
c->swap_byte_order = FALSE; c->swap_byte_order = FALSE;
c->dead = FALSE; c->dead = FALSE;
@ -1423,7 +1430,15 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
c->original_name = NULL; c->original_name = NULL;
if (!c->authorized && p->auth_ip_acl && pa_ip_acl_check(p->auth_ip_acl, pa_iochannel_get_recv_fd(io)) > 0) { if (o->auth_anonymous) {
pa_log_info("Client authenticated anonymously.");
c->authorized = TRUE;
}
if (!c->authorized &&
o->auth_ip_acl &&
pa_ip_acl_check(o->auth_ip_acl, pa_iochannel_get_recv_fd(io)) > 0) {
pa_log_info("Client authenticated by IP ACL."); pa_log_info("Client authenticated by IP ACL.");
c->authorized = TRUE; c->authorized = TRUE;
} }
@ -1442,71 +1457,163 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_idxset_put(p->connections, c, &c->index); pa_idxset_put(p->connections, c, &c->index);
} }
/*** entry points ***/ void pa_esound_protocol_disconnect(pa_esound_protocol *p, pa_module *m) {
connection *c;
void *state = NULL;
pa_protocol_esound* pa_protocol_esound_new(pa_core*core, pa_socket_server *server, pa_module *m, pa_modargs *ma) { pa_assert(p);
pa_protocol_esound *p = NULL;
pa_bool_t public = FALSE;
const char *acl;
pa_assert(core);
pa_assert(server);
pa_assert(m); pa_assert(m);
pa_assert(ma);
if (pa_modargs_get_value_boolean(ma, "auth-anonymous", &public) < 0) { while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
pa_log("auth-anonymous= expects a boolean argument."); if (c->options->module == m)
goto fail; connection_unlink(c);
}
p = pa_xnew(pa_protocol_esound, 1);
if (pa_authkey_load_auto(pa_modargs_get_value(ma, "cookie", DEFAULT_COOKIE_FILE), p->esd_key, sizeof(p->esd_key)) < 0)
goto fail;
if ((acl = pa_modargs_get_value(ma, "auth-ip-acl", NULL))) {
if (!(p->auth_ip_acl = pa_ip_acl_new(acl))) {
pa_log("Failed to parse IP ACL '%s'", acl);
goto fail;
}
} else
p->auth_ip_acl = NULL;
p->core = core;
p->module = m;
p->public = public;
p->server = pa_socket_server_ref(server);
pa_socket_server_set_callback(p->server, on_connection, p);
p->connections = pa_idxset_new(NULL, NULL);
p->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
p->source_name = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
p->n_player = 0;
return p;
fail:
pa_xfree(p);
return NULL;
} }
void pa_protocol_esound_free(pa_protocol_esound *p) { static pa_esound_protocol* esound_protocol_new(pa_core *c) {
pa_esound_protocol *p;
pa_assert(c);
p = pa_xnew(pa_esound_protocol, 1);
PA_REFCNT_INIT(p);
p->core = c;
p->connections = pa_idxset_new(NULL, NULL);
p->n_player = 0;
pa_assert_se(pa_shared_set(c, "esound-protocol", p) >= 0);
return p;
}
pa_esound_protocol* pa_esound_protocol_get(pa_core *c) {
pa_esound_protocol *p;
if ((p = pa_shared_get(c, "esound-protocol")))
return pa_esound_protocol_ref(p);
return esound_protocol_new(c);
}
pa_esound_protocol* pa_esound_protocol_ref(pa_esound_protocol *p) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
PA_REFCNT_INC(p);
return p;
}
void pa_esound_protocol_unref(pa_esound_protocol *p) {
connection *c; connection *c;
pa_assert(p); pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
if (PA_REFCNT_DEC(p) > 0)
return;
while ((c = pa_idxset_first(p->connections, NULL))) while ((c = pa_idxset_first(p->connections, NULL)))
connection_unlink(c); connection_unlink(c);
pa_idxset_free(p->connections, NULL, NULL); pa_idxset_free(p->connections, NULL, NULL);
if (p->server) pa_assert_se(pa_shared_remove(p->core, "esound-protocol") >= 0);
pa_socket_server_unref(p->server);
if (p->auth_ip_acl)
pa_ip_acl_free(p->auth_ip_acl);
pa_xfree(p->sink_name);
pa_xfree(p->source_name);
pa_xfree(p); pa_xfree(p);
} }
pa_esound_options* pa_esound_options_new(void) {
pa_esound_options *o;
o = pa_xnew0(pa_esound_options, 1);
PA_REFCNT_INIT(o);
return o;
}
pa_esound_options* pa_esound_options_ref(pa_esound_options *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
PA_REFCNT_INC(o);
return o;
}
void pa_esound_options_unref(pa_esound_options *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
if (PA_REFCNT_DEC(o) > 0)
return;
if (o->auth_ip_acl)
pa_ip_acl_free(o->auth_ip_acl);
if (o->auth_cookie)
pa_auth_cookie_unref(o->auth_cookie);
pa_xfree(o->default_sink);
pa_xfree(o->default_source);
pa_xfree(o);
}
int pa_esound_options_parse(pa_esound_options *o, pa_core *c, pa_modargs *ma) {
pa_bool_t enabled;
const char *acl;
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
pa_assert(ma);
if (pa_modargs_get_value_boolean(ma, "auth-anonymous", &o->auth_anonymous) < 0) {
pa_log("auth-anonymous= expects a boolean argument.");
return -1;
}
if ((acl = pa_modargs_get_value(ma, "auth-ip-acl", NULL))) {
pa_ip_acl *ipa;
if (!(o->auth_ip_acl = pa_ip_acl_new(acl))) {
pa_log("Failed to parse IP ACL '%s'", acl);
return -1;
}
if (o->auth_ip_acl)
pa_ip_acl_free(o->auth_ip_acl);
o->auth_ip_acl = ipa;
}
enabled = TRUE;
if (pa_modargs_get_value_boolean(ma, "auth-cookie-enabled", &enabled) < 0) {
pa_log("auth-cookie-enabled= expects a boolean argument.");
return -1;
}
if (o->auth_cookie)
pa_auth_cookie_unref(o->auth_cookie);
if (enabled) {
const char *cn;
/* The new name for this is 'auth-cookie', for compat reasons
* we check the old name too */
if (!(cn = pa_modargs_get_value(ma, "auth-cookie", NULL)))
if (!(cn = pa_modargs_get_value(ma, "cookie", NULL)))
cn = DEFAULT_COOKIE_FILE;
if (!(o->auth_cookie = pa_auth_cookie_get(c, cn, ESD_KEY_LEN)))
return -1;
} else
o->auth_cookie = NULL;
pa_xfree(o->default_sink);
o->default_sink = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
pa_xfree(o->default_source);
o->default_source = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
return 0;
}

View file

@ -24,13 +24,35 @@
***/ ***/
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/socket-server.h> #include <pulsecore/ipacl.h>
#include <pulsecore/auth-cookie.h>
#include <pulsecore/iochannel.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
typedef struct pa_protocol_esound pa_protocol_esound; typedef struct pa_esound_protocol pa_esound_protocol;
pa_protocol_esound* pa_protocol_esound_new(pa_core*core, pa_socket_server *server, pa_module *m, pa_modargs *ma); typedef struct pa_esound_options {
void pa_protocol_esound_free(pa_protocol_esound *p); PA_REFCNT_DECLARE;
pa_module *module;
pa_bool_t auth_anonymous;
pa_ip_acl *auth_ip_acl;
pa_auth_cookie *auth_cookie;
char *default_sink, *default_source;
} pa_esound_options;
pa_esound_protocol* pa_esound_protocol_get(pa_core*core);
pa_esound_protocol* pa_esound_protocol_ref(pa_esound_protocol *p);
void pa_esound_protocol_unref(pa_esound_protocol *p);
void pa_esound_protocol_connect(pa_esound_protocol *p, pa_iochannel *io, pa_esound_options *o);
void pa_esound_protocol_disconnect(pa_esound_protocol *p, pa_module *m);
pa_esound_options* pa_esound_options_new(void);
pa_esound_options* pa_esound_options_ref(pa_esound_options *o);
void pa_esound_options_unref(pa_esound_options *o);
int pa_esound_options_parse(pa_esound_options *o, pa_core *c, pa_modargs *ma);
#endif #endif

View file

@ -35,6 +35,7 @@
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/cli-text.h> #include <pulsecore/cli-text.h>
#include <pulsecore/shared.h>
#include "protocol-http.h" #include "protocol-http.h"
@ -48,16 +49,21 @@
#define URL_STATUS "/status" #define URL_STATUS "/status"
struct connection { struct connection {
pa_protocol_http *protocol; pa_http_protocol *protocol;
pa_ioline *line; pa_ioline *line;
enum { REQUEST_LINE, MIME_HEADER, DATA } state; enum {
REQUEST_LINE,
MIME_HEADER,
DATA
} state;
char *url; char *url;
pa_module *module;
}; };
struct pa_protocol_http { struct pa_http_protocol {
pa_module *module; PA_REFCNT_DECLARE;
pa_core *core; pa_core *core;
pa_socket_server*server;
pa_idxset *connections; pa_idxset *connections;
}; };
@ -101,14 +107,13 @@ static void http_message(struct connection *c, int code, const char *msg, const
} }
static void connection_free(struct connection *c, int del) { static void connection_unlink(struct connection *c) {
pa_assert(c); pa_assert(c);
if (c->url) if (c->url)
pa_xfree(c->url); pa_xfree(c->url);
if (del) pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
pa_ioline_unref(c->line); pa_ioline_unref(c->line);
pa_xfree(c); pa_xfree(c);
@ -121,7 +126,7 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
if (!s) { if (!s) {
/* EOF */ /* EOF */
connection_free(c, 1); connection_unlink(c);
return; return;
} }
@ -220,16 +225,15 @@ fail:
internal_server_error(c); internal_server_error(c);
} }
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) { void pa_http_protocol_connect(pa_http_protocol *p, pa_iochannel *io, pa_module *m) {
pa_protocol_http *p = userdata;
struct connection *c; struct connection *c;
pa_assert(s);
pa_assert(io);
pa_assert(p); pa_assert(p);
pa_assert(io);
pa_assert(m);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
pa_iochannel_free(io); pa_iochannel_free(io);
return; return;
} }
@ -239,37 +243,73 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
c->line = pa_ioline_new(io); c->line = pa_ioline_new(io);
c->state = REQUEST_LINE; c->state = REQUEST_LINE;
c->url = NULL; c->url = NULL;
c->module = m;
pa_ioline_set_callback(c->line, line_callback, c); pa_ioline_set_callback(c->line, line_callback, c);
pa_idxset_put(p->connections, c, NULL); pa_idxset_put(p->connections, c, NULL);
} }
pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) { void pa_http_protocol_disconnect(pa_http_protocol *p, pa_module *m) {
pa_protocol_http* p; struct connection *c;
void *state = NULL;
pa_core_assert_ref(core); pa_assert(p);
pa_assert(server); pa_assert(m);
p = pa_xnew(pa_protocol_http, 1); while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
p->module = m; if (c->module == m)
p->core = core; connection_unlink(c);
p->server = pa_socket_server_ref(server); }
static pa_http_protocol* http_protocol_new(pa_core *c) {
pa_http_protocol *p;
pa_assert(c);
p = pa_xnew(pa_http_protocol, 1);
PA_REFCNT_INIT(p);
p->core = c;
p->connections = pa_idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
pa_socket_server_set_callback(p->server, on_connection, p); pa_assert_se(pa_shared_set(c, "http-protocol", p) >= 0);
return p; return p;
} }
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) { pa_http_protocol* pa_http_protocol_get(pa_core *c) {
pa_assert(p); pa_http_protocol *p;
connection_free(p, 0);
if ((p = pa_shared_get(c, "http-protocol")))
return pa_http_protocol_ref(p);
return http_protocol_new(c);
} }
void pa_protocol_http_free(pa_protocol_http *p) { pa_http_protocol* pa_http_protocol_ref(pa_http_protocol *p) {
pa_assert(p); pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
PA_REFCNT_INC(p);
return p;
}
void pa_http_protocol_unref(pa_http_protocol *p) {
struct connection *c;
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
if (PA_REFCNT_DEC(p) > 0)
return;
while ((c = pa_idxset_first(p->connections, NULL)))
connection_unlink(c);
pa_idxset_free(p->connections, NULL, NULL);
pa_assert_se(pa_shared_remove(p->core, "http-protocol") >= 0);
pa_idxset_free(p->connections, free_connection, NULL);
pa_socket_server_unref(p->server);
pa_xfree(p); pa_xfree(p);
} }

View file

@ -23,13 +23,17 @@
***/ ***/
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/socket-server.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/iochannel.h>
typedef struct pa_protocol_http pa_protocol_http;
pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server, pa_module *m, pa_modargs *ma); typedef struct pa_http_protocol pa_http_protocol;
void pa_protocol_http_free(pa_protocol_http *n);
pa_http_protocol* pa_http_protocol_get(pa_core *core);
pa_http_protocol* pa_http_protocol_ref(pa_http_protocol *p);
void pa_http_protocol_unref(pa_http_protocol *p);
void pa_http_protocol_connect(pa_http_protocol *p, pa_iochannel *io, pa_module *m);
void pa_http_protocol_disconnect(pa_http_protocol *p, pa_module *m);
#endif #endif

View file

@ -52,7 +52,7 @@
#include <pulsecore/autoload.h> #include <pulsecore/autoload.h>
#include <pulsecore/authkey-prop.h> #include <pulsecore/authkey-prop.h>
#include <pulsecore/strlist.h> #include <pulsecore/strlist.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/creds.h> #include <pulsecore/creds.h>
@ -74,7 +74,7 @@
#define DEFAULT_FRAGSIZE_MSEC DEFAULT_TLENGTH_MSEC #define DEFAULT_FRAGSIZE_MSEC DEFAULT_TLENGTH_MSEC
typedef struct connection connection; typedef struct connection connection;
struct pa_protocol_native; struct pa_native_protocol;
typedef struct record_stream { typedef struct record_stream {
pa_msgobject parent; pa_msgobject parent;
@ -88,10 +88,18 @@ typedef struct record_stream {
pa_usec_t source_latency; pa_usec_t source_latency;
} record_stream; } record_stream;
PA_DECLARE_CLASS(record_stream);
#define RECORD_STREAM(o) (record_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(record_stream, pa_msgobject);
typedef struct output_stream { typedef struct output_stream {
pa_msgobject parent; pa_msgobject parent;
} output_stream; } output_stream;
PA_DECLARE_CLASS(output_stream);
#define OUTPUT_STREAM(o) (output_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(output_stream, pa_msgobject);
typedef struct playback_stream { typedef struct playback_stream {
output_stream parent; output_stream parent;
@ -114,6 +122,10 @@ typedef struct playback_stream {
size_t render_memblockq_length; size_t render_memblockq_length;
} playback_stream; } playback_stream;
PA_DECLARE_CLASS(playback_stream);
#define PLAYBACK_STREAM(o) (playback_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(playback_stream, output_stream);
typedef struct upload_stream { typedef struct upload_stream {
output_stream parent; output_stream parent;
@ -128,13 +140,17 @@ typedef struct upload_stream {
pa_proplist *proplist; pa_proplist *proplist;
} upload_stream; } upload_stream;
PA_DECLARE_CLASS(upload_stream);
#define UPLOAD_STREAM(o) (upload_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(upload_stream, output_stream);
struct connection { struct connection {
pa_msgobject parent; pa_msgobject parent;
pa_native_protocol *protocol;
pa_native_options *options;
pa_bool_t authorized:1; pa_bool_t authorized:1;
pa_bool_t is_local:1; pa_bool_t is_local:1;
uint32_t version; uint32_t version;
pa_protocol_native *protocol;
pa_client *client; pa_client *client;
pa_pstream *pstream; pa_pstream *pstream;
pa_pdispatch *pdispatch; pa_pdispatch *pdispatch;
@ -144,38 +160,21 @@ struct connection {
pa_time_event *auth_timeout_event; pa_time_event *auth_timeout_event;
}; };
PA_DECLARE_CLASS(record_stream);
#define RECORD_STREAM(o) (record_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(record_stream, pa_msgobject);
PA_DECLARE_CLASS(output_stream);
#define OUTPUT_STREAM(o) (output_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(output_stream, pa_msgobject);
PA_DECLARE_CLASS(playback_stream);
#define PLAYBACK_STREAM(o) (playback_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(playback_stream, output_stream);
PA_DECLARE_CLASS(upload_stream);
#define UPLOAD_STREAM(o) (upload_stream_cast(o))
static PA_DEFINE_CHECK_TYPE(upload_stream, output_stream);
PA_DECLARE_CLASS(connection); PA_DECLARE_CLASS(connection);
#define CONNECTION(o) (connection_cast(o)) #define CONNECTION(o) (connection_cast(o))
static PA_DEFINE_CHECK_TYPE(connection, pa_msgobject); static PA_DEFINE_CHECK_TYPE(connection, pa_msgobject);
struct pa_protocol_native { struct pa_native_protocol {
pa_module *module; PA_REFCNT_DECLARE;
pa_core *core; pa_core *core;
pa_bool_t public;
pa_socket_server *server;
pa_idxset *connections; pa_idxset *connections;
uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH];
pa_bool_t auth_cookie_in_property; pa_strlist *servers;
#ifdef HAVE_CREDS pa_hook servers_changed;
char *auth_group;
#endif pa_hashmap *extensions;
pa_ip_acl *auth_ip_acl;
}; };
enum { enum {
@ -264,6 +263,7 @@ static void command_set_stream_buffer_attr(pa_pdispatch *pd, uint32_t command, u
static void command_update_stream_sample_rate(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_update_stream_sample_rate(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
static void command_update_proplist(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_update_proplist(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
static void command_remove_proplist(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_remove_proplist(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
static void command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_ERROR] = NULL, [PA_COMMAND_ERROR] = NULL,
@ -354,6 +354,8 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST] = command_remove_proplist, [PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST] = command_remove_proplist,
[PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST] = command_remove_proplist, [PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST] = command_remove_proplist,
[PA_COMMAND_REMOVE_CLIENT_PROPLIST] = command_remove_proplist, [PA_COMMAND_REMOVE_CLIENT_PROPLIST] = command_remove_proplist,
[PA_COMMAND_EXTENSION] = command_extension
}; };
/* structure management */ /* structure management */
@ -556,7 +558,7 @@ static record_stream* record_stream_new(
pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p); pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p);
pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
data.driver = __FILE__; data.driver = __FILE__;
data.module = c->protocol->module; data.module = c->options->module;
data.client = c->client; data.client = c->client;
data.source = source; data.source = source;
data.direct_on_input = direct_on_input; data.direct_on_input = direct_on_input;
@ -901,7 +903,7 @@ static playback_stream* playback_stream_new(
pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p); pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p);
pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
data.driver = __FILE__; data.driver = __FILE__;
data.module = c->protocol->module; data.module = c->options->module;
data.client = c->client; data.client = c->client;
data.sink = sink; data.sink = sink;
pa_sink_input_new_data_set_sample_spec(&data, ss); pa_sink_input_new_data_set_sample_spec(&data, ss);
@ -1002,6 +1004,9 @@ static void connection_unlink(connection *c) {
if (!c->protocol) if (!c->protocol)
return; return;
if (c->options)
pa_native_options_unref(c->options);
while ((r = pa_idxset_first(c->record_streams, NULL))) while ((r = pa_idxset_first(c->record_streams, NULL)))
record_stream_unlink(r); record_stream_unlink(r);
@ -2007,17 +2012,17 @@ static void command_auth(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t
if ((creds = pa_pdispatch_creds(pd))) { if ((creds = pa_pdispatch_creds(pd))) {
if (creds->uid == getuid()) if (creds->uid == getuid())
success = TRUE; success = TRUE;
else if (c->protocol->auth_group) { else if (c->options->auth_group) {
int r; int r;
gid_t gid; gid_t gid;
if ((gid = pa_get_gid_of_group(c->protocol->auth_group)) == (gid_t) -1) if ((gid = pa_get_gid_of_group(c->options->auth_group)) == (gid_t) -1)
pa_log_warn("Failed to get GID of group '%s'", c->protocol->auth_group); pa_log_warn("Failed to get GID of group '%s'", c->options->auth_group);
else if (gid == creds->gid) else if (gid == creds->gid)
success = TRUE; success = TRUE;
if (!success) { if (!success) {
if ((r = pa_uid_in_group(creds->uid, c->protocol->auth_group)) < 0) if ((r = pa_uid_in_group(creds->uid, c->options->auth_group)) < 0)
pa_log_warn("Failed to check group membership."); pa_log_warn("Failed to check group membership.");
else if (r > 0) else if (r > 0)
success = TRUE; success = TRUE;
@ -2031,8 +2036,13 @@ static void command_auth(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t
} }
#endif #endif
if (!success && memcmp(c->protocol->auth_cookie, cookie, PA_NATIVE_COOKIE_LENGTH) == 0) if (!success && c->options->auth_cookie) {
success = TRUE; const uint8_t *ac;
if ((ac = pa_auth_cookie_read(c->options->auth_cookie, PA_NATIVE_COOKIE_LENGTH)))
if (memcmp(ac, cookie, PA_NATIVE_COOKIE_LENGTH) == 0)
success = TRUE;
}
if (!success) { if (!success) {
pa_log_warn("Denied access to client with invalid authorization data."); pa_log_warn("Denied access to client with invalid authorization data.");
@ -3830,6 +3840,43 @@ static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa
pa_pstream_send_simple_ack(c->pstream, tag); pa_pstream_send_simple_ack(c->pstream, tag);
} }
static void command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
connection *c = CONNECTION(userdata);
uint32_t idx = PA_INVALID_INDEX;
const char *name = NULL;
pa_module *m;
pa_native_protocol_ext_cb_t cb;
connection_assert_ref(c);
pa_assert(t);
if (pa_tagstruct_getu32(t, &idx) < 0 ||
pa_tagstruct_gets(t, &name) < 0) {
protocol_error(c);
return;
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || !*name || pa_utf8_valid(name), tag, PA_ERR_INVALID);
if (idx != PA_INVALID_INDEX)
m = pa_idxset_get_by_index(c->protocol->core->modules, idx);
else {
for (m = pa_idxset_first(c->protocol->core->modules, &idx); m; m = pa_idxset_next(c->protocol->core->modules, &idx))
if (strcmp(name, m->name) == 0)
break;
}
CHECK_VALIDITY(c->pstream, m, tag, PA_ERR_NOEXTENSION);
CHECK_VALIDITY(c->pstream, m->load_once || idx != PA_INVALID_INDEX, tag, PA_ERR_INVALID);
cb = (pa_native_protocol_ext_cb_t) pa_hashmap_get(c->protocol->extensions, m);
CHECK_VALIDITY(c->pstream, m, tag, PA_ERR_NOEXTENSION);
cb(c->protocol, m, c->pstream, tag, t);
}
/*** pstream callbacks ***/ /*** pstream callbacks ***/
static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_creds *creds, void *userdata) { static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_creds *creds, void *userdata) {
@ -3951,7 +3998,7 @@ static void client_kill_cb(pa_client *c) {
connection_unlink(CONNECTION(c->userdata)); connection_unlink(CONNECTION(c->userdata));
} }
/*** socket server callbacks ***/ /*** module entry points ***/
static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
connection *c = CONNECTION(userdata); connection *c = CONNECTION(userdata);
@ -3965,13 +4012,13 @@ static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timev
connection_unlink(c); connection_unlink(c);
} }
static void on_connection(PA_GCC_UNUSED pa_socket_server*s, pa_iochannel *io, void *userdata) { void pa_native_protocol_connect(pa_native_protocol *p, pa_iochannel *io, pa_native_options *o) {
pa_protocol_native *p = userdata;
connection *c; connection *c;
char cname[256], pname[128]; char cname[256], pname[128];
pa_assert(io);
pa_assert(p); pa_assert(p);
pa_assert(io);
pa_assert(o);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@ -3982,10 +4029,19 @@ static void on_connection(PA_GCC_UNUSED pa_socket_server*s, pa_iochannel *io, vo
c = pa_msgobject_new(connection); c = pa_msgobject_new(connection);
c->parent.parent.free = connection_free; c->parent.parent.free = connection_free;
c->parent.process_msg = connection_process_msg; c->parent.process_msg = connection_process_msg;
c->protocol = p;
c->options = pa_native_options_ref(o);
c->authorized = FALSE;
c->authorized = p->public; if (o->auth_anonymous) {
pa_log_info("Client authenticated anonymously.");
c->authorized = TRUE;
}
if (!c->authorized &&
o->auth_ip_acl &&
pa_ip_acl_check(o->auth_ip_acl, pa_iochannel_get_recv_fd(io)) > 0) {
if (!c->authorized && p->auth_ip_acl && pa_ip_acl_check(p->auth_ip_acl, pa_iochannel_get_recv_fd(io)) > 0) {
pa_log_info("Client authenticated by IP ACL."); pa_log_info("Client authenticated by IP ACL.");
c->authorized = TRUE; c->authorized = TRUE;
} }
@ -4000,17 +4056,16 @@ static void on_connection(PA_GCC_UNUSED pa_socket_server*s, pa_iochannel *io, vo
c->is_local = pa_iochannel_socket_is_local(io); c->is_local = pa_iochannel_socket_is_local(io);
c->version = 8; c->version = 8;
c->protocol = p;
pa_iochannel_socket_peer_to_string(io, pname, sizeof(pname)); pa_iochannel_socket_peer_to_string(io, pname, sizeof(pname));
pa_snprintf(cname, sizeof(cname), "Native client (%s)", pname); pa_snprintf(cname, sizeof(cname), "Native client (%s)", pname);
c->client = pa_client_new(p->core, __FILE__, cname); c->client = pa_client_new(p->core, __FILE__, cname);
pa_proplist_sets(c->client->proplist, "native-protocol.peer", pname); pa_proplist_sets(c->client->proplist, "native-protocol.peer", pname);
c->client->kill = client_kill_cb; c->client->kill = client_kill_cb;
c->client->userdata = c; c->client->userdata = c;
c->client->module = p->module; c->client->module = o->module;
c->pstream = pa_pstream_new(p->core->mainloop, io, p->core->mempool); c->pstream = pa_pstream_new(p->core->mainloop, io, p->core->mempool);
pa_pstream_set_recieve_packet_callback(c->pstream, pstream_packet_callback, c); pa_pstream_set_recieve_packet_callback(c->pstream, pstream_packet_callback, c);
pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c); pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c);
pa_pstream_set_die_callback(c->pstream, pstream_die_callback, c); pa_pstream_set_die_callback(c->pstream, pstream_die_callback, c);
@ -4034,163 +4089,228 @@ static void on_connection(PA_GCC_UNUSED pa_socket_server*s, pa_iochannel *io, vo
#endif #endif
} }
/*** module entry points ***/ void pa_native_protocol_disconnect(pa_native_protocol *p, pa_module *m) {
connection *c;
void *state = NULL;
static int load_key(pa_protocol_native*p, const char*fn) {
pa_assert(p); pa_assert(p);
pa_assert(m);
p->auth_cookie_in_property = FALSE; while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
if (c->options->module == m)
if (!fn && pa_authkey_prop_get(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME, p->auth_cookie, sizeof(p->auth_cookie)) >= 0) { connection_unlink(c);
pa_log_info("using already loaded auth cookie.");
pa_authkey_prop_ref(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
p->auth_cookie_in_property = TRUE;
return 0;
}
if (!fn)
fn = PA_NATIVE_COOKIE_FILE;
if (pa_authkey_load_auto(fn, p->auth_cookie, sizeof(p->auth_cookie)) < 0)
return -1;
pa_log_info("loading cookie from disk.");
if (pa_authkey_prop_put(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME, p->auth_cookie, sizeof(p->auth_cookie)) >= 0)
p->auth_cookie_in_property = TRUE;
return 0;
} }
static pa_protocol_native* protocol_new_internal(pa_core *c, pa_module *m, pa_modargs *ma) { static pa_native_protocol* native_protocol_new(pa_core *c) {
pa_protocol_native *p; pa_native_protocol *p;
pa_bool_t public = FALSE;
const char *acl;
pa_assert(c); pa_assert(c);
pa_assert(ma);
if (pa_modargs_get_value_boolean(ma, "auth-anonymous", &public) < 0) { p = pa_xnew(pa_native_protocol, 1);
pa_log("auth-anonymous= expects a boolean argument."); PA_REFCNT_INIT(p);
return NULL;
}
p = pa_xnew(pa_protocol_native, 1);
p->core = c; p->core = c;
p->module = m;
p->public = public;
p->server = NULL;
p->auth_ip_acl = NULL;
#ifdef HAVE_CREDS
{
pa_bool_t a = TRUE;
if (pa_modargs_get_value_boolean(ma, "auth-group-enabled", &a) < 0) {
pa_log("auth-group-enabled= expects a boolean argument.");
return NULL;
}
p->auth_group = a ? pa_xstrdup(pa_modargs_get_value(ma, "auth-group", pa_in_system_mode() ? PA_ACCESS_GROUP : NULL)) : NULL;
if (p->auth_group)
pa_log_info("Allowing access to group '%s'.", p->auth_group);
}
#endif
if ((acl = pa_modargs_get_value(ma, "auth-ip-acl", NULL))) {
if (!(p->auth_ip_acl = pa_ip_acl_new(acl))) {
pa_log("Failed to parse IP ACL '%s'", acl);
goto fail;
}
}
if (load_key(p, pa_modargs_get_value(ma, "cookie", NULL)) < 0)
goto fail;
p->connections = pa_idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
return p; p->servers = NULL;
pa_hook_init(&p->servers_changed, p);
fail: pa_assert_se(pa_shared_set(c, "native-protocol", p) >= 0);
#ifdef HAVE_CREDS
pa_xfree(p->auth_group);
#endif
if (p->auth_ip_acl)
pa_ip_acl_free(p->auth_ip_acl);
pa_xfree(p);
return NULL;
}
pa_protocol_native* pa_protocol_native_new(pa_core *core, pa_socket_server *server, pa_module *m, pa_modargs *ma) {
char t[256];
pa_protocol_native *p;
if (!(p = protocol_new_internal(core, m, ma)))
return NULL;
p->server = pa_socket_server_ref(server);
pa_socket_server_set_callback(p->server, on_connection, p);
if (pa_socket_server_get_address(p->server, t, sizeof(t))) {
pa_strlist *l;
l = pa_property_get(core, PA_NATIVE_SERVER_PROPERTY_NAME);
l = pa_strlist_prepend(l, t);
pa_property_replace(core, PA_NATIVE_SERVER_PROPERTY_NAME, l);
}
return p; return p;
} }
void pa_protocol_native_free(pa_protocol_native *p) { pa_native_protocol* pa_native_protocol_get(pa_core *c) {
pa_native_protocol *p;
if ((p = pa_shared_get(c, "native-protocol")))
return pa_native_protocol_ref(p);
return native_protocol_new(c);
}
pa_native_protocol* pa_native_protocol_ref(pa_native_protocol *p) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
PA_REFCNT_INC(p);
return p;
}
void pa_native_protocol_unref(pa_native_protocol *p) {
connection *c; connection *c;
pa_assert(p); pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
if (PA_REFCNT_DEC(p) > 0)
return;
while ((c = pa_idxset_first(p->connections, NULL))) while ((c = pa_idxset_first(p->connections, NULL)))
connection_unlink(c); connection_unlink(c);
pa_idxset_free(p->connections, NULL, NULL); pa_idxset_free(p->connections, NULL, NULL);
if (p->server) { pa_strlist_free(p->servers);
char t[256]; pa_hook_done(&p->servers_changed);
if (pa_socket_server_get_address(p->server, t, sizeof(t))) { pa_assert_se(pa_shared_remove(p->core, "native-protocol") >= 0);
pa_strlist *l;
l = pa_property_get(p->core, PA_NATIVE_SERVER_PROPERTY_NAME);
l = pa_strlist_remove(l, t);
if (l)
pa_property_replace(p->core, PA_NATIVE_SERVER_PROPERTY_NAME, l);
else
pa_property_remove(p->core, PA_NATIVE_SERVER_PROPERTY_NAME);
}
pa_socket_server_unref(p->server);
}
if (p->auth_cookie_in_property)
pa_authkey_prop_unref(p->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
if (p->auth_ip_acl)
pa_ip_acl_free(p->auth_ip_acl);
#ifdef HAVE_CREDS
pa_xfree(p->auth_group);
#endif
pa_xfree(p); pa_xfree(p);
} }
pa_protocol_native* pa_protocol_native_new_iochannel( void pa_native_protocol_add_server_string(pa_native_protocol *p, const char *name) {
pa_core*core, pa_assert(p);
pa_iochannel *io, pa_assert(PA_REFCNT_VALUE(p) >= 1);
pa_module *m, pa_assert(name);
pa_modargs *ma) {
pa_protocol_native *p; p->servers = pa_strlist_prepend(p->servers, name);
if (!(p = protocol_new_internal(core, m, ma))) pa_hook_fire(&p->servers_changed, p->servers);
return NULL; }
on_connection(NULL, io, p); void pa_native_protocol_remove_server_string(pa_native_protocol *p, const char *name) {
pa_assert(p);
return p; pa_assert(PA_REFCNT_VALUE(p) >= 1);
pa_assert(name);
p->servers = pa_strlist_remove(p->servers, name);
pa_hook_fire(&p->servers_changed, p->servers);
}
pa_hook *pa_native_protocol_servers_changed(pa_native_protocol *p) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
return &p->servers_changed;
}
pa_strlist *pa_native_protocol_servers(pa_native_protocol *p) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
return p->servers;
}
int pa_native_protocol_install_ext(pa_native_protocol *p, pa_module *m, pa_native_protocol_ext_cb_t cb) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
pa_assert(m);
pa_assert(cb);
pa_assert(!pa_hashmap_get(p->extensions, m));
pa_assert_se(pa_hashmap_put(p->extensions, m, (void*) cb) == 0);
return 0;
}
void pa_native_protocol_remove_ext(pa_native_protocol *p, pa_module *m) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
pa_assert(m);
pa_assert_se(pa_hashmap_remove(p->extensions, m));
}
pa_native_options* pa_native_options_new(void) {
pa_native_options *o;
o = pa_xnew0(pa_native_options, 1);
PA_REFCNT_INIT(o);
return o;
}
pa_native_options* pa_native_options_ref(pa_native_options *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
PA_REFCNT_INC(o);
return o;
}
void pa_native_options_unref(pa_native_options *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
if (PA_REFCNT_DEC(o) > 0)
return;
pa_xfree(o->auth_group);
if (o->auth_ip_acl)
pa_ip_acl_free(o->auth_ip_acl);
if (o->auth_cookie)
pa_auth_cookie_unref(o->auth_cookie);
pa_xfree(o);
}
int pa_native_options_parse(pa_native_options *o, pa_core *c, pa_modargs *ma) {
pa_bool_t enabled;
const char *acl;
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
pa_assert(ma);
if (pa_modargs_get_value_boolean(ma, "auth-anonymous", &o->auth_anonymous) < 0) {
pa_log("auth-anonymous= expects a boolean argument.");
return -1;
}
enabled = TRUE;
if (pa_modargs_get_value_boolean(ma, "auth-group-enabled", &enabled) < 0) {
pa_log("auth-group-enabled= expects a boolean argument.");
return -1;
}
pa_xfree(o->auth_group);
o->auth_group = enabled ? pa_xstrdup(pa_modargs_get_value(ma, "auth-group", pa_in_system_mode() ? PA_ACCESS_GROUP : NULL)) : NULL;
#ifndef HAVE_CREDS
if (o->auth_group)
pa_log_warn("Authentication group configured, but not available on local system. Ignoring.");
#endif
if ((acl = pa_modargs_get_value(ma, "auth-ip-acl", NULL))) {
pa_ip_acl *ipa;
if (!(o->auth_ip_acl = pa_ip_acl_new(acl))) {
pa_log("Failed to parse IP ACL '%s'", acl);
return -1;
}
if (o->auth_ip_acl)
pa_ip_acl_free(o->auth_ip_acl);
o->auth_ip_acl = ipa;
}
enabled = TRUE;
if (pa_modargs_get_value_boolean(ma, "auth-cookie-enabled", &enabled) < 0) {
pa_log("auth-cookie-enabled= expects a boolean argument.");
return -1;
}
if (o->auth_cookie)
pa_auth_cookie_unref(o->auth_cookie);
if (enabled) {
const char *cn;
/* The new name for this is 'auth-cookie', for compat reasons
* we check the old name too */
if (!(cn = pa_modargs_get_value(ma, "auth-cookie", NULL)))
if (!(cn = pa_modargs_get_value(ma, "cookie", NULL)))
cn = PA_NATIVE_COOKIE_FILE;
if (!(o->auth_cookie = pa_auth_cookie_get(c, cn, PA_NATIVE_COOKIE_LENGTH)))
return -1;
} else
o->auth_cookie = NULL;
return 0;
} }

View file

@ -24,15 +24,49 @@
***/ ***/
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/socket-server.h> #include <pulsecore/ipacl.h>
#include <pulsecore/auth-cookie.h>
#include <pulsecore/iochannel.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/strlist.h>
#include <pulsecore/hook-list.h>
#include <pulsecore/pstream.h>
#include <pulsecore/tagstruct.h>
typedef struct pa_protocol_native pa_protocol_native; typedef struct pa_native_protocol pa_native_protocol;
pa_protocol_native* pa_protocol_native_new(pa_core*core, pa_socket_server *server, pa_module *m, pa_modargs *ma); typedef struct pa_native_options {
void pa_protocol_native_free(pa_protocol_native *n); PA_REFCNT_DECLARE;
pa_protocol_native* pa_protocol_native_new_iochannel(pa_core*core, pa_iochannel *io, pa_module *m, pa_modargs *ma); pa_module *module;
pa_bool_t auth_anonymous;
char *auth_group;
pa_ip_acl *auth_ip_acl;
pa_auth_cookie *auth_cookie;
} pa_native_options;
pa_native_protocol* pa_native_protocol_get(pa_core *core);
pa_native_protocol* pa_native_protocol_ref(pa_native_protocol *p);
void pa_native_protocol_unref(pa_native_protocol *p);
void pa_native_protocol_connect(pa_native_protocol *p, pa_iochannel *io, pa_native_options *a);
void pa_native_protocol_disconnect(pa_native_protocol *p, pa_module *m);
void pa_native_protocol_add_server_string(pa_native_protocol *p, const char *name);
void pa_native_protocol_remove_server_string(pa_native_protocol *p, const char *name);
pa_hook *pa_native_protocol_servers_changed(pa_native_protocol *p);
pa_strlist *pa_native_protocol_servers(pa_native_protocol *p);
typedef void (*pa_native_protocol_ext_cb_t)(pa_native_protocol *p, pa_module *m, pa_pstream *ps, uint32_t tag, pa_tagstruct *t);
int pa_native_protocol_install_ext(pa_native_protocol *p, pa_module *m, pa_native_protocol_ext_cb_t cb);
void pa_native_protocol_remove_ext(pa_native_protocol *p, pa_module *m);
pa_native_options* pa_native_options_new(void);
pa_native_options* pa_native_options_ref(pa_native_options *o);
void pa_native_options_unref(pa_native_options *o);
int pa_native_options_parse(pa_native_options *o, pa_core *c, pa_modargs *ma);
#endif #endif

View file

@ -42,6 +42,7 @@
#include <pulsecore/atomic.h> #include <pulsecore/atomic.h>
#include <pulsecore/thread-mq.h> #include <pulsecore/thread-mq.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/shared.h>
#include "protocol-simple.h" #include "protocol-simple.h"
@ -50,7 +51,8 @@
typedef struct connection { typedef struct connection {
pa_msgobject parent; pa_msgobject parent;
pa_protocol_simple *protocol; pa_simple_protocol *protocol;
pa_simple_options *options;
pa_iochannel *io; pa_iochannel *io;
pa_sink_input *sink_input; pa_sink_input *sink_input;
pa_source_output *source_output; pa_source_output *source_output;
@ -71,20 +73,11 @@ PA_DECLARE_CLASS(connection);
#define CONNECTION(o) (connection_cast(o)) #define CONNECTION(o) (connection_cast(o))
static PA_DEFINE_CHECK_TYPE(connection, pa_msgobject); static PA_DEFINE_CHECK_TYPE(connection, pa_msgobject);
struct pa_protocol_simple { struct pa_simple_protocol {
pa_module *module; PA_REFCNT_DECLARE;
pa_core *core; pa_core *core;
pa_socket_server*server;
pa_idxset *connections; pa_idxset *connections;
enum {
RECORD = 1,
PLAYBACK = 2,
DUPLEX = 3
} mode;
pa_sample_spec sample_spec;
char *source_name, *sink_name;
}; };
enum { enum {
@ -98,7 +91,6 @@ enum {
CONNECTION_MESSAGE_UNLINK_CONNECTION /* Please drop a aconnection now */ CONNECTION_MESSAGE_UNLINK_CONNECTION /* Please drop a aconnection now */
}; };
#define PLAYBACK_BUFFER_SECONDS (.5) #define PLAYBACK_BUFFER_SECONDS (.5)
#define PLAYBACK_BUFFER_FRAGMENTS (10) #define PLAYBACK_BUFFER_FRAGMENTS (10)
#define RECORD_BUFFER_SECONDS (5) #define RECORD_BUFFER_SECONDS (5)
@ -111,6 +103,11 @@ static void connection_unlink(connection *c) {
if (!c->protocol) if (!c->protocol)
return; return;
if (c->options) {
pa_simple_options_unref(c->options);
c->options = NULL;
}
if (c->sink_input) { if (c->sink_input) {
pa_sink_input_unlink(c->sink_input); pa_sink_input_unlink(c->sink_input);
pa_sink_input_unref(c->sink_input); pa_sink_input_unref(c->sink_input);
@ -477,14 +474,13 @@ static void io_callback(pa_iochannel*io, void *userdata) {
/*** socket_server callbacks ***/ /*** socket_server callbacks ***/
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) { void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simple_options *o) {
pa_protocol_simple *p = userdata;
connection *c = NULL; connection *c = NULL;
char cname[256], pname[128]; char cname[256], pname[128];
pa_assert(s);
pa_assert(io);
pa_assert(p); pa_assert(p);
pa_assert(io);
pa_assert(o);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@ -500,6 +496,7 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
c->source_output = NULL; c->source_output = NULL;
c->input_memblockq = c->output_memblockq = NULL; c->input_memblockq = c->output_memblockq = NULL;
c->protocol = p; c->protocol = p;
c->options = pa_simple_options_ref(o);
c->playback.current_memblock = NULL; c->playback.current_memblock = NULL;
c->playback.memblock_index = 0; c->playback.memblock_index = 0;
c->dead = FALSE; c->dead = FALSE;
@ -510,27 +507,27 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_snprintf(cname, sizeof(cname), "Simple client (%s)", pname); pa_snprintf(cname, sizeof(cname), "Simple client (%s)", pname);
pa_assert_se(c->client = pa_client_new(p->core, __FILE__, cname)); pa_assert_se(c->client = pa_client_new(p->core, __FILE__, cname));
pa_proplist_sets(c->client->proplist, "simple-protocol.peer", pname); pa_proplist_sets(c->client->proplist, "simple-protocol.peer", pname);
c->client->module = p->module; c->client->module = o->module;
c->client->kill = client_kill_cb; c->client->kill = client_kill_cb;
c->client->userdata = c; c->client->userdata = c;
if (p->mode & PLAYBACK) { if (o->playback) {
pa_sink_input_new_data data; pa_sink_input_new_data data;
size_t l; size_t l;
pa_sink *sink; pa_sink *sink;
if (!(sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, TRUE))) { if (!(sink = pa_namereg_get(c->protocol->core, o->default_sink, PA_NAMEREG_SINK, TRUE))) {
pa_log("Failed to get sink."); pa_log("Failed to get sink.");
goto fail; goto fail;
} }
pa_sink_input_new_data_init(&data); pa_sink_input_new_data_init(&data);
data.driver = __FILE__; data.driver = __FILE__;
data.module = p->module; data.module = o->module;
data.client = c->client; data.client = c->client;
data.sink = sink; data.sink = sink;
pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
pa_sink_input_new_data_set_sample_spec(&data, &p->sample_spec); pa_sink_input_new_data_set_sample_spec(&data, &o->sample_spec);
c->sink_input = pa_sink_input_new(p->core, &data, 0); c->sink_input = pa_sink_input_new(p->core, &data, 0);
pa_sink_input_new_data_done(&data); pa_sink_input_new_data_done(&data);
@ -549,12 +546,12 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_sink_input_set_requested_latency(c->sink_input, DEFAULT_SINK_LATENCY); pa_sink_input_set_requested_latency(c->sink_input, DEFAULT_SINK_LATENCY);
l = (size_t) (pa_bytes_per_second(&p->sample_spec)*PLAYBACK_BUFFER_SECONDS); l = (size_t) (pa_bytes_per_second(&o->sample_spec)*PLAYBACK_BUFFER_SECONDS);
c->input_memblockq = pa_memblockq_new( c->input_memblockq = pa_memblockq_new(
0, 0,
l, l,
l, l,
pa_frame_size(&p->sample_spec), pa_frame_size(&o->sample_spec),
(size_t) -1, (size_t) -1,
l/PLAYBACK_BUFFER_FRAGMENTS, l/PLAYBACK_BUFFER_FRAGMENTS,
0, 0,
@ -566,23 +563,23 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_sink_input_put(c->sink_input); pa_sink_input_put(c->sink_input);
} }
if (p->mode & RECORD) { if (o->record) {
pa_source_output_new_data data; pa_source_output_new_data data;
size_t l; size_t l;
pa_source *source; pa_source *source;
if (!(source = pa_namereg_get(c->protocol->core, c->protocol->source_name, PA_NAMEREG_SOURCE, TRUE))) { if (!(source = pa_namereg_get(c->protocol->core, o->default_source, PA_NAMEREG_SOURCE, TRUE))) {
pa_log("Failed to get source."); pa_log("Failed to get source.");
goto fail; goto fail;
} }
pa_source_output_new_data_init(&data); pa_source_output_new_data_init(&data);
data.driver = __FILE__; data.driver = __FILE__;
data.module = p->module; data.module = o->module;
data.client = c->client; data.client = c->client;
data.source = source; data.source = source;
pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
pa_source_output_new_data_set_sample_spec(&data, &p->sample_spec); pa_source_output_new_data_set_sample_spec(&data, &o->sample_spec);
c->source_output = pa_source_output_new(p->core, &data, 0); c->source_output = pa_source_output_new(p->core, &data, 0);
pa_source_output_new_data_done(&data); pa_source_output_new_data_done(&data);
@ -598,12 +595,12 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_source_output_set_requested_latency(c->source_output, DEFAULT_SOURCE_LATENCY); pa_source_output_set_requested_latency(c->source_output, DEFAULT_SOURCE_LATENCY);
l = (size_t) (pa_bytes_per_second(&p->sample_spec)*RECORD_BUFFER_SECONDS); l = (size_t) (pa_bytes_per_second(&o->sample_spec)*RECORD_BUFFER_SECONDS);
c->output_memblockq = pa_memblockq_new( c->output_memblockq = pa_memblockq_new(
0, 0,
l, l,
0, 0,
pa_frame_size(&p->sample_spec), pa_frame_size(&o->sample_spec),
1, 1,
0, 0,
0, 0,
@ -623,74 +620,137 @@ fail:
connection_unlink(c); connection_unlink(c);
} }
pa_protocol_simple* pa_protocol_simple_new(pa_core *core, pa_socket_server *server, pa_module *m, pa_modargs *ma) { void pa_simple_protocol_disconnect(pa_simple_protocol *p, pa_module *m) {
pa_protocol_simple* p = NULL; connection *c;
pa_bool_t enable; void *state = NULL;
pa_assert(core); pa_assert(p);
pa_assert(server);
pa_assert(m); pa_assert(m);
pa_assert(ma);
p = pa_xnew0(pa_protocol_simple, 1); while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
p->module = m; if (c->options->module == m)
p->core = core; connection_unlink(c);
p->server = pa_socket_server_ref(server);
p->connections = pa_idxset_new(NULL, NULL);
p->sample_spec = core->default_sample_spec;
if (pa_modargs_get_sample_spec(ma, &p->sample_spec) < 0) {
pa_log("Failed to parse sample type specification.");
goto fail;
}
p->source_name = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
p->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
enable = FALSE;
if (pa_modargs_get_value_boolean(ma, "record", &enable) < 0) {
pa_log("record= expects a numeric argument.");
goto fail;
}
p->mode = enable ? RECORD : 0;
enable = TRUE;
if (pa_modargs_get_value_boolean(ma, "playback", &enable) < 0) {
pa_log("playback= expects a numeric argument.");
goto fail;
}
p->mode |= enable ? PLAYBACK : 0;
if ((p->mode & (RECORD|PLAYBACK)) == 0) {
pa_log("neither playback nor recording enabled for protocol.");
goto fail;
}
pa_socket_server_set_callback(p->server, on_connection, p);
return p;
fail:
if (p)
pa_protocol_simple_free(p);
return NULL;
} }
static pa_simple_protocol* simple_protocol_new(pa_core *c) {
pa_simple_protocol *p;
void pa_protocol_simple_free(pa_protocol_simple *p) { pa_assert(c);
p = pa_xnew(pa_simple_protocol, 1);
PA_REFCNT_INIT(p);
p->core = c;
p->connections = pa_idxset_new(NULL, NULL);
pa_assert_se(pa_shared_set(c, "simple-protocol", p) >= 0);
return p;
}
pa_simple_protocol* pa_simple_protocol_get(pa_core *c) {
pa_simple_protocol *p;
if ((p = pa_shared_get(c, "simple-protocol")))
return pa_simple_protocol_ref(p);
return simple_protocol_new(c);
}
pa_simple_protocol* pa_simple_protocol_ref(pa_simple_protocol *p) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
PA_REFCNT_INC(p);
return p;
}
void pa_simple_protocol_unref(pa_simple_protocol *p) {
connection *c; connection *c;
pa_assert(p); pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
if (p->connections) { if (PA_REFCNT_DEC(p) > 0)
while((c = pa_idxset_first(p->connections, NULL))) return;
connection_unlink(c);
pa_idxset_free(p->connections, NULL, NULL); while ((c = pa_idxset_first(p->connections, NULL)))
} connection_unlink(c);
if (p->server) pa_idxset_free(p->connections, NULL, NULL);
pa_socket_server_unref(p->server);
pa_assert_se(pa_shared_remove(p->core, "simple-protocol") >= 0);
pa_xfree(p); pa_xfree(p);
} }
pa_simple_options* pa_simple_options_new(void) {
pa_simple_options *o;
o = pa_xnew0(pa_simple_options, 1);
PA_REFCNT_INIT(o);
return o;
}
pa_simple_options* pa_simple_options_ref(pa_simple_options *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
PA_REFCNT_INC(o);
return o;
}
void pa_simple_options_unref(pa_simple_options *o) {
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
if (PA_REFCNT_DEC(o) > 0)
return;
pa_xfree(o->default_sink);
pa_xfree(o->default_source);
pa_xfree(o);
}
int pa_simple_options_parse(pa_simple_options *o, pa_core *c, pa_modargs *ma) {
pa_bool_t enabled;
pa_assert(o);
pa_assert(PA_REFCNT_VALUE(o) >= 1);
pa_assert(ma);
o->sample_spec = c->default_sample_spec;
if (pa_modargs_get_sample_spec_and_channel_map(ma, &o->sample_spec, &o->channel_map, PA_CHANNEL_MAP_DEFAULT) < 0) {
pa_log("Failed to parse sample type specification.");
return -1;
}
pa_xfree(o->default_source);
o->default_source = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
pa_xfree(o->default_sink);
o->default_sink = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
enabled = FALSE;
if (pa_modargs_get_value_boolean(ma, "record", &enabled) < 0) {
pa_log("record= expects a boolean argument.");
return -1;
}
o->record = enabled;
enabled = TRUE;
if (pa_modargs_get_value_boolean(ma, "playback", &enabled) < 0) {
pa_log("playback= expects a boolean argument.");
return -1;
}
o->playback = enabled;
if (!o->playback && !o->record) {
pa_log("neither playback nor recording enabled for protocol.");
return -1;
}
return 0;
}

View file

@ -27,9 +27,31 @@
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
typedef struct pa_protocol_simple pa_protocol_simple; typedef struct pa_simple_protocol pa_simple_protocol;
pa_protocol_simple* pa_protocol_simple_new(pa_core *core, pa_socket_server *server, pa_module *m, pa_modargs *ma); typedef struct pa_simple_options {
void pa_protocol_simple_free(pa_protocol_simple *n); PA_REFCNT_DECLARE;
pa_module *module;
char *default_sink, *default_source;
pa_sample_spec sample_spec;
pa_channel_map channel_map;
pa_bool_t record:1;
pa_bool_t playback:1;
} pa_simple_options;
pa_simple_protocol* pa_simple_protocol_get(pa_core*core);
pa_simple_protocol* pa_simple_protocol_ref(pa_simple_protocol *p);
void pa_simple_protocol_unref(pa_simple_protocol *p);
void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simple_options *o);
void pa_simple_protocol_disconnect(pa_simple_protocol *p, pa_module *m);
pa_simple_options* pa_simple_options_new(void);
pa_simple_options* pa_simple_options_ref(pa_simple_options *o);
void pa_simple_options_unref(pa_simple_options *o);
int pa_simple_options_parse(pa_simple_options *o, pa_core *c, pa_modargs *ma);
#endif #endif

View file

@ -37,7 +37,7 @@
#include "random.h" #include "random.h"
static int has_whined = 0; static pa_bool_t has_whined = TRUE;
static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL }; static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL };
@ -77,6 +77,8 @@ static int random_proper(void *ret_data, size_t length) {
if (ret == 0) if (ret == 0)
break; break;
device++;
} }
return ret; return ret;
@ -87,9 +89,11 @@ void pa_random_seed(void) {
unsigned int seed; unsigned int seed;
if (random_proper(&seed, sizeof(unsigned int)) < 0) { if (random_proper(&seed, sizeof(unsigned int)) < 0) {
if (!has_whined)
if (!has_whined) {
pa_log_warn("Failed to get proper entropy. Falling back to seeding with current time."); pa_log_warn("Failed to get proper entropy. Falling back to seeding with current time.");
has_whined = 1; has_whined = TRUE;
}
seed = (unsigned int) time(NULL); seed = (unsigned int) time(NULL);
} }
@ -107,9 +111,10 @@ void pa_random(void *ret_data, size_t length) {
if (random_proper(ret_data, length) >= 0) if (random_proper(ret_data, length) >= 0)
return; return;
if (!has_whined) if (!has_whined) {
pa_log_warn("Failed to get proper entropy. Falling back to unsecure pseudo RNG."); pa_log_warn("Failed to get proper entropy. Falling back to unsecure pseudo RNG.");
has_whined = 1; has_whined = TRUE;
}
for (p = ret_data, l = length; l > 0; p++, l--) for (p = ret_data, l = length; l > 0; p++, l--)
*p = (uint8_t) rand(); *p = (uint8_t) rand();

View file

@ -27,112 +27,112 @@
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include "props.h" #include "shared.h"
typedef struct pa_property { typedef struct pa_shared {
char *name; /* Points to memory allocated by the property subsystem */ char *name; /* Points to memory allocated by the shared property system */
void *data; /* Points to memory maintained by the caller */ void *data; /* Points to memory maintained by the caller */
} pa_property; } pa_shared;
/* Allocate a new property object */ /* Allocate a new shared property object */
static pa_property* property_new(const char *name, void *data) { static pa_shared* shared_new(const char *name, void *data) {
pa_property* p; pa_shared* p;
pa_assert(name); pa_assert(name);
pa_assert(data); pa_assert(data);
p = pa_xnew(pa_property, 1); p = pa_xnew(pa_shared, 1);
p->name = pa_xstrdup(name); p->name = pa_xstrdup(name);
p->data = data; p->data = data;
return p; return p;
} }
/* Free a property object */ /* Free a shared property object */
static void property_free(pa_property *p) { static void shared_free(pa_shared *p) {
pa_assert(p); pa_assert(p);
pa_xfree(p->name); pa_xfree(p->name);
pa_xfree(p); pa_xfree(p);
} }
void* pa_property_get(pa_core *c, const char *name) { void* pa_shared_get(pa_core *c, const char *name) {
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(c->properties); pa_assert(c->shared);
if (!(p = pa_hashmap_get(c->properties, name))) if (!(p = pa_hashmap_get(c->shared, name)))
return NULL; return NULL;
return p->data; return p->data;
} }
int pa_property_set(pa_core *c, const char *name, void *data) { int pa_shared_set(pa_core *c, const char *name, void *data) {
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(data); pa_assert(data);
pa_assert(c->properties); pa_assert(c->shared);
if (pa_hashmap_get(c->properties, name)) if (pa_hashmap_get(c->shared, name))
return -1; return -1;
p = property_new(name, data); p = shared_new(name, data);
pa_hashmap_put(c->properties, p->name, p); pa_hashmap_put(c->shared, p->name, p);
return 0; return 0;
} }
int pa_property_remove(pa_core *c, const char *name) { int pa_shared_remove(pa_core *c, const char *name) {
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(c->properties); pa_assert(c->shared);
if (!(p = pa_hashmap_remove(c->properties, name))) if (!(p = pa_hashmap_remove(c->shared, name)))
return -1; return -1;
property_free(p); shared_free(p);
return 0; return 0;
} }
void pa_property_init(pa_core *c) { void pa_shared_init(pa_core *c) {
pa_assert(c); pa_assert(c);
c->properties = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
} }
void pa_property_cleanup(pa_core *c) { void pa_shared_cleanup(pa_core *c) {
pa_assert(c); pa_assert(c);
if (!c->properties) if (!c->shared)
return; return;
pa_assert(!pa_hashmap_size(c->properties)); pa_assert(pa_hashmap_isempty(c->shared));
pa_hashmap_free(c->properties, NULL, NULL); pa_hashmap_free(c->shared, NULL, NULL);
c->properties = NULL; c->shared = NULL;
} }
void pa_property_dump(pa_core *c, pa_strbuf *s) { void pa_shared_dump(pa_core *c, pa_strbuf *s) {
void *state = NULL; void *state = NULL;
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(s); pa_assert(s);
while ((p = pa_hashmap_iterate(c->properties, &state, NULL))) while ((p = pa_hashmap_iterate(c->shared, &state, NULL)))
pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data); pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data);
} }
int pa_property_replace(pa_core *c, const char *name, void *data) { int pa_shared_replace(pa_core *c, const char *name, void *data) {
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_property_remove(c, name); pa_shared_remove(c, name);
return pa_property_set(c, name, data); return pa_shared_set(c, name, data);
} }

View file

@ -1,5 +1,5 @@
#ifndef foopropshfoo #ifndef foosharedshfoo
#define foopropshfoo #define foosharedshfoo
/*** /***
This file is part of PulseAudio. This file is part of PulseAudio.
@ -25,34 +25,37 @@
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/strbuf.h> #include <pulsecore/strbuf.h>
/* The property subsystem is to be used to share data between /* The shared property subsystem is to be used to share data between
* modules. Consider them to be kind of "global" variables for a * modules. Consider them to be kind of "global" variables for a
* core. Why not use the hashmap functions directly? The hashmap * core. Why not use the hashmap functions directly? The hashmap
* functions copy neither the key nor value, while this property * functions copy neither the key nor value, while this property
* system copies the key. Users of this system have to think about * system copies the key. Users of this system have to think about
* reference counting themselves. */ * reference counting themselves. */
/* Return a pointer to the value of the specified property. */ /* Note: please don't confuse this with the proplist framework in
void* pa_property_get(pa_core *c, const char *name); * pulse/proplist.[ch]! */
/* Set the property 'name' to 'data'. This function fails in case a /* Return a pointer to the value of the specified shared property. */
* property by this name already exists. The property data is not void* pa_shared_get(pa_core *c, const char *name);
* copied or reference counted. This is the caller's job. */
int pa_property_set(pa_core *c, const char *name, void *data);
/* Remove the specified property. Return non-zero on failure */ /* Set the shared property 'name' to 'data'. This function fails in
int pa_property_remove(pa_core *c, const char *name); * case a property by this name already exists. The property data is
* not copied or reference counted. This is the caller's job. */
int pa_shared_set(pa_core *c, const char *name, void *data);
/* A combination of pa_property_remove() and pa_property_set() */ /* Remove the specified shared property. Return non-zero on failure */
int pa_property_replace(pa_core *c, const char *name, void *data); int pa_shared_remove(pa_core *c, const char *name);
/* Free all memory used by the property system */ /* A combination of pa_shared_remove() and pa_shared_set() */
void pa_property_cleanup(pa_core *c); int pa_shared_replace(pa_core *c, const char *name, void *data);
/* Initialize the properties subsystem */ /* Free all memory used by the shared property system */
void pa_property_init(pa_core *c); void pa_shared_cleanup(pa_core *c);
/* Dump the current set of properties */ /* Initialize the shared property system */
void pa_property_dump(pa_core *c, pa_strbuf *s); void pa_shared_init(pa_core *c);
/* Dump the current set of shared properties */
void pa_shared_dump(pa_core *c, pa_strbuf *s);
#endif #endif

View file

@ -29,7 +29,7 @@
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/props.h> #include <pulsecore/shared.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
@ -192,7 +192,7 @@ static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char
XAddConnectionWatch(d, x11_watch, (XPointer) w); XAddConnectionWatch(d, x11_watch, (XPointer) w);
pa_assert_se(pa_property_set(c, w->property_name, w) >= 0); pa_assert_se(pa_shared_set(c, w->property_name, w) >= 0);
return w; return w;
} }
@ -200,7 +200,7 @@ static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char
static void x11_wrapper_free(pa_x11_wrapper*w) { static void x11_wrapper_free(pa_x11_wrapper*w) {
pa_assert(w); pa_assert(w);
pa_assert_se(pa_property_remove(w->core, w->property_name) >= 0); pa_assert_se(pa_shared_remove(w->core, w->property_name) >= 0);
pa_assert(!w->clients); pa_assert(!w->clients);
@ -223,8 +223,9 @@ pa_x11_wrapper* pa_x11_wrapper_get(pa_core *c, const char *name) {
pa_core_assert_ref(c); pa_core_assert_ref(c);
pa_snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "-" : "", name ? name : ""); pa_snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "@" : "", name ? name : "");
if ((w = pa_property_get(c, t)))
if ((w = pa_shared_get(c, t)))
return pa_x11_wrapper_ref(w); return pa_x11_wrapper_ref(w);
return x11_wrapper_new(c, name, t); return x11_wrapper_new(c, name, t);
@ -242,8 +243,10 @@ void pa_x11_wrapper_unref(pa_x11_wrapper* w) {
pa_assert(w); pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1); pa_assert(PA_REFCNT_VALUE(w) >= 1);
if (PA_REFCNT_DEC(w) <= 0) if (PA_REFCNT_DEC(w) > 0)
x11_wrapper_free(w); return;
x11_wrapper_free(w);
} }
Display *pa_x11_wrapper_get_display(pa_x11_wrapper *w) { Display *pa_x11_wrapper_get_display(pa_x11_wrapper *w) {

View file

@ -31,7 +31,7 @@ int main(int argc, char *argv[]) {
pa_hook_fire(&hook, (void*) "call2"); pa_hook_fire(&hook, (void*) "call2");
pa_hook_free(&hook); pa_hook_done(&hook);
return 0; return 0;
} }