4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <X11/Xatom.h>
44 #include "native-common.h"
45 #include "module-x11-publish-symdef.h"
46 #include "authkey-prop.h"
52 PA_MODULE_AUTHOR("Lennart Poettering")
53 PA_MODULE_DESCRIPTION("X11 Credential Publisher")
54 PA_MODULE_VERSION(PACKAGE_VERSION
)
55 PA_MODULE_USAGE("display=<X11 display>")
57 static const char* const valid_modargs
[] = {
67 struct pa_x11_wrapper
*x11_wrapper
;
70 uint8_t auth_cookie
[PA_NATIVE_COOKIE_LENGTH
];
71 int auth_cookie_in_property
;
74 static int load_key(struct userdata
*u
, const char*fn
) {
77 u
->auth_cookie_in_property
= 0;
79 if (!fn
&& pa_authkey_prop_get(u
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, u
->auth_cookie
, sizeof(u
->auth_cookie
)) >= 0) {
80 pa_log(__FILE__
": using already loaded auth cookie.\n");
81 pa_authkey_prop_ref(u
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
);
82 u
->auth_cookie_in_property
= 1;
87 fn
= PA_NATIVE_COOKIE_FILE
;
89 if (pa_authkey_load_from_home(fn
, u
->auth_cookie
, sizeof(u
->auth_cookie
)) < 0)
92 pa_log(__FILE__
": loading cookie from disk.\n");
94 if (pa_authkey_prop_put(u
->core
, PA_NATIVE_COOKIE_PROPERTY_NAME
, u
->auth_cookie
, sizeof(u
->auth_cookie
)) >= 0)
95 u
->auth_cookie_in_property
= 1;
100 int pa__init(struct pa_core
*c
, struct pa_module
*m
) {
102 struct pa_modargs
*ma
= NULL
;
103 char hn
[256], un
[128];
104 char hx
[PA_NATIVE_COOKIE_LENGTH
*2+1];
107 struct pa_strlist
*l
;
109 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
110 pa_log(__FILE__
": failed to parse module arguments\n");
114 m
->userdata
= u
= pa_xmalloc(sizeof(struct userdata
));
117 u
->auth_cookie_in_property
= 0;
119 if (load_key(u
, pa_modargs_get_value(ma
, "cookie", NULL
)) < 0)
122 if (!(u
->x11_wrapper
= pa_x11_wrapper_get(c
, pa_modargs_get_value(ma
, "display", NULL
))))
125 u
->display
= pa_x11_wrapper_get_display(u
->x11_wrapper
);
127 if (!(l
= pa_property_get(c
, PA_NATIVE_SERVER_PROPERTY_NAME
)))
130 s
= pa_strlist_tostring(l
);
131 pa_x11_set_prop(u
->display
, "POLYP_SERVER", s
);
134 if (!pa_get_fqdn(hn
, sizeof(hn
)) || !pa_get_user_name(un
, sizeof(un
)))
137 u
->id
= pa_sprintf_malloc("%s@%s/%u", un
, hn
, (unsigned) getpid());
138 pa_x11_set_prop(u
->display
, "POLYP_ID", u
->id
);
140 if ((t
= pa_modargs_get_value(ma
, "source", NULL
)))
141 pa_x11_set_prop(u
->display
, "POLYP_SOURCE", t
);
143 if ((t
= pa_modargs_get_value(ma
, "sink", NULL
)))
144 pa_x11_set_prop(u
->display
, "POLYP_SINK", t
);
146 pa_x11_set_prop(u
->display
, "POLYP_COOKIE", pa_hexstr(u
->auth_cookie
, sizeof(u
->auth_cookie
), hx
, sizeof(hx
)));
159 void pa__done(struct pa_core
*c
, struct pa_module
*m
) {
163 if (!(u
= m
->userdata
))
166 if (u
->x11_wrapper
) {
169 /* Yes, here is a race condition */
170 if (!pa_x11_get_prop(u
->display
, "POLYP_ID", t
, sizeof(t
)) || strcmp(t
, u
->id
))
171 pa_log("WARNING: Polypaudio information vanished from X11!\n");
173 pa_x11_del_prop(u
->display
, "POLYP_ID");
174 pa_x11_del_prop(u
->display
, "POLYP_SERVER");
175 pa_x11_del_prop(u
->display
, "POLYP_SINK");
176 pa_x11_del_prop(u
->display
, "POLYP_SOURCE");
177 pa_x11_del_prop(u
->display
, "POLYP_COOKIE");
178 XSync(u
->display
, False
);
183 pa_x11_wrapper_unref(u
->x11_wrapper
);
185 if (u
->auth_cookie_in_property
)
186 pa_authkey_prop_unref(c
, PA_NATIVE_COOKIE_PROPERTY_NAME
);