Experimental changes to mnet
This commit is contained in:
parent
b6f328ffa3
commit
baa755a1cc
4
dist/config/mnet.cfg.example
vendored
4
dist/config/mnet.cfg.example
vendored
@ -1,9 +1,9 @@
|
|||||||
MYNODE 1
|
MYNODE 1
|
||||||
|
|
||||||
IMHUB TRUE
|
IMHUB TRUE
|
||||||
|
;UPLINK 1
|
||||||
|
|
||||||
INDIR /home/andrew/MagickaBBS/mnet/in
|
INDIR /home/andrew/MagickaBBS/mnet/in
|
||||||
OUTDIR /home/andrew/MagickaBBS/mnet/out
|
OUTDIR /home/andrew/MagickaBBS/mnet/out
|
||||||
|
|
||||||
MSGAREA 1, /home/andrew/MagickaBBS/msgs/mnet_general, 2, 3, 4
|
MSGAREA 1, 1, /home/andrew/MagickaBBS/msgs/mnet_general, 2, 3, 4
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ char *baseoutdir = NULL;
|
|||||||
|
|
||||||
struct msgarea_t {
|
struct msgarea_t {
|
||||||
int id;
|
int id;
|
||||||
|
int hub;
|
||||||
char *basedir;
|
char *basedir;
|
||||||
int *links;
|
int *links;
|
||||||
int link_count;
|
int link_count;
|
||||||
@ -29,6 +30,9 @@ struct msg_t {
|
|||||||
|
|
||||||
struct msgarea_t **areas;
|
struct msgarea_t **areas;
|
||||||
int area_count;
|
int area_count;
|
||||||
|
int mynode = 0;
|
||||||
|
int hubnode = 0;
|
||||||
|
int imhub = 0;
|
||||||
|
|
||||||
s_JamBase *open_jam_base(char *path) {
|
s_JamBase *open_jam_base(char *path) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -102,7 +106,18 @@ int parse_config_file(char *filename) {
|
|||||||
if (buffer[strlen(buffer) - 1] == '\n'){
|
if (buffer[strlen(buffer) - 1] == '\n'){
|
||||||
buffer[strlen(buffer) - 1] = '\0';
|
buffer[strlen(buffer) - 1] = '\0';
|
||||||
|
|
||||||
if (strncasecmp(buffer, "OUTDIR", 6) == 0) {
|
if (strncasecmp(buffer, "MYNODE", 6) == 0) {
|
||||||
|
trimwhitespace(bufferw, 256, &buffer[7]);
|
||||||
|
mynode = atoi(bufferw);
|
||||||
|
} else if (strncasecmp, "IMHUB", 5 == 0) {
|
||||||
|
trimwhitespace(bufferw, 256, &buffer[7]);
|
||||||
|
if (strcasecmp(bufferw, "TRUE")) {
|
||||||
|
imhub = 1;
|
||||||
|
}
|
||||||
|
} else if (strncasecmp(buffer, "UPLINK", 6) == 0) {
|
||||||
|
trimwhitespace(bufferw, 256, &buffer[7]);
|
||||||
|
hubnode = atoi(bufferw);
|
||||||
|
} else if (strncasecmp(buffer, "OUTDIR", 6) == 0) {
|
||||||
trimwhitespace(bufferw, 256, &buffer[7]);
|
trimwhitespace(bufferw, 256, &buffer[7]);
|
||||||
baseoutdir = strdup(bufferw);
|
baseoutdir = strdup(bufferw);
|
||||||
} else if (strncasecmp(buffer, "MSGAREA", 7) == 0) {
|
} else if (strncasecmp(buffer, "MSGAREA", 7) == 0) {
|
||||||
@ -115,20 +130,27 @@ int parse_config_file(char *filename) {
|
|||||||
newarea->id = atoi(bufferw);
|
newarea->id = atoi(bufferw);
|
||||||
newarea->link_count = 0;
|
newarea->link_count = 0;
|
||||||
ptr = strtok(NULL, ",");
|
ptr = strtok(NULL, ",");
|
||||||
|
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
trimwhitespace(bufferw, 256, ptr);
|
trimwhitespace(bufferw, 256, ptr);
|
||||||
newarea->basedir = strdup(bufferw);
|
newarea->hub = atoi(bufferw);
|
||||||
ptr = strtok(NULL, ",");
|
ptr = strtok(NULL, ",");
|
||||||
while (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
|
|
||||||
trimwhitespace(bufferw, 256, ptr);
|
trimwhitespace(bufferw, 256, ptr);
|
||||||
if (newarea->link_count == 0) {
|
newarea->basedir = strdup(bufferw);
|
||||||
newarea->links = (int *)malloc(sizeof(int));
|
|
||||||
} else {
|
|
||||||
newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1));
|
|
||||||
}
|
|
||||||
newarea->links[newarea->link_count] = atoi(bufferw);
|
|
||||||
newarea->link_count++;
|
|
||||||
ptr = strtok(NULL, ",");
|
ptr = strtok(NULL, ",");
|
||||||
|
while (ptr != NULL) {
|
||||||
|
trimwhitespace(bufferw, 256, ptr);
|
||||||
|
if (newarea->link_count == 0) {
|
||||||
|
newarea->links = (int *)malloc(sizeof(int));
|
||||||
|
} else {
|
||||||
|
newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1));
|
||||||
|
}
|
||||||
|
newarea->links[newarea->link_count] = atoi(bufferw);
|
||||||
|
newarea->link_count++;
|
||||||
|
ptr = strtok(NULL, ",");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,12 +247,6 @@ int export_messages(int area) {
|
|||||||
}
|
}
|
||||||
memcpy(msg.to, jsp->Fields[z]->Buffer, len);
|
memcpy(msg.to, jsp->Fields[z]->Buffer, len);
|
||||||
}
|
}
|
||||||
if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) {
|
|
||||||
msg.daddr = atoi(jsp->Fields[z]->Buffer);
|
|
||||||
}
|
|
||||||
if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) {
|
|
||||||
msg.oaddr = atoi(jsp->Fields[z]->Buffer);
|
|
||||||
}
|
|
||||||
if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
|
if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) {
|
||||||
memset(msgid, 0, 37);
|
memset(msgid, 0, 37);
|
||||||
memcpy(msgid, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen));
|
memcpy(msgid, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen));
|
||||||
@ -239,6 +255,7 @@ int export_messages(int area) {
|
|||||||
memcpy(msg.reply, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen));
|
memcpy(msg.reply, jsp->Fields[z]->Buffer, (jsp->Fields[z]->DatLen > 36 ? 36 : jsp->Fields[z]->DatLen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msg.oaddr = mynode;
|
||||||
msg.timedate = jmh.DateWritten;
|
msg.timedate = jmh.DateWritten;
|
||||||
body = (char *)malloc(jmh.TxtLen + 1);
|
body = (char *)malloc(jmh.TxtLen + 1);
|
||||||
memset(body, 0, jmh.TxtLen + 1);
|
memset(body, 0, jmh.TxtLen + 1);
|
||||||
@ -270,15 +287,54 @@ int export_messages(int area) {
|
|||||||
|
|
||||||
msg.area = areas[area]->id;
|
msg.area = areas[area]->id;
|
||||||
|
|
||||||
for (n = 0; n < areas[area]->link_count; n++) {
|
if (areas[area]->hub == mynode) {
|
||||||
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->links[n]);
|
for (n = 0; n < areas[area]->link_count; n++) {
|
||||||
|
if (imhub) {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->links[n]);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, hubnode);
|
||||||
|
}
|
||||||
|
if (stat(buffer, &st) != 0) {
|
||||||
|
if (mkdir(buffer, 0755) != 0) {
|
||||||
|
fprintf(stderr, "Error making directory %s\n", buffer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (imhub) {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, areas[area]->links[n], areas[area]->links[n], msgid);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, areas[area]->links[n], msgid);
|
||||||
|
}
|
||||||
|
msg.daddr = areas[area]->links[n];
|
||||||
|
fptr = fopen(buffer, "wb");
|
||||||
|
if (fptr == NULL) {
|
||||||
|
fprintf(stderr, "Error creating file %s\n", buffer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite(&msg, sizeof(struct msg_t), 1, fptr);
|
||||||
|
fwrite(body, strlen(body), 1, fptr);
|
||||||
|
fclose(fptr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (imhub) {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->hub);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, hubnode);
|
||||||
|
}
|
||||||
if (stat(buffer, &st) != 0) {
|
if (stat(buffer, &st) != 0) {
|
||||||
if (mkdir(buffer, 0755) != 0) {
|
if (mkdir(buffer, 0755) != 0) {
|
||||||
fprintf(stderr, "Error making directory %s\n", buffer);
|
fprintf(stderr, "Error making directory %s\n", buffer);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf(buffer, PATH_MAX, "%s/%d/%s.message", baseoutdir, areas[area]->links[n], msgid);
|
if (imhub) {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, areas[area]->hub, areas[area]->hub, msgid);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, areas[area]->hub, msgid);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.daddr = areas[area]->hub;
|
||||||
fptr = fopen(buffer, "wb");
|
fptr = fopen(buffer, "wb");
|
||||||
if (fptr == NULL) {
|
if (fptr == NULL) {
|
||||||
fprintf(stderr, "Error creating file %s\n", buffer);
|
fprintf(stderr, "Error creating file %s\n", buffer);
|
||||||
|
@ -14,6 +14,7 @@ int imhub = 0;
|
|||||||
|
|
||||||
struct msgarea_t {
|
struct msgarea_t {
|
||||||
int id;
|
int id;
|
||||||
|
int hub;
|
||||||
char *basedir;
|
char *basedir;
|
||||||
int *links;
|
int *links;
|
||||||
int link_count;
|
int link_count;
|
||||||
@ -33,6 +34,7 @@ struct msg_t {
|
|||||||
struct msgarea_t **areas;
|
struct msgarea_t **areas;
|
||||||
int area_count;
|
int area_count;
|
||||||
int mynode = 0;
|
int mynode = 0;
|
||||||
|
int hubnode = 0;
|
||||||
|
|
||||||
int copy_file(char *src, char *dest) {
|
int copy_file(char *src, char *dest) {
|
||||||
FILE *src_file;
|
FILE *src_file;
|
||||||
@ -140,6 +142,9 @@ int parse_config_file(char *filename) {
|
|||||||
if (strcasecmp(bufferw, "TRUE") == 0) {
|
if (strcasecmp(bufferw, "TRUE") == 0) {
|
||||||
imhub = 1;
|
imhub = 1;
|
||||||
}
|
}
|
||||||
|
} else if (strncasecmp(buffer, "UPLINK", 6) == 0) {
|
||||||
|
trimwhitespace(bufferw, 256, &buffer[7]);
|
||||||
|
hubnode = atoi(bufferw);
|
||||||
} else if (strncasecmp(buffer, "INDIR", 5) == 0) {
|
} else if (strncasecmp(buffer, "INDIR", 5) == 0) {
|
||||||
trimwhitespace(bufferw, 256, &buffer[6]);
|
trimwhitespace(bufferw, 256, &buffer[6]);
|
||||||
baseindir = strdup(bufferw);
|
baseindir = strdup(bufferw);
|
||||||
@ -159,20 +164,27 @@ int parse_config_file(char *filename) {
|
|||||||
newarea->id = atoi(bufferw);
|
newarea->id = atoi(bufferw);
|
||||||
newarea->link_count = 0;
|
newarea->link_count = 0;
|
||||||
ptr = strtok(NULL, ",");
|
ptr = strtok(NULL, ",");
|
||||||
|
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
trimwhitespace(bufferw, 256, ptr);
|
trimwhitespace(bufferw, 256, ptr);
|
||||||
newarea->basedir = strdup(bufferw);
|
newarea->hub = atoi(bufferw);
|
||||||
ptr = strtok(NULL, ",");
|
ptr = strtok(NULL, ",");
|
||||||
while (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
|
|
||||||
trimwhitespace(bufferw, 256, ptr);
|
trimwhitespace(bufferw, 256, ptr);
|
||||||
if (newarea->link_count == 0) {
|
newarea->basedir = strdup(bufferw);
|
||||||
newarea->links = (int *)malloc(sizeof(int));
|
|
||||||
} else {
|
|
||||||
newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1));
|
|
||||||
}
|
|
||||||
newarea->links[newarea->link_count] = atoi(bufferw);
|
|
||||||
newarea->link_count++;
|
|
||||||
ptr = strtok(NULL, ",");
|
ptr = strtok(NULL, ",");
|
||||||
|
while (ptr != NULL) {
|
||||||
|
trimwhitespace(bufferw, 256, ptr);
|
||||||
|
if (newarea->link_count == 0) {
|
||||||
|
newarea->links = (int *)malloc(sizeof(int));
|
||||||
|
} else {
|
||||||
|
newarea->links = (int *)realloc(newarea->links, sizeof(int) * (newarea->link_count + 1));
|
||||||
|
}
|
||||||
|
newarea->links[newarea->link_count] = atoi(bufferw);
|
||||||
|
newarea->link_count++;
|
||||||
|
ptr = strtok(NULL, ",");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +277,7 @@ int import(char *filename) {
|
|||||||
s_JamSubfield jsf;
|
s_JamSubfield jsf;
|
||||||
|
|
||||||
snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename);
|
snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename);
|
||||||
strncpy(uuid, filename, 36);
|
strncpy(uuid, strchr(filename, '-') + 1, 36);
|
||||||
|
|
||||||
uuid[36] = '\0';
|
uuid[36] = '\0';
|
||||||
|
|
||||||
@ -289,27 +301,44 @@ int import(char *filename) {
|
|||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
|
|
||||||
|
|
||||||
for (i=0;i<area_count;i++) {
|
if (msg.daddr != mynode) {
|
||||||
if (msg.area == areas[i]->id) {
|
if (imhub) {
|
||||||
areaid = i;
|
snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, msg.daddr, filename);
|
||||||
break;
|
copy_file(buffer, buffer2);
|
||||||
}
|
}
|
||||||
}
|
return 1;
|
||||||
|
} else {
|
||||||
if (imhub) {
|
for (i=0;i<area_count;i++) {
|
||||||
for (i=0;i<areas[areaid]->link_count;i++) {
|
if (msg.area == areas[i]->id) {
|
||||||
if (areas[areaid]->links[i] == msg.oaddr) {
|
areaid = i;
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, areas[areaid]->links[i]);
|
}
|
||||||
if (stat(buffer2, &st) != 0) {
|
|
||||||
if (mkdir(buffer2, 0755) != 0) {
|
if (areas[areaid]->hub == mynode) {
|
||||||
fprintf(stderr, "Error making directory %s\n", buffer2);
|
for (i=0;i<areas[areaid]->link_count;i++) {
|
||||||
|
if (areas[areaid]->links[i] == msg.oaddr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (imhub) {
|
||||||
|
snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, areas[areaid]->links[i]);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, hubnode);
|
||||||
|
}
|
||||||
|
if (stat(buffer2, &st) != 0) {
|
||||||
|
if (mkdir(buffer2, 0755) != 0) {
|
||||||
|
fprintf(stderr, "Error making directory %s\n", buffer2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (imhub) {
|
||||||
|
snprintf(buffer2, PATH_MAX, "%s/%d/%d-%s", baseoutdir, areas[areaid]->links[i], areas[areaid]->links[i], filename);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer2, PATH_MAX, "%s/%d/%d-%s", baseoutdir, hubnode, areas[areaid]->links[i], filename);
|
||||||
|
}
|
||||||
|
copy_file(buffer, buffer2);
|
||||||
}
|
}
|
||||||
snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, areas[areaid]->links[i], filename);
|
|
||||||
copy_file(buffer, buffer2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user