about summary refs log tree commit diff stats
path: root/shared.c
diff options
context:
space:
mode:
authorLars Hjemli2007-05-20 22:09:55 +0200
committerLars Hjemli2007-05-20 22:09:55 +0200
commitdc3ac3f76077c5d612d42e8beb4878e43acfc58a (patch)
treedfb996c0ce9833841578e1f0accbb5a387c01237 /shared.c
parentMerge branch 'index-header' (diff)
parentDon't be fooled by trailing '/' in url-parameter (diff)
downloadcgit-dc3ac3f76077c5d612d42e8beb4878e43acfc58a.tar.gz
cgit-dc3ac3f76077c5d612d42e8beb4878e43acfc58a.zip
Merge branch 'virtual-url'
* virtual-url:
  Don't be fooled by trailing '/' in url-parameter
  cache_safe_filename() needs more buffers
  Enable url=value querystring parameter
  Add lookup-function for valid repo commands
  Move cgit_get_repoinfo into shared.c
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/shared.c b/shared.c index 54b1813..45fde7f 100644 --- a/shared.c +++ b/shared.c
@@ -10,6 +10,7 @@
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";
@@ -52,6 +53,18 @@ int cgit_query_ofs = 0;
52 53
53int htmlfd = 0; 54int htmlfd = 0;
54 55
56
57int cgit_get_cmd_index(const char *cmd)
58{
59 static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL};
60 int i;
61
62 for(i = 0; cmds[i]; i++)
63 if (!strcmp(cmd, cmds[i]))
64 return i + 1;
65 return 0;
66}
67
55int chk_zero(int result, char *msg) 68int chk_zero(int result, char *msg)
56{ 69{
57 if (result != 0) 70 if (result != 0)
@@ -94,6 +107,19 @@ struct repoinfo *add_repo(const char *url)
94 return ret; 107 return ret;
95} 108}
96 109
110struct repoinfo *cgit_get_repoinfo(const char *url)
111{
112 int i;
113 struct repoinfo *repo;
114
115 for (i=0; i<cgit_repolist.count; i++) {
116 repo = &cgit_repolist.repos[i];
117 if (!strcmp(repo->url, url))
118 return repo;
119 }
120 return NULL;
121}
122
97void cgit_global_config_cb(const char *name, const char *value) 123void cgit_global_config_cb(const char *name, const char *value)
98{ 124{
99 if (!strcmp(name, "root-title")) 125 if (!strcmp(name, "root-title"))
@@ -162,8 +188,12 @@ void cgit_querystring_cb(const char *name, const char *value)
162{ 188{
163 if (!strcmp(name,"r")) { 189 if (!strcmp(name,"r")) {
164 cgit_query_repo = xstrdup(value); 190 cgit_query_repo = xstrdup(value);
191 cgit_repo = cgit_get_repoinfo(value);
165 } else if (!strcmp(name, "p")) { 192 } else if (!strcmp(name, "p")) {
166 cgit_query_page = xstrdup(value); 193 cgit_query_page = xstrdup(value);
194 cgit_cmd = cgit_get_cmd_index(value);
195 } else if (!strcmp(name, "url")) {
196 cgit_parse_url(value);
167 } else if (!strcmp(name, "q")) { 197 } else if (!strcmp(name, "q")) {
168 cgit_query_search = xstrdup(value); 198 cgit_query_search = xstrdup(value);
169 } else if (!strcmp(name, "h")) { 199 } else if (!strcmp(name, "h")) {