timekeeper

My first (abandoned unfinished) web application for time tracking
git clone git://jacobedwards.org/timekeeper
Log | Files | Refs | README

util.c (1473B)


      1 #define const
      2 
      3 #include "common.h"
      4 #include "../frag.h"
      5 
      6 enum kcgi_err
      7 redirect(struct pagedata *pd, char *to, char *msg)
      8 {
      9 	static char *css[] = { "css/main.css", NULL };
     10 	static struct pagetemplate template = {
     11 		"Redirect",
     12 		.css = css
     13 	};
     14 
     15 	enum kcgi_err status;
     16 
     17 	if ((status = khttp_head(&pd->req, kresps[KRESP_LOCATION], "%s", to)) != KCGI_OK)
     18 		return status;
     19 	if ((status = tk_startpage(pd, &template, KHTTP_303)) != KCGI_OK)
     20 		return status;
     21 	if ((status = khtml_elem(&pd->html, KELEM_H1)) != KCGI_OK ||
     22 	    (status = khtml_puts(&pd->html, msg)) != KCGI_OK ||
     23 	    (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK ||
     24 	    (status = khtml_elem(&pd->html, KELEM_P)) != KCGI_OK ||
     25 	    (status = khtml_puts(&pd->html, "You are being redirected to ")) != KCGI_OK ||
     26 	    (status = khtml_attr(&pd->html, KELEM_A,
     27 	        KATTR_HREF, to,
     28 		KATTR__MAX)) != KCGI_OK ||
     29 	    (status = khtml_puts(&pd->html, to)) != KCGI_OK ||
     30 	    (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK ||
     31 	    (status = khtml_putc(&pd->html, '.')) != KCGI_OK)
     32 		return status;
     33 	return khtml_close(&pd->html);
     34 }
     35 
     36 enum kcgi_err
     37 fragpage(struct pagedata *pd, char *name, char *fragname)
     38 {
     39 	static char *css[] = { "css/main.css", NULL };
     40 
     41 	enum kcgi_err status;
     42 	struct pagetemplate template = {
     43 		name,
     44 		.css = css
     45 	};
     46 
     47 	if ((status = tk_startpage(pd, &template, KHTTP_200)) != KCGI_OK)
     48 		return status;
     49 
     50 	if (frag(pd, fragname))
     51 		return KCGI_SYSTEM;
     52 
     53 	return endpage(pd, &template);
     54 }