summaryrefslogtreecommitdiff
path: root/src/pulse
diff options
context:
space:
mode:
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>2014-06-08 16:32:54 +0300
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>2014-06-24 13:13:50 +0300
commit5141188ca8659b19a877cec6c7e6892804a85e26 (patch)
tree87513964ddc8614c7588b5b88c1d9aa48f870e6b /src/pulse
parent067e61cb668c426e3a03c54cead2e2102485d5f7 (diff)
client-conf: Move x11 and env loading to pa_client_conf_load()
This simplifies the code a bit.
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/client-conf.c88
-rw-r--r--src/pulse/client-conf.h11
-rw-r--r--src/pulse/context.c9
3 files changed, 55 insertions, 53 deletions
diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
index db54743f7..8252419d9 100644
--- a/src/pulse/client-conf.c
+++ b/src/pulse/client-conf.c
@@ -40,6 +40,10 @@
#include "client-conf.h"
+#ifdef HAVE_X11
+#include <client-conf-x11.h>
+#endif
+
#define DEFAULT_CLIENT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "client.conf"
#define DEFAULT_CLIENT_CONFIG_FILE_USER "client.conf"
@@ -91,7 +95,39 @@ void pa_client_conf_free(pa_client_conf *c) {
pa_xfree(c);
}
-void pa_client_conf_load(pa_client_conf *c) {
+static void load_env(pa_client_conf *c) {
+ char *e;
+
+ if ((e = getenv(ENV_DEFAULT_SINK))) {
+ pa_xfree(c->default_sink);
+ c->default_sink = pa_xstrdup(e);
+ }
+
+ if ((e = getenv(ENV_DEFAULT_SOURCE))) {
+ pa_xfree(c->default_source);
+ c->default_source = pa_xstrdup(e);
+ }
+
+ 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))) {
+ pa_xfree(c->daemon_binary);
+ c->daemon_binary = pa_xstrdup(e);
+ }
+
+ if ((e = getenv(ENV_COOKIE_FILE)) && *e) {
+ pa_xfree(c->cookie_file_from_env);
+ c->cookie_file_from_env = pa_xstrdup(e);
+ }
+}
+
+void pa_client_conf_load(pa_client_conf *c, bool load_from_x11, bool load_from_env) {
FILE *f = NULL;
char *fn = NULL;
@@ -114,12 +150,20 @@ void pa_client_conf_load(pa_client_conf *c) {
};
f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn);
- if (!f)
- return;
+ if (f) {
+ pa_config_parse(fn, f, table, NULL, NULL);
+ pa_xfree(fn);
+ fclose(f);
+ }
- pa_config_parse(fn, f, table, NULL, NULL);
- pa_xfree(fn);
- fclose(f);
+ if (load_from_x11) {
+#ifdef HAVE_X11
+ pa_client_conf_from_x11(c);
+#endif
+ }
+
+ if (load_from_env)
+ load_env(c);
}
int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length) {
@@ -183,38 +227,6 @@ int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie
return -1;
}
-void pa_client_conf_env(pa_client_conf *c) {
- char *e;
-
- if ((e = getenv(ENV_DEFAULT_SINK))) {
- pa_xfree(c->default_sink);
- c->default_sink = pa_xstrdup(e);
- }
-
- if ((e = getenv(ENV_DEFAULT_SOURCE))) {
- pa_xfree(c->default_source);
- c->default_source = pa_xstrdup(e);
- }
-
- 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))) {
- pa_xfree(c->daemon_binary);
- c->daemon_binary = pa_xstrdup(e);
- }
-
- if ((e = getenv(ENV_COOKIE_FILE)) && *e) {
- pa_xfree(c->cookie_file_from_env);
- c->cookie_file_from_env = pa_xstrdup(e);
- }
-}
-
void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file) {
pa_assert(c);
pa_assert(!cookie_file || *cookie_file);
diff --git a/src/pulse/client-conf.h b/src/pulse/client-conf.h
index 05a7025c3..3c7fd7de3 100644
--- a/src/pulse/client-conf.h
+++ b/src/pulse/client-conf.h
@@ -47,9 +47,10 @@ typedef struct pa_client_conf {
pa_client_conf *pa_client_conf_new(void);
void pa_client_conf_free(pa_client_conf *c);
-/* Load the configuration data from the client configuration file, overwriting
- * the current settings in *c. */
-void pa_client_conf_load(pa_client_conf *c);
+/* Load the configuration data from the client configuration file and
+ * optionally from X11 and/or environment variables, overwriting the current
+ * settings in *c. */
+void pa_client_conf_load(pa_client_conf *c, bool load_from_x11, bool load_from_env);
/* Load the cookie from the cookie sources specified in the configuration, or
* if nothing is specified or none of the sources work, load the cookie from
@@ -57,10 +58,6 @@ void pa_client_conf_load(pa_client_conf *c);
* returns a negative value and initializes the cookie to all-zeroes. */
int pa_client_conf_load_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_length);
-/* Load the configuration data from the environment of the current
- process, overwriting the current settings in *c. */
-void pa_client_conf_env(pa_client_conf *c);
-
void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file);
#endif
diff --git a/src/pulse/context.c b/src/pulse/context.c
index ce19d91ea..d9080234a 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -48,9 +48,6 @@
#include <pulse/timeval.h>
#include <pulse/fork-detect.h>
#include <pulse/client-conf.h>
-#ifdef HAVE_X11
-#include <pulse/client-conf-x11.h>
-#endif
#include <pulsecore/core-error.h>
#include <pulsecore/i18n.h>
@@ -166,11 +163,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
#endif
c->conf = pa_client_conf_new();
- pa_client_conf_load(c->conf);
-#ifdef HAVE_X11
- pa_client_conf_from_x11(c->conf);
-#endif
- pa_client_conf_env(c->conf);
+ pa_client_conf_load(c->conf, true, true);
if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) {