]>
code.delx.au - pulseaudio/blob - src/utils/pax11publish.c
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
34 #include <pulse/util.h>
35 #include <pulse/i18n.h>
37 #include <pulsecore/core-util.h>
38 #include <pulsecore/log.h>
39 #include <pulsecore/authkey.h>
40 #include <pulsecore/native-common.h>
41 #include <pulsecore/x11prop.h>
43 #include "../pulse/client-conf.h"
45 int main(int argc
, char *argv
[]) {
46 const char *dname
= NULL
, *sink
= NULL
, *source
= NULL
, *server
= NULL
, *cookie_file
= PA_NATIVE_COOKIE_FILE
;
48 xcb_connection_t
*xcb
= NULL
;
49 enum { DUMP
, EXPORT
, IMPORT
, REMOVE
} mode
= DUMP
;
51 setlocale(LC_ALL
, "");
52 bindtextdomain(GETTEXT_PACKAGE
, PULSE_LOCALEDIR
);
54 while ((c
= getopt(argc
, argv
, "deiD:S:O:I:c:hr")) != -1) {
60 printf(_("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
61 " -d Show current PulseAudio data attached to X11 display (default)\n"
62 " -e Export local PulseAudio data to X11 display\n"
63 " -i Import PulseAudio data from X11 display to local environment variables and cookie file.\n"
64 " -r Remove PulseAudio data from X11 display\n"),
65 pa_path_get_filename(argv
[0]));
93 fprintf(stderr
, _("Failed to parse command line.\n"));
98 if (!(xcb
= xcb_connect(dname
, NULL
))) {
99 pa_log(_("xcb_connect() failed"));
106 if (pa_x11_get_prop(xcb
, "PULSE_SERVER", t
, sizeof(t
)))
107 printf(_("Server: %s\n"), t
);
108 if (pa_x11_get_prop(xcb
, "PULSE_SOURCE", t
, sizeof(t
)))
109 printf(_("Source: %s\n"), t
);
110 if (pa_x11_get_prop(xcb
, "PULSE_SINK", t
, sizeof(t
)))
111 printf(_("Sink: %s\n"), t
);
112 if (pa_x11_get_prop(xcb
, "PULSE_COOKIE", t
, sizeof(t
)))
113 printf(_("Cookie: %s\n"), t
);
120 if (pa_x11_get_prop(xcb
, "PULSE_SERVER", t
, sizeof(t
)))
121 printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t
);
122 if (pa_x11_get_prop(xcb
, "PULSE_SOURCE", t
, sizeof(t
)))
123 printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t
);
124 if (pa_x11_get_prop(xcb
, "PULSE_SINK", t
, sizeof(t
)))
125 printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t
);
127 if (pa_x11_get_prop(xcb
, "PULSE_COOKIE", t
, sizeof(t
))) {
128 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
130 if ((l
= pa_parsehex(t
, cookie
, sizeof(cookie
))) != sizeof(cookie
)) {
131 fprintf(stderr
, _("Failed to parse cookie data\n"));
135 if (pa_authkey_save(cookie_file
, cookie
, l
) < 0) {
136 fprintf(stderr
, _("Failed to save cookie data\n"));
145 pa_client_conf
*conf
= pa_client_conf_new();
146 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
147 char hx
[PA_NATIVE_COOKIE_LENGTH
*2+1];
150 if (pa_client_conf_load(conf
, NULL
) < 0) {
151 fprintf(stderr
, _("Failed to load client configuration file.\n"));
155 if (pa_client_conf_env(conf
) < 0) {
156 fprintf(stderr
, _("Failed to read environment configuration data.\n"));
160 pa_x11_del_prop(xcb
, "PULSE_SERVER");
161 pa_x11_del_prop(xcb
, "PULSE_SINK");
162 pa_x11_del_prop(xcb
, "PULSE_SOURCE");
163 pa_x11_del_prop(xcb
, "PULSE_ID");
164 pa_x11_del_prop(xcb
, "PULSE_COOKIE");
167 pa_x11_set_prop(xcb
, "PULSE_SERVER", server
);
168 else if (conf
->default_server
)
169 pa_x11_set_prop(xcb
, "PULSE_SERVER", conf
->default_server
);
172 if (!pa_get_fqdn(hn
, sizeof(hn
))) {
173 fprintf(stderr
, _("Failed to get FQDN.\n"));
177 pa_x11_set_prop(xcb
, "PULSE_SERVER", hn
);
181 pa_x11_set_prop(xcb
, "PULSE_SINK", sink
);
182 else if (conf
->default_sink
)
183 pa_x11_set_prop(xcb
, "PULSE_SINK", conf
->default_sink
);
186 pa_x11_set_prop(xcb
, "PULSE_SOURCE", source
);
187 if (conf
->default_source
)
188 pa_x11_set_prop(xcb
, "PULSE_SOURCE", conf
->default_source
);
190 pa_client_conf_free(conf
);
192 if (pa_authkey_load_auto(cookie_file
, cookie
, sizeof(cookie
)) < 0) {
193 fprintf(stderr
, _("Failed to load cookie data\n"));
197 pa_x11_set_prop(xcb
, "PULSE_COOKIE", pa_hexstr(cookie
, sizeof(cookie
), hx
, sizeof(hx
)));
202 pa_x11_del_prop(xcb
, "PULSE_SERVER");
203 pa_x11_del_prop(xcb
, "PULSE_SINK");
204 pa_x11_del_prop(xcb
, "PULSE_SOURCE");
205 pa_x11_del_prop(xcb
, "PULSE_ID");
206 pa_x11_del_prop(xcb
, "PULSE_COOKIE");
210 fprintf(stderr
, _("Not yet implemented.\n"));