Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.zx2c4.com/cgit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2014-01-14 03:29:07 +0400
committerJason A. Donenfeld <Jason@zx2c4.com>2014-01-14 05:05:14 +0400
commit80f87c1003a4c58dc7e516d77598cd0213127c02 (patch)
tree0585d82b6440c2a1aec7dcefc64a69f755cb6a38
parent3488d124052f5c3ddef303ed5306ad6a458794c1 (diff)
filter: refactor cgit_new_filter()
Use prefixcmp() as a preparation for using strip_prefix() later. Also, interpret the command as a file name if it contains a colon but none of the filter prefixes matches instead of bailing out and adding a special check for Windows. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r--filter.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/filter.c b/filter.c
index 4d4acaf..1997881 100644
--- a/filter.c
+++ b/filter.c
@@ -379,31 +379,19 @@ static const struct {
const char *prefix;
struct cgit_filter *(*ctor)(const char *cmd, int argument_count);
} filter_specs[] = {
- { "exec", new_exec_filter },
+ { "exec:", new_exec_filter },
#ifndef NO_LUA
- { "lua", new_lua_filter },
+ { "lua:", new_lua_filter },
#endif
};
struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
{
- char *colon;
- int i;
- size_t len;
- int argument_count;
+ int argument_count, i;
if (!cmd || !cmd[0])
return NULL;
- 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;
-
switch (filtertype) {
case EMAIL:
argument_count = 2;
@@ -420,15 +408,11 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
break;
}
- /* If no prefix is given, exec filter is the default. */
- if (!colon)
- return new_exec_filter(cmd, argument_count);
-
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, argument_count);
+ if (!prefixcmp(cmd, filter_specs[i].prefix))
+ return filter_specs[i].ctor(strchr(cmd, ':') + 1, argument_count);
}
- die("Invalid filter type: %.*s", (int) len, cmd);
+ /* If no valid prefix is given, exec filter is the default. */
+ return new_exec_filter(cmd, argument_count);
}