diff options
Diffstat (limited to 'ctl.c')
-rw-r--r-- | ctl.c | 37 |
1 files changed, 30 insertions, 7 deletions
@@ -7,6 +7,7 @@ #include "query.h" #include "site.h" +/* Print UNIX timestamp as written date. */ void printdate(int timestamp) { @@ -24,7 +25,7 @@ showatt(id) { struct att *att; - if(!(att = getatt(byid("atts", id)))){ + if(!(att = getatt(selectbyint("atts", "oid", id)))){ srverr("Could not retrieve att"); return; } @@ -40,15 +41,22 @@ showfront() char *title; struct post *post; struct user *user; - sqlite3_stmt *stmt; + sqlite3_stmt *pstmt, *ustmt; if(sqlite3_prepare(db, "SELECT oid, * from posts ORDER BY created DESC", - -1, &stmt, 0) != SQLITE_OK){ + -1, &pstmt, 0) != SQLITE_OK){ srverr("Could not retrieve posts"); return; } + if(sqlite3_prepare(db, + "SELECT oid, * from users ORDER BY created DESC", + -1, &ustmt, 0) != SQLITE_OK){ + srverr("Could not retrieve users"); + return; + } + title = site.name; printf("Content-Type: text/html\n\n"); #include "t/front.tc" @@ -63,17 +71,17 @@ showpost(int id) struct user *user; sqlite3_stmt *stmt; - if(!(post = getpost(byid("posts", id)))){ + if(!(post = getpost(selectbyint("posts", "oid", id)))){ srverr("Could not retrieve post"); return; } - if(!(user = getuser(byid("users", post->user)))){ + if(!(user = getuser(selectbyint("users", "oid", post->user)))){ srverr("Could not retrieve post author"); return; } - stmt = byid("atts", id); + stmt = selectbyint("atts", "post", id); title = site.name; printf("Content-Type: text/html\n\n"); @@ -86,15 +94,30 @@ void showuser(int id) { char *title; + sqlite3_stmt *stmt; + struct post *post; struct user *user; - if(!(user = getuser(byid("users", id)))){ + if(!(user = getuser(selectbyint("users", "oid", id)))){ srverr("Could not retrieve user"); return; } + if(sqlite3_prepare(db, + "SELECT oid, * from posts WHERE user = ? ORDER BY created DESC", + -1, &stmt, 0) != SQLITE_OK) + goto err; + + if(sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) + goto err; + title = site.name; printf("Content-Type: text/html\n\n"); #include "t/user.tc" free(user); + return; + +err: + srverr("Could not retrieve posts"); + return; }
\ No newline at end of file |