4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34 #include <X11/Xatom.h>
36 #include <pulse/util.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 while ((c
= getopt(argc
, argv
, "deiD:S:O:I:c:hr")) != -1) {
58 printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
59 " -d Show current PulseAudio data attached to X11 display (default)\n"
60 " -e Export local PulseAudio data to X11 display\n"
61 " -i Import PulseAudio data from X11 display to local environment variables and cookie file.\n"
62 " -r Remove PulseAudio data from X11 display\n",
63 pa_path_get_filename(argv
[0]));
91 fprintf(stderr
, "Failed to parse command line.\n");
96 if (!(d
= XOpenDisplay(dname
))) {
97 pa_log("XOpenDisplay() failed");
104 if (pa_x11_get_prop(d
, "PULSE_SERVER", t
, sizeof(t
)))
105 printf("Server: %s\n", t
);
106 if (pa_x11_get_prop(d
, "PULSE_SOURCE", t
, sizeof(t
)))
107 printf("Source: %s\n", t
);
108 if (pa_x11_get_prop(d
, "PULSE_SINK", t
, sizeof(t
)))
109 printf("Sink: %s\n", t
);
110 if (pa_x11_get_prop(d
, "PULSE_COOKIE", t
, sizeof(t
)))
111 printf("Cookie: %s\n", t
);
118 if (pa_x11_get_prop(d
, "PULSE_SERVER", t
, sizeof(t
)))
119 printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t
);
120 if (pa_x11_get_prop(d
, "PULSE_SOURCE", t
, sizeof(t
)))
121 printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t
);
122 if (pa_x11_get_prop(d
, "PULSE_SINK", t
, sizeof(t
)))
123 printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t
);
125 if (pa_x11_get_prop(d
, "PULSE_COOKIE", t
, sizeof(t
))) {
126 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
128 if ((l
= pa_parsehex(t
, cookie
, sizeof(cookie
))) != sizeof(cookie
)) {
129 fprintf(stderr
, "Failed to parse cookie data\n");
133 if (pa_authkey_save(cookie_file
, cookie
, l
) < 0) {
134 fprintf(stderr
, "Failed to save cookie data\n");
143 pa_client_conf
*conf
= pa_client_conf_new();
144 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
145 char hx
[PA_NATIVE_COOKIE_LENGTH
*2+1];
148 if (pa_client_conf_load(conf
, NULL
) < 0) {
149 fprintf(stderr
, "Failed to load client configuration file.\n");
153 if (pa_client_conf_env(conf
) < 0) {
154 fprintf(stderr
, "Failed to read environment configuration data.\n");
158 pa_x11_del_prop(d
, "PULSE_SERVER");
159 pa_x11_del_prop(d
, "PULSE_SINK");
160 pa_x11_del_prop(d
, "PULSE_SOURCE");
161 pa_x11_del_prop(d
, "PULSE_ID");
162 pa_x11_del_prop(d
, "PULSE_COOKIE");
165 pa_x11_set_prop(d
, "PULSE_SERVER", server
);
166 else if (conf
->default_server
)
167 pa_x11_set_prop(d
, "PULSE_SERVER", conf
->default_server
);
170 if (!pa_get_fqdn(hn
, sizeof(hn
))) {
171 fprintf(stderr
, "Failed to get FQDN.\n");
175 pa_x11_set_prop(d
, "PULSE_SERVER", hn
);
179 pa_x11_set_prop(d
, "PULSE_SINK", sink
);
180 else if (conf
->default_sink
)
181 pa_x11_set_prop(d
, "PULSE_SINK", conf
->default_sink
);
184 pa_x11_set_prop(d
, "PULSE_SOURCE", source
);
185 if (conf
->default_source
)
186 pa_x11_set_prop(d
, "PULSE_SOURCE", conf
->default_source
);
188 pa_client_conf_free(conf
);
190 if (pa_authkey_load_auto(cookie_file
, cookie
, sizeof(cookie
)) < 0) {
191 fprintf(stderr
, "Failed to load cookie data\n");
195 pa_x11_set_prop(d
, "PULSE_COOKIE", pa_hexstr(cookie
, sizeof(cookie
), hx
, sizeof(hx
)));
200 pa_x11_del_prop(d
, "PULSE_SERVER");
201 pa_x11_del_prop(d
, "PULSE_SINK");
202 pa_x11_del_prop(d
, "PULSE_SOURCE");
203 pa_x11_del_prop(d
, "PULSE_ID");
204 pa_x11_del_prop(d
, "PULSE_COOKIE");
208 fprintf(stderr
, "No yet implemented.\n");