summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorMichael Krelin <hacker@klever.net>2007-07-21 11:13:40 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-21 11:13:40 (UTC)
commit0df096f6e146187e55e2203ea1c017442cc2c8c6 (patch) (unidiff)
treec3daea456db5424bbddee326c1479a2b759d551a /ui-shared.c
parent86ca02231fc42a629c50abebcae3ea9d4d692979 (diff)
downloadcgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.zip
cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.tar.gz
cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.tar.bz2
added snapshot filename to the link
- changed cgit_pageurl into cgit_fileurl with the filename parameter - rewritten cgit_pageurl as a wrapper around cgit_fileurl Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/ui-shared.c b/ui-shared.c
index d4376ce..1c1415e 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -12,114 +12,121 @@ const char cgit_doctype[] =
12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
14 14
15static char *http_date(time_t t) 15static char *http_date(time_t t)
16{ 16{
17 static char day[][4] = 17 static char day[][4] =
18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
19 static char month[][4] = 19 static char month[][4] =
20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
22 struct tm *tm = gmtime(&t); 22 struct tm *tm = gmtime(&t);
23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
25 tm->tm_hour, tm->tm_min, tm->tm_sec); 25 tm->tm_hour, tm->tm_min, tm->tm_sec);
26} 26}
27 27
28static long ttl_seconds(long ttl) 28static long ttl_seconds(long ttl)
29{ 29{
30 if (ttl<0) 30 if (ttl<0)
31 return 60 * 60 * 24 * 365; 31 return 60 * 60 * 24 * 365;
32 else 32 else
33 return ttl * 60; 33 return ttl * 60;
34} 34}
35 35
36void cgit_print_error(char *msg) 36void 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
43char *cgit_rooturl() 43char *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
51char *cgit_repourl(const char *reponame) 51char *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
60char *cgit_pageurl(const char *reponame, const char *pagename, 60char *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&amp;p=%s&amp;%s", reponame, pagename, query); 72 return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query);
73 else 73 else
74 return fmt("?r=%s&amp;p=%s", reponame, pagename); 74 return fmt("?r=%s&amp;p=%s", reponame, pagename);
75 } 75 }
76} 76}
77 77
78char *cgit_pageurl(const char *reponame, const char *pagename,
79 const char *query)
80{
81 return cgit_fileurl(reponame,pagename,0,query);
82}
83
84
78char *cgit_currurl() 85char *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
90static char *repolink(char *title, char *class, char *page, char *head, 97static 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) {
102 html(" class='"); 109 html(" class='");
103 html_attr(class); 110 html_attr(class);
104 html("'"); 111 html("'");
105 } 112 }
106 html(" href='"); 113 html(" href='");
107 if (cgit_virtual_root) { 114 if (cgit_virtual_root) {
108 html_attr(cgit_virtual_root); 115 html_attr(cgit_virtual_root);
109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') 116 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
110 html("/"); 117 html("/");
111 html_attr(cgit_repo->url); 118 html_attr(cgit_repo->url);
112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 119 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
113 html("/"); 120 html("/");
114 if (page) { 121 if (page) {
115 html(page); 122 html(page);
116 html("/"); 123 html("/");
117 if (path) 124 if (path)
118 html_attr(path); 125 html_attr(path);
119 } 126 }
120 } else { 127 } else {
121 html(cgit_script_name); 128 html(cgit_script_name);
122 html("?url="); 129 html("?url=");
123 html_attr(cgit_repo->url); 130 html_attr(cgit_repo->url);
124 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 131 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
125 html("/"); 132 html("/");
@@ -323,48 +330,50 @@ void cgit_print_pageheader(char *title, int show_search)
323 cgit_tree_link("tree", NULL, NULL, cgit_query_head, 330 cgit_tree_link("tree", NULL, NULL, cgit_query_head,
324 cgit_query_sha1, NULL); 331 cgit_query_sha1, NULL);
325 html(" "); 332 html(" ");
326 cgit_commit_link("commit", NULL, NULL, cgit_query_head, 333 cgit_commit_link("commit", NULL, NULL, cgit_query_head,
327 cgit_query_sha1); 334 cgit_query_sha1);
328 html(" "); 335 html(" ");
329 cgit_diff_link("diff", NULL, NULL, cgit_query_head, 336 cgit_diff_link("diff", NULL, NULL, cgit_query_head,
330 cgit_query_sha1, cgit_query_sha2, 337 cgit_query_sha1, cgit_query_sha2,
331 cgit_query_path); 338 cgit_query_path);
332 } else { 339 } else {
333 html_txt("Index of repositories"); 340 html_txt("Index of repositories");
334 } 341 }
335 html("</td>"); 342 html("</td>");
336 html("<td id='search'>"); 343 html("<td id='search'>");
337 if (show_search) { 344 if (show_search) {
338 html("<form method='get' action='"); 345 html("<form method='get' action='");
339 html_attr(cgit_currurl()); 346 html_attr(cgit_currurl());
340 html("'>"); 347 html("'>");
341 if (!cgit_virtual_root) { 348 if (!cgit_virtual_root) {
342 if (cgit_query_repo) 349 if (cgit_query_repo)
343 html_hidden("r", cgit_query_repo); 350 html_hidden("r", cgit_query_repo);
344 if (cgit_query_page) 351 if (cgit_query_page)
345 html_hidden("p", cgit_query_page); 352 html_hidden("p", cgit_query_page);
346 } 353 }
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
361void cgit_print_snapshot_start(const char *mimetype, const char *filename, 368void 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: */