aboutsummaryrefslogtreecommitdiffstats
path: root/filter.c
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2014-01-12 17:13:53 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2014-01-14 02:00:07 +0100
commit4bb87cbf17588ec91b46bf0ef0be01672e9be787 (patch)
tree454216292add842ac194ec909a073002dc840609 /filter.c
parent7bd90b8048fd6937766dff7474947dd80205ea7e (diff)
downloadcgit-4bb87cbf17588ec91b46bf0ef0be01672e9be787.tar.gz
cgit-4bb87cbf17588ec91b46bf0ef0be01672e9be787.tar.bz2
cgit-4bb87cbf17588ec91b46bf0ef0be01672e9be787.zip
filter: introduce "filter type" prefix
This allows different filter implementations to be specified in the configuration file. Currently only "exec" is supported, but it may now be specified either with or without the "exec:" prefix. Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/filter.c b/filter.c
index 0f3edb0..ba66e46 100644
--- a/filter.c
+++ b/filter.c
@@ -64,7 +64,7 @@ done:
static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, const char *prefix)
{
struct cgit_exec_filter *filter = (struct cgit_exec_filter *) base;
- fprintf(f, "%s%s\n", prefix, filter->cmd);
+ fprintf(f, "%sexec:%s\n", prefix, filter->cmd);
}
int cgit_open_filter(struct cgit_filter *filter, ...)
@@ -125,10 +125,39 @@ static struct cgit_filter *new_exec_filter(const char *cmd, filter_type filterty
return &f->base;
}
+static const struct {
+ const char *prefix;
+ struct cgit_filter *(*ctor)(const char *cmd, filter_type filtertype);
+} filter_specs[] = {
+ { "exec", new_exec_filter },
+};
+
struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
{
+ char *colon;
+ int i;
+ size_t len;
if (!cmd || !cmd[0])
return NULL;
- return new_exec_filter(cmd, filtertype);
+ colon = strchr(cmd, ':');
+ len = colon - cmd;
+ /*
+ * In case we're running on Windows, don't allow a single letter before
+ * the colon.
+ */
+ if (len == 1)
+ colon = NULL;
+
+ /* If no prefix is given, exec filter is the default. */
+ if (!colon)
+ return new_exec_filter(cmd, filtertype);
+
+ for (i = 0; i < ARRAY_SIZE(filter_specs); i++) {
+ if (len == strlen(filter_specs[i].prefix) &&
+ !strncmp(filter_specs[i].prefix, cmd, len))
+ return filter_specs[i].ctor(colon + 1, filtertype);
+ }
+
+ die("Invalid filter type: %.*s", (int) len, cmd);
}