aboutsummaryrefslogtreecommitdiffstats
path: root/filter.c
diff options
context:
space:
mode:
authorJohn Keeping2014-01-12 17:13:53 +0000
committerJason A. Donenfeld2014-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:
64static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, const char *prefix) 64static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, const char *prefix)
65{ 65{
66 struct cgit_exec_filter *filter = (struct cgit_exec_filter *) base; 66 struct cgit_exec_filter *filter = (struct cgit_exec_filter *) base;
67 fprintf(f, "%s%s\n", prefix, filter->cmd); 67 fprintf(f, "%sexec:%s\n", prefix, filter->cmd);
68} 68}
69 69
70int cgit_open_filter(struct cgit_filter *filter, ...) 70int cgit_open_filter(struct cgit_filter *filter, ...)
@@ -125,10 +125,39 @@ static struct cgit_filter *new_exec_filter(const char *cmd, filter_type filterty
125 return &f->base; 125 return &f->base;
126} 126}
127 127
128static const struct {
129 const char *prefix;
130 struct cgit_filter *(*ctor)(const char *cmd, filter_type filtertype);
131} filter_specs[] = {
132 { "exec", new_exec_filter },
133};
134
128struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) 135struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
129{ 136{
137 char *colon;
138 int i;
139 size_t len;
130 if (!cmd || !cmd[0]) 140 if (!cmd || !cmd[0])
131 return NULL; 141 return NULL;
132 142
133 return new_exec_filter(cmd, filtertype); 143 colon = strchr(cmd, ':');
144 len = colon - cmd;
145 /*
146 * In case we're running on Windows, don't allow a single letter before
147 * the colon.
148 */
149 if (len == 1)
150 colon = NULL;
151
152 /* If no prefix is given, exec filter is the default. */
153 if (!colon)
154 return new_exec_filter(cmd, filtertype);
155
156 for (i = 0; i < ARRAY_SIZE(filter_specs); i++) {
157 if (len == strlen(filter_specs[i].prefix) &&
158 !strncmp(filter_specs[i].prefix, cmd, len))
159 return filter_specs[i].ctor(colon + 1, filtertype);
160 }
161
162 die("Invalid filter type: %.*s", (int) len, cmd);
134} 163}