aboutsummaryrefslogtreecommitdiff
path: root/ctl.c
blob: c5f90f45530672d8da79271a249a11b10a9f37e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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()
{
	char *title;
	
	title = site.name;
	printf("Content-Type: text/html\n\n");
	#include "t/head.tc"
	#include "t/front.tc"
	#include "t/foot.tc"
}

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");
	#include "t/head.tc"
	#include "t/post.tc"
	#include "t/foot.tc"
}

void
showuser(int id)
{
	char s[128], *title;
	struct user *user;
	
	if(!(user = getuser(id))){
		srverr("Could not retrieve user");
		return;
	}
	
	title = site.name;
	printf("Content-Type: text/html\n\n");
	#include "t/head.tc"
	#include "t/user.tc"
	#include "t/foot.tc"
	free(user);
}