+ cookie_path = pa_modargs_get_value(ma, "cookie", NULL);
+ server = pa_xstrdup(pa_modargs_get_value(ma, "server", NULL));
+
+ if (automatic) {
+#ifdef HAVE_X11
+ /* Need an X11 connection to get root properties */
+ if (getenv("DISPLAY") != NULL) {
+ if (!(xcb = xcb_connect(getenv("DISPLAY"), NULL)))
+ pa_log("xcb_connect() failed");
+ else {
+ if (xcb_connection_has_error(xcb)) {
+ pa_log("xcb_connection_has_error() returned true");
+ xcb_disconnect(xcb);
+ xcb = NULL;
+ }
+ }
+ }
+#endif
+
+ /* Figure out the cookie the same way a normal client would */
+ if (!cookie_path)
+ cookie_path = getenv(ENV_COOKIE_FILE);
+
+#ifdef HAVE_X11
+ if (!cookie_path && xcb) {
+ char t[1024];
+ if (pa_x11_get_prop(xcb, 0, "PULSE_COOKIE", t, sizeof(t))) {
+ uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
+
+ if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie))
+ pa_log("Failed to parse cookie data");
+ else {
+ if (!(u->auth_cookie = pa_auth_cookie_create(u->core, cookie, sizeof(cookie))))
+ goto fail;
+ }
+ }
+ }
+#endif
+
+ /* Same thing for the server name */
+ if (!server)
+ server = pa_xstrdup(getenv(ENV_DEFAULT_SERVER));
+
+#ifdef HAVE_X11
+ if (!server && xcb) {
+ char t[1024];
+ if (pa_x11_get_prop(xcb, 0, "PULSE_SERVER", t, sizeof(t)))
+ server = pa_xstrdup(t);
+ }
+#endif
+
+ /* Also determine the default sink/source on the other server */
+#ifdef TUNNEL_SINK
+ if (!u->sink_name)
+ u->sink_name = pa_xstrdup(getenv(ENV_DEFAULT_SINK));
+
+#ifdef HAVE_X11
+ if (!u->sink_name && xcb) {
+ char t[1024];
+ if (pa_x11_get_prop(xcb, 0, "PULSE_SINK", t, sizeof(t)))
+ u->sink_name = pa_xstrdup(t);
+ }
+#endif
+#else
+ if (!u->source_name)
+ u->source_name = pa_xstrdup(getenv(ENV_DEFAULT_SOURCE));
+
+#ifdef HAVE_X11
+ if (!u->source_name && xcb) {
+ char t[1024];
+ if (pa_x11_get_prop(xcb, 0, "PULSE_SOURCE", t, sizeof(t)))
+ u->source_name = pa_xstrdup(t);
+ }
+#endif
+#endif
+ }
+
+ if (!cookie_path && !u->auth_cookie)
+ cookie_path = PA_NATIVE_COOKIE_FILE;
+
+ if (cookie_path) {
+ if (!(u->auth_cookie = pa_auth_cookie_get(u->core, cookie_path, true, PA_NATIVE_COOKIE_LENGTH)))
+ goto fail;
+ }
+
+ if (server) {
+ if (!(server_list = pa_strlist_parse(server))) {
+ pa_log("Invalid server specified.");
+ goto fail;
+ }
+ } else {
+ char *ufn;
+
+ if (!automatic) {
+ pa_log("No server specified.");
+ goto fail;
+ }
+
+ pa_log("No server address found. Attempting default local sockets.");
+
+ /* The system wide instance via PF_LOCAL */
+ server_list = pa_strlist_prepend(server_list, PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET);
+
+ /* The user instance via PF_LOCAL */
+ if ((ufn = pa_runtime_path(PA_NATIVE_DEFAULT_UNIX_SOCKET))) {
+ server_list = pa_strlist_prepend(server_list, ufn);
+ pa_xfree(ufn);
+ }