aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-09 22:15:28 +0200
committerMax Kellermann <max@duempel.org>2011-09-09 23:01:22 +0200
commit9f5c938ff3cfe6f264340461c88defa2bb614cb0 (patch)
treeb26252f3da5bd374c15cc9b6b03a8849b398a4e3
parentb42a8d236434d7ec63c742d275cd7b75adbe760b (diff)
downloadmpd-9f5c938ff3cfe6f264340461c88defa2bb614cb0.tar.gz
mpd-9f5c938ff3cfe6f264340461c88defa2bb614cb0.tar.xz
mpd-9f5c938ff3cfe6f264340461c88defa2bb614cb0.zip
conf: add config_dup_block_path()
-rw-r--r--src/conf.c20
-rw-r--r--src/conf.h9
-rw-r--r--src/output/fifo_output_plugin.c23
3 files changed, 38 insertions, 14 deletions
diff --git a/src/conf.c b/src/conf.c
index 245a2a811..9e9c199fd 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -606,6 +606,26 @@ config_get_block_string(const struct config_param *param, const char *name,
return bp->value;
}
+char *
+config_dup_block_path(const struct config_param *param, const char *name,
+ GError **error_r)
+{
+ assert(error_r != NULL);
+ assert(*error_r == NULL);
+
+ const struct block_param *bp = config_get_block_param(param, name);
+ if (bp == NULL)
+ return NULL;
+
+ char *path = parsePath(bp->value, error_r);
+ if (G_UNLIKELY(path == NULL))
+ g_prefix_error(error_r,
+ "Invalid path in \"%s\" at line %i: ",
+ name, bp->line);
+
+ return path;
+}
+
unsigned
config_get_block_unsigned(const struct config_param *param, const char *name,
unsigned default_value)
diff --git a/src/conf.h b/src/conf.h
index 9593501b0..1c6e464c4 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -194,6 +194,15 @@ config_dup_block_string(const struct config_param *param, const char *name,
return g_strdup(config_get_block_string(param, name, default_value));
}
+/**
+ * Same as config_dup_path(), but looks up the setting in the
+ * specified block.
+ */
+G_GNUC_MALLOC
+char *
+config_dup_block_path(const struct config_param *param, const char *name,
+ GError **error_r);
+
G_GNUC_PURE
unsigned
config_get_block_unsigned(const struct config_param *param, const char *name,
diff --git a/src/output/fifo_output_plugin.c b/src/output/fifo_output_plugin.c
index e522ef6b9..708062552 100644
--- a/src/output/fifo_output_plugin.c
+++ b/src/output/fifo_output_plugin.c
@@ -178,30 +178,25 @@ fifo_open(struct fifo_data *fd, GError **error)
static void *
fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
const struct config_param *param,
- GError **error)
+ GError **error_r)
{
struct fifo_data *fd;
- char *value, *path;
-
- value = config_dup_block_string(param, "path", NULL);
- if (value == NULL) {
- g_set_error(error, fifo_output_quark(), errno,
- "No \"path\" parameter specified");
- return NULL;
- }
- path = parsePath(value, error);
- g_free(value);
+ GError *error = NULL;
+ char *path = config_dup_block_path(param, "path", &error);
if (!path) {
- g_prefix_error(error, "Invalid path in line %i: ",
- param->line);
+ if (error != NULL)
+ g_propagate_error(error_r, error);
+ else
+ g_set_error(error_r, fifo_output_quark(), 0,
+ "No \"path\" parameter specified");
return NULL;
}
fd = fifo_data_new();
fd->path = path;
- if (!fifo_open(fd, error)) {
+ if (!fifo_open(fd, error_r)) {
fifo_data_free(fd);
return NULL;
}