summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-07-20 18:56:43 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-20 18:56:43 (UTC)
commit127f43d4e202ba3e63f72add44238c2686dd97f3 (patch) (unidiff)
tree5543c525155fdb0d925d881094307e4be807c002
parent3aae82703bfe70fc273f0611cdc780804df77bb8 (diff)
downloadcgit-127f43d4e202ba3e63f72add44238c2686dd97f3.zip
cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.tar.gz
cgit-127f43d4e202ba3e63f72add44238c2686dd97f3.tar.bz2
added a chk_non_negative check
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h1
-rw-r--r--shared.c7
2 files changed, 8 insertions, 0 deletions
diff --git a/cgit.h b/cgit.h
index f01f6c9..6937c42 100644
--- a/cgit.h
+++ b/cgit.h
@@ -112,96 +112,97 @@ extern char *cgit_logo_link;
112extern char *cgit_module_link; 112extern char *cgit_module_link;
113extern char *cgit_agefile; 113extern char *cgit_agefile;
114extern char *cgit_virtual_root; 114extern char *cgit_virtual_root;
115extern char *cgit_script_name; 115extern char *cgit_script_name;
116extern char *cgit_cache_root; 116extern char *cgit_cache_root;
117extern char *cgit_repo_group; 117extern char *cgit_repo_group;
118 118
119extern int cgit_nocache; 119extern int cgit_nocache;
120extern int cgit_snapshots; 120extern int cgit_snapshots;
121extern int cgit_enable_index_links; 121extern int cgit_enable_index_links;
122extern int cgit_enable_log_filecount; 122extern int cgit_enable_log_filecount;
123extern int cgit_enable_log_linecount; 123extern int cgit_enable_log_linecount;
124extern int cgit_max_lock_attempts; 124extern int cgit_max_lock_attempts;
125extern int cgit_cache_root_ttl; 125extern int cgit_cache_root_ttl;
126extern int cgit_cache_repo_ttl; 126extern int cgit_cache_repo_ttl;
127extern int cgit_cache_dynamic_ttl; 127extern int cgit_cache_dynamic_ttl;
128extern int cgit_cache_static_ttl; 128extern int cgit_cache_static_ttl;
129extern int cgit_cache_max_create_time; 129extern int cgit_cache_max_create_time;
130extern int cgit_summary_log; 130extern int cgit_summary_log;
131 131
132extern int cgit_max_msg_len; 132extern int cgit_max_msg_len;
133extern int cgit_max_repodesc_len; 133extern int cgit_max_repodesc_len;
134extern int cgit_max_commit_count; 134extern int cgit_max_commit_count;
135 135
136extern int cgit_query_has_symref; 136extern int cgit_query_has_symref;
137extern int cgit_query_has_sha1; 137extern int cgit_query_has_sha1;
138 138
139extern char *cgit_querystring; 139extern char *cgit_querystring;
140extern char *cgit_query_repo; 140extern char *cgit_query_repo;
141extern char *cgit_query_page; 141extern char *cgit_query_page;
142extern char *cgit_query_search; 142extern char *cgit_query_search;
143extern char *cgit_query_head; 143extern char *cgit_query_head;
144extern char *cgit_query_sha1; 144extern char *cgit_query_sha1;
145extern char *cgit_query_sha2; 145extern char *cgit_query_sha2;
146extern char *cgit_query_path; 146extern char *cgit_query_path;
147extern char *cgit_query_name; 147extern char *cgit_query_name;
148extern int cgit_query_ofs; 148extern int cgit_query_ofs;
149 149
150extern int htmlfd; 150extern int htmlfd;
151 151
152extern int cgit_get_cmd_index(const char *cmd); 152extern int cgit_get_cmd_index(const char *cmd);
153extern struct repoinfo *cgit_get_repoinfo(const char *url); 153extern struct repoinfo *cgit_get_repoinfo(const char *url);
154extern void cgit_global_config_cb(const char *name, const char *value); 154extern void cgit_global_config_cb(const char *name, const char *value);
155extern void cgit_repo_config_cb(const char *name, const char *value); 155extern void cgit_repo_config_cb(const char *name, const char *value);
156extern void cgit_querystring_cb(const char *name, const char *value); 156extern void cgit_querystring_cb(const char *name, const char *value);
157 157
158extern int chk_zero(int result, char *msg); 158extern int chk_zero(int result, char *msg);
159extern int chk_positive(int result, char *msg); 159extern int chk_positive(int result, char *msg);
160extern int chk_non_negative(int result, char *msg);
160 161
161extern int hextoint(char c); 162extern int hextoint(char c);
162extern char *trim_end(const char *str, char c); 163extern char *trim_end(const char *str, char c);
163 164
164extern void *cgit_free_commitinfo(struct commitinfo *info); 165extern void *cgit_free_commitinfo(struct commitinfo *info);
165 166
166extern int cgit_diff_files(const unsigned char *old_sha1, 167extern 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
170extern void cgit_diff_tree(const unsigned char *old_sha1, 171extern 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
174extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 175extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
175 176
176extern char *fmt(const char *format,...); 177extern char *fmt(const char *format,...);
177 178
178extern void html(const char *txt); 179extern void html(const char *txt);
179extern void htmlf(const char *format,...); 180extern void htmlf(const char *format,...);
180extern void html_txt(char *txt); 181extern void html_txt(char *txt);
181extern void html_ntxt(int len, char *txt); 182extern void html_ntxt(int len, char *txt);
182extern void html_attr(char *txt); 183extern void html_attr(char *txt);
183extern void html_hidden(char *name, char *value); 184extern void html_hidden(char *name, char *value);
184extern void html_link_open(char *url, char *title, char *class); 185extern void html_link_open(char *url, char *title, char *class);
185extern void html_link_close(void); 186extern void html_link_close(void);
186extern void html_filemode(unsigned short mode); 187extern void html_filemode(unsigned short mode);
187extern int html_include(const char *filename); 188extern int html_include(const char *filename);
188 189
189extern int cgit_read_config(const char *filename, configfn fn); 190extern int cgit_read_config(const char *filename, configfn fn);
190extern int cgit_parse_query(char *txt, configfn fn); 191extern int cgit_parse_query(char *txt, configfn fn);
191extern struct commitinfo *cgit_parse_commit(struct commit *commit); 192extern struct commitinfo *cgit_parse_commit(struct commit *commit);
192extern struct taginfo *cgit_parse_tag(struct tag *tag); 193extern struct taginfo *cgit_parse_tag(struct tag *tag);
193extern void cgit_parse_url(const char *url); 194extern void cgit_parse_url(const char *url);
194 195
195extern char *cache_safe_filename(const char *unsafe); 196extern char *cache_safe_filename(const char *unsafe);
196extern int cache_lock(struct cacheitem *item); 197extern int cache_lock(struct cacheitem *item);
197extern int cache_unlock(struct cacheitem *item); 198extern int cache_unlock(struct cacheitem *item);
198extern int cache_cancel_lock(struct cacheitem *item); 199extern int cache_cancel_lock(struct cacheitem *item);
199extern int cache_exist(struct cacheitem *item); 200extern int cache_exist(struct cacheitem *item);
200extern int cache_expired(struct cacheitem *item); 201extern int cache_expired(struct cacheitem *item);
201 202
202extern char *cgit_repourl(const char *reponame); 203extern char *cgit_repourl(const char *reponame);
203extern char *cgit_pageurl(const char *reponame, const char *pagename, 204extern char *cgit_pageurl(const char *reponame, const char *pagename,
204 const char *query); 205 const char *query);
205 206
206extern void cgit_tree_link(char *name, char *title, char *class, char *head, 207extern void cgit_tree_link(char *name, char *title, char *class, char *head,
207 char *rev, char *path); 208 char *rev, char *path);
diff --git a/shared.c b/shared.c
index 1a5b866..65fc8b2 100644
--- a/shared.c
+++ b/shared.c
@@ -41,96 +41,103 @@ int cgit_summary_log = 0;
41 41
42int cgit_max_msg_len = 60; 42int cgit_max_msg_len = 60;
43int cgit_max_repodesc_len = 60; 43int cgit_max_repodesc_len = 60;
44int cgit_max_commit_count = 50; 44int cgit_max_commit_count = 50;
45 45
46int cgit_query_has_symref = 0; 46int cgit_query_has_symref = 0;
47int cgit_query_has_sha1 = 0; 47int cgit_query_has_sha1 = 0;
48 48
49char *cgit_querystring = NULL; 49char *cgit_querystring = NULL;
50char *cgit_query_repo = NULL; 50char *cgit_query_repo = NULL;
51char *cgit_query_page = NULL; 51char *cgit_query_page = NULL;
52char *cgit_query_head = NULL; 52char *cgit_query_head = NULL;
53char *cgit_query_search = NULL; 53char *cgit_query_search = NULL;
54char *cgit_query_sha1 = NULL; 54char *cgit_query_sha1 = NULL;
55char *cgit_query_sha2 = NULL; 55char *cgit_query_sha2 = NULL;
56char *cgit_query_path = NULL; 56char *cgit_query_path = NULL;
57char *cgit_query_name = NULL; 57char *cgit_query_name = NULL;
58int cgit_query_ofs = 0; 58int cgit_query_ofs = 0;
59 59
60int htmlfd = 0; 60int htmlfd = 0;
61 61
62 62
63int cgit_get_cmd_index(const char *cmd) 63int 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
75int chk_zero(int result, char *msg) 75int 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
82int chk_positive(int result, char *msg) 82int 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
89int chk_non_negative(int result, char *msg)
90{
91 if (result < 0)
92 die("%s: %s",msg, strerror(errno));
93 return result;
94}
95
89struct repoinfo *add_repo(const char *url) 96struct 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
119struct repoinfo *cgit_get_repoinfo(const char *url) 126struct 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
132void cgit_global_config_cb(const char *name, const char *value) 139void 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"))