diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | doc/todo | 1 | ||||
-rw-r--r-- | polyp/Makefile.am | 22 | ||||
-rw-r--r-- | polyp/client-conf-x11.c | 89 | ||||
-rw-r--r-- | polyp/client-conf-x11.h | 29 | ||||
-rw-r--r-- | polyp/client-conf.c | 40 | ||||
-rw-r--r-- | polyp/client-conf.h | 8 | ||||
-rw-r--r-- | polyp/module-protocol-stub.c | 2 | ||||
-rw-r--r-- | polyp/module-x11-publish.c | 51 | ||||
-rw-r--r-- | polyp/native-common.h | 3 | ||||
-rw-r--r-- | polyp/pax11publish.c | 85 | ||||
-rw-r--r-- | polyp/polyplib-context.c | 19 | ||||
-rw-r--r-- | polyp/polyplib-internal.h | 3 | ||||
-rw-r--r-- | polyp/x11prop.c | 70 | ||||
-rw-r--r-- | polyp/x11prop.h | 33 |
15 files changed, 337 insertions, 119 deletions
diff --git a/configure.ac b/configure.ac index 026d4d97..6eec2d81 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,7 @@ HAVE_X11=0 test "x$no_x" != "xyes" && HAVE_X11=1 AC_SUBST(HAVE_X11) AM_CONDITIONAL(HAVE_X11, test "x$no_x" != "xyes") +AC_DEFINE([HAVE_X11], [], [Have X11]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -20,6 +20,7 @@ - add LGPL blurb to all concerning files - non-fp mixing - non-fp resampling +- esound backend ** later *** - xmlrpc/http diff --git a/polyp/Makefile.am b/polyp/Makefile.am index 18aa51c1..cc9705c2 100644 --- a/polyp/Makefile.am +++ b/polyp/Makefile.am @@ -27,8 +27,8 @@ AM_CFLAGS+=-DDLSEARCHPATH=\"$(modlibdir)\" AM_CFLAGS+=-DDEFAULT_CONFIG_DIR=\"$(polypconfdir)\" AM_CFLAGS+=-DPOLYPAUDIO_BINARY=\"$(bindir)/polypaudio\" -AM_LDADD=$(PTHREAD_LIBS) -lm AM_LIBADD=$(PTHREAD_LIBS) -lm +AM_LDADD=$(PTHREAD_LIBS) -lm EXTRA_DIST = default.pa.in daemon.conf.in client.conf.in depmod.py esdcompat.sh.in module-defs.h.m4 bin_PROGRAMS = polypaudio pacat pactl paplay @@ -462,6 +462,7 @@ cpulimit_test2_LDADD = $(AM_LDADD) libpolyp-mainloop-@PA_MAJORMINOR@.la if HAVE_X11 modlib_LTLIBRARIES+= \ libx11wrap.la \ + libx11prop.la \ module-x11-bell.la \ module-x11-publish.la SYMDEF_FILES += \ @@ -471,24 +472,33 @@ SYMDEF_FILES += \ libx11wrap_la_SOURCES = x11wrap.c x11wrap.h libx11wrap_la_LDFLAGS = -avoid-version libx11wrap_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) -libx11wrap_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB) +libx11wrap_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) + +libx11prop_la_SOURCES = x11prop.c x11prop.h +libx11prop_la_LDFLAGS = -avoid-version +libx11prop_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) +libx11prop_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) module_x11_bell_la_SOURCES = module-x11-bell.c module_x11_bell_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) module_x11_bell_la_LDFLAGS = -module -avoid-version -module_x11_bell_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB) libx11wrap.la +module_x11_bell_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) libx11wrap.la module_x11_publish_la_SOURCES = module-x11-publish.c module_x11_publish_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) module_x11_publish_la_LDFLAGS = -module -avoid-version -module_x11_publish_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB) libx11wrap.la libauthkey.la libauthkey-prop.la +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 bin_PROGRAMS+= \ pax11publish -pax11publish_SOURCES = pax11publish.c util.c xmalloc.c log.c authkey.c client-conf.c conf-parser.c +pax11publish_SOURCES = pax11publish.c util.c xmalloc.c log.c authkey.c client-conf.c conf-parser.c x11prop.c pax11publish_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) -pax11publish_LDADD = $(AM_LDADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB) +pax11publish_LDADD = $(AM_LDADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) + +libpolyp_@PA_MAJORMINOR@_la_CFLAGS += $(X_CFLAGS) +libpolyp_@PA_MAJORMINOR@_la_LDFLAGS += $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIBS) +libpolyp_@PA_MAJORMINOR@_la_SOURCES += x11prop.c client-conf-x11.c endif diff --git a/polyp/client-conf-x11.c b/polyp/client-conf-x11.c new file mode 100644 index 00000000..54c3b06a --- /dev/null +++ b/polyp/client-conf-x11.c @@ -0,0 +1,89 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio 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 General Public License + along with polypaudio; 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 <string.h> +#include <assert.h> + +#include <X11/Xlib.h> +#include <X11/Xatom.h> + +#include "client-conf-x11.h" +#include "x11prop.h" +#include "log.h" +#include "xmalloc.h" +#include "util.h" + +int pa_client_conf_from_x11(struct pa_client_conf *c, const char *dname) { + Display *d = NULL; + int ret = -1; + char t[1024]; + + if (!(d = XOpenDisplay(dname))) { + pa_log(__FILE__": XOpenDisplay() failed\n"); + goto finish; + } + + if (!pa_x11_get_prop(d, "POLYP_SERVER", t, sizeof(t))) + goto finish; + + pa_xfree(c->default_server); + c->default_server = pa_xstrdup(t); + + if (pa_x11_get_prop(d, "POLYP_SINK", t, sizeof(t))) { + pa_xfree(c->default_sink); + c->default_sink = pa_xstrdup(t); + } + + if (pa_x11_get_prop(d, "POLYP_SOURCE", t, sizeof(t))) { + pa_xfree(c->default_source); + c->default_source = pa_xstrdup(t); + } + + if (pa_x11_get_prop(d, "POLYP_COOKIE", t, sizeof(t))) { + uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; + + if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) { + pa_log(__FILE__": failed to parse cookie data\n"); + goto finish; + } + + assert(sizeof(cookie) == sizeof(c->cookie)); + memcpy(c->cookie, cookie, sizeof(cookie)); + + c->cookie_valid = 1; + + pa_xfree(c->cookie_file); + c->cookie_file = NULL; + } + + ret = 0; + +finish: + if (d) + XCloseDisplay(d); + + return ret; + +} diff --git a/polyp/client-conf-x11.h b/polyp/client-conf-x11.h new file mode 100644 index 00000000..626b4f30 --- /dev/null +++ b/polyp/client-conf-x11.h @@ -0,0 +1,29 @@ +#ifndef fooclientconfx11hfoo +#define fooclientconfx11hfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio 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 General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include "client-conf.h" + +int pa_client_conf_from_x11(struct pa_client_conf *c, const char *display); + +#endif diff --git a/polyp/client-conf.c b/polyp/client-conf.c index 0f442c99..4a0fc629 100644 --- a/polyp/client-conf.c +++ b/polyp/client-conf.c @@ -30,6 +30,7 @@ #include "log.h" #include "conf-parser.h" #include "util.h" +#include "authkey.h" #ifndef DEFAULT_CONFIG_DIR #define DEFAULT_CONFIG_DIR "/etc/polypaudio" @@ -43,6 +44,7 @@ #define ENV_DEFAULT_SOURCE "POLYP_SOURCE" #define ENV_DEFAULT_SERVER "POLYP_SERVER" #define ENV_DAEMON_BINARY "POLYP_BINARY" +#define ENV_COOKIE_FILE "POLYP_COOKIE" static const struct pa_client_conf default_conf = { .daemon_binary = NULL, @@ -50,14 +52,20 @@ static const struct pa_client_conf default_conf = { .default_sink = NULL, .default_source = NULL, .default_server = NULL, - .autospawn = 0 + .autospawn = 0, + .cookie_file = NULL, + .cookie_valid = 0 }; struct pa_client_conf *pa_client_conf_new(void) { struct pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); + + c->daemon_binary = pa_xstrdup(POLYPAUDIO_BINARY); c->extra_arguments = pa_xstrdup("--log-target=syslog --exit-idle-time=5"); + + c->cookie_file = pa_xstrdup(PA_NATIVE_COOKIE_FILE); return c; } @@ -69,6 +77,7 @@ void pa_client_conf_free(struct pa_client_conf *c) { pa_xfree(c->default_sink); pa_xfree(c->default_source); pa_xfree(c->default_server); + pa_xfree(c->cookie_file); pa_xfree(c); } int pa_client_conf_load(struct pa_client_conf *c, const char *filename) { @@ -83,6 +92,7 @@ int pa_client_conf_load(struct pa_client_conf *c, const char *filename) { { "default-source", pa_config_parse_string, NULL }, { "default-server", pa_config_parse_string, NULL }, { "autospawn", pa_config_parse_bool, NULL }, + { "cookie-file", pa_config_parse_string, NULL }, { NULL, NULL, NULL }, }; @@ -92,6 +102,7 @@ int pa_client_conf_load(struct pa_client_conf *c, const char *filename) { table[3].data = &c->default_source; table[4].data = &c->default_server; table[5].data = &c->autospawn; + table[6].data = &c->cookie_file; f = filename ? fopen((fn = pa_xstrdup(filename)), "r") : @@ -104,6 +115,10 @@ int pa_client_conf_load(struct pa_client_conf *c, const char *filename) { r = f ? pa_config_parse(fn, f, table, NULL) : 0; + if (!r) + r = pa_client_conf_load_cookie(c); + + finish: pa_xfree(fn); @@ -136,5 +151,28 @@ int pa_client_conf_env(struct pa_client_conf *c) { c->daemon_binary = pa_xstrdup(e); } + if ((e = getenv(ENV_COOKIE_FILE))) { + pa_xfree(c->cookie_file); + c->cookie_file = pa_xstrdup(e); + + return pa_client_conf_load_cookie(c); + } + return 0; } + +int pa_client_conf_load_cookie(struct pa_client_conf* c) { + assert(c); + + c->cookie_valid = 0; + + if (!c->cookie_file) + return -1; + + if (pa_authkey_load_auto(c->cookie_file, c->cookie, sizeof(c->cookie)) < 0) + return -1; + + c->cookie_valid = 1; + return 0; +} + diff --git a/polyp/client-conf.h b/polyp/client-conf.h index 6fd4a20d..2ce056f4 100644 --- a/polyp/client-conf.h +++ b/polyp/client-conf.h @@ -22,9 +22,13 @@ USA. ***/ +#include "native-common.h" + struct pa_client_conf { - char *daemon_binary, *extra_arguments, *default_sink, *default_source, *default_server; + char *daemon_binary, *extra_arguments, *default_sink, *default_source, *default_server, *cookie_file; int autospawn; + uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; + int cookie_valid; }; struct pa_client_conf *pa_client_conf_new(void); @@ -33,4 +37,6 @@ void pa_client_conf_free(struct pa_client_conf *c); int pa_client_conf_load(struct pa_client_conf *c, const char *filename); int pa_client_conf_env(struct pa_client_conf *c); +int pa_client_conf_load_cookie(struct pa_client_conf* c); + #endif diff --git a/polyp/module-protocol-stub.c b/polyp/module-protocol-stub.c index 8cef3bdb..6ff7d774 100644 --- a/polyp/module-protocol-stub.c +++ b/polyp/module-protocol-stub.c @@ -83,7 +83,7 @@ #define protocol_free pa_protocol_native_free #define TCPWRAP_SERVICE "polypaudio-native" #define IPV4_PORT PA_NATIVE_DEFAULT_PORT - #define UNIX_SOCKET "/tmp/polypaudio/native" + #define UNIX_SOCKET PA_NATIVE_DEFAULT_SERVER_UNIX #define MODULE_ARGUMENTS "public", "cookie", #ifdef USE_TCP_SOCKETS #include "module-native-protocol-tcp-symdef.h" diff --git a/polyp/module-x11-publish.c b/polyp/module-x11-publish.c index c862fe3a..6e100153 100644 --- a/polyp/module-x11-publish.c +++ b/polyp/module-x11-publish.c @@ -45,6 +45,7 @@ #include "module-x11-publish-symdef.h" #include "authkey-prop.h" #include "authkey.h" +#include "x11prop.h" PA_MODULE_AUTHOR("Lennart Poettering") PA_MODULE_DESCRIPTION("X11 Credential Publisher") @@ -68,34 +69,6 @@ struct userdata { int auth_cookie_in_property; }; -static void set_x11_prop(Display *d, const char *name, const char *data) { - Atom a = XInternAtom(d, name, False); - XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (unsigned char*) data, strlen(data)+1); -} - -static void del_x11_prop(Display *d, const char *name) { - Atom a = XInternAtom(d, name, False); - XDeleteProperty(d, RootWindow(d, 0), a); -} - -static char* get_x11_prop(Display *d, const char *name, char *p, size_t l) { - Atom actual_type; - int actual_format; - unsigned long nitems; - unsigned long nbytes_after; - unsigned char *prop; - - Atom a = XInternAtom(d, name, False); - if (XGetWindowProperty(d, RootWindow(d, 0), a, 0, (l+2)/4, False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop) != Success) - return NULL; - - memcpy(p, prop, nitems); - p[nitems] = 0; - - XFree(prop); - return p; -} - static int load_key(struct userdata *u, const char*fn) { assert(u); @@ -155,16 +128,16 @@ int pa__init(struct pa_core *c, struct pa_module*m) { u->id = pa_sprintf_malloc("%s@%s/%u", un, hn, (unsigned) getpid()); - set_x11_prop(u->display, "POLYP_SERVER", hn); - set_x11_prop(u->display, "POLYP_ID", u->id); + pa_x11_set_prop(u->display, "POLYP_SERVER", hn); + pa_x11_set_prop(u->display, "POLYP_ID", u->id); if ((t = pa_modargs_get_value(ma, "source", NULL))) - set_x11_prop(u->display, "POLYP_SOURCE", t); + pa_x11_set_prop(u->display, "POLYP_SOURCE", t); if ((t = pa_modargs_get_value(ma, "sink", NULL))) - set_x11_prop(u->display, "POLYP_SINK", t); + pa_x11_set_prop(u->display, "POLYP_SINK", t); - set_x11_prop(u->display, "POLYP_COOKIE", pa_hexstr(u->auth_cookie, sizeof(u->auth_cookie), hx, sizeof(hx))); + pa_x11_set_prop(u->display, "POLYP_COOKIE", pa_hexstr(u->auth_cookie, sizeof(u->auth_cookie), hx, sizeof(hx))); pa_modargs_free(ma); return 0; @@ -188,14 +161,14 @@ void pa__done(struct pa_core *c, struct pa_module*m) { char t[256]; /* Yes, here is a race condition */ - if (!get_x11_prop(u->display, "POLYP_ID", t, sizeof(t)) || strcmp(t, u->id)) + if (!pa_x11_get_prop(u->display, "POLYP_ID", t, sizeof(t)) || strcmp(t, u->id)) pa_log("WARNING: Polypaudio information vanished from X11!\n"); else { - del_x11_prop(u->display, "POLYP_ID"); - del_x11_prop(u->display, "POLYP_SERVER"); - del_x11_prop(u->display, "POLYP_SINK"); - del_x11_prop(u->display, "POLYP_SOURCE"); - del_x11_prop(u->display, "POLYP_COOKIE"); + pa_x11_del_prop(u->display, "POLYP_ID"); + pa_x11_del_prop(u->display, "POLYP_SERVER"); + pa_x11_del_prop(u->display, "POLYP_SINK"); + pa_x11_del_prop(u->display, "POLYP_SOURCE"); + pa_x11_del_prop(u->display, "POLYP_COOKIE"); XSync(u->display, False); } } diff --git a/polyp/native-common.h b/polyp/native-common.h index fbee74c9..597bb56b 100644 --- a/polyp/native-common.h +++ b/polyp/native-common.h @@ -100,6 +100,9 @@ enum { #define PA_NATIVE_COOKIE_PROPERTY_NAME "protocol-native-cookie" +#define PA_NATIVE_DEFAULT_SERVER_UNIX "/tmp/polypaudio/native" + + PA_C_DECL_END #endif diff --git a/polyp/pax11publish.c b/polyp/pax11publish.c index fc1d6ab7..f151c197 100644 --- a/polyp/pax11publish.c +++ b/polyp/pax11publish.c @@ -36,44 +36,7 @@ #include "authkey.h" #include "native-common.h" #include "client-conf.h" - -static void set_x11_prop(Display *d, const char *name, const char *data) { - Atom a = XInternAtom(d, name, False); - XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (unsigned char*) data, strlen(data)+1); -} - -static void del_x11_prop(Display *d, const char *name) { - Atom a = XInternAtom(d, name, False); - XDeleteProperty(d, RootWindow(d, 0), a); -} - -static char* get_x11_prop(Display *d, const char *name, char *p, size_t l) { - Atom actual_type; - int actual_format; - unsigned long nitems; - unsigned long nbytes_after; - unsigned char *prop = NULL; - char *ret = NULL; - - Atom a = XInternAtom(d, name, False); - if (XGetWindowProperty(d, RootWindow(d, 0), a, 0, (l+2)/4, False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop) != Success) - goto finish; - - if (actual_type != XA_STRING) - goto finish; - - memcpy(p, prop, nitems); - p[nitems] = 0; - - ret = p; - -finish: - - if (prop) - XFree(prop); - - return ret; -} +#include "x11prop.h" int main(int argc, char *argv[]) { const char *dname = NULL, *sink = NULL, *source = NULL, *server = NULL, *cookie_file = PA_NATIVE_COOKIE_FILE; @@ -133,15 +96,15 @@ int main(int argc, char *argv[]) { switch (mode) { case DUMP: { char t[1024]; - if (!get_x11_prop(d, "POLYP_SERVER", t, sizeof(t))) + if (!pa_x11_get_prop(d, "POLYP_SERVER", t, sizeof(t))) goto finish; printf("Server: %s\n", t); - if (get_x11_prop(d, "POLYP_SOURCE", t, sizeof(t))) + if (pa_x11_get_prop(d, "POLYP_SOURCE", t, sizeof(t))) printf("Source: %s\n", t); - if (get_x11_prop(d, "POLYP_SINK", t, sizeof(t))) + if (pa_x11_get_prop(d, "POLYP_SINK", t, sizeof(t))) printf("Sink: %s\n", t); - if (get_x11_prop(d, "POLYP_COOKIE", t, sizeof(t))) + if (pa_x11_get_prop(d, "POLYP_COOKIE", t, sizeof(t))) printf("Cookie: %s\n", t); break; @@ -149,20 +112,20 @@ int main(int argc, char *argv[]) { case IMPORT: { char t[1024]; - if (!get_x11_prop(d, "POLYP_SERVER", t, sizeof(t))) + if (!pa_x11_get_prop(d, "POLYP_SERVER", t, sizeof(t))) goto finish; printf("POLYP_SERVER='%s'\nexport POLYP_SERVER\n", t); - if (get_x11_prop(d, "POLYP_SOURCE", t, sizeof(t))) + if (pa_x11_get_prop(d, "POLYP_SOURCE", t, sizeof(t))) printf("POLYP_SOURCE='%s'\nexport POLYP_SOURCE\n", t); - if (get_x11_prop(d, "POLYP_SINK", t, sizeof(t))) + if (pa_x11_get_prop(d, "POLYP_SINK", t, sizeof(t))) printf("POLYP_SINK='%s'\nexport POLYP_SINK\n", t); - if (get_x11_prop(d, "POLYP_COOKIE", t, sizeof(t))) { + if (pa_x11_get_prop(d, "POLYP_COOKIE", t, sizeof(t))) { uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; size_t l; - if ((l = pa_parsehex(t, cookie, sizeof(cookie))) == (size_t) -1) { + if ((l = pa_parsehex(t, cookie, sizeof(cookie))) != sizeof(cookie)) { fprintf(stderr, "Failed to parse cookie data\n"); goto finish; } @@ -192,12 +155,12 @@ int main(int argc, char *argv[]) { goto finish; } - del_x11_prop(d, "POLYP_ID"); + pa_x11_del_prop(d, "POLYP_ID"); if (server) - set_x11_prop(d, "POLYP_SERVER", c->default_server); + pa_x11_set_prop(d, "POLYP_SERVER", c->default_server); else if (c->default_server) - set_x11_prop(d, "POLYP_SERVER", c->default_server); + pa_x11_set_prop(d, "POLYP_SERVER", c->default_server); else { char hn[256]; if (!pa_get_fqdn(hn, sizeof(hn))) { @@ -205,18 +168,18 @@ int main(int argc, char *argv[]) { goto finish; } - set_x11_prop(d, "POLYP_SERVER", hn); + pa_x11_set_prop(d, "POLYP_SERVER", hn); } if (sink) - set_x11_prop(d, "POLYP_SINK", sink); + pa_x11_set_prop(d, "POLYP_SINK", sink); else if (c->default_sink) - set_x11_prop(d, "POLYP_SINK", c->default_sink); + pa_x11_set_prop(d, "POLYP_SINK", c->default_sink); if (source) - set_x11_prop(d, "POLYP_SOURCE", source); + pa_x11_set_prop(d, "POLYP_SOURCE", source); if (c->default_source) - set_x11_prop(d, "POLYP_SOURCE", c->default_source); + pa_x11_set_prop(d, "POLYP_SOURCE", c->default_source); pa_client_conf_free(c); @@ -225,16 +188,16 @@ int main(int argc, char *argv[]) { goto finish; } - set_x11_prop(d, "POLYP_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx))); + pa_x11_set_prop(d, "POLYP_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx))); break; } case REMOVE: - del_x11_prop(d, "POLYP_SERVER"); - del_x11_prop(d, "POLYP_SINK"); - del_x11_prop(d, "POLYP_SOURCE"); - del_x11_prop(d, "POLYP_ID"); - del_x11_prop(d, "POLYP_COOKIE"); + pa_x11_del_prop(d, "POLYP_SERVER"); + pa_x11_del_prop(d, "POLYP_SINK"); + pa_x11_del_prop(d, "POLYP_SOURCE"); + pa_x11_del_prop(d, "POLYP_ID"); + pa_x11_del_prop(d, "POLYP_COOKIE"); break; default: diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c index 1a25523f..36512a8a 100644 --- a/polyp/polyplib-context.c +++ b/polyp/polyplib-context.c @@ -44,14 +44,16 @@ #include "dynarray.h" #include "socket-client.h" #include "pstream-util.h" -#include "authkey.h" #include "util.h" #include "xmalloc.h" #include "log.h" #include "client-conf.h" #include "socket-util.h" -#define DEFAULT_SERVER "/tmp/polypaudio/native" +#ifdef HAVE_X11 +#include "client-conf-x11.h" +#endif + #define AUTOSPAWN_LOCK "/tmp/polypaudio/autospawn.lock" static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = { @@ -96,6 +98,9 @@ struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char * c->conf = pa_client_conf_new(); pa_client_conf_load(c->conf, NULL); +#ifdef HAVE_X11 + pa_client_conf_from_x11(c->conf, NULL); +#endif pa_client_conf_env(c->conf); return c; @@ -312,7 +317,7 @@ static void setup_context(struct pa_context *c, struct pa_iochannel *io) { c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX); assert(c->pdispatch); - if (pa_authkey_load_from_home(PA_NATIVE_COOKIE_FILE, c->auth_cookie, sizeof(c->auth_cookie)) < 0) { + if (!c->conf->cookie_valid) { pa_context_fail(c, PA_ERROR_AUTHKEY); goto finish; } @@ -321,7 +326,7 @@ static void setup_context(struct pa_context *c, struct pa_iochannel *io) { assert(t); pa_tagstruct_putu32(t, PA_COMMAND_AUTH); pa_tagstruct_putu32(t, tag = c->ctag++); - pa_tagstruct_put_arbitrary(t, c->auth_cookie, sizeof(c->auth_cookie)); + pa_tagstruct_put_arbitrary(t, c->conf->cookie, sizeof(c->conf->cookie)); pa_pstream_send_tagstruct(c->pstream, t); pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, setup_complete_callback, c); @@ -355,10 +360,10 @@ finish: static int default_server_is_running(void) { struct stat st; - if (DEFAULT_SERVER[0] != '/') + if (PA_NATIVE_DEFAULT_SERVER_UNIX[0] != '/') return 1; - if (stat(DEFAULT_SERVER, &st) < 0) + if (stat(PA_NATIVE_DEFAULT_SERVER_UNIX, &st) < 0) return 0; return 1; @@ -488,7 +493,7 @@ int pa_context_connect(struct pa_context *c, const char *server, int spawn, cons } if (!server) - server = DEFAULT_SERVER; + server = PA_NATIVE_DEFAULT_SERVER_UNIX; pa_context_ref(c); diff --git a/polyp/polyplib-internal.h b/polyp/polyplib-internal.h index 623a89b3..4e6553a8 100644 --- a/polyp/polyplib-internal.h +++ b/polyp/polyplib-internal.h @@ -61,8 +61,6 @@ struct pa_context { uint32_t error; enum pa_context_state state; - uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH]; - void (*state_callback)(struct pa_context*c, void *userdata); void *state_userdata; @@ -109,7 +107,6 @@ struct pa_stream { void (*write_callback)(struct pa_stream *p, size_t length, void *userdata); void *write_userdata; - }; struct pa_operation { diff --git a/polyp/x11prop.c b/polyp/x11prop.c new file mode 100644 index 00000000..6ff91ec4 --- /dev/null +++ b/polyp/x11prop.c @@ -0,0 +1,70 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio 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 General Public License + along with polypaudio; 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 <string.h> + +#include <X11/Xlib.h> +#include <X11/Xatom.h> + +#include "x11prop.h" + + +void pa_x11_set_prop(Display *d, const char *name, const char *data) { + Atom a = XInternAtom(d, name, False); + XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (unsigned char*) data, strlen(data)+1); +} + +void pa_x11_del_prop(Display *d, const char *name) { + Atom a = XInternAtom(d, name, False); + XDeleteProperty(d, RootWindow(d, 0), a); +} + +char* pa_x11_get_prop(Display *d, const char *name, char *p, size_t l) { + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long nbytes_after; + unsigned char *prop = NULL; + char *ret = NULL; + + Atom a = XInternAtom(d, name, False); + if (XGetWindowProperty(d, RootWindow(d, 0), a, 0, (l+2)/4, False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop) != Success) + goto finish; + + if (actual_type != XA_STRING) + goto finish; + + memcpy(p, prop, nitems); + p[nitems] = 0; + + ret = p; + +finish: + + if (prop) + XFree(prop); + + return ret; +} diff --git a/polyp/x11prop.h b/polyp/x11prop.h new file mode 100644 index 00000000..22461858 --- /dev/null +++ b/polyp/x11prop.h @@ -0,0 +1,33 @@ +#ifndef foox11prophfoo +#define foox11prophfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio 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 General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include <sys/types.h> + +#include <X11/Xlib.h> + +void pa_x11_set_prop(Display *d, const char *name, const char *data); +void pa_x11_del_prop(Display *d, const char *name); +char* pa_x11_get_prop(Display *d, const char *name, char *p, size_t l); + +#endif |