]>
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", pa_path_get_filename(argv
[0]));
106 cookie_file
= optarg
;
118 fprintf(stderr
, "Failed to parse command line.\n");
123 if (!(d
= XOpenDisplay(dname
))) {
124 pa_log(__FILE__
": XOpenDisplay() failed\n");
131 if (!get_x11_prop(d
, "POLYP_SERVER", t
, sizeof(t
)))
134 printf("Server: %s\n", t
);
135 if (get_x11_prop(d
, "POLYP_SOURCE", t
, sizeof(t
)))
136 printf("Source: %s\n", t
);
137 if (get_x11_prop(d
, "POLYP_SINK", t
, sizeof(t
)))
138 printf("Sink: %s\n", t
);
139 if (get_x11_prop(d
, "POLYP_COOKIE", t
, sizeof(t
)))
140 printf("Cookie: %s\n", t
);
147 if (!get_x11_prop(d
, "POLYP_SERVER", t
, sizeof(t
)))
150 printf("POLYP_SERVER='%s'\nexport POLYP_SERVER\n", t
);
152 if (get_x11_prop(d
, "POLYP_SOURCE", t
, sizeof(t
)))
153 printf("POLYP_SOURCE='%s'\nexport POLYP_SOURCE\n", t
);
154 if (get_x11_prop(d
, "POLYP_SINK", t
, sizeof(t
)))
155 printf("POLYP_SINK='%s'\nexport POLYP_SINK\n", t
);
157 if (get_x11_prop(d
, "POLYP_COOKIE", t
, sizeof(t
))) {
158 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
160 if ((l
= pa_parsehex(t
, cookie
, sizeof(cookie
))) == (size_t) -1) {
161 fprintf(stderr
, "Failed to parse cookie data\n");
165 if (pa_authkey_save(cookie_file
, cookie
, l
) < 0) {
166 fprintf(stderr
, "Failed to save cookie data\n");
175 struct pa_client_conf
*c
= pa_client_conf_new();
176 uint8_t cookie
[PA_NATIVE_COOKIE_LENGTH
];
177 char hx
[PA_NATIVE_COOKIE_LENGTH
*2+1];
180 if (pa_client_conf_load(c
, NULL
) < 0) {
181 fprintf(stderr
, "Failed to load client configuration file.\n");
185 if (pa_client_conf_env(c
) < 0) {
186 fprintf(stderr
, "Failed to read environment configuration data.\n");
190 del_x11_prop(d
, "POLYP_ID");
193 set_x11_prop(d
, "POLYP_SERVER", c
->default_server
);
194 else if (c
->default_server
)
195 set_x11_prop(d
, "POLYP_SERVER", c
->default_server
);
198 pa_get_host_name(hn
, sizeof(hn
));
199 set_x11_prop(d
, "POLYP_SERVER", hn
);
203 set_x11_prop(d
, "POLYP_SINK", sink
);
204 else if (c
->default_sink
)
205 set_x11_prop(d
, "POLYP_SINK", c
->default_sink
);
208 set_x11_prop(d
, "POLYP_SOURCE", source
);
209 if (c
->default_source
)
210 set_x11_prop(d
, "POLYP_SOURCE", c
->default_source
);
212 pa_client_conf_free(c
);
214 if (pa_authkey_load_auto(cookie_file
, cookie
, sizeof(cookie
)) < 0) {
215 fprintf(stderr
, "Failed to load cookie data\n");
219 set_x11_prop(d
, "POLYP_COOKIE", pa_hexstr(cookie
, sizeof(cookie
), hx
, sizeof(hx
)));
224 del_x11_prop(d
, "POLYP_SERVER");
225 del_x11_prop(d
, "POLYP_SINK");
226 del_x11_prop(d
, "POLYP_SOURCE");
227 del_x11_prop(d
, "POLYP_ID");
228 del_x11_prop(d
, "POLYP_COOKIE");
232 fprintf(stderr
, "No yet implemented.\n");