/* ui-shared.c: common web output functions
*
* Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com>
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "ui-shared.h"
#include "cmd.h"
#include "html.h"
#include "version.h"
static const char cgit_doctype[] =
"<!DOCTYPE html>\n";
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", "Nov", "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);
}
void cgit_print_error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
cgit_vprint_error(fmt, ap);
va_end(ap);
}
void cgit_vprint_error(const char *fmt, va_list ap)
{
va_list cp;
html("<div class='error'>");
va_copy(cp, ap);
html_vtxtf(fmt, cp);
va_end(cp);
html("</div>\n");
}
const char *cgit_httpscheme(void)
{
if (ctx.env.https && !strcmp(ctx.env.https, "on"))
return "https://";
else
return "http://";
}
char *cgit_hosturl(void)
{
if (ctx.env.http_host)
return xstrdup(ctx.env.http_host);
if (!ctx.env.server_name)
return NULL;
if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
return xstrdup(ctx.env.server_name);
return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
}
char *cgit_currenturl(void)
{
const char *root = cgit_rooturl();
size_t len = strlen(root);
if (!ctx.qry.url)
return xstrdup(root);
if (len && root[len - 1] == '/')
return fmtalloc("%s%s", root, ctx.qry.url);
return fmtalloc("%s/%s", root, ctx.