[PATCH 01/17] ui-shared: add cgit_print_error_page() function

John Keeping john at keeping.me.uk
Sun Apr 5 17:54:47 CEST 2015


This will allow us to generate error responses with the correct HTTP
response code without needing all of the layout boilerplate.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 14 ++++++++++++++
 ui-shared.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/ui-shared.c b/ui-shared.c
index ac5a287..bcde2bb 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -767,6 +767,20 @@ void cgit_print_docend(void)
 	html("</body>\n</html>\n");
 }
 
+void cgit_print_error_page(int code, const char *msg, const char *fmt, ...)
+{
+	va_list ap;
+	ctx.page.status = 404;
+	ctx.page.statusmsg = "Not found";
+	cgit_print_http_headers();
+	cgit_print_docstart();
+	cgit_print_pageheader();
+	va_start(ap, fmt);
+	cgit_vprint_error(fmt, ap);
+	va_end(ap);
+	cgit_print_docend();
+}
+
 static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
 {
 	struct strbuf **url_list = strbuf_split_str(txt, ' ', 0);
diff --git a/ui-shared.h b/ui-shared.h
index 1b8ecb5..6a14858 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -63,6 +63,8 @@ extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
 extern void cgit_print_http_headers(void);
 extern void cgit_print_docstart(void);
 extern void cgit_print_docend();
+__attribute__((format (printf,3,4)))
+extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...);
 extern void cgit_print_pageheader(void);
 extern void cgit_print_filemode(unsigned short mode);
 extern void cgit_print_snapshot_links(const char *repo, const char *head,
-- 
2.4.0.rc0.173.gb1cefcc



More information about the CGit mailing list