]>
code.delx.au - pulseaudio/blob - polyp/pax11publish.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU 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 polypaudio 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 General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <X11/Xatom.h>
37 #include "native-common.h"
38 #include "client-conf.h"
40 static void set_x11_prop(Display
*d
, const char *name
, const char *data
) {
41 Atom a
= XInternAtom(d
, name
, False
);
42 XChangeProperty(d
, RootWindow(d
, 0), a
, XA_STRING
, 8, PropModeReplace
, (unsigned char*) data
, strlen(data
)+1);
45 static void del_x11_prop(Display
*d
, const char *name
) {
46 Atom a
= XInternAtom(d
, name
, False
);
47 XDeleteProperty(d
, RootWindow(d
, 0), a
);
50 static char* get_x11_prop(Display
*d
, const char *name
, char *p
, size_t l
) {
54 unsigned long nbytes_after
;
55 unsigned char *prop
= NULL
;
58 Atom a
= XInternAtom(d
, name
, False
);
59 if (XGetWindowProperty(d
, RootWindow(d
, 0), a
, 0, (l
+2)/4, False
, XA_STRING
, &actual_type
, &actual_format
, &nitems
, &nbytes_after
, &prop
) != Success
)
62 if (actual_type
!= XA_STRING
)
65 memcpy(p
, prop
, nitems
);
78 int main(int argc
, char *argv
[]) {
79 const char *dname
= NULL
, *sink
= NULL
, *source
= NULL
, *server
= NULL
, *cookie_file
= PA_NATIVE_COOKIE_FILE
;
82 enum { DUMP
, EXPORT
, IMPORT
, REMOVE
} mode
= DUMP
;
84 while ((c
= getopt(argc
, argv
, "deiD:S:O:I:c:hr")) != -1) {
90 printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
91 " -d Show current Polypaudio data attached to X11 display (default)\n"
92 " -e Export local Polypaudio data to X11 display\n"
93 " -i Import Polypaudio data from X11 display to local environment variables and cookie file.\n"
94 " -r Remove Polypaudio data from X11 display\n",
95 pa_path_get_filename(argv
[0]));
111 cookie_file
= optarg
;
123 fprintf(stderr
, "Failed to parse command line.\n");
128 if (!(d
= XOpenDisplay(dname
))) {
129 pa_log(__FILE__
": XOpenDisplay() failed\n");
136 if (!get_x11_prop(d
, "POLYP_SERVER", t
, sizeof(t
)))
139 printf("Server: %s\n", t
);
140 if (get_x11_prop(d
, "POLYP_SOURCE", t
, sizeof(t
)))
141 printf("Source: %s\n", t
);
142 if (get_x11_prop(d
, "POLYP_SINK", t
, sizeof(t
)))
143 printf("Sink: %s\n", t
);
144 if (get_x11_prop(d
, "POLYP_COOKIE", t
, sizeof(t
)))
145 printf("Cookie: %s\n", t
);
152 if (!get_x11_prop(d
, "POLYP_SERVER", t
, sizeof(t
)))
155 printf("POLYP_SERVER='%s'\nexport POLYP_SERVER\n", t
);
157 if (get_x11_prop(d
, "POLYP_SOURCE", t
, sizeof(t
)))
158 printf("POLYP_SOURCE='%s'\nexport POLYP_SOURCE\n", t
);
159 if (get_x11_prop(d
, "POLYP_SINK", t
, sizeof(t
)))
160 printf("POLYP_SINK='%s'\nexport POLYP_SINK\n", t
);
162 if (get_x11_prop(d
, "POLYP_COOKIE", t
, sizeof(t
))) {
163 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
165 if ((l
= pa_parsehex(t
, cookie
, sizeof(cookie
))) == (size_t) -1) {
166 fprintf(stderr
, "Failed to parse cookie data\n");
170 if (pa_authkey_save(cookie_file
, cookie
, l
) < 0) {
171 fprintf(stderr
, "Failed to save cookie data\n");
180 struct pa_client_conf
*c
= pa_client_conf_new();
181 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
182 char hx
[PA_NATIVE_COOKIE_LENGTH
*2+1];
185 if (pa_client_conf_load(c
, NULL
) < 0) {
186 fprintf(stderr
, "Failed to load client configuration file.\n");
190 if (pa_client_conf_env(c
) < 0) {
191 fprintf(stderr
, "Failed to read environment configuration data.\n");
195 del_x11_prop(d
, "POLYP_ID");
198 set_x11_prop(d
, "POLYP_SERVER", c
->default_server
);
199 else if (c
->default_server
)
200 set_x11_prop(d
, "POLYP_SERVER", c
->default_server
);
203 if (!pa_get_fqdn(hn
, sizeof(hn
))) {
204 fprintf(stderr
, "Failed to get FQDN.\n");
208 set_x11_prop(d
, "POLYP_SERVER", hn
);
212 set_x11_prop(d
, "POLYP_SINK", sink
);
213 else if (c
->default_sink
)
214 set_x11_prop(d
, "POLYP_SINK", c
->default_sink
);
217 set_x11_prop(d
, "POLYP_SOURCE", source
);
218 if (c
->default_source
)
219 set_x11_prop(d
, "POLYP_SOURCE", c
->default_source
);
221 pa_client_conf_free(c
);
223 if (pa_authkey_load_auto(cookie_file
, cookie
, sizeof(cookie
)) < 0) {
224 fprintf(stderr
, "Failed to load cookie data\n");
228 set_x11_prop(d
, "POLYP_COOKIE", pa_hexstr(cookie
, sizeof(cookie
), hx
, sizeof(hx
)));
233 del_x11_prop(d
, "POLYP_SERVER");
234 del_x11_prop(d
, "POLYP_SINK");
235 del_x11_prop(d
, "POLYP_SOURCE");
236 del_x11_prop(d
, "POLYP_ID");
237 del_x11_prop(d
, "POLYP_COOKIE");
241 fprintf(stderr
, "No yet implemented.\n");