summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (show whitespace changes)
-rw-r--r--shared.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 4ddba61..65af11a 100644
--- a/shared.c
+++ b/shared.c
@@ -7,16 +7,18 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13int cgit_cmd;
13 14
14char *cgit_root_title = "Git repository browser"; 15char *cgit_root_title = "Git repository browser";
15char *cgit_css = "/cgit.css"; 16char *cgit_css = "/cgit.css";
16char *cgit_logo = "/git-logo.png"; 17char *cgit_logo = "/git-logo.png";
18char *cgit_index_header = NULL;
17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 19char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
18char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; 20char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
19char *cgit_virtual_root = NULL; 21char *cgit_virtual_root = NULL;
20char *cgit_script_name = CGIT_SCRIPT_NAME; 22char *cgit_script_name = CGIT_SCRIPT_NAME;
21char *cgit_cache_root = "/var/cache/cgit"; 23char *cgit_cache_root = "/var/cache/cgit";
22char *cgit_repo_group = NULL; 24char *cgit_repo_group = NULL;
@@ -49,12 +51,24 @@ char *cgit_query_sha2 = NULL;
49char *cgit_query_path = NULL; 51char *cgit_query_path = NULL;
50char *cgit_query_name = NULL; 52char *cgit_query_name = NULL;
51int cgit_query_ofs = 0; 53int cgit_query_ofs = 0;
52 54
53int htmlfd = 0; 55int htmlfd = 0;
54 56
57
58int cgit_get_cmd_index(const char *cmd)
59{
60 static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL};
61 int i;
62
63 for(i = 0; cmds[i]; i++)
64 if (!strcmp(cmd, cmds[i]))
65 return i + 1;
66 return 0;
67}
68
55int chk_zero(int result, char *msg) 69int chk_zero(int result, char *msg)
56{ 70{
57 if (result != 0) 71 if (result != 0)
58 die("%s: %s", msg, strerror(errno)); 72 die("%s: %s", msg, strerror(errno));
59 return result; 73 return result;
60} 74}
@@ -92,20 +106,35 @@ struct repoinfo *add_repo(const char *url)
92 ret->enable_log_filecount = cgit_enable_log_filecount; 106 ret->enable_log_filecount = cgit_enable_log_filecount;
93 ret->enable_log_linecount = cgit_enable_log_linecount; 107 ret->enable_log_linecount = cgit_enable_log_linecount;
94 ret->module_link = cgit_module_link; 108 ret->module_link = cgit_module_link;
95 return ret; 109 return ret;
96} 110}
97 111
112struct repoinfo *cgit_get_repoinfo(const char *url)
113{
114 int i;
115 struct repoinfo *repo;
116
117 for (i=0; i<cgit_repolist.count; i++) {
118 repo = &cgit_repolist.repos[i];
119 if (!strcmp(repo->url, url))
120 return repo;
121 }
122 return NULL;
123}
124
98void cgit_global_config_cb(const char *name, const char *value) 125void cgit_global_config_cb(const char *name, const char *value)
99{ 126{
100 if (!strcmp(name, "root-title")) 127 if (!strcmp(name, "root-title"))
101 cgit_root_title = xstrdup(value); 128 cgit_root_title = xstrdup(value);
102 else if (!strcmp(name, "css")) 129 else if (!strcmp(name, "css"))
103 cgit_css = xstrdup(value); 130 cgit_css = xstrdup(value);
104 else if (!strcmp(name, "logo")) 131 else if (!strcmp(name, "logo"))
105 cgit_logo = xstrdup(value); 132 cgit_logo = xstrdup(value);
133 else if (!strcmp(name, "index-header"))
134 cgit_index_header = xstrdup(value);
106 else if (!strcmp(name, "logo-link")) 135 else if (!strcmp(name, "logo-link"))
107 cgit_logo_link = xstrdup(value); 136 cgit_logo_link = xstrdup(value);
108 else if (!strcmp(name, "module-link")) 137 else if (!strcmp(name, "module-link"))
109 cgit_module_link = xstrdup(value); 138 cgit_module_link = xstrdup(value);
110 else if (!strcmp(name, "virtual-root")) 139 else if (!strcmp(name, "virtual-root"))
111 cgit_virtual_root = xstrdup(value); 140 cgit_virtual_root = xstrdup(value);
@@ -160,14 +189,18 @@ void cgit_global_config_cb(const char *name, const char *value)
160} 189}
161 190
162void cgit_querystring_cb(const char *name, const char *value) 191void cgit_querystring_cb(const char *name, const char *value)
163{ 192{
164 if (!strcmp(name,"r")) { 193 if (!strcmp(name,"r")) {
165 cgit_query_repo = xstrdup(value); 194 cgit_query_repo = xstrdup(value);
195 cgit_repo = cgit_get_repoinfo(value);
166 } else if (!strcmp(name, "p")) { 196 } else if (!strcmp(name, "p")) {
167 cgit_query_page = xstrdup(value); 197 cgit_query_page = xstrdup(value);
198 cgit_cmd = cgit_get_cmd_index(value);
199 } else if (!strcmp(name, "url")) {
200 cgit_parse_url(value);
168 } else if (!strcmp(name, "q")) { 201 } else if (!strcmp(name, "q")) {
169 cgit_query_search = xstrdup(value); 202 cgit_query_search = xstrdup(value);
170 } else if (!strcmp(name, "h")) { 203 } else if (!strcmp(name, "h")) {
171 cgit_query_head = xstrdup(value); 204 cgit_query_head = xstrdup(value);
172 cgit_query_has_symref = 1; 205 cgit_query_has_symref = 1;
173 } else if (!strcmp(name, "id")) { 206 } else if (!strcmp(name, "id")) {