2004-10-30 01:55:16 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2004-10-30 01:55:16 +00:00
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-10-30 01:55:16 +00:00
|
|
|
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.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-10-30 01:55:16 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/util.h>
|
|
|
|
|
#include <pulse/xmalloc.h>
|
|
|
|
|
|
|
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/sink.h>
|
|
|
|
|
#include <pulsecore/core-scache.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
|
|
|
|
#include <pulsecore/namereg.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/x11wrap.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/native-common.h>
|
2008-08-03 16:44:38 +02:00
|
|
|
#include <pulsecore/auth-cookie.h>
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/x11prop.h>
|
|
|
|
|
#include <pulsecore/strlist.h>
|
2008-08-01 02:10:54 +03:00
|
|
|
#include <pulsecore/shared.h>
|
2008-08-03 16:44:38 +02:00
|
|
|
#include <pulsecore/protocol-native.h>
|
2006-02-16 19:19:58 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
#include "module-x11-publish-symdef.h"
|
|
|
|
|
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering");
|
2008-06-11 16:58:00 +00:00
|
|
|
PA_MODULE_DESCRIPTION("X11 credential publisher");
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
|
|
|
|
PA_MODULE_LOAD_ONCE(FALSE);
|
2009-02-12 23:14:24 +01:00
|
|
|
PA_MODULE_USAGE(
|
|
|
|
|
"display=<X11 display> "
|
|
|
|
|
"sink=<Sink to publish> "
|
|
|
|
|
"source=<Source to publish> "
|
|
|
|
|
"cookie=<Cookie file to publish> ");
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"display",
|
|
|
|
|
"sink",
|
|
|
|
|
"source",
|
2004-11-07 20:48:46 +00:00
|
|
|
"cookie",
|
2004-10-30 01:55:16 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct userdata {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core *core;
|
2008-06-11 16:58:00 +00:00
|
|
|
pa_module *module;
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_native_protocol *protocol;
|
2008-06-11 16:58:00 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
char *id;
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_auth_cookie *auth_cookie;
|
2008-06-11 16:58:00 +00:00
|
|
|
|
|
|
|
|
pa_x11_wrapper *x11_wrapper;
|
|
|
|
|
pa_x11_client *x11_client;
|
2008-08-03 16:44:38 +02:00
|
|
|
|
|
|
|
|
pa_hook_slot *hook_slot;
|
2004-10-30 01:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) {
|
|
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
|
|
|
|
|
pa_assert(w);
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->x11_wrapper == w);
|
|
|
|
|
|
|
|
|
|
if (u->x11_client)
|
|
|
|
|
pa_x11_client_free(u->x11_client);
|
|
|
|
|
|
|
|
|
|
if (u->x11_wrapper)
|
|
|
|
|
pa_x11_wrapper_unref(u->x11_wrapper);
|
|
|
|
|
|
|
|
|
|
u->x11_client = NULL;
|
|
|
|
|
u->x11_wrapper = NULL;
|
|
|
|
|
|
2008-08-05 23:56:25 +02:00
|
|
|
pa_module_unload_request(u->module, TRUE);
|
2008-06-11 16:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa__init(pa_module*m) {
|
2004-10-30 01:55:16 +00:00
|
|
|
struct userdata *u;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_modargs *ma = NULL;
|
2009-04-01 21:15:52 +02:00
|
|
|
char *mid;
|
2004-11-07 20:48:46 +00:00
|
|
|
char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
|
|
|
|
|
const char *t;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(m);
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("failed to parse module arguments");
|
2004-10-30 01:55:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
m->userdata = u = pa_xnew(struct userdata, 1);
|
2007-10-28 19:13:50 +00:00
|
|
|
u->core = m->core;
|
2008-06-11 16:58:00 +00:00
|
|
|
u->module = m;
|
2008-08-03 16:44:38 +02:00
|
|
|
u->protocol = pa_native_protocol_get(m->core);
|
2004-10-30 01:55:16 +00:00
|
|
|
u->id = NULL;
|
2008-08-03 16:44:38 +02:00
|
|
|
u->auth_cookie = NULL;
|
2008-06-11 16:58:00 +00:00
|
|
|
u->x11_client = NULL;
|
|
|
|
|
u->x11_wrapper = NULL;
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2008-08-04 18:58:29 +02:00
|
|
|
u->hook_slot = pa_hook_connect(&pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_SERVERS_CHANGED], PA_HOOK_NORMAL, servers_changed_cb, u);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
if (!(u->auth_cookie = pa_auth_cookie_get(m->core, pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), PA_NATIVE_COOKIE_LENGTH)))
|
2004-10-30 01:55:16 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
|
2004-11-09 01:04:17 +00:00
|
|
|
goto fail;
|
2004-11-11 21:18:33 +00:00
|
|
|
|
2009-04-01 21:15:52 +02:00
|
|
|
mid = pa_machine_id();
|
|
|
|
|
u->id = pa_sprintf_malloc("%lu@%s/%lu", (unsigned long) getuid(), mid, (unsigned long) getpid());
|
|
|
|
|
pa_xfree(mid);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", u->id);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
publish_servers(u, pa_native_protocol_servers(u->protocol));
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
if ((t = pa_modargs_get_value(ma, "source", NULL)))
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SOURCE", t);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if ((t = pa_modargs_get_value(ma, "sink", NULL)))
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SINK", t);
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
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)));
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
u->x11_client = pa_x11_client_new(u->x11_wrapper, NULL, x11_kill_cb, u);
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
pa_modargs_free(ma);
|
2008-06-11 16:58:00 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
return 0;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
fail:
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa__done(m);
|
2008-06-11 16:58:00 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa__done(pa_module*m) {
|
2004-10-30 01:55:16 +00:00
|
|
|
struct userdata*u;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(m);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 16:58:00 +00:00
|
|
|
if (u->x11_client)
|
|
|
|
|
pa_x11_client_free(u->x11_client);
|
|
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
if (u->x11_wrapper) {
|
|
|
|
|
char t[256];
|
|
|
|
|
|
|
|
|
|
/* Yes, here is a race condition */
|
2006-06-19 23:56:54 +00:00
|
|
|
if (!pa_x11_get_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id))
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("PulseAudio information vanished from X11!");
|
2004-10-30 01:55:16 +00:00
|
|
|
else {
|
2006-06-19 23:56:54 +00:00
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_ID");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SINK");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SOURCE");
|
|
|
|
|
pa_x11_del_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_COOKIE");
|
2006-04-22 21:51:30 +00:00
|
|
|
XSync(pa_x11_wrapper_get_display(u->x11_wrapper), False);
|
2004-10-30 01:55:16 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
pa_x11_wrapper_unref(u->x11_wrapper);
|
2008-06-11 16:58:00 +00:00
|
|
|
}
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
if (u->auth_cookie)
|
|
|
|
|
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);
|
2004-11-07 20:48:46 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
pa_xfree(u->id);
|
|
|
|
|
pa_xfree(u);
|
|
|
|
|
}
|