Toss now exports to other nodes... or at least it should :)
This commit is contained in:
parent
42fdc30972
commit
ea2b6a5b56
@ -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
|
@ -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;i<area_count;i++) {
|
||||
if (msg.area == areas[i]->id) {
|
||||
areaid = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<areas[areaid]->link_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;i<area_count;i++) {
|
||||
if (msg.area == areas[i]->id) {
|
||||
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");
|
||||
|
Reference in New Issue
Block a user