diff options
author | John Ankarström <john@ankarstrom.se> | 2021-09-19 15:02:28 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-09-19 15:09:47 +0200 |
commit | 93c1df59ef14348e9a3e1d66ea0b96960f5b5732 (patch) | |
tree | 19c325492173e2bc602b5a8c116471e274e19068 | |
parent | 53569c91e4ebdbba96e6286f846dead1d427e6e2 (diff) | |
download | cforum-93c1df59ef14348e9a3e1d66ea0b96960f5b5732.tar.gz |
Fix ISVIS, parse database error
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | ctl.c | 17 |
2 files changed, 13 insertions, 8 deletions
@@ -9,7 +9,7 @@ It is also rather small: wc -l *.c *.h */*.t */*.lex 96 cforum.c - 296 ctl.c + 301 ctl.c 268 db.c 11 err.c 144 query.c @@ -22,4 +22,4 @@ It is also rather small: 28 t/post.t 12 t/user.t 95 mktpl/mktpl.lex - 1132 total + 1137 total @@ -5,6 +5,8 @@ #include <time.h> #include "cforum.h" +#define MAXMSG 256 + /* Print UNIX timestamp as written date. */ void printdate(int timestamp) @@ -51,8 +53,8 @@ newpost() void newuser() { -#define MAXMSG 256 - char *captcha, *confirm, *hlite, msg[MAXMSG], *name, *full, *p, *pass, *v; + char *captcha, *confirm, *name, *full, *pass; + char *hlite, msg[MAXMSG], *p, *v; char title[] = "New User"; int i; struct user *user; @@ -123,12 +125,12 @@ newuser() goto err; } -#define ISVIS(c) ((unsigned int)c >= 20) +#define ISVIS(c) ((unsigned char)c >= 32) #define ISALNUM(c) (c>='A' && c<='Z' || c>='a' && c<='z' || c>='0' && c<='9') /* Constrain character sets. */ for(i = 0; name[i]; i++) - if(!ISVIS(name[i]) || !(name[i] == '_' || ISALNUM(name[i]))){ + if(!name[i] == '_' && !ISALNUM(name[i])){ hlite = strdup("name"); snprintf(msg, MAXMSG, "Username may only contain ASCII letters, " @@ -174,8 +176,11 @@ newuser() user->hash = pass; /* TODO */ if(!adduser(user)){ - snprintf(msg, MAXMSG, "Could not add user to database: %s", - sqlite3_errmsg(db)); + if(strcmp(sqlite3_errmsg(db), "column name is not unique")==0) + snprintf(msg, MAXMSG, "Username already exists."); + else + snprintf(msg, MAXMSG, "Could not create user: %s. ", + sqlite3_errmsg(db)); goto err; } |