diff --git a/utils/mnetscan/mnet.cfg.example b/dist/config/mnet.cfg.example similarity index 68% rename from utils/mnetscan/mnet.cfg.example rename to dist/config/mnet.cfg.example index f6d26ed..a052d8c 100644 --- a/utils/mnetscan/mnet.cfg.example +++ b/dist/config/mnet.cfg.example @@ -1,4 +1,6 @@ -INDIR /home/andrew/MagickaBBS/mnet/out/2 +MYNODE 1 + +INDIR /home/andrew/MagickaBBS/mnet/in OUTDIR /home/andrew/MagickaBBS/mnet/out MSGAREA 1, /home/andrew/MagickaBBS/msgs/mnet_general, 2, 3, 4 diff --git a/utils/mnettoss/mnettoss.c b/utils/mnettoss/mnettoss.c index 3b224b7..aa15f75 100644 --- a/utils/mnettoss/mnettoss.c +++ b/utils/mnettoss/mnettoss.c @@ -8,6 +8,7 @@ #include "jamlib/jam.h" char *baseindir = NULL; +char *baseoutdir = NULL; struct msgarea_t { int id; @@ -29,6 +30,37 @@ struct msg_t { struct msgarea_t **areas; int area_count; +int mynode = 0; + +int copy_file(char *src, char *dest) { + FILE *src_file; + FILE *dest_file; + + char c; + + src_file = fopen(src, "rb"); + if (!src_file) { + return -1; + } + dest_file = fopen(dest, "wb"); + if (!dest_file) { + fclose(src_file); + return -1; + } + + while(1) { + c = fgetc(src_file); + if (!feof(src_file)) { + fputc(c, dest_file); + } else { + break; + } + } + + fclose(src_file); + fclose(dest_file); + return 0; +} s_JamBase *open_jam_base(char *path) { int ret; @@ -105,6 +137,12 @@ int parse_config_file(char *filename) { if (strncasecmp(buffer, "INDIR", 5) == 0) { trimwhitespace(bufferw, 256, &buffer[6]); baseindir = strdup(bufferw); + } else if (strncasecmp(buffer, "OUTDIR", 6) == 0) { + trimwhitespace(bufferw, 256, &buffer[7]); + baseoutdir = strdup(bufferw); + } else if (strncasecmp(buffer, "MYNODE", 6) == 0) { + trimwhitespace(bufferw, 256, &buffer[7]); + mynode = atoi(bufferw); } else if (strncasecmp(buffer, "MSGAREA", 7) == 0) { newarea = NULL; ptr = strtok(&buffer[8], ","); @@ -205,6 +243,7 @@ int isdupe(struct msg_t *msg, char *uuid) { int import(char *filename) { FILE *fptr; char buffer[PATH_MAX]; + char buffer2[PATH_MAX]; char uuid[37]; struct msg_t msg; int ret; @@ -235,6 +274,28 @@ int import(char *filename) { fread(&msg, sizeof(struct msg_t), 1, fptr); + for (i=0;iid) { + areaid = i; + break; + } + } + + for (i=0;ilink_count;i++) { + if (areas[areaid]->links[i] == msg.oaddr) { + continue; + } + 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); + continue; + } + } + snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, areas[areaid]->links[i], filename); + copy_file(buffer, buffer2); + } + ret = isdupe(&msg, uuid); if (ret == -1) { fclose(fptr); @@ -297,12 +358,7 @@ int import(char *filename) { JAM_PutSubfield(jsp, &jsf); jmh.ReplyCRC = JAM_Crc32(msg.reply, strlen(msg.reply)); } - for (i=0;iid) { - areaid = i; - break; - } - } + jb = open_jam_base(areas[areaid]->basedir); if (!jb) { return 0; @@ -358,6 +414,11 @@ int main(int argc, char **argv) { fprintf(stderr, "Error parsing config file: %s\n", argv[1]); return -1; } + + if (baseoutdir == NULL) { + fprintf(stderr, "OUTDIR must be defined\n"); + return -1; + } if (baseindir == NULL) { fprintf(stderr, "INDIR must be defined\n");