From f0779587478f5c4012dc5c9debc8dc562c81f967 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 17 Sep 2004 20:06:17 +0000 Subject: rename some stuff git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@212 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/Makefile.am | 4 +- polyp/client-conf.c | 138 +++++++++++++++++++++++++++ polyp/client-conf.h | 36 ++++++++ polyp/cmdline.c | 2 +- polyp/cmdline.h | 4 +- polyp/conf.c | 231 ---------------------------------------------- polyp/conf.h | 57 ------------ polyp/config-client.c | 138 --------------------------- polyp/config-client.h | 36 -------- polyp/daemon-conf.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++ polyp/daemon-conf.h | 58 ++++++++++++ polyp/dumpmodules.c | 4 +- polyp/dumpmodules.h | 4 +- polyp/main.c | 15 +-- polyp/polyplib-context.c | 2 +- polyp/polyplib-internal.h | 2 +- 16 files changed, 483 insertions(+), 479 deletions(-) create mode 100644 polyp/client-conf.c create mode 100644 polyp/client-conf.h delete mode 100644 polyp/conf.c delete mode 100644 polyp/conf.h delete mode 100644 polyp/config-client.c delete mode 100644 polyp/config-client.h create mode 100644 polyp/daemon-conf.c create mode 100644 polyp/daemon-conf.h diff --git a/polyp/Makefile.am b/polyp/Makefile.am index 76f4f2c7..9dde211d 100644 --- a/polyp/Makefile.am +++ b/polyp/Makefile.am @@ -157,7 +157,7 @@ polypaudio_SOURCES = idxset.c idxset.h \ log.c log.h \ gcc-printf.h \ modinfo.c modinfo.h \ - conf.c conf.h \ + daemon-conf.c daemon-conf.h \ dumpmodules.c dumpmodules.h \ conparser.h confparser.c @@ -334,7 +334,7 @@ libpolyp_@PA_MAJORMINOR@_la_SOURCES = polyplib.h \ llist.h \ log.c log.h \ gcc-printf.h \ - config-client.c config-client.h \ + client-conf.c client-conf.h \ confparser.c confparser.h libpolyp_@PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) diff --git a/polyp/client-conf.c b/polyp/client-conf.c new file mode 100644 index 00000000..cfc257c6 --- /dev/null +++ b/polyp/client-conf.c @@ -0,0 +1,138 @@ +/* $Id$ */ + +/*** + 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 + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + 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. + + You should have received a copy of the GNU 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 +#include +#include + +#include "client-conf.h" +#include "xmalloc.h" +#include "log.h" +#include "confparser.h" +#include "util.h" + +#ifndef DEFAULT_CLIENT_CONFIG_FILE +#define DEFAULT_CLIENT_CONFIG_FILE "/etc/polypaudio/client.conf" +#endif + +#ifndef DEFAULT_CLIENT_CONFIG_FILE_USER +#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" + + +static const struct pa_client_conf default_conf = { + .daemon_binary = NULL, + .extra_arguments = NULL, + .default_sink = NULL, + .default_source = NULL, + .default_server = NULL, + .autospawn = 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"); + + return c; +} + +void pa_client_conf_free(struct pa_client_conf *c) { + assert(c); + 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); + 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 }, + { 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; + } + } + } + + if (!filename) + filename = DEFAULT_CLIENT_CONFIG_FILE; + + r = pa_config_parse(filename, table, NULL); + pa_xfree(def); + return r; +} + +int pa_client_conf_env(struct 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); + } + + if ((e = getenv(ENV_DAEMON_BINARY))) { + pa_xfree(c->daemon_binary); + c->daemon_binary = pa_xstrdup(e); + } + + return 0; +} diff --git a/polyp/client-conf.h b/polyp/client-conf.h new file mode 100644 index 00000000..6fd4a20d --- /dev/null +++ b/polyp/client-conf.h @@ -0,0 +1,36 @@ +#ifndef fooclientconfhfoo +#define fooclientconfhfoo + +/* $Id$ */ + +/*** + 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 + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + 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. + + You should have received a copy of the GNU 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. +***/ + +struct pa_client_conf { + char *daemon_binary, *extra_arguments, *default_sink, *default_source, *default_server; + int autospawn; +}; + +struct pa_client_conf *pa_client_conf_new(void); +void pa_client_conf_free(struct pa_client_conf *c); + +int pa_client_conf_load(struct pa_client_conf *c, const char *filename); +int pa_client_conf_env(struct pa_client_conf *c); + +#endif diff --git a/polyp/cmdline.c b/polyp/cmdline.c index d429256f..7f8a947b 100644 --- a/polyp/cmdline.c +++ b/polyp/cmdline.c @@ -107,7 +107,7 @@ void pa_cmdline_help(const char *argv0) { " -n Don't load default script file\n", e); } -int pa_cmdline_parse(struct pa_conf *conf, int argc, char *const argv [], int *d) { +int pa_cmdline_parse(struct pa_daemon_conf *conf, int argc, char *const argv [], int *d) { struct pa_strbuf *buf = NULL; int c; assert(conf && argc && argv); diff --git a/polyp/cmdline.h b/polyp/cmdline.h index e4bd8af6..bfbae470 100644 --- a/polyp/cmdline.h +++ b/polyp/cmdline.h @@ -22,9 +22,9 @@ USA. ***/ -#include "conf.h" +#include "daemon-conf.h" -int pa_cmdline_parse(struct pa_conf*c, int argc, char *const argv [], int *d); +int pa_cmdline_parse(struct pa_daemon_conf*c, int argc, char *const argv [], int *d); void pa_cmdline_help(const char *argv0); diff --git a/polyp/conf.c b/polyp/conf.c deleted file mode 100644 index efc471af..00000000 --- a/polyp/conf.c +++ /dev/null @@ -1,231 +0,0 @@ -/* $Id$ */ - -/*** - 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 - by the Free Software Foundation; either version 2 of the License, - or (at your option) any later version. - - polypaudio is distributed in the hope that it will be useful, but - 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. - - You should have received a copy of the GNU 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. -***/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include - -#include "conf.h" -#include "util.h" -#include "xmalloc.h" -#include "strbuf.h" -#include "confparser.h" - -#ifndef DEFAULT_SCRIPT_FILE -#define DEFAULT_SCRIPT_FILE "/etc/polypaudio/default.pa" -#endif - -#ifndef DEFAULT_SCRIPT_FILE_USER -#define DEFAULT_SCRIPT_FILE_USER ".polypaudio/default.pa" -#endif - -#ifndef DEFAULT_CONFIG_FILE -#define DEFAULT_CONFIG_FILE "/etc/polypaudio/daemon.conf" -#endif - -#ifndef DEFAULT_CONFIG_FILE_USER -#define DEFAULT_CONFIG_FILE_USER ".polypaudio/daemon.conf" -#endif - -#define ENV_SCRIPT_FILE "POLYP_SCRIPT" -#define ENV_CONFIG_FILE "POLYP_CONFIG" -#define ENV_DL_SEARCH_PATH "POLYP_DLPATH" - -static const struct pa_conf default_conf = { - .cmd = PA_CMD_DAEMON, - .daemonize = 0, - .fail = 1, - .verbose = 0, - .high_priority = 0, - .disallow_module_loading = 0, - .exit_idle_time = -1, - .module_idle_time = 20, - .scache_idle_time = 20, - .auto_log_target = 1, - .script_commands = NULL, - .dl_search_path = NULL, - .default_script_file = NULL, - .log_target = PA_LOG_SYSLOG, - .resample_method = SRC_SINC_FASTEST -}; - -char* default_file(const char *envvar, const char *global, const char *local) { - char *p, *h; - - assert(envvar && global && local); - - if ((p = getenv(envvar))) - return pa_xstrdup(p); - - if ((h = getenv("HOME"))) { - p = pa_sprintf_malloc("%s/%s", h, local); - if (!access(p, F_OK)) - return p; - - pa_xfree(p); - } - - return pa_xstrdup(global); -} - -struct pa_conf* pa_conf_new(void) { - struct pa_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); - c->default_script_file = default_file(ENV_SCRIPT_FILE, DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER); -#ifdef DLSEARCHPATH - c->dl_search_path = pa_xstrdup(DLSEARCHPATH); -#endif - return c; -} - -void pa_conf_free(struct pa_conf *c) { - assert(c); - pa_xfree(c->script_commands); - pa_xfree(c->dl_search_path); - pa_xfree(c->default_script_file); - pa_xfree(c); -} - -int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) { - struct pa_conf *c = data; - assert(filename && lvalue && rvalue && data); - - if (!strcmp(rvalue, "auto")) - c->auto_log_target = 1; - else if (!strcmp(rvalue, "syslog")) { - c->auto_log_target = 0; - c->log_target = PA_LOG_SYSLOG; - } else if (!strcmp(rvalue, "stderr")) { - c->auto_log_target = 0; - c->log_target = PA_LOG_STDERR; - } else { - pa_log(__FILE__": [%s:%u] Invalid log target '%s'.\n", filename, line, rvalue); - return -1; - } - - return 0; -} - -int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) { - struct pa_conf *c = data; - assert(filename && lvalue && rvalue && data); - - if (!strcmp(rvalue, "sinc-best-quality")) - c->resample_method = SRC_SINC_BEST_QUALITY; - else if (!strcmp(rvalue, "sinc-medium-quality")) - c->resample_method = SRC_SINC_MEDIUM_QUALITY; - else if (!strcmp(rvalue, "sinc-fastest")) - c->resample_method = SRC_SINC_FASTEST; - else if (!strcmp(rvalue, "zero-order-hold")) - c->resample_method = SRC_ZERO_ORDER_HOLD; - else if (!strcmp(rvalue, "linear")) - c->resample_method = SRC_LINEAR; - else { - pa_log(__FILE__": [%s:%u] Inavalid resample method '%s'.\n", filename, line, rvalue); - return -1; - } - - return 0; -} - -int pa_conf_load(struct pa_conf *c, const char *filename) { - char *def = NULL; - int r; - - const struct pa_config_item table[] = { - { "verbose", pa_config_parse_bool, &c->verbose }, - { "daemonize", pa_config_parse_bool, &c->daemonize }, - { "fail", pa_config_parse_bool, &c->fail }, - { "high-priority", pa_config_parse_bool, &c->high_priority }, - { "disallow-module-loading", pa_config_parse_bool, &c->disallow_module_loading }, - { "exit-idle-time", pa_config_parse_int, &c->exit_idle_time }, - { "module-idle-time", pa_config_parse_int, &c->module_idle_time }, - { "scache-idle-time", pa_config_parse_int, &c->scache_idle_time }, - { "dl-search-path", pa_config_parse_string, &c->dl_search_path }, - { "default-script-file", pa_config_parse_string, &c->default_script_file }, - { "log-target", parse_log_target, c }, - { "resample-method", parse_resample_method, c }, - { NULL, NULL, NULL }, - }; - - if (!filename) - filename = def = default_file(ENV_CONFIG_FILE, DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER); - - r = pa_config_parse(filename, table, NULL); - pa_xfree(def); - return r; -} - -int pa_conf_env(struct pa_conf *c) { - char *e; - - if ((e = getenv(ENV_DL_SEARCH_PATH))) { - pa_xfree(c->dl_search_path); - c->dl_search_path = pa_xstrdup(e); - } - if ((e = getenv(ENV_SCRIPT_FILE))) { - pa_xfree(c->default_script_file); - c->default_script_file = pa_xstrdup(e); - } - - return 0; -} - -char *pa_conf_dump(struct pa_conf *c) { - struct pa_strbuf *s = pa_strbuf_new(); - char *d; - - static const char const* resample_methods[] = { - "sinc-best-quality", - "sinc-medium-quality", - "sinc-fastest", - "zero-order-hold", - "linear" - }; - - d = default_file(ENV_CONFIG_FILE, DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER); - pa_strbuf_printf(s, "### Default configuration file: %s ###\n", d); - - pa_strbuf_printf(s, "verbose = %i\n", !!c->verbose); - pa_strbuf_printf(s, "daemonize = %i\n", !!c->daemonize); - pa_strbuf_printf(s, "fail = %i\n", !!c->fail); - pa_strbuf_printf(s, "high-priority = %i\n", !!c->high_priority); - pa_strbuf_printf(s, "disallow-module-loading = %i\n", !!c->disallow_module_loading); - pa_strbuf_printf(s, "exit-idle-time = %i\n", c->exit_idle_time); - pa_strbuf_printf(s, "module-idle-time = %i\n", c->module_idle_time); - pa_strbuf_printf(s, "scache-idle-time = %i\n", c->scache_idle_time); - pa_strbuf_printf(s, "dl-search-path = %s\n", c->dl_search_path ? c->dl_search_path : ""); - pa_strbuf_printf(s, "default-script-file = %s\n", c->default_script_file); - pa_strbuf_printf(s, "log-target = %s\n", c->auto_log_target ? "auto" : (c->log_target == PA_LOG_SYSLOG ? "syslog" : "stderr")); - - assert(c->resample_method <= 4 && c->resample_method >= 0); - pa_strbuf_printf(s, "resample-method = %s\n", resample_methods[c->resample_method]); - - pa_xfree(d); - - return pa_strbuf_tostring_free(s); -} diff --git a/polyp/conf.h b/polyp/conf.h deleted file mode 100644 index ace5396d..00000000 --- a/polyp/conf.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef fooconfhfoo -#define fooconfhfoo - -/* $Id$ */ - -/*** - 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 - by the Free Software Foundation; either version 2 of the License, - or (at your option) any later version. - - polypaudio is distributed in the hope that it will be useful, but - 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. - - You should have received a copy of the GNU 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 "log.h" - -enum pa_conf_cmd { - PA_CMD_DAEMON, - PA_CMD_HELP, - PA_CMD_VERSION, - PA_CMD_DUMP_CONF, - PA_CMD_DUMP_MODULES -}; - -struct pa_conf { - enum pa_conf_cmd cmd; - int daemonize, - fail, - verbose, - high_priority, - disallow_module_loading, - exit_idle_time, - module_idle_time, - scache_idle_time, - auto_log_target; - char *script_commands, *dl_search_path, *default_script_file; - enum pa_log_target log_target; - int resample_method; -}; - -struct pa_conf* pa_conf_new(void); -void pa_conf_free(struct pa_conf*c); - -int pa_conf_load(struct pa_conf *c, const char *filename); -char *pa_conf_dump(struct pa_conf *c); - -#endif diff --git a/polyp/config-client.c b/polyp/config-client.c deleted file mode 100644 index 758927f3..00000000 --- a/polyp/config-client.c +++ /dev/null @@ -1,138 +0,0 @@ -/* $Id$ */ - -/*** - 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 - by the Free Software Foundation; either version 2 of the License, - or (at your option) any later version. - - polypaudio is distributed in the hope that it will be useful, but - 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. - - You should have received a copy of the GNU 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 -#include -#include - -#include "config-client.h" -#include "xmalloc.h" -#include "log.h" -#include "confparser.h" -#include "util.h" - -#ifndef DEFAULT_CLIENT_CONFIG_FILE -#define DEFAULT_CLIENT_CONFIG_FILE "/etc/polypaudio/client.conf" -#endif - -#ifndef DEFAULT_CLIENT_CONFIG_FILE_USER -#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" - - -static const struct pa_client_conf default_conf = { - .daemon_binary = NULL, - .extra_arguments = NULL, - .default_sink = NULL, - .default_source = NULL, - .default_server = NULL, - .autospawn = 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"); - - return c; -} - -void pa_client_conf_free(struct pa_client_conf *c) { - assert(c); - 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); - 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 }, - { 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; - } - } - } - - if (!filename) - filename = DEFAULT_CLIENT_CONFIG_FILE; - - r = pa_config_parse(filename, table, NULL); - pa_xfree(def); - return r; -} - -int pa_client_conf_env(struct 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); - } - - if ((e = getenv(ENV_DAEMON_BINARY))) { - pa_xfree(c->daemon_binary); - c->daemon_binary = pa_xstrdup(e); - } - - return 0; -} diff --git a/polyp/config-client.h b/polyp/config-client.h deleted file mode 100644 index 1b1c519d..00000000 --- a/polyp/config-client.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef fooconfigclienthfoo -#define fooconfigclienthfoo - -/* $Id$ */ - -/*** - 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 - by the Free Software Foundation; either version 2 of the License, - or (at your option) any later version. - - polypaudio is distributed in the hope that it will be useful, but - 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. - - You should have received a copy of the GNU 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. -***/ - -struct pa_client_conf { - char *daemon_binary, *extra_arguments, *default_sink, *default_source, *default_server; - int autospawn; -}; - -struct pa_client_conf *pa_client_conf_new(void); -void pa_client_conf_free(struct pa_client_conf *c); - -int pa_client_conf_load(struct pa_client_conf *c, const char *filename); -int pa_client_conf_env(struct pa_client_conf *c); - -#endif diff --git a/polyp/daemon-conf.c b/polyp/daemon-conf.c new file mode 100644 index 00000000..72ded989 --- /dev/null +++ b/polyp/daemon-conf.c @@ -0,0 +1,231 @@ +/* $Id$ */ + +/*** + 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 + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + 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. + + You should have received a copy of the GNU 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. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include "daemon-conf.h" +#include "util.h" +#include "xmalloc.h" +#include "strbuf.h" +#include "confparser.h" + +#ifndef DEFAULT_SCRIPT_FILE +#define DEFAULT_SCRIPT_FILE "/etc/polypaudio/default.pa" +#endif + +#ifndef DEFAULT_SCRIPT_FILE_USER +#define DEFAULT_SCRIPT_FILE_USER ".polypaudio/default.pa" +#endif + +#ifndef DEFAULT_CONFIG_FILE +#define DEFAULT_CONFIG_FILE "/etc/polypaudio/daemon.conf" +#endif + +#ifndef DEFAULT_CONFIG_FILE_USER +#define DEFAULT_CONFIG_FILE_USER ".polypaudio/daemon.conf" +#endif + +#define ENV_SCRIPT_FILE "POLYP_SCRIPT" +#define ENV_CONFIG_FILE "POLYP_CONFIG" +#define ENV_DL_SEARCH_PATH "POLYP_DLPATH" + +static const struct pa_daemon_conf default_conf = { + .cmd = PA_CMD_DAEMON, + .daemonize = 0, + .fail = 1, + .verbose = 0, + .high_priority = 0, + .disallow_module_loading = 0, + .exit_idle_time = -1, + .module_idle_time = 20, + .scache_idle_time = 20, + .auto_log_target = 1, + .script_commands = NULL, + .dl_search_path = NULL, + .default_script_file = NULL, + .log_target = PA_LOG_SYSLOG, + .resample_method = SRC_SINC_FASTEST +}; + +char* default_file(const char *envvar, const char *global, const char *local) { + char *p, *h; + + assert(envvar && global && local); + + if ((p = getenv(envvar))) + return pa_xstrdup(p); + + if ((h = getenv("HOME"))) { + p = pa_sprintf_malloc("%s/%s", h, local); + if (!access(p, F_OK)) + return p; + + pa_xfree(p); + } + + return pa_xstrdup(global); +} + +struct pa_daemon_conf* pa_daemon_conf_new(void) { + struct pa_daemon_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf)); + c->default_script_file = default_file(ENV_SCRIPT_FILE, DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FILE_USER); +#ifdef DLSEARCHPATH + c->dl_search_path = pa_xstrdup(DLSEARCHPATH); +#endif + return c; +} + +void pa_daemon_conf_free(struct pa_daemon_conf *c) { + assert(c); + pa_xfree(c->script_commands); + pa_xfree(c->dl_search_path); + pa_xfree(c->default_script_file); + pa_xfree(c); +} + +int parse_log_target(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) { + struct pa_daemon_conf *c = data; + assert(filename && lvalue && rvalue && data); + + if (!strcmp(rvalue, "auto")) + c->auto_log_target = 1; + else if (!strcmp(rvalue, "syslog")) { + c->auto_log_target = 0; + c->log_target = PA_LOG_SYSLOG; + } else if (!strcmp(rvalue, "stderr")) { + c->auto_log_target = 0; + c->log_target = PA_LOG_STDERR; + } else { + pa_log(__FILE__": [%s:%u] Invalid log target '%s'.\n", filename, line, rvalue); + return -1; + } + + return 0; +} + +int parse_resample_method(const char *filename, unsigned line, const char *lvalue, const char *rvalue, void *data, void *userdata) { + struct pa_daemon_conf *c = data; + assert(filename && lvalue && rvalue && data); + + if (!strcmp(rvalue, "sinc-best-quality")) + c->resample_method = SRC_SINC_BEST_QUALITY; + else if (!strcmp(rvalue, "sinc-medium-quality")) + c->resample_method = SRC_SINC_MEDIUM_QUALITY; + else if (!strcmp(rvalue, "sinc-fastest")) + c->resample_method = SRC_SINC_FASTEST; + else if (!strcmp(rvalue, "zero-order-hold")) + c->resample_method = SRC_ZERO_ORDER_HOLD; + else if (!strcmp(rvalue, "linear")) + c->resample_method = SRC_LINEAR; + else { + pa_log(__FILE__": [%s:%u] Inavalid resample method '%s'.\n", filename, line, rvalue); + return -1; + } + + return 0; +} + +int pa_daemon_conf_load(struct pa_daemon_conf *c, const char *filename) { + char *def = NULL; + int r; + + const struct pa_config_item table[] = { + { "verbose", pa_config_parse_bool, &c->verbose }, + { "daemonize", pa_config_parse_bool, &c->daemonize }, + { "fail", pa_config_parse_bool, &c->fail }, + { "high-priority", pa_config_parse_bool, &c->high_priority }, + { "disallow-module-loading", pa_config_parse_bool, &c->disallow_module_loading }, + { "exit-idle-time", pa_config_parse_int, &c->exit_idle_time }, + { "module-idle-time", pa_config_parse_int, &c->module_idle_time }, + { "scache-idle-time", pa_config_parse_int, &c->scache_idle_time }, + { "dl-search-path", pa_config_parse_string, &c->dl_search_path }, + { "default-script-file", pa_config_parse_string, &c->default_script_file }, + { "log-target", parse_log_target, c }, + { "resample-method", parse_resample_method, c }, + { NULL, NULL, NULL }, + }; + + if (!filename) + filename = def = default_file(ENV_CONFIG_FILE, DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER); + + r = pa_config_parse(filename, table, NULL); + pa_xfree(def); + return r; +} + +int pa_daemon_conf_env(struct pa_daemon_conf *c) { + char *e; + + if ((e = getenv(ENV_DL_SEARCH_PATH))) { + pa_xfree(c->dl_search_path); + c->dl_search_path = pa_xstrdup(e); + } + if ((e = getenv(ENV_SCRIPT_FILE))) { + pa_xfree(c->default_script_file); + c->default_script_file = pa_xstrdup(e); + } + + return 0; +} + +char *pa_daemon_conf_dump(struct pa_daemon_conf *c) { + struct pa_strbuf *s = pa_strbuf_new(); + char *d; + + static const char const* resample_methods[] = { + "sinc-best-quality", + "sinc-medium-quality", + "sinc-fastest", + "zero-order-hold", + "linear" + }; + + d = default_file(ENV_CONFIG_FILE, DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER); + pa_strbuf_printf(s, "### Default configuration file: %s ###\n", d); + + pa_strbuf_printf(s, "verbose = %i\n", !!c->verbose); + pa_strbuf_printf(s, "daemonize = %i\n", !!c->daemonize); + pa_strbuf_printf(s, "fail = %i\n", !!c->fail); + pa_strbuf_printf(s, "high-priority = %i\n", !!c->high_priority); + pa_strbuf_printf(s, "disallow-module-loading = %i\n", !!c->disallow_module_loading); + pa_strbuf_printf(s, "exit-idle-time = %i\n", c->exit_idle_time); + pa_strbuf_printf(s, "module-idle-time = %i\n", c->module_idle_time); + pa_strbuf_printf(s, "scache-idle-time = %i\n", c->scache_idle_time); + pa_strbuf_printf(s, "dl-search-path = %s\n", c->dl_search_path ? c->dl_search_path : ""); + pa_strbuf_printf(s, "default-script-file = %s\n", c->default_script_file); + pa_strbuf_printf(s, "log-target = %s\n", c->auto_log_target ? "auto" : (c->log_target == PA_LOG_SYSLOG ? "syslog" : "stderr")); + + assert(c->resample_method <= 4 && c->resample_method >= 0); + pa_strbuf_printf(s, "resample-method = %s\n", resample_methods[c->resample_method]); + + pa_xfree(d); + + return pa_strbuf_tostring_free(s); +} diff --git a/polyp/daemon-conf.h b/polyp/daemon-conf.h new file mode 100644 index 00000000..c987a6d5 --- /dev/null +++ b/polyp/daemon-conf.h @@ -0,0 +1,58 @@ +#ifndef foodaemonconfhfoo +#define foodaemonconfhfoo + +/* $Id$ */ + +/*** + 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 + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + 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. + + You should have received a copy of the GNU 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 "log.h" + +enum pa_daemon_conf_cmd { + PA_CMD_DAEMON, + PA_CMD_HELP, + PA_CMD_VERSION, + PA_CMD_DUMP_CONF, + PA_CMD_DUMP_MODULES +}; + +struct pa_daemon_conf { + enum pa_daemon_conf_cmd cmd; + int daemonize, + fail, + verbose, + high_priority, + disallow_module_loading, + exit_idle_time, + module_idle_time, + scache_idle_time, + auto_log_target; + char *script_commands, *dl_search_path, *default_script_file; + enum pa_log_target log_target; + int resample_method; +}; + +struct pa_daemon_conf* pa_daemon_conf_new(void); +void pa_daemon_conf_free(struct pa_daemon_conf*c); + +int pa_daemon_conf_load(struct pa_daemon_conf *c, const char *filename); +char *pa_daemon_conf_dump(struct pa_daemon_conf *c); +int pa_daemon_conf_env(struct pa_daemon_conf *c); + +#endif diff --git a/polyp/dumpmodules.c b/polyp/dumpmodules.c index ae42d36e..a9c02825 100644 --- a/polyp/dumpmodules.c +++ b/polyp/dumpmodules.c @@ -78,7 +78,7 @@ static void show_info(const char *name, const char *path, void (*info)(const cha static int callback(const char *path, lt_ptr data) { const char *e; - struct pa_conf *c = (data); + struct pa_daemon_conf *c = (data); if ((e = (const char*) strrchr(path, '/'))) e++; @@ -91,7 +91,7 @@ static int callback(const char *path, lt_ptr data) { return 0; } -void pa_dump_modules(struct pa_conf *c, int argc, char * const argv[]) { +void pa_dump_modules(struct pa_daemon_conf *c, int argc, char * const argv[]) { if (argc > 0) { int i; for (i = 0; i < argc; i++) diff --git a/polyp/dumpmodules.h b/polyp/dumpmodules.h index 6b1bd858..544c55d2 100644 --- a/polyp/dumpmodules.h +++ b/polyp/dumpmodules.h @@ -22,8 +22,8 @@ USA. ***/ -#include "conf.h" +#include "daemon-conf.h" -void pa_dump_modules(struct pa_conf *c, int argc, char * const argv[]); +void pa_dump_modules(struct pa_daemon_conf *c, int argc, char * const argv[]); #endif diff --git a/polyp/main.c b/polyp/main.c index 3b25a030..10774388 100644 --- a/polyp/main.c +++ b/polyp/main.c @@ -45,7 +45,7 @@ #include "xmalloc.h" #include "cpulimit.h" #include "log.h" -#include "conf.h" +#include "daemon-conf.h" #include "dumpmodules.h" static struct pa_mainloop *mainloop; @@ -90,7 +90,7 @@ static void close_pipe(int p[2]) { int main(int argc, char *argv[]) { struct pa_core *c; struct pa_strbuf *buf = NULL; - struct pa_conf *conf; + struct pa_daemon_conf *conf; char *s; int r, retval = 1, d = 0; int daemon_pipe[2] = { -1, -1 }; @@ -100,11 +100,14 @@ int main(int argc, char *argv[]) { pa_log_set_ident("polypaudio"); - conf = pa_conf_new(); + conf = pa_daemon_conf_new(); - if (pa_conf_load(conf, NULL) < 0) + if (pa_daemon_conf_load(conf, NULL) < 0) goto finish; + if (pa_daemon_conf_env(conf) < 0) + goto finish; + if (pa_cmdline_parse(conf, argc, argv, &d) < 0) { pa_log(__FILE__": failed to parse command line.\n"); goto finish; @@ -127,7 +130,7 @@ int main(int argc, char *argv[]) { goto finish; case PA_CMD_DUMP_CONF: { - char *s = pa_conf_dump(conf); + char *s = pa_daemon_conf_dump(conf); fputs(s, stdout); pa_xfree(s); retval = 0; @@ -261,7 +264,7 @@ int main(int argc, char *argv[]) { finish: if (conf) - pa_conf_free(conf); + pa_daemon_conf_free(conf); close_pipe(daemon_pipe); diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c index 04ee3d89..4ed15c4b 100644 --- a/polyp/polyplib-context.c +++ b/polyp/polyplib-context.c @@ -47,7 +47,7 @@ #include "util.h" #include "xmalloc.h" #include "log.h" -#include "config-client.h" +#include "client-conf.h" #define DEFAULT_SERVER "/tmp/polypaudio/native" diff --git a/polyp/polyplib-internal.h b/polyp/polyplib-internal.h index 1d0e41d8..6e64755d 100644 --- a/polyp/polyplib-internal.h +++ b/polyp/polyplib-internal.h @@ -33,7 +33,7 @@ #include "polyplib-operation.h" #include "llist.h" #include "native-common.h" -#include "config-client.h" +#include "client-conf.h" #define DEFAULT_TLENGTH (10240*8) #define DEFAULT_MAXLENGTH ((DEFAULT_TLENGTH*3)/2) -- cgit