From: Lars Hjemli Date: Sun, 20 May 2007 20:09:55 +0000 (+0200) Subject: Merge branch 'virtual-url' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/dc3ac3f76077c5d612d42e8beb4878e43acfc58a?hp=-c 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 --- dc3ac3f76077c5d612d42e8beb4878e43acfc58a diff --combined cgit.h index 3ee11bb,e5b3f5e..e0879bd --- a/cgit.h +++ b/cgit.h @@@ -18,6 -18,17 +18,17 @@@ #include + /* + * The valid cgit repo-commands + */ + #define CMD_LOG 1 + #define CMD_COMMIT 2 + #define CMD_DIFF 3 + #define CMD_TREE 4 + #define CMD_VIEW 5 + #define CMD_BLOB 6 + #define CMD_SNAPSHOT 7 + typedef void (*configfn)(const char *name, const char *value); typedef void (*filepair_fn)(struct diff_filepair *pair); typedef void (*linediff_fn)(char *line, int len); @@@ -71,11 -82,11 +82,12 @@@ extern const char cgit_version[] extern struct repolist cgit_repolist; extern struct repoinfo *cgit_repo; + extern int cgit_cmd; extern char *cgit_root_title; extern char *cgit_css; extern char *cgit_logo; +extern char *cgit_index_header; extern char *cgit_logo_link; extern char *cgit_module_link; extern char *cgit_virtual_root; @@@ -113,6 -124,8 +125,8 @@@ extern int cgit_query_ofs extern int htmlfd; + extern int cgit_get_cmd_index(const char *cmd); + extern struct repoinfo *cgit_get_repoinfo(const char *url); extern void cgit_global_config_cb(const char *name, const char *value); extern void cgit_repo_config_cb(const char *name, const char *value); extern void cgit_querystring_cb(const char *name, const char *value); @@@ -145,12 -158,12 +159,13 @@@ extern void html_hidden(char *name, cha extern void html_link_open(char *url, char *title, char *class); extern void html_link_close(void); extern void html_filemode(unsigned short mode); +extern int html_include(const char *filename); extern int cgit_read_config(const char *filename, configfn fn); extern int cgit_parse_query(char *txt, configfn fn); extern struct commitinfo *cgit_parse_commit(struct commit *commit); extern struct taginfo *cgit_parse_tag(struct tag *tag); + extern void cgit_parse_url(const char *url); extern char *cache_safe_filename(const char *unsafe); extern int cache_lock(struct cacheitem *item); diff --combined shared.c index 54b1813,0b074da..45fde7f --- a/shared.c +++ b/shared.c @@@ -10,11 -10,11 +10,12 @@@ 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; @@@ -52,6 -52,18 +53,18 @@@ 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) @@@ -94,6 -106,19 +107,19 @@@ struct repoinfo *add_repo(const char *u return ret; } + struct repoinfo *cgit_get_repoinfo(const char *url) + { + int i; + struct repoinfo *repo; + + for (i=0; iurl, url)) + return repo; + } + return NULL; + } + void cgit_global_config_cb(const char *name, const char *value) { if (!strcmp(name, "root-title")) @@@ -102,8 -127,6 +128,8 @@@ 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")) @@@ -162,8 -185,12 +188,12 @@@ void cgit_querystring_cb(const char *na { 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")) {