AmendHub

Download:

jcs

/

subtext

/

amendments

/

361

db: Add timezone UTC offset setting, tweak fidonet fields


jcs made amendment 361 about 1 year ago
--- db.c Thu Mar 2 17:38:42 2023 +++ db.c Mon Mar 6 16:35:28 2023 @@ -40,6 +40,9 @@ struct struct_field config_fields[] = { { "Timezone (Abbrev)", CONFIG_TYPE_STRING, offsetof(struct config, timezone), 1, member_size(struct config, timezone) }, + { "Timezone (UTC Offset)", CONFIG_TYPE_SHORT, + offsetof(struct config, timezone_utcoff), + -1200, 1400 }, { "Allow Open Signup", CONFIG_TYPE_BOOLEAN, offsetof(struct config, open_signup), 0, 0 }, @@ -90,15 +93,21 @@ struct struct_field config_fields[] = { offsetof(struct config, session_log_days), 1, USHRT_MAX }, - { "FidoNet Binkp Hub Hostname", CONFIG_TYPE_STRING, + { "FidoNet Local Node Address", CONFIG_TYPE_STRING, + offsetof(struct config, fidonet_node_addr), + 0, member_size(struct config, fidonet_node_addr) }, + { "FidoNet Hub Address", CONFIG_TYPE_STRING, + offsetof(struct config, fidonet_hub_addr), + 0, member_size(struct config, fidonet_hub_addr) }, + { "FidoNet Hub Packet Password", CONFIG_TYPE_PASSWORD, + offsetof(struct config, fidonet_pkt_password), + 0, member_size(struct config, fidonet_pkt_password) }, + { "FidoNet Binkp Hostname", CONFIG_TYPE_STRING, offsetof(struct config, binkp_hostname), 0, member_size(struct config, binkp_hostname) }, - { "FidoNet Binkp Hub Port", CONFIG_TYPE_SHORT, + { "FidoNet Binkp Port", CONFIG_TYPE_SHORT, offsetof(struct config, binkp_port), 0, 65535 }, - { "FidoNet Binkp Node Address", CONFIG_TYPE_STRING, - offsetof(struct config, binkp_node_addr), - 0, member_size(struct config, binkp_node_addr) }, { "FidoNet Binkp Password", CONFIG_TYPE_PASSWORD, offsetof(struct config, binkp_password), 0, member_size(struct config, binkp_password) }, @@ -332,8 +341,6 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa sprintf(tdb->config.location, "Springfield"); sprintf(tdb->config.hostname, "bbs.example.com"); sprintf(tdb->config.timezone, "CT"); - tdb->config.telnet_port = 0; - tdb->config.modem_port = 0; tdb->config.modem_speed = 9600; sprintf(tdb->config.modem_init, "ATQ0V1S0=2"); sprintf(tdb->config.modem_parity, "8N1"); @@ -344,7 +351,6 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa tdb->config.session_log_days = 21; tdb->config.binkp_port = 24554; tdb->config.binkp_interval_seconds = (60 * 60 * 3); - tdb->config.binkp_delete_done = 0; db_config_save(tdb); /* create a default sysop user */ @@ -576,15 +582,17 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa break; } case 12: { - /* 12->13, added binkp fields */ + /* 12->13, added fidonet/binkp fields */ struct config new_config = { 0 }; bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); - + + new_config.fidonet_node_addr[0] = '\0'; + new_config.fidonet_hub_addr[0] = '\0'; + new_config.fidonet_pkt_password[0] = '\0'; new_config.binkp_hostname[0] = '\0'; new_config.binkp_port = 24554; - new_config.binkp_node_addr[0] = '\0'; new_config.binkp_password[0] = '\0'; new_config.binkp_interval_seconds = (60 * 60 * 3); new_config.binkp_delete_done = 0; @@ -594,11 +602,11 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa break; } case 13: { - /* 13->14, move mail to separate db */ + /* 13->14, move mail to separate db, add fidonet fields */ Str255 newfullpath; struct bile *mail_bile; - struct bile_object *o; - size_t n, size, id; + size_t nids, n, size, id; + unsigned long *ids; char *data; memcpy(newfullpath, fullpath, sizeof(newfullpath)); @@ -611,27 +619,30 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa if (mail_bile == NULL) panic("Couldn't create %s: %d", PtoCstr(newfullpath), bile_error(NULL)); - - for (n = 0; (o = bile_get_nth_of_type(tdb->bile, n, - MAIL_SPOOL_MESSAGE_RTYPE)); n++) { - progress("Copying mail message %ld...", o->id); - size = bile_read_alloc(tdb->bile, o->type, o->id, - &data); - bile_write(mail_bile, o->type, o->id, data, size); - + + nids = bile_ids_by_type(tdb->bile, MAIL_SPOOL_MESSAGE_RTYPE, + &ids); + for (n = 0; n < nids; n++) { + progress("Copying mail message %ld...", ids[n]); + size = bile_read_alloc(tdb->bile, MAIL_SPOOL_MESSAGE_RTYPE, + ids[n], &data); + bile_write(mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, ids[n], + data, size); xfree(&data); - xfree(&o); + + size += (sizeof(struct mail_message) - + offsetof(struct mail_message, fidonet_msgid)); + if (bile_resize(mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, + ids[n], size) != size) + panic("failed resizing message %ld", ids[n]); } bile_flush(mail_bile, true); /* now we can actually delete mail */ - while ((o = bile_get_nth_of_type(tdb->bile, 0, - MAIL_SPOOL_MESSAGE_RTYPE))) { - id = o->id; - xfree(&o); - progress("Deleting old mail message %ld...", id); - bile_delete(tdb->bile, MAIL_SPOOL_MESSAGE_RTYPE, id, 0); + for (n = 0; n < nids; n++) { + progress("Deleting old mail message %ld...", ids[n]); + bile_delete(tdb->bile, MAIL_SPOOL_MESSAGE_RTYPE, ids[n], 0); } bile_write_map(tdb->bile); bile_close(mail_bile); @@ -647,7 +658,7 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa grow = member_size(struct board, fidonet_area); - nids = bile_sorted_ids_by_type(tdb->bile, DB_BOARD_RTYPE, &ids); + nids = bile_ids_by_type(tdb->bile, DB_BOARD_RTYPE, &ids); for (n = 0; n < nids; n++) { o = bile_find(tdb->bile, DB_BOARD_RTYPE, ids[n]); progress("Growing board %ld/%ld...", n + 1, nids); @@ -663,46 +674,16 @@ db_migrate(struct db *tdb, short is_new, Str255 fullpa break; } case 15: { - /* 15->16, mail gets fido fields */ - Str255 newfullpath; - struct bile *mail_bile; - struct bile_object *o; - struct mail_message mail; - size_t nids, n, size; - unsigned long *ids; - char *data; - - memcpy(newfullpath, fullpath, sizeof(newfullpath)); - PtoCstr(newfullpath); - strlcat((char *)&newfullpath, "-mail", sizeof(newfullpath)); - CtoPstr(newfullpath); + /* 15->16, timezone UTC offset */ + struct config new_config = { 0 }; - mail_bile = bile_open(newfullpath, tdb->bile->vrefnum); - if (mail_bile == NULL) - /* no mail here, no problem */ - break; + bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, + sizeof(new_config)); + + new_config.timezone_utcoff = 0; - nids = bile_ids_by_type(mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, - &ids); - if (ids == NULL) { - bile_close(mail_bile); - break; - } - for (n = 0; n < nids; n++) { - o = bile_find(mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, ids[n]); - if (!o) - panic("can't find message %ld but it's in ids", - ids[n]); - progress("Growing mail message %ld/%ld...", n + 1, nids); - size = o->size + - (sizeof(struct mail_message) - - offsetof(struct mail_message, fidonet_msgid)); - if (bile_resize(mail_bile, o->type, o->id, size) != size) - panic("failed resizing message %ld", o->id); - xfree(&o); - } - xfree(&ids); - bile_close(mail_bile); + bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, + sizeof(new_config)); break; } } --- db.h Thu Mar 2 15:37:19 2023 +++ db.h Mon Mar 6 16:34:35 2023 @@ -88,12 +88,15 @@ struct config { unsigned short trusted_proxy_udp_port; short session_log_days; char modem_parity[4]; + char fidonet_node_addr[32]; + char fidonet_hub_addr[32]; + char fidonet_pkt_password[9]; char binkp_hostname[64]; - char binkp_node_addr[32]; unsigned short binkp_port; char binkp_password[32]; unsigned long binkp_interval_seconds; short binkp_delete_done; + short timezone_utcoff; }; extern struct struct_field config_fields[];