author | Lars Hjemli <hjemli@gmail.com> | 2006-12-10 21:41:14 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-10 21:41:14 (UTC) |
commit | 7640d90b73c01b16bb04ce4c541f52cbaae5f82a (patch) (side-by-side diff) | |
tree | a0ec3e5222dbb0cff965487def39f5781e5cb231 /cgit.c | |
parent | 25105d7ecaba474d4b7c364ebb586aac3dfc5abb (diff) | |
download | cgit-7640d90b73c01b16bb04ce4c541f52cbaae5f82a.zip cgit-7640d90b73c01b16bb04ce4c541f52cbaae5f82a.tar.gz cgit-7640d90b73c01b16bb04ce4c541f52cbaae5f82a.tar.bz2 |
Add license file and copyright notices
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1,192 +1,200 @@ +/* cgit.c: cgi for the git scm + * + * Copyright (C) 2006 Lars Hjemli + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + #include "cgit.h" static const char cgit_doctype[] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; static const char cgit_error[] = "<div class='error'>%s</div>"; static const char cgit_lib_error[] = "<div class='error'>%s: %s</div>"; int htmlfd = 0; char *cgit_root = "/usr/src/git"; char *cgit_root_title = "Git repository browser"; char *cgit_css = "/cgit.css"; char *cgit_logo = "/git-logo.png"; char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; char *cgit_virtual_root = NULL; char *cgit_cache_root = "/var/cache/cgit"; int cgit_cache_root_ttl = 5; int cgit_cache_repo_ttl = 5; int cgit_cache_dynamic_ttl = 5; int cgit_cache_static_ttl = -1; int cgit_cache_max_create_time = 5; char *cgit_repo_name = NULL; char *cgit_repo_desc = NULL; char *cgit_repo_owner = NULL; int cgit_query_has_symref = 0; int cgit_query_has_sha1 = 0; char *cgit_querystring = NULL; char *cgit_query_repo = NULL; char *cgit_query_page = NULL; char *cgit_query_head = NULL; char *cgit_query_sha1 = NULL; struct cacheitem cacheitem; int cgit_parse_query(char *txt, configfn fn) { char *t, *value = NULL, c; if (!txt) return 0; t = txt = xstrdup(txt); while((c=*t) != '\0') { if (c=='=') { *t = '\0'; value = t+1; } else if (c=='&') { *t = '\0'; (*fn)(txt, value); txt = t+1; value = NULL; } t++; } if (t!=txt) (*fn)(txt, value); return 0; } void cgit_global_config_cb(const char *name, const char *value) { if (!strcmp(name, "root")) cgit_root = xstrdup(value); else if (!strcmp(name, "root-title")) cgit_root_title = xstrdup(value); else if (!strcmp(name, "css")) cgit_css = xstrdup(value); else if (!strcmp(name, "logo")) cgit_logo = xstrdup(value); else if (!strcmp(name, "logo-link")) cgit_logo_link = xstrdup(value); else if (!strcmp(name, "virtual-root")) cgit_virtual_root = xstrdup(value); } void cgit_repo_config_cb(const char *name, const char *value) { if (!strcmp(name, "name")) cgit_repo_name = xstrdup(value); else if (!strcmp(name, "desc")) cgit_repo_desc = xstrdup(value); else if (!strcmp(name, "owner")) cgit_repo_owner = xstrdup(value); } void cgit_querystring_cb(const char *name, const char *value) { if (!strcmp(name,"r")) cgit_query_repo = xstrdup(value); else if (!strcmp(name, "p")) cgit_query_page = xstrdup(value); else if (!strcmp(name, "h")) { cgit_query_head = xstrdup(value); cgit_query_has_symref = 1; } else if (!strcmp(name, "id")) { cgit_query_sha1 = xstrdup(value); cgit_query_has_sha1 = 1; } } char *cgit_repourl(const char *reponame) { if (cgit_virtual_root) { return fmt("%s/%s/", cgit_virtual_root, reponame); } else { return fmt("?r=%s", reponame); } } char *cgit_pageurl(const char *reponame, const char *pagename, const char *query) { if (cgit_virtual_root) { return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, pagename, query); } else { return fmt("?r=%s&p=%s&%s", reponame, pagename, query); } } static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct commit *commit; char buf[256], *url; commit = lookup_commit(sha1); if (commit && !parse_commit(commit)){ html("<tr><td>"); url = cgit_pageurl(cgit_query_repo, "log", fmt("h=%s", refname)); html_link_open(url, NULL, NULL); strncpy(buf, refname, sizeof(buf)); html_txt(buf); html_link_close(); html("</td><td>"); pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf, sizeof(buf), 0, NULL, NULL, 0); html_txt(buf); html("</td></tr>\n"); } else { html("<tr><td>"); html_txt(buf); html("</td><td>"); htmlf("*** bad ref %s", sha1_to_hex(sha1)); html("</td></tr>\n"); } return 0; } /* Sun, 06 Nov 1994 08:49:37 GMT */ static char *http_date(time_t t) { static char day[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static char month[][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; struct tm *tm = gmtime(&t); return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); } static int ttl_seconds(int ttl) { if (ttl<0) return 60 * 60 * 24 * 365; else return ttl * 60; } static void cgit_print_docstart(char *title) { html("Content-Type: text/html; charset=utf-8\n"); htmlf("Last-Modified: %s\n", http_date(cacheitem.st.st_mtime)); htmlf("Expires: %s\n", http_date(cacheitem.st.st_mtime + ttl_seconds(cacheitem.ttl))); html("\n"); html(cgit_doctype); html("<html>\n"); html("<head>\n"); html("<title>"); |