author | Michael Krelin <hacker@klever.net> | 2007-07-20 18:56:43 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-20 18:56:43 (UTC) |
commit | 127f43d4e202ba3e63f72add44238c2686dd97f3 (patch) (unidiff) | |
tree | 5543c525155fdb0d925d881094307e4be807c002 | |
parent | 3aae82703bfe70fc273f0611cdc780804df77bb8 (diff) | |
download | cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.zip cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.tar.gz cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.tar.bz2 |
added a chk_non_negative check
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | shared.c | 7 |
2 files changed, 8 insertions, 0 deletions
@@ -112,96 +112,97 @@ extern char *cgit_logo_link; | |||
112 | extern char *cgit_module_link; | 112 | extern char *cgit_module_link; |
113 | extern char *cgit_agefile; | 113 | extern char *cgit_agefile; |
114 | extern char *cgit_virtual_root; | 114 | extern char *cgit_virtual_root; |
115 | extern char *cgit_script_name; | 115 | extern char *cgit_script_name; |
116 | extern char *cgit_cache_root; | 116 | extern char *cgit_cache_root; |
117 | extern char *cgit_repo_group; | 117 | extern char *cgit_repo_group; |
118 | 118 | ||
119 | extern int cgit_nocache; | 119 | extern int cgit_nocache; |
120 | extern int cgit_snapshots; | 120 | extern int cgit_snapshots; |
121 | extern int cgit_enable_index_links; | 121 | extern int cgit_enable_index_links; |
122 | extern int cgit_enable_log_filecount; | 122 | extern int cgit_enable_log_filecount; |
123 | extern int cgit_enable_log_linecount; | 123 | extern int cgit_enable_log_linecount; |
124 | extern int cgit_max_lock_attempts; | 124 | extern int cgit_max_lock_attempts; |
125 | extern int cgit_cache_root_ttl; | 125 | extern int cgit_cache_root_ttl; |
126 | extern int cgit_cache_repo_ttl; | 126 | extern int cgit_cache_repo_ttl; |
127 | extern int cgit_cache_dynamic_ttl; | 127 | extern int cgit_cache_dynamic_ttl; |
128 | extern int cgit_cache_static_ttl; | 128 | extern int cgit_cache_static_ttl; |
129 | extern int cgit_cache_max_create_time; | 129 | extern int cgit_cache_max_create_time; |
130 | extern int cgit_summary_log; | 130 | extern int cgit_summary_log; |
131 | 131 | ||
132 | extern int cgit_max_msg_len; | 132 | extern int cgit_max_msg_len; |
133 | extern int cgit_max_repodesc_len; | 133 | extern int cgit_max_repodesc_len; |
134 | extern int cgit_max_commit_count; | 134 | extern int cgit_max_commit_count; |
135 | 135 | ||
136 | extern int cgit_query_has_symref; | 136 | extern int cgit_query_has_symref; |
137 | extern int cgit_query_has_sha1; | 137 | extern int cgit_query_has_sha1; |
138 | 138 | ||
139 | extern char *cgit_querystring; | 139 | extern char *cgit_querystring; |
140 | extern char *cgit_query_repo; | 140 | extern char *cgit_query_repo; |
141 | extern char *cgit_query_page; | 141 | extern char *cgit_query_page; |
142 | extern char *cgit_query_search; | 142 | extern char *cgit_query_search; |
143 | extern char *cgit_query_head; | 143 | extern char *cgit_query_head; |
144 | extern char *cgit_query_sha1; | 144 | extern char *cgit_query_sha1; |
145 | extern char *cgit_query_sha2; | 145 | extern char *cgit_query_sha2; |
146 | extern char *cgit_query_path; | 146 | extern char *cgit_query_path; |
147 | extern char *cgit_query_name; | 147 | extern char *cgit_query_name; |
148 | extern int cgit_query_ofs; | 148 | extern int cgit_query_ofs; |
149 | 149 | ||
150 | extern int htmlfd; | 150 | extern int htmlfd; |
151 | 151 | ||
152 | extern int cgit_get_cmd_index(const char *cmd); | 152 | extern int cgit_get_cmd_index(const char *cmd); |
153 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 153 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
154 | extern void cgit_global_config_cb(const char *name, const char *value); | 154 | extern void cgit_global_config_cb(const char *name, const char *value); |
155 | extern void cgit_repo_config_cb(const char *name, const char *value); | 155 | extern void cgit_repo_config_cb(const char *name, const char *value); |
156 | extern void cgit_querystring_cb(const char *name, const char *value); | 156 | extern void cgit_querystring_cb(const char *name, const char *value); |
157 | 157 | ||
158 | extern int chk_zero(int result, char *msg); | 158 | extern int chk_zero(int result, char *msg); |
159 | extern int chk_positive(int result, char *msg); | 159 | extern int chk_positive(int result, char *msg); |
160 | extern int chk_non_negative(int result, char *msg); | ||
160 | 161 | ||
161 | extern int hextoint(char c); | 162 | extern int hextoint(char c); |
162 | extern char *trim_end(const char *str, char c); | 163 | extern char *trim_end(const char *str, char c); |
163 | 164 | ||
164 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 165 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
165 | 166 | ||
166 | extern int cgit_diff_files(const unsigned char *old_sha1, | 167 | extern int cgit_diff_files(const unsigned char *old_sha1, |
167 | const unsigned char *new_sha1, | 168 | const unsigned char *new_sha1, |
168 | linediff_fn fn); | 169 | linediff_fn fn); |
169 | 170 | ||
170 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 171 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
171 | const unsigned char *new_sha1, | 172 | const unsigned char *new_sha1, |
172 | filepair_fn fn); | 173 | filepair_fn fn); |
173 | 174 | ||
174 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 175 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
175 | 176 | ||
176 | extern char *fmt(const char *format,...); | 177 | extern char *fmt(const char *format,...); |
177 | 178 | ||
178 | extern void html(const char *txt); | 179 | extern void html(const char *txt); |
179 | extern void htmlf(const char *format,...); | 180 | extern void htmlf(const char *format,...); |
180 | extern void html_txt(char *txt); | 181 | extern void html_txt(char *txt); |
181 | extern void html_ntxt(int len, char *txt); | 182 | extern void html_ntxt(int len, char *txt); |
182 | extern void html_attr(char *txt); | 183 | extern void html_attr(char *txt); |
183 | extern void html_hidden(char *name, char *value); | 184 | extern void html_hidden(char *name, char *value); |
184 | extern void html_link_open(char *url, char *title, char *class); | 185 | extern void html_link_open(char *url, char *title, char *class); |
185 | extern void html_link_close(void); | 186 | extern void html_link_close(void); |
186 | extern void html_filemode(unsigned short mode); | 187 | extern void html_filemode(unsigned short mode); |
187 | extern int html_include(const char *filename); | 188 | extern int html_include(const char *filename); |
188 | 189 | ||
189 | extern int cgit_read_config(const char *filename, configfn fn); | 190 | extern int cgit_read_config(const char *filename, configfn fn); |
190 | extern int cgit_parse_query(char *txt, configfn fn); | 191 | extern int cgit_parse_query(char *txt, configfn fn); |
191 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
192 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
193 | extern void cgit_parse_url(const char *url); | 194 | extern void cgit_parse_url(const char *url); |
194 | 195 | ||
195 | extern char *cache_safe_filename(const char *unsafe); | 196 | extern char *cache_safe_filename(const char *unsafe); |
196 | extern int cache_lock(struct cacheitem *item); | 197 | extern int cache_lock(struct cacheitem *item); |
197 | extern int cache_unlock(struct cacheitem *item); | 198 | extern int cache_unlock(struct cacheitem *item); |
198 | extern int cache_cancel_lock(struct cacheitem *item); | 199 | extern int cache_cancel_lock(struct cacheitem *item); |
199 | extern int cache_exist(struct cacheitem *item); | 200 | extern int cache_exist(struct cacheitem *item); |
200 | extern int cache_expired(struct cacheitem *item); | 201 | extern int cache_expired(struct cacheitem *item); |
201 | 202 | ||
202 | extern char *cgit_repourl(const char *reponame); | 203 | extern char *cgit_repourl(const char *reponame); |
203 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 204 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
204 | const char *query); | 205 | const char *query); |
205 | 206 | ||
206 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 207 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
207 | char *rev, char *path); | 208 | char *rev, char *path); |
@@ -41,96 +41,103 @@ int cgit_summary_log = 0; | |||
41 | 41 | ||
42 | int cgit_max_msg_len = 60; | 42 | int cgit_max_msg_len = 60; |
43 | int cgit_max_repodesc_len = 60; | 43 | int cgit_max_repodesc_len = 60; |
44 | int cgit_max_commit_count = 50; | 44 | int cgit_max_commit_count = 50; |
45 | 45 | ||
46 | int cgit_query_has_symref = 0; | 46 | int cgit_query_has_symref = 0; |
47 | int cgit_query_has_sha1 = 0; | 47 | int cgit_query_has_sha1 = 0; |
48 | 48 | ||
49 | char *cgit_querystring = NULL; | 49 | char *cgit_querystring = NULL; |
50 | char *cgit_query_repo = NULL; | 50 | char *cgit_query_repo = NULL; |
51 | char *cgit_query_page = NULL; | 51 | char *cgit_query_page = NULL; |
52 | char *cgit_query_head = NULL; | 52 | char *cgit_query_head = NULL; |
53 | char *cgit_query_search = NULL; | 53 | char *cgit_query_search = NULL; |
54 | char *cgit_query_sha1 = NULL; | 54 | char *cgit_query_sha1 = NULL; |
55 | char *cgit_query_sha2 = NULL; | 55 | char *cgit_query_sha2 = NULL; |
56 | char *cgit_query_path = NULL; | 56 | char *cgit_query_path = NULL; |
57 | char *cgit_query_name = NULL; | 57 | char *cgit_query_name = NULL; |
58 | int cgit_query_ofs = 0; | 58 | int cgit_query_ofs = 0; |
59 | 59 | ||
60 | int htmlfd = 0; | 60 | int htmlfd = 0; |
61 | 61 | ||
62 | 62 | ||
63 | int cgit_get_cmd_index(const char *cmd) | 63 | int cgit_get_cmd_index(const char *cmd) |
64 | { | 64 | { |
65 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 65 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
66 | "snapshot", NULL}; | 66 | "snapshot", NULL}; |
67 | int i; | 67 | int i; |
68 | 68 | ||
69 | for(i = 0; cmds[i]; i++) | 69 | for(i = 0; cmds[i]; i++) |
70 | if (!strcmp(cmd, cmds[i])) | 70 | if (!strcmp(cmd, cmds[i])) |
71 | return i + 1; | 71 | return i + 1; |
72 | return 0; | 72 | return 0; |
73 | } | 73 | } |
74 | 74 | ||
75 | int chk_zero(int result, char *msg) | 75 | int chk_zero(int result, char *msg) |
76 | { | 76 | { |
77 | if (result != 0) | 77 | if (result != 0) |
78 | die("%s: %s", msg, strerror(errno)); | 78 | die("%s: %s", msg, strerror(errno)); |
79 | return result; | 79 | return result; |
80 | } | 80 | } |
81 | 81 | ||
82 | int chk_positive(int result, char *msg) | 82 | int chk_positive(int result, char *msg) |
83 | { | 83 | { |
84 | if (result <= 0) | 84 | if (result <= 0) |
85 | die("%s: %s", msg, strerror(errno)); | 85 | die("%s: %s", msg, strerror(errno)); |
86 | return result; | 86 | return result; |
87 | } | 87 | } |
88 | 88 | ||
89 | int chk_non_negative(int result, char *msg) | ||
90 | { | ||
91 | if (result < 0) | ||
92 | die("%s: %s",msg, strerror(errno)); | ||
93 | return result; | ||
94 | } | ||
95 | |||
89 | struct repoinfo *add_repo(const char *url) | 96 | struct repoinfo *add_repo(const char *url) |
90 | { | 97 | { |
91 | struct repoinfo *ret; | 98 | struct repoinfo *ret; |
92 | 99 | ||
93 | if (++cgit_repolist.count > cgit_repolist.length) { | 100 | if (++cgit_repolist.count > cgit_repolist.length) { |
94 | if (cgit_repolist.length == 0) | 101 | if (cgit_repolist.length == 0) |
95 | cgit_repolist.length = 8; | 102 | cgit_repolist.length = 8; |
96 | else | 103 | else |
97 | cgit_repolist.length *= 2; | 104 | cgit_repolist.length *= 2; |
98 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 105 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
99 | cgit_repolist.length * | 106 | cgit_repolist.length * |
100 | sizeof(struct repoinfo)); | 107 | sizeof(struct repoinfo)); |
101 | } | 108 | } |
102 | 109 | ||
103 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 110 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
104 | ret->url = xstrdup(url); | 111 | ret->url = xstrdup(url); |
105 | ret->name = ret->url; | 112 | ret->name = ret->url; |
106 | ret->path = NULL; | 113 | ret->path = NULL; |
107 | ret->desc = NULL; | 114 | ret->desc = NULL; |
108 | ret->owner = NULL; | 115 | ret->owner = NULL; |
109 | ret->group = cgit_repo_group; | 116 | ret->group = cgit_repo_group; |
110 | ret->defbranch = "master"; | 117 | ret->defbranch = "master"; |
111 | ret->snapshots = cgit_snapshots; | 118 | ret->snapshots = cgit_snapshots; |
112 | ret->enable_log_filecount = cgit_enable_log_filecount; | 119 | ret->enable_log_filecount = cgit_enable_log_filecount; |
113 | ret->enable_log_linecount = cgit_enable_log_linecount; | 120 | ret->enable_log_linecount = cgit_enable_log_linecount; |
114 | ret->module_link = cgit_module_link; | 121 | ret->module_link = cgit_module_link; |
115 | ret->readme = NULL; | 122 | ret->readme = NULL; |
116 | return ret; | 123 | return ret; |
117 | } | 124 | } |
118 | 125 | ||
119 | struct repoinfo *cgit_get_repoinfo(const char *url) | 126 | struct repoinfo *cgit_get_repoinfo(const char *url) |
120 | { | 127 | { |
121 | int i; | 128 | int i; |
122 | struct repoinfo *repo; | 129 | struct repoinfo *repo; |
123 | 130 | ||
124 | for (i=0; i<cgit_repolist.count; i++) { | 131 | for (i=0; i<cgit_repolist.count; i++) { |
125 | repo = &cgit_repolist.repos[i]; | 132 | repo = &cgit_repolist.repos[i]; |
126 | if (!strcmp(repo->url, url)) | 133 | if (!strcmp(repo->url, url)) |
127 | return repo; | 134 | return repo; |
128 | } | 135 | } |
129 | return NULL; | 136 | return NULL; |
130 | } | 137 | } |
131 | 138 | ||
132 | void cgit_global_config_cb(const char *name, const char *value) | 139 | void cgit_global_config_cb(const char *name, const char *value) |
133 | { | 140 | { |
134 | if (!strcmp(name, "root-title")) | 141 | if (!strcmp(name, "root-title")) |
135 | cgit_root_title = xstrdup(value); | 142 | cgit_root_title = xstrdup(value); |
136 | else if (!strcmp(name, "css")) | 143 | else if (!strcmp(name, "css")) |