#include #include #include #include #include "db.h" #include "query.h" #include "site.h" void printdate(int timestamp) { char buf[20]; struct tm *t; t = localtime((time_t *)×tamp); strftime(buf, 20, "%Y-%m-%d %H:%M", t); printf(buf); } void showfront() { char *title; sqlite3_stmt *stmt; if(sqlite3_prepare(db, "SELECT oid, * from posts ORDER BY created DESC", -1, &stmt, 0) != SQLITE_OK){ srverr("Could not retrieve posts"); return; } title = site.name; printf("Content-Type: text/html\n\n"); #include "t/front.tc" } void showpost(int id) { char *title; struct post *post; struct user *user; if(!(post = getpost(byid("posts", id), 1))){ srverr("Could not retrieve post"); return; } if(!(user = getuser(byid("users", post->user), 1))){ srverr("Could not retrieve post author"); return; } title = site.name; printf("Content-Type: text/html\n\n"); #include "t/post.tc" } void showuser(int id) { char s[128], *title; struct user *user; if(!(user = getuser(byid("users", id), 1))){ srverr("Could not retrieve user"); return; } title = site.name; printf("Content-Type: text/html\n\n"); #include "t/user.tc" free(user); }