]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'virtual-url'
authorLars Hjemli <hjemli@gmail.com>
Sun, 20 May 2007 20:09:55 +0000 (22:09 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sun, 20 May 2007 20:09:55 +0000 (22:09 +0200)
* 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

1  2 
cgit.h
shared.c

diff --combined cgit.h
index 3ee11bb3985607afcb28df6df653c6cdb318e5d3,e5b3f5e8719a3f5be5c14f08580064c7bc110360..e0879bd26d0eda774d045586e1f1e6b16a0e3aaf
--- 1/cgit.h
--- 2/cgit.h
+++ b/cgit.h
  #include <xdiff/xdiff.h>
  
  
+ /*
+  * 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 54b1813a882806c67b5afe9422fdae51737cd665,0b074da779d652b9983b9d487793540482ac9ae7..45fde7fe3bc23fd8d7e9bbf6861f70395330df25
+++ b/shared.c
  
  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; 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_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")) {