summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c14
-rw-r--r--cgit.h1
-rw-r--r--shared.c13
3 files changed, 14 insertions, 14 deletions
diff --git a/cgit.c b/cgit.c
index 3e7e595..431e8fb 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,75 +1,61 @@
1/* cgit.c: cgi for the git scm 1/* cgit.c: cgi for the git scm
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11const char cgit_version[] = CGIT_VERSION; 11const char cgit_version[] = CGIT_VERSION;
12 12
13 13
14static struct repoinfo *cgit_get_repoinfo(char *url)
15{
16 int i;
17 struct repoinfo *repo;
18
19 for (i=0; i<cgit_repolist.count; i++) {
20 repo = &cgit_repolist.repos[i];
21 if (!strcmp(repo->url, url))
22 return repo;
23 }
24 return NULL;
25}
26
27
28static int cgit_prepare_cache(struct cacheitem *item) 14static int cgit_prepare_cache(struct cacheitem *item)
29{ 15{
30 if (!cgit_query_repo) { 16 if (!cgit_query_repo) {
31 item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); 17 item->name = xstrdup(fmt("%s/index.html", cgit_cache_root));
32 item->ttl = cgit_cache_root_ttl; 18 item->ttl = cgit_cache_root_ttl;
33 return 1; 19 return 1;
34 } 20 }
35 cgit_repo = cgit_get_repoinfo(cgit_query_repo); 21 cgit_repo = cgit_get_repoinfo(cgit_query_repo);
36 if (!cgit_repo) { 22 if (!cgit_repo) {
37 char *title = fmt("%s - %s", cgit_root_title, "Bad request"); 23 char *title = fmt("%s - %s", cgit_root_title, "Bad request");
38 cgit_print_docstart(title, item); 24 cgit_print_docstart(title, item);
39 cgit_print_pageheader(title, 0); 25 cgit_print_pageheader(title, 0);
40 cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); 26 cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo));
41 cgit_print_docend(); 27 cgit_print_docend();
42 return 0; 28 return 0;
43 } 29 }
44 30
45 if (!cgit_query_page) { 31 if (!cgit_query_page) {
46 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, 32 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root,
47 cgit_repo->url)); 33 cgit_repo->url));
48 item->ttl = cgit_cache_repo_ttl; 34 item->ttl = cgit_cache_repo_ttl;
49 } else { 35 } else {
50 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, 36 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root,
51 cgit_repo->url, cgit_query_page, 37 cgit_repo->url, cgit_query_page,
52 cache_safe_filename(cgit_querystring))); 38 cache_safe_filename(cgit_querystring)));
53 if (cgit_query_has_symref) 39 if (cgit_query_has_symref)
54 item->ttl = cgit_cache_dynamic_ttl; 40 item->ttl = cgit_cache_dynamic_ttl;
55 else if (cgit_query_has_sha1) 41 else if (cgit_query_has_sha1)
56 item->ttl = cgit_cache_static_ttl; 42 item->ttl = cgit_cache_static_ttl;
57 else 43 else
58 item->ttl = cgit_cache_repo_ttl; 44 item->ttl = cgit_cache_repo_ttl;
59 } 45 }
60 return 1; 46 return 1;
61} 47}
62 48
63static void cgit_print_repo_page(struct cacheitem *item) 49static void cgit_print_repo_page(struct cacheitem *item)
64{ 50{
65 char *title; 51 char *title;
66 int show_search; 52 int show_search;
67 53
68 if (!cgit_query_head) 54 if (!cgit_query_head)
69 cgit_query_head = cgit_repo->defbranch; 55 cgit_query_head = cgit_repo->defbranch;
70 56
71 if (chdir(cgit_repo->path)) { 57 if (chdir(cgit_repo->path)) {
72 title = fmt("%s - %s", cgit_root_title, "Bad request"); 58 title = fmt("%s - %s", cgit_root_title, "Bad request");
73 cgit_print_docstart(title, item); 59 cgit_print_docstart(title, item);
74 cgit_print_pageheader(title, 0); 60 cgit_print_pageheader(title, 0);
75 cgit_print_error(fmt("Unable to scan repository: %s", 61 cgit_print_error(fmt("Unable to scan repository: %s",
diff --git a/cgit.h b/cgit.h
index f3d783e..a38981d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -67,96 +67,97 @@ struct taginfo {
67 char *msg; 67 char *msg;
68}; 68};
69 69
70extern const char cgit_version[]; 70extern const char cgit_version[];
71 71
72extern struct repolist cgit_repolist; 72extern struct repolist cgit_repolist;
73extern struct repoinfo *cgit_repo; 73extern struct repoinfo *cgit_repo;
74 74
75extern char *cgit_root_title; 75extern char *cgit_root_title;
76extern char *cgit_css; 76extern char *cgit_css;
77extern char *cgit_logo; 77extern char *cgit_logo;
78extern char *cgit_logo_link; 78extern char *cgit_logo_link;
79extern char *cgit_module_link; 79extern char *cgit_module_link;
80extern char *cgit_virtual_root; 80extern char *cgit_virtual_root;
81extern char *cgit_script_name; 81extern char *cgit_script_name;
82extern char *cgit_cache_root; 82extern char *cgit_cache_root;
83 83
84extern int cgit_nocache; 84extern int cgit_nocache;
85extern int cgit_snapshots; 85extern int cgit_snapshots;
86extern int cgit_enable_log_filecount; 86extern int cgit_enable_log_filecount;
87extern int cgit_enable_log_linecount; 87extern int cgit_enable_log_linecount;
88extern int cgit_max_lock_attempts; 88extern int cgit_max_lock_attempts;
89extern int cgit_cache_root_ttl; 89extern int cgit_cache_root_ttl;
90extern int cgit_cache_repo_ttl; 90extern int cgit_cache_repo_ttl;
91extern int cgit_cache_dynamic_ttl; 91extern int cgit_cache_dynamic_ttl;
92extern int cgit_cache_static_ttl; 92extern int cgit_cache_static_ttl;
93extern int cgit_cache_max_create_time; 93extern int cgit_cache_max_create_time;
94 94
95extern int cgit_max_msg_len; 95extern int cgit_max_msg_len;
96extern int cgit_max_repodesc_len; 96extern int cgit_max_repodesc_len;
97extern int cgit_max_commit_count; 97extern int cgit_max_commit_count;
98 98
99extern int cgit_query_has_symref; 99extern int cgit_query_has_symref;
100extern int cgit_query_has_sha1; 100extern int cgit_query_has_sha1;
101 101
102extern char *cgit_querystring; 102extern char *cgit_querystring;
103extern char *cgit_query_repo; 103extern char *cgit_query_repo;
104extern char *cgit_query_page; 104extern char *cgit_query_page;
105extern char *cgit_query_search; 105extern char *cgit_query_search;
106extern char *cgit_query_head; 106extern char *cgit_query_head;
107extern char *cgit_query_sha1; 107extern char *cgit_query_sha1;
108extern char *cgit_query_sha2; 108extern char *cgit_query_sha2;
109extern char *cgit_query_path; 109extern char *cgit_query_path;
110extern char *cgit_query_name; 110extern char *cgit_query_name;
111extern int cgit_query_ofs; 111extern int cgit_query_ofs;
112 112
113extern int htmlfd; 113extern int htmlfd;
114 114
115extern struct repoinfo *cgit_get_repoinfo(const char *url);
115extern void cgit_global_config_cb(const char *name, const char *value); 116extern void cgit_global_config_cb(const char *name, const char *value);
116extern void cgit_repo_config_cb(const char *name, const char *value); 117extern void cgit_repo_config_cb(const char *name, const char *value);
117extern void cgit_querystring_cb(const char *name, const char *value); 118extern void cgit_querystring_cb(const char *name, const char *value);
118 119
119extern int chk_zero(int result, char *msg); 120extern int chk_zero(int result, char *msg);
120extern int chk_positive(int result, char *msg); 121extern int chk_positive(int result, char *msg);
121 122
122extern int hextoint(char c); 123extern int hextoint(char c);
123 124
124extern void *cgit_free_commitinfo(struct commitinfo *info); 125extern void *cgit_free_commitinfo(struct commitinfo *info);
125 126
126extern int cgit_diff_files(const unsigned char *old_sha1, 127extern int cgit_diff_files(const unsigned char *old_sha1,
127 const unsigned char *new_sha1, 128 const unsigned char *new_sha1,
128 linediff_fn fn); 129 linediff_fn fn);
129 130
130extern void cgit_diff_tree(const unsigned char *old_sha1, 131extern void cgit_diff_tree(const unsigned char *old_sha1,
131 const unsigned char *new_sha1, 132 const unsigned char *new_sha1,
132 filepair_fn fn); 133 filepair_fn fn);
133 134
134extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 135extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
135 136
136extern char *fmt(const char *format,...); 137extern char *fmt(const char *format,...);
137 138
138extern void html(const char *txt); 139extern void html(const char *txt);
139extern void htmlf(const char *format,...); 140extern void htmlf(const char *format,...);
140extern void html_txt(char *txt); 141extern void html_txt(char *txt);
141extern void html_ntxt(int len, char *txt); 142extern void html_ntxt(int len, char *txt);
142extern void html_attr(char *txt); 143extern void html_attr(char *txt);
143extern void html_hidden(char *name, char *value); 144extern void html_hidden(char *name, char *value);
144extern void html_link_open(char *url, char *title, char *class); 145extern void html_link_open(char *url, char *title, char *class);
145extern void html_link_close(void); 146extern void html_link_close(void);
146extern void html_filemode(unsigned short mode); 147extern void html_filemode(unsigned short mode);
147 148
148extern int cgit_read_config(const char *filename, configfn fn); 149extern int cgit_read_config(const char *filename, configfn fn);
149extern int cgit_parse_query(char *txt, configfn fn); 150extern int cgit_parse_query(char *txt, configfn fn);
150extern struct commitinfo *cgit_parse_commit(struct commit *commit); 151extern struct commitinfo *cgit_parse_commit(struct commit *commit);
151extern struct taginfo *cgit_parse_tag(struct tag *tag); 152extern struct taginfo *cgit_parse_tag(struct tag *tag);
152 153
153extern char *cache_safe_filename(const char *unsafe); 154extern char *cache_safe_filename(const char *unsafe);
154extern int cache_lock(struct cacheitem *item); 155extern int cache_lock(struct cacheitem *item);
155extern int cache_unlock(struct cacheitem *item); 156extern int cache_unlock(struct cacheitem *item);
156extern int cache_cancel_lock(struct cacheitem *item); 157extern int cache_cancel_lock(struct cacheitem *item);
157extern int cache_exist(struct cacheitem *item); 158extern int cache_exist(struct cacheitem *item);
158extern int cache_expired(struct cacheitem *item); 159extern int cache_expired(struct cacheitem *item);
159 160
160extern char *cgit_repourl(const char *reponame); 161extern char *cgit_repourl(const char *reponame);
161extern char *cgit_pageurl(const char *reponame, const char *pagename, 162extern char *cgit_pageurl(const char *reponame, const char *pagename,
162 const char *query); 163 const char *query);
diff --git a/shared.c b/shared.c
index 53cd9b0..b164d81 100644
--- a/shared.c
+++ b/shared.c
@@ -48,96 +48,109 @@ char *cgit_query_sha2 = NULL;
48char *cgit_query_path = NULL; 48char *cgit_query_path = NULL;
49char *cgit_query_name = NULL; 49char *cgit_query_name = NULL;
50int cgit_query_ofs = 0; 50int cgit_query_ofs = 0;
51 51
52int htmlfd = 0; 52int htmlfd = 0;
53 53
54int chk_zero(int result, char *msg) 54int chk_zero(int result, char *msg)
55{ 55{
56 if (result != 0) 56 if (result != 0)
57 die("%s: %s", msg, strerror(errno)); 57 die("%s: %s", msg, strerror(errno));
58 return result; 58 return result;
59} 59}
60 60
61int chk_positive(int result, char *msg) 61int chk_positive(int result, char *msg)
62{ 62{
63 if (result <= 0) 63 if (result <= 0)
64 die("%s: %s", msg, strerror(errno)); 64 die("%s: %s", msg, strerror(errno));
65 return result; 65 return result;
66} 66}
67 67
68struct repoinfo *add_repo(const char *url) 68struct repoinfo *add_repo(const char *url)
69{ 69{
70 struct repoinfo *ret; 70 struct repoinfo *ret;
71 71
72 if (++cgit_repolist.count > cgit_repolist.length) { 72 if (++cgit_repolist.count > cgit_repolist.length) {
73 if (cgit_repolist.length == 0) 73 if (cgit_repolist.length == 0)
74 cgit_repolist.length = 8; 74 cgit_repolist.length = 8;
75 else 75 else
76 cgit_repolist.length *= 2; 76 cgit_repolist.length *= 2;
77 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 77 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
78 cgit_repolist.length * 78 cgit_repolist.length *
79 sizeof(struct repoinfo)); 79 sizeof(struct repoinfo));
80 } 80 }
81 81
82 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 82 ret = &cgit_repolist.repos[cgit_repolist.count-1];
83 ret->url = xstrdup(url); 83 ret->url = xstrdup(url);
84 ret->name = ret->url; 84 ret->name = ret->url;
85 ret->path = NULL; 85 ret->path = NULL;
86 ret->desc = NULL; 86 ret->desc = NULL;
87 ret->owner = NULL; 87 ret->owner = NULL;
88 ret->defbranch = "master"; 88 ret->defbranch = "master";
89 ret->snapshots = cgit_snapshots; 89 ret->snapshots = cgit_snapshots;
90 ret->enable_log_filecount = cgit_enable_log_filecount; 90 ret->enable_log_filecount = cgit_enable_log_filecount;
91 ret->enable_log_linecount = cgit_enable_log_linecount; 91 ret->enable_log_linecount = cgit_enable_log_linecount;
92 ret->module_link = cgit_module_link; 92 ret->module_link = cgit_module_link;
93 return ret; 93 return ret;
94} 94}
95 95
96struct repoinfo *cgit_get_repoinfo(const char *url)
97{
98 int i;
99 struct repoinfo *repo;
100
101 for (i=0; i<cgit_repolist.count; i++) {
102 repo = &cgit_repolist.repos[i];
103 if (!strcmp(repo->url, url))
104 return repo;
105 }
106 return NULL;
107}
108
96void cgit_global_config_cb(const char *name, const char *value) 109void cgit_global_config_cb(const char *name, const char *value)
97{ 110{
98 if (!strcmp(name, "root-title")) 111 if (!strcmp(name, "root-title"))
99 cgit_root_title = xstrdup(value); 112 cgit_root_title = xstrdup(value);
100 else if (!strcmp(name, "css")) 113 else if (!strcmp(name, "css"))
101 cgit_css = xstrdup(value); 114 cgit_css = xstrdup(value);
102 else if (!strcmp(name, "logo")) 115 else if (!strcmp(name, "logo"))
103 cgit_logo = xstrdup(value); 116 cgit_logo = xstrdup(value);
104 else if (!strcmp(name, "logo-link")) 117 else if (!strcmp(name, "logo-link"))
105 cgit_logo_link = xstrdup(value); 118 cgit_logo_link = xstrdup(value);
106 else if (!strcmp(name, "module-link")) 119 else if (!strcmp(name, "module-link"))
107 cgit_module_link = xstrdup(value); 120 cgit_module_link = xstrdup(value);
108 else if (!strcmp(name, "virtual-root")) 121 else if (!strcmp(name, "virtual-root"))
109 cgit_virtual_root = xstrdup(value); 122 cgit_virtual_root = xstrdup(value);
110 else if (!strcmp(name, "nocache")) 123 else if (!strcmp(name, "nocache"))
111 cgit_nocache = atoi(value); 124 cgit_nocache = atoi(value);
112 else if (!strcmp(name, "snapshots")) 125 else if (!strcmp(name, "snapshots"))
113 cgit_snapshots = atoi(value); 126 cgit_snapshots = atoi(value);
114 else if (!strcmp(name, "enable-log-filecount")) 127 else if (!strcmp(name, "enable-log-filecount"))
115 cgit_enable_log_filecount = atoi(value); 128 cgit_enable_log_filecount = atoi(value);
116 else if (!strcmp(name, "enable-log-linecount")) 129 else if (!strcmp(name, "enable-log-linecount"))
117 cgit_enable_log_linecount = atoi(value); 130 cgit_enable_log_linecount = atoi(value);
118 else if (!strcmp(name, "cache-root")) 131 else if (!strcmp(name, "cache-root"))
119 cgit_cache_root = xstrdup(value); 132 cgit_cache_root = xstrdup(value);
120 else if (!strcmp(name, "cache-root-ttl")) 133 else if (!strcmp(name, "cache-root-ttl"))
121 cgit_cache_root_ttl = atoi(value); 134 cgit_cache_root_ttl = atoi(value);
122 else if (!strcmp(name, "cache-repo-ttl")) 135 else if (!strcmp(name, "cache-repo-ttl"))
123 cgit_cache_repo_ttl = atoi(value); 136 cgit_cache_repo_ttl = atoi(value);
124 else if (!strcmp(name, "cache-static-ttl")) 137 else if (!strcmp(name, "cache-static-ttl"))
125 cgit_cache_static_ttl = atoi(value); 138 cgit_cache_static_ttl = atoi(value);
126 else if (!strcmp(name, "cache-dynamic-ttl")) 139 else if (!strcmp(name, "cache-dynamic-ttl"))
127 cgit_cache_dynamic_ttl = atoi(value); 140 cgit_cache_dynamic_ttl = atoi(value);
128 else if (!strcmp(name, "max-message-length")) 141 else if (!strcmp(name, "max-message-length"))
129 cgit_max_msg_len = atoi(value); 142 cgit_max_msg_len = atoi(value);
130 else if (!strcmp(name, "max-repodesc-length")) 143 else if (!strcmp(name, "max-repodesc-length"))
131 cgit_max_repodesc_len = atoi(value); 144 cgit_max_repodesc_len = atoi(value);
132 else if (!strcmp(name, "max-commit-count")) 145 else if (!strcmp(name, "max-commit-count"))
133 cgit_max_commit_count = atoi(value); 146 cgit_max_commit_count = atoi(value);
134 else if (!strcmp(name, "repo.url")) 147 else if (!strcmp(name, "repo.url"))
135 cgit_repo = add_repo(value); 148 cgit_repo = add_repo(value);
136 else if (!strcmp(name, "repo.name")) 149 else if (!strcmp(name, "repo.name"))
137 cgit_repo->name = xstrdup(value); 150 cgit_repo->name = xstrdup(value);
138 else if (cgit_repo && !strcmp(name, "repo.path")) 151 else if (cgit_repo && !strcmp(name, "repo.path"))
139 cgit_repo->path = xstrdup(value); 152 cgit_repo->path = xstrdup(value);
140 else if (cgit_repo && !strcmp(name, "repo.desc")) 153 else if (cgit_repo && !strcmp(name, "repo.desc"))
141 cgit_repo->desc = xstrdup(value); 154 cgit_repo->desc = xstrdup(value);
142 else if (cgit_repo && !strcmp(name, "repo.owner")) 155 else if (cgit_repo && !strcmp(name, "repo.owner"))
143 cgit_repo->owner = xstrdup(value); 156 cgit_repo->owner = xstrdup(value);