Arrays to vectors.
This is the big push to get rid of the last of the unadorned dynamic arrays. Use ptr_vectors for things like mail conferences etc. Lots of incidental cleanup along the way. Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
parent
d8dc2e8f7d
commit
aacb1000c8
@ -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 \
|
||||
|
40
src/bbs.h
40
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);
|
||||
|
313
src/bluewave.c
313
src/bluewave.c
@ -6,11 +6,14 @@
|
||||
#include <fcntl.h>
|
||||
#include <sqlite3.h>
|
||||
#include <sys/wait.h>
|
||||
#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) {
|
||||
|
333
src/files.c
333
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++;
|
||||
}
|
||||
}
|
||||
|
129
src/lua_glue.c
129
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();
|
||||
|
949
src/mail_menu.c
949
src/mail_menu.c
File diff suppressed because it is too large
Load Diff
28
src/mail_utils.h
Normal file
28
src/mail_utils.h
Normal file
@ -0,0 +1,28 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#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);
|
||||
}
|
408
src/main.c
408
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);
|
||||
|
@ -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");
|
||||
|
26
src/menus.c
26
src/menus.c
@ -3,11 +3,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
12
src/users.c
12
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;
|
||||
}
|
||||
|
||||
|
11
src/www.c
11
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);
|
||||
|
@ -4,9 +4,11 @@
|
||||
#include <time.h>
|
||||
#include <sqlite3.h>
|
||||
#include <libgen.h>
|
||||
#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, "<div class=\"content-header\"><h2>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, "</h2></div>\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, "<table class=\"fileentry\"><thead><tr><td>Filename</td><td>Size</td><td>Description</td></tr></thead><tbody>\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, "<tr><td class=\"filename\"><a href=\"");
|
||||
stralloc_cats(&page, conf.www_url);
|
||||
@ -335,7 +347,7 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
stralloc_cats(&page, base_filename);
|
||||
stralloc_cats(&page, "</a></td>");
|
||||
|
||||
size = sqlite3_column_int(res, 3);
|
||||
int size = sqlite3_column_int(res, 3);
|
||||
stralloc_cats(&page, "<td class=\"filesize\">");
|
||||
int c = 'b';
|
||||
if (size > 1024) {
|
||||
@ -355,7 +367,7 @@ char *www_files_display_listing(int dir, int sub) {
|
||||
stralloc_cats(&page, "</td>");
|
||||
|
||||
stralloc_cats(&page, "<td class=\"filedesc\">");
|
||||
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, "<div class=\"content-header\"><h2>File Directories</h2></div>\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, "<div class=\"conference-list-item\">");
|
||||
stralloc_cats(&page, conf.file_directories[i]->name);
|
||||
stralloc_cats(&page, dir->name);
|
||||
stralloc_cats(&page, "</div>\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, "<div class=\"area-list-item\"><a href=\"");
|
||||
stralloc_cats(&page, conf.www_url);
|
||||
stralloc_cats(&page, "files/areas/");
|
||||
@ -395,7 +409,7 @@ char *www_files_areas() {
|
||||
stralloc_append1(&page, '/');
|
||||
stralloc_cat_long(&page, j);
|
||||
stralloc_cats(&page, "/\">");
|
||||
stralloc_cats(&page, conf.file_directories[i]->file_subs[j]->name);
|
||||
stralloc_cats(&page, sub->name);
|
||||
stralloc_cats(&page, "</a></div>\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);
|
||||
|
167
src/www_msgs.c
167
src/www_msgs.c
@ -6,10 +6,13 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/stat.h>
|
||||
#include <iconv.h>
|
||||
#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, "<div class=\"content-header\"><h2>Message Conferences</h2></div>\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, "<div class=\"conference-list-item\">");
|
||||
stralloc_cats(&page, conf.mail_conferences[i]->name);
|
||||
stralloc_cats(&page, mc->name);
|
||||
stralloc_cats(&page, "</div>\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, "<div class=\"area-list-");
|
||||
@ -80,7 +84,7 @@ char *www_msgs_arealist(struct user_record *user) {
|
||||
stralloc_append1(&page, '/');
|
||||
stralloc_cat_long(&page, j);
|
||||
stralloc_cats(&page, "/\">");
|
||||
stralloc_cats(&page, conf.mail_conferences[i]->mail_areas[j]->name);
|
||||
stralloc_cats(&page, ma->name);
|
||||
stralloc_cats(&page, "</a></div>\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, "<div class=\"content-header\"><h2>");
|
||||
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, "</h2></div>\n");
|
||||
|
||||
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
|
||||
if (ma->type != TYPE_NETMAIL_AREA) {
|
||||
stralloc_cats(&page, "<div class=\"button\"><a href=\"");
|
||||
stralloc_cats(&page, conf.www_url);
|
||||
stralloc_cats(&page, "msgs/new/");
|
||||
@ -130,7 +138,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i
|
||||
|
||||
stralloc_cats(&page, "<div class=\"div-table\">\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, "\"><h2>");
|
||||
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, "</h2></a></div>\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, "<div class=\"msg-view-from\">From: %s (@%s)</div>\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, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
|
||||
} else {
|
||||
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (<span class=\"bbsname\">%s</span> - %s)</div>\n", from_s, nodename, oaddress);
|
||||
snprintf(buffer, sizeof buffer,
|
||||
"<div class=\"msg-view-from\">From: %s (<span class=\"bbsname\">%s</span> - %s)</div>\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, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\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, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\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, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\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, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\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, "<div class=\"msg-view-options\"><a href=\"%smsgs/flag/%d/%d/%d\"><img src=\"%sstatic/flag.png\" /></a></div>", conf.www_url, conference, area, msg, conf.www_url);
|
||||
snprintf(buffer, sizeof buffer,
|
||||
"<div class=\"msg-view-options\"><a href=\"%smsgs/flag/%d/%d/%d\"><img src=\"%sstatic/flag.png\" /></a></div>",
|
||||
conf.www_url, conference, area, msg, conf.www_url);
|
||||
stralloc_cats(&page, buffer);
|
||||
|
||||
stralloc_cats(&page, "</div>\n");
|
||||
@ -416,7 +429,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
|
||||
stralloc_cats(&page, "</div>\n");
|
||||
|
||||
stralloc_cats(&page, "<div class=\"msg-reply-form\">\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, "<h3>Reply</h3>\n");
|
||||
stralloc_cats(&page, "<form action=\"");
|
||||
stralloc_cats(&page, conf.www_url);
|
||||
@ -658,14 +671,19 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
|
||||
|
||||
uuid_t magi_msgid;
|
||||
|
||||
if (conference < 0 || conference >= 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);
|
||||
|
Reference in New Issue
Block a user