summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 6fd70a8..5757d0c 100644
--- a/shared.c
+++ b/shared.c
@@ -23,52 +23,67 @@ int cgit_nocache = 0;
23int cgit_max_lock_attempts = 5; 23int cgit_max_lock_attempts = 5;
24int cgit_cache_root_ttl = 5; 24int cgit_cache_root_ttl = 5;
25int cgit_cache_repo_ttl = 5; 25int cgit_cache_repo_ttl = 5;
26int cgit_cache_dynamic_ttl = 5; 26int cgit_cache_dynamic_ttl = 5;
27int cgit_cache_static_ttl = -1; 27int cgit_cache_static_ttl = -1;
28int cgit_cache_max_create_time = 5; 28int cgit_cache_max_create_time = 5;
29 29
30int cgit_max_msg_len = 60; 30int cgit_max_msg_len = 60;
31 31
32char *cgit_repo_name = NULL; 32char *cgit_repo_name = NULL;
33char *cgit_repo_desc = NULL; 33char *cgit_repo_desc = NULL;
34char *cgit_repo_owner = NULL; 34char *cgit_repo_owner = NULL;
35 35
36int cgit_query_has_symref = 0; 36int cgit_query_has_symref = 0;
37int cgit_query_has_sha1 = 0; 37int cgit_query_has_sha1 = 0;
38 38
39char *cgit_querystring = NULL; 39char *cgit_querystring = NULL;
40char *cgit_query_repo = NULL; 40char *cgit_query_repo = NULL;
41char *cgit_query_page = NULL; 41char *cgit_query_page = NULL;
42char *cgit_query_head = NULL; 42char *cgit_query_head = NULL;
43char *cgit_query_search = NULL; 43char *cgit_query_search = NULL;
44char *cgit_query_sha1 = NULL; 44char *cgit_query_sha1 = NULL;
45char *cgit_query_sha2 = NULL; 45char *cgit_query_sha2 = NULL;
46char *cgit_query_path = NULL; 46char *cgit_query_path = NULL;
47char *cgit_query_name = NULL;
47int cgit_query_ofs = 0; 48int cgit_query_ofs = 0;
48 49
49int htmlfd = 0; 50int htmlfd = 0;
50 51
52int chk_zero(int result, char *msg)
53{
54 if (result != 0)
55 die("%s: %s", msg, strerror(errno));
56 return result;
57}
58
59int chk_positive(int result, char *msg)
60{
61 if (result <= 0)
62 die("%s: %s", msg, strerror(errno));
63 return result;
64}
65
51struct repoinfo *add_repo(const char *url) 66struct repoinfo *add_repo(const char *url)
52{ 67{
53 struct repoinfo *ret; 68 struct repoinfo *ret;
54 69
55 if (++cgit_repolist.count > cgit_repolist.length) { 70 if (++cgit_repolist.count > cgit_repolist.length) {
56 if (cgit_repolist.length == 0) 71 if (cgit_repolist.length == 0)
57 cgit_repolist.length = 8; 72 cgit_repolist.length = 8;
58 else 73 else
59 cgit_repolist.length *= 2; 74 cgit_repolist.length *= 2;
60 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 75 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
61 cgit_repolist.length * 76 cgit_repolist.length *
62 sizeof(struct repoinfo)); 77 sizeof(struct repoinfo));
63 } 78 }
64 79
65 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 80 ret = &cgit_repolist.repos[cgit_repolist.count-1];
66 ret->url = xstrdup(url); 81 ret->url = xstrdup(url);
67 ret->name = ret->url; 82 ret->name = ret->url;
68 ret->path = NULL; 83 ret->path = NULL;
69 ret->desc = NULL; 84 ret->desc = NULL;
70 ret->owner = NULL; 85 ret->owner = NULL;
71 return ret; 86 return ret;
72} 87}
73 88
74void cgit_global_config_cb(const char *name, const char *value) 89void cgit_global_config_cb(const char *name, const char *value)
@@ -119,48 +134,50 @@ void cgit_repo_config_cb(const char *name, const char *value)
119 cgit_repo_owner = xstrdup(value); 134 cgit_repo_owner = xstrdup(value);
120} 135}
121 136
122void cgit_querystring_cb(const char *name, const char *value) 137void cgit_querystring_cb(const char *name, const char *value)
123{ 138{
124 if (!strcmp(name,"r")) { 139 if (!strcmp(name,"r")) {
125 cgit_query_repo = xstrdup(value); 140 cgit_query_repo = xstrdup(value);
126 } else if (!strcmp(name, "p")) { 141 } else if (!strcmp(name, "p")) {
127 cgit_query_page = xstrdup(value); 142 cgit_query_page = xstrdup(value);
128 } else if (!strcmp(name, "q")) { 143 } else if (!strcmp(name, "q")) {
129 cgit_query_search = xstrdup(value); 144 cgit_query_search = xstrdup(value);
130 } else if (!strcmp(name, "h")) { 145 } else if (!strcmp(name, "h")) {
131 cgit_query_head = xstrdup(value); 146 cgit_query_head = xstrdup(value);
132 cgit_query_has_symref = 1; 147 cgit_query_has_symref = 1;
133 } else if (!strcmp(name, "id")) { 148 } else if (!strcmp(name, "id")) {
134 cgit_query_sha1 = xstrdup(value); 149 cgit_query_sha1 = xstrdup(value);
135 cgit_query_has_sha1 = 1; 150 cgit_query_has_sha1 = 1;
136 } else if (!strcmp(name, "id2")) { 151 } else if (!strcmp(name, "id2")) {
137 cgit_query_sha2 = xstrdup(value); 152 cgit_query_sha2 = xstrdup(value);
138 cgit_query_has_sha1 = 1; 153 cgit_query_has_sha1 = 1;
139 } else if (!strcmp(name, "ofs")) { 154 } else if (!strcmp(name, "ofs")) {
140 cgit_query_ofs = atoi(value); 155 cgit_query_ofs = atoi(value);
141 } else if (!strcmp(name, "path")) { 156 } else if (!strcmp(name, "path")) {
142 cgit_query_path = xstrdup(value); 157 cgit_query_path = xstrdup(value);
158 } else if (!strcmp(name, "name")) {
159 cgit_query_name = xstrdup(value);
143 } 160 }
144} 161}
145 162
146void *cgit_free_commitinfo(struct commitinfo *info) 163void *cgit_free_commitinfo(struct commitinfo *info)
147{ 164{
148 free(info->author); 165 free(info->author);
149 free(info->author_email); 166 free(info->author_email);
150 free(info->committer); 167 free(info->committer);
151 free(info->committer_email); 168 free(info->committer_email);
152 free(info->subject); 169 free(info->subject);
153 free(info); 170 free(info);
154 return NULL; 171 return NULL;
155} 172}
156 173
157int hextoint(char c) 174int hextoint(char c)
158{ 175{
159 if (c >= 'a' && c <= 'f') 176 if (c >= 'a' && c <= 'f')
160 return 10 + c - 'a'; 177 return 10 + c - 'a';
161 else if (c >= 'A' && c <= 'F') 178 else if (c >= 'A' && c <= 'F')
162 return 10 + c - 'A'; 179 return 10 + c - 'A';
163 else if (c >= '0' && c <= '9') 180 else if (c >= '0' && c <= '9')
164 return c - '0'; 181 return c - '0';
165 else 182 else
166 return -1; 183 return -1;