#include #include #include #include #include "ctl.h" /* Controllers. */ #include "err.h" /* HTTP errors. */ #include "site.h" /* Site settings. Defines global struct site. */ #include "query.h" /* Query functions. Defines global string qs. */ #define MAXERR 300 int main(int argc, char *argv[]) { char err[MAXERR], *qs; sqlite3 *db; sqlite3_stmt *res; /* * The database is opened or a server error is generated. * In the rest of the program, the database is always * assumed to be opened. */ if(sqlite3_open("db", &db) != SQLITE_OK){ snprintf(err, MAXERR, "The database could not be opened: %s\n", sqlite3_errmsg(db)); srverr(err); sqlite3_close(db); return 1; } /* * The site name is retrieved from the database. This early on, * it is appropriate to die with a server error on failure. */ if(sqlite3_prepare(db, "SELECT value FROM settings WHERE key = 'name'", -1, &res, 0) != SQLITE_OK){ snprintf(err, MAXERR, "The site name could not be retrieved: %s\n", sqlite3_errmsg(db)); srverr(err); sqlite3_close(db); return 1; } if(sqlite3_step(res) == SQLITE_ROW) site.name = strdup(sqlite3_column_text(res, 0)); else{ snprintf(err, MAXERR, "The site name is not set.\n"); srverr(err); sqlite3_finalize(res); sqlite3_close(db); return 1; } sqlite3_finalize(res); /* * The global variable qs is set to the query string, or the * program dies. From now on, qs is assumed to be set. */ setqs(); /* Handle request. */ if(!qs || !*qs) front(); /* INSERT CONDITIONS HERE */ else front(); sqlite3_close(db); return 0; }