Experimental changes to mnet

This commit is contained in:
Andrew Pamment 2018-05-23 21:53:24 +10:00
parent b6f328ffa3
commit baa755a1cc
3 changed files with 138 additions and 53 deletions

View File

@ -1,9 +1,9 @@
MYNODE 1
IMHUB TRUE
;UPLINK 1
INDIR /home/andrew/MagickaBBS/mnet/in
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

View File

@ -11,6 +11,7 @@ char *baseoutdir = NULL;
struct msgarea_t {
int id;
int hub;
char *basedir;
int *links;
int link_count;
@ -29,6 +30,9 @@ struct msg_t {
struct msgarea_t **areas;
int area_count;
int mynode = 0;
int hubnode = 0;
int imhub = 0;
s_JamBase *open_jam_base(char *path) {
int ret;
@ -102,7 +106,18 @@ int parse_config_file(char *filename) {
if (buffer[strlen(buffer) - 1] == '\n'){
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]);
baseoutdir = strdup(bufferw);
} else if (strncasecmp(buffer, "MSGAREA", 7) == 0) {
@ -115,20 +130,27 @@ int parse_config_file(char *filename) {
newarea->id = atoi(bufferw);
newarea->link_count = 0;
ptr = strtok(NULL, ",");
if (ptr != NULL) {
trimwhitespace(bufferw, 256, ptr);
newarea->basedir = strdup(bufferw);
newarea->hub = atoi(bufferw);
ptr = strtok(NULL, ",");
while (ptr != NULL) {
if (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++;
newarea->basedir = strdup(bufferw);
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);
}
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) {
memset(msgid, 0, 37);
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));
}
}
msg.oaddr = mynode;
msg.timedate = jmh.DateWritten;
body = (char *)malloc(jmh.TxtLen + 1);
memset(body, 0, jmh.TxtLen + 1);
@ -270,15 +287,54 @@ int export_messages(int area) {
msg.area = areas[area]->id;
for (n = 0; n < areas[area]->link_count; n++) {
snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, areas[area]->links[n]);
if (areas[area]->hub == mynode) {
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 (mkdir(buffer, 0755) != 0) {
fprintf(stderr, "Error making directory %s\n", buffer);
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");
if (fptr == NULL) {
fprintf(stderr, "Error creating file %s\n", buffer);

View File

@ -14,6 +14,7 @@ int imhub = 0;
struct msgarea_t {
int id;
int hub;
char *basedir;
int *links;
int link_count;
@ -33,6 +34,7 @@ struct msg_t {
struct msgarea_t **areas;
int area_count;
int mynode = 0;
int hubnode = 0;
int copy_file(char *src, char *dest) {
FILE *src_file;
@ -140,6 +142,9 @@ int parse_config_file(char *filename) {
if (strcasecmp(bufferw, "TRUE") == 0) {
imhub = 1;
}
} else if (strncasecmp(buffer, "UPLINK", 6) == 0) {
trimwhitespace(bufferw, 256, &buffer[7]);
hubnode = atoi(bufferw);
} else if (strncasecmp(buffer, "INDIR", 5) == 0) {
trimwhitespace(bufferw, 256, &buffer[6]);
baseindir = strdup(bufferw);
@ -159,20 +164,27 @@ int parse_config_file(char *filename) {
newarea->id = atoi(bufferw);
newarea->link_count = 0;
ptr = strtok(NULL, ",");
if (ptr != NULL) {
trimwhitespace(bufferw, 256, ptr);
newarea->basedir = strdup(bufferw);
newarea->hub = atoi(bufferw);
ptr = strtok(NULL, ",");
while (ptr != NULL) {
if (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++;
newarea->basedir = strdup(bufferw);
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;
snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename);
strncpy(uuid, filename, 36);
strncpy(uuid, strchr(filename, '-') + 1, 36);
uuid[36] = '\0';
@ -289,27 +301,44 @@ int import(char *filename) {
fclose(fptr);
for (i=0;i<area_count;i++) {
if (msg.area == areas[i]->id) {
areaid = i;
break;
if (msg.daddr != mynode) {
if (imhub) {
snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, msg.daddr, filename);
copy_file(buffer, buffer2);
}
}
if (imhub) {
for (i=0;i<areas[areaid]->link_count;i++) {
if (areas[areaid]->links[i] == msg.oaddr) {
continue;
return 1;
} else {
for (i=0;i<area_count;i++) {
if (msg.area == areas[i]->id) {
areaid = i;
break;
}
snprintf(buffer2, PATH_MAX, "%s/%d/", baseoutdir, areas[areaid]->links[i]);
if (stat(buffer2, &st) != 0) {
if (mkdir(buffer2, 0755) != 0) {
fprintf(stderr, "Error making directory %s\n", buffer2);
}
if (areas[areaid]->hub == mynode) {
for (i=0;i<areas[areaid]->link_count;i++) {
if (areas[areaid]->links[i] == msg.oaddr) {
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);
}
}