This file is part of polypaudio.
polypaudio is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
+ it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with polypaudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
+#include <errno.h>
+#include <string.h>
#include "client-conf.h"
#include "xmalloc.h"
#include "log.h"
-#include "confparser.h"
+#include "conf-parser.h"
#include "util.h"
+#include "authkey.h"
-#ifndef DEFAULT_CLIENT_CONFIG_FILE
-#define DEFAULT_CLIENT_CONFIG_FILE "/etc/polypaudio/client.conf"
+#ifndef DEFAULT_CONFIG_DIR
+#define DEFAULT_CONFIG_DIR "/etc/polypaudio"
#endif
-#ifndef DEFAULT_CLIENT_CONFIG_FILE_USER
+#define DEFAULT_CLIENT_CONFIG_FILE DEFAULT_CONFIG_DIR"/client.conf"
#define DEFAULT_CLIENT_CONFIG_FILE_USER ".polypaudio/client.conf"
-#endif
#define ENV_CLIENT_CONFIG_FILE "POLYP_CLIENTCONFIG"
#define ENV_DEFAULT_SINK "POLYP_SINK"
#define ENV_DEFAULT_SOURCE "POLYP_SOURCE"
#define ENV_DEFAULT_SERVER "POLYP_SERVER"
#define ENV_DAEMON_BINARY "POLYP_BINARY"
-
+#define ENV_COOKIE_FILE "POLYP_COOKIE"
static const struct pa_client_conf default_conf = {
.daemon_binary = NULL,
.default_sink = NULL,
.default_source = NULL,
.default_server = NULL,
- .autospawn = 0
+ .autospawn = 0,
+ .cookie_file = NULL,
+ .cookie_valid = 0
};
struct pa_client_conf *pa_client_conf_new(void) {
struct pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf));
+
+
c->daemon_binary = pa_xstrdup(POLYPAUDIO_BINARY);
- c->extra_arguments = pa_xstrdup("--daemonize=yes --log-target=syslog");
+ c->extra_arguments = pa_xstrdup("--log-target=syslog --exit-idle-time=5");
+
+ c->cookie_file = pa_xstrdup(PA_NATIVE_COOKIE_FILE);
return c;
}
pa_xfree(c->default_sink);
pa_xfree(c->default_source);
pa_xfree(c->default_server);
+ pa_xfree(c->cookie_file);
pa_xfree(c);
}
int pa_client_conf_load(struct pa_client_conf *c, const char *filename) {
- char *def = NULL;
- int r;
-
- const struct pa_config_item table[] = {
- { "daemon-binary", pa_config_parse_string, &c->daemon_binary },
- { "extra-arguments", pa_config_parse_string, &c->extra_arguments },
- { "default-sink", pa_config_parse_string, &c->default_sink },
- { "default-source", pa_config_parse_string, &c->default_source },
- { "default-server", pa_config_parse_string, &c->default_server },
- { "autospawn", pa_config_parse_bool, &c->autospawn },
+ FILE *f = NULL;
+ char *fn = NULL;
+ int r = -1;
+
+ struct 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 },
{ NULL, NULL, NULL },
};
- if (!filename)
- filename = getenv(ENV_CLIENT_CONFIG_FILE);
-
- if (!filename) {
- char *h;
-
- if ((h = getenv("HOME"))) {
- def = pa_sprintf_malloc("%s/%s", h, DEFAULT_CLIENT_CONFIG_FILE_USER);
-
- if (!access(def, F_OK))
- filename = def;
- else {
- pa_xfree(def);
- def = 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;
+
+ f = filename ?
+ fopen((fn = pa_xstrdup(filename)), "r") :
+ pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn);
+
+ if (!f && errno != EINTR) {
+ pa_log(__FILE__": WARNING: failed to open configuration file '%s': %s\n", filename, strerror(errno));
+ goto finish;
}
+
+ r = f ? pa_config_parse(fn, f, table, NULL) : 0;
- if (!filename)
- filename = DEFAULT_CLIENT_CONFIG_FILE;
+ if (!r)
+ r = pa_client_conf_load_cookie(c);
+
+
+finish:
+ pa_xfree(fn);
+
+ if (f)
+ fclose(f);
- r = pa_config_parse(filename, table, NULL);
- pa_xfree(def);
return r;
}
c->daemon_binary = pa_xstrdup(e);
}
+ if ((e = getenv(ENV_COOKIE_FILE))) {
+ pa_xfree(c->cookie_file);
+ c->cookie_file = pa_xstrdup(e);
+
+ return pa_client_conf_load_cookie(c);
+ }
+
+ return 0;
+}
+
+int pa_client_conf_load_cookie(struct pa_client_conf* c) {
+ assert(c);
+
+ c->cookie_valid = 0;
+
+ if (!c->cookie_file)
+ return -1;
+
+ if (pa_authkey_load_auto(c->cookie_file, c->cookie, sizeof(c->cookie)) < 0)
+ return -1;
+
+ c->cookie_valid = 1;
return 0;
}
+