2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio 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.1 of the License,
9 or (at your option) any later version.
11 PulseAudio 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 PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <X11/Xatom.h>
35 #include <pulse/util.h>
36 #include <pulse/i18n.h>
38 #include <pulsecore/core-util.h>
39 #include <pulsecore/log.h>
40 #include <pulsecore/authkey.h>
41 #include <pulsecore/native-common.h>
42 #include <pulsecore/x11prop.h>
44 #include "../pulse/client-conf.h"
46 int main(int argc, char *argv[]) {
47 const char *dname = NULL, *sink = NULL, *source = NULL, *server = NULL, *cookie_file = PA_NATIVE_COOKIE_FILE;
50 enum { DUMP, EXPORT, IMPORT, REMOVE } mode = DUMP;
52 setlocale(LC_ALL, "");
53 bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
55 while ((c = getopt(argc, argv, "deiD:S:O:I:c:hr")) != -1) {
61 printf(_("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
62 " -d Show current PulseAudio data attached to X11 display (default)\n"
63 " -e Export local PulseAudio data to X11 display\n"
64 " -i Import PulseAudio data from X11 display to local environment variables and cookie file.\n"
65 " -r Remove PulseAudio data from X11 display\n"),
66 pa_path_get_filename(argv[0]));
94 fprintf(stderr, _("Failed to parse command line.\n"));
99 if (!(d = XOpenDisplay(dname))) {
100 pa_log(_("XOpenDisplay() failed"));
107 if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t)))
108 printf(_("Server: %s\n"), t);
109 if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t)))
110 printf(_("Source: %s\n"), t);
111 if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t)))
112 printf(_("Sink: %s\n"), t);
113 if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t)))
114 printf(_("Cookie: %s\n"), t);
121 if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t)))
122 printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t);
123 if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t)))
124 printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t);
125 if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t)))
126 printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t);
128 if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t))) {
129 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
131 if ((l = pa_parsehex(t, cookie, sizeof(cookie))) != sizeof(cookie)) {
132 fprintf(stderr, _("Failed to parse cookie data\n"));
136 if (pa_authkey_save(cookie_file, cookie, l) < 0) {
137 fprintf(stderr, _("Failed to save cookie data\n"));
146 pa_client_conf *conf = pa_client_conf_new();
147 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
148 char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
151 if (pa_client_conf_load(conf, NULL) < 0) {
152 fprintf(stderr, _("Failed to load client configuration file.\n"));
156 if (pa_client_conf_env(conf) < 0) {
157 fprintf(stderr, _("Failed to read environment configuration data.\n"));
161 pa_x11_del_prop(d, "PULSE_SERVER");
162 pa_x11_del_prop(d, "PULSE_SINK");
163 pa_x11_del_prop(d, "PULSE_SOURCE");
164 pa_x11_del_prop(d, "PULSE_ID");
165 pa_x11_del_prop(d, "PULSE_COOKIE");
168 pa_x11_set_prop(d, "PULSE_SERVER", server);
169 else if (conf->default_server)
170 pa_x11_set_prop(d, "PULSE_SERVER", conf->default_server);
173 if (!pa_get_fqdn(hn, sizeof(hn))) {
174 fprintf(stderr, _("Failed to get FQDN.\n"));
178 pa_x11_set_prop(d, "PULSE_SERVER", hn);
182 pa_x11_set_prop(d, "PULSE_SINK", sink);
183 else if (conf->default_sink)
184 pa_x11_set_prop(d, "PULSE_SINK", conf->default_sink);
187 pa_x11_set_prop(d, "PULSE_SOURCE", source);
188 if (conf->default_source)
189 pa_x11_set_prop(d, "PULSE_SOURCE", conf->default_source);
191 pa_client_conf_free(conf);
193 if (pa_authkey_load_auto(cookie_file, cookie, sizeof(cookie)) < 0) {
194 fprintf(stderr, _("Failed to load cookie data\n"));
198 pa_x11_set_prop(d, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
203 pa_x11_del_prop(d, "PULSE_SERVER");
204 pa_x11_del_prop(d, "PULSE_SINK");
205 pa_x11_del_prop(d, "PULSE_SOURCE");
206 pa_x11_del_prop(d, "PULSE_ID");
207 pa_x11_del_prop(d, "PULSE_COOKIE");
211 fprintf(stderr, _("Not yet implemented.\n"));