summaryrefslogtreecommitdiffabout
path: root/html.c
authorLars Hjemli <hjemli@gmail.com>2008-08-05 23:20:24 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-08-06 09:21:09 (UTC)
commit02a545e63454530c1639014d3239c14ced2022c6 (patch) (side-by-side diff)
treeda4c89a94b117d936f2eeb486c9dedf192e6746e /html.c
parent0f0ab148c6d444316af10e6b4c7a60630fed45d3 (diff)
downloadcgit-02a545e63454530c1639014d3239c14ced2022c6.zip
cgit-02a545e63454530c1639014d3239c14ced2022c6.tar.gz
cgit-02a545e63454530c1639014d3239c14ced2022c6.tar.bz2
Add support for cloning over http
This patch implements basic support for cloning over http, based on the work on git-http-backend by Shawn O. Pearce. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'html.c') (more/less context) (show whitespace changes)
-rw-r--r--html.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/html.c b/html.c
index bddb04d..1237076 100644
--- a/html.c
+++ b/html.c
@@ -6,96 +6,103 @@
* (see COPYING for full license text)
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
int htmlfd = STDOUT_FILENO;
char *fmt(const char *format, ...)
{
static char buf[8][1024];
static int bufidx;
int len;
va_list args;
bufidx++;
bufidx &= 7;
va_start(args, format);
len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
va_end(args);
if (len>sizeof(buf[bufidx])) {
fprintf(stderr, "[html.c] string truncated: %s\n", format);
exit(1);
}
return buf[bufidx];
}
void html(const char *txt)
{
write(htmlfd, txt, strlen(txt));
}
void htmlf(const char *format, ...)
{
static char buf[65536];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
html(buf);
}
+void html_status(int code, int more_headers)
+{
+ htmlf("Status: %d\n", code);
+ if (!more_headers)
+ html("\n");
+}
+
void html_txt(char *txt)
{
char *t = txt;
while(t && *t){
int c = *t;
if (c=='<' || c=='>' || c=='&') {
write(htmlfd, txt, t - txt);
if (c=='>')
html("&gt;");
else if (c=='<')
html("&lt;");
else if (c=='&')
html("&amp;");
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
void html_ntxt(int len, char *txt)
{
char *t = txt;
while(t && *t && len--){
int c = *t;
if (c=='<' || c=='>' || c=='&') {
write(htmlfd, txt, t - txt);
if (c=='>')
html("&gt;");
else if (c=='<')
html("&lt;");
else if (c=='&')
html("&amp;");
txt = t+1;
}
t++;
}
if (t!=txt)
write(htmlfd, txt, t - txt);
if (len<0)
html("...");
}
void html_attr(char *txt)
{
char *t = txt;
while(t && *t){