From 93c1df59ef14348e9a3e1d66ea0b96960f5b5732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 19 Sep 2021 15:02:28 +0200 Subject: Fix ISVIS, parse database error --- README | 4 ++-- ctl.c | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README b/README index 9a80f3c..7f982fa 100644 --- a/README +++ b/README @@ -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 diff --git a/ctl.c b/ctl.c index 2bda5a7..58db942 100644 --- a/ctl.c +++ b/ctl.c @@ -5,6 +5,8 @@ #include #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; } -- cgit v1.2.3