diff options
author | John Keeping <john@keeping.me.uk> | 2014-01-13 02:13:53 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-01-14 10:00:07 (JST) |
commit | 4bb87cbf17588ec91b46bf0ef0be01672e9be787 (patch) | |
tree | 454216292add842ac194ec909a073002dc840609 /filter.c | |
parent | 7bd90b8048fd6937766dff7474947dd80205ea7e (diff) | |
download | cgit-4bb87cbf17588ec91b46bf0ef0be01672e9be787.zip cgit-4bb87cbf17588ec91b46bf0ef0be01672e9be787.tar.gz |
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.c | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -64,7 +64,7 @@ done: | |||
64 | static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, const char *prefix) | 64 | static 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 | ||
70 | int cgit_open_filter(struct cgit_filter *filter, ...) | 70 | 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 | |||
125 | return &f->base; | 125 | return &f->base; |
126 | } | 126 | } |
127 | 127 | ||
128 | static 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 | |||
128 | struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) | 135 | struct 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 | } |