aboutsummaryrefslogtreecommitdiff
path: root/cforum.c
diff options
context:
space:
mode:
Diffstat (limited to 'cforum.c')
-rw-r--r--cforum.c36
1 files changed, 12 insertions, 24 deletions
diff --git a/cforum.c b/cforum.c
index 900465a..feee431 100644
--- a/cforum.c
+++ b/cforum.c
@@ -15,10 +15,9 @@
int
main(int argc, char *argv[])
{
- char msg[MAXMSG], *p, *v;
+ char msg[MAXMSG], *new, *p, *v;
int attid, postid, userid;
sqlite3_stmt *stmt;
- struct att *att;
/*
* The database is opened or a server error is generated.
@@ -60,21 +59,6 @@ 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.
*/
@@ -87,15 +71,14 @@ main(int argc, char *argv[])
}
/* Parse query string. */
+ new = NULL;
attid = postid = userid = 0;
while(p = nextparam(GET, 128)){
v = split(p);
- if(!attid && strcmp(p, "att") == 0)
- attid = atoi(v);
- else if(!postid && strcmp(p, "post") == 0)
- postid = atoi(v);
- else if(!userid && strcmp(p, "user") == 0)
- userid = atoi(v);
+ if(!attid && strcmp(p, "att") == 0) attid = atoi(v);
+ else if(!postid && strcmp(p, "post") == 0) postid = atoi(v);
+ else if(!userid && strcmp(p, "user") == 0) userid = atoi(v);
+ else if(!new && strcmp(p, "new") == 0) new = strdup(v);
}
/* Handle request. */
@@ -105,7 +88,12 @@ main(int argc, char *argv[])
showpost(postid);
else if(userid)
showuser(userid);
- else
+ else if(new){
+ if(strcmp(v, "att") == 0) newatt();
+ else if(strcmp(v, "post") == 0) newpost();
+ else if(strcmp(v, "user") == 0) newuser();
+ /* else bad request */
+ }else
showfront();
end: