diff options
Diffstat (limited to 'ctl.c')
-rw-r--r-- | ctl.c | 39 |
1 files changed, 37 insertions, 2 deletions
@@ -1,9 +1,28 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <time.h> #include "db.h" #include "query.h" #include "site.h" +#define PFREE(s) do{ printf("%s", s); free(s); }while(0) + +char * +date(int timestamp) +{ + char *buf; + struct tm *t; + + if(!(buf = malloc(20))) + err(1, "malloc"); + + t = localtime((time_t *)×tamp); + strftime(buf, 20, "%Y-%m-%d %H:%M", t); + + return buf; +} + void showfront() { @@ -20,6 +39,18 @@ void showpost(int id) { char *title; + struct post *post; + struct user *user; + + if(!(post = getpost(id))){ + srverr("Could not retrieve post"); + return; + } + + if(!(user = getuser(post->user))){ + srverr("Could not retrieve post author"); + return; + } title = site.name; printf("Content-Type: text/html\n\n"); @@ -31,10 +62,14 @@ showpost(int id) void showuser(int id) { - char *title; + char s[128], *title; struct user *user; - user = getuser(id); + if(!(user = getuser(id))){ + srverr("Could not retrieve user"); + return; + } + title = site.name; printf("Content-Type: text/html\n\n"); #include "t/head.tc" |