diff options
-rw-r--r-- | README | 14 | ||||
-rw-r--r-- | cforum.c | 7 | ||||
-rw-r--r-- | cforum.h | 97 | ||||
-rw-r--r-- | ctl.c | 5 | ||||
-rw-r--r-- | ctl.h | 7 | ||||
-rw-r--r-- | db.c | 2 | ||||
-rw-r--r-- | db.h | 41 | ||||
-rw-r--r-- | err.c | 1 | ||||
-rw-r--r-- | err.h | 1 | ||||
-rw-r--r-- | query.c | 2 | ||||
-rw-r--r-- | query.h | 17 | ||||
-rw-r--r-- | site.h | 13 |
12 files changed, 107 insertions, 100 deletions
@@ -8,16 +8,12 @@ C89, it can be run on practically any UNIX system. It is also rather small: wc -l *.c *.h */*.t */*.lex - 101 cforum.c - 299 ctl.c + 96 cforum.c + 296 ctl.c 268 db.c - 10 err.c + 11 err.c 144 query.c - 6 ctl.h - 40 db.h - 0 err.h - 16 query.h - 12 site.h + 96 cforum.h 3 t/err.t 1 t/foot.t 29 t/front.t @@ -26,4 +22,4 @@ It is also rather small: 28 t/post.t 12 t/user.t 95 mktpl/mktpl.lex - 1117 total + 1132 total @@ -3,12 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> - -#include "ctl.h" /* Controllers. */ -#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. */ +#include "cforum.h" #define MAXMSG 300 diff --git a/cforum.h b/cforum.h new file mode 100644 index 0000000..13d0d30 --- /dev/null +++ b/cforum.h @@ -0,0 +1,97 @@ +#include <sqlite3.h> + +/***** Types *****/ + +enum method{ + GET, + POST +}; + +struct att{ + int id; + int post; + int bytes; /* Size of data. */ + char *name; + char *desc; + char *mime; + char *data; +}; + +struct post{ + int id; + int parent; + int user; + int created; + int edited; + char *subject; + char *text; +}; + +struct user{ + int id; + int created; + char *name; + char *full; + char *hash; +}; + +struct query{ + int method; + int length; /* Content length. */ + char *string; +}; + +struct site{ + char *name; +}; + +/***** Functions *****/ + +/* ctl.c */ +void newatt(void); +void newpost(void); +void newuser(void); +void showatt(int); +void showfront(void); +void showpost(int); +void showuser(int); + +/* db.c */ +int addatt(struct att *); +int adduser(struct user *); +struct att *getatt(sqlite3_stmt *); +struct post *getpost(sqlite3_stmt *); +struct user *getuser(sqlite3_stmt *); +struct att *nextatt(sqlite3_stmt *); +struct post *nextpost(sqlite3_stmt *); +struct user *nextuser(sqlite3_stmt *); +sqlite3_stmt *selectbyint(char *, char *, int); + +/* err.c */ +void srverr(char *); + +/* query.c */ +char *nextparam(enum method, int *, int); +void setquery(void); +char *split(char *); +int urldecode(char *, int); + +/***** Definitions *****/ + +#define TRUNCATED(s) s[-1] + +/* Maximum allowed Content-Length for various forms. */ +#define MAXATTDATA 4096 +#define MAXUSERDATA 512 +#define MAXPOSTDATA 4096 + +/* Maximum size of user information, incl. NUL. */ +#define MAXUSERNAME 40 +#define MAXUSERFULL 128 +#define MAXUSERPASS 128 + +/***** Variables *****/ + +sqlite3 *db; +struct query query; +struct site site;
\ No newline at end of file @@ -3,10 +3,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> -#include "err.h" -#include "db.h" -#include "query.h" -#include "site.h" +#include "cforum.h" /* Print UNIX timestamp as written date. */ void @@ -1,7 +0,0 @@ -void newatt(void); -void newpost(void); -void newuser(void); -void showatt(int); -void showfront(void); -void showpost(int); -void showuser(int);
\ No newline at end of file @@ -4,7 +4,7 @@ #include <string.h> #include <sqlite3.h> #include <time.h> -#include "db.h" +#include "cforum.h" static char * strdupn(const unsigned char *); @@ -1,41 +0,0 @@ -#include <sqlite3.h> - -sqlite3 *db; - -struct att{ - int id; - int post; - int bytes; /* Size of data. */ - char *name; - char *desc; - char *mime; - char *data; -}; - -struct post{ - int id; - int parent; - int user; - int created; - int edited; - char *subject; - char *text; -}; - -struct user{ - int id; - int created; - char *name; - char *full; - char *hash; -}; - -int addatt(struct att *); -int adduser(struct user *); -struct att *getatt(sqlite3_stmt *); -struct post *getpost(sqlite3_stmt *); -struct user *getuser(sqlite3_stmt *); -struct att *nextatt(sqlite3_stmt *); -struct post *nextpost(sqlite3_stmt *); -struct user *nextuser(sqlite3_stmt *); -sqlite3_stmt *selectbyint(char *, char *, int);
\ No newline at end of file @@ -1,4 +1,5 @@ #include <stdio.h> +#include "cforum.h" void srverr(char *err) @@ -1 +0,0 @@ -void srverr(char *);
\ No newline at end of file @@ -2,7 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "query.h" +#include "cforum.h" /* * Return an allocated string containing the next parameter ("key=value"). diff --git a/query.h b/query.h deleted file mode 100644 index d9c7ac9..0000000 --- a/query.h +++ /dev/null @@ -1,17 +0,0 @@ -#define TRUNCATED(s) s[-1] - -struct query{ - int method; - int length; /* Content length. */ - char *string; -} query; - -enum method{ - GET, - POST -}; - -char *nextparam(enum method, int *, int); -void setquery(void); -char *split(char *); -int urldecode(char *, int);
\ No newline at end of file @@ -1,13 +0,0 @@ -/* Maximum allowed Content-Length for various forms. */ -#define MAXATTDATA 4096 -#define MAXUSERDATA 512 -#define MAXPOSTDATA 4096 - -/* Maximum size of user information, incl. NUL. */ -#define MAXUSERNAME 40 -#define MAXUSERFULL 128 -#define MAXUSERPASS 128 - -struct site{ - char *name; -} site;
\ No newline at end of file |