From 8b611fc3febd84809f39f1710ea9eac1662cb1ea Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 23 Apr 2017 12:28:01 +1000 Subject: [PATCH] More work on utf8 --- bbs.c | 3 +++ bbs.h | 1 + files.c | 4 ++-- magicka.strings | 1 + settings.c | 7 +++++++ users.c | 15 ++++++++++----- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bbs.c b/bbs.c index 2912c4c..2c387ae 100644 --- a/bbs.c +++ b/bbs.c @@ -210,6 +210,9 @@ void s_printf(char *fmt, ...) { } int should_convert_utf8() { + if (gUser != NULL) { + return gUser->codepage; + } return conf.codepage; } diff --git a/bbs.h b/bbs.h index 58ab727..07e14d0 100644 --- a/bbs.h +++ b/bbs.h @@ -202,6 +202,7 @@ struct user_record { int defarchiver; int defprotocol; int nodemsgs; + int codepage; }; struct jam_msg { diff --git a/files.c b/files.c index d10fe62..c30e96b 100644 --- a/files.c +++ b/files.c @@ -443,7 +443,7 @@ int do_download(struct user_record *user, char *file) { free(arguments); } - + return 1; } int do_upload(struct user_record *user, char *final_path) { @@ -571,7 +571,7 @@ int do_upload(struct user_record *user, char *final_path) { } while ((dent = readdir(inb)) != NULL) { if (dent->d_type == DT_REG) { - snprintf(upload_command, 1-24, "%s%s", upload_path, dent->d_name); + snprintf(upload_command, 1024, "%s%s", upload_path, dent->d_name); snprintf(upload_filename, 1024, "%s/%s", final_path, dent->d_name); if (stat(upload_filename, &s) == 0) { diff --git a/magicka.strings b/magicka.strings index 7e089d4..e34e677 100644 --- a/magicka.strings +++ b/magicka.strings @@ -219,3 +219,4 @@ File exists!\r\n \r\n\e[1;31mInvalid Node!\e[0m\r\n \r\n\e[1;37mEnter your message (256 chars max)...\e[0m\r\n %s on node %d says:\r\n %s\r\n\r\n +\e[0;36mC. \e[1;37mCodepage (\e[1;33m%s\e[1;37m)\r\n diff --git a/settings.c b/settings.c index daf4867..314a198 100644 --- a/settings.c +++ b/settings.c @@ -22,6 +22,7 @@ void settings_menu(struct user_record *user) { s_printf(get_string(205), conf.archivers[user->defarchiver - 1]->name); s_printf(get_string(213), conf.protocols[user->defprotocol - 1]->name); s_printf(get_string(215), (user->nodemsgs ? "TRUE" : "FALSE")); + s_printf(get_string(221), (user->codepage ? "UTF-8" : "CP437")); s_printf(get_string(153)); s_printf(get_string(154)); @@ -118,6 +119,12 @@ void settings_menu(struct user_record *user) { save_user(user); } break; + case 'c': + { + user->codepage = !user->codepage; + save_user(user); + } + break; case 'q': dosettings = 1; break; diff --git a/users.c b/users.c index 06e0c09..5db48d3 100644 --- a/users.c +++ b/users.c @@ -81,7 +81,7 @@ int save_user(struct user_record *user) { int rc; char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," - "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=? where loginname LIKE ?"; + "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=? where loginname LIKE ?"; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -115,7 +115,8 @@ sqlite3_busy_timeout(db, 5000); sqlite3_bind_int(res, 16, user->defarchiver); sqlite3_bind_int(res, 17, user->defprotocol); sqlite3_bind_int(res, 18, user->nodemsgs); - sqlite3_bind_text(res, 19, user->loginname, -1, 0); + sqlite3_bind_int(res, 19, user->codepage); + sqlite3_bind_text(res, 20, user->loginname, -1, 0); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } @@ -159,10 +160,11 @@ int inst_user(struct user_record *user) { "bwavepktno INTEGER," "archiver INTEGER," "protocol INTEGER," - "nodemsgs INTEGER);"; + "nodemsgs INTEGER," + "codepage INTEGER);"; char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname," - "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; char *err_msg = 0; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -209,6 +211,7 @@ sqlite3_busy_timeout(db, 5000); sqlite3_bind_int(res, 17, user->defarchiver); sqlite3_bind_int(res, 18, user->defprotocol); sqlite3_bind_int(res, 19, user->nodemsgs); + sqlite3_bind_int(res, 20, user->codepage); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } @@ -236,7 +239,7 @@ struct user_record *check_user_pass(char *loginname, char *password) { sqlite3_stmt *res; int rc; char *sql = "SELECT Id, loginname, password, salt, firstname," - "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs FROM users WHERE loginname LIKE ?"; + "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage FROM users WHERE loginname LIKE ?"; char *pass_hash; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -284,6 +287,7 @@ struct user_record *check_user_pass(char *loginname, char *password) { user->defarchiver = sqlite3_column_int(res, 17); user->defprotocol = sqlite3_column_int(res, 18); user->nodemsgs = sqlite3_column_int(res, 19); + user->codepage = sqlite3_column_int(res, 20); pass_hash = hash_sha256(password, user->salt); if (strcmp(pass_hash, user->password) != 0) { @@ -568,6 +572,7 @@ struct user_record *new_user() { user->defprotocol = 1; user->defarchiver = 1; user->nodemsgs = 1; + user->codepage = conf.codepage; inst_user(user); return user;