-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-shared.c | 17 | ||||
-rw-r--r-- | ui-snapshot.c | 2 |
3 files changed, 16 insertions, 5 deletions
@@ -180,48 +180,50 @@ extern void html(const char *txt); | |||
180 | extern void htmlf(const char *format,...); | 180 | extern void htmlf(const char *format,...); |
181 | extern void html_txt(char *txt); | 181 | extern void html_txt(char *txt); |
182 | extern void html_ntxt(int len, char *txt); | 182 | extern void html_ntxt(int len, char *txt); |
183 | extern void html_attr(char *txt); | 183 | extern void html_attr(char *txt); |
184 | extern void html_hidden(char *name, char *value); | 184 | extern void html_hidden(char *name, char *value); |
185 | extern void html_link_open(char *url, char *title, char *class); | 185 | extern void html_link_open(char *url, char *title, char *class); |
186 | extern void html_link_close(void); | 186 | extern void html_link_close(void); |
187 | extern void html_filemode(unsigned short mode); | 187 | extern void html_filemode(unsigned short mode); |
188 | extern int html_include(const char *filename); | 188 | extern int html_include(const char *filename); |
189 | 189 | ||
190 | extern int cgit_read_config(const char *filename, configfn fn); | 190 | extern int cgit_read_config(const char *filename, configfn fn); |
191 | extern int cgit_parse_query(char *txt, configfn fn); | 191 | extern int cgit_parse_query(char *txt, configfn fn); |
192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 192 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 193 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
194 | extern void cgit_parse_url(const char *url); | 194 | extern void cgit_parse_url(const char *url); |
195 | 195 | ||
196 | extern char *cache_safe_filename(const char *unsafe); | 196 | extern char *cache_safe_filename(const char *unsafe); |
197 | extern int cache_lock(struct cacheitem *item); | 197 | extern int cache_lock(struct cacheitem *item); |
198 | extern int cache_unlock(struct cacheitem *item); | 198 | extern int cache_unlock(struct cacheitem *item); |
199 | extern int cache_cancel_lock(struct cacheitem *item); | 199 | extern int cache_cancel_lock(struct cacheitem *item); |
200 | extern int cache_exist(struct cacheitem *item); | 200 | extern int cache_exist(struct cacheitem *item); |
201 | extern int cache_expired(struct cacheitem *item); | 201 | extern int cache_expired(struct cacheitem *item); |
202 | 202 | ||
203 | extern char *cgit_repourl(const char *reponame); | 203 | extern char *cgit_repourl(const char *reponame); |
204 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | ||
205 | const char *filename, const char *query); | ||
204 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 206 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
205 | const char *query); | 207 | const char *query); |
206 | 208 | ||
207 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 209 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
208 | char *rev, char *path); | 210 | char *rev, char *path); |
209 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 211 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
210 | char *rev, char *path, int ofs); | 212 | char *rev, char *path, int ofs); |
211 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 213 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
212 | char *rev); | 214 | char *rev); |
213 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 215 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
214 | char *new_rev, char *old_rev, char *path); | 216 | char *new_rev, char *old_rev, char *path); |
215 | 217 | ||
216 | extern void cgit_print_error(char *msg); | 218 | extern void cgit_print_error(char *msg); |
217 | extern void cgit_print_date(time_t secs, char *format); | 219 | extern void cgit_print_date(time_t secs, char *format); |
218 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 220 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
219 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 221 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
220 | extern void cgit_print_docend(); | 222 | extern void cgit_print_docend(); |
221 | extern void cgit_print_pageheader(char *title, int show_search); | 223 | extern void cgit_print_pageheader(char *title, int show_search); |
222 | extern void cgit_print_snapshot_start(const char *mimetype, | 224 | extern void cgit_print_snapshot_start(const char *mimetype, |
223 | const char *filename, | 225 | const char *filename, |
224 | struct cacheitem *item); | 226 | struct cacheitem *item); |
225 | 227 | ||
226 | extern void cgit_print_repolist(struct cacheitem *item); | 228 | extern void cgit_print_repolist(struct cacheitem *item); |
227 | extern void cgit_print_summary(); | 229 | extern void cgit_print_summary(); |
diff --git a/ui-shared.c b/ui-shared.c index d4376ce..1c1415e 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -36,66 +36,73 @@ static long ttl_seconds(long ttl) | |||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_fileurl(const char *reponame, const char *pagename, |
61 | const char *query) | 61 | const char *filename, const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, |
66 | pagename, query); | 66 | pagename, filename?filename:"", query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_pageurl(const char *reponame, const char *pagename, | ||
79 | const char *query) | ||
80 | { | ||
81 | return cgit_fileurl(reponame,pagename,0,query); | ||
82 | } | ||
83 | |||
84 | |||
78 | char *cgit_currurl() | 85 | char *cgit_currurl() |
79 | { | 86 | { |
80 | if (!cgit_virtual_root) | 87 | if (!cgit_virtual_root) |
81 | return cgit_script_name; | 88 | return cgit_script_name; |
82 | else if (cgit_query_page) | 89 | else if (cgit_query_page) |
83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 90 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
84 | else if (cgit_query_repo) | 91 | else if (cgit_query_repo) |
85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 92 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
86 | else | 93 | else |
87 | return fmt("%s/", cgit_virtual_root); | 94 | return fmt("%s/", cgit_virtual_root); |
88 | } | 95 | } |
89 | 96 | ||
90 | static char *repolink(char *title, char *class, char *page, char *head, | 97 | static char *repolink(char *title, char *class, char *page, char *head, |
91 | char *path) | 98 | char *path) |
92 | { | 99 | { |
93 | char *delim = "?"; | 100 | char *delim = "?"; |
94 | 101 | ||
95 | html("<a"); | 102 | html("<a"); |
96 | if (title) { | 103 | if (title) { |
97 | html(" title='"); | 104 | html(" title='"); |
98 | html_attr(title); | 105 | html_attr(title); |
99 | html("'"); | 106 | html("'"); |
100 | } | 107 | } |
101 | if (class) { | 108 | if (class) { |
@@ -347,24 +354,26 @@ void cgit_print_pageheader(char *title, int show_search) | |||
347 | if (cgit_query_head) | 354 | if (cgit_query_head) |
348 | html_hidden("h", cgit_query_head); | 355 | html_hidden("h", cgit_query_head); |
349 | if (cgit_query_sha1) | 356 | if (cgit_query_sha1) |
350 | html_hidden("id", cgit_query_sha1); | 357 | html_hidden("id", cgit_query_sha1); |
351 | if (cgit_query_sha2) | 358 | if (cgit_query_sha2) |
352 | html_hidden("id2", cgit_query_sha2); | 359 | html_hidden("id2", cgit_query_sha2); |
353 | html("<input type='text' name='q' value='"); | 360 | html("<input type='text' name='q' value='"); |
354 | html_attr(cgit_query_search); | 361 | html_attr(cgit_query_search); |
355 | html("'/></form>"); | 362 | html("'/></form>"); |
356 | } | 363 | } |
357 | html("</td></tr>"); | 364 | html("</td></tr>"); |
358 | html("<tr><td id='content' colspan='2'>"); | 365 | html("<tr><td id='content' colspan='2'>"); |
359 | } | 366 | } |
360 | 367 | ||
361 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 368 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
362 | struct cacheitem *item) | 369 | struct cacheitem *item) |
363 | { | 370 | { |
364 | htmlf("Content-Type: %s\n", mimetype); | 371 | htmlf("Content-Type: %s\n", mimetype); |
365 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 372 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
366 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 373 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
367 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 374 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
368 | ttl_seconds(item->ttl))); | 375 | ttl_seconds(item->ttl))); |
369 | html("\n"); | 376 | html("\n"); |
370 | } | 377 | } |
378 | |||
379 | /* vim:set sw=8: */ | ||
diff --git a/ui-snapshot.c b/ui-snapshot.c index 84bf8f7..7076b50 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -88,29 +88,29 @@ void cgit_print_snapshot(struct cacheitem *item, const char *hex, | |||
88 | if(!commit) { | 88 | if(!commit) { |
89 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 89 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
90 | return;; | 90 | return;; |
91 | } | 91 | } |
92 | 92 | ||
93 | memset(&args,0,sizeof(args)); | 93 | memset(&args,0,sizeof(args)); |
94 | args.base = fmt("%s/", prefix); | 94 | args.base = fmt("%s/", prefix); |
95 | args.tree = commit->tree; | 95 | args.tree = commit->tree; |
96 | 96 | ||
97 | cgit_print_snapshot_start(sat->mimetype, filename, item); | 97 | cgit_print_snapshot_start(sat->mimetype, filename, item); |
98 | (*sat->write_func)(&args); | 98 | (*sat->write_func)(&args); |
99 | return; | 99 | return; |
100 | } | 100 | } |
101 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 101 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
102 | } | 102 | } |
103 | 103 | ||
104 | void cgit_print_snapshot_links(const char *repo,const char *hex) | 104 | void cgit_print_snapshot_links(const char *repo,const char *hex) |
105 | { | 105 | { |
106 | char *filename; | 106 | char *filename; |
107 | int f; | 107 | int f; |
108 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 108 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { |
109 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 109 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; |
110 | filename = fmt("%s-%s%s",repo,hex,sat->suffix); | 110 | filename = fmt("%s-%s%s",repo,hex,sat->suffix); |
111 | htmlf("<a href='%s'>%s</a><br/>", | 111 | htmlf("<a href='%s'>%s</a><br/>", |
112 | cgit_pageurl(repo,"snapshot", | 112 | cgit_fileurl(repo,"snapshot",filename, |
113 | fmt("id=%s&name=%s",hex,filename)), filename); | 113 | fmt("id=%s&name=%s",hex,filename)), filename); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | /* vim:set sw=8: */ | 116 | /* vim:set sw=8: */ |