]>
code.delx.au - pulseaudio/blob - src/utils/pax11publish.c
4 This file is part of PulseAudio.
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 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
32 #include <X11/Xatom.h>
34 #include <pulse/util.h>
36 #include <pulsecore/core-util.h>
37 #include <pulsecore/log.h>
38 #include <pulsecore/authkey.h>
39 #include <pulsecore/native-common.h>
40 #include <pulsecore/x11prop.h>
42 #include "../pulse/client-conf.h"
44 int main(int argc
, char *argv
[]) {
45 const char *dname
= NULL
, *sink
= NULL
, *source
= NULL
, *server
= NULL
, *cookie_file
= PA_NATIVE_COOKIE_FILE
;
48 enum { DUMP
, EXPORT
, IMPORT
, REMOVE
} mode
= DUMP
;
50 while ((c
= getopt(argc
, argv
, "deiD:S:O:I:c:hr")) != -1) {
56 printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
57 " -d Show current PulseAudio data attached to X11 display (default)\n"
58 " -e Export local PulseAudio data to X11 display\n"
59 " -i Import PulseAudio data from X11 display to local environment variables and cookie file.\n"
60 " -r Remove PulseAudio data from X11 display\n",
61 pa_path_get_filename(argv
[0]));
89 fprintf(stderr
, "Failed to parse command line.\n");
94 if (!(d
= XOpenDisplay(dname
))) {
95 pa_log("XOpenDisplay() failed");
102 if (pa_x11_get_prop(d
, "PULSE_SERVER", t
, sizeof(t
)))
103 printf("Server: %s\n", t
);
104 if (pa_x11_get_prop(d
, "PULSE_SOURCE", t
, sizeof(t
)))
105 printf("Source: %s\n", t
);
106 if (pa_x11_get_prop(d
, "PULSE_SINK", t
, sizeof(t
)))
107 printf("Sink: %s\n", t
);
108 if (pa_x11_get_prop(d
, "PULSE_COOKIE", t
, sizeof(t
)))
109 printf("Cookie: %s\n", t
);
116 if (pa_x11_get_prop(d
, "PULSE_SERVER", t
, sizeof(t
)))
117 printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t
);
118 if (pa_x11_get_prop(d
, "PULSE_SOURCE", t
, sizeof(t
)))
119 printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t
);
120 if (pa_x11_get_prop(d
, "PULSE_SINK", t
, sizeof(t
)))
121 printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t
);
123 if (pa_x11_get_prop(d
, "PULSE_COOKIE", t
, sizeof(t
))) {
124 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
126 if ((l
= pa_parsehex(t
, cookie
, sizeof(cookie
))) != sizeof(cookie
)) {
127 fprintf(stderr
, "Failed to parse cookie data\n");
131 if (pa_authkey_save(cookie_file
, cookie
, l
) < 0) {
132 fprintf(stderr
, "Failed to save cookie data\n");
141 pa_client_conf
*conf
= pa_client_conf_new();
142 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
143 char hx
[PA_NATIVE_COOKIE_LENGTH
*2+1];
146 if (pa_client_conf_load(conf
, NULL
) < 0) {
147 fprintf(stderr
, "Failed to load client configuration file.\n");
151 if (pa_client_conf_env(conf
) < 0) {
152 fprintf(stderr
, "Failed to read environment configuration data.\n");
156 pa_x11_del_prop(d
, "PULSE_SERVER");
157 pa_x11_del_prop(d
, "PULSE_SINK");
158 pa_x11_del_prop(d
, "PULSE_SOURCE");
159 pa_x11_del_prop(d
, "PULSE_ID");
160 pa_x11_del_prop(d
, "PULSE_COOKIE");
163 pa_x11_set_prop(d
, "PULSE_SERVER", server
);
164 else if (conf
->default_server
)
165 pa_x11_set_prop(d
, "PULSE_SERVER", conf
->default_server
);
168 if (!pa_get_fqdn(hn
, sizeof(hn
))) {
169 fprintf(stderr
, "Failed to get FQDN.\n");
173 pa_x11_set_prop(d
, "PULSE_SERVER", hn
);
177 pa_x11_set_prop(d
, "PULSE_SINK", sink
);
178 else if (conf
->default_sink
)
179 pa_x11_set_prop(d
, "PULSE_SINK", conf
->default_sink
);
182 pa_x11_set_prop(d
, "PULSE_SOURCE", source
);
183 if (conf
->default_source
)
184 pa_x11_set_prop(d
, "PULSE_SOURCE", conf
->default_source
);
186 pa_client_conf_free(conf
);
188 if (pa_authkey_load_auto(cookie_file
, cookie
, sizeof(cookie
)) < 0) {
189 fprintf(stderr
, "Failed to load cookie data\n");
193 pa_x11_set_prop(d
, "PULSE_COOKIE", pa_hexstr(cookie
, sizeof(cookie
), hx
, sizeof(hx
)));
198 pa_x11_del_prop(d
, "PULSE_SERVER");
199 pa_x11_del_prop(d
, "PULSE_SINK");
200 pa_x11_del_prop(d
, "PULSE_SOURCE");
201 pa_x11_del_prop(d
, "PULSE_ID");
202 pa_x11_del_prop(d
, "PULSE_COOKIE");
206 fprintf(stderr
, "No yet implemented.\n");