author | Ferry Huberts <ferry.huberts@pelagic.nl> | 2011-03-09 07:16:59 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2011-03-26 14:13:35 (UTC) |
commit | 5db02854e64fa41aa459ea7d13fc827063deda41 (patch) (unidiff) | |
tree | 8db8d588e5d1f2bf3ede996e5907569389677eb8 /cgit.c | |
parent | 3f1ebd3565afa33196dfc3e8584e04564987e33c (diff) | |
download | cgit-5db02854e64fa41aa459ea7d13fc827063deda41.zip cgit-5db02854e64fa41aa459ea7d13fc827063deda41.tar.gz cgit-5db02854e64fa41aa459ea7d13fc827063deda41.tar.bz2 |
new_filter: correctly initialise all arguments for a new filter
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1,136 +1,138 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | 4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> |
5 | * | 5 | * |
6 | * Licensed under GNU General Public License v2 | 6 | * Licensed under GNU General Public License v2 |
7 | * (see COPYING for full license text) | 7 | * (see COPYING for full license text) |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "cgit.h" | 10 | #include "cgit.h" |
11 | #include "cache.h" | 11 | #include "cache.h" |
12 | #include "cmd.h" | 12 | #include "cmd.h" |
13 | #include "configfile.h" | 13 | #include "configfile.h" |
14 | #include "html.h" | 14 | #include "html.h" |
15 | #include "ui-shared.h" | 15 | #include "ui-shared.h" |
16 | #include "ui-stats.h" | 16 | #include "ui-stats.h" |
17 | #include "scan-tree.h" | 17 | #include "scan-tree.h" |
18 | 18 | ||
19 | const char *cgit_version = CGIT_VERSION; | 19 | const char *cgit_version = CGIT_VERSION; |
20 | 20 | ||
21 | void add_mimetype(const char *name, const char *value) | 21 | void add_mimetype(const char *name, const char *value) |
22 | { | 22 | { |
23 | struct string_list_item *item; | 23 | struct string_list_item *item; |
24 | 24 | ||
25 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); | 25 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); |
26 | item->util = xstrdup(value); | 26 | item->util = xstrdup(value); |
27 | } | 27 | } |
28 | 28 | ||
29 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 29 | struct cgit_filter *new_filter(const char *cmd, int extra_args) |
30 | { | 30 | { |
31 | struct cgit_filter *f; | 31 | struct cgit_filter *f; |
32 | int args_size = 0; | ||
32 | 33 | ||
33 | if (!cmd || !cmd[0]) | 34 | if (!cmd || !cmd[0]) |
34 | return NULL; | 35 | return NULL; |
35 | 36 | ||
36 | f = xmalloc(sizeof(struct cgit_filter)); | 37 | f = xmalloc(sizeof(struct cgit_filter)); |
37 | f->cmd = xstrdup(cmd); | 38 | f->cmd = xstrdup(cmd); |
38 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); | 39 | args_size = (2 + extra_args) * sizeof(char *); |
40 | f->argv = xmalloc(args_size); | ||
41 | memset(f->argv, 0, args_size); | ||
39 | f->argv[0] = f->cmd; | 42 | f->argv[0] = f->cmd; |
40 | f->argv[1] = NULL; | ||
41 | return f; | 43 | return f; |
42 | } | 44 | } |
43 | 45 | ||
44 | static void process_cached_repolist(const char *path); | 46 | static void process_cached_repolist(const char *path); |
45 | 47 | ||
46 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) | 48 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) |
47 | { | 49 | { |
48 | if (!strcmp(name, "name")) | 50 | if (!strcmp(name, "name")) |
49 | repo->name = xstrdup(value); | 51 | repo->name = xstrdup(value); |
50 | else if (!strcmp(name, "clone-url")) | 52 | else if (!strcmp(name, "clone-url")) |
51 | repo->clone_url = xstrdup(value); | 53 | repo->clone_url = xstrdup(value); |
52 | else if (!strcmp(name, "desc")) | 54 | else if (!strcmp(name, "desc")) |
53 | repo->desc = xstrdup(value); | 55 | repo->desc = xstrdup(value); |
54 | else if (!strcmp(name, "owner")) | 56 | else if (!strcmp(name, "owner")) |
55 | repo->owner = xstrdup(value); | 57 | repo->owner = xstrdup(value); |
56 | else if (!strcmp(name, "defbranch")) | 58 | else if (!strcmp(name, "defbranch")) |
57 | repo->defbranch = xstrdup(value); | 59 | repo->defbranch = xstrdup(value); |
58 | else if (!strcmp(name, "snapshots")) | 60 | else if (!strcmp(name, "snapshots")) |
59 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); | 61 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); |
60 | else if (!strcmp(name, "enable-commit-graph")) | 62 | else if (!strcmp(name, "enable-commit-graph")) |
61 | repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value); | 63 | repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value); |
62 | else if (!strcmp(name, "enable-log-filecount")) | 64 | else if (!strcmp(name, "enable-log-filecount")) |
63 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 65 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
64 | else if (!strcmp(name, "enable-log-linecount")) | 66 | else if (!strcmp(name, "enable-log-linecount")) |
65 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 67 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
66 | else if (!strcmp(name, "enable-remote-branches")) | 68 | else if (!strcmp(name, "enable-remote-branches")) |
67 | repo->enable_remote_branches = atoi(value); | 69 | repo->enable_remote_branches = atoi(value); |
68 | else if (!strcmp(name, "enable-subject-links")) | 70 | else if (!strcmp(name, "enable-subject-links")) |
69 | repo->enable_subject_links = atoi(value); | 71 | repo->enable_subject_links = atoi(value); |
70 | else if (!strcmp(name, "max-stats")) | 72 | else if (!strcmp(name, "max-stats")) |
71 | repo->max_stats = cgit_find_stats_period(value, NULL); | 73 | repo->max_stats = cgit_find_stats_period(value, NULL); |
72 | else if (!strcmp(name, "module-link")) | 74 | else if (!strcmp(name, "module-link")) |
73 | repo->module_link= xstrdup(value); | 75 | repo->module_link= xstrdup(value); |
74 | else if (!strcmp(name, "section")) | 76 | else if (!strcmp(name, "section")) |
75 | repo->section = xstrdup(value); | 77 | repo->section = xstrdup(value); |
76 | else if (!strcmp(name, "readme") && value != NULL) | 78 | else if (!strcmp(name, "readme") && value != NULL) |
77 | repo->readme = xstrdup(value); | 79 | repo->readme = xstrdup(value); |
78 | else if (!strcmp(name, "logo") && value != NULL) | 80 | else if (!strcmp(name, "logo") && value != NULL) |
79 | repo->logo = xstrdup(value); | 81 | repo->logo = xstrdup(value); |
80 | else if (!strcmp(name, "logo-link") && value != NULL) | 82 | else if (!strcmp(name, "logo-link") && value != NULL) |
81 | repo->logo_link = xstrdup(value); | 83 | repo->logo_link = xstrdup(value); |
82 | else if (ctx.cfg.enable_filter_overrides) { | 84 | else if (ctx.cfg.enable_filter_overrides) { |
83 | if (!strcmp(name, "about-filter")) | 85 | if (!strcmp(name, "about-filter")) |
84 | repo->about_filter = new_filter(value, 0); | 86 | repo->about_filter = new_filter(value, 0); |
85 | else if (!strcmp(name, "commit-filter")) | 87 | else if (!strcmp(name, "commit-filter")) |
86 | repo->commit_filter = new_filter(value, 0); | 88 | repo->commit_filter = new_filter(value, 0); |
87 | else if (!strcmp(name, "source-filter")) | 89 | else if (!strcmp(name, "source-filter")) |
88 | repo->source_filter = new_filter(value, 1); | 90 | repo->source_filter = new_filter(value, 1); |
89 | } | 91 | } |
90 | } | 92 | } |
91 | 93 | ||
92 | void config_cb(const char *name, const char *value) | 94 | void config_cb(const char *name, const char *value) |
93 | { | 95 | { |
94 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) | 96 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) |
95 | ctx.cfg.section = xstrdup(value); | 97 | ctx.cfg.section = xstrdup(value); |
96 | else if (!strcmp(name, "repo.url")) | 98 | else if (!strcmp(name, "repo.url")) |
97 | ctx.repo = cgit_add_repo(value); | 99 | ctx.repo = cgit_add_repo(value); |
98 | else if (ctx.repo && !strcmp(name, "repo.path")) | 100 | else if (ctx.repo && !strcmp(name, "repo.path")) |
99 | ctx.repo->path = trim_end(value, '/'); | 101 | ctx.repo->path = trim_end(value, '/'); |
100 | else if (ctx.repo && !prefixcmp(name, "repo.")) | 102 | else if (ctx.repo && !prefixcmp(name, "repo.")) |
101 | repo_config(ctx.repo, name + 5, value); | 103 | repo_config(ctx.repo, name + 5, value); |
102 | else if (!strcmp(name, "readme")) | 104 | else if (!strcmp(name, "readme")) |
103 | ctx.cfg.readme = xstrdup(value); | 105 | ctx.cfg.readme = xstrdup(value); |
104 | else if (!strcmp(name, "root-title")) | 106 | else if (!strcmp(name, "root-title")) |
105 | ctx.cfg.root_title = xstrdup(value); | 107 | ctx.cfg.root_title = xstrdup(value); |
106 | else if (!strcmp(name, "root-desc")) | 108 | else if (!strcmp(name, "root-desc")) |
107 | ctx.cfg.root_desc = xstrdup(value); | 109 | ctx.cfg.root_desc = xstrdup(value); |
108 | else if (!strcmp(name, "root-readme")) | 110 | else if (!strcmp(name, "root-readme")) |
109 | ctx.cfg.root_readme = xstrdup(value); | 111 | ctx.cfg.root_readme = xstrdup(value); |
110 | else if (!strcmp(name, "css")) | 112 | else if (!strcmp(name, "css")) |
111 | ctx.cfg.css = xstrdup(value); | 113 | ctx.cfg.css = xstrdup(value); |
112 | else if (!strcmp(name, "favicon")) | 114 | else if (!strcmp(name, "favicon")) |
113 | ctx.cfg.favicon = xstrdup(value); | 115 | ctx.cfg.favicon = xstrdup(value); |
114 | else if (!strcmp(name, "footer")) | 116 | else if (!strcmp(name, "footer")) |
115 | ctx.cfg.footer = xstrdup(value); | 117 | ctx.cfg.footer = xstrdup(value); |
116 | else if (!strcmp(name, "head-include")) | 118 | else if (!strcmp(name, "head-include")) |
117 | ctx.cfg.head_include = xstrdup(value); | 119 | ctx.cfg.head_include = xstrdup(value); |
118 | else if (!strcmp(name, "header")) | 120 | else if (!strcmp(name, "header")) |
119 | ctx.cfg.header = xstrdup(value); | 121 | ctx.cfg.header = xstrdup(value); |
120 | else if (!strcmp(name, "logo")) | 122 | else if (!strcmp(name, "logo")) |
121 | ctx.cfg.logo = xstrdup(value); | 123 | ctx.cfg.logo = xstrdup(value); |
122 | else if (!strcmp(name, "index-header")) | 124 | else if (!strcmp(name, "index-header")) |
123 | ctx.cfg.index_header = xstrdup(value); | 125 | ctx.cfg.index_header = xstrdup(value); |
124 | else if (!strcmp(name, "index-info")) | 126 | else if (!strcmp(name, "index-info")) |
125 | ctx.cfg.index_info = xstrdup(value); | 127 | ctx.cfg.index_info = xstrdup(value); |
126 | else if (!strcmp(name, "logo-link")) | 128 | else if (!strcmp(name, "logo-link")) |
127 | ctx.cfg.logo_link = xstrdup(value); | 129 | ctx.cfg.logo_link = xstrdup(value); |
128 | else if (!strcmp(name, "module-link")) | 130 | else if (!strcmp(name, "module-link")) |
129 | ctx.cfg.module_link = xstrdup(value); | 131 | ctx.cfg.module_link = xstrdup(value); |
130 | else if (!strcmp(name, "strict-export")) | 132 | else if (!strcmp(name, "strict-export")) |
131 | ctx.cfg.strict_export = xstrdup(value); | 133 | ctx.cfg.strict_export = xstrdup(value); |
132 | else if (!strcmp(name, "virtual-root")) { | 134 | else if (!strcmp(name, "virtual-root")) { |
133 | ctx.cfg.virtual_root = trim_end(value, '/'); | 135 | ctx.cfg.virtual_root = trim_end(value, '/'); |
134 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | 136 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
135 | ctx.cfg.virtual_root = ""; | 137 | ctx.cfg.virtual_root = ""; |
136 | } else if (!strcmp(name, "nocache")) | 138 | } else if (!strcmp(name, "nocache")) |