From 1bf1dfff0555f9d9031f0aa462896fad73f4e7e7 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 27 May 2018 21:44:29 +1000 Subject: [PATCH] Move mnet utils as a submodule --- .gitignore | 4 - .gitmodules | 3 + utils/mnet | 1 + utils/mnetftpc/Makefile | 56 --- utils/mnetftpc/mnetftpc | 1 + utils/mnetftpc/mnetftpc.c | 216 ----------- utils/mnetscan/Makefile | 21 - utils/mnetscan/mnetscan | 1 + utils/mnetscan/mnetscan.c | 405 ------------------- utils/mnetsubunsub/Makefile | 26 -- utils/mnetsubunsub/mnetsubunsub | 1 + utils/mnetsubunsub/mnetsubunsub.c | 372 ------------------ utils/mnettoss/Makefile | 21 - utils/mnettoss/mnettoss | 1 + utils/mnettoss/mnettoss.c | 619 ------------------------------ 15 files changed, 8 insertions(+), 1740 deletions(-) create mode 100644 .gitmodules create mode 160000 utils/mnet delete mode 100644 utils/mnetftpc/Makefile create mode 120000 utils/mnetftpc/mnetftpc delete mode 100644 utils/mnetftpc/mnetftpc.c delete mode 100644 utils/mnetscan/Makefile create mode 120000 utils/mnetscan/mnetscan delete mode 100644 utils/mnetscan/mnetscan.c delete mode 100644 utils/mnetsubunsub/Makefile create mode 120000 utils/mnetsubunsub/mnetsubunsub delete mode 100644 utils/mnetsubunsub/mnetsubunsub.c delete mode 100644 utils/mnettoss/Makefile create mode 120000 utils/mnettoss/mnettoss delete mode 100644 utils/mnettoss/mnettoss.c diff --git a/.gitignore b/.gitignore index 0461a46..cdfa7ee 100644 --- a/.gitignore +++ b/.gitignore @@ -89,14 +89,10 @@ deps/libuuid/libtool deps/libuuid/libuuid.la deps/libuuid/stamp-h1 deps/libuuid/uuid.pc -utils/mnetscan/mnetscan mail.out -utils/mnettoss/mnettoss mnet/* -utils/mnetsubunsub/mnetsubunsub deps/libuuid/autom4te.cache utils/mnetftpd/mnetftpd -utils/mnetftpc/mnetftpc deps/ftplib-4.0-1/src/qftp.static deps/ftplib-4.0-1/src/libftp.so deps/ftplib-4.0-1/src/libftp.so.4 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f79d495 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "utils/mnet"] + path = utils/mnet + url = https://github.com/MagickaBBS/MagiNet diff --git a/utils/mnet b/utils/mnet new file mode 160000 index 0000000..1a4f77c --- /dev/null +++ b/utils/mnet @@ -0,0 +1 @@ +Subproject commit 1a4f77c29fa8245489d0107d8e7f3d7d054cba8e diff --git a/utils/mnetftpc/Makefile b/utils/mnetftpc/Makefile deleted file mode 100644 index 1d44db5..0000000 --- a/utils/mnetftpc/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -OS := $(shell uname -s) - -ifeq ($(OS), FreeBSD) - CC=cc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS=-L/usr/local/lib -endif -ifeq ($(OS), DragonFly) - CC=cc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS=-L/usr/local/lib -endif -ifeq ($(OS), NetBSD) - CC=cc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib -endif -ifeq ($(OS), OpenBSD) - CC=cc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS=-L/usr/local/lib -endif -ifeq ($(OS), Linux) - CC=gcc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS= -endif -ifeq ($(OS), Darwin) - CC=cc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS= -endif -ifeq ($(OS), SunOS) - CC=gcc - CFLAGS=-I/usr/local/include -I../../deps/ -I../../deps/ftplib-4.0-1/src - LDFLAGS=-lsocket -lnsl -lresolv -endif -DEPS = mnetftpc.c -LIBFTP = ../../deps/ftplib-4.0-1/src/libftp.a -OBJ = mnetftpc.o - -all: mnetftpc - -%.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) - -$(LIBFTP): - cd ../../deps/ftplib-4.0-1/src && $(MAKE) libftp.a - -mnetftpc: $(OBJ) $(LIBFTP) - $(CC) -o mnetftpc $^ -L/usr/local/lib $(LDFLAGS) - -.PHONY: clean - -clean: - rm -f $(OBJ) mnetftpc \ No newline at end of file diff --git a/utils/mnetftpc/mnetftpc b/utils/mnetftpc/mnetftpc new file mode 120000 index 0000000..2ca1b66 --- /dev/null +++ b/utils/mnetftpc/mnetftpc @@ -0,0 +1 @@ +../mnet/mnetftpc \ No newline at end of file diff --git a/utils/mnetftpc/mnetftpc.c b/utils/mnetftpc/mnetftpc.c deleted file mode 100644 index 80f95e8..0000000 --- a/utils/mnetftpc/mnetftpc.c +++ /dev/null @@ -1,216 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int imhub = 0; -int hubnode = 0; -char *baseindir = NULL; -char *baseoutdir = NULL; -char *ftphost = NULL; -char *ftpusername = NULL; -char *ftppassword = NULL; -char **filenames; -int file_count = 0; - - -size_t trimwhitespace(char *out, size_t len, const char *str) { - if(len == 0) - return 0; - - const char *end; - size_t out_size; - - // Trim leading space - while(isspace((unsigned char)*str)) str++; - - if(*str == 0) { - *out = 0; - return 1; - } - - // Trim trailing space - end = str + strlen(str) - 1; - while(end > str && isspace((unsigned char)*end)) end--; - end++; - - // Set output size to minimum of trimmed string length and buffer size minus 1 - out_size = (end - str) < len-1 ? (end - str) : len-1; - - // Copy trimmed string and add null terminator - memcpy(out, str, out_size); - out[out_size] = 0; - - return out_size; -} - -int parse_config_file(char *filename) { - FILE *fptr; - char buffer[256]; - char bufferw[256]; - char *ptr; - - fptr = fopen(filename, "r"); - if (!fptr) { - return 0; - } - - fgets(buffer, 256, fptr); - while (!feof(fptr)) { - if (buffer[0] != ';') { - if (buffer[strlen(buffer) - 1] == '\n'){ - buffer[strlen(buffer) - 1] = '\0'; - if (strncasecmp(buffer, "IMHUB", 5) == 0) { - trimwhitespace(bufferw, 256, &buffer[6]); - 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, "FTPHOST", 7) == 0) { - trimwhitespace(bufferw, 256, &buffer[8]); - ftphost = strdup(bufferw); - } else if (strncasecmp(buffer, "FTPUSER", 7) == 0) { - trimwhitespace(bufferw, 256, &buffer[8]); - ftpusername = strdup(bufferw); - } else if (strncasecmp(buffer, "FTPPASS", 7) == 0) { - trimwhitespace(bufferw, 256, &buffer[8]); - ftppassword = strdup(bufferw); - } else 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 { - fclose(fptr); - return 0; - } - } - fgets(buffer, 256, fptr); - } - - fclose(fptr); - return 1; -} - -int main(int argc, char **argv) { - netbuf *nb; - netbuf *nd; - char buffer[PATH_MAX]; - int len; - int i; - DIR *outdir; - struct dirent *dent; - struct stat s; - - - if (argc < 2) { - fprintf(stderr, "Usage ./mnetftpc mnet.cfg\n"); - return -1; - } - - if (!parse_config_file(argv[1])) { - 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"); - return -1; - } - - if (ftphost == NULL) { - fprintf(stderr, "FTPHOST must be defined\n"); - return -1; - } - - if (ftpusername == NULL) { - fprintf(stderr, "FTPUSER must be defined\n"); - return -1; - } - - if (ftppassword == NULL) { - fprintf(stderr, "FTPPASS must be defined\n"); - return -1; - } - - FtpInit(); - if (FtpConnect(ftphost, &nb)) { - if (FtpLogin(ftpusername, ftppassword, nb)) { - // logged in... - // receive files in in - if (FtpChdir("in", nb)) { - if (FtpAccess("/in", FTPLIB_DIR, FTPLIB_ASCII, nb, &nd)) { - len = FtpRead(buffer, PATH_MAX-1, nd); - while(len != -1 && len != 0) { - buffer[len-1] = '\0'; - if (strcmp(buffer, "..") != 0 && strcmp(buffer, ".") != 0) { - if (file_count == 0) { - filenames = (char **)malloc(sizeof(char *)); - } else { - filenames = (char **)realloc(filenames, sizeof(char *) * (file_count + 1)); - } - filenames[file_count] = strdup(buffer); - file_count++; - } - - len = FtpRead(buffer, PATH_MAX-1, nd); - } - - FtpClose(nd); - - for (i=0;id_name); - if (stat(buffer, &s) == 0 && !S_ISDIR(s.st_mode)) { - if (FtpPut(buffer, dent->d_name, FTPLIB_BINARY, nb)) { - fprintf(stdout, "Sent %s\n", dent->d_name); - unlink(buffer); - rewinddir(outdir); - } - } - } - closedir(outdir); - } - - } else { - fprintf(stderr, "Unable to authenticate with FTP server\n"); - } - FtpQuit(nb); - } else { - fprintf(stderr, "Unable to connect to FTP server\n"); - } - return 0; -} \ No newline at end of file diff --git a/utils/mnetscan/Makefile b/utils/mnetscan/Makefile deleted file mode 100644 index 046af63..0000000 --- a/utils/mnetscan/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC=cc -CFLAGS=-I/usr/local/include -I../../deps/ -DEPS = mnetscan.c -JAMLIB = ../../deps/jamlib/jamlib.a -OBJ = mnetscan.o - -all: mnetscan - -%.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) - -$(JAMLIB): - cd ../../deps/jamlib && make -f Makefile.linux - -mnetscan: $(OBJ) $(JAMLIB) - $(CC) -o mnetscan $^ $(CFLAGS) -L/usr/local/lib - -.PHONY: clean - -clean: - rm -f $(OBJ) mnetscan diff --git a/utils/mnetscan/mnetscan b/utils/mnetscan/mnetscan new file mode 120000 index 0000000..6633c36 --- /dev/null +++ b/utils/mnetscan/mnetscan @@ -0,0 +1 @@ +../mnet/mnetscan \ No newline at end of file diff --git a/utils/mnetscan/mnetscan.c b/utils/mnetscan/mnetscan.c deleted file mode 100644 index 14863d4..0000000 --- a/utils/mnetscan/mnetscan.c +++ /dev/null @@ -1,405 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "jamlib/jam.h" - -char *baseoutdir = NULL; - -struct msgarea_t { - int id; - int hub; - char *basedir; - int *links; - int link_count; -}; - -struct msg_t { - uint32_t area; - char from[32]; - char to[32]; - char subject[64]; - uint32_t timedate; - uint32_t oaddr; - uint32_t daddr; - uint32_t type; - char reply[36]; -} __attribute__ ((packed)); - -struct msgarea_t **areas; -int area_count; -int mynode = 0; -int hubnode = 0; -int imhub = 0; - -void msg_to_nl(struct msg_t *msg) { - msg->area = htonl(msg->area); - msg->timedate = htonl(msg->timedate); - msg->oaddr = htonl(msg->oaddr); - msg->daddr = htonl(msg->daddr); - msg->type = htonl(msg->type); -} - -s_JamBase *open_jam_base(char *path) { - int ret; - s_JamBase *jb; - - ret = JAM_OpenMB((char *)path, &jb); - - if (ret != 0) { - if (ret == JAM_IO_ERROR) { - free(jb); - ret = JAM_CreateMB((char *)path, 1, &jb); - if (ret != 0) { - free(jb); - return NULL; - } - } else { - free(jb); - return NULL; - } - } - return jb; -} - -size_t trimwhitespace(char *out, size_t len, const char *str) { - if(len == 0) - return 0; - - const char *end; - size_t out_size; - - // Trim leading space - while(isspace((unsigned char)*str)) str++; - - if(*str == 0) { - *out = 0; - return 1; - } - - // Trim trailing space - end = str + strlen(str) - 1; - while(end > str && isspace((unsigned char)*end)) end--; - end++; - - // Set output size to minimum of trimmed string length and buffer size minus 1 - out_size = (end - str) < len-1 ? (end - str) : len-1; - - // Copy trimmed string and add null terminator - memcpy(out, str, out_size); - out[out_size] = 0; - - return out_size; -} - -int parse_config_file(char *filename) { - FILE *fptr; - char buffer[256]; - char bufferw[256]; - char *ptr; - struct msgarea_t *newarea; - - area_count = 0; - - fptr = fopen(filename, "r"); - if (!fptr) { - return 0; - } - - fgets(buffer, 256, fptr); - while (!feof(fptr)) { - if (buffer[0] != ';') { - if (buffer[strlen(buffer) - 1] == '\n'){ - buffer[strlen(buffer) - 1] = '\0'; - - if (strncasecmp(buffer, "MYNODE", 6) == 0) { - trimwhitespace(bufferw, 256, &buffer[7]); - mynode = atoi(bufferw); - } else if (strncasecmp(buffer, "IMHUB", 5) == 0) { - trimwhitespace(bufferw, 256, &buffer[6]); - 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, "OUTDIR", 6) == 0) { - trimwhitespace(bufferw, 256, &buffer[7]); - baseoutdir = strdup(bufferw); - } else if (strncasecmp(buffer, "MSGAREA", 7) == 0) { - newarea = NULL; - ptr = strtok(&buffer[8], ","); - - if (ptr != NULL) { - newarea = (struct msgarea_t *)malloc(sizeof(struct msgarea_t)); - trimwhitespace(bufferw, 256, ptr); - newarea->id = atoi(bufferw); - newarea->link_count = 0; - ptr = strtok(NULL, ","); - - if (ptr != NULL) { - trimwhitespace(bufferw, 256, ptr); - newarea->hub = atoi(bufferw); - ptr = strtok(NULL, ","); - if (ptr != NULL) { - - trimwhitespace(bufferw, 256, ptr); - 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, ","); - } - } - } - } - if (newarea != NULL) { - if (area_count == 0) { - areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *)); - } else { - areas = (struct msgarea_t **)realloc(areas, sizeof(struct msgarea_t *) * (area_count + 1)); - } - areas[area_count] = newarea; - area_count++; - } - } - } else { - fclose(fptr); - return 0; - } - } - fgets(buffer, 256, fptr); - } - - fclose(fptr); - return 1; -} - -int export_messages(int area) { - s_JamBase *jb; - s_JamBaseHeader jbh; - s_JamMsgHeader jmh; - s_JamSubPacket* jsp; - - FILE *fptr; - - char buffer[PATH_MAX]; - - int i; - int z; - int len; - int n; - int scanned = 0; - - struct msg_t msg; - char msgid[37]; - - char *body; - struct stat st; - - jb = open_jam_base(areas[area]->basedir); - if (!jb) { - return 0; - } - JAM_ReadMBHeader(jb, &jbh); - if (jbh.ActiveMsgs > 0) { - for (i=0;iNumFields;z++) { - if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { - if (jsp->Fields[z]->DatLen > 63) { - len = 64; - } else { - len = jsp->Fields[z]->DatLen; - } - memcpy(msg.subject, jsp->Fields[z]->Buffer, len); - } - if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) { - if (jsp->Fields[z]->DatLen > 61) { - len = 32; - } else { - len = jsp->Fields[z]->DatLen; - } - memcpy(msg.from, jsp->Fields[z]->Buffer, len); - } - if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) { - if (jsp->Fields[z]->DatLen > 61) { - len = 32; - } else { - len = jsp->Fields[z]->DatLen; - } - memcpy(msg.to, jsp->Fields[z]->Buffer, len); - } - 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)); - } - if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) { - 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); - JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body); - - jmh.Attribute |= JAM_MSG_SENT; - - while (1) { - z = JAM_LockMB(jb, 100); - if (z == 0) { - break; - } else if (z == JAM_LOCK_FAILED) { - sleep(1); - } else { - free(body); - JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); - free(jb); - fprintf(stderr, "Error locking JAM base!\n"); - return scanned; - } - } - n =JAM_ChangeMsgHeader(jb, i, &jmh); - if (n != 0) { - fprintf(stderr, "Error updating message header %d %d\n", n, JAM_Errno(jb)); - } - JAM_UnlockMB(jb); - JAM_DelSubPacket(jsp); - - msg.area = areas[area]->id; - msg.type = 0; - if (areas[area]->hub == mynode) { - msg_to_nl(&msg); - 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 = htonl(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; - } - } - 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); - continue; - } - - msg_to_nl(&msg); - - fwrite(&msg, sizeof(struct msg_t), 1, fptr); - fwrite(body, strlen(body), 1, fptr); - fclose(fptr); - } - scanned++; - } - } - } - JAM_CloseMB(jb); - free(jb); - - return scanned; -} - -int main(int argc, char **argv) { - int i; - int l; - - if (argc < 2) { - fprintf(stderr, "Usage ./mnetscan mnet.cfg\n"); - return -1; - } - - if (!parse_config_file(argv[1])) { - fprintf(stderr, "Error parsing config file: %s\n", argv[1]); - return -1; - } - - if (baseoutdir == NULL) { - fprintf(stderr, "OUTDIR must be defined\n"); - return -1; - } - - printf("Out Base Dir: %s\n", baseoutdir); - - for (i=0;iid); - printf(" - path %s\n", areas[i]->basedir); - printf(" - links: "); - for (l=0;llink_count;l++) { - printf("%d, ", areas[i]->links[l]); - } - printf("\n"); - - printf("\nExported %d messages\n", export_messages(i)); - } - return 0; -} \ No newline at end of file diff --git a/utils/mnetsubunsub/Makefile b/utils/mnetsubunsub/Makefile deleted file mode 100644 index 3a90fa2..0000000 --- a/utils/mnetsubunsub/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -CC=cc -CFLAGS=-I/usr/local/include -I../../deps/ -DEPS = mnetsubunsub.c -JAMLIB = ../../deps/jamlib/jamlib.a -LIBUUID = ../../deps/libuuid/.libs/libuuid.a -OBJ = mnetsubunsub.o - -all: mnetsubunsub - -%.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) - -$(JAMLIB): - cd ../../deps/jamlib && make -f Makefile.linux - -$(LIBUUID): - cd ../../deps/libuuuid && ./configure - cd ../../deps/libuuuid && $(MAKE) - -mnetsubunsub: $(OBJ) $(JAMLIB) $(LIBUUID) - $(CC) -o mnetsubunsub $^ $(CFLAGS) -L/usr/local/lib - -.PHONY: clean - -clean: - rm -f $(OBJ) mnetsubunsub diff --git a/utils/mnetsubunsub/mnetsubunsub b/utils/mnetsubunsub/mnetsubunsub new file mode 120000 index 0000000..d659202 --- /dev/null +++ b/utils/mnetsubunsub/mnetsubunsub @@ -0,0 +1 @@ +../mnet/mnetsubunsub \ No newline at end of file diff --git a/utils/mnetsubunsub/mnetsubunsub.c b/utils/mnetsubunsub/mnetsubunsub.c deleted file mode 100644 index c03f537..0000000 --- a/utils/mnetsubunsub/mnetsubunsub.c +++ /dev/null @@ -1,372 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libuuid/uuid.h" - -char *baseindir = NULL; -char *baseoutdir = NULL; - -char *config_file; - -int imhub = 0; - -struct msgarea_t { - int id; - int hub; - char *basedir; - int *links; - int link_count; -}; - -struct msg_t { - uint32_t area; - char from[32]; - char to[32]; - char subject[64]; - uint32_t timedate; - uint32_t oaddr; - uint32_t daddr; - uint32_t type; - char reply[36]; -} __attribute__ ((packed)); - -struct msgarea_t **areas; -int area_count; -int mynode = 0; -int hubnode = 0; - -void msg_to_nl(struct msg_t *msg) { - msg->area = htonl(msg->area); - msg->timedate = htonl(msg->timedate); - msg->oaddr = htonl(msg->oaddr); - msg->daddr = htonl(msg->daddr); - msg->type = htonl(msg->type); -} - -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; -} - -size_t trimwhitespace(char *out, size_t len, const char *str) { - if(len == 0) - return 0; - - const char *end; - size_t out_size; - - // Trim leading space - while(isspace((unsigned char)*str)) str++; - - if(*str == 0) { - *out = 0; - return 1; - } - - // Trim trailing space - end = str + strlen(str) - 1; - while(end > str && isspace((unsigned char)*end)) end--; - end++; - - // Set output size to minimum of trimmed string length and buffer size minus 1 - out_size = (end - str) < len-1 ? (end - str) : len-1; - - // Copy trimmed string and add null terminator - memcpy(out, str, out_size); - out[out_size] = 0; - - return out_size; -} - -int parse_config_file(char *filename) { - FILE *fptr; - char buffer[256]; - char bufferw[256]; - char *ptr; - struct msgarea_t *newarea; - - - area_count = 0; - - fptr = fopen(filename, "r"); - if (!fptr) { - return 0; - } - - fgets(buffer, 256, fptr); - while (!feof(fptr)) { - if (buffer[0] != ';') { - if (buffer[strlen(buffer) - 1] == '\n'){ - buffer[strlen(buffer) - 1] = '\0'; - if (strncasecmp(buffer, "IMHUB", 5) == 0) { - trimwhitespace(bufferw, 256, &buffer[6]); - 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); - } 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], ","); - - if (ptr != NULL) { - newarea = (struct msgarea_t *)malloc(sizeof(struct msgarea_t)); - trimwhitespace(bufferw, 256, ptr); - newarea->id = atoi(bufferw); - newarea->link_count = 0; - ptr = strtok(NULL, ","); - - if (ptr != NULL) { - trimwhitespace(bufferw, 256, ptr); - newarea->hub = atoi(bufferw); - ptr = strtok(NULL, ","); - if (ptr != NULL) { - - trimwhitespace(bufferw, 256, ptr); - 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, ","); - } - } - } - } - if (newarea != NULL) { - if (area_count == 0) { - areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *)); - } else { - areas = (struct msgarea_t **)realloc(areas, sizeof(struct msgarea_t *) * (area_count + 1)); - } - areas[area_count] = newarea; - area_count++; - } - } - } else { - fclose(fptr); - return 0; - } - } - fgets(buffer, 256, fptr); - } - - fclose(fptr); - return 1; -} - - - -void remove_config_file_area(int areaid) { - char backup[PATH_MAX]; - char buffer[256]; - char bufferc[256]; - char bufferw[256]; - FILE *fptr1; - FILE *fptr2; - char *ptr; - int id; - int i; - - snprintf(backup, PATH_MAX, "%s.bak", config_file); - fptr1 = fopen(config_file, "r"); - fptr2 = fopen(backup, "w"); - - fgets(buffer, 256, fptr1); - while (!feof(fptr1)) { - if (strncasecmp(buffer, "MSGAREA", 7) == 0) { - strcpy(bufferc, buffer); - ptr = strtok(&bufferc[8], ","); - if (ptr != NULL) { - trimwhitespace(bufferw, 256, ptr); - id = atoi(bufferw); - if (id != areaid) { - fputs(buffer, fptr2); - } - } - } else { - fputs(buffer, fptr2); - } - fgets(buffer, 256, fptr1); - } - fclose(fptr1); - fclose(fptr2); - unlink(config_file); - rename(backup, config_file); -} - -int main(int argc, char **argv) { - char buffer[PATH_MAX]; - struct msg_t msg; - uuid_t myuuid; - char msgid[37]; - FILE *fptr, *fptr2; - struct stat st; - - if (argc != 6) { - fprintf(stderr, "Usage ./mnetsubunsub [Configfile] [ADD/REMOVE] [AREA#] [HOST#] [JamBase]"); - return -1; - } - - if (!parse_config_file(argv[1])) { - fprintf(stderr, "Error parsing config file: %s\n", argv[1]); - return -1; - } - - if (baseoutdir == NULL) { - fprintf(stderr, "OUTDIR must be defined\n"); - return -1; - } - config_file = argv[1]; - - if (strcasecmp(argv[2], "ADD") == 0) { - // send add control message - memset(&msg, 0, sizeof(struct msg_t)); - msg.area = atoi(argv[3]); - sprintf(msg.from, "SYSTEM"); - sprintf(msg.to, "SYSTEM"); - sprintf(msg.subject, "ADD Message"); - msg.timedate = time(NULL); - msg.oaddr = mynode; - msg.daddr = atoi(argv[4]); - msg.type = 1; - if (imhub) { - snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, msg.daddr); - } 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); - return -1; - } - } - - memset(msgid, 0, 37); - uuid_generate(myuuid); - uuid_unparse_lower(myuuid, msgid); - - if (imhub) { - snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, msg.daddr, msg.daddr, msgid); - } else { - snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, msg.daddr, msgid); - } - fptr = fopen(buffer, "wb"); - if (fptr == NULL) { - fprintf(stderr, "Error creating file %s\n", buffer); - return -1; - } - - // add config line - fptr2 = fopen(argv[1], "a"); - fprintf(fptr2, "MSGAREA %d, %d, %s\n", msg.area, msg.daddr, argv[5]); - fclose(fptr2); - - msg_to_nl(&msg); - - fwrite(&msg, sizeof(struct msg_t), 1, fptr); - fwrite("ADD\r", 4, 1, fptr); - fclose(fptr); - - - - } else if (strcasecmp(argv[2], "REMOVE") == 0) { - // send remove control message - memset(&msg, 0, sizeof(struct msg_t)); - msg.area = atoi(argv[3]); - sprintf(msg.from, "SYSTEM"); - sprintf(msg.to, "SYSTEM"); - sprintf(msg.subject, "REMOVE Message"); - msg.timedate = time(NULL); - msg.oaddr = mynode; - msg.daddr = atoi(argv[4]); - msg.type = 1; - if (imhub) { - snprintf(buffer, PATH_MAX, "%s/%d/", baseoutdir, msg.daddr); - } 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); - return -1; - } - } - - memset(msgid, 0, 37); - uuid_generate(myuuid); - uuid_unparse_lower(myuuid, msgid); - - if (imhub) { - snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, msg.daddr, msg.daddr, msgid); - } else { - snprintf(buffer, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, msg.daddr, msgid); - } - fptr = fopen(buffer, "wb"); - if (fptr == NULL) { - fprintf(stderr, "Error creating file %s\n", buffer); - return -1; - } - - // remove config line - remove_config_file_area(msg.area); - - msg_to_nl(&msg); - - fwrite(&msg, sizeof(struct msg_t), 1, fptr); - fwrite("REMOVE\r", 7, 1, fptr); - fclose(fptr); - - - } - return 0; -} \ No newline at end of file diff --git a/utils/mnettoss/Makefile b/utils/mnettoss/Makefile deleted file mode 100644 index e7eeab7..0000000 --- a/utils/mnettoss/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC=cc -CFLAGS=-I/usr/local/include -I../../deps/ -DEPS = mnettoss.c -JAMLIB = ../../deps/jamlib/jamlib.a -OBJ = mnettoss.o - -all: mnettoss - -%.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) - -$(JAMLIB): - cd ../../deps/jamlib && make -f Makefile.linux - -mnettoss: $(OBJ) $(JAMLIB) - $(CC) -o mnettoss $^ $(CFLAGS) -L/usr/local/lib - -.PHONY: clean - -clean: - rm -f $(OBJ) mnettoss diff --git a/utils/mnettoss/mnettoss b/utils/mnettoss/mnettoss new file mode 120000 index 0000000..561546b --- /dev/null +++ b/utils/mnettoss/mnettoss @@ -0,0 +1 @@ +../mnet/mnettoss \ No newline at end of file diff --git a/utils/mnettoss/mnettoss.c b/utils/mnettoss/mnettoss.c deleted file mode 100644 index fbb28f8..0000000 --- a/utils/mnettoss/mnettoss.c +++ /dev/null @@ -1,619 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "jamlib/jam.h" - -char *baseindir = NULL; -char *baseoutdir = NULL; - -char *config_file; - -int imhub = 0; - -struct msgarea_t { - int id; - int hub; - char *basedir; - int *links; - int link_count; -}; - -struct msg_t { - uint32_t area; - char from[32]; - char to[32]; - char subject[64]; - uint32_t timedate; - uint32_t oaddr; - uint32_t daddr; - uint32_t type; - char reply[36]; -} __attribute__ ((packed)); - -struct msgarea_t **areas; -int area_count; -int mynode = 0; -int hubnode = 0; - -void msg_to_hl(struct msg_t *msg) { - msg->area = ntohl(msg->area); - msg->timedate = ntohl(msg->timedate); - msg->oaddr = ntohl(msg->oaddr); - msg->daddr = ntohl(msg->daddr); - msg->type = ntohl(msg->type); -} - -void msg_to_nl(struct msg_t *msg) { - msg->area = htonl(msg->area); - msg->timedate = htonl(msg->timedate); - msg->oaddr = htonl(msg->oaddr); - msg->daddr = htonl(msg->daddr); - msg->type = htonl(msg->type); -} - -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; - s_JamBase *jb; - - ret = JAM_OpenMB((char *)path, &jb); - - if (ret != 0) { - if (ret == JAM_IO_ERROR) { - free(jb); - ret = JAM_CreateMB((char *)path, 1, &jb); - if (ret != 0) { - free(jb); - return NULL; - } - } else { - free(jb); - return NULL; - } - } - return jb; -} - -size_t trimwhitespace(char *out, size_t len, const char *str) { - if(len == 0) - return 0; - - const char *end; - size_t out_size; - - // Trim leading space - while(isspace((unsigned char)*str)) str++; - - if(*str == 0) { - *out = 0; - return 1; - } - - // Trim trailing space - end = str + strlen(str) - 1; - while(end > str && isspace((unsigned char)*end)) end--; - end++; - - // Set output size to minimum of trimmed string length and buffer size minus 1 - out_size = (end - str) < len-1 ? (end - str) : len-1; - - // Copy trimmed string and add null terminator - memcpy(out, str, out_size); - out[out_size] = 0; - - return out_size; -} - -int parse_config_file(char *filename) { - FILE *fptr; - char buffer[256]; - char bufferw[256]; - char *ptr; - struct msgarea_t *newarea; - - area_count = 0; - - fptr = fopen(filename, "r"); - if (!fptr) { - return 0; - } - - fgets(buffer, 256, fptr); - while (!feof(fptr)) { - if (buffer[0] != ';') { - if (buffer[strlen(buffer) - 1] == '\n'){ - buffer[strlen(buffer) - 1] = '\0'; - if (strncasecmp(buffer, "IMHUB", 5) == 0) { - trimwhitespace(bufferw, 256, &buffer[6]); - 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); - } 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], ","); - - if (ptr != NULL) { - newarea = (struct msgarea_t *)malloc(sizeof(struct msgarea_t)); - trimwhitespace(bufferw, 256, ptr); - newarea->id = atoi(bufferw); - newarea->link_count = 0; - ptr = strtok(NULL, ","); - - if (ptr != NULL) { - trimwhitespace(bufferw, 256, ptr); - newarea->hub = atoi(bufferw); - ptr = strtok(NULL, ","); - if (ptr != NULL) { - - trimwhitespace(bufferw, 256, ptr); - 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, ","); - } - } - } - } - if (newarea != NULL) { - if (area_count == 0) { - areas = (struct msgarea_t **)malloc(sizeof(struct msgarea_t *)); - } else { - areas = (struct msgarea_t **)realloc(areas, sizeof(struct msgarea_t *) * (area_count + 1)); - } - areas[area_count] = newarea; - area_count++; - } - } - } else { - fclose(fptr); - return 0; - } - } - fgets(buffer, 256, fptr); - } - - fclose(fptr); - return 1; -} - -int isdupe(struct msg_t *msg, char *uuid) { - s_JamBase *jb; - s_JamBaseHeader jbh; - s_JamMsgHeader jmh; - s_JamSubPacket* jsp; - - int areaid; - int i; - int z; - - for (i=0;iarea == areas[i]->id) { - areaid = i; - break; - } - } - - jb = open_jam_base(areas[areaid]->basedir); - if (!jb) { - return -1; - } - JAM_ReadMBHeader(jb, &jbh); - if (jbh.ActiveMsgs > 0) { - for (i=0;iNumFields;z++) { - if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) { - if (strncasecmp(uuid, jsp->Fields[z]->Buffer, 36) == 0) { - JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); - free(jb); - return 1; - } - } - } - } - } - JAM_CloseMB(jb); - free(jb); - - return 0; -} - -void update_config_file_area(int areaid) { - char backup[PATH_MAX]; - char buffer[256]; - char bufferc[256]; - char bufferw[256]; - FILE *fptr1; - FILE *fptr2; - char *ptr; - int id; - int i; - - snprintf(backup, PATH_MAX, "%s.bak", config_file); - fptr1 = fopen(config_file, "r"); - fptr2 = fopen(backup, "w"); - - fgets(buffer, 256, fptr1); - while (!feof(fptr1)) { - if (strncasecmp(buffer, "MSGAREA", 7) == 0) { - strcpy(bufferc, buffer); - ptr = strtok(&bufferc[8], ","); - if (ptr != NULL) { - trimwhitespace(bufferw, 256, ptr); - id = atoi(bufferw); - if (id == areas[areaid]->id) { - fprintf(fptr2, "MSGAREA %d, %d, %s", areas[areaid]->id, areas[areaid]->hub, areas[areaid]->basedir); - for (i=0;ilink_count;i++) { - fprintf(fptr2, ", %d", areas[areaid]->links[i]); - } - fprintf(fptr2, "\n"); - } else { - fputs(buffer, fptr2); - } - } - } else { - fputs(buffer, fptr2); - } - fgets(buffer, 256, fptr1); - } - fclose(fptr1); - fclose(fptr2); - unlink(config_file); - rename(backup, config_file); -} - -int import(char *filename) { - FILE *fptr; - char buffer[PATH_MAX]; - char buffer2[PATH_MAX]; - char uuid[37]; - struct msg_t msg; - int ret; - int areaid; - struct stat st; - int z; - int i; - int j; - char *body; - s_JamBase *jb; - s_JamBaseHeader jbh; - s_JamMsgHeader jmh; - s_JamSubPacket* jsp; - s_JamSubfield jsf; - - snprintf(buffer, PATH_MAX, "%s/%s", baseindir, filename); - strncpy(uuid, strchr(filename, '-') + 1, 36); - - uuid[36] = '\0'; - - if (stat(buffer, &st) != 0) { - return 0; - } - - fptr = fopen(buffer, "rb"); - if (!fptr) { - return 0; - } - - fread(&msg, sizeof(struct msg_t), 1, fptr); - - msg_to_hl(&msg); - - body = malloc(st.st_size - sizeof(struct msg_t) + 1); - - memset(body, 0, st.st_size - sizeof(struct msg_t) + 1); - - fread(body, st.st_size - sizeof(struct msg_t), 1, fptr); - - fclose(fptr); - - - if (msg.daddr != mynode) { - if (imhub) { - snprintf(buffer2, PATH_MAX, "%s/%d/%s", baseoutdir, msg.daddr, filename); - copy_file(buffer, buffer2); - } - return 1; - } else { - for (i=0;iid) { - areaid = i; - break; - } - } - - if (areas[areaid]->hub == mynode) { - if (msg.type == 1) { - if (strncasecmp(body, "ADD", 3) == 0) { - for (i=0;ilink_count;i++) { - if (areas[areaid]->links[i] == msg.oaddr) { - // already subscribed - return 1; - } - } - - if (areas[areaid]->link_count == 0) { - areas[areaid]->links = (int *)malloc(sizeof(int)); - } else { - areas[areaid]->links = (int *)realloc(areas[areaid]->links, sizeof(int) * (areas[areaid]->link_count + 1)); - } - - areas[areaid]->links[areas[areaid]->link_count] = msg.oaddr; - areas[areaid]->link_count++; - - // - update_config_file_area(areaid); - - } else if (strncasecmp(body, "REMOVE", 6) == 0) { - for (i=0;ilink_count;i++) { - if (areas[areaid]->links[i] == msg.oaddr) { - - if (areas[areaid]->link_count == 1) { - free(areas[areaid]->links); - areas[areaid]->link_count = 0; - } else { - for (j=i;jlink_count-1;j++) { - areas[areaid]->links[j] = areas[areaid]->links[j+1]; - } - - areas[areaid]->links = (int *)realloc(areas[areaid]->links, sizeof(int) * (areas[areaid]->link_count - 1)); - areas[areaid]->link_count--; - - - } - update_config_file_area(areaid); - return 1; - } - } - } - return 1; - } - - for (i=0;ilink_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.message", baseoutdir, areas[areaid]->links[i], areas[areaid]->links[i], uuid); - } else { - snprintf(buffer2, PATH_MAX, "%s/%d/%d-%s.message", baseoutdir, hubnode, areas[areaid]->links[i], uuid); - } - msg.daddr = areas[areaid]->links[i]; - msg_to_nl(&msg); - - fptr = fopen(buffer2, "wb"); - fwrite(&msg, sizeof(struct msg_t), 1, fptr); - fwrite(body, strlen(body), 1, fptr); - fclose(fptr); - - msg_to_hl(&msg); - } - } - } - - - ret = isdupe(&msg, uuid); - if (ret == -1) { - free(body); - fclose(fptr); - return 0; - } else if (ret == 1) { - free(body); - fclose(fptr); - return 1; - } - - - JAM_ClearMsgHeader(&jmh); - jmh.DateWritten = msg.timedate; - jmh.Attribute |= JAM_MSG_TYPEECHO; - - jsp = JAM_NewSubPacket(); - - jsf.LoID = JAMSFLD_SENDERNAME; - jsf.HiID = 0; - jsf.DatLen = strlen(msg.from); - jsf.Buffer = msg.from; - JAM_PutSubfield(jsp, &jsf); - - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; - jsf.DatLen = strlen(msg.to); - jsf.Buffer = msg.to; - JAM_PutSubfield(jsp, &jsf); - - jsf.LoID = JAMSFLD_SUBJECT; - jsf.HiID = 0; - jsf.DatLen = strlen(msg.subject); - jsf.Buffer = msg.subject; - JAM_PutSubfield(jsp, &jsf); - - sprintf(buffer, "%d", msg.oaddr); - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = buffer; - JAM_PutSubfield(jsp, &jsf); - - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; - jsf.DatLen = strlen(uuid); - jsf.Buffer = uuid; - JAM_PutSubfield(jsp, &jsf); - - if (strlen(msg.reply)> 0) { - jsf.LoID = JAMSFLD_REPLYID; - jsf.HiID = 0; - jsf.DatLen = strlen(msg.reply); - jsf.Buffer = msg.reply; - JAM_PutSubfield(jsp, &jsf); - jmh.ReplyCRC = JAM_Crc32(msg.reply, strlen(msg.reply)); - } - - jb = open_jam_base(areas[areaid]->basedir); - if (!jb) { - return 0; - } - while (1) { - z = JAM_LockMB(jb, 100); - if (z == 0) { - break; - } else if (z == JAM_LOCK_FAILED) { - sleep(1); - } else { - free(body); - JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); - free(jb); - fprintf(stderr, "Error locking JAM base!\n"); - return 0; - } - } - if (JAM_AddMessage(jb, &jmh, jsp, body, strlen(body))) { - JAM_UnlockMB(jb); - JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); - free(jb); - fprintf(stderr, "Error Adding Message!\n"); - free(body); - return 0; - } - JAM_UnlockMB(jb); - JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); - free(jb); - - free(body); - - return 1; -} - -int main(int argc, char **argv) { - int i; - int l; - int processed = 0; - DIR *indir; - struct dirent *dent; - char buffer[PATH_MAX]; - - if (argc < 2) { - fprintf(stderr, "Usage ./mnettoss mnet.cfg\n"); - return -1; - } - - if (!parse_config_file(argv[1])) { - fprintf(stderr, "Error parsing config file: %s\n", argv[1]); - return -1; - } - - config_file = argv[1]; - - if (baseoutdir == NULL) { - fprintf(stderr, "OUTDIR must be defined\n"); - return -1; - } - - if (baseindir == NULL) { - fprintf(stderr, "INDIR must be defined\n"); - return -1; - } - - printf("In Base Dir: %s\n", baseindir); - - indir = opendir(baseindir); - if (!indir) { - fprintf(stderr, "Error opening inbound directory!\n"); - return -1; - } - - while ((dent = readdir(indir)) != NULL) { - if (strlen(dent->d_name) < 8) { - continue; - } - - if (strcasecmp(&dent->d_name[strlen(dent->d_name) - 8], ".message") == 0) { - if (import(dent->d_name)) { - processed++; - snprintf(buffer, PATH_MAX, "%s/%s", baseindir, dent->d_name); - unlink(buffer); - rewinddir(indir); - } - } - } - closedir(indir); - - printf("Processed %d Messages\n", processed); - return 0; -} \ No newline at end of file