summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2009-08-10 06:21:09 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-08-10 06:21:09 (UTC)
commit60a26272e0ca529407fe6b613f061f04ba585d53 (patch) (unidiff)
treec2b6ee3c19a44bd276043650298229c481ca4535 /ui-shared.c
parente6cd7121edf55c13f04cd5d6fca8f07c4035ce0a (diff)
downloadcgit-60a26272e0ca529407fe6b613f061f04ba585d53.zip
cgit-60a26272e0ca529407fe6b613f061f04ba585d53.tar.gz
cgit-60a26272e0ca529407fe6b613f061f04ba585d53.tar.bz2
Cleanup handling of environment variables
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 015c52b..538ddda 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,161 +1,149 @@
1/* ui-shared.c: common web output functions 1/* ui-shared.c: common web output functions
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#include "cmd.h" 10#include "cmd.h"
11#include "html.h" 11#include "html.h"
12 12
13const char cgit_doctype[] = 13const char cgit_doctype[] =
14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
16 16
17static char *http_date(time_t t) 17static char *http_date(time_t t)
18{ 18{
19 static char day[][4] = 19 static char day[][4] =
20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
21 static char month[][4] = 21 static char month[][4] =
22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
24 struct tm *tm = gmtime(&t); 24 struct tm *tm = gmtime(&t);
25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
27 tm->tm_hour, tm->tm_min, tm->tm_sec); 27 tm->tm_hour, tm->tm_min, tm->tm_sec);
28} 28}
29 29
30void cgit_print_error(char *msg) 30void cgit_print_error(char *msg)
31{ 31{
32 html("<div class='error'>"); 32 html("<div class='error'>");
33 html_txt(msg); 33 html_txt(msg);
34 html("</div>\n"); 34 html("</div>\n");
35} 35}
36 36
37char *cgit_httpscheme() 37char *cgit_httpscheme()
38{ 38{
39 char *https; 39 if (ctx.env.https && !strcmp(ctx.env.https, "on"))
40
41 https = getenv("HTTPS");
42 if (https != NULL && strcmp(https, "on") == 0)
43 return "https://"; 40 return "https://";
44 else 41 else
45 return "http://"; 42 return "http://";
46} 43}
47 44
48char *cgit_hosturl() 45char *cgit_hosturl()
49{ 46{
50 char *host, *port; 47 if (ctx.env.http_host)
51 48 return ctx.env.http_host;
52 host = getenv("HTTP_HOST"); 49 if (!ctx.env.server_name)
53 if (host) { 50 return NULL;
54 host = xstrdup(host); 51 if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
55 } else { 52 return ctx.env.server_name;
56 host = getenv("SERVER_NAME"); 53 return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port));
57 if (!host)
58 return NULL;
59 port = getenv("SERVER_PORT");
60 if (port && atoi(port) != 80)
61 host = xstrdup(fmt("%s:%d", host, atoi(port)));
62 else
63 host = xstrdup(host);
64 }
65 return host;
66} 54}
67 55
68char *cgit_rooturl() 56char *cgit_rooturl()
69{ 57{
70 if (ctx.cfg.virtual_root) 58 if (ctx.cfg.virtual_root)
71 return fmt("%s/", ctx.cfg.virtual_root); 59 return fmt("%s/", ctx.cfg.virtual_root);
72 else 60 else
73 return ctx.cfg.script_name; 61 return ctx.cfg.script_name;
74} 62}
75 63
76char *cgit_repourl(const char *reponame) 64char *cgit_repourl(const char *reponame)
77{ 65{
78 if (ctx.cfg.virtual_root) { 66 if (ctx.cfg.virtual_root) {
79 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); 67 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame);
80 } else { 68 } else {
81 return fmt("?r=%s", reponame); 69 return fmt("?r=%s", reponame);
82 } 70 }
83} 71}
84 72
85char *cgit_fileurl(const char *reponame, const char *pagename, 73char *cgit_fileurl(const char *reponame, const char *pagename,
86 const char *filename, const char *query) 74 const char *filename, const char *query)
87{ 75{
88 char *tmp; 76 char *tmp;
89 char *delim; 77 char *delim;
90 78
91 if (ctx.cfg.virtual_root) { 79 if (ctx.cfg.virtual_root) {
92 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, 80 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame,
93 pagename, (filename ? filename:"")); 81 pagename, (filename ? filename:""));
94 delim = "?"; 82 delim = "?";
95 } else { 83 } else {
96 tmp = fmt("?url=%s/%s/%s", reponame, pagename, 84 tmp = fmt("?url=%s/%s/%s", reponame, pagename,
97 (filename ? filename : "")); 85 (filename ? filename : ""));
98 delim = "&"; 86 delim = "&";
99 } 87 }
100 if (query) 88 if (query)
101 tmp = fmt("%s%s%s", tmp, delim, query); 89 tmp = fmt("%s%s%s", tmp, delim, query);
102 return tmp; 90 return tmp;
103} 91}
104 92
105char *cgit_pageurl(const char *reponame, const char *pagename, 93char *cgit_pageurl(const char *reponame, const char *pagename,
106 const char *query) 94 const char *query)
107{ 95{
108 return cgit_fileurl(reponame,pagename,0,query); 96 return cgit_fileurl(reponame,pagename,0,query);
109} 97}
110 98
111const char *cgit_repobasename(const char *reponame) 99const char *cgit_repobasename(const char *reponame)
112{ 100{
113 /* I assume we don't need to store more than one repo basename */ 101 /* I assume we don't need to store more than one repo basename */
114 static char rvbuf[1024]; 102 static char rvbuf[1024];
115 int p; 103 int p;
116 const char *rv; 104 const char *rv;
117 strncpy(rvbuf,reponame,sizeof(rvbuf)); 105 strncpy(rvbuf,reponame,sizeof(rvbuf));
118 if(rvbuf[sizeof(rvbuf)-1]) 106 if(rvbuf[sizeof(rvbuf)-1])
119 die("cgit_repobasename: truncated repository name '%s'", reponame); 107 die("cgit_repobasename: truncated repository name '%s'", reponame);
120 p = strlen(rvbuf)-1; 108 p = strlen(rvbuf)-1;
121 /* strip trailing slashes */ 109 /* strip trailing slashes */
122 while(p && rvbuf[p]=='/') rvbuf[p--]=0; 110 while(p && rvbuf[p]=='/') rvbuf[p--]=0;
123 /* strip trailing .git */ 111 /* strip trailing .git */
124 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { 112 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
125 p -= 3; rvbuf[p--] = 0; 113 p -= 3; rvbuf[p--] = 0;
126 } 114 }
127 /* strip more trailing slashes if any */ 115 /* strip more trailing slashes if any */
128 while( p && rvbuf[p]=='/') rvbuf[p--]=0; 116 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
129 /* find last slash in the remaining string */ 117 /* find last slash in the remaining string */
130 rv = strrchr(rvbuf,'/'); 118 rv = strrchr(rvbuf,'/');
131 if(rv) 119 if(rv)
132 return ++rv; 120 return ++rv;
133 return rvbuf; 121 return rvbuf;
134} 122}
135 123
136char *cgit_currurl() 124char *cgit_currurl()
137{ 125{
138 if (!ctx.cfg.virtual_root) 126 if (!ctx.cfg.virtual_root)
139 return ctx.cfg.script_name; 127 return ctx.cfg.script_name;
140 else if (ctx.qry.page) 128 else if (ctx.qry.page)
141 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); 129 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
142 else if (ctx.qry.repo) 130 else if (ctx.qry.repo)
143 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); 131 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
144 else 132 else
145 return fmt("%s/", ctx.cfg.virtual_root); 133 return fmt("%s/", ctx.cfg.virtual_root);
146} 134}
147 135
148static void site_url(char *page, char *search, int ofs) 136static void site_url(char *page, char *search, int ofs)
149{ 137{
150 char *delim = "?"; 138 char *delim = "?";
151 139
152 if (ctx.cfg.virtual_root) { 140 if (ctx.cfg.virtual_root) {
153 html_attr(ctx.cfg.virtual_root); 141 html_attr(ctx.cfg.virtual_root);
154 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') 142 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
155 html("/"); 143 html("/");
156 } else 144 } else
157 html(ctx.cfg.script_name); 145 html(ctx.cfg.script_name);
158 146
159 if (page) { 147 if (page) {
160 htmlf("?p=%s", page); 148 htmlf("?p=%s", page);
161 delim = "&"; 149 delim = "&";
@@ -374,215 +362,213 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
374 html("</a>"); 362 html("</a>");
375} 363}
376 364
377void cgit_patch_link(char *name, char *title, char *class, char *head, 365void cgit_patch_link(char *name, char *title, char *class, char *head,
378 char *rev) 366 char *rev)
379{ 367{
380 reporevlink("patch", name, title, class, head, rev, NULL); 368 reporevlink("patch", name, title, class, head, rev, NULL);
381} 369}
382 370
383void cgit_stats_link(char *name, char *title, char *class, char *head, 371void cgit_stats_link(char *name, char *title, char *class, char *head,
384 char *path) 372 char *path)
385{ 373{
386 reporevlink("stats", name, title, class, head, NULL, path); 374 reporevlink("stats", name, title, class, head, NULL, path);
387} 375}
388 376
389void cgit_object_link(struct object *obj) 377void cgit_object_link(struct object *obj)
390{ 378{
391 char *page, *shortrev, *fullrev, *name; 379 char *page, *shortrev, *fullrev, *name;
392 380
393 fullrev = sha1_to_hex(obj->sha1); 381 fullrev = sha1_to_hex(obj->sha1);
394 shortrev = xstrdup(fullrev); 382 shortrev = xstrdup(fullrev);
395 shortrev[10] = '\0'; 383 shortrev[10] = '\0';
396 if (obj->type == OBJ_COMMIT) { 384 if (obj->type == OBJ_COMMIT) {
397 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, 385 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
398 ctx.qry.head, fullrev); 386 ctx.qry.head, fullrev);
399 return; 387 return;
400 } else if (obj->type == OBJ_TREE) 388 } else if (obj->type == OBJ_TREE)
401 page = "tree"; 389 page = "tree";
402 else if (obj->type == OBJ_TAG) 390 else if (obj->type == OBJ_TAG)
403 page = "tag"; 391 page = "tag";
404 else 392 else
405 page = "blob"; 393 page = "blob";
406 name = fmt("%s %s...", typename(obj->type), shortrev); 394 name = fmt("%s %s...", typename(obj->type), shortrev);
407 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 395 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
408} 396}
409 397
410void cgit_print_date(time_t secs, char *format, int local_time) 398void cgit_print_date(time_t secs, char *format, int local_time)
411{ 399{
412 char buf[64]; 400 char buf[64];
413 struct tm *time; 401 struct tm *time;
414 402
415 if (!secs) 403 if (!secs)
416 return; 404 return;
417 if(local_time) 405 if(local_time)
418 time = localtime(&secs); 406 time = localtime(&secs);
419 else 407 else
420 time = gmtime(&secs); 408 time = gmtime(&secs);
421 strftime(buf, sizeof(buf)-1, format, time); 409 strftime(buf, sizeof(buf)-1, format, time);
422 html_txt(buf); 410 html_txt(buf);
423} 411}
424 412
425void cgit_print_age(time_t t, time_t max_relative, char *format) 413void cgit_print_age(time_t t, time_t max_relative, char *format)
426{ 414{
427 time_t now, secs; 415 time_t now, secs;
428 416
429 if (!t) 417 if (!t)
430 return; 418 return;
431 time(&now); 419 time(&now);
432 secs = now - t; 420 secs = now - t;
433 421
434 if (secs > max_relative && max_relative >= 0) { 422 if (secs > max_relative && max_relative >= 0) {
435 cgit_print_date(t, format, ctx.cfg.local_time); 423 cgit_print_date(t, format, ctx.cfg.local_time);
436 return; 424 return;
437 } 425 }
438 426
439 if (secs < TM_HOUR * 2) { 427 if (secs < TM_HOUR * 2) {
440 htmlf("<span class='age-mins'>%.0f min.</span>", 428 htmlf("<span class='age-mins'>%.0f min.</span>",
441 secs * 1.0 / TM_MIN); 429 secs * 1.0 / TM_MIN);
442 return; 430 return;
443 } 431 }
444 if (secs < TM_DAY * 2) { 432 if (secs < TM_DAY * 2) {
445 htmlf("<span class='age-hours'>%.0f hours</span>", 433 htmlf("<span class='age-hours'>%.0f hours</span>",
446 secs * 1.0 / TM_HOUR); 434 secs * 1.0 / TM_HOUR);
447 return; 435 return;
448 } 436 }
449 if (secs < TM_WEEK * 2) { 437 if (secs < TM_WEEK * 2) {
450 htmlf("<span class='age-days'>%.0f days</span>", 438 htmlf("<span class='age-days'>%.0f days</span>",
451 secs * 1.0 / TM_DAY); 439 secs * 1.0 / TM_DAY);
452 return; 440 return;
453 } 441 }
454 if (secs < TM_MONTH * 2) { 442 if (secs < TM_MONTH * 2) {
455 htmlf("<span class='age-weeks'>%.0f weeks</span>", 443 htmlf("<span class='age-weeks'>%.0f weeks</span>",
456 secs * 1.0 / TM_WEEK); 444 secs * 1.0 / TM_WEEK);
457 return; 445 return;
458 } 446 }
459 if (secs < TM_YEAR * 2) { 447 if (secs < TM_YEAR * 2) {
460 htmlf("<span class='age-months'>%.0f months</span>", 448 htmlf("<span class='age-months'>%.0f months</span>",
461 secs * 1.0 / TM_MONTH); 449 secs * 1.0 / TM_MONTH);
462 return; 450 return;
463 } 451 }
464 htmlf("<span class='age-years'>%.0f years</span>", 452 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR); 453 secs * 1.0 / TM_YEAR);
466} 454}
467 455
468void cgit_print_http_headers(struct cgit_context *ctx) 456void cgit_print_http_headers(struct cgit_context *ctx)
469{ 457{
470 const char *method = getenv("REQUEST_METHOD");
471
472 if (ctx->cfg.embedded) 458 if (ctx->cfg.embedded)
473 return; 459 return;
474 460
475 if (ctx->page.status) 461 if (ctx->page.status)
476 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 462 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
477 if (ctx->page.mimetype && ctx->page.charset) 463 if (ctx->page.mimetype && ctx->page.charset)
478 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 464 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
479 ctx->page.charset); 465 ctx->page.charset);
480 else if (ctx->page.mimetype) 466 else if (ctx->page.mimetype)
481 htmlf("Content-Type: %s\n", ctx->page.mimetype); 467 htmlf("Content-Type: %s\n", ctx->page.mimetype);
482 if (ctx->page.size) 468 if (ctx->page.size)
483 htmlf("Content-Length: %ld\n", ctx->page.size); 469 htmlf("Content-Length: %ld\n", ctx->page.size);
484 if (ctx->page.filename) 470 if (ctx->page.filename)
485 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 471 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
486 ctx->page.filename); 472 ctx->page.filename);
487 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 473 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
488 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 474 htmlf("Expires: %s\n", http_date(ctx->page.expires));
489 if (ctx->page.etag) 475 if (ctx->page.etag)
490 htmlf("ETag: \"%s\"\n", ctx->page.etag); 476 htmlf("ETag: \"%s\"\n", ctx->page.etag);
491 html("\n"); 477 html("\n");
492 if (method && !strcmp(method, "HEAD")) 478 if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD"))
493 exit(0); 479 exit(0);
494} 480}
495 481
496void cgit_print_docstart(struct cgit_context *ctx) 482void cgit_print_docstart(struct cgit_context *ctx)
497{ 483{
498 if (ctx->cfg.embedded) 484 if (ctx->cfg.embedded)
499 return; 485 return;
500 486
501 char *host = cgit_hosturl(); 487 char *host = cgit_hosturl();
502 html(cgit_doctype); 488 html(cgit_doctype);
503 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 489 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
504 html("<head>\n"); 490 html("<head>\n");
505 html("<title>"); 491 html("<title>");
506 html_txt(ctx->page.title); 492 html_txt(ctx->page.title);
507 html("</title>\n"); 493 html("</title>\n");
508 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 494 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
509 if (ctx->cfg.robots && *ctx->cfg.robots) 495 if (ctx->cfg.robots && *ctx->cfg.robots)
510 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 496 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
511 html("<link rel='stylesheet' type='text/css' href='"); 497 html("<link rel='stylesheet' type='text/css' href='");
512 html_attr(ctx->cfg.css); 498 html_attr(ctx->cfg.css);
513 html("'/>\n"); 499 html("'/>\n");
514 if (ctx->cfg.favicon) { 500 if (ctx->cfg.favicon) {
515 html("<link rel='shortcut icon' href='"); 501 html("<link rel='shortcut icon' href='");
516 html_attr(ctx->cfg.favicon); 502 html_attr(ctx->cfg.favicon);
517 html("'/>\n"); 503 html("'/>\n");
518 } 504 }
519 if (host && ctx->repo) { 505 if (host && ctx->repo) {
520 html("<link rel='alternate' title='Atom feed' href='"); 506 html("<link rel='alternate' title='Atom feed' href='");
521 html(cgit_httpscheme()); 507 html(cgit_httpscheme());
522 html_attr(cgit_hosturl()); 508 html_attr(cgit_hosturl());
523 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, 509 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
524 fmt("h=%s", ctx->qry.head))); 510 fmt("h=%s", ctx->qry.head)));
525 html("' type='application/atom+xml'/>\n"); 511 html("' type='application/atom+xml'/>\n");
526 } 512 }
527 if (ctx->cfg.head_include) 513 if (ctx->cfg.head_include)
528 html_include(ctx->cfg.head_include); 514 html_include(ctx->cfg.head_include);
529 html("</head>\n"); 515 html("</head>\n");
530 html("<body>\n"); 516 html("<body>\n");
531 if (ctx->cfg.header) 517 if (ctx->cfg.header)
532 html_include(ctx->cfg.header); 518 html_include(ctx->cfg.header);
533} 519}
534 520
535void cgit_print_docend() 521void cgit_print_docend()
536{ 522{
537 html("</div>"); 523 html("</div>");
538 if (ctx.cfg.footer) 524 if (ctx.cfg.footer)
539 html_include(ctx.cfg.footer); 525 html_include(ctx.cfg.footer);
540 else { 526 else {
541 htmlf("<div class='footer'>generated by cgit %s at ", 527 htmlf("<div class='footer'>generated by cgit %s at ",
542 cgit_version); 528 cgit_version);
543 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); 529 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
544 html("</div>\n"); 530 html("</div>\n");
545 } 531 }
546 html("</div>"); 532 html("</div>");
547 if (ctx.cfg.embedded) 533 if (ctx.cfg.embedded)
548 return; 534 return;
549 html("</body>\n</html>\n"); 535 html("</body>\n</html>\n");
550} 536}
551 537
552int print_branch_option(const char *refname, const unsigned char *sha1, 538int print_branch_option(const char *refname, const unsigned char *sha1,
553 int flags, void *cb_data) 539 int flags, void *cb_data)
554{ 540{
555 char *name = (char *)refname; 541 char *name = (char *)refname;
556 html_option(name, name, ctx.qry.head); 542 html_option(name, name, ctx.qry.head);
557 return 0; 543 return 0;
558} 544}
559 545
560int print_archive_ref(const char *refname, const unsigned char *sha1, 546int print_archive_ref(const char *refname, const unsigned char *sha1,
561 int flags, void *cb_data) 547 int flags, void *cb_data)
562{ 548{
563 struct tag *tag; 549 struct tag *tag;
564 struct taginfo *info; 550 struct taginfo *info;
565 struct object *obj; 551 struct object *obj;
566 char buf[256], *url; 552 char buf[256], *url;
567 unsigned char fileid[20]; 553 unsigned char fileid[20];
568 int *header = (int *)cb_data; 554 int *header = (int *)cb_data;
569 555
570 if (prefixcmp(refname, "refs/archives")) 556 if (prefixcmp(refname, "refs/archives"))
571 return 0; 557 return 0;
572 strncpy(buf, refname+14, sizeof(buf)); 558 strncpy(buf, refname+14, sizeof(buf));
573 obj = parse_object(sha1); 559 obj = parse_object(sha1);
574 if (!obj) 560 if (!obj)
575 return 1; 561 return 1;
576 if (obj->type == OBJ_TAG) { 562 if (obj->type == OBJ_TAG) {
577 tag = lookup_tag(sha1); 563 tag = lookup_tag(sha1);
578 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 564 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
579 return 0; 565 return 0;
580 hashcpy(fileid, tag->tagged->sha1); 566 hashcpy(fileid, tag->tagged->sha1);
581 } else if (obj->type != OBJ_BLOB) { 567 } else if (obj->type != OBJ_BLOB) {
582 return 0; 568 return 0;
583 } else { 569 } else {
584 hashcpy(fileid, sha1); 570 hashcpy(fileid, sha1);
585 } 571 }
586 if (!*header) { 572 if (!*header) {
587 html("<h1>download</h1>\n"); 573 html("<h1>download</h1>\n");
588 *header = 1; 574 *header = 1;