#include #include #include #include #include "err.h" #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 showattachment(id) { struct attachment *attachment; if(!(attachment = getattachment(byid("attachments", id), 1))){ srverr("Could not retrieve attachment"); return; } printf("Content-Type: %s\n\n", attachment->mime); printf("%.*s", attachment->bytes, attachment->data); } void showfront() { char *title; struct post *post; struct user *user; 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 attachment *attachment; struct post *post; struct user *user; sqlite3_stmt *stmt; 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; } stmt = byid("attachments", id); title = site.name; printf("Content-Type: text/html\n\n"); #include "t/post.tc" } void showuser(int id) { char *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); }