]> code.delx.au - pulseaudio/blob - src/utils/pax11publish.c
remove all occurences of
[pulseaudio] / src / utils / pax11publish.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <getopt.h>
28 #include <string.h>
29 #include <assert.h>
30
31 #include <X11/Xlib.h>
32 #include <X11/Xatom.h>
33
34 #include <pulse/util.h>
35
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>
41
42 #include "../pulse/client-conf.h"
43
44 int main(int argc, char *argv[]) {
45 const char *dname = NULL, *sink = NULL, *source = NULL, *server = NULL, *cookie_file = PA_NATIVE_COOKIE_FILE;
46 int c, ret = 1;
47 Display *d = NULL;
48 enum { DUMP, EXPORT, IMPORT, REMOVE } mode = DUMP;
49
50 while ((c = getopt(argc, argv, "deiD:S:O:I:c:hr")) != -1) {
51 switch (c) {
52 case 'D' :
53 dname = optarg;
54 break;
55 case 'h':
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]));
62 ret = 0;
63 goto finish;
64 case 'd':
65 mode = DUMP;
66 break;
67 case 'e':
68 mode = EXPORT;
69 break;
70 case 'i':
71 mode = IMPORT;
72 break;
73 case 'r':
74 mode = REMOVE;
75 break;
76 case 'c':
77 cookie_file = optarg;
78 break;
79 case 'I':
80 source = optarg;
81 break;
82 case 'O':
83 sink = optarg;
84 break;
85 case 'S':
86 server = optarg;
87 break;
88 default:
89 fprintf(stderr, "Failed to parse command line.\n");
90 goto finish;
91 }
92 }
93
94 if (!(d = XOpenDisplay(dname))) {
95 pa_log("XOpenDisplay() failed");
96 goto finish;
97 }
98
99 switch (mode) {
100 case DUMP: {
101 char t[1024];
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);
110
111 break;
112 }
113
114 case IMPORT: {
115 char t[1024];
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);
122
123 if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t))) {
124 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
125 size_t l;
126 if ((l = pa_parsehex(t, cookie, sizeof(cookie))) != sizeof(cookie)) {
127 fprintf(stderr, "Failed to parse cookie data\n");
128 goto finish;
129 }
130
131 if (pa_authkey_save(cookie_file, cookie, l) < 0) {
132 fprintf(stderr, "Failed to save cookie data\n");
133 goto finish;
134 }
135 }
136
137 break;
138 }
139
140 case EXPORT: {
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];
144 assert(conf);
145
146 if (pa_client_conf_load(conf, NULL) < 0) {
147 fprintf(stderr, "Failed to load client configuration file.\n");
148 goto finish;
149 }
150
151 if (pa_client_conf_env(conf) < 0) {
152 fprintf(stderr, "Failed to read environment configuration data.\n");
153 goto finish;
154 }
155
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");
161
162 if (server)
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);
166 else {
167 char hn[256];
168 if (!pa_get_fqdn(hn, sizeof(hn))) {
169 fprintf(stderr, "Failed to get FQDN.\n");
170 goto finish;
171 }
172
173 pa_x11_set_prop(d, "PULSE_SERVER", hn);
174 }
175
176 if (sink)
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);
180
181 if (source)
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);
185
186 pa_client_conf_free(conf);
187
188 if (pa_authkey_load_auto(cookie_file, cookie, sizeof(cookie)) < 0) {
189 fprintf(stderr, "Failed to load cookie data\n");
190 goto finish;
191 }
192
193 pa_x11_set_prop(d, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
194 break;
195 }
196
197 case REMOVE:
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");
203 break;
204
205 default:
206 fprintf(stderr, "No yet implemented.\n");
207 goto finish;
208 }
209
210 ret = 0;
211
212 finish:
213
214 if (d) {
215 XSync(d, False);
216 XCloseDisplay(d);
217 }
218
219 return ret;
220 }