AmendHub

Download:

jcs

/

subtext

/

amendments

/

510

db: Add location field to session{,_log}, ipdb db path to config


jcs made amendment 510 10 months ago
--- db.c Sat Apr 8 22:50:43 2023 +++ db.c Thu Jun 15 10:22:32 2023 @@ -61,6 +61,9 @@ struct struct_field config_fields[] = { { "Telnet Trusted Proxy UDP Port", CONFIG_TYPE_SHORT, offsetof(struct config, trusted_proxy_udp_port), 0, 65535 }, + { "IP Geolocation Database Path", CONFIG_TYPE_STRING, + offsetof(struct config, ipdb_path), + 0, member_size(struct config, ipdb_path) }, { "Modem Port", CONFIG_TYPE_SHORT, offsetof(struct config, modem_port), @@ -724,6 +727,49 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, sizeof(new_config)); + break; + } + case 18: { + /* 18->19, ipdb_path, add session_log.location */ + struct config new_config = { 0 }; + Str255 newfullpath; + struct bile *sessions_bile; + size_t nids, n, size; + unsigned long *ids; + char *data; + + bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, + sizeof(new_config)); + + new_config.ipdb_path[0] = '\0'; + + bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, + sizeof(new_config)); + + /* migrate session log entries */ + memcpy(&newfullpath, fullpath, sizeof(newfullpath)); + PtoCstr(newfullpath); + strlcat((char *)&newfullpath, "-sessions", sizeof(newfullpath)); + CtoPstr(newfullpath); + + sessions_bile = bile_open(newfullpath, tdb->bile->vrefnum); + if (sessions_bile == NULL) + /* nothing to migrate */ + break; + + nids = bile_ids_by_type(sessions_bile, SL_LOG_RTYPE, &ids); + for (n = 0; n < nids; n++) { + size = bile_read_alloc(sessions_bile, SL_LOG_RTYPE, + ids[n], &data); + size += member_size(struct session_log, location); + if (bile_resize(sessions_bile, SL_LOG_RTYPE, + ids[n], size) != size) + panic("failed resizing session log %ld", ids[n]); + } + + bile_flush(sessions_bile, true); + xfree(&ids); + bile_close(sessions_bile); break; } } --- db.h Sat Apr 8 22:46:01 2023 +++ db.h Wed Jun 14 17:49:15 2023 @@ -19,7 +19,7 @@ #include <time.h> -#define DB_CUR_VERS 18 +#define DB_CUR_VERS 19 #define SUBTEXT_CREATOR 'SUBT' #define DB_TYPE 'STDB' @@ -69,6 +69,7 @@ #include "bile.h" #include "board.h" #include "folder.h" +#include "ipdb.h" #include "settings.h" struct config { @@ -103,6 +104,7 @@ struct config { short mail_prune_days; unsigned long ftn_max_tossed_message_size; short max_sysop_idle_minutes; + char ipdb_path[255]; }; extern struct struct_field config_fields[]; @@ -120,6 +122,7 @@ struct db { struct folder *folders; short nfolders; struct bile *mail_bile; + struct ipdb_file *ipdb; }; struct db * db_open(Str255 file, short vrefnum); --- session.h Thu Apr 27 09:09:23 2023 +++ session.h Wed Jun 14 16:48:55 2023 @@ -64,11 +64,13 @@ struct session_log { unsigned long logged_off_at; unsigned long ip_address; unsigned short tspeed; + char location[32]; }; struct session { char node[16]; char via[16]; + char location[32]; unsigned char obuf[768]; unsigned long obuf_canary; unsigned char ibuf[512];