diff options
Diffstat (limited to 'cforum.c')
-rw-r--r-- | cforum.c | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -1,22 +1,24 @@ +#include <err.h> #include <sqlite3.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "ctl.h" /* Controllers. */ -#include "db.h" /* Database. Defines global variable db. */ +#include "db.h" /* Database functions. 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. */ -#define MAXERR 300 +#define MAXMSG 300 int main(int argc, char *argv[]) { - char err[MAXERR], *p, *v; + char msg[MAXMSG], *p, *v; int attid, postid, userid; sqlite3_stmt *stmt; + struct att *att; /* * The database is opened or a server error is generated. @@ -24,10 +26,10 @@ main(int argc, char *argv[]) * assumed to be opened. */ if(sqlite3_open("db", &db) != SQLITE_OK){ - snprintf(err, MAXERR, + snprintf(msg, MAXMSG, "The database could not be opened: %s\n", sqlite3_errmsg(db)); - srverr(err); + srverr(msg); sqlite3_close(db); return 1; } @@ -39,18 +41,18 @@ main(int argc, char *argv[]) if(sqlite3_prepare(db, "SELECT value FROM settings WHERE key = 'name'", -1, &stmt, 0) != SQLITE_OK){ - snprintf(err, MAXERR, + snprintf(msg, MAXMSG, "The site name could not be retrieved: %s\n", sqlite3_errmsg(db)); - srverr(err); + srverr(msg); sqlite3_close(db); return 1; } if(sqlite3_step(stmt) == SQLITE_ROW) site.name = strdup((char *)sqlite3_column_text(stmt, 0)); else{ - snprintf(err, MAXERR, "The site name is not set.\n"); - srverr(err); + snprintf(msg, MAXMSG, "The site name is not set.\n"); + srverr(msg); sqlite3_finalize(stmt); sqlite3_close(db); return 1; @@ -58,6 +60,21 @@ main(int argc, char *argv[]) sqlite3_finalize(stmt); /* + if(!(att = malloc(sizeof(struct att)))) + err(1, "malloc"); + att->post = 1; + att->name = strdup("example2"); + att->description = NULL; + att->mime = strdup("text/html"); + att->data = strdup("Hello!"); + att->bytes = strlen(att->data)+1; + + fprintf(stderr, "[add] %d %s\n", + addatt(att), sqlite3_errmsg(db)); + free(att); + */ + + /* * The global struct query is set, or the program dies. * From now on, query is assumed to be set. */ |