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 "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")
#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,
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;
}
if (f)
fclose(f);
+ if (fn)
+ pa_xfree(fn);
+
return ret;
}
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);
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) {