From a259082692bc9dcd33b583b98954ae5240c4776a Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Mon, 11 Sep 2017 16:10:38 +1000 Subject: [PATCH] Add option to enable / disable external editor --- bbs.h | 1 + magicka.strings | 1 + mail_menu.c | 10 +++++++--- settings.c | 23 ++++++++++++++++++++++- users.c | 15 ++++++++++----- utils/sql_update/users_sql_update.pl | 22 +++++++++++++++++++++- 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/bbs.h b/bbs.h index 1400dbf..9183b5a 100644 --- a/bbs.h +++ b/bbs.h @@ -203,6 +203,7 @@ struct user_record { int defprotocol; int nodemsgs; int codepage; + int exteditor; }; struct jam_msg { diff --git a/magicka.strings b/magicka.strings index e34e677..44d683f 100644 --- a/magicka.strings +++ b/magicka.strings @@ -220,3 +220,4 @@ File exists!\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 +\e[0;36mE. \e[1;37mUse External Editor (\e[1;33m%s\e[1;37m)\r\n diff --git a/mail_menu.c b/mail_menu.c index 1e6b072..42b8341 100644 --- a/mail_menu.c +++ b/mail_menu.c @@ -366,9 +366,13 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot - if (conf.external_editor_cmd != NULL) { - s_printf(get_string(85)); - c = s_getc(); + if (conf.external_editor_cmd != NULL && user->exteditor != 0) { + if (user->exteditor == 2) { + s_printf(get_string(85)); + c = s_getc(); + } else { + c = 'y'; + } if (tolower(c) == 'y') { sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); diff --git a/settings.c b/settings.c index 314a198..7492c0d 100644 --- a/settings.c +++ b/settings.c @@ -23,6 +23,18 @@ void settings_menu(struct user_record *user) { 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")); + switch (user->exteditor) { + case 0: + sprintf(buffer, "NO"); + break; + case 1: + sprintf(buffer, "YES"); + break; + case 2: + sprintf(buffer, "ASK"); + break; + } + s_printf(get_string(222), buffer); s_printf(get_string(153)); s_printf(get_string(154)); @@ -124,7 +136,16 @@ void settings_menu(struct user_record *user) { user->codepage = !user->codepage; save_user(user); } - break; + break; + case 'e': + { + user->exteditor++; + if (user->exteditor == 3) { + user->exteditor = 0; + } + save_user(user); + } + break; case 'q': dosettings = 1; break; diff --git a/users.c b/users.c index 5db48d3..bfbe7a3 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=?,codepage=? 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=?,exteditor=? where loginname LIKE ?"; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -116,7 +116,8 @@ sqlite3_busy_timeout(db, 5000); sqlite3_bind_int(res, 17, user->defprotocol); sqlite3_bind_int(res, 18, user->nodemsgs); sqlite3_bind_int(res, 19, user->codepage); - sqlite3_bind_text(res, 20, user->loginname, -1, 0); + sqlite3_bind_int(res, 20, user->exteditor); + sqlite3_bind_text(res, 21, user->loginname, -1, 0); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } @@ -161,10 +162,11 @@ int inst_user(struct user_record *user) { "archiver INTEGER," "protocol INTEGER," "nodemsgs INTEGER," - "codepage INTEGER);"; + "codepage INTEGER," + "exteditor 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, codepage) 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, exteditor) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; char *err_msg = 0; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -212,6 +214,7 @@ sqlite3_busy_timeout(db, 5000); sqlite3_bind_int(res, 18, user->defprotocol); sqlite3_bind_int(res, 19, user->nodemsgs); sqlite3_bind_int(res, 20, user->codepage); + sqlite3_bind_int(res, 21, user->exteditor); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } @@ -239,7 +242,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, codepage 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, exteditor FROM users WHERE loginname LIKE ?"; char *pass_hash; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -288,6 +291,7 @@ struct user_record *check_user_pass(char *loginname, char *password) { user->defprotocol = sqlite3_column_int(res, 18); user->nodemsgs = sqlite3_column_int(res, 19); user->codepage = sqlite3_column_int(res, 20); + user->exteditor = sqlite3_column_int(res, 21); pass_hash = hash_sha256(password, user->salt); if (strcmp(pass_hash, user->password) != 0) { @@ -573,6 +577,7 @@ struct user_record *new_user() { user->defarchiver = 1; user->nodemsgs = 1; user->codepage = conf.codepage; + user->exteditor = 2; inst_user(user); return user; diff --git a/utils/sql_update/users_sql_update.pl b/utils/sql_update/users_sql_update.pl index 2a025bf..83a0be4 100755 --- a/utils/sql_update/users_sql_update.pl +++ b/utils/sql_update/users_sql_update.pl @@ -135,4 +135,24 @@ if (check_exists("codepage") == 0) { my $sql = "ALTER TABLE users ADD COLUMN codepage INTEGER DEFAULT 0"; $dbh->do($sql); $dbh->disconnect; -} \ No newline at end of file +} + +if (check_exists("exteditor") == 0) { + print "Column \"exteditor\" doesn't exist... adding..\n"; + + my ($needed) = @_; + + my $dsn = "dbi:SQLite:dbname=$dbfile"; + my $user = ""; + my $password = ""; + my $dbh = DBI->connect($dsn, $user, $password, { + PrintError => 0, + RaiseError => 1, + AutoCommit => 1, + FetchHashKeyName => 'NAME_lc', + }); + + my $sql = "ALTER TABLE users ADD COLUMN exteditor INTEGER DEFAULT 2"; + $dbh->do($sql); + $dbh->disconnect; +}