2 cehtehs git web frontend
5 2007, Christian Thaeter <ct@pipapo.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define WEBGIT_CONFIG "./webgit.conf"
28 #define WEBGIT_CONFIG "/etc/webgit.conf"
35 #include "git/git-compat-util.h"
49 webgit_err_vargs (const char *err, va_list params)
51 html_list_append (error_log, html (html_fmt_vargs (err, params), html_tag ("br")));
57 webgit_err (const char *err, ...)
61 webgit_err_vargs (err, args);
67 webgit_warn_vargs (const char *err, va_list params)
69 html_list_append (error_log, html (html_fmt_vargs (err, params), html_tag("br")));
74 webgit_warn (const char *err, ...)
78 webgit_warn_vargs (err, args);
86 set_die_routine (webgit_err_vargs);
87 set_error_routine (webgit_err_vargs);
88 set_warn_routine (webgit_warn_vargs);
93 webgit_email_link (Html name, Html email)
98 html ("mailto:", email))
106 webgit_mimetype (const char* name)
113 char* ext = strrchr (name, '.');
120 FILE* mime_types = fopen ("/etc/mime.types", "r");
124 while (fgets (buf, 256, mime_types))
126 if (buf[0] == '#' || !strtok (buf, " \t\n"))
130 while ((suffix = strtok (NULL, " \t\n")))
131 if (!strcmp (suffix, ext))
134 return cwa_strndup (buf, SIZE_MAX);
141 webgit_header (struct webgit_query* query)
151 main (int argc, char**argv)
154 struct webgit_query query;
158 error_log = html_list();
160 clock_t timestat = clock();
162 webgit_query_init (&query);
164 /* set some defaults if not already set */
165 setenv ("REQUEST_METHOD", "GET", 0);
166 setenv ("SCRIPT_NAME", argv[0], 0);
167 setenv ("WEBGIT_CONFIG", WEBGIT_CONFIG, 0);
169 /* we can only longjmp out of libgit's error handling */
170 if (setjmp (err_jmp))
173 if (webgit_commandline_dispatch (argc, argv, &query))
177 if (webgit_configfile_dispatch (getenv("WEBGIT_CONFIG"), &query))
181 // parse request/query What to show?
183 query.request = cgi_new ();
185 cgi_run_query (query.request, webgit_param_dispatch, &query);
188 query.count = query.count_def;
190 /* TODO: if no object given but repo+path+ref are given then compute object */
192 /* default action is to show the main page with the list of repos */
194 query.action = cwa_strndup ("main", SIZE_MAX);
197 // query to cache-line
203 Html content = webgit_action_dispatch (&query);
205 if (query.content_type && !strcmp (query.content_type, "text/html"))
207 /* generate html page */
213 html_attr("charset", "UTF-8")
215 //html_httpfield("Last-Modified", cgit_page.modified),
216 //html_httpfield("Expires", cgit_page.expires)
219 "-//W3C//DTD XHTML 1.0 Transitional//EN",
220 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
224 html(html_tag("title"), "webgit"),
226 html_meta("generator", "webgit"),
227 html_link_rel("stylesheet", "text/css", query.stylesheet),
228 html_link_rel("icon", "image/png", "/skins/default/icons/favicon.png")
234 html_attr("id", "container")
236 /* TODO header.inc should be configurable and may not exist
237 The idea is to have a project header and footer available
238 as plain html so that someone can install webgit
239 and quickly add their project logo, menu back to the main
240 project website and any other notices they may wish to add
242 html_include ("/home/cillian/webgit/skins/default/inc/header.inc"),
246 html_attr("id", "errors")
250 // See TODO header.inc above
251 // html_include ("/home/cillian/webgit/skins/default/inc/footer.inc"),
256 html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
257 html_attr("xml:lang", "en"),
258 html_attr("lang", "en")
263 timestat = clock() - timestat;
264 html_list_append (error_log, html (
265 html_tag("div", html_attr ("id", "timestat")),
266 html_fmt ("processing took %g secs\n", timestat/(float)CLOCKS_PER_SEC)
275 /* diffrent content type, raw content */
276 html_free (error_log);
280 html_httpfield ("Content-type",
283 : "application/octet-stream")
289 html_fprint (stdout, page);
293 webgit_query_destroy (&query);
303 html_attr("charset", "UTF-8")
306 "-//W3C//DTD XHTML 1.0 Transitional//EN",
307 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
311 html(html_tag("title"), "ERROR: webgit"),
313 html_meta("generator", "webgit")
320 html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
321 html_attr("xml:lang", "en"),
322 html_attr("lang", "en")
327 html_fprint (stdout, page);