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 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 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 Lesser 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>
34 #include <polypcore/util.h>
35 #include <polypcore/log.h>
36 #include <polypcore/authkey.h>
37 #include <polypcore/native-common.h>
38 #include <polypcore/x11prop.h>
39 #include <polyp/client-conf.h>
41 int main(int argc, char *argv[]) {
42 const char *dname = NULL, *sink = NULL, *source = NULL, *server = NULL, *cookie_file = PA_NATIVE_COOKIE_FILE;
45 enum { DUMP, EXPORT, IMPORT, REMOVE } mode = DUMP;
47 while ((c = getopt(argc, argv, "deiD:S:O:I:c:hr")) != -1) {
53 printf("%s [-D display] [-S server] [-O sink] [-I source] [-c file] [-d|-e|-i|-r]\n\n"
54 " -d Show current Polypaudio data attached to X11 display (default)\n"
55 " -e Export local Polypaudio data to X11 display\n"
56 " -i Import Polypaudio data from X11 display to local environment variables and cookie file.\n"
57 " -r Remove Polypaudio data from X11 display\n",
58 pa_path_get_filename(argv[0]));
86 fprintf(stderr, "Failed to parse command line.\n");
91 if (!(d = XOpenDisplay(dname))) {
92 pa_log(__FILE__": XOpenDisplay() failed\n");
99 if (pa_x11_get_prop(d, "POLYP_SERVER", t, sizeof(t)))
100 printf("Server: %s\n", t);
101 if (pa_x11_get_prop(d, "POLYP_SOURCE", t, sizeof(t)))
102 printf("Source: %s\n", t);
103 if (pa_x11_get_prop(d, "POLYP_SINK", t, sizeof(t)))
104 printf("Sink: %s\n", t);
105 if (pa_x11_get_prop(d, "POLYP_COOKIE", t, sizeof(t)))
106 printf("Cookie: %s\n", t);
113 if (pa_x11_get_prop(d, "POLYP_SERVER", t, sizeof(t)))
114 printf("POLYP_SERVER='%s'\nexport POLYP_SERVER\n", t);
115 if (pa_x11_get_prop(d, "POLYP_SOURCE", t, sizeof(t)))
116 printf("POLYP_SOURCE='%s'\nexport POLYP_SOURCE\n", t);
117 if (pa_x11_get_prop(d, "POLYP_SINK", t, sizeof(t)))
118 printf("POLYP_SINK='%s'\nexport POLYP_SINK\n", t);
120 if (pa_x11_get_prop(d, "POLYP_COOKIE", t, sizeof(t))) {
121 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
123 if ((l = pa_parsehex(t, cookie, sizeof(cookie))) != sizeof(cookie)) {
124 fprintf(stderr, "Failed to parse cookie data\n");
128 if (pa_authkey_save(cookie_file, cookie, l) < 0) {
129 fprintf(stderr, "Failed to save cookie data\n");
138 pa_client_conf *conf = pa_client_conf_new();
139 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
140 char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
143 if (pa_client_conf_load(conf, NULL) < 0) {
144 fprintf(stderr, "Failed to load client configuration file.\n");
148 if (pa_client_conf_env(conf) < 0) {
149 fprintf(stderr, "Failed to read environment configuration data.\n");
153 pa_x11_del_prop(d, "POLYP_SERVER");
154 pa_x11_del_prop(d, "POLYP_SINK");
155 pa_x11_del_prop(d, "POLYP_SOURCE");
156 pa_x11_del_prop(d, "POLYP_ID");
157 pa_x11_del_prop(d, "POLYP_COOKIE");
160 pa_x11_set_prop(d, "POLYP_SERVER", server);
161 else if (conf->default_server)
162 pa_x11_set_prop(d, "POLYP_SERVER", conf->default_server);
165 if (!pa_get_fqdn(hn, sizeof(hn))) {
166 fprintf(stderr, "Failed to get FQDN.\n");
170 pa_x11_set_prop(d, "POLYP_SERVER", hn);
174 pa_x11_set_prop(d, "POLYP_SINK", sink);
175 else if (conf->default_sink)
176 pa_x11_set_prop(d, "POLYP_SINK", conf->default_sink);
179 pa_x11_set_prop(d, "POLYP_SOURCE", source);
180 if (conf->default_source)
181 pa_x11_set_prop(d, "POLYP_SOURCE", conf->default_source);
183 pa_client_conf_free(conf);
185 if (pa_authkey_load_auto(cookie_file, cookie, sizeof(cookie)) < 0) {
186 fprintf(stderr, "Failed to load cookie data\n");
190 pa_x11_set_prop(d, "POLYP_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
195 pa_x11_del_prop(d, "POLYP_SERVER");
196 pa_x11_del_prop(d, "POLYP_SINK");
197 pa_x11_del_prop(d, "POLYP_SOURCE");
198 pa_x11_del_prop(d, "POLYP_ID");
199 pa_x11_del_prop(d, "POLYP_COOKIE");
203 fprintf(stderr, "No yet implemented.\n");