2004-09-17 19:45:44 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2004-09-17 19:45:44 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-09-17 19:45:44 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-09-17 19:45:44 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2006-01-10 17:51:06 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-17 19:45:44 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
2004-11-04 21:27:12 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
#include <pulsecore/core-error.h>
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/conf-parser.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/authkey.h>
|
2006-02-16 19:19:58 +00:00
|
|
|
|
2006-02-17 12:10:58 +00:00
|
|
|
#include "client-conf.h"
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#define DEFAULT_CLIENT_CONFIG_FILE PA_DEFAULT_CONFIG_DIR PA_PATH_SEP "client.conf"
|
2006-07-19 21:48:35 +00:00
|
|
|
#define DEFAULT_CLIENT_CONFIG_FILE_USER "client.conf"
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2006-06-19 23:56:54 +00:00
|
|
|
#define ENV_CLIENT_CONFIG_FILE "PULSE_CLIENTCONFIG"
|
|
|
|
|
#define ENV_DEFAULT_SINK "PULSE_SINK"
|
|
|
|
|
#define ENV_DEFAULT_SOURCE "PULSE_SOURCE"
|
|
|
|
|
#define ENV_DEFAULT_SERVER "PULSE_SERVER"
|
|
|
|
|
#define ENV_DAEMON_BINARY "PULSE_BINARY"
|
|
|
|
|
#define ENV_COOKIE_FILE "PULSE_COOKIE"
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static const pa_client_conf default_conf = {
|
2004-09-17 19:45:44 +00:00
|
|
|
.daemon_binary = NULL,
|
|
|
|
|
.extra_arguments = NULL,
|
|
|
|
|
.default_sink = NULL,
|
|
|
|
|
.default_source = NULL,
|
|
|
|
|
.default_server = NULL,
|
2007-11-01 00:33:14 +00:00
|
|
|
.autospawn = FALSE,
|
|
|
|
|
.disable_shm = FALSE,
|
2004-11-09 23:19:42 +00:00
|
|
|
.cookie_file = NULL,
|
2007-11-01 00:33:14 +00:00
|
|
|
.cookie_valid = FALSE,
|
2004-09-17 19:45:44 +00:00
|
|
|
};
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_client_conf *pa_client_conf_new(void) {
|
|
|
|
|
pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf));
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-07-19 17:44:19 +00:00
|
|
|
c->daemon_binary = pa_xstrdup(PA_BINARY);
|
2004-09-17 20:43:40 +00:00
|
|
|
c->extra_arguments = pa_xstrdup("--log-target=syslog --exit-idle-time=5");
|
2004-11-09 23:19:42 +00:00
|
|
|
c->cookie_file = pa_xstrdup(PA_NATIVE_COOKIE_FILE);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-09-17 19:45:44 +00:00
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_conf_free(pa_client_conf *c) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
2004-09-17 19:45:44 +00:00
|
|
|
pa_xfree(c->daemon_binary);
|
|
|
|
|
pa_xfree(c->extra_arguments);
|
|
|
|
|
pa_xfree(c->default_sink);
|
|
|
|
|
pa_xfree(c->default_source);
|
|
|
|
|
pa_xfree(c->default_server);
|
2004-11-09 23:19:42 +00:00
|
|
|
pa_xfree(c->cookie_file);
|
2004-09-17 19:45:44 +00:00
|
|
|
pa_xfree(c);
|
|
|
|
|
}
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
int pa_client_conf_load(pa_client_conf *c, const char *filename) {
|
2004-11-04 21:27:12 +00:00
|
|
|
FILE *f = NULL;
|
|
|
|
|
char *fn = NULL;
|
|
|
|
|
int r = -1;
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* Prepare the configuration parse table */
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_config_item table[] = {
|
2004-09-18 12:28:29 +00:00
|
|
|
{ "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 },
|
2004-11-09 23:19:42 +00:00
|
|
|
{ "cookie-file", pa_config_parse_string, NULL },
|
2006-08-19 01:18:30 +00:00
|
|
|
{ "disable-shm", pa_config_parse_bool, NULL },
|
2004-09-17 19:45:44 +00:00
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
|
};
|
|
|
|
|
|
2004-09-18 12:28:29 +00:00
|
|
|
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;
|
2004-11-09 23:19:42 +00:00
|
|
|
table[6].data = &c->cookie_file;
|
2006-08-19 01:18:30 +00:00
|
|
|
table[7].data = &c->disable_shm;
|
2004-09-18 12:28:29 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (filename) {
|
2004-11-04 21:27:12 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
if (!(f = fopen(filename, "r"))) {
|
|
|
|
|
pa_log("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
|
|
|
|
|
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;
|
2004-09-17 19:45:44 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-08 23:48:19 +00:00
|
|
|
r = f ? pa_config_parse(fn, f, table, NULL) : 0;
|
2004-11-04 21:27:12 +00:00
|
|
|
|
2004-11-09 23:19:42 +00:00
|
|
|
if (!r)
|
|
|
|
|
r = pa_client_conf_load_cookie(c);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-04 21:27:12 +00:00
|
|
|
finish:
|
|
|
|
|
pa_xfree(fn);
|
2004-09-17 19:45:44 +00:00
|
|
|
|
2004-11-04 21:27:12 +00:00
|
|
|
if (f)
|
|
|
|
|
fclose(f);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-09-17 19:45:44 +00:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
int pa_client_conf_env(pa_client_conf *c) {
|
2004-09-17 19:45:44 +00:00
|
|
|
char *e;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-09-17 19:45:44 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-09-17 19:45:44 +00:00
|
|
|
if ((e = getenv(ENV_DAEMON_BINARY))) {
|
|
|
|
|
pa_xfree(c->daemon_binary);
|
|
|
|
|
c->daemon_binary = pa_xstrdup(e);
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-09 23:19:42 +00:00
|
|
|
if ((e = getenv(ENV_COOKIE_FILE))) {
|
|
|
|
|
pa_xfree(c->cookie_file);
|
|
|
|
|
c->cookie_file = pa_xstrdup(e);
|
|
|
|
|
|
|
|
|
|
return pa_client_conf_load_cookie(c);
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-09-17 19:45:44 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2004-11-09 23:19:42 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
int pa_client_conf_load_cookie(pa_client_conf* c) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
2004-11-09 23:19:42 +00:00
|
|
|
|
2007-11-01 00:33:14 +00:00
|
|
|
c->cookie_valid = FALSE;
|
2004-11-09 23:19:42 +00:00
|
|
|
|
|
|
|
|
if (!c->cookie_file)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (pa_authkey_load_auto(c->cookie_file, c->cookie, sizeof(c->cookie)) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-01 00:33:14 +00:00
|
|
|
c->cookie_valid = TRUE;
|
2004-11-09 23:19:42 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|