diff --git a/src/GNUmakefile.common b/src/GNUmakefile.common index c1961ff..8b16f71 100644 --- a/src/GNUmakefile.common +++ b/src/GNUmakefile.common @@ -50,7 +50,7 @@ ${UUID}: ${CUTEST}: cd ${DEPSDIR}/cutest-1.5 && make -HDRS:= bbs.h +HDRS:= bbs.h bluewave.h mail_utils.h OBJS:= inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o \ doors.o bbs_list.o chat_system.o email.o files.o settings.o \ lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o \ diff --git a/src/bbs.h b/src/bbs.h index 7a04af7..1e51fab 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -46,6 +46,14 @@ #define IAC_SUPPRESS_GO_AHEAD 3 #define IAC_ECHO 1 +struct ptr_vector { + size_t len; + size_t capacity; + void **ptrs; +}; + +static const struct ptr_vector EMPTY_PTR_VECTOR = {0, 0, NULL}; + struct fido_addr { unsigned short zone; unsigned short net; @@ -91,8 +99,7 @@ struct mail_conference { int nettype; int realnames; int sec_level; - int mail_area_count; - struct mail_area **mail_areas; + struct ptr_vector mail_areas; struct fido_addr *fidoaddr; int maginode; }; @@ -110,8 +117,7 @@ struct file_directory { char *path; int sec_level; int display_on_web; - int file_sub_count; - struct file_sub **file_subs; + struct ptr_vector file_subs; }; struct archiver { @@ -194,21 +200,15 @@ struct bbs_config { int ipguard_timeout; int ipguard_tries; - int mail_conference_count; - struct mail_conference **mail_conferences; - int door_count; - struct door_config **doors; - int file_directory_count; - struct file_directory **file_directories; - int text_file_count; - struct text_file **text_files; + struct ptr_vector mail_conferences; + struct ptr_vector doors; + struct ptr_vector file_directories; + struct ptr_vector text_files; char *config_path; - int archiver_count; - struct archiver **archivers; + struct ptr_vector archivers; - int protocol_count; - struct protocol **protocols; + struct ptr_vector protocols; }; struct sec_level_t { @@ -268,14 +268,6 @@ struct blog_entry_t { time_t date; }; -struct ptr_vector { - size_t len; - size_t capacity; - void **ptrs; -}; - -static const struct ptr_vector EMPTY_PTR_VECTOR = {0, 0, NULL}; - extern void init_ptr_vector(struct ptr_vector *vec); extern void ptr_vector_clear(struct ptr_vector *vec); extern void *ptr_vector_get(struct ptr_vector *vec, size_t i); diff --git a/src/bluewave.c b/src/bluewave.c index 55da216..f791e2f 100644 --- a/src/bluewave.c +++ b/src/bluewave.c @@ -6,11 +6,14 @@ #include #include #include -#include "bluewave.h" + #include "jamlib/jam.h" -#include "bbs.h" #include "libuuid/uuid.h" +#include "bluewave.h" +#include "bbs.h" +#include "mail_utils.h" + extern struct bbs_config conf; extern struct user_record *gUser; extern int mynode; @@ -158,24 +161,24 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file return totmsgs; } - jb = open_jam_base(conf.mail_conferences[confr]->mail_areas[area]->path); + struct mail_area *ma = get_area(confr, area); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[confr]->mail_areas[area]->path); + dolog("Error opening JAM base.. %s", ma->path); if (msghs != NULL) { free_message_headers(msghs); } return totmsgs; - } else { - all_unread = 0; - if (JAM_ReadLastRead(jb, gUser->id, &jlr) == JAM_NO_USER) { - jlr.LastReadMsg = 0; - jlr.HighReadMsg = 0; - jlr.UserCRC = JAM_Crc32(gUser->loginname, strlen(gUser->loginname)); - jlr.UserID = gUser->id; - all_unread = 1; - } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { - all_unread = 1; - } + } + all_unread = 0; + if (JAM_ReadLastRead(jb, gUser->id, &jlr) == JAM_NO_USER) { + jlr.LastReadMsg = 0; + jlr.HighReadMsg = 0; + jlr.UserCRC = JAM_Crc32(gUser->loginname, strlen(gUser->loginname)); + jlr.UserID = gUser->id; + all_unread = 1; + } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { + all_unread = 1; } if (all_unread == 0) { @@ -299,7 +302,6 @@ void bwave_create_packet() { int area_count; tWORD flags; int lasttot; - int bpos; int last_ptr = 0; int stout; int stin; @@ -323,8 +325,9 @@ void bwave_create_packet() { init_ptr_vector(&areas); - for (i = 0; i < conf.mail_conference_count; i++) { - for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { + for (size_t i = 0; i < ptr_vector_len(&conf.mail_conferences); i++) { + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, i); + for (size_t j = 0; j < ptr_vector_len(&mc->mail_areas); j++) { if (msgbase_is_subscribed(i, j)) { tot_areas++; } @@ -361,27 +364,27 @@ void bwave_create_packet() { hdr.subject_len = 71; memcpy(hdr.packet_id, conf.bwave_name, strlen(conf.bwave_name)); - snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/", conf.bbs_path, mynode); if (stat(buffer, &s) == 0) { recursive_delete(buffer); } mkdir(buffer, 0755); - snprintf(buffer, 1024, "%s/node%d/bwave/%s.FTI", conf.bbs_path, mynode, conf.bwave_name); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/%s.FTI", conf.bbs_path, mynode, conf.bwave_name); fti_file = fopen(buffer, "wb"); - snprintf(buffer, 1024, "%s/node%d/bwave/%s.MIX", conf.bbs_path, mynode, conf.bwave_name); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/%s.MIX", conf.bbs_path, mynode, conf.bwave_name); mix_file = fopen(buffer, "wb"); - snprintf(buffer, 1024, "%s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name); dat_file = fopen(buffer, "wb"); s_printf("\r\n"); @@ -408,42 +411,41 @@ void bwave_create_packet() { area_count++; if (totmsgs < conf.bwave_max_msgs) { - - for (i = 0; i < conf.mail_conference_count; i++) { - for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { - if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level <= gUser->sec_level && conf.mail_conferences[i]->mail_areas[j]->qwkname != NULL && msgbase_is_subscribed(i, j)) { + for (size_t i = 0; i < ptr_vector_len(&conf.mail_conferences); i++) { + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, i); + for (size_t j = 0; j < ptr_vector_len(&mc->mail_areas); j++) { + struct mail_area *ma = get_area(i, j); + if (ma->read_sec_level <= gUser->sec_level && ma->qwkname != NULL && msgbase_is_subscribed(i, j)) { lasttot = totmsgs; totmsgs = bwave_scan_area(i, j, area_count + 1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); - s_printf(get_string(195), conf.mail_conferences[i]->name, conf.mail_conferences[i]->mail_areas[j]->name, totmsgs - lasttot); + s_printf(get_string(195), mc->name, ma->name, totmsgs - lasttot); //if (lasttot == totmsgs) { // continue; //} - flags = 0; area = (INF_AREA_INFO *)malloz(sizeof(INF_AREA_INFO)); snprintf(area->areanum, sizeof area->areanum, "%d", area_count + 1); + strlcpy(area->echotag, ma->qwkname, sizeof area->echotag); + strlcpy(area->title, ma->name, sizeof area->title); - strlcpy(area->echotag, conf.mail_conferences[i]->mail_areas[j]->qwkname, sizeof area->echotag); - - strlcpy(area->title, conf.mail_conferences[i]->mail_areas[j]->name, sizeof area->title); - - if (conf.mail_conferences[i]->mail_areas[j]->write_sec_level <= gUser->sec_level) { + flags = 0; + if (ma->write_sec_level <= gUser->sec_level) { flags |= INF_POST; } - if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { flags |= INF_NO_PUBLIC; flags |= INF_NETMAIL; flags |= INF_ECHO; } - if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { flags |= INF_NO_PRIVATE; flags |= INF_ECHO; } - if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_LOCAL_AREA) { + if (ma->type == TYPE_LOCAL_AREA) { flags |= INF_NO_PRIVATE; } @@ -485,7 +487,6 @@ void bwave_create_packet() { if (totmsgs > 0) { // create archive - bpos = 0; if (gUser->bwavestyle) { thetime = time(NULL); localtime_r(&thetime, &time_tm); @@ -494,29 +495,41 @@ void bwave_create_packet() { gUser->bwavepktno = time_tm.tm_wday * 10; } - snprintf(archive, 1024, "%s/node%d/%s.%s%d", conf.bbs_path, mynode, conf.bwave_name, weekday[time_tm.tm_wday], gUser->bwavepktno % 10); + snprintf(archive, sizeof archive, "%s/node%d/%s.%s%d", + conf.bbs_path, mynode, conf.bwave_name, weekday[time_tm.tm_wday], gUser->bwavepktno % 10); } else { - snprintf(archive, 1024, "%s/node%d/%s.%03d", conf.bbs_path, mynode, conf.bwave_name, gUser->bwavepktno); + snprintf(archive, sizeof archive, "%s/node%d/%s.%03d", conf.bbs_path, mynode, conf.bwave_name, gUser->bwavepktno); } - for (i = 0; i < strlen(conf.archivers[gUser->defarchiver - 1]->pack); i++) { - if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') { - i++; - if (conf.archivers[gUser->defarchiver - 1]->pack[i] == 'a') { - sprintf(&buffer[bpos], "%s", archive); - bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver - 1]->pack[i] == 'f') { - sprintf(&buffer[bpos], "%s/node%d/bwave/%s.INF %s/node%d/bwave/%s.MIX %s/node%d/bwave/%s.FTI %s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name); - bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver - 1]->pack[i] == '*') { - buffer[bpos++] = '*'; - buffer[bpos] = '\0'; - } - } else { - buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->pack[i]; - buffer[bpos] = '\0'; + struct archiver *arc = ptr_vector_get(&conf.archivers, gUser->defarchiver - 1); + assert(arc != NULL); + char *b = buffer; + size_t blen = sizeof buffer; + for (const char *p = arc->pack; *p != '\0' && blen >= 1; ++p) { + if (*p != '*') { + *b++ = *p; + --blen; + continue; } + p++; + size_t alen = 0; + if (*p == 'a') { + strlcpy(b, archive, blen); + alen = strlen(archive); + } else if (*p == 'f') { + snprintf(b, blen, "%s/node%d/bwave/%s.INF %s/node%d/bwave/%s.MIX %s/node%d/bwave/%s.FTI %s/node%d/bwave/%s.DAT", + conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, + mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name); + alen = strlen(b); + } else if (*p == '*') { + *b++ = '*'; + alen = 1; + } + b += alen; + blen -= alen; } + *b = '\0'; + if (sshBBS) { stout = dup(STDOUT_FILENO); stin = dup(STDIN_FILENO); @@ -580,16 +593,18 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char char buffer[256]; uuid_t magi_msgid; - jb = open_jam_base(conf.mail_conferences[confr]->mail_areas[area]->path); + struct mail_area *ma = get_area(confr, area); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[confr]->mail_areas[area]->path); + dolog("Error opening JAM base.. %s", ma->path); return 1; } JAM_ClearMsgHeader(&jmh); jmh.DateWritten = dwritten; jmh.Attribute |= JAM_MSG_LOCAL; - if (conf.mail_conferences[confr]->realnames == 0) { + struct mail_conference *mc = get_conf(confr); + if (mc->realnames == 0) { strlcpy(buffer, gUser->loginname, sizeof buffer); } else { snprintf(buffer, sizeof buffer, "%s %s", gUser->firstname, gUser->lastname); @@ -603,7 +618,7 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_NEWSGROUP_AREA) { strlcpy(buffer, "ALL", sizeof buffer); jsf.LoID = JAMSFLD_RECVRNAME; jsf.HiID = 0; @@ -625,21 +640,21 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - - if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[confr]->fidoaddr->point) { + struct mail_conference *mc = get_conf(confr); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point) { snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", - conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point); } else { snprintf(buffer, sizeof buffer, "%d:%d/%d", - conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -648,10 +663,10 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char JAM_PutSubfield(jsp, &jsf); snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", - conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point, + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, generate_msgid()); jsf.LoID = JAMSFLD_MSGID; @@ -660,8 +675,8 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - } else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) { - snprintf(buffer, sizeof buffer, "%d", conf.mail_conferences[confr]->maginode); + } else if (mc->nettype == NETWORK_MAGI) { + snprintf(buffer, sizeof buffer, "%d", mc->maginode); jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -677,28 +692,28 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - } else if (conf.mail_conferences[confr]->nettype == NETWORK_QWK) { + } else if (mc->nettype == NETWORK_QWK) { jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(conf.bwave_name); jsf.Buffer = (char *)conf.bwave_name; JAM_PutSubfield(jsp, &jsf); } - } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA && conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { + } else if (ma->type == TYPE_NETMAIL_AREA && mc->nettype == NETWORK_FIDO) { jmh.Attribute |= JAM_MSG_TYPENET; jmh.Attribute |= JAM_MSG_PRIVATE; - if (conf.mail_conferences[confr]->fidoaddr->point) { + if (mc->fidoaddr->point) { snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", - conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point); } else { snprintf(buffer, sizeof buffer, "%d:%d/%d", - conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -727,10 +742,10 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char } snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", - conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point, + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, generate_msgid()); jsf.LoID = JAMSFLD_MSGID; @@ -777,7 +792,6 @@ void bwave_upload_reply() { char msgbuffer[1024]; char originlinebuffer[256]; int i; - int bpos; UPL_HEADER upl_hdr; UPL_REC upl_rec; int j; @@ -836,25 +850,32 @@ void bwave_upload_reply() { return; } - bpos = 0; - for (i = 0; i < strlen(conf.archivers[gUser->defarchiver - 1]->unpack); i++) { - if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') { - i++; - if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == 'a') { - sprintf(&buffer[bpos], "%s", upload_filename); - bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == 'd') { - sprintf(&buffer[bpos], "%s/node%d/bwave/", conf.bbs_path, mynode); - bpos = strlen(buffer); - } else if (conf.archivers[gUser->defarchiver - 1]->unpack[i] == '*') { - buffer[bpos++] = '*'; - buffer[bpos] = '\0'; - } - } else { - buffer[bpos++] = conf.archivers[gUser->defarchiver - 1]->unpack[i]; - buffer[bpos] = '\0'; + struct archiver *arc = ptr_vector_get(&conf.archivers, gUser->defarchiver - 1); + assert(arc != NULL); + char *b = buffer; + size_t blen = sizeof buffer; + for (const char *p = arc->unpack; *p != '\0' && blen > 1; ++p) { + if (*p != '*') { + *b++ = *p; + --blen; + continue; } + p++; + size_t alen = 0; + if (*p == 'a') { + strlcpy(b, upload_filename, blen); + alen = strlen(upload_filename); + } else if (*p == 'd') { + snprintf(b, blen, "%s/node%d/bwave/", conf.bbs_path, mynode); + alen = strlen(b); + } else if (*p == '*') { + *b++ = '*'; + alen = 1; + } + b += alen; + blen -= alen; } + *b = '\0'; if (sshBBS) { stout = dup(STDOUT_FILENO); stin = dup(STDIN_FILENO); @@ -889,12 +910,12 @@ void bwave_upload_reply() { unlink(upload_filename); - snprintf(buffer, 1024, "%s/node%d/bwave/%s.UPL", conf.bbs_path, mynode, conf.bwave_name); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/%s.UPL", conf.bbs_path, mynode, conf.bwave_name); upl_file = fopen(buffer, "r"); if (!upl_file) { - snprintf(buffer, 1024, "%s/node%d/bwave/%s.upl", conf.bbs_path, mynode, conf.bwave_name); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/%s.upl", conf.bbs_path, mynode, conf.bwave_name); upl_file = fopen(buffer, "r"); if (!upl_file) { s_printf(get_string(196)); @@ -924,13 +945,12 @@ void bwave_upload_reply() { continue; } - bpos = 0; - for (i = 0; i < strlen(body); i++) { - if (body[i] != '\n') { - body[bpos++] = body[i]; - } + char *b = body; + for (char *p = body; *p != '\0'; ++p) { + if (*p != '\n') + *b++ = *p; } - body[bpos] = '\0'; + *b = '\0'; snprintf(buffer, sizeof buffer, "%s/email.sq3", conf.bbs_path); @@ -982,9 +1002,11 @@ void bwave_upload_reply() { confr = -1; area = -1; - for (i = 0; i < conf.mail_conference_count; i++) { - for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { - if (strcmp(conf.mail_conferences[i]->mail_areas[j]->qwkname, upl_rec.echotag) == 0) { + for (i = 0; i < ptr_vector_len(&conf.mail_conferences); i++) { + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, i); + for (j = 0; j < ptr_vector_len(&mc->mail_areas); j++) { + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, j); + if (strcmp(ma->qwkname, upl_rec.echotag) == 0) { confr = i; area = j; break; @@ -997,7 +1019,8 @@ void bwave_upload_reply() { if (confr != -1 && area != -1) { // import message - if (conf.mail_conferences[confr]->mail_areas[area]->write_sec_level <= gUser->sec_level) { + struct mail_area *ma = get_area(confr, area); + if (ma->write_sec_level <= gUser->sec_level) { msg_attr = converts(upl_rec.msg_attr); if (msg_attr & UPL_INACTIVE) { @@ -1013,7 +1036,7 @@ void bwave_upload_reply() { addr.node = 0; addr.zone = 0; - if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { if (!(msg_attr & UPL_NETMAIL)) { continue; } @@ -1022,7 +1045,7 @@ void bwave_upload_reply() { addr.node = converts(upl_rec.destnode); addr.zone = converts(upl_rec.destpoint); netmail = 1; - } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { + } else if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { if (msg_attr & UPL_PRIVATE) { continue; } @@ -1033,32 +1056,36 @@ void bwave_upload_reply() { } } - snprintf(msgbuffer, 1024, "%s/node%d/bwave/%s", conf.bbs_path, mynode, upl_rec.filename); + snprintf(msgbuffer, sizeof buffer, "%s/node%d/bwave/%s", conf.bbs_path, mynode, upl_rec.filename); - if (conf.mail_conferences[confr]->tagline != NULL) { - tagline = conf.mail_conferences[confr]->tagline; - } else { - tagline = conf.default_tagline; + tagline = conf.default_tagline; + struct mail_conference *mc = get_conf(confr); + if (mc->tagline != NULL) { + tagline = mc->tagline; } - if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[confr]->fidoaddr->point == 0) { - snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (%d:%d/%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point == 0) { + snprintf(originlinebuffer, sizeof originlinebuffer, "\r--- %s\r * Origin: %s (%d:%d/%d)\r", + upl_hdr.reader_tear, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } else { - snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (%d:%d/%d.%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + snprintf(originlinebuffer, sizeof originlinebuffer, "\r--- %s\r * Origin: %s (%d:%d/%d.%d)\r", + upl_hdr.reader_tear, tagline, + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point); } - } else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) { - snprintf(originlinebuffer, 256, "\r--- %s\r * Origin: %s (@%d)\r", upl_hdr.reader_tear, tagline, conf.mail_conferences[confr]->maginode); - } else if (conf.mail_conferences[confr]->nettype == NETWORK_QWK) { - snprintf(originlinebuffer, 256, "\r--- $s\r * Origin: %s (%s)\r", upl_hdr.reader_tear, tagline, conf.bwave_name); + } else if (mc->nettype == NETWORK_MAGI) { + snprintf(originlinebuffer, sizeof originlinebuffer, "\r--- %s\r * Origin: %s (@%d)\r", + upl_hdr.reader_tear, tagline, mc->maginode); + } else if (mc->nettype == NETWORK_QWK) { + snprintf(originlinebuffer, sizeof originlinebuffer, "\r--- $s\r * Origin: %s (%s)\r", + upl_hdr.reader_tear, tagline, conf.bwave_name); } else { - snprintf(originlinebuffer, 256, "\r"); + snprintf(originlinebuffer, sizeof originlinebuffer, "\r"); } sa = file2stralloc(msgbuffer); @@ -1089,7 +1116,7 @@ void bwave_upload_reply() { } } - snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/bwave/", conf.bbs_path, mynode); recursive_delete(buffer); if (netmail == 1) { diff --git a/src/files.c b/src/files.c index bc9491e..804d872 100644 --- a/src/files.c +++ b/src/files.c @@ -17,6 +17,7 @@ #include "lua/lua.h" #include "lua/lualib.h" #include "lua/lauxlib.h" + extern struct bbs_config conf; extern int gSocket; extern int sshBBS; @@ -47,6 +48,41 @@ struct tagged_file { int fid; }; +static struct file_directory *get_dir(size_t d) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, d); + assert(dir != NULL); + return dir; +} + +static struct file_directory *user_dir(struct user_record *user) { + assert(user != NULL); + return get_dir(user->cur_file_dir); +} + +static struct file_sub *get_sub(size_t d, size_t s) { + struct file_directory *dir = get_dir(d); + struct file_sub *sub = ptr_vector_get(&dir->file_subs, s); + assert(sub != NULL); + return sub; +} + +static struct file_sub *user_sub(struct user_record *user) { + assert(user != NULL); + return get_sub(user->cur_file_dir, user->cur_file_sub); +} + +static void open_sub_db_or_die(sqlite3 **db, char *sub) { + char buffer[PATH_MAX]; + snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, sub); + if (sqlite3_open(buffer, db) != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(*db)); + sqlite3_close(*db); + exit(1); + } + assert(db != NULL); + sqlite3_busy_timeout(*db, 5000); +} + struct tagged_file **tagged_files; int tagged_count = 0; @@ -122,12 +158,10 @@ char *upload_path; char upload_filename[1024]; FILE *ZOpenFile(char *name, u_long crc, ZModem *info) { - FILE *fptr; - struct stat s; snprintf(upload_filename, 1023, "%s/%s", upload_path, basename(name)); - if (stat(upload_filename, &s) == 0) { + if (access(upload_filename, F_OK) == 0) { return NULL; } @@ -287,7 +321,6 @@ void upload_zmodem(struct user_record *user, char *upload_p) { char *get_file_id_diz(char *filename) { char *description; char buffer[1024]; - struct stat s; int bpos; int i; FILE *fptr; @@ -315,8 +348,10 @@ char *get_file_id_diz(char *filename) { return NULL; } - for (i = 0; i < conf.archiver_count; i++) { - if (strcasecmp(&filename[ext], conf.archivers[i]->extension) == 0) { + struct archiver *arc = NULL; + for (i = 0; i < ptr_vector_len(&conf.archivers); ++i) { + arc = ptr_vector_get(&conf.archivers, i); + if (strcasecmp(&filename[ext], arc->extension) == 0) { arch = i; break; } @@ -325,41 +360,45 @@ char *get_file_id_diz(char *filename) { if (arch == -1) { return NULL; } + assert(arc != NULL); - snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode); - if (stat(buffer, &s) != 0) { + snprintf(buffer, sizeof buffer, "%s/node%d", conf.bbs_path, mynode); + if (access(buffer, X_OK) != 0) { mkdir(buffer, 0755); } - snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode); - if (stat(buffer, &s) == 0) { - + snprintf(buffer, sizeof buffer, "%s/node%d/temp", conf.bbs_path, mynode); + if (access(buffer, F_OK|W_OK) == 0) { if (recursive_delete(buffer) != 0) { return NULL; } } - mkdir(buffer, 0755); - bpos = 0; - for (i = 0; i < strlen(conf.archivers[arch]->unpack); i++) { - if (conf.archivers[arch]->unpack[i] == '*') { - i++; - if (conf.archivers[arch]->unpack[i] == 'a') { - sprintf(&buffer[bpos], "%s", filename); - bpos = strlen(buffer); - } else if (conf.archivers[arch]->unpack[i] == 'd') { - sprintf(&buffer[bpos], "%s/node%d/temp/", conf.bbs_path, mynode); - bpos = strlen(buffer); - } else if (conf.archivers[arch]->unpack[i] == '*') { - buffer[bpos++] = '*'; - buffer[bpos] = '\0'; - } - } else { - buffer[bpos++] = conf.archivers[arch]->unpack[i]; - buffer[bpos] = '\0'; + char *s = buffer; + size_t blen = sizeof buffer; + for (const char *p = arc->unpack; *p != '\0' && blen > 1; ++p) { + if (*p != '*') { + *s++ = *p; + --blen; + continue; } + p++; + size_t slen = 0; + if (*p == 'a') { + strlcpy(s, filename, blen); + slen = strlen(s); + } else if (*p == 'd') { + snprintf(s, blen, "%s/node%d/temp/", conf.bbs_path, mynode); + slen = strlen(s); + } else if (*p == '*') { + *s++ = '*'; + slen = 1; + } + s += slen; + blen -= slen; } + *s = '\0'; if (sshBBS) { stout = dup(STDOUT_FILENO); @@ -384,7 +423,6 @@ char *get_file_id_diz(char *filename) { free(args); if (sshBBS) { - dup2(stout, STDOUT_FILENO); dup2(sterr, STDERR_FILENO); dup2(stin, STDIN_FILENO); @@ -394,13 +432,13 @@ char *get_file_id_diz(char *filename) { close(sterr); } - snprintf(buffer, 1024, "%s/node%d/temp/FILE_ID.DIZ", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/temp/FILE_ID.DIZ", conf.bbs_path, mynode); description = file2str(buffer); if (description == NULL) { - snprintf(buffer, 1024, "%s/node%d/temp/file_id.diz", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/temp/file_id.diz", conf.bbs_path, mynode); description = file2str(buffer); if (description == NULL) { - snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/temp", conf.bbs_path, mynode); recursive_delete(buffer); return NULL; } @@ -417,7 +455,7 @@ char *get_file_id_diz(char *filename) { } description[bpos] = '\0'; - snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/temp", conf.bbs_path, mynode); recursive_delete(buffer); return description; @@ -436,7 +474,9 @@ int do_download(struct user_record *user, char *file) { char iac_binary_will[] = {IAC, IAC_WILL, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'}; - if (conf.protocols[user->defprotocol - 1]->internal_zmodem) { + struct protocol *defproto = ptr_vector_get(&conf.protocols, user->defprotocol - 1); + assert(defproto != NULL); + if (defproto->internal_zmodem) { if (sshBBS) { ttySetRaw(STDIN_FILENO, &oldit); ttySetRaw(STDOUT_FILENO, &oldot); @@ -456,30 +496,30 @@ int do_download(struct user_record *user, char *file) { return 1; } else { bpos = 0; - for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->download); i++) { - if (conf.protocols[user->defprotocol - 1]->download[i] == '*') { + for (i = 0; i < strlen(defproto->download); i++) { + if (defproto->download[i] == '*') { i++; - if (conf.protocols[user->defprotocol - 1]->download[i] == '*') { - download_command[bpos++] = conf.protocols[user->defprotocol - 1]->download[i]; + if (defproto->download[i] == '*') { + download_command[bpos++] = defproto->download[i]; download_command[bpos] = '\0'; continue; - } else if (conf.protocols[user->defprotocol - 1]->download[i] == 'f') { + } else if (defproto->download[i] == 'f') { sprintf(&download_command[bpos], "%s", file); bpos = strlen(download_command); continue; - } else if (conf.protocols[user->defprotocol - 1]->download[i] == 's') { + } else if (defproto->download[i] == 's') { if (!sshBBS) { sprintf(&download_command[bpos], "%d", gSocket); bpos = strlen(download_command); } else { - s_printf(get_string(209), conf.protocols[user->defprotocol - 1]->name); + s_printf(get_string(209), defproto->name); return 0; } } } else { - download_command[bpos++] = conf.protocols[user->defprotocol - 1]->download[i]; + download_command[bpos++] = defproto->download[i]; download_command[bpos] = '\0'; } } @@ -521,7 +561,7 @@ int do_download(struct user_record *user, char *file) { write(gSocket, iac_binary_do, 3); } } - runexternal(user, download_command, conf.protocols[user->defprotocol - 1]->stdio, arguments, conf.bbs_path, 1, NULL); + runexternal(user, download_command, defproto->stdio, arguments, conf.bbs_path, 1, NULL); free(arguments); } @@ -539,12 +579,12 @@ int do_upload(struct user_record *user, char *final_path) { char **arguments; DIR *inb; struct dirent *dent; - struct stat s; int len; char iac_binary_will[] = {IAC, IAC_WILL, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'}; - if (conf.protocols[user->defprotocol - 1]->internal_zmodem) { + struct protocol *defproto = ptr_vector_get(&conf.protocols, user->defprotocol - 1); + if (defproto->internal_zmodem) { if (!sshBBS) { if (telnet_bin_mode == 0) { write(gSocket, iac_binary_will, 3); @@ -557,37 +597,37 @@ int do_upload(struct user_record *user, char *final_path) { return 1; } else { - if (conf.protocols[user->defprotocol - 1]->upload_prompt) { + if (defproto->upload_prompt) { s_printf(get_string(210)); s_readstring(buffer3, 256); s_printf("\r\n"); } bpos = 0; - for (i = 0; i < strlen(conf.protocols[user->defprotocol - 1]->upload); i++) { - if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') { + for (i = 0; i < strlen(defproto->upload); i++) { + if (defproto->upload[i] == '*') { i++; - if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') { - upload_command[bpos++] = conf.protocols[user->defprotocol - 1]->upload[i]; + if (defproto->upload[i] == '*') { + upload_command[bpos++] = defproto->upload[i]; upload_command[bpos] = '\0'; continue; - } else if (conf.protocols[user->defprotocol - 1]->upload[i] == 'f') { - if (conf.protocols[user->defprotocol - 1]->upload_prompt) { + } else if (defproto->upload[i] == 'f') { + if (defproto->upload_prompt) { sprintf(&upload_command[bpos], "%s", buffer3); bpos = strlen(upload_command); } continue; - } else if (conf.protocols[user->defprotocol - 1]->upload[i] == 's') { + } else if (defproto->upload[i] == 's') { if (!sshBBS) { sprintf(&upload_command[bpos], "%d", gSocket); bpos = strlen(upload_command); } else { - s_printf(get_string(209), conf.protocols[user->defprotocol - 1]->name); + s_printf(get_string(209), defproto->name); return 0; } } } else { - upload_command[bpos++] = conf.protocols[user->defprotocol - 1]->upload[i]; + upload_command[bpos++] = defproto->upload[i]; upload_command[bpos] = '\0'; } } @@ -626,7 +666,7 @@ int do_upload(struct user_record *user, char *final_path) { snprintf(upload_path, 1024, "%s/node%d/upload/", conf.bbs_path, mynode); - if (stat(upload_path, &s) == 0) { + if (access(upload_path, F_OK) == 0) { recursive_delete(upload_path); } @@ -638,19 +678,19 @@ int do_upload(struct user_record *user, char *final_path) { write(gSocket, iac_binary_do, 3); } } - runexternal(user, upload_command, conf.protocols[user->defprotocol - 1]->stdio, arguments, upload_path, 1, NULL); + runexternal(user, upload_command, defproto->stdio, arguments, upload_path, 1, NULL); free(arguments); - if (conf.protocols[user->defprotocol - 1]->upload_prompt) { + if (defproto->upload_prompt) { snprintf(upload_command, 1024, "%s%s", upload_path, buffer3); - if (stat(upload_command, &s) != 0) { + if (access(upload_command, W_OK|X_OK) != 0) { recursive_delete(upload_path); return 0; } snprintf(upload_filename, 1024, "%s/%s", final_path, buffer3); - if (stat(upload_filename, &s) == 0) { + if (access(upload_filename, F_OK) == 0) { recursive_delete(upload_path); s_printf(get_string(214)); return 0; @@ -670,6 +710,7 @@ int do_upload(struct user_record *user, char *final_path) { while ((dent = readdir(inb)) != NULL) { #ifdef __sun snprintf(upload_command, 1024, "%s%s", upload_path, dent->d_name); + struct state s; stat(upload_command, &s); if (S_ISREG(s.st_mode)) { #else @@ -678,7 +719,7 @@ int do_upload(struct user_record *user, char *final_path) { 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) { + if (access(upload_filename, F_OK) == 0) { recursive_delete(upload_path); s_printf(get_string(214)); closedir(inb); @@ -719,12 +760,12 @@ void upload(struct user_record *user) { sqlite3 *db; sqlite3_stmt *res; int rc; - struct stat s; char *err_msg = NULL; char *description; time_t curtime; - if (!do_upload(user, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path)) { + struct file_sub *sub = user_sub(user); + if (!do_upload(user, sub->upload_path)) { s_printf(get_string(211)); return; } @@ -752,17 +793,7 @@ void upload(struct user_record *user) { } else { s_printf(get_string(201)); } - snprintf(pathname, sizeof pathname, "%s/%s.sq3", - conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); - - rc = sqlite3_open(pathname, &db); - - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } - sqlite3_busy_timeout(db, 5000); + open_sub_db_or_die(&db, sub->database); rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); if (rc != SQLITE_OK) { dolog("SQL error: %s", err_msg); @@ -775,6 +806,7 @@ void upload(struct user_record *user) { rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc == SQLITE_OK) { + struct stat s; stat(upload_filename, &s); sqlite3_bind_text(res, 1, upload_filename, -1, 0); @@ -936,16 +968,8 @@ void download(struct user_record *user) { do_download(user, tagged_files[i]->filename); - sprintf(buffer, "%s/%s.sq3", conf.bbs_path, conf.file_directories[tagged_files[i]->dir]->file_subs[tagged_files[i]->sub]->database); - - rc = sqlite3_open(buffer, &db); - - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } - sqlite3_busy_timeout(db, 5000); + struct file_sub *sub = get_sub(tagged_files[i]->dir, tagged_files[i]->sub); + open_sub_db_or_die(&db, sub->database); rc = sqlite3_prepare_v2(db, ssql, -1, &res, 0); if (rc == SQLITE_OK) { @@ -1049,7 +1073,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { } else { z = atoi(buffer); if (z >= 0 && z < files_c) { - if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { + if (get_sub(files_e[z]->dir, files_e[z]->sub)->download_sec_level <= gUser->sec_level) { match = 0; for (k = 0; k < tagged_count; k++) { if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) { @@ -1104,7 +1128,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { } else { z = atoi(buffer); if (z >= 0 && z < files_c) { - if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { + if (get_sub(files_e[z]->dir, files_e[z]->sub)->download_sec_level <= gUser->sec_level) { match = 0; for (k = 0; k < tagged_count; k++) { if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) { @@ -1148,7 +1172,7 @@ void do_list_files(struct file_entry **files_e, int files_c) { } else { z = atoi(buffer); if (z >= 0 && z < files_c) { - if (conf.file_directories[files_e[z]->dir]->file_subs[files_e[z]->sub]->download_sec_level <= gUser->sec_level) { + if (get_sub(files_e[z]->dir, files_e[z]->sub)->download_sec_level <= gUser->sec_level) { match = 0; for (k = 0; k < tagged_count; k++) { if (strcmp(tagged_files[k]->filename, files_e[z]->filename) == 0) { @@ -1256,16 +1280,9 @@ void file_search() { if (!all) { files_c = 0; - snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->database); + struct file_sub *sub = user_sub(gUser); + open_sub_db_or_die(&db, sub->database); - rc = sqlite3_open(buffer, &db); - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - - exit(1); - } - sqlite3_busy_timeout(db, 5000); rc = sqlite3_prepare_v2(db, sqlbuffer, -1, &res, 0); if (rc != SQLITE_OK) { @@ -1313,23 +1330,18 @@ void file_search() { } } else { files_c = 0; - for (search_dir = 0; search_dir < conf.file_directory_count; search_dir++) { - if (conf.file_directories[search_dir]->sec_level > gUser->sec_level) { + for (search_dir = 0; search_dir < ptr_vector_len(&conf.file_directories); search_dir++) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, search_dir); + if (dir->sec_level > gUser->sec_level) { continue; } - for (search_sub = 0; search_sub < conf.file_directories[search_dir]->file_sub_count; search_sub++) { - if (conf.file_directories[search_dir]->file_subs[search_sub]->download_sec_level > gUser->sec_level) { + for (search_sub = 0; search_sub < ptr_vector_len(&dir->file_subs); search_sub++) { + struct file_sub *sub = ptr_vector_get(&dir->file_subs, search_sub); + if (sub->download_sec_level > gUser->sec_level) { continue; } - snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[search_dir]->file_subs[search_sub]->database); + open_sub_db_or_die(&db, sub->database); - rc = sqlite3_open(buffer, &db); - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - exit(1); - } - sqlite3_busy_timeout(db, 5000); rc = sqlite3_prepare_v2(db, sqlbuffer, -1, &res, 0); if (rc != SQLITE_OK) { @@ -1414,16 +1426,8 @@ void list_files(struct user_record *user) { break; } s_printf("\r\n"); - snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); - - rc = sqlite3_open(buffer, &db); - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - - exit(1); - } - sqlite3_busy_timeout(db, 5000); + struct file_sub *sub = user_sub(user); + open_sub_db_or_die(&db, sub->database); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc != SQLITE_OK) { sqlite3_close(db); @@ -1477,10 +1481,12 @@ void choose_subdir() { struct ptr_vector subs; init_ptr_vector(&subs); - for (i = 0; i < conf.file_directories[gUser->cur_file_dir]->file_sub_count; i++) { - if (conf.file_directories[gUser->cur_file_dir]->file_subs[i]->download_sec_level <= gUser->sec_level) { + struct file_directory *dir = user_dir(gUser); + for (i = 0; i < ptr_vector_len(&dir->file_subs); i++) { + struct file_sub *fsub = ptr_vector_get(&dir->file_subs, i); + if (fsub->download_sec_level <= gUser->sec_level) { struct subdir_tmp_t *sub = (struct subdir_tmp_t *)malloz(sizeof(struct subdir_tmp_t)); - sub->sub = conf.file_directories[gUser->cur_file_dir]->file_subs[i]; + sub->sub = fsub; sub->index = i; ptr_vector_append(&subs, sub); } @@ -1491,7 +1497,7 @@ void choose_subdir() { while (1) { if (redraw) { s_printf("\e[2J\e[1;1H"); - s_printf(get_string(252), conf.file_directories[gUser->cur_file_dir]->name); + s_printf(get_string(252), user_dir(gUser)->name); s_printf(get_string(248)); for (i = start; i < start + 22 && i < list_tmp; i++) { if (i == selected) { @@ -1613,10 +1619,11 @@ void choose_directory() { struct ptr_vector dirs; init_ptr_vector(&dirs); - for (i = 0; i < conf.file_directory_count; i++) { - if (conf.file_directories[i]->sec_level <= gUser->sec_level) { + for (i = 0; i < ptr_vector_len(&conf.file_directories); i++) { + struct file_directory *fdir = ptr_vector_get(&conf.file_directories, i); + if (fdir->sec_level <= gUser->sec_level) { struct dir_tmp_t *dir = (struct dir_tmp_t *)malloz(sizeof(struct dir_tmp_t)); - dir->dir = conf.file_directories[i]; + dir->dir = fdir; dir->index = i; ptr_vector_append(&dirs, dir); } @@ -1748,49 +1755,39 @@ void clear_tagged_files() { } void next_file_dir(struct user_record *user) { - int i; - for (i = user->cur_file_dir; i < conf.file_directory_count; i++) { - if (i + 1 == conf.file_directory_count) { - i = -1; - } - if (conf.file_directories[i + 1]->sec_level <= user->sec_level) { - user->cur_file_dir = i + 1; - user->cur_file_sub = 0; + size_t n = ptr_vector_len(&conf.file_directories); + size_t start = user->cur_file_dir; + size_t i; + for (i = (start + 1) % n; i != start; i = (i + 1) % n) { + struct file_directory *dir = get_dir(i); + if (dir->sec_level <= user->sec_level) break; - } } + user->cur_file_dir = i; + user->cur_file_sub = 0; } void prev_file_dir(struct user_record *user) { - int i; - for (i = user->cur_file_dir; i >= 0; i--) { - if (i - 1 == -1) { - i = conf.file_directory_count; - } - if (conf.file_directories[i - 1]->sec_level <= user->sec_level) { - user->cur_file_dir = i - 1; - user->cur_file_sub = 0; + size_t n = ptr_vector_len(&conf.file_directories); + size_t start = user->cur_file_dir; + size_t i; + for (i = (start + n - 1) % n; i != start; i = (i + n - 1) % n) { + struct file_directory *dir = get_dir(i); + if (dir->sec_level <= user->sec_level) break; - } } + user->cur_file_dir = i; + user->cur_file_sub = 0; } void next_file_sub(struct user_record *user) { - int i; - i = user->cur_file_sub; - if (i + 1 == conf.file_directories[user->cur_file_dir]->file_sub_count) { - i = -1; - } - user->cur_file_sub = i + 1; + size_t n = ptr_vector_len(&conf.file_directories); + user->cur_file_sub = (user->cur_file_sub + 1) % n; } void prev_file_sub(struct user_record *user) { - int i; - i = user->cur_file_sub; - if (i - 1 == -1) { - i = conf.file_directories[user->cur_file_dir]->file_sub_count; - } - user->cur_file_sub = i - 1; + size_t n = ptr_vector_len(&conf.file_directories); + user->cur_file_sub = (user->cur_file_sub + n - 1) % n; } void file_scan() { @@ -1809,30 +1806,24 @@ void file_scan() { c = s_getc(); if (tolower(c) == 'y') { - for (i = 0; i < conf.file_directory_count; i++) { - if (conf.file_directories[i]->sec_level > gUser->sec_level) { + for (i = 0; i < ptr_vector_len(&conf.file_directories); i++) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, i); + if (dir->sec_level > gUser->sec_level) { continue; } - s_printf(get_string(140), i, conf.file_directories[i]->name); + s_printf(get_string(140), i, dir->name); lines += 2; if (lines == 22) { s_printf(get_string(6)); s_getc(); lines = 0; } - for (j = 0; j < conf.file_directories[i]->file_sub_count; j++) { - if (conf.file_directories[i]->file_subs[j]->download_sec_level > gUser->sec_level) { + for (j = 0; j < ptr_vector_len(&dir->file_subs); j++) { + struct file_sub *sub = ptr_vector_get(&dir->file_subs, j); + if (sub->download_sec_level > gUser->sec_level) { continue; } - snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[i]->file_subs[j]->database); - rc = sqlite3_open(buffer, &db); - if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - - exit(1); - } - sqlite3_busy_timeout(db, 5000); + open_sub_db_or_die(&db, sub->database); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc != SQLITE_OK) { @@ -1845,7 +1836,7 @@ void file_scan() { if (sqlite3_step(res) != SQLITE_ERROR) { new_files = sqlite3_column_int(res, 0); if (new_files > 0) { - s_printf(get_string(141), j, conf.file_directories[i]->file_subs[j]->name, new_files); + s_printf(get_string(141), j, sub->name, new_files); lines++; } } diff --git a/src/lua_glue.c b/src/lua_glue.c index 16183c2..94d774b 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -157,19 +157,29 @@ int l_bbsDisplayAutoMsg(lua_State *L) { } int l_getMailAreaInfo(lua_State *L) { + assert(gUser != NULL); lua_pushnumber(L, gUser->cur_mail_conf); - lua_pushstring(L, conf.mail_conferences[gUser->cur_mail_conf]->name); + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, gUser->cur_mail_conf); + assert(mc != NULL); + lua_pushstring(L, mc->name); lua_pushnumber(L, gUser->cur_mail_area); - lua_pushstring(L, conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[gUser->cur_mail_area]->name); + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, gUser->cur_mail_area); + assert(ma != NULL); + lua_pushstring(L, ma->name); return 4; } int l_getFileAreaInfo(lua_State *L) { + assert(gUser != NULL); lua_pushnumber(L, gUser->cur_file_dir); - lua_pushstring(L, conf.file_directories[gUser->cur_file_dir]->name); + struct file_directory *dir = ptr_vector_get(&conf.file_directories, gUser->cur_file_dir); + assert(dir != NULL); + lua_pushstring(L, dir->name); lua_pushnumber(L, gUser->cur_file_sub); - lua_pushstring(L, conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->name); + struct file_sub *sub = ptr_vector_get(&dir->file_subs, gUser->cur_file_sub); + assert(sub != NULL); + lua_pushstring(L, sub->name); return 4; } @@ -204,9 +214,13 @@ int l_messageFound(lua_State *L) { s_JamMsgHeader jmh; s_JamSubPacket *jsp; - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, conference); + assert(mc != NULL); + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, area); + assert(ma != NULL); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[conference]->mail_areas[area]->path); + dolog("Error opening JAM base.. %s", ma->path); lua_pushnumber(L, 0); return 1; } @@ -248,9 +262,13 @@ int l_readMessageHdr(lua_State *L) { char *sender = NULL; char *recipient = NULL; - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, conference); + assert(mc != NULL); + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, area); + assert(ma != NULL); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[conference]->mail_areas[area]->path); + dolog("Error opening JAM base.. %s", ma->path); return 0; } z = JAM_ReadMsgHeader(jb, id, &jmh, &jsp); @@ -312,9 +330,13 @@ int l_readMessage(lua_State *L) { char *body = NULL; - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, conference); + assert(mc != NULL); + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, area); + assert(ma != NULL); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[conference]->mail_areas[area]->path); + dolog("Error opening JAM base.. %s", ma->path); return 0; } z = JAM_ReadMsgHeader(jb, id, &jmh, NULL); @@ -380,10 +402,10 @@ int l_postMessage(lua_State *L) { int confr = lua_tointeger(L, 1); int area = lua_tointeger(L, 2); time_t dwritten = utc_to_local(time(NULL)); - char *to = lua_tostring(L, 3); - char *from = lua_tostring(L, 4); - char *subject = lua_tostring(L, 5); - char *body = lua_tostring(L, 6); + const char *to = lua_tostring(L, 3); + const char *from = lua_tostring(L, 4); + const char *subject = lua_tostring(L, 5); + const char *body = lua_tostring(L, 6); int sem_fd; char buffer[256]; @@ -398,9 +420,13 @@ int l_postMessage(lua_State *L) { char *tagline; struct utsname name; - jb = open_jam_base(conf.mail_conferences[confr]->mail_areas[area]->path); + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, confr); + assert(mc != NULL); + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, area); + assert(ma != NULL); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[confr]->mail_areas[area]->path); + dolog("Error opening JAM base.. %s", ma->path); return 0; } @@ -416,7 +442,7 @@ int l_postMessage(lua_State *L) { jsf.Buffer = (char *)from; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_NEWSGROUP_AREA) { sprintf(buffer, "ALL"); jsf.LoID = JAMSFLD_RECVRNAME; jsf.HiID = 0; @@ -438,18 +464,20 @@ int l_postMessage(lua_State *L) { jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - if (conf.mail_conferences[confr]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + if (mc->fidoaddr->point) { + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point); } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -457,11 +485,12 @@ int l_postMessage(lua_State *L) { jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point, - generate_msgid()); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -469,8 +498,7 @@ int l_postMessage(lua_State *L) { jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - - } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { + } else if (ma->type == TYPE_NETMAIL_AREA) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); free(jb); @@ -492,30 +520,29 @@ int l_postMessage(lua_State *L) { } uname(&name); - if (conf.mail_conferences[confr]->tagline != NULL) { - tagline = conf.mail_conferences[confr]->tagline; - } else { - tagline = conf.default_tagline; + tagline = conf.default_tagline; + if (mc != NULL) { + tagline = mc->tagline; } - if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[confr]->fidoaddr->point == 0) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point == 0) { + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[confr]->fidoaddr->zone, - conf.mail_conferences[confr]->fidoaddr->net, - conf.mail_conferences[confr]->fidoaddr->node, - conf.mail_conferences[confr]->fidoaddr->point); + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, mc->fidoaddr->point); } } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); } stralloc sa = EMPTY_STRALLOC; stralloc_ready(&sa, strlen(body) + 2 + strlen(buffer)); - for (char *p = body; *p != '\0'; ++p) + for (const char *p = body; *p != '\0'; ++p) if (*p != '\n') stralloc_append1(&sa, *p); stralloc_cats(&sa, buffer); @@ -538,7 +565,7 @@ int l_postMessage(lua_State *L) { free(jb); free(msg); - if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { if (conf.echomail_sem != NULL) { sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); close(sem_fd); @@ -616,9 +643,9 @@ void do_lua_script(char *script) { } if (script[0] == '/') { - snprintf(buffer, PATH_MAX, "%s.lua", script); + snprintf(buffer, sizeof buffer, "%s.lua", script); } else { - snprintf(buffer, PATH_MAX, "%s/%s.lua", conf.script_path, script); + snprintf(buffer, sizeof buffer, "%s/%s.lua", conf.script_path, script); } L = luaL_newstate(); diff --git a/src/mail_menu.c b/src/mail_menu.c index 486315e..0c8d95d 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -8,13 +8,16 @@ #include #include #include + #include "jamlib/jam.h" -#include "bbs.h" #include "lua/lua.h" #include "lua/lualib.h" #include "lua/lauxlib.h" #include "libuuid/uuid.h" +#include "bbs.h" +#include "mail_utils.h" + #ifdef __sun #include "os/sunos.h" #endif @@ -99,7 +102,7 @@ unsigned long generate_msgid() { dolog("Unable to open message id log"); } } - sprintf(buffer, "%lX", lastid); + snprintf(buffer, sizeof buffer, "%lX", lastid); return strtoul(&buffer[strlen(buffer) - 8], NULL, 16); } @@ -108,27 +111,13 @@ void free_message_headers(struct msg_headers *msghs) { for (i = 0; i < msghs->msg_count; i++) { free(msghs->msgs[i]->msg_h); - if (msghs->msgs[i]->from != NULL) { - free(msghs->msgs[i]->from); - } - if (msghs->msgs[i]->to != NULL) { - free(msghs->msgs[i]->to); - } - if (msghs->msgs[i]->from != NULL) { - free(msghs->msgs[i]->subject); - } - if (msghs->msgs[i]->oaddress != NULL) { - free(msghs->msgs[i]->oaddress); - } - if (msghs->msgs[i]->daddress != NULL) { - free(msghs->msgs[i]->daddress); - } - if (msghs->msgs[i]->msgid != NULL) { - free(msghs->msgs[i]->msgid); - } - if (msghs->msgs[i]->replyid != NULL) { - free(msghs->msgs[i]->replyid); - } + free(msghs->msgs[i]->from); + free(msghs->msgs[i]->to); + free(msghs->msgs[i]->subject); + free(msghs->msgs[i]->oaddress); + free(msghs->msgs[i]->daddress); + free(msghs->msgs[i]->msgid); + free(msghs->msgs[i]->replyid); free(msghs->msgs[i]); } if (msghs->msg_count > 0) { @@ -139,21 +128,20 @@ void free_message_headers(struct msg_headers *msghs) { int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, int msgconf) { char *myname; - struct fido_addr *dest; - int j; - int magi_dest; if (rn) { myname = str3dup(user->firstname, " ", user->lastname); } else { myname = strdup(user->loginname); } + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf); + assert(mc != NULL); if (type == NETWORK_FIDO && address != NULL) { if (strcasecmp(myname, addressed_to) == 0) { - dest = parse_fido_addr(address); - if (conf.mail_conferences[msgconf]->fidoaddr->zone == dest->zone && - conf.mail_conferences[msgconf]->fidoaddr->net == dest->net && - conf.mail_conferences[msgconf]->fidoaddr->node == dest->node && - conf.mail_conferences[msgconf]->fidoaddr->point == dest->point) { + struct fido_addr *dest = parse_fido_addr(address); + if (mc->fidoaddr->zone == dest->zone && + mc->fidoaddr->net == dest->net && + mc->fidoaddr->node == dest->node && + mc->fidoaddr->point == dest->point) { free(dest); free(myname); return 1; @@ -164,8 +152,8 @@ int msg_is_to(struct user_record *user, char *addressed_to, char *address, int t return 0; } else if (type == NETWORK_MAGI && address != NULL) { if (strcasecmp(myname, addressed_to) == 0) { - magi_dest = atoi(address); - if (magi_dest == conf.mail_conferences[msgconf]->maginode) { + int magi_dest = atoi(address); + if (magi_dest == mc->maginode) { free(myname); return 1; } @@ -184,22 +172,21 @@ int msg_is_to(struct user_record *user, char *addressed_to, char *address, int t int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf) { char *myname; - struct fido_addr *orig; - int j; - int magi_orig; if (rn) { myname = str3dup(user->firstname, " ", user->lastname); } else { myname = strdup(user->loginname); } + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf); + assert(mc != NULL); if (type == NETWORK_FIDO && address != NULL) { if (strcasecmp(myname, addressed_from) == 0) { - orig = parse_fido_addr(address); - if (conf.mail_conferences[msgconf]->fidoaddr->zone == orig->zone && - conf.mail_conferences[msgconf]->fidoaddr->net == orig->net && - conf.mail_conferences[msgconf]->fidoaddr->node == orig->node && - conf.mail_conferences[msgconf]->fidoaddr->point == orig->point) { + struct fido_addr *orig = parse_fido_addr(address); + if (mc->fidoaddr->zone == orig->zone && + mc->fidoaddr->net == orig->net && + mc->fidoaddr->node == orig->node && + mc->fidoaddr->point == orig->point) { free(orig); free(myname); return 1; @@ -210,8 +197,8 @@ int msg_is_from(struct user_record *user, char *addressed_from, char *address, i return 0; } else if (type == NETWORK_MAGI && address != NULL) { if (strcasecmp(myname, addressed_from) == 0) { - magi_orig = atoi(address); - if (magi_orig == conf.mail_conferences[msgconf]->maginode) { + int magi_orig = atoi(address); + if (magi_orig == mc->maginode) { free(myname); return 1; } @@ -243,149 +230,122 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r struct fido_addr *dest; struct msg_headers *msghs = NULL; + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf); + assert(mc != NULL); + struct mail_area *area = ptr_vector_get(&mc->mail_areas, msgarea); + assert(area != NULL); - jb = open_jam_base(conf.mail_conferences[msgconf]->mail_areas[msgarea]->path); + jb = open_jam_base(area->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[msgconf]->mail_areas[msgarea]->path); + dolog("Error opening JAM base.. %s", area->path); return NULL; } JAM_ReadMBHeader(jb, &jbh); - if (jbh.ActiveMsgs > 0) { - init_ptr_vector(&vec); - msghs = (struct msg_headers *)malloz(sizeof(struct msg_headers)); - msghs->msg_count = 0; - k = 0; - for (i = 0; k < jbh.ActiveMsgs; i++) { - - memset(&jmh, 0, sizeof(s_JamMsgHeader)); - z = JAM_ReadMsgHeader(jb, i, &jmh, &jsp); - if (z != 0) { - dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); - continue; - } - - if (jmh.Attribute & JAM_MSG_DELETED) { - JAM_DelSubPacket(jsp); - continue; - } - - jamm = (struct jam_msg *)malloz(sizeof(struct jam_msg)); - - jamm->msg_no = i; - jamm->msg_h = (s_JamMsgHeader *)malloz(sizeof(s_JamMsgHeader)); - memcpy(jamm->msg_h, &jmh, sizeof(s_JamMsgHeader)); - jamm->from = NULL; - jamm->to = NULL; - jamm->subject = NULL; - jamm->oaddress = NULL; - jamm->daddress = NULL; - jamm->msgid = NULL; - jamm->replyid = NULL; - - for (z = 0; z < jsp->NumFields; z++) { - if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { - jamm->subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) { - jamm->from = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) { - jamm->to = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) { - jamm->daddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) { - jamm->oaddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) { - jamm->msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) { - jamm->replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } - } - JAM_DelSubPacket(jsp); - - if (jamm->subject == NULL) { - jamm->subject = strdup("(No Subject)"); - } - if (jamm->from == NULL) { - jamm->from = strdup("(No Sender)"); - } - if (jamm->to == NULL) { - jamm->to = strdup("(No Recipient)"); - } - if (jmh.Attribute & JAM_MSG_PRIVATE) { - if (!msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, conf.mail_conferences[msgconf]->realnames, msgconf) && - !msg_is_from(user, jamm->from, jamm->oaddress, conf.mail_conferences[msgconf]->nettype, conf.mail_conferences[msgconf]->realnames, msgconf) && - !msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf) && - !msg_is_from(user, jamm->from, jamm->oaddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf)) { - - if (jamm->subject != NULL) { - free(jamm->subject); - } - if (jamm->from != NULL) { - free(jamm->from); - } - if (jamm->to != NULL) { - free(jamm->to); - } - if (jamm->oaddress != NULL) { - free(jamm->oaddress); - } - if (jamm->daddress != NULL) { - free(jamm->daddress); - } - if (jamm->msgid != NULL) { - free(jamm->msgid); - } - if (jamm->replyid != NULL) { - free(jamm->replyid); - } - free(jamm->msg_h); - free(jamm); - k++; - continue; - } - } else if (personal) { - if (!msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, conf.mail_conferences[msgconf]->realnames, msgconf) && - !msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf)) { - - if (jamm->subject != NULL) { - free(jamm->subject); - } - if (jamm->from != NULL) { - free(jamm->from); - } - if (jamm->to != NULL) { - free(jamm->to); - } - if (jamm->oaddress != NULL) { - free(jamm->oaddress); - } - if (jamm->daddress != NULL) { - free(jamm->daddress); - } - if (jamm->msgid != NULL) { - free(jamm->msgid); - } - if (jamm->replyid != NULL) { - free(jamm->replyid); - } - free(jamm->msg_h); - free(jamm); - k++; - continue; - } - } - - ptr_vector_append(&vec, jamm); - k++; - } - msghs->msg_count = ptr_vector_len(&vec); - msghs->msgs = (struct jam_msg **)consume_ptr_vector(&vec); - } else { + if (jbh.ActiveMsgs <= 0) { JAM_CloseMB(jb); free(jb); return NULL; } + init_ptr_vector(&vec); + msghs = (struct msg_headers *)malloz(sizeof(struct msg_headers)); + msghs->msg_count = 0; + k = 0; + for (i = 0; k < jbh.ActiveMsgs; i++) { + memset(&jmh, 0, sizeof(s_JamMsgHeader)); + z = JAM_ReadMsgHeader(jb, i, &jmh, &jsp); + if (z != 0) { + dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); + continue; + } + + if (jmh.Attribute & JAM_MSG_DELETED) { + JAM_DelSubPacket(jsp); + continue; + } + + jamm = (struct jam_msg *)malloz(sizeof(struct jam_msg)); + jamm->msg_no = i; + jamm->msg_h = (s_JamMsgHeader *)malloz(sizeof(s_JamMsgHeader)); + memcpy(jamm->msg_h, &jmh, sizeof(s_JamMsgHeader)); + jamm->from = NULL; + jamm->to = NULL; + jamm->subject = NULL; + jamm->oaddress = NULL; + jamm->daddress = NULL; + jamm->msgid = NULL; + jamm->replyid = NULL; + + for (z = 0; z < jsp->NumFields; z++) { + if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { + jamm->subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) { + jamm->from = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) { + jamm->to = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) { + jamm->daddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) { + jamm->oaddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) { + jamm->msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) { + jamm->replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } + } + JAM_DelSubPacket(jsp); + + if (jamm->subject == NULL) { + jamm->subject = strdup("(No Subject)"); + } + if (jamm->from == NULL) { + jamm->from = strdup("(No Sender)"); + } + if (jamm->to == NULL) { + jamm->to = strdup("(No Recipient)"); + } + if (jmh.Attribute & JAM_MSG_PRIVATE) { + if (!msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, mc->realnames, msgconf) && + !msg_is_from(user, jamm->from, jamm->oaddress, mc->nettype, mc->realnames, msgconf) && + !msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, !mc->realnames, msgconf) && + !msg_is_from(user, jamm->from, jamm->oaddress, mc->nettype, !mc->realnames, msgconf)) { + free(jamm->subject); + free(jamm->from); + free(jamm->to); + free(jamm->oaddress); + free(jamm->daddress); + free(jamm->msgid); + free(jamm->replyid); + free(jamm->msg_h); + free(jamm); + k++; + continue; + } + } else if (personal) { + if (!msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, mc->realnames, msgconf) && + !msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, !mc->realnames, msgconf)) { + + free(jamm->subject); + free(jamm->from); + free(jamm->to); + free(jamm->oaddress); + free(jamm->daddress); + free(jamm->msgid); + free(jamm->replyid); + free(jamm->msg_h); + free(jamm); + k++; + continue; + } + } + + ptr_vector_append(&vec, jamm); + k++; + } + msghs->msg_count = ptr_vector_len(&vec); + msghs->msgs = (struct jam_msg **)consume_ptr_vector(&vec); + JAM_CloseMB(jb); free(jb); return msghs; @@ -413,15 +373,11 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot c = 'y'; } if (tolower(c) == 'y') { - - sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); - + snprintf(buffer, sizeof buffer, "%s/node%d", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { mkdir(buffer, 0755); } - - sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode); - + strlcat(buffer, "/MSGTMP", sizeof buffer); if (stat(buffer, &s) == 0) { remove(buffer); } @@ -443,7 +399,7 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot } fclose(fptr); } - sprintf(buffer, "%s/node%d/MSGINF", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/MSGINF", conf.bbs_path, mynode); fptr = fopen(buffer, "w"); fprintf(fptr, "%s\r\n", user->loginname); if (qfrom != NULL) { @@ -458,8 +414,9 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot fprintf(fptr, "YES\r\n"); } else { if (!sig) { - fprintf(fptr, "%s\r\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + struct mail_area *area = get_user_area(user); + fprintf(fptr, "%s\r\n", area->name); + if (area->type == TYPE_NETMAIL_AREA) { fprintf(fptr, "YES\r\n"); } else { fprintf(fptr, "NO\r\n"); @@ -474,7 +431,7 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot rundoor(user, conf.external_editor_cmd, conf.external_editor_stdio, conf.external_editor_codepage); // readin msgtmp - sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode); + snprintf(buffer, sizeof buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode); body = file2str(buffer); if (body == NULL) { @@ -486,33 +443,37 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot if (email == 1) { tagline = conf.default_tagline; } else { - if (conf.mail_conferences[user->cur_mail_conf]->tagline != NULL) { - tagline = conf.mail_conferences[user->cur_mail_conf]->tagline; - } else { - tagline = conf.default_tagline; + tagline = conf.default_tagline; + struct mail_conference *mc = get_user_conf(user); + if (mc->tagline != NULL) { + tagline = mc->tagline; } } if (!sig) { uname(&name); - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + struct mail_conference *mc = get_user_conf(user); + if (mc->nettype == NETWORK_FIDO && !email) { + if (mc->fidoaddr->point == 0) { + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, mc->fidoaddr->point); } - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI && !email) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->maginode); - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK && !email) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%s)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.bwave_name); + } else if (mc->nettype == NETWORK_MAGI && !email) { + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->maginode); + } else if (mc->nettype == NETWORK_QWK && !email) { + snprintf(buffer, sizeof buffer, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%s)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + conf.bwave_name); } else { - snprintf(buffer, 256, "\r"); + snprintf(buffer, sizeof buffer, "\r"); } if (user->autosig) { body2 = (char *)malloz(totlen + 3 + strlen(buffer) + strlen(user->signature)); @@ -526,7 +487,6 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot } j = 0; - for (i = 0; i < totlen; i++) { if (body[i] == '\n') { continue; @@ -623,30 +583,37 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in } size++; - if (conf.mail_conferences[user->cur_mail_conf]->tagline != NULL) { - tagline = conf.mail_conferences[user->cur_mail_conf]->tagline; - } else { - tagline = conf.default_tagline; + tagline = conf.default_tagline; + struct mail_conference *mc = get_user_conf(user); + if (mc->tagline != NULL) { + tagline = mc->tagline; } if (!sig) { uname(&name); - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + if (mc->nettype == NETWORK_FIDO && !email) { + if (mc->fidoaddr->point == 0) { + snprintf(buffer, sizeof buffer, + "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + snprintf(buffer, sizeof buffer, + "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, mc->fidoaddr->point); } - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI && !email) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->maginode); - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK && !email) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%s)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.bwave_name); + } else if (mc->nettype == NETWORK_MAGI && !email) { + snprintf(buffer, sizeof buffer, + "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->maginode); + } else if (mc->nettype == NETWORK_QWK && !email) { + snprintf(buffer, sizeof buffer, + "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%s)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + conf.bwave_name); } else { - snprintf(buffer, 256, "\r"); + strlcpy(buffer, "\r", sizeof buffer); } if (user->autosig) { size += 3; @@ -1450,9 +1417,10 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno init_ptr_vector(&msg_lines); - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + struct mail_area *ma = get_user_area(user); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", ma->path); return 0; } @@ -1469,24 +1437,27 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno jlr.HighReadMsg = msghs->msgs[mailno]->msg_h->MsgNum; } - if (msghs->msgs[mailno]->oaddress != NULL && conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { + struct mail_conference *mc = get_user_conf(user); + if (msghs->msgs[mailno]->oaddress != NULL && mc->nettype == NETWORK_FIDO) { from_addr = parse_fido_addr(msghs->msgs[mailno]->oaddress); s_printf(get_string(105), msghs->msgs[mailno]->from, from_addr->zone, from_addr->net, from_addr->node, from_addr->point); free(from_addr); - } else if (msghs->msgs[mailno]->oaddress != NULL && conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI) { + } else if (msghs->msgs[mailno]->oaddress != NULL && mc->nettype == NETWORK_MAGI) { s_printf(get_string(288), msghs->msgs[mailno]->from, atoi(msghs->msgs[mailno]->oaddress)); - } else if (msghs->msgs[mailno]->oaddress != NULL && conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK) { + } else if (msghs->msgs[mailno]->oaddress != NULL && mc->nettype == NETWORK_QWK) { s_printf(get_string(289), msghs->msgs[mailno]->from, msghs->msgs[mailno]->oaddress); } else { s_printf(get_string(106), msghs->msgs[mailno]->from); } - s_printf(get_string(107), msghs->msgs[mailno]->to, conf.mail_conferences[user->cur_mail_conf]->name); - s_printf(get_string(108), msghs->msgs[mailno]->subject, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); + struct mail_area *ma = get_user_area(user); + s_printf(get_string(107), msghs->msgs[mailno]->to, mc->name); + s_printf(get_string(108), msghs->msgs[mailno]->subject, ma->name); gmtime_r((time_t *)&msghs->msgs[mailno]->msg_h->DateWritten, &msg_date); - sprintf(buffer, "%s", asctime(&msg_date)); + snprintf(buffer, sizeof buffer, "%s", asctime(&msg_date)); buffer[strlen(buffer) - 1] = '\0'; s_printf(get_string(109), buffer, mailno + 1, msghs->msg_count); - s_printf(get_string(110), (msghs->msgs[mailno]->msg_h->Attribute & JAM_MSG_SENT ? "SENT" : ""), (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[mailno]->msg_h->MsgNum) ? "FLAGGED" : "")); + s_printf(get_string(110), (msghs->msgs[mailno]->msg_h->Attribute & JAM_MSG_SENT ? "SENT" : ""), + (msgbase_is_flagged(user, user->cur_mail_conf, user->cur_mail_area, msghs->msgs[mailno]->msg_h->MsgNum) ? "FLAGGED" : "")); s_printf(get_string(111)); body = (char *)malloz(msghs->msgs[mailno]->msg_h->TxtLen); @@ -1606,16 +1577,17 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno JAM_CloseMB(jb); free(jb); jb = NULL; - if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { + struct mail_area *ma = get_user_area(user); + if (user->sec_level < ma->write_sec_level) { s_printf(get_string(113)); - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + jb = open_jam_base(ma->path); } else { - if (msghs->msgs[mailno]->subject != NULL) { - if (strncasecmp(msghs->msgs[mailno]->subject, "RE:", 3) != 0) { - snprintf(buffer, 256, "RE: %s", msghs->msgs[mailno]->subject); - } else { - snprintf(buffer, 256, "%s", msghs->msgs[mailno]->subject); - } + const char *old_subject = msghs->msgs[mailno]->subject; + if (old_subject != NULL) { + *buffer = '\0'; + if (strncasecmp(old_subject, "RE:", 3) != 0) + strlcpy(buffer, "RE: ", sizeof buffer); + strlcat(buffer, old_subject, sizeof buffer); } subject = strdup(buffer); @@ -1632,21 +1604,21 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno if (msghs->msgs[mailno]->from != NULL) { strlcpy(buffer, msghs->msgs[mailno]->from, sizeof buffer); } - if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { + struct mail_conference *mc = get_user_conf(user); + if (mc->realnames == 0) { from = strdup(user->loginname); } else { from = str3dup(user->firstname, " ", user->lastname); } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_NEWSGROUP_AREA) { free(to); to = strdup("ALL"); } replybody = external_editor(user, to, from, body, z2, msghs->msgs[mailno]->from, subject, 0, 0); if (replybody != NULL) { - - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", ma->path); free(replybody); free(body); free(subject); @@ -1680,19 +1652,17 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point) { + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, + mc->fidoaddr->point); } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -1700,11 +1670,12 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -1713,7 +1684,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno JAM_PutSubfield(jsp, &jsf); if (msghs->msgs[mailno]->msgid != NULL) { - sprintf(buffer, "%s", msghs->msgs[mailno]->msgid); + strlcpy(buffer, msghs->msgs[mailno]->msgid, sizeof buffer); jsf.LoID = JAMSFLD_REPLYID; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -1722,8 +1693,8 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); } - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI) { - sprintf(buffer, "%d", conf.mail_conferences[user->cur_mail_conf]->maginode); + } else if (mc->nettype == NETWORK_MAGI) { + snprintf(buffer, sizeof buffer, "%d", mc->maginode); jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -1739,7 +1710,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); if (msghs->msgs[mailno]->msgid != NULL) { - sprintf(buffer, "%s", msghs->msgs[mailno]->msgid); + strlcpy(buffer, msghs->msgs[mailno]->msgid, sizeof buffer); jsf.LoID = JAMSFLD_REPLYID; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -1747,27 +1718,25 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno JAM_PutSubfield(jsp, &jsf); jmh.ReplyCRC = JAM_Crc32(buffer, strlen(buffer)); } - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK) { + } else if (mc->nettype == NETWORK_QWK) { jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(conf.bwave_name); jsf.Buffer = (char *)conf.bwave_name; JAM_PutSubfield(jsp, &jsf); } - } else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + } else if (ma->type == TYPE_NETMAIL_AREA) { jmh.Attribute |= JAM_MSG_TYPENET; jmh.Attribute |= JAM_MSG_PRIVATE; - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point) { + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, + mc->fidoaddr->point); } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -1778,14 +1747,12 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno from_addr = parse_fido_addr(msghs->msgs[mailno]->oaddress); if (from_addr != NULL) { if (from_addr->point) { - sprintf(buffer, "%d:%d/%d.%d", from_addr->zone, - from_addr->net, - from_addr->node, - from_addr->point); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + from_addr->zone, from_addr->net, from_addr->node, + from_addr->point); } else { - sprintf(buffer, "%d:%d/%d", from_addr->zone, - from_addr->net, - from_addr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + from_addr->zone, from_addr->net, from_addr->node); } jsf.LoID = JAMSFLD_DADDRESS; jsf.HiID = 0; @@ -1795,11 +1762,12 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno free(from_addr); } - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -1808,7 +1776,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); if (msghs->msgs[mailno]->msgid != NULL) { - sprintf(buffer, "%s", msghs->msgs[mailno]->msgid); + strlcpy(buffer, msghs->msgs[mailno]->msgid, sizeof buffer); jsf.LoID = JAMSFLD_REPLYID; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -1840,12 +1808,12 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno if (JAM_AddMessage(jb, &jmh, jsp, (char *)replybody, strlen(replybody))) { dolog("Failed to add message"); } else { - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { if (conf.netmail_sem != NULL) { sem_fd = open(conf.netmail_sem, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); close(sem_fd); } - } else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + } else if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { if (conf.echomail_sem != NULL) { sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); close(sem_fd); @@ -1860,22 +1828,13 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno // JAM_CloseMB(jb); // doquit = 1; } else { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + jb = open_jam_base(ma->path); } } free(body); - - if (from != NULL) { - free(from); - } - - if (to != NULL) { - free(to); - } - - if (subject != NULL) { - free(subject); - } + free(from); + free(to); + free(subject); } else if (tolower(c) == 'j' && newscan == 1) { free(body); doquit = 1; @@ -1904,10 +1863,9 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno destroy_ptr_vector(&msg_lines); } - if (jb != NULL) { + if (jb != NULL) JAM_CloseMB(jb); - free(jb); - } + free(jb); if (doquit == 2) { return 1; @@ -1927,9 +1885,10 @@ int read_new_msgs(struct user_record *user, struct msg_headers *msghs) { // list mail in message base if (msghs != NULL && msghs->msg_count > 0) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + struct mail_area *ma = get_user_area(user); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", ma->path); return 0; } else { all_unread = 0; @@ -1982,46 +1941,50 @@ void read_mail(struct user_record *user) { s_printf("\r\n"); // list mail in message base msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user, 0); - if (msghs != NULL && msghs->msg_count > 0) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - return; - } else { - all_unread = 0; - if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { - jlr.LastReadMsg = 0; - jlr.HighReadMsg = 0; - all_unread = 1; - } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { - all_unread = 1; - } - JAM_CloseMB(jb); - free(jb); - s_printf(get_string(120), msghs->msg_count); + if (msghs == NULL) + return; + if (msghs->msg_count <= 0) { + free_message_headers(msghs); + return; + } + struct mail_area *ma = get_user_area(user); + jb = open_jam_base(ma->path); + if (!jb) { + dolog("Error opening JAM base.. %s", ma->path); + return; + } + all_unread = 0; + if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { + jlr.LastReadMsg = 0; + jlr.HighReadMsg = 0; + all_unread = 1; + } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { + all_unread = 1; + } + JAM_CloseMB(jb); + free(jb); + s_printf(get_string(120), msghs->msg_count); - s_readstring(buffer, 6); + s_readstring(buffer, 6); - if (tolower(buffer[0]) == 'n') { - if (all_unread == 0) { - k = jlr.HighReadMsg; - for (i = 0; i < msghs->msg_count; i++) { - if (msghs->msgs[i]->msg_h->MsgNum == k) { - break; - } - } - i += 2; - } else { - i = 1; + if (tolower(buffer[0]) == 'n') { + if (all_unread == 0) { + k = jlr.HighReadMsg; + for (i = 0; i < msghs->msg_count; i++) { + if (msghs->msgs[i]->msg_h->MsgNum == k) { + break; } - } else { - i = atoi(buffer); - } - - if (i > 0 && i <= msghs->msg_count) { - read_message(user, msghs, i - 1, 0); } + i += 2; + } else { + i = 1; } + } else { + i = atoi(buffer); + } + + if (i > 0 && i <= msghs->msg_count) { + read_message(user, msghs, i - 1, 0); } if (msghs != NULL) { free_message_headers(msghs); @@ -2048,12 +2011,13 @@ void post_message(struct user_record *user) { s_JamSubfield jsf; s_JamLastRead jlr; - if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { + struct mail_area *ma = get_user_area(user); + if (user->sec_level < ma->write_sec_level) { s_printf(get_string(113)); return; } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { - sprintf(buffer, "ALL"); + if (ma->type == TYPE_NEWSGROUP_AREA) { + strlcpy(buffer, "ALL", sizeof buffer); } else { s_printf(get_string(54)); s_readstring(buffer, 32); @@ -2062,10 +2026,11 @@ void post_message(struct user_record *user) { strlcpy(buffer, "ALL", sizeof(buffer)); } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { s_printf(get_string(121)); s_readstring(buffer2, 32); - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { + struct mail_conference *mc = get_user_conf(user); + if (mc->nettype == NETWORK_FIDO) { from_addr = parse_fido_addr(buffer2); if (!from_addr) { s_printf(get_string(122)); @@ -2076,8 +2041,10 @@ void post_message(struct user_record *user) { s_printf(get_string(122)); return; } - if (conf.mail_conferences[gUser->cur_mail_conf]->domain != NULL) { - bbsname = nl_get_bbsname(from_addr, conf.mail_conferences[gUser->cur_mail_conf]->domain); + // TODO: Is this different than `user`? + struct mail_conference *gmc = get_user_conf(gUser); + if (gmc->domain != NULL) { + bbsname = nl_get_bbsname(from_addr, gmc->domain); } else { bbsname = strdup("Unknown"); } @@ -2101,7 +2068,8 @@ void post_message(struct user_record *user) { subject = strdup(buffer); // post a message - if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { + struct mail_conference *mc = get_user_conf(user); + if (mc->realnames == 0) { from = strdup(user->loginname); } else { from = str3dup(user->firstname, " ", user->lastname); @@ -2111,9 +2079,9 @@ void post_message(struct user_record *user) { free(from); if (msg != NULL) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", ma->path); free(msg); free(to); free(subject); @@ -2123,7 +2091,7 @@ void post_message(struct user_record *user) { JAM_ClearMsgHeader(&jmh); jmh.DateWritten = (uint32_t)utc_to_local(time(NULL)); jmh.Attribute |= JAM_MSG_LOCAL; - if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { + if (mc->realnames == 0) { strlcpy(buffer, user->loginname, sizeof(buffer)); } else { snprintf(buffer, sizeof buffer, "%s %s", user->firstname, user->lastname); @@ -2149,19 +2117,17 @@ void post_message(struct user_record *user) { jsf.Buffer = (char *)subject; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point) { + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, + mc->fidoaddr->point); } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -2169,11 +2135,9 @@ void post_message(struct user_record *user) { jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, + mc->fidoaddr->point, generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -2181,9 +2145,8 @@ void post_message(struct user_record *user) { jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_MAGI) { - sprintf(buffer, "%d", conf.mail_conferences[user->cur_mail_conf]->maginode); + } else if (mc->nettype == NETWORK_MAGI) { + snprintf(buffer, sizeof buffer, "%d", mc->maginode); jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -2200,26 +2163,24 @@ void post_message(struct user_record *user) { JAM_PutSubfield(jsp, &jsf); jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_QWK) { + } else if (mc->nettype == NETWORK_QWK) { jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(conf.bwave_name); jsf.Buffer = (char *)conf.bwave_name; JAM_PutSubfield(jsp, &jsf); } - } else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + } else if (ma->type == TYPE_NETMAIL_AREA) { jmh.Attribute |= JAM_MSG_TYPENET; jmh.Attribute |= JAM_MSG_PRIVATE; - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point) { + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, + mc->fidoaddr->point); } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -2229,14 +2190,12 @@ void post_message(struct user_record *user) { if (from_addr != NULL) { if (from_addr->point) { - sprintf(buffer, "%d:%d/%d.%d", from_addr->zone, - from_addr->net, - from_addr->node, - from_addr->point); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + from_addr->zone, from_addr->net, from_addr->node, + from_addr->point); } else { - sprintf(buffer, "%d:%d/%d", from_addr->zone, - from_addr->net, - from_addr->node); + snprintf(buffer, sizeof buffer, "%d:%d/%d", + from_addr->zone, from_addr->net, from_addr->node); } jsf.LoID = JAMSFLD_DADDRESS; jsf.HiID = 0; @@ -2247,11 +2206,12 @@ void post_message(struct user_record *user) { from_addr = NULL; } - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -2285,12 +2245,12 @@ void post_message(struct user_record *user) { if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { dolog("Failed to add message"); } else { - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { if (conf.netmail_sem != NULL) { sem_fd = open(conf.netmail_sem, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); close(sem_fd); } - } else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + } else if (ma->type == TYPE_ECHOMAIL_AREA || ma->type == TYPE_NEWSGROUP_AREA) { if (conf.echomail_sem != NULL) { sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); close(sem_fd); @@ -2326,18 +2286,22 @@ void list_messages(struct user_record *user) { int offset = 2; int height = 22; - if (conf.mail_conferences[gUser->cur_mail_conf]->header != NULL) { + struct mail_conference *gmc = get_conf(gUser->cur_mail_conf); + if (gmc->header != NULL) { offset = 8; height = 16; } + struct mail_conference *mc = get_user_conf(user); + s_printf("\r\n"); // list mail in message base msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user, 0); if (msghs != NULL && msghs->msg_count > 0) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + struct mail_area *ma = get_user_area(user); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", ma->path); return; } else { all_unread = 0; @@ -2382,9 +2346,9 @@ void list_messages(struct user_record *user) { start = i - 1; while (!closed) { if (redraw) { - if (conf.mail_conferences[user->cur_mail_conf]->header != NULL) { + if (mc->header != NULL) { s_printf("\e[2J\e[1;1H"); - s_displayansi(conf.mail_conferences[user->cur_mail_conf]->header); + s_displayansi(mc->header); s_printf("\e[7;1H"); } else { s_printf("\e[2J\e[1;1H"); @@ -2604,9 +2568,10 @@ void list_messages(struct user_record *user) { read_message(user, msghs, i - 1, 0); free_message_headers(msghs); msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user, 0); - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + struct mail_area *ma = get_user_area(user); + jb = open_jam_base(ma->path); if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + dolog("Error opening JAM base.. %s", ma->path); if (msghs != NULL) { free_message_headers(msghs); } @@ -2652,10 +2617,11 @@ void choose_conference() { struct ptr_vector vec; init_ptr_vector(&vec); - for (i = 0; i < conf.mail_conference_count; i++) { - if (conf.mail_conferences[i]->sec_level <= gUser->sec_level) { + for (i = 0; i < ptr_vector_len(&conf.mail_conferences); ++i) { + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, i); + if (mc->sec_level <= gUser->sec_level) { struct conf_tmp_t *c = (struct conf_tmp_t *)malloz(sizeof(struct conf_tmp_t)); - c->conference = conf.mail_conferences[i]; + c->conference = mc; c->index = i; ptr_vector_append(&vec, c); } @@ -2790,16 +2756,18 @@ void choose_area() { int height = 22; struct ptr_vector vec; - if (conf.mail_conferences[gUser->cur_mail_conf]->header != NULL) { + struct mail_conference *gmc = get_user_conf(gUser); + if (gmc->header != NULL) { offset = 8; height = 16; } init_ptr_vector(&vec); - for (i = 0; i < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; i++) { - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->read_sec_level <= gUser->sec_level) { + for (i = 0; i < ptr_vector_len(&gmc->mail_areas); ++i) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, i); + if (ma->read_sec_level <= gUser->sec_level) { struct area_tmp_t *area = (struct area_tmp_t *)malloz(sizeof(struct area_tmp_t)); - area->area = conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]; + area->area = ma; area->index = i; ptr_vector_append(&vec, area); } @@ -2809,14 +2777,15 @@ void choose_area() { while (1) { if (redraw) { - if (conf.mail_conferences[gUser->cur_mail_conf]->header != NULL) { + struct mail_conference *gmc = get_user_conf(gUser); + if (gmc->header != NULL) { s_printf("\e[2J\e[1;1H"); - s_displayansi(conf.mail_conferences[gUser->cur_mail_conf]->header); + s_displayansi(gmc->header); s_printf("\e[7;1H"); } else { s_printf("\e[2J\e[1;1H"); } - s_printf(get_string(251), conf.mail_conferences[gUser->cur_mail_conf]->name); + s_printf(get_string(251), gmc->name); s_printf(get_string(248)); for (i = start; i < start + height && i < list_tmp; i++) { if (i == selected) { @@ -2947,55 +2916,54 @@ void choose_area() { } void next_mail_conf(struct user_record *user) { - int i; - - for (i = user->cur_mail_conf; i < conf.mail_conference_count; i++) { - if (i + 1 == conf.mail_conference_count) { - i = -1; - } - if (conf.mail_conferences[i + 1]->sec_level <= user->sec_level) { - user->cur_mail_conf = i + 1; - user->cur_mail_area = 0; + size_t n = ptr_vector_len(&conf.mail_conferences); + size_t start = user->cur_mail_conf; + size_t i; + for (i = (start + 1) % n; i != start; i = (i + 1) % n) { + struct mail_conference *mc = get_conf(i); + if (mc->sec_level <= user->sec_level) { break; } } + user->cur_mail_conf = i; + user->cur_mail_area = 0; } void prev_mail_conf(struct user_record *user) { - int i; - for (i = user->cur_mail_conf; i >= 0; i--) { - if (i - 1 == -1) { - i = conf.mail_conference_count; - } - if (conf.mail_conferences[i - 1]->sec_level <= user->sec_level) { - user->cur_mail_conf = i - 1; - user->cur_mail_area = 0; + size_t n = ptr_vector_len(&conf.mail_conferences); + size_t start = user->cur_mail_conf; + size_t i; + for (i = (start + n - 1) % n; i != start; i = (i + n - 1) % n) { + struct mail_conference *mc = get_conf(i); + if (mc->sec_level <= user->sec_level) { break; } } + user->cur_mail_conf = i; + user->cur_mail_area = 0; } void next_mail_area(struct user_record *user) { - int i; - for (i = user->cur_mail_area; i < conf.mail_conferences[user->cur_mail_conf]->mail_area_count; i++) { - if (i + 1 == conf.mail_conferences[user->cur_mail_conf]->mail_area_count) { - i = -1; - } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i + 1]->read_sec_level <= user->sec_level) { - user->cur_mail_area = i + 1; + struct mail_conference *mc = get_user_conf(user); + size_t n = ptr_vector_len(&mc->mail_areas); + size_t start = user->cur_mail_area; + for (size_t i = (start + 1) % n; i != start; i = (i + 1) % n) { + struct mail_area *ma = get_area(user->cur_mail_conf, i); + if (ma->read_sec_level <= user->sec_level) { + user->cur_mail_area = i; break; } } } void prev_mail_area(struct user_record *user) { - int i; - for (i = user->cur_mail_area; i >= 0; i--) { - if (i - 1 == -1) { - i = conf.mail_conferences[user->cur_mail_conf]->mail_area_count; - } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i - 1]->read_sec_level <= user->sec_level) { - user->cur_mail_area = i - 1; + struct mail_conference *mc = get_user_conf(user); + size_t n = ptr_vector_len(&mc->mail_areas); + size_t start = user->cur_mail_area; + for (size_t i = (start + n - 1) % n; i != start; i = (i + n - 1) % n) { + struct mail_area *ma = get_area(user->cur_mail_conf, i); + if (ma->read_sec_level <= user->sec_level) { + user->cur_mail_area = i; break; } } @@ -3025,12 +2993,13 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { c = s_getc(); if (tolower(c) == 'y' || tolower(c) == 's') { - for (i = 0; i < conf.mail_conference_count; i++) { - if (conf.mail_conferences[i]->sec_level > user->sec_level) { + for (i = 0; i < ptr_vector_len(&conf.mail_conferences); i++) { + struct mail_conference *mc = get_conf(i); + if (mc->sec_level > user->sec_level) { continue; } if (oldscan) { - s_printf(get_string(140), i, conf.mail_conferences[i]->name); + s_printf(get_string(140), i, mc->name); lines += 2; if (lines == 22) { @@ -3039,8 +3008,9 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { lines = 0; } } - for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { - if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) { + for (j = 0; j < ptr_vector_len(&mc->mail_areas); j++) { + struct mail_area *ma = get_area(i, j); + if (ma->read_sec_level > user->sec_level) { continue; } @@ -3048,7 +3018,7 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { continue; } - jb = open_jam_base(conf.mail_conferences[i]->mail_areas[j]->path); + jb = open_jam_base(ma->path); if (!jb) { dolog("Unable to open message base"); continue; @@ -3066,12 +3036,12 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { free(jb); continue; } - if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { if (msghs->msg_count > 0) { if (oldscan) { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(141), j, ma->name, msghs->msg_count); lines++; if (lines == 22) { s_printf(get_string(6)); @@ -3080,8 +3050,8 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } } else { s_printf("\e[2J\e[1;1H"); - s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(277), i, mc->name); + s_printf(get_string(278), j, ma->name, msghs->msg_count); s_printf(get_string(279)); ch = s_getchar(); @@ -3104,7 +3074,7 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } } else { if (oldscan) { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs); + s_printf(get_string(141), j, ma->name, jbh.ActiveMsgs); lines++; if (lines == 22) { s_printf(get_string(6)); @@ -3117,8 +3087,8 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { if (msghs->msg_count > 0) { s_printf("\e[2J\e[1;1H"); - s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(277), i, mc->name); + s_printf(get_string(278), j, ma->name, msghs->msg_count); s_printf(get_string(279)); ch = s_getchar(); @@ -3142,8 +3112,7 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } } else { if (jlr.HighReadMsg < jbh.ActiveMsgs) { - - if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { + if (ma->type == TYPE_NETMAIL_AREA) { msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { if (msghs->msg_count > 0) { @@ -3157,7 +3126,7 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } if (unread_count > 0) { if (oldscan) { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(141), j, ma->name, unread_count); lines++; if (lines == 22) { s_printf(get_string(6)); @@ -3166,8 +3135,8 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } } else { s_printf("\e[2J\e[1;1H"); - s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(277), i, mc->name); + s_printf(get_string(278), j, ma->name, unread_count); s_printf(get_string(279)); ch = s_getchar(); @@ -3191,7 +3160,7 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } } else { if (oldscan) { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs - jlr.HighReadMsg); + s_printf(get_string(141), j, ma->name, jbh.ActiveMsgs - jlr.HighReadMsg); lines++; if (lines == 22) { s_printf(get_string(6)); @@ -3212,8 +3181,8 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) { } if (unread_count > 0) { s_printf("\e[2J\e[1;1H"); - s_printf(get_string(277), i, conf.mail_conferences[i]->name); - s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(277), i, mc->name); + s_printf(get_string(278), j, ma->name, unread_count); s_printf(get_string(279)); ch = s_getchar(); @@ -3280,10 +3249,11 @@ void msg_conf_sub_bases() { s_printf("\e[1;1H\e[2J"); do { - - for (i = 0; i < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; i++) { - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->read_sec_level <= gUser->sec_level) { - s_printf(get_string(226), i, (msgbase_is_subscribed(gUser->cur_mail_conf, i) ? get_string(227) : get_string(228)), conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[i]->name); + struct mail_conference *gmc = get_user_conf(gUser); + for (i = 0; i < ptr_vector_len(&gmc->mail_areas); i++) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, i); + if (ma->read_sec_level <= gUser->sec_level) { + s_printf(get_string(226), i, (msgbase_is_subscribed(gUser->cur_mail_conf, i) ? get_string(227) : get_string(228)), ma->name); lines++; } @@ -3294,16 +3264,17 @@ void msg_conf_sub_bases() { if (strlen(buffer) > 0) { if (buffer[0] >= '0' && buffer[0] <= '9') { toggle_area = atoi(buffer); - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[toggle_area]->read_sec_level <= gUser->sec_level) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, toggle_area); + if (ma->read_sec_level <= gUser->sec_level) { msgbase_sub_unsub(gUser->cur_mail_conf, toggle_area); } lines = 0; - break; } if (buffer[0] == 'a' || buffer[0] == 'A') { - for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { + for (j = 0; j < ptr_vector_len(&gmc->mail_areas); j++) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, j); + if (ma->read_sec_level <= gUser->sec_level) { if (!msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); } @@ -3312,8 +3283,9 @@ void msg_conf_sub_bases() { break; } if (buffer[0] == 'n' || buffer[0] == 'N') { - for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { + for (j = 0; j < ptr_vector_len(&gmc->mail_areas); j++) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, j); + if (ma->read_sec_level <= gUser->sec_level) { if (msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); } @@ -3333,21 +3305,24 @@ void msg_conf_sub_bases() { if (strlen(buffer) > 0) { if (buffer[0] >= '0' && buffer[0] <= '9') { toggle_area = atoi(buffer); - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[toggle_area]->read_sec_level <= gUser->sec_level) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, toggle_area); + if (ma->read_sec_level <= gUser->sec_level) { msgbase_sub_unsub(gUser->cur_mail_conf, toggle_area); } lines = 0; } else if (buffer[0] == 'a' || buffer[0] == 'A') { - for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { + for (j = 0; j < ptr_vector_len(&gmc->mail_areas); j++) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, j); + if (ma->read_sec_level <= gUser->sec_level) { if (!msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); } } } } else if (buffer[0] == 'n' || buffer[0] == 'N') { - for (j = 0; j < conf.mail_conferences[gUser->cur_mail_conf]->mail_area_count; j++) { - if (conf.mail_conferences[gUser->cur_mail_conf]->mail_areas[j]->read_sec_level <= gUser->sec_level) { + for (j = 0; j < ptr_vector_len(&gmc->mail_areas); j++) { + struct mail_area *ma = ptr_vector_get(&gmc->mail_areas, j); + if (ma->read_sec_level <= gUser->sec_level) { if (msgbase_is_subscribed(gUser->cur_mail_conf, j)) { msgbase_sub_unsub(gUser->cur_mail_conf, j); } @@ -3375,7 +3350,8 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { int active_msgs; int i, j, k; - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[msgarea]->path); + struct mail_area *ma = get_area(conference, msgarea); + jb = open_jam_base(ma->path); if (!jb) { dolog("Unable to open message base"); return; @@ -3432,12 +3408,10 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { } void msgbase_reset_all_pointers(int readm) { - int i, j; - - for (i = 0; i < conf.mail_conference_count; i++) { - for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { + for (size_t i = 0; i < ptr_vector_len(&conf.mail_conferences); ++i) { + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, i); + for (size_t j = 0; j < ptr_vector_len(&mc->mail_areas); ++j) msgbase_reset_pointers(i, j, readm, -1); - } } } @@ -3448,7 +3422,8 @@ int new_messages(struct user_record *user, int conference, int area) { s_JamLastRead jlr; struct msg_headers *msghs; - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + struct mail_area *ma = get_area(conference, area); + jb = open_jam_base(ma->path); if (!jb) { return 0; } diff --git a/src/mail_utils.h b/src/mail_utils.h new file mode 100644 index 0000000..a863973 --- /dev/null +++ b/src/mail_utils.h @@ -0,0 +1,28 @@ +#include +#include + +#include "bbs.h" + +static inline struct mail_conference *get_conf(size_t c) { + extern struct bbs_config conf; + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, c); + assert(mc != NULL); + return mc; +} + +static inline struct mail_conference *get_user_conf(struct user_record *user) { + assert(user != NULL); + return get_conf(user->cur_mail_conf); +} + +static inline struct mail_area *get_area(size_t c, size_t a) { + struct mail_conference *mc = get_conf(c); + struct mail_area *ma = ptr_vector_get(&mc->mail_areas, a); + assert(ma != NULL); + return ma; +} + +static inline struct mail_area *get_user_area(struct user_record *user) { + assert(user != NULL); + return get_area(user->cur_mail_conf, user->cur_mail_area); +} diff --git a/src/main.c b/src/main.c index b14fa96..c6bb4ab 100644 --- a/src/main.c +++ b/src/main.c @@ -83,75 +83,37 @@ void sigchld_handler(int s) { static int protocol_config_handler(void *user, const char *section, const char *name, const char *value) { struct bbs_config *conf = (struct bbs_config *)user; - int i; - for (i = 0; i < conf->protocol_count; i++) { - if (strcasecmp(conf->protocols[i]->name, section) == 0) { - // found it - if (strcasecmp(name, "upload command") == 0) { - conf->protocols[i]->upload = strdup(value); - } else if (strcasecmp(name, "download command") == 0) { - conf->protocols[i]->download = strdup(value); - } else if (strcasecmp(name, "internal zmodem") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->protocols[i]->internal_zmodem = 1; - } else { - conf->protocols[i]->internal_zmodem = 0; - } - } else if (strcasecmp(name, "stdio") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->protocols[i]->stdio = 1; - } else { - conf->protocols[i]->stdio = 0; - } - } else if (strcasecmp(name, "upload prompt") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->protocols[i]->upload_prompt = 1; - } else { - conf->protocols[i]->upload_prompt = 0; - } - } - return 1; + struct protocol *proto = NULL; + for (size_t i = 0; i < ptr_vector_len(&conf->protocols); ++i) { + struct protocol *aproto = ptr_vector_get(&conf->protocols, i); + assert(aproto != NULL); + if (strcasecmp(aproto->name, section) == 0) { + proto = aproto; + break; } } - - if (conf->protocol_count == 0) { - conf->protocols = (struct protocol **)malloz(sizeof(struct protocol *)); - } else { - conf->protocols = (struct protocol **)realloc(conf->protocols, sizeof(struct protocol *) * (conf->protocol_count + 1)); + if (proto == NULL) { + proto = (struct protocol *)malloz(sizeof(struct protocol)); + ptr_vector_append(&conf->protocols, proto); + proto->name = strdup(section); + proto->internal_zmodem = 0; + proto->upload_prompt = 0; + proto->stdio = 0; } - - conf->protocols[conf->protocol_count] = (struct protocol *)malloz(sizeof(struct protocol)); - - conf->protocols[conf->protocol_count]->name = strdup(section); - conf->protocols[conf->protocol_count]->internal_zmodem = 0; - conf->protocols[conf->protocol_count]->upload_prompt = 0; - conf->protocols[conf->protocol_count]->stdio = 0; - if (strcasecmp(name, "upload command") == 0) { - conf->protocols[conf->protocol_count]->upload = strdup(value); + free(proto->upload); + proto->upload = strdup(value); } else if (strcasecmp(name, "download command") == 0) { - conf->protocols[conf->protocol_count]->download = strdup(value); + free(proto->download); + proto->download = strdup(value); } else if (strcasecmp(name, "internal zmodem") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->protocols[conf->protocol_count]->internal_zmodem = 1; - } else { - conf->protocols[conf->protocol_count]->internal_zmodem = 0; - } + proto->internal_zmodem = (strcasecmp(value, "true") == 0); } else if (strcasecmp(name, "stdio") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->protocols[conf->protocol_count]->stdio = 1; - } else { - conf->protocols[conf->protocol_count]->stdio = 0; - } + proto->stdio = (strcasecmp(value, "true") == 0); } else if (strcasecmp(name, "upload prompt") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->protocols[conf->protocol_count]->upload_prompt = 1; - } else { - conf->protocols[conf->protocol_count]->upload_prompt = 0; - } + proto->upload_prompt = (strcasecmp(value, "true") == 0); } - conf->protocol_count++; return 1; } @@ -159,40 +121,31 @@ static int protocol_config_handler(void *user, const char *section, const char * static int archiver_config_handler(void *user, const char *section, const char *name, const char *value) { struct bbs_config *conf = (struct bbs_config *)user; - int i; - for (i = 0; i < conf->archiver_count; i++) { - if (strcasecmp(conf->archivers[i]->name, section) == 0) { - // found it - if (strcasecmp(name, "extension") == 0) { - conf->archivers[i]->extension = strdup(value); - } else if (strcasecmp(name, "unpack") == 0) { - conf->archivers[i]->unpack = strdup(value); - } else if (strcasecmp(name, "pack") == 0) { - conf->archivers[i]->pack = strdup(value); - } - return 1; + struct archiver *arc = NULL; + for (size_t i = 0; i < ptr_vector_len(&conf->archivers); ++i) { + struct archiver *anarc = ptr_vector_get(&conf->archivers, i); + if (strcasecmp(anarc->name, section) == 0) { + arc = anarc; // hy in the UK. + break; } } + if (arc == NULL) { + arc = malloz(sizeof(struct archiver)); + ptr_vector_append(&conf->archivers, arc); - if (conf->archiver_count == 0) { - conf->archivers = (struct archiver **)malloz(sizeof(struct archiver *)); - } else { - conf->archivers = (struct archiver **)realloc(conf->archivers, sizeof(struct archiver *) * (conf->archiver_count + 1)); + arc->name = strdup(section); } - - conf->archivers[conf->archiver_count] = (struct archiver *)malloz(sizeof(struct archiver)); - - conf->archivers[conf->archiver_count]->name = strdup(section); - if (strcasecmp(name, "extension") == 0) { - conf->archivers[conf->archiver_count]->extension = strdup(value); + free(arc->extension); + arc->extension = strdup(value); } else if (strcasecmp(name, "unpack") == 0) { - conf->archivers[conf->archiver_count]->unpack = strdup(value); + free(arc->unpack); + arc->unpack = strdup(value); } else if (strcasecmp(name, "pack") == 0) { - conf->archivers[conf->archiver_count]->pack = strdup(value); + free(arc->pack); + arc->pack = strdup(value); } - conf->archiver_count++; return 1; } @@ -200,49 +153,31 @@ static int archiver_config_handler(void *user, const char *section, const char * static int door_config_handler(void *user, const char *section, const char *name, const char *value) { struct bbs_config *conf = (struct bbs_config *)user; - int i; - for (i = 0; i < conf->door_count; i++) { - if (strcasecmp(conf->doors[i]->name, section) == 0) { - // found it - if (strcasecmp(name, "command") == 0) { - conf->doors[i]->command = strdup(value); - } else if (strcasecmp(name, "stdio") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->doors[i]->stdio = 1; - } else { - conf->doors[i]->stdio = 0; - } - } else if (strcasecmp(name, "codepage") == 0) { - conf->doors[i]->codepage = strdup(value); - } - return 1; + struct door_config *door = NULL; + for (size_t i = 0; i < ptr_vector_len(&conf->doors); ++i) { + struct door_config *adoor = ptr_vector_get(&conf->doors, i); + assert(adoor != NULL); + if (strcasecmp(adoor->name, section) == 0) { + door = adoor; + break; } } - - if (conf->door_count == 0) { - conf->doors = (struct door_config **)malloz(sizeof(struct door_config *)); - } else { - conf->doors = (struct door_config **)realloc(conf->doors, sizeof(struct door_config *) * (conf->door_count + 1)); + if (door == NULL) { + door = malloz(sizeof(struct door_config)); + ptr_vector_append(&conf->doors, door); + door->name = strdup(section); + door->codepage = NULL; } - - conf->doors[conf->door_count] = (struct door_config *)malloz(sizeof(struct door_config)); - - conf->doors[conf->door_count]->name = strdup(section); - conf->doors[conf->door_count]->codepage = NULL; - if (strcasecmp(name, "command") == 0) { - conf->doors[conf->door_count]->command = strdup(value); + free(door->command); + door->command = strdup(value); } else if (strcasecmp(name, "stdio") == 0) { - if (strcasecmp(value, "true") == 0) { - conf->doors[conf->door_count]->stdio = 1; - } else { - conf->doors[conf->door_count]->stdio = 0; - } + door->stdio = (strcasecmp(value, "true") == 0); } else if (strcasecmp(name, "codepage") == 0) { - conf->doors[conf->door_count]->codepage = strdup(value); + free(door->codepage); + door->codepage = strdup(value); } - conf->door_count++; return 1; } @@ -250,53 +185,40 @@ static int door_config_handler(void *user, const char *section, const char *name static int file_sub_handler(void *user, const char *section, const char *name, const char *value) { struct file_directory *fd = (struct file_directory *)user; - int i; if (strcasecmp(section, "main") == 0) { if (strcasecmp(name, "visible sec level") == 0) { fd->sec_level = atoi(value); } else if (strcasecmp(name, "visible on web") == 0) { - if (strcasecmp(value, "true") == 0) { - fd->display_on_web = 1; - } else { - fd->display_on_web = 0; - } + fd->display_on_web = (strcasecmp(value, "true") == 0); } - } else { - // check if it's partially filled in - for (i = 0; i < fd->file_sub_count; i++) { - if (strcasecmp(fd->file_subs[i]->name, section) == 0) { - if (strcasecmp(name, "upload sec level") == 0) { - fd->file_subs[i]->upload_sec_level = atoi(value); - } else if (strcasecmp(name, "download sec level") == 0) { - fd->file_subs[i]->download_sec_level = atoi(value); - } else if (strcasecmp(name, "database") == 0) { - fd->file_subs[i]->database = strdup(value); - } else if (strcasecmp(name, "upload path") == 0) { - fd->file_subs[i]->upload_path = strdup(value); - } - return 1; - } + return 1; + } + // check if it's partially filled in + struct file_sub *sub = NULL; + for (size_t i = 0; i < ptr_vector_len(&fd->file_subs); ++i) { + struct file_sub *asub = ptr_vector_get(&fd->file_subs, i); + assert(asub != NULL); + if (strcasecmp(asub->name, section) == 0) { + sub = asub; + break; } - if (fd->file_sub_count == 0) { - fd->file_subs = (struct file_sub **)malloz(sizeof(struct file_sub *)); - } else { - fd->file_subs = (struct file_sub **)realloc(fd->file_subs, sizeof(struct file_sub *) * (fd->file_sub_count + 1)); - } - - fd->file_subs[fd->file_sub_count] = (struct file_sub *)malloz(sizeof(struct file_sub)); - - fd->file_subs[fd->file_sub_count]->name = strdup(section); - if (strcasecmp(name, "upload sec level") == 0) { - fd->file_subs[fd->file_sub_count]->upload_sec_level = atoi(value); - } else if (strcasecmp(name, "download sec level") == 0) { - fd->file_subs[fd->file_sub_count]->download_sec_level = atoi(value); - } else if (strcasecmp(name, "database") == 0) { - fd->file_subs[fd->file_sub_count]->database = strdup(value); - } else if (strcasecmp(name, "upload path") == 0) { - fd->file_subs[fd->file_sub_count]->upload_path = strdup(value); - } - fd->file_sub_count++; + } + if (sub == NULL) { + sub = (struct file_sub *)malloz(sizeof(struct file_sub)); + ptr_vector_append(&fd->file_subs, sub); + sub->name = strdup(section); + } + if (strcasecmp(name, "upload sec level") == 0) { + sub->upload_sec_level = atoi(value); + } else if (strcasecmp(name, "download sec level") == 0) { + sub->download_sec_level = atoi(value); + } else if (strcasecmp(name, "database") == 0) { + free(sub->database); + sub->database = strdup(value); + } else if (strcasecmp(name, "upload path") == 0) { + free(sub->upload_path); + sub->upload_path = strdup(value); } return 1; } @@ -304,26 +226,19 @@ static int file_sub_handler(void *user, const char *section, const char *name, static int mail_area_handler(void *user, const char *section, const char *name, const char *value) { struct mail_conference *mc = (struct mail_conference *)user; - int i; if (strcasecmp(section, "main") == 0) { if (strcasecmp(name, "visible sec level") == 0) { mc->sec_level = atoi(value); } else if (strcasecmp(name, "networked") == 0) { - if (strcasecmp(value, "true") == 0) { - mc->networked = 1; - } else { - mc->networked = 0; - } + mc->networked = (strcasecmp(value, "true") == 0); } else if (strcasecmp(name, "real names") == 0) { - if (strcasecmp(value, "true") == 0) { - mc->realnames = 1; - } else { - mc->realnames = 0; - } + mc->realnames = (strcasecmp(value, "true") == 0); } else if (strcasecmp(name, "tagline") == 0) { + free(mc->tagline); mc->tagline = strdup(value); } else if (strcasecmp(name, "header") == 0) { + free(mc->header); mc->header = strdup(value); } } else if (strcasecmp(section, "network") == 0) { @@ -338,74 +253,48 @@ static int mail_area_handler(void *user, const char *section, const char *name, } else if (strcasecmp(name, "fido node") == 0) { mc->fidoaddr = parse_fido_addr(value); } else if (strcasecmp(name, "domain") == 0) { + free(mc->domain); mc->domain = strdup(value); } else if (strcasecmp(name, "magi node") == 0) { mc->maginode = atoi(value); } } else { // check if it's partially filled in - for (i = 0; i < mc->mail_area_count; i++) { - if (strcasecmp(mc->mail_areas[i]->name, section) == 0) { - if (strcasecmp(name, "read sec level") == 0) { - mc->mail_areas[i]->read_sec_level = atoi(value); - } else if (strcasecmp(name, "write sec level") == 0) { - mc->mail_areas[i]->write_sec_level = atoi(value); - } else if (strcasecmp(name, "path") == 0) { - mc->mail_areas[i]->path = strdup(value); - } else if (strcasecmp(name, "type") == 0) { - if (strcasecmp(value, "local") == 0) { - mc->mail_areas[i]->type = TYPE_LOCAL_AREA; - } else if (strcasecmp(value, "echo") == 0) { - mc->mail_areas[i]->type = TYPE_ECHOMAIL_AREA; - } else if (strcasecmp(value, "netmail") == 0) { - mc->mail_areas[i]->type = TYPE_NETMAIL_AREA; - } else if (strcasecmp(value, "newsgroup") == 0) { - mc->mail_areas[i]->type = TYPE_NEWSGROUP_AREA; - } - } else if (strcasecmp(name, "qwk name") == 0) { - mc->mail_areas[i]->qwkname = strdup(value); - if (strlen(mc->mail_areas[i]->qwkname) > 8) { - mc->mail_areas[i]->qwkname[8] = '\0'; - } - } - return 1; + struct mail_area *area = NULL; + for (size_t i = 0; i < ptr_vector_len(&mc->mail_areas); ++i) { + struct mail_area *anarea = ptr_vector_get(&mc->mail_areas, i); + if (strcasecmp(anarea->name, section) == 0) { + area = anarea; + break; } } - if (mc->mail_area_count == 0) { - mc->mail_areas = (struct mail_area **)malloz(sizeof(struct mail_area *)); - } else { - mc->mail_areas = (struct mail_area **)realloc(mc->mail_areas, sizeof(struct mail_area *) * (mc->mail_area_count + 1)); + if (area == NULL) { + area = (struct mail_area *)malloz(sizeof(struct mail_area)); + ptr_vector_append(&mc->mail_areas, area); + area->qwkname = NULL; + area->name = strdup(section); } - - mc->mail_areas[mc->mail_area_count] = (struct mail_area *)malloz(sizeof(struct mail_area)); - - mc->mail_areas[mc->mail_area_count]->qwkname = NULL; - - mc->mail_areas[mc->mail_area_count]->name = strdup(section); if (strcasecmp(name, "read sec level") == 0) { - mc->mail_areas[mc->mail_area_count]->read_sec_level = atoi(value); + area->read_sec_level = atoi(value); } else if (strcasecmp(name, "write sec level") == 0) { - mc->mail_areas[mc->mail_area_count]->write_sec_level = atoi(value); + area->write_sec_level = atoi(value); } else if (strcasecmp(name, "path") == 0) { - mc->mail_areas[mc->mail_area_count]->path = strdup(value); + area->path = strdup(value); } else if (strcasecmp(name, "type") == 0) { if (strcasecmp(value, "local") == 0) { - mc->mail_areas[mc->mail_area_count]->type = TYPE_LOCAL_AREA; + area->type = TYPE_LOCAL_AREA; } else if (strcasecmp(value, "echo") == 0) { - mc->mail_areas[mc->mail_area_count]->type = TYPE_ECHOMAIL_AREA; + area->type = TYPE_ECHOMAIL_AREA; } else if (strcasecmp(value, "netmail") == 0) { - mc->mail_areas[mc->mail_area_count]->type = TYPE_NETMAIL_AREA; + area->type = TYPE_NETMAIL_AREA; } else if (strcasecmp(value, "newsgroup") == 0) { - mc->mail_areas[mc->mail_area_count]->type = TYPE_NEWSGROUP_AREA; + area->type = TYPE_NEWSGROUP_AREA; } } else if (strcasecmp(name, "qwk name") == 0) { - mc->mail_areas[mc->mail_area_count]->qwkname = strdup(value); - if (strlen(mc->mail_areas[mc->mail_area_count]->qwkname) > 8) { - mc->mail_areas[mc->mail_area_count]->qwkname[8] = '\0'; - } + area->qwkname = strndup(value, 8); } - mc->mail_area_count++; } + return 1; } @@ -564,45 +453,27 @@ static int handler(void *user, const char *section, const char *name, conf->menu_path = strdup(value); } } else if (strcasecmp(section, "mail conferences") == 0) { - if (conf->mail_conference_count == 0) { - conf->mail_conferences = (struct mail_conference **)malloz(sizeof(struct mail_conference *)); - } else { - conf->mail_conferences = (struct mail_conference **)realloc(conf->mail_conferences, sizeof(struct mail_conference *) * (conf->mail_conference_count + 1)); - } - - conf->mail_conferences[conf->mail_conference_count] = (struct mail_conference *)malloz(sizeof(struct mail_conference)); - conf->mail_conferences[conf->mail_conference_count]->name = strdup(name); - conf->mail_conferences[conf->mail_conference_count]->path = strdup(value); - conf->mail_conferences[conf->mail_conference_count]->tagline = NULL; - conf->mail_conferences[conf->mail_conference_count]->mail_area_count = 0; - conf->mail_conferences[conf->mail_conference_count]->nettype = 0; - conf->mail_conferences[conf->mail_conference_count]->domain = NULL; - conf->mail_conferences[conf->mail_conference_count]->header = NULL; - conf->mail_conference_count++; + struct mail_conference *conference = malloz(sizeof(struct mail_conference)); + conference->name = strdup(name); + conference->path = strdup(value); + conference->tagline = NULL; + init_ptr_vector(&conference->mail_areas); + conference->nettype = 0; + conference->domain = NULL; + conference->header = NULL; + ptr_vector_append(&conf->mail_conferences, conference); } else if (strcasecmp(section, "file directories") == 0) { - if (conf->file_directory_count == 0) { - conf->file_directories = (struct file_directory **)malloz(sizeof(struct file_directory *)); - } else { - conf->file_directories = (struct file_directory **)realloc(conf->file_directories, sizeof(struct file_directory *) * (conf->file_directory_count + 1)); - } - - conf->file_directories[conf->file_directory_count] = (struct file_directory *)malloz(sizeof(struct file_directory)); - conf->file_directories[conf->file_directory_count]->name = strdup(name); - conf->file_directories[conf->file_directory_count]->path = strdup(value); - conf->file_directories[conf->file_directory_count]->file_sub_count = 0; - conf->file_directories[conf->file_directory_count]->display_on_web = 0; - conf->file_directory_count++; + struct file_directory *dir = malloz(sizeof(struct file_directory)); + dir->name = strdup(name); + dir->path = strdup(value); + init_ptr_vector(&dir->file_subs); + dir->display_on_web = 0; + ptr_vector_append(&conf->file_directories, dir); } else if (strcasecmp(section, "text files") == 0) { - if (conf->text_file_count == 0) { - conf->text_files = (struct text_file **)malloz(sizeof(struct text_file *)); - } else { - conf->text_files = (struct text_file **)realloc(conf->text_files, sizeof(struct text_file *) * (conf->text_file_count + 1)); - } - - conf->text_files[conf->text_file_count] = (struct text_file *)malloz(sizeof(struct text_file)); - conf->text_files[conf->text_file_count]->name = strdup(name); - conf->text_files[conf->text_file_count]->path = strdup(value); - conf->text_file_count++; + struct text_file *file = malloz(sizeof(struct text_file)); + file->name = strdup(name); + file->path = strdup(value); + ptr_vector_append(&conf->text_files, file); } return 1; @@ -1268,13 +1139,13 @@ int main(int argc, char **argv) { exit(1); } - conf.mail_conference_count = 0; - conf.door_count = 0; - conf.file_directory_count = 0; + init_ptr_vector(&conf.mail_conferences); + init_ptr_vector(&conf.doors); + init_ptr_vector(&conf.file_directories); conf.mgchat_server = NULL; conf.mgchat_port = 2025; conf.mgchat_bbstag = NULL; - conf.text_file_count = 0; + init_ptr_vector(&conf.text_files); conf.external_editor_cmd = NULL; conf.external_editor_codepage = NULL; conf.log_path = NULL; @@ -1286,7 +1157,7 @@ int main(int argc, char **argv) { conf.string_file = NULL; conf.www_path = NULL; conf.www_url = NULL; - conf.archiver_count = 0; + init_ptr_vector(&conf.archivers); conf.broadcast_enable = 0; conf.broadcast_port = 0; conf.broadcast_address = NULL; @@ -1297,12 +1168,13 @@ int main(int argc, char **argv) { conf.ipguard_enable = 0; conf.ipguard_tries = 4; conf.ipguard_timeout = 120; - conf.protocol_count = 0; + init_ptr_vector(&conf.protocols); conf.codepage = 0; conf.date_style = 0; conf.ipv6 = 0; conf.uid = getuid(); conf.gid = getgid(); + // Load BBS data if (ini_parse(argv[1], handler, &conf) < 0) { fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); @@ -1320,22 +1192,24 @@ int main(int argc, char **argv) { } // Load mail Areas - for (i = 0; i < conf.mail_conference_count; i++) { - if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) < 0) { - fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path); + for (i = 0; i < ptr_vector_len(&conf.mail_conferences); i++) { + struct mail_conference *conference = ptr_vector_get(&conf.mail_conferences, i); + if (ini_parse(conference->path, mail_area_handler, conference) < 0) { + fprintf(stderr, "Unable to load configuration ini (%s)!\n", conference->path); exit(-1); } } + // Load file Subs - for (i = 0; i < conf.file_directory_count; i++) { - if (ini_parse(conf.file_directories[i]->path, file_sub_handler, conf.file_directories[i]) < 0) { - fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path); + for (i = 0; i < ptr_vector_len(&conf.file_directories); i++) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, i); + if (ini_parse(dir->path, file_sub_handler, dir) < 0) { + fprintf(stderr, "Unable to load configuration ini (%s)!\n", dir->path); exit(-1); } } snprintf(buffer, 1024, "%s/doors.ini", conf.config_path); - if (ini_parse(buffer, door_config_handler, &conf) < 0) { fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n"); exit(-1); diff --git a/src/main_menu.c b/src/main_menu.c index 08503b1..1b7a433 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -93,7 +93,7 @@ void display_textfiles() { int selected = 0; char c; - if (conf.text_file_count == 0) { + if (ptr_vector_len(&conf.text_files) == 0) { s_printf("\e[2J\e[1;1H"); s_printf(get_string(148)); s_printf(get_string(185)); @@ -107,12 +107,9 @@ void display_textfiles() { s_printf("\e[2J\e[1;1H"); s_printf(get_string(143)); s_printf(get_string(144)); - for (i = start; i < start + 22 && i < conf.text_file_count; i++) { - if (i == selected) { - s_printf(get_string(249), i - start + 2, i, conf.text_files[i]->name); - } else { - s_printf(get_string(250), i - start + 2, i, conf.text_files[i]->name); - } + for (size_t i = start; i < start + 22 && i < ptr_vector_len(&conf.text_files); i++) { + struct text_file *file = ptr_vector_get(&conf.text_files, i); + s_printf(get_string(i == selected ? 249 : 250), i - start + 2, i, file->name); } s_printf("\e[%d;5H", selected - start + 2); redraw = 0; @@ -128,18 +125,22 @@ void display_textfiles() { // down if (selected + 1 >= start + 22) { start += 22; - if (start >= conf.text_file_count) { - start = conf.text_file_count - 22; + if (start >= ptr_vector_len(&conf.text_files)) { + start = ptr_vector_len(&conf.text_files) - 22; } redraw = 1; } selected++; - if (selected >= conf.text_file_count) { - selected = conf.text_file_count - 1; + if (selected >= ptr_vector_len(&conf.text_files)) { + selected = ptr_vector_len(&conf.text_files) - 1; } else { if (!redraw) { - s_printf(get_string(250), selected - start + 1, selected - 1, conf.text_files[selected - 1]->name); - s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name); + struct text_file *prev_file = ptr_vector_get(&conf.text_files, selected - 1); + struct text_file *file = ptr_vector_get(&conf.text_files, selected); + assert(prev_file != NULL); + assert(file != NULL); + s_printf(get_string(250), selected - start + 1, selected - 1, prev_file->name); + s_printf(get_string(249), selected - start + 2, selected, file->name); s_printf("\e[%d;5H", selected - start + 2); } } @@ -157,15 +158,17 @@ void display_textfiles() { selected = 0; } else { if (!redraw) { - s_printf(get_string(249), selected - start + 2, selected, conf.text_files[selected]->name); - s_printf(get_string(250), selected - start + 3, selected + 1, conf.text_files[selected + 1]->name); + struct text_file *file = ptr_vector_get(&conf.text_files, selected); + struct text_file *next_file = ptr_vector_get(&conf.text_files, selected + 1); + s_printf(get_string(249), selected - start + 2, selected, file->name); + s_printf(get_string(250), selected - start + 3, selected + 1, next_file->name); s_printf("\e[%d;5H", selected - start + 2); } } } else if (c == 75) { // END KEY - selected = conf.text_file_count - 1; - start = conf.text_file_count - 22; + selected = ptr_vector_len(&conf.text_files) - 1; + start = selected - 21; if (start < 0) { start = 0; } @@ -192,16 +195,18 @@ void display_textfiles() { } // PAGE DOWN selected = selected + 22; - if (selected >= conf.text_file_count) { - selected = conf.text_file_count - 1; + if (selected >= ptr_vector_len(&conf.text_files)) { + selected = ptr_vector_len(&conf.text_files) - 1; } start = selected; redraw = 1; } } } else if (c == 13) { + struct text_file *file = ptr_vector_get(&conf.text_files, selected); + assert(file != NULL); s_printf("\e[2J\e[1;1H"); - s_displayansi_p(conf.text_files[selected]->path); + s_displayansi_p(file->path); s_printf(get_string(185)); s_getc(); s_printf("\r\n"); diff --git a/src/menus.c b/src/menus.c index da5803e..98dd79a 100644 --- a/src/menus.c +++ b/src/menus.c @@ -3,11 +3,13 @@ #include #include #include -#include "bbs.h" + #include "lua/lua.h" #include "lua/lualib.h" #include "lua/lauxlib.h" +#include "bbs.h" + #define MENU_SUBMENU 1 #define MENU_LOGOFF 2 #define MENU_PREVMENU 3 @@ -382,12 +384,13 @@ int menu_system(char *menufile) { settings_menu(gUser); break; case MENU_DOOR: { - for (m = 0; m < conf.door_count; m++) { - if (strcasecmp(cmd->data, conf.doors[m]->name) == 0) { - dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); - broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name); - rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage); - dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); + for (m = 0; m < ptr_vector_len(&conf.doors); m++) { + struct door_config *door = ptr_vector_get(&conf.doors, m); + if (strcasecmp(cmd->data, door->name) == 0) { + dolog("%s launched door %s, on node %d", gUser->loginname, door->name, mynode); + broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, door->name); + rundoor(gUser, door->command, door->stdio, door->codepage); + dolog("%s returned from door %s, on node %d", gUser->loginname, door->name, mynode); break; } } @@ -452,14 +455,19 @@ int menu_system(char *menufile) { broadcast("USER: %s; NODE:%d; STATUS: Browsing Files.", gUser->loginname, mynode); list_files(gUser); break; - case MENU_UPLOAD: - if (gUser->sec_level >= conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->upload_sec_level) { + case MENU_UPLOAD: { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, gUser->cur_file_dir); + assert(dir != NULL); + struct file_sub *sub = ptr_vector_get(&dir->file_subs, gUser->cur_file_sub); + assert(sub != NULL); + if (gUser->sec_level >= sub->upload_sec_level) { broadcast("USER: %s; NODE:%d; STATUS: Uploading a File.", gUser->loginname, mynode); upload(gUser); } else { s_printf(get_string(84)); } break; + } case MENU_DOWNLOAD: broadcast("USER: %s; NODE:%d; STATUS: Downloading Files.", gUser->loginname, mynode); download(gUser); diff --git a/src/nodelist.c b/src/nodelist.c index fa6be92..4a1ef49 100644 --- a/src/nodelist.c +++ b/src/nodelist.c @@ -93,7 +93,9 @@ void nl_browser() { return; } - sqlite3_bind_text(res, 1, conf.mail_conferences[gUser->cur_mail_conf]->domain, -1, 0); + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, gUser->cur_mail_conf); + assert(mc != NULL); + sqlite3_bind_text(res, 1, mc->domain, -1, 0); init_ptr_vector(&vec); while (sqlite3_step(res) == SQLITE_ROW) { diff --git a/src/settings.c b/src/settings.c index f6e90fe..c7e7e74 100644 --- a/src/settings.c +++ b/src/settings.c @@ -16,12 +16,14 @@ void settings_menu(struct user_record *user) { char *sig; while (!dosettings) { + struct archiver *arc = ptr_vector_get(&conf.archivers, user->defarchiver - 1); + struct protocol *proto = ptr_vector_get(&conf.protocols, user->defprotocol - 1); s_printf(get_string(149)); s_printf(get_string(150)); s_printf(get_string(151)); s_printf(get_string(152), user->location); - 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(205), arc->name); + s_printf(get_string(213), proto->name); s_printf(get_string(215), (user->nodemsgs ? "TRUE" : "FALSE")); s_printf(get_string(221), (user->codepage ? "UTF-8" : "CP437")); switch (user->exteditor) { @@ -84,15 +86,16 @@ void settings_menu(struct user_record *user) { case 'a': { s_printf(get_string(206)); - for (i = 0; i < conf.archiver_count; i++) { - s_printf(get_string(207), i + 1, conf.archivers[i]->name); + for (i = 0; i < ptr_vector_len(&conf.archivers); i++) { + struct archiver *arc = ptr_vector_get(&conf.archivers, i); + s_printf(get_string(207), i + 1, arc->name); } s_printf(get_string(208)); s_readstring(buffer, 5); new_arc = atoi(buffer); - if (new_arc - 1 < 0 || new_arc > conf.archiver_count) { + if (new_arc - 1 < 0 || new_arc > ptr_vector_len(&conf.archivers)) { break; } else { user->defarchiver = new_arc; @@ -103,15 +106,16 @@ void settings_menu(struct user_record *user) { case 'o': { s_printf(get_string(212)); - for (i = 0; i < conf.protocol_count; i++) { - s_printf(get_string(207), i + 1, conf.protocols[i]->name); + for (i = 0; i < ptr_vector_len(&conf.protocols); i++) { + struct protocol *proto = ptr_vector_get(&conf.protocols, i); + s_printf(get_string(207), i + 1, proto->name); } s_printf(get_string(208)); s_readstring(buffer, 5); new_arc = atoi(buffer); - if (new_arc - 1 < 0 || new_arc > conf.protocol_count) { + if (new_arc - 1 < 0 || new_arc > ptr_vector_len(&conf.protocols)) { break; } else { user->defprotocol = new_arc; diff --git a/src/users.c b/src/users.c index 9508e43..3e45416 100644 --- a/src/users.c +++ b/src/users.c @@ -486,16 +486,20 @@ struct user_record *check_user_pass(char *loginname, char *password) { dolog("Unable to load sec Level ini (%s)!", pathbuf); exit(-1); } - if (user->cur_mail_conf >= conf.mail_conference_count) { + if (user->cur_mail_conf >= ptr_vector_len(&conf.mail_conferences)) { user->cur_mail_conf = 0; } - if (user->cur_file_dir >= conf.file_directory_count) { + if (user->cur_file_dir >= ptr_vector_len(&conf.file_directories)) { user->cur_file_dir = 0; } - if (user->cur_mail_area >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count) { + struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, user->cur_mail_conf); + assert(mc != NULL); + if (user->cur_mail_area >= ptr_vector_len(&mc->mail_areas)) { user->cur_mail_area = 0; } - if (user->cur_file_sub >= conf.file_directories[user->cur_file_dir]->file_sub_count) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, user->cur_file_dir); + assert(dir != NULL); + if (user->cur_file_sub >= ptr_vector_len(&dir->file_subs)) { user->cur_file_sub = 0; } diff --git a/src/www.c b/src/www.c index 453ecf2..eff92d5 100644 --- a/src/www.c +++ b/src/www.c @@ -789,14 +789,17 @@ int www_handler(void *cls, struct MHD_Connection *connection, const char *url, c free(url_copy); if (file_dir != -1 && file_sub != -1 && filen == NULL) { - if (file_dir >= 0 && file_dir < conf.file_directory_count && file_sub >= 0 && file_sub < conf.file_directories[file_dir]->file_sub_count) { - if (conf.file_directories[file_dir]->display_on_web) { + if (file_dir >= 0 && file_dir < ptr_vector_len(&conf.file_directories)) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, file_dir); + assert(dir != NULL); + if (dir->display_on_web && file_sub >= 0 && file_sub < ptr_vector_len(&dir->file_subs)) { page = www_files_display_listing(file_dir, file_sub); } } } else if (file_dir != -1 && file_sub != -1 && filen != NULL) { - if (file_dir >= 0 && file_dir < conf.file_directory_count && file_sub >= 0 && file_sub < conf.file_directories[file_dir]->file_sub_count) { - if (conf.file_directories[file_dir]->display_on_web) { + if (file_dir >= 0 && file_dir < ptr_vector_len(&conf.file_directories)) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, file_dir); + if (dir->display_on_web && file_sub >= 0 && file_sub < ptr_vector_len(&dir->file_subs)) { // send file filename = www_files_get_from_area(file_dir, file_sub, filen); free(filen); diff --git a/src/www_files.c b/src/www_files.c index 6e37c65..af95024 100644 --- a/src/www_files.c +++ b/src/www_files.c @@ -4,9 +4,11 @@ #include #include #include -#include "bbs.h" + #include "../deps/hashids/hashids.h" +#include "bbs.h" + extern struct bbs_config conf; extern struct user_record *gUser; extern char *aha(char *input); @@ -222,12 +224,17 @@ char *www_decode_hash(char *hash) { sub = (int)numbers[2]; fid = (int)numbers[3]; - if (dir >= conf.file_directory_count || sub >= conf.file_directories[dir]->file_sub_count) { + if (dir >= ptr_vector_len(&conf.file_directories)) return NULL; - } + struct file_directory *fdir = ptr_vector_get(&conf.file_directories, dir); + assert(fdir != NULL); + if (sub >= ptr_vector_len(&fdir->file_subs)) + return NULL; + struct file_sub *fsub = ptr_vector_get(&fdir->file_subs, sub); + assert(fsub != NULL); // get filename from database - snprintf(pathbuf, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); + snprintf(pathbuf, sizeof pathbuf, "%s/%s.sq3", conf.bbs_path, fsub->database); rc = sqlite3_open(pathbuf, &db); if (rc != SQLITE_OK) { return NULL; @@ -260,11 +267,13 @@ char *www_create_link(int dir, int sub, int fid) { hashids_t *hashids = hashids_init(conf.bbs_name); - sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid); + sizereq = hashids_estimate_encoded_size_v(hashids, 4, (unsigned long long)gUser->id, + (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid); hashid = (char *)malloz(sizereq + 1); - if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) { + if (hashids_encode_v(hashids, hashid, 4, (unsigned long long)gUser->id, + (unsigned long long)dir, (unsigned long long)sub, (unsigned long long)fid) == 0) { hashids_free(hashids); free(hashid); return NULL; @@ -272,7 +281,7 @@ char *www_create_link(int dir, int sub, int fid) { hashids_free(hashids); - snprintf(url, PATH_MAX, "%sfiles/%s", conf.www_url, hashid); + snprintf(url, sizeof url, "%sfiles/%s", conf.www_url, hashid); // add link into hash database expiry = time(NULL) + 86400; @@ -285,28 +294,31 @@ char *www_create_link(int dir, int sub, int fid) { return ret; } char *www_files_display_listing(int dir, int sub) { + static const char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename"; + stralloc page = EMPTY_STRALLOC; char pathbuf[PATH_MAX]; - char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename"; - char *filename; - char c; - int size; - char *aha_out; - char *description; - sqlite3 *db; - sqlite3_stmt *res; - int rc; - int i; - char *clean_url; + char *aha_out = NULL; + sqlite3 *db = NULL; + sqlite3_stmt *res = NULL; + int rc = 0; + + if (dir >= ptr_vector_len(&conf.file_directories)) + return NULL; + struct file_directory *fdir = ptr_vector_get(&conf.file_directories, dir); + assert(fdir != NULL); + if (sub >= ptr_vector_len(&fdir->file_subs)) + return NULL; + struct file_sub *fsub = ptr_vector_get(&fdir->file_subs, sub); + assert(fsub != NULL); stralloc_copys(&page, "

Files: "); - stralloc_cats(&page, conf.file_directories[dir]->name); + stralloc_cats(&page, fdir->name); stralloc_cats(&page, " - "); - stralloc_cats(&page, conf.file_directories[dir]->file_subs[sub]->name); + stralloc_cats(&page, fsub->name); stralloc_cats(&page, "

\n"); - snprintf(pathbuf, sizeof pathbuf, "%s/%s.sq3", - conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); + snprintf(pathbuf, sizeof pathbuf, "%s/%s.sq3", conf.bbs_path, fsub->database); rc = sqlite3_open(pathbuf, &db); if (rc != SQLITE_OK) { free(page.s); @@ -321,7 +333,7 @@ char *www_files_display_listing(int dir, int sub) { } stralloc_cats(&page, "\n"); while (sqlite3_step(res) == SQLITE_ROW) { - filename = strdup((char *)sqlite3_column_text(res, 1)); + char *filename = strdup((char *)sqlite3_column_text(res, 1)); char *base_filename = basename(filename); stralloc_cats(&page, ""); - size = sqlite3_column_int(res, 3); + int size = sqlite3_column_int(res, 3); stralloc_cats(&page, ""); stralloc_cats(&page, "
FilenameSizeDescription
"); int c = 'b'; if (size > 1024) { @@ -355,7 +367,7 @@ char *www_files_display_listing(int dir, int sub) { stralloc_cats(&page, ""); - description = strdup((char *)sqlite3_column_text(res, 2)); + char *description = strdup((char *)sqlite3_column_text(res, 2)); for (char *p = description; *p != '\0'; ++p) { if (*p == '\n') *p = '\r'; @@ -381,13 +393,15 @@ char *www_files_areas() { stralloc page = EMPTY_STRALLOC; stralloc_copys(&page, "

File Directories

\n"); - for (int i = 0; i < conf.file_directory_count; i++) { - if (!conf.file_directories[i]->display_on_web) + for (size_t i = 0; i < ptr_vector_len(&conf.file_directories); ++i) { + struct file_directory *dir = ptr_vector_get(&conf.file_directories, i); + if (!dir->display_on_web) continue; stralloc_cats(&page, "
"); - stralloc_cats(&page, conf.file_directories[i]->name); + stralloc_cats(&page, dir->name); stralloc_cats(&page, "
\n"); - for (int j = 0; j < conf.file_directories[i]->file_sub_count; j++) { + for (size_t j = 0; j < ptr_vector_len(&dir->file_subs); ++j) { + struct file_sub *sub = ptr_vector_get(&dir->file_subs, j); stralloc_cats(&page, "\n"); } } @@ -405,17 +419,15 @@ char *www_files_areas() { } char *www_files_get_from_area(int dir, int sub, char *clean_file) { - char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\""; + static const char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\""; + stralloc filenamelike = EMPTY_STRALLOC; - sqlite3 *db; - sqlite3_stmt *res; - int rc; + sqlite3 *db = NULL; + sqlite3_stmt *res = NULL; + int rc = 0; char pathbuf[PATH_MAX]; char *ret = NULL; - int i; - int extra = 0; - int j; - char *file; + char *file = NULL; file = www_decode(clean_file); stralloc_copys(&filenamelike, "%"); @@ -427,7 +439,16 @@ char *www_files_get_from_area(int dir, int sub, char *clean_file) { stralloc_0(&filenamelike); free(file); - snprintf(pathbuf, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); + if (dir >= ptr_vector_len(&conf.file_directories)) + return NULL; + struct file_directory *fdir = ptr_vector_get(&conf.file_directories, dir); + assert(fdir != NULL); + if (sub >= ptr_vector_len(&fdir->file_subs)) + return NULL; + struct file_sub *fsub = ptr_vector_get(&fdir->file_subs, sub); + assert(fsub != NULL); + + snprintf(pathbuf, sizeof pathbuf, "%s/%s.sq3", conf.bbs_path, fsub->database); rc = sqlite3_open(pathbuf, &db); if (rc != SQLITE_OK) { free(filenamelike.s); diff --git a/src/www_msgs.c b/src/www_msgs.c index f348bcd..9faadf3 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -6,10 +6,13 @@ #include #include #include -#include "bbs.h" + #include "jamlib/jam.h" #include "libuuid/uuid.h" +#include "bbs.h" +#include "mail_utils.h" + #define IN 0 #define OUT 1 extern char *aha(char *input); @@ -59,16 +62,17 @@ char *www_sanitize(char *inp) { char *www_msgs_arealist(struct user_record *user) { stralloc page = EMPTY_STRALLOC; - int i, j; stralloc_copys(&page, "

Message Conferences

\n"); - for (i = 0; i < conf.mail_conference_count; i++) { - if (conf.mail_conferences[i]->sec_level <= user->sec_level) { + for (size_t i = 0; i < ptr_vector_len(&conf.mail_conferences); i++) { + struct mail_conference *mc = get_conf(i); + if (mc->sec_level <= user->sec_level) { stralloc_cats(&page, "
"); - stralloc_cats(&page, conf.mail_conferences[i]->name); + stralloc_cats(&page, mc->name); stralloc_cats(&page, "
\n"); - for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) { - if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) { + for (size_t j = 0; j < ptr_vector_len(&mc->mail_areas); j++) { + struct mail_area *ma = get_area(i, j); + if (ma->read_sec_level > user->sec_level) { continue; } stralloc_cats(&page, "
"); - stralloc_cats(&page, conf.mail_conferences[i]->mail_areas[j]->name); + stralloc_cats(&page, ma->name); stralloc_cats(&page, "
\n"); } } @@ -104,16 +108,20 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i char *from; char *subject; - if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { + if (conference < 0 || conference >= ptr_vector_len(&conf.mail_conferences)) return NULL; - } + struct mail_conference *mc = get_conf(conference); + if (area < 0 || area >= ptr_vector_len(&mc->mail_areas)) + return NULL; + struct mail_area *ma = get_area(conference, area); + stralloc_copys(&page, "

"); - stralloc_cats(&page, conf.mail_conferences[conference]->name); + stralloc_cats(&page, mc->name); stralloc_cats(&page, " - "); - stralloc_cats(&page, conf.mail_conferences[conference]->mail_areas[area]->name); + stralloc_cats(&page, ma->name); stralloc_cats(&page, "

\n"); - if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { + if (ma->type != TYPE_NETMAIL_AREA) { stralloc_cats(&page, "
\n"); - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + jb = open_jam_base(ma->path); if (!jb) { free(page.s); free_message_headers(mhrs); @@ -236,14 +244,14 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i char *nodename; struct fido_addr *nodeno; - if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { + if (conference < 0 || conference >= ptr_vector_len(&conf.mail_conferences)) return NULL; - } + struct mail_conference *mc = get_conf(conference); + if (area < 0 || area >= ptr_vector_len(&mc->mail_areas)) + return NULL; + struct mail_area *ma = get_area(conference, area); - if (!(conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level)) { - return NULL; - } - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + jb = open_jam_base(ma->path); if (!jb) { return NULL; } @@ -296,11 +304,10 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i } if (jmh.Attribute & JAM_MSG_PRIVATE) { - if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && - !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && - !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && - !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { - + if (!msg_is_to(user, to, daddress, mc->nettype, mc->realnames, conference) && + !msg_is_from(user, from, oaddress, mc->nettype, mc->realnames, conference) && + !msg_is_to(user, to, daddress, mc->nettype, !mc->realnames, conference) && + !msg_is_from(user, from, oaddress, mc->nettype, !mc->realnames, conference)) { free(subject); free(from); free(to); @@ -339,9 +346,9 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i stralloc_append1(&page, '/'); stralloc_cat_long(&page, area); stralloc_cats(&page, "\">

"); - stralloc_cats(&page, conf.mail_conferences[conference]->name); + stralloc_cats(&page, mc->name); stralloc_cats(&page, " - "); - stralloc_cats(&page, conf.mail_conferences[conference]->mail_areas[area]->name); + stralloc_cats(&page, ma->name); stralloc_cats(&page, "

\n"); if (msgbase_is_flagged(user, conference, area, msg)) { @@ -357,17 +364,19 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i free(subject_s); from_s = www_sanitize(from); - if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) { - if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { + if (ma->type != TYPE_LOCAL_AREA && oaddress != NULL) { + if (mc->nettype == NETWORK_MAGI) { snprintf(buffer, sizeof buffer, "
From: %s (@%s)
\n", from_s, oaddress); - } else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { + } else if (mc->nettype == NETWORK_FIDO) { nodeno = parse_fido_addr(oaddress); if (nodeno != NULL) { - nodename = nl_get_bbsname(nodeno, conf.mail_conferences[conference]->domain); + nodename = nl_get_bbsname(nodeno, mc->domain); if (strcmp(nodename, "Unknown") == 0) { snprintf(buffer, sizeof buffer, "
From: %s (%s)
\n", from_s, oaddress); } else { - snprintf(buffer, sizeof buffer, "
From: %s (%s - %s)
\n", from_s, nodename, oaddress); + snprintf(buffer, sizeof buffer, + "
From: %s (%s - %s)
\n", + from_s, nodename, oaddress); } free(nodename); free(nodeno); @@ -393,14 +402,18 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i date = (time_t)jmh.DateWritten; gmtime_r(&date, &msg_date); if (conf.date_style == 1) { - snprintf(buffer, sizeof buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", + msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - snprintf(buffer, sizeof buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", + msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } stralloc_cats(&page, buffer); - snprintf(buffer, sizeof buffer, "
", conf.www_url, conference, area, msg, conf.www_url); + snprintf(buffer, sizeof buffer, + "
", + conf.www_url, conference, area, msg, conf.www_url); stralloc_cats(&page, buffer); stralloc_cats(&page, "\n"); @@ -416,7 +429,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i stralloc_cats(&page, "\n"); stralloc_cats(&page, "
\n"); - if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { + if (ma->write_sec_level <= user->sec_level && ma->type != TYPE_NETMAIL_AREA) { stralloc_cats(&page, "

Reply

\n"); stralloc_cats(&page, "
= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { - return 0; - } if (subj == NULL || to == NULL || body == NULL) { return 0; } - if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + + if (conference < 0 || conference >= ptr_vector_len(&conf.mail_conferences)) + return 0; + struct mail_conference *mc = get_conf(conference); + if (area < 0 || area >= ptr_vector_len(&mc->mail_areas)) + return 0; + struct mail_area *ma = get_area(conference, area); + + if (ma->write_sec_level <= user->sec_level && ma->type != TYPE_NETMAIL_AREA) { + jb = open_jam_base(ma->path); if (!jb) { return 0; } @@ -674,7 +692,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, jmh.DateWritten = (uint32_t)utc_to_local(time(NULL)); jmh.Attribute |= JAM_MSG_LOCAL; - if (conf.mail_conferences[conference]->realnames == 0) { + if (mc->realnames == 0) { strlcpy(buffer, user->loginname, sizeof buffer); } else { snprintf(buffer, sizeof buffer, "%s %s", user->firstname, user->lastname); @@ -699,21 +717,21 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, jsf.Buffer = (char *)subj; JAM_PutSubfield(jsp, &jsf); - if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA) { jmh.Attribute |= JAM_MSG_TYPEECHO; - if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[conference]->fidoaddr->point) { + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point) { snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", - conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node, - conf.mail_conferences[conference]->fidoaddr->point); + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point); } else { snprintf(buffer, sizeof buffer, "%d:%d/%d", - conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node); + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node); } jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; @@ -722,10 +740,10 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_PutSubfield(jsp, &jsf); snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", - conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node, - conf.mail_conferences[conference]->fidoaddr->point, + mc->fidoaddr->zone, + mc->fidoaddr->net, + mc->fidoaddr->node, + mc->fidoaddr->point, generate_msgid()); jsf.LoID = JAMSFLD_MSGID; @@ -743,8 +761,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_PutSubfield(jsp, &jsf); jmh.ReplyCRC = JAM_Crc32(buffer, strlen(replyid)); } - } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { - snprintf(buffer, sizeof buffer, "%d", conf.mail_conferences[conference]->maginode); + } else if (mc->nettype == NETWORK_MAGI) { + snprintf(buffer, sizeof buffer, "%d", mc->maginode); jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(buffer); @@ -789,29 +807,28 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, return 0; } - if (conf.mail_conferences[conference]->tagline != NULL) { - tagline = conf.mail_conferences[conference]->tagline; - } else { - tagline = conf.default_tagline; + tagline = conf.default_tagline; + if (mc->tagline != NULL) { + tagline = mc->tagline; } uname(&name); - if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[conference]->fidoaddr->point == 0) { - snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node); + if (mc->nettype == NETWORK_FIDO) { + if (mc->fidoaddr->point == 0) { + snprintf(buffer, sizeof buffer, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node); } else { - snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone, - conf.mail_conferences[conference]->fidoaddr->net, - conf.mail_conferences[conference]->fidoaddr->node, - conf.mail_conferences[conference]->fidoaddr->point); + snprintf(buffer, sizeof buffer, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, + mc->fidoaddr->zone, mc->fidoaddr->net, mc->fidoaddr->node, mc->fidoaddr->point); } - } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { - snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->maginode); + } else if (mc->nettype == NETWORK_MAGI) { + snprintf(buffer, sizeof buffer, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", + VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, mc->maginode); } else { - snprintf(buffer, 256, "\r"); + snprintf(buffer, sizeof buffer, "\r"); } body2 = www_wordwrap(body, 73); if (body2 == NULL) { @@ -853,7 +870,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, iconv_close(ic); return 0; } else { - if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { + if (ma->type == TYPE_ECHOMAIL_AREA) { if (conf.echomail_sem != NULL) { sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); close(sem_fd);