mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
client-conf: Move x11 and env loading to pa_client_conf_load()
This simplifies the code a bit.
This commit is contained in:
parent
067e61cb66
commit
5141188ca8
6 changed files with 58 additions and 64 deletions
|
|
@ -59,9 +59,6 @@
|
|||
#endif
|
||||
|
||||
#include <pulse/client-conf.h>
|
||||
#ifdef HAVE_X11
|
||||
#include <pulse/client-conf-x11.h>
|
||||
#endif
|
||||
#include <pulse/mainloop.h>
|
||||
#include <pulse/mainloop-signal.h>
|
||||
#include <pulse/timeval.h>
|
||||
|
|
@ -325,11 +322,7 @@ static char *check_configured_address(void) {
|
|||
char *default_server = NULL;
|
||||
pa_client_conf *c = pa_client_conf_new();
|
||||
|
||||
pa_client_conf_load(c);
|
||||
#ifdef HAVE_X11
|
||||
pa_client_conf_from_x11(c);
|
||||
#endif
|
||||
pa_client_conf_env(c);
|
||||
pa_client_conf_load(c, true, true);
|
||||
|
||||
if (c->default_server && *c->default_server)
|
||||
default_server = pa_xstrdup(c->default_server);
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ static enum get_address_result_t get_address(pa_server_type_t server_type, char
|
|||
|
||||
*address = NULL;
|
||||
|
||||
pa_client_conf_load(conf);
|
||||
pa_client_conf_load(conf, false, false);
|
||||
|
||||
if (conf->default_dbus_server)
|
||||
*address = pa_xstrdup(conf->default_dbus_server);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))) {
|
||||
|
||||
|
|
|
|||
|
|
@ -152,8 +152,7 @@ int main(int argc, char *argv[]) {
|
|||
char hx[PA_NATIVE_COOKIE_LENGTH*2+1];
|
||||
assert(conf);
|
||||
|
||||
pa_client_conf_load(conf);
|
||||
pa_client_conf_env(conf);
|
||||
pa_client_conf_load(conf, false, true);
|
||||
|
||||
pa_x11_del_prop(xcb, screen, "PULSE_SERVER");
|
||||
pa_x11_del_prop(xcb, screen, "PULSE_SINK");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue