X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/450ad85b35bd600ed020f7ec119d51e7e7bc01a4..fa499dad06ba6558111cdef64c18f2401e803cff:/polyp/module-match.c diff --git a/polyp/module-match.c b/polyp/module-match.c index 964ff2fd..6f4fc38c 100644 --- a/polyp/module-match.c +++ b/polyp/module-match.c @@ -4,7 +4,7 @@ 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. @@ -13,7 +13,7 @@ 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. @@ -39,6 +39,7 @@ #include "subscribe.h" #include "xmalloc.h" #include "sink-input.h" +#include "module-match-symdef.h" PA_MODULE_AUTHOR("Lennart Poettering") PA_MODULE_DESCRIPTION("Sink input matching module") @@ -47,6 +48,13 @@ PA_MODULE_VERSION(PACKAGE_VERSION) #define WHITESPACE "\n\r \t" +#ifndef DEFAULT_CONFIG_DIR +#define DEFAULT_CONFIG_DIR "/etc/polypaudio" +#endif + +#define DEFAULT_MATCH_TABLE_FILE DEFAULT_CONFIG_DIR"/match.table" +#define DEFAULT_MATCH_TABLE_FILE_USER ".polypaudio/match.table" + static const char* const valid_modargs[] = { "table", NULL, @@ -68,9 +76,14 @@ static int load_rules(struct userdata *u, const char *filename) { int n = 0; int ret = -1; struct rule *end = NULL; + char *fn = NULL; + + f = filename ? + fopen(fn = pa_xstrdup(filename), "r") : + pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn); - if (!(f = fopen(filename, "r"))) { - pa_log(__FILE__": failed to open file '%s': %s\n", filename, strerror(errno)); + if (!f) { + pa_log(__FILE__": failed to open file '%s': %s\n", fn, strerror(errno)); goto finish; } @@ -134,6 +147,9 @@ finish: if (f) fclose(f); + if (fn) + pa_xfree(fn); + return ret; } @@ -164,7 +180,6 @@ static void callback(struct pa_core *c, enum pa_subscription_event_type t, uint3 int pa__init(struct pa_core *c, struct pa_module*m) { struct pa_modargs *ma = NULL; - int ret = -1; const char *table_file; struct userdata *u; assert(c && m); @@ -172,25 +187,28 @@ int pa__init(struct pa_core *c, struct pa_module*m) { if (!(ma = pa_modargs_new(m->argument, valid_modargs)) || !(table_file = pa_modargs_get_value(ma, "table", NULL))) { pa_log(__FILE__": Failed to parse module arguments\n"); - goto finish; + goto fail; } u = pa_xmalloc(sizeof(struct userdata)); u->rules = NULL; u->subscription = NULL; + m->userdata = u; if (load_rules(u, table_file) < 0) - goto finish; + goto fail; u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u); - - ret = 0; -finish: + pa_modargs_free(ma); + return 0; + +fail: + pa__done(c, m); + if (ma) pa_modargs_free(ma); - - return ret; + return -1; } void pa__done(struct pa_core *c, struct pa_module*m) {