diff options
Diffstat (limited to 'cforum.c')
-rw-r--r-- | cforum.c | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -4,6 +4,7 @@ #include <string.h> #include "ctl.h" /* Controllers. */ +#include "db.h" /* Database. Defines global variable db. */ #include "err.h" /* HTTP errors. */ #include "site.h" /* Site settings. Defines global struct site. */ #include "query.h" /* Query functions. Defines global struct query. */ @@ -13,9 +14,9 @@ int main(int argc, char *argv[]) { - char err[MAXERR], *qs; - sqlite3 *db; - sqlite3_stmt *res; + char err[MAXERR], *p, *qs, *v; + int postid, userid; + sqlite3_stmt *stmt; /* * The database is opened or a server error is generated. @@ -37,7 +38,7 @@ main(int argc, char *argv[]) */ if(sqlite3_prepare(db, "SELECT value FROM settings WHERE key = 'name'", - -1, &res, 0) != SQLITE_OK){ + -1, &stmt, 0) != SQLITE_OK){ snprintf(err, MAXERR, "The site name could not be retrieved: %s\n", sqlite3_errmsg(db)); @@ -45,16 +46,16 @@ main(int argc, char *argv[]) sqlite3_close(db); return 1; } - if(sqlite3_step(res) == SQLITE_ROW) - site.name = strdup(sqlite3_column_text(res, 0)); + if(sqlite3_step(stmt) == SQLITE_ROW) + site.name = strdup(sqlite3_column_text(stmt, 0)); else{ snprintf(err, MAXERR, "The site name is not set.\n"); srverr(err); - sqlite3_finalize(res); + sqlite3_finalize(stmt); sqlite3_close(db); return 1; } - sqlite3_finalize(res); + sqlite3_finalize(stmt); /* * The global struct query is set, or the program dies. @@ -62,13 +63,29 @@ main(int argc, char *argv[]) */ setquery(); + /* Handle empty request. */ + if(!*query.string){ + showfront(); + goto end; + } + + /* Parse query string. */ + postid = userid = -1; + while(p = nextparam(GET, 128)){ + v = split(p); + if(strcmp(p, "post") == 0) postid = atoi(v); + else if(strcmp(p, "user") == 0) userid = atoi(v); + } + /* Handle request. */ - if(!*query.string) - front(); - /* INSERT CONDITIONS HERE */ + if(postid != -1) + showpost(postid); + else if(userid != -1) + showuser(userid); else - front(); + showfront(); +end: sqlite3_close(db); return 0; }
\ No newline at end of file |