client-conf: Move x11 and env loading to pa_client_conf_load()

This simplifies the code a bit.
This commit is contained in:
Tanu Kaskinen 2014-06-08 16:32:54 +03:00
parent 067e61cb66
commit 5141188ca8
6 changed files with 58 additions and 64 deletions

View file

@ -59,9 +59,6 @@
#endif #endif
#include <pulse/client-conf.h> #include <pulse/client-conf.h>
#ifdef HAVE_X11
#include <pulse/client-conf-x11.h>
#endif
#include <pulse/mainloop.h> #include <pulse/mainloop.h>
#include <pulse/mainloop-signal.h> #include <pulse/mainloop-signal.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
@ -325,11 +322,7 @@ static char *check_configured_address(void) {
char *default_server = NULL; char *default_server = NULL;
pa_client_conf *c = pa_client_conf_new(); pa_client_conf *c = pa_client_conf_new();
pa_client_conf_load(c); pa_client_conf_load(c, true, true);
#ifdef HAVE_X11
pa_client_conf_from_x11(c);
#endif
pa_client_conf_env(c);
if (c->default_server && *c->default_server) if (c->default_server && *c->default_server)
default_server = pa_xstrdup(c->default_server); default_server = pa_xstrdup(c->default_server);

View file

@ -125,7 +125,7 @@ static enum get_address_result_t get_address(pa_server_type_t server_type, char
*address = NULL; *address = NULL;
pa_client_conf_load(conf); pa_client_conf_load(conf, false, false);
if (conf->default_dbus_server) if (conf->default_dbus_server)
*address = pa_xstrdup(conf->default_dbus_server); *address = pa_xstrdup(conf->default_dbus_server);

View file

@ -40,6 +40,10 @@
#include "client-conf.h" #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 PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "client.conf"
#define DEFAULT_CLIENT_CONFIG_FILE_USER "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); 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; FILE *f = NULL;
char *fn = 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); f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn);
if (!f) if (f) {
return; pa_config_parse(fn, f, table, NULL, NULL);
pa_xfree(fn);
fclose(f);
}
pa_config_parse(fn, f, table, NULL, NULL); if (load_from_x11) {
pa_xfree(fn); #ifdef HAVE_X11
fclose(f); 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) { 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; 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) { void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file) {
pa_assert(c); pa_assert(c);
pa_assert(!cookie_file || *cookie_file); pa_assert(!cookie_file || *cookie_file);

View file

@ -47,9 +47,10 @@ typedef struct pa_client_conf {
pa_client_conf *pa_client_conf_new(void); pa_client_conf *pa_client_conf_new(void);
void pa_client_conf_free(pa_client_conf *c); void pa_client_conf_free(pa_client_conf *c);
/* Load the configuration data from the client configuration file, overwriting /* Load the configuration data from the client configuration file and
* the current settings in *c. */ * optionally from X11 and/or environment variables, overwriting the current
void pa_client_conf_load(pa_client_conf *c); * 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 /* 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 * 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. */ * 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); 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); void pa_client_conf_set_cookie_file_from_application(pa_client_conf *c, const char *cookie_file);
#endif #endif

View file

@ -48,9 +48,6 @@
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/fork-detect.h> #include <pulse/fork-detect.h>
#include <pulse/client-conf.h> #include <pulse/client-conf.h>
#ifdef HAVE_X11
#include <pulse/client-conf-x11.h>
#endif
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/i18n.h> #include <pulsecore/i18n.h>
@ -166,11 +163,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
#endif #endif
c->conf = pa_client_conf_new(); c->conf = pa_client_conf_new();
pa_client_conf_load(c->conf); pa_client_conf_load(c->conf, true, true);
#ifdef HAVE_X11
pa_client_conf_from_x11(c->conf);
#endif
pa_client_conf_env(c->conf);
if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) { if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) {

View file

@ -152,8 +152,7 @@ int main(int argc, char *argv[]) {
char hx[PA_NATIVE_COOKIE_LENGTH*2+1]; char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
assert(conf); assert(conf);
pa_client_conf_load(conf); pa_client_conf_load(conf, false, true);
pa_client_conf_env(conf);
pa_x11_del_prop(xcb, screen, "PULSE_SERVER"); pa_x11_del_prop(xcb, screen, "PULSE_SERVER");
pa_x11_del_prop(xcb, screen, "PULSE_SINK"); pa_x11_del_prop(xcb, screen, "PULSE_SINK");