summaryrefslogtreecommitdiffabout
path: root/shared.c
Side-by-side diff
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 @@
*/
#include "cgit.h"
struct repolist cgit_repolist;
struct repoinfo *cgit_repo;
+int cgit_cmd;
char *cgit_root_title = "Git repository browser";
char *cgit_css = "/cgit.css";
char *cgit_logo = "/git-logo.png";
+char *cgit_index_header = NULL;
char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
char *cgit_virtual_root = NULL;
char *cgit_script_name = CGIT_SCRIPT_NAME;
char *cgit_cache_root = "/var/cache/cgit";
char *cgit_repo_group = NULL;
@@ -49,12 +51,24 @@ char *cgit_query_sha2 = NULL;
char *cgit_query_path = NULL;
char *cgit_query_name = NULL;
int cgit_query_ofs = 0;
int htmlfd = 0;
+
+int cgit_get_cmd_index(const char *cmd)
+{
+ static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL};
+ int i;
+
+ for(i = 0; cmds[i]; i++)
+ if (!strcmp(cmd, cmds[i]))
+ return i + 1;
+ return 0;
+}
+
int chk_zero(int result, char *msg)
{
if (result != 0)
die("%s: %s", msg, strerror(errno));
return result;
}
@@ -92,20 +106,35 @@ struct repoinfo *add_repo(const char *url)
ret->enable_log_filecount = cgit_enable_log_filecount;
ret->enable_log_linecount = cgit_enable_log_linecount;
ret->module_link = cgit_module_link;
return ret;
}
+struct repoinfo *cgit_get_repoinfo(const char *url)
+{
+ int i;
+ struct repoinfo *repo;
+
+ for (i=0; i<cgit_repolist.count; i++) {
+ repo = &cgit_repolist.repos[i];
+ if (!strcmp(repo->url, url))
+ return repo;
+ }
+ return NULL;
+}
+
void cgit_global_config_cb(const char *name, const char *value)
{
if (!strcmp(name, "root-title"))
cgit_root_title = xstrdup(value);
else if (!strcmp(name, "css"))
cgit_css = xstrdup(value);
else if (!strcmp(name, "logo"))
cgit_logo = xstrdup(value);
+ else if (!strcmp(name, "index-header"))
+ cgit_index_header = xstrdup(value);
else if (!strcmp(name, "logo-link"))
cgit_logo_link = xstrdup(value);
else if (!strcmp(name, "module-link"))
cgit_module_link = xstrdup(value);
else if (!strcmp(name, "virtual-root"))
cgit_virtual_root = xstrdup(value);
@@ -160,14 +189,18 @@ void cgit_global_config_cb(const char *name, const char *value)
}
void cgit_querystring_cb(const char *name, const char *value)
{
if (!strcmp(name,"r")) {
cgit_query_repo = xstrdup(value);
+ cgit_repo = cgit_get_repoinfo(value);
} else if (!strcmp(name, "p")) {
cgit_query_page = xstrdup(value);
+ cgit_cmd = cgit_get_cmd_index(value);
+ } else if (!strcmp(name, "url")) {
+ cgit_parse_url(value);
} else if (!strcmp(name, "q")) {
cgit_query_search = xstrdup(value);
} else if (!strcmp(name, "h")) {
cgit_query_head = xstrdup(value);
cgit_query_has_symref = 1;
} else if (!strcmp(name, "id")) {