aboutsummaryrefslogtreecommitdiff
path: root/ctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctl.c')
-rw-r--r--ctl.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/ctl.c b/ctl.c
index 1a3627c..c5f90f4 100644
--- a/ctl.c
+++ b/ctl.c
@@ -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 *)&timestamp);
+ 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"