Make mailareas network ready.

This commit is contained in:
Andrew Pamment 2016-03-24 17:23:42 +10:00
parent f9575b92a0
commit 881289efd9
7 changed files with 248 additions and 6 deletions

81
bbs.c
View File

@ -20,6 +20,63 @@ int gSocket;
int usertimeout;
struct fido_addr *parse_fido_addr(const char *str) {
struct fido_addr *ret = (struct fido_addr *)malloc(sizeof(struct fido_addr));
int c;
int state = 0;
ret->zone = 0;
ret->net = 0;
ret->node = 0;
ret->point = 0;
for (c=0;c<strlen(str);c++) {
switch(str[c]) {
case ':':
state = 1;
break;
case '/':
state = 2;
break;
case '.':
state = 3;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
switch (state) {
case 0:
ret->zone *= 10 + (str[c] - '0');
break;
case 1:
ret->net *= 10 + (str[c] - '0');
break;
case 2:
ret->node *= 10 + (str[c] - '0');
break;
case 3:
ret->point *= 10 + (str[c] - '0');
break;
}
}
break;
default:
free(ret);
return NULL;
}
}
return ret;
}
void timer_handler(int signum) {
if (signum == SIGALRM) {
if (gUser != NULL) {
@ -157,6 +214,14 @@ static int mail_area_handler(void* user, const char* section, const char* name,
mc->realnames = 0;
}
}
} else if (strcasecmp(section, "network") == 0) {
if (strcasecmp(name, "type") == 0) {
if (strcasecmp(value, "fido") == 0) {
mc->nettype = NETWORK_FIDO;
}
} else if (strcasecmp(name, "fido node") == 0) {
mc->fidoaddr = parse_fido_addr(value);
}
} else {
// check if it's partially filled in
for (i=0;i<mc->mail_area_count;i++) {
@ -167,6 +232,14 @@ static int mail_area_handler(void* user, const char* section, const char* name,
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;
}
}
return 1;
}
@ -186,6 +259,14 @@ static int mail_area_handler(void* user, const char* section, const char* name,
mc->mail_areas[mc->mail_area_count]->write_sec_level = atoi(value);
} else if (strcasecmp(name, "path") == 0) {
mc->mail_areas[mc->mail_area_count]->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;
} else if (strcasecmp(value, "echo") == 0) {
mc->mail_areas[mc->mail_area_count]->type = TYPE_ECHOMAIL_AREA;
} else if (strcasecmp(value, "netmail") == 0) {
mc->mail_areas[mc->mail_area_count]->type = TYPE_NETMAIL_AREA;
}
}
mc->mail_area_count++;
}

18
bbs.h
View File

@ -7,6 +7,19 @@
#define VERSION_MINOR 1
#define VERSION_STR "dev"
#define NETWORK_FIDO 0
#define TYPE_LOCAL_AREA 0
#define TYPE_NETMAIL_AREA 1
#define TYPE_ECHOMAIL_AREA 2
struct fido_addr {
unsigned short zone;
unsigned short net;
unsigned short node;
unsigned short point;
};
struct last10_callers {
char name[17];
char location[33];
@ -25,16 +38,19 @@ struct mail_area {
char *path;
int read_sec_level;
int write_sec_level;
int type;
};
struct mail_conference {
char *name;
char *path;
int networked;
int nettype;
int realnames;
int sec_level;
int mail_area_count;
struct mail_area **mail_areas;
struct fido_addr *fidoaddr;
};
struct file_sub {
@ -95,7 +111,7 @@ struct user_record {
extern void runbbs(int sock, char *config);
extern struct fido_addr *parse_fido_addr(const char *str);
extern void s_putchar(int socket, char c);
extern void s_putstring(int socket, char *c);
extern void s_displayansi(int socket, char *file);

View File

@ -11,6 +11,7 @@ Email Path = /home/andrew/MagickaBBS/msgs/email
[mail conferences]
Local Mail = config/localmail.ini
IllusionNet = config/illusionnet.ini
[file directories]
General Files = config/filesgen.ini

View File

@ -0,0 +1,15 @@
[main]
Visible Sec Level = 10
Networked = true
Real Names = false
[network]
type = fido
fido node = 867:61/2
[General]
Read Sec Level = 10
Write Sec Level = 10
Path = /home/andrew/MagickaBBS/msgs/il_general
; local / echo or netmail
Type = Echo

View File

@ -7,8 +7,10 @@ Real Names = false
Read Sec Level = 10
Write Sec Level = 10
Path = /home/andrew/MagickaBBS/msgs/general
Type = Local
[Testing]
Read Sec Level = 10
Write Sec Level = 10
Path = /home/andrew/MagickaBBS/msgs/testing
Type = Local

View File

@ -273,7 +273,7 @@ void read_message(int socket, struct user_record *user, int mailno) {
int lines = 0;
char c;
char *replybody;
struct fido_addr *from_addr = NULL;
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
if (!jb) {
printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
@ -300,7 +300,12 @@ void read_message(int socket, struct user_record *user, int mailno) {
to = (char *)malloc(jsp->Fields[z]->DatLen + 1);
memset(to, 0, jsp->Fields[z]->DatLen + 1);
memcpy(to, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
}
}
if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) {
memset(buffer, 0, jsp->Fields[z]->DatLen + 1);
memcpy(buffer, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
from_addr = parse_fido_addr(buffer);
}
}
@ -378,6 +383,9 @@ void read_message(int socket, struct user_record *user, int mailno) {
free(subject);
free(to);
free(from);
if (from_addr != NULL) {
free(from_addr);
}
return;
}
@ -403,7 +411,49 @@ void read_message(int socket, struct user_record *user, int mailno) {
jsf.DatLen = strlen(subject);
jsf.Buffer = (uchar *)subject;
JAM_PutSubfield(jsp, &jsf);
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA) {
jmh.Attribute |= MSG_TYPEECHO;
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point);
jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
jsf.Buffer = (uchar *)buffer;
JAM_PutSubfield(jsp, &jsf);
}
} else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) {
jmh.Attribute |= MSG_TYPENET;
jmh.Attribute |= MSG_KILLSENT;
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point);
jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
jsf.Buffer = (uchar *)buffer;
JAM_PutSubfield(jsp, &jsf);
if (from_addr != NULL) {
sprintf(buffer, "%d:%d/%d.%d", from_addr->zone,
from_addr->net,
from_addr->node,
from_addr->point);
jsf.LoID = JAMSFLD_DADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
jsf.Buffer = (uchar *)buffer;
JAM_PutSubfield(jsp, &jsf);
}
}
}
while (1) {
z = JAM_LockMB(jb, 100);
@ -418,6 +468,9 @@ void read_message(int socket, struct user_record *user, int mailno) {
free(to);
free(from);
printf("Failed to lock msg base!\n");
if (from_addr != NULL) {
free(from_addr);
}
return;
}
}
@ -447,7 +500,9 @@ void read_message(int socket, struct user_record *user, int mailno) {
if (subject != NULL) {
free(subject);
}
if (from_addr != NULL) {
free(from_addr);
}
}
int mail_menu(int socket, struct user_record *user) {
@ -480,6 +535,7 @@ int mail_menu(int socket, struct user_record *user) {
ulong jam_crc;
unsigned int lastmsg,currmsg;
int lines;
struct fido_addr *from_addr;
while (!domail) {
s_displayansi(socket, "mailmenu");
@ -510,7 +566,17 @@ int mail_menu(int socket, struct user_record *user) {
break;
}
}
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) {
s_putstring(socket, "\r\nADDR: ");
s_readstring(socket, buffer, 32);
from_addr = parse_fido_addr(buffer);
if (!from_addr) {
s_putstring(socket, "\r\n\r\nInvalid Address\r\n");
break;
} else {
sprintf(buffer, "\r\nMailing to %d:%d/%d.%d\r\n", from_addr->zone, from_addr->net, from_addr->node, from_addr->point);
}
}
to = strdup(buffer);
s_putstring(socket, "\r\nSUBJECT: ");
s_readstring(socket, buffer, 25);
@ -557,6 +623,48 @@ int mail_menu(int socket, struct user_record *user) {
jsf.Buffer = (uchar *)subject;
JAM_PutSubfield(jsp, &jsf);
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA) {
jmh.Attribute |= MSG_TYPEECHO;
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point);
jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
jsf.Buffer = (uchar *)buffer;
JAM_PutSubfield(jsp, &jsf);
}
} else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) {
jmh.Attribute |= MSG_TYPENET;
jmh.Attribute |= MSG_KILLSENT;
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node,
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point);
jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
jsf.Buffer = (uchar *)buffer;
JAM_PutSubfield(jsp, &jsf);
if (from_addr != NULL) {
sprintf(buffer, "%d:%d/%d.%d", from_addr->zone,
from_addr->net,
from_addr->node,
from_addr->point);
jsf.LoID = JAMSFLD_DADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
jsf.Buffer = (uchar *)buffer;
JAM_PutSubfield(jsp, &jsf);
}
}
}
while (1) {
z = JAM_LockMB(jb, 100);
@ -834,6 +942,9 @@ int mail_menu(int socket, struct user_record *user) {
JAM_PutSubfield(jsp, &jsf);
while (1) {
z = JAM_LockMB(jb, 100);
if (z == 0) {

16
users.c
View File

@ -234,6 +234,22 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
exit(-1);
}
if (user->cur_mail_conf > conf.mail_conference_count) {
user->cur_mail_conf = 0;
}
if (user->cur_file_dir > conf.file_directory_count) {
user->cur_file_dir = 0;
}
if (user->cur_mail_area > conf.mail_conferences[user->cur_mail_conf]->mail_area_count) {
user->cur_mail_area = 0;
}
if (user->cur_file_sub > conf.file_directories[user->cur_file_sub]->file_sub_count) {
user->cur_file_sub = 0;
}
return user;
}