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);
142 main (int argc, char**argv)
145 struct webgit_query query;
149 error_log = html_list();
151 clock_t timestat = clock();
153 webgit_query_init (&query);
155 /* set some defaults if not already set */
156 setenv ("REQUEST_METHOD", "GET", 0);
157 setenv ("SCRIPT_NAME", argv[0], 0);
158 setenv ("WEBGIT_CONFIG", WEBGIT_CONFIG, 0);
160 /* we can only longjmp out of libgit's error handling */
161 if (setjmp (err_jmp))
164 if (webgit_commandline_dispatch (argc, argv, &query))
168 if (webgit_configfile_dispatch (getenv("WEBGIT_CONFIG"), &query))
172 // parse request/query What to show?
174 query.request = cgi_new ();
176 cgi_run_query (query.request, webgit_param_dispatch, &query);
179 query.count = query.count_def;
181 /* TODO: if no object given but repo+path+ref are given then compute object */
183 /* default action is to show the main page with the list of repos */
185 query.action = cwa_strndup ("main", SIZE_MAX);
188 // query to cache-line
194 Html content = webgit_action_dispatch (&query);
196 if (query.content_type && !strcmp (query.content_type, "text/html"))
198 /* generate html page */
204 html_attr("charset", "UTF-8")
206 //html_httpfield("Last-Modified", cgit_page.modified),
207 //html_httpfield("Expires", cgit_page.expires)
210 "-//W3C//DTD XHTML 1.0 Transitional//EN",
211 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
215 html(html_tag("title"), "webgit"),
217 html_meta("generator", "webgit"),
218 html_link_rel("stylesheet", "text/css", query.stylesheet),
219 html_link_rel("icon", "image/png", "/skins/default/icons/favicon.png")
225 html_attr("id", "container")
234 html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
235 html_attr("xml:lang", "en"),
236 html_attr("lang", "en")
238 timestat = clock() - timestat;
239 html_list_append (error_log, html (
240 html_tag("div", html_attr ("id", "timestat")),
241 html_fmt ("processing took %g secs\n", timestat/(float)CLOCKS_PER_SEC)
253 /* diffrent content type, raw content */
254 html_free (error_log);
258 html_httpfield ("Content-type",
261 : "application/octet-stream")
267 html_fprint (stdout, page);
271 webgit_query_destroy (&query);
281 html_attr("charset", "UTF-8")
284 "-//W3C//DTD XHTML 1.0 Transitional//EN",
285 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
289 html(html_tag("title"), "ERROR: webgit"),
291 html_meta("generator", "webgit")
298 html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
299 html_attr("xml:lang", "en"),
300 html_attr("lang", "en")
305 html_fprint (stdout, page);