]> code.delx.au - pulseaudio/blobdiff - src/pulse/client-conf.c
client-conf: Remove redundant function parameters
[pulseaudio] / src / pulse / client-conf.c
index 2ead871f4a5d3fe01b33e6edf740ad058f769801..ea583a335d2b0e5366e271f086decb25a6745529 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
-#include <string.h>
 
 #include <pulse/xmalloc.h>
 
+#include <pulsecore/i18n.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/log.h>
@@ -56,18 +56,24 @@ static const pa_client_conf default_conf = {
     .default_sink = NULL,
     .default_source = NULL,
     .default_server = NULL,
-    .autospawn = TRUE,
-    .disable_shm = FALSE,
+    .default_dbus_server = NULL,
+    .autospawn = true,
+    .disable_shm = false,
     .cookie_file = NULL,
-    .cookie_valid = FALSE,
+    .cookie_valid = false,
+    .shm_size = 0,
+    .auto_connect_localhost = false,
+    .auto_connect_display = false
 };
 
+static int parse_cookie_file(pa_client_conf* c);
+
 pa_client_conf *pa_client_conf_new(void) {
     pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf));
 
     c->daemon_binary = pa_xstrdup(PA_BINARY);
-    c->extra_arguments = pa_xstrdup("--log-target=syslog --exit-idle-time=5");
-    c->cookie_file = pa_xstrdup(PA_NATIVE_COOKIE_FILE);
+    c->extra_arguments = pa_xstrdup("--log-target=syslog");
+    c->cookie_file = NULL;
 
     return c;
 }
@@ -79,57 +85,42 @@ void pa_client_conf_free(pa_client_conf *c) {
     pa_xfree(c->default_sink);
     pa_xfree(c->default_source);
     pa_xfree(c->default_server);
+    pa_xfree(c->default_dbus_server);
     pa_xfree(c->cookie_file);
     pa_xfree(c);
 }
 
-int pa_client_conf_load(pa_client_conf *c, const char *filename) {
+int pa_client_conf_load(pa_client_conf *c) {
     FILE *f = NULL;
     char *fn = NULL;
     int r = -1;
 
     /* Prepare the configuration parse table */
     pa_config_item table[] = {
-        { "daemon-binary",          pa_config_parse_string,  NULL },
-        { "extra-arguments",        pa_config_parse_string,  NULL },
-        { "default-sink",           pa_config_parse_string,  NULL },
-        { "default-source",         pa_config_parse_string,  NULL },
-        { "default-server",         pa_config_parse_string,  NULL },
-        { "autospawn",              pa_config_parse_bool,    NULL },
-        { "cookie-file",            pa_config_parse_string,  NULL },
-        { "disable-shm",            pa_config_parse_bool,    NULL },
-        { NULL,                     NULL,                    NULL },
+        { "daemon-binary",          pa_config_parse_string,   &c->daemon_binary, NULL },
+        { "extra-arguments",        pa_config_parse_string,   &c->extra_arguments, NULL },
+        { "default-sink",           pa_config_parse_string,   &c->default_sink, NULL },
+        { "default-source",         pa_config_parse_string,   &c->default_source, NULL },
+        { "default-server",         pa_config_parse_string,   &c->default_server, NULL },
+        { "default-dbus-server",    pa_config_parse_string,   &c->default_dbus_server, NULL },
+        { "autospawn",              pa_config_parse_bool,     &c->autospawn, NULL },
+        { "cookie-file",            pa_config_parse_string,   &c->cookie_file, NULL },
+        { "disable-shm",            pa_config_parse_bool,     &c->disable_shm, NULL },
+        { "enable-shm",             pa_config_parse_not_bool, &c->disable_shm, NULL },
+        { "shm-size-bytes",         pa_config_parse_size,     &c->shm_size, NULL },
+        { "auto-connect-localhost", pa_config_parse_bool,     &c->auto_connect_localhost, NULL },
+        { "auto-connect-display",   pa_config_parse_bool,     &c->auto_connect_display, NULL },
+        { NULL,                     NULL,                     NULL, NULL },
     };
 
-    table[0].data = &c->daemon_binary;
-    table[1].data = &c->extra_arguments;
-    table[2].data = &c->default_sink;
-    table[3].data = &c->default_source;
-    table[4].data = &c->default_server;
-    table[5].data = &c->autospawn;
-    table[6].data = &c->cookie_file;
-    table[7].data = &c->disable_shm;
-
-    if (filename) {
-
-        if (!(f = fopen(filename, "r"))) {
-            pa_log("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
+    if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn)))
+        if (errno != ENOENT)
             goto finish;
-        }
-
-        fn = pa_xstrdup(fn);
-
-    } else {
-
-        if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn)))
-            if (errno != ENOENT)
-                goto finish;
-    }
 
-    r = f ? pa_config_parse(fn, f, table, NULL) : 0;
+    r = f ? pa_config_parse(fn, f, table, NULL, NULL) : 0;
 
     if (!r)
-        r = pa_client_conf_load_cookie(c);
+        r = parse_cookie_file(c);
 
 finish:
     pa_xfree(fn);
@@ -156,6 +147,9 @@ int pa_client_conf_env(pa_client_conf *c) {
     if ((e = getenv(ENV_DEFAULT_SERVER))) {
         pa_xfree(c->default_server);
         c->default_server = pa_xstrdup(e);
+
+        /* We disable autospawning automatically if a specific server was set */
+        c->autospawn = false;
     }
 
     if ((e = getenv(ENV_DAEMON_BINARY))) {
@@ -164,26 +158,72 @@ int pa_client_conf_env(pa_client_conf *c) {
     }
 
     if ((e = getenv(ENV_COOKIE_FILE))) {
-        pa_xfree(c->cookie_file);
-        c->cookie_file = pa_xstrdup(e);
+        return pa_client_conf_load_cookie_from_file(c, e);
+    }
+
+    return 0;
+}
+
+static int parse_cookie_file(pa_client_conf* c) {
+    int k;
+
+    pa_assert(c);
 
-        return pa_client_conf_load_cookie(c);
+    c->cookie_valid = false;
+
+    if (c->cookie_file)
+        k = pa_authkey_load_auto(c->cookie_file, true, c->cookie, sizeof(c->cookie));
+    else {
+        k = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE, false, c->cookie, sizeof(c->cookie));
+
+        if (k < 0) {
+            k = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE_FALLBACK, false, c->cookie, sizeof(c->cookie));
+
+            if (k < 0)
+                k = pa_authkey_load_auto(PA_NATIVE_COOKIE_FILE, true, c->cookie, sizeof(c->cookie));
+        }
     }
 
+    if (k < 0)
+        return k;
+
+    c->cookie_valid = true;
     return 0;
 }
 
-int pa_client_conf_load_cookie(pa_client_conf* c) {
+int pa_client_conf_load_cookie_from_hex(pa_client_conf* c, const char *cookie_in_hex) {
+    uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
+
     pa_assert(c);
+    pa_assert(cookie_in_hex);
+
+    if (pa_parsehex(cookie_in_hex, cookie, sizeof(cookie)) != sizeof(cookie)) {
+        pa_log(_("Failed to parse cookie data"));
+        return -PA_ERR_INVALID;
+    }
 
-    if (!c->cookie_file)
-        return -1;
+    pa_xfree(c->cookie_file);
+    c->cookie_file = NULL;
+
+    return pa_client_conf_set_cookie(c, cookie, PA_NATIVE_COOKIE_LENGTH);
+}
+
+int pa_client_conf_load_cookie_from_file(pa_client_conf *c, const char *cookie_file_path) {
+    pa_assert(c);
+    pa_assert(cookie_file_path);
 
-    c->cookie_valid = FALSE;
+    pa_xfree(c->cookie_file);
+    c->cookie_file = pa_xstrdup(cookie_file_path);
+    return parse_cookie_file(c);
+}
 
-    if (pa_authkey_load_auto(c->cookie_file, c->cookie, sizeof(c->cookie)) < 0)
-        return -1;
+int pa_client_conf_set_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_size) {
+    pa_assert(c);
+    pa_assert(cookie);
 
-    c->cookie_valid = TRUE;
+    if (cookie_size != PA_NATIVE_COOKIE_LENGTH)
+        return -PA_ERR_INVALID;
+    memcpy(c->cookie, cookie, cookie_size);
+    c->cookie_valid = true;
     return 0;
 }