]> code.citadel.org Git - citadel.git/blobdiff - citadel/netproc.c
* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / netproc.c
index e1301b607b2b0c74f9a64f3fc231e5bf40812d40..93b20f627e193f62bc9b99e58184c50851abccfb 100644 (file)
@@ -1,7 +1,9 @@
 /*
+ * $Id$
+ *
  * Citadel/UX Intelligent Network Processor for IGnet/Open networks
  * See copyright.txt for copyright information
- * $Id$
+ *
  */
 
 /* How long it takes for an old node to drop off the network map */
 #define USE_TIME       (604800L)
 
 /* Where do we keep our lock file? */
-#define LOCKFILE       "/var/lock/LCK.netproc"
+#define LOCKFILE       "/tmp/netproc.LCK"
 
 /* Path to the 'uudecode' utility (needed for network file transfers) */
 #define UUDECODE       "/usr/bin/uudecode"
 
 /* Files used by the networker */
-#define ZAPLIST                "./network/zaplist"
 #define MAILSYSINFO    "./network/mail.sysinfo"
 
 /* Uncomment the DEBUG def to see noisy traces */
@@ -42,6 +43,7 @@
 #endif
 #include "citadel.h"
 #include "tools.h"
+#include "ipc.h"
 
 /* A list of users you wish to filter out of incoming traffic can be kept
  * in ./network/filterlist -- messages from these users will be automatically
@@ -84,13 +86,40 @@ struct syslist {
 };
 
 
-void attach_to_server(int argc, char **argv);
+
+/*
+ * This structure is used to hold all of the fields of a message
+ * during conversion, processing, or whatever.
+ */
+struct minfo {
+       char A[512];
+       char B[512];
+       char C[512];
+       char D[512];
+       char E[512];
+       char G[512];
+       char H[512];
+       char I[512];
+       char N[512];
+       char O[512];
+       char P[512];
+       char R[512];
+       char S[512];
+       long T;
+       char U[512];
+       char Z[512];
+       char nexthop[512];
+       };
+
+
+
 void serv_read(char *buf, int bytes);
 void serv_write(char *buf, int nbytes);
 void get_config(void);
 
 struct filterlist *filter = NULL;
 struct syslist *slist = NULL;
+struct msglist *purgelist = NULL;
 
 struct config config;
 extern char bbs_home_directory[];
@@ -539,7 +568,7 @@ BONFGM:     b = getc(fp);
        if (b == 'T')
                buffer->T = atol(bbb);
        if (b == 'I')
-               buffer->I = atol(bbb);
+               strcpy(buffer->I, bbb);
        if (b == 'H')
                strcpy(buffer->H, bbb);
        if (b == 'B')
@@ -554,14 +583,6 @@ BONFGM:    b = getc(fp);
 
 END:
 
-       /* NOTE: we used to use the following two lines of code to assign
-        * the timestamp as a message-ID if there was no message-ID already
-        * in the message.  We don't do this anymore because it screws up
-        * the loopzapper.
-        *
-       if (buffer->I == 0L)
-               buffer->I = buffer->T;
-        */
 }
 
 
@@ -726,7 +747,12 @@ void bounce(struct minfo *bminfo)
 void strmsgid(char *buf, struct minfo *msginfo) {
        int i;
 
-       sprintf(buf, "%ld@%s", msginfo->I, msginfo->N);
+       strcpy(buf, msginfo->I);
+       if (strchr(buf, '@') == NULL) {
+               strcat(buf, "@");
+               strcat(buf, msginfo->N);
+       }
+
        for (i=0; i<strlen(buf); ++i) {
                if (isspace(buf[i])) {
                        strcpy(&buf[i], &buf[i+1]);
@@ -749,7 +775,7 @@ int already_received(GDBM_FILE ut, struct minfo *msginfo) {
        int retval = 0;
 
        /* We can't check for dups on a zero msgid, so just pass them through */
-       if ((msginfo->I)==0L) {
+       if (strlen(msginfo->I)==0) {
                return 0;
        }
 
@@ -816,63 +842,6 @@ void purge_use_table(GDBM_FILE ut) {
 
 
 
-/*
- * Delete any messages on the zapped list
- */
-void process_zaplist(void) {
-       FILE *zaplist;
-       char curr_rm[ROOMNAMELEN];
-       char buf[256];
-       char room[256];
-       char id[256];
-       char node[256];
-
-       zaplist = fopen(ZAPLIST, "r");
-       if (zaplist == NULL) {
-               syslog(LOG_ERR, "cannot open %s: %s\n",
-                       ZAPLIST, strerror(errno));
-               return;
-       }
-
-       strcpy(curr_rm, "_nothing_");
-
-       while (fgets(buf, 256, zaplist) != NULL) {
-               buf[strlen(buf) - 1] = 0;
-
-               extract(room, buf, 0);
-               extract(id, buf, 1);
-               extract(node, buf, 2);
-
-               /* Change rooms if we have to */
-               if (strcasecmp(curr_rm, room)) {
-                       sprintf(buf, "GOTO %s", room);
-                       serv_puts(buf);
-                       serv_gets(buf);
-                       if (buf[0] == '2') {
-                               extract(curr_rm, &buf[4], 0);
-                       } else {
-                               syslog(LOG_ERR, "%s", buf);
-                       }
-               }
-
-               /* And only do the zap if we succeeded */
-               if (!strcasecmp(curr_rm, room)) {
-
-
-
-               /* FIX    not finished */
-
-
-               }
-
-       }
-
-       fclose(zaplist);
-
-}
-
-
-
 
 
 /*
@@ -880,9 +849,8 @@ void process_zaplist(void) {
  */
 void inprocess(void)
 {
-       FILE *fp, *message, *testfp, *ls, *duplist, *zaplist;
+       FILE *fp, *message, *testfp, *ls, *duplist;
        static struct minfo minfo;
-       struct recentmsg recentmsg;
        char tname[128], aaa[1024], iname[256], sfilename[256], pfilename[256];
        int a, b;
        int FieldID;
@@ -891,6 +859,7 @@ void inprocess(void)
        char buf[256];
        long msglen;
        int bloklen;
+       int valid_msg;
 
        /* temp file names */
        sprintf(tname, tmpnam(NULL));
@@ -904,9 +873,6 @@ void inprocess(void)
        /* temporary file to contain a log of rejected dups */
        duplist = tmpfile();
 
-       /* Open the zapped-list for appending */
-       zaplist = fopen(ZAPLIST, "a");
-
        /* Let the shell do the dirty work. Get all data from spoolin */
        do {
                sprintf(aaa, "cd %s/network/spoolin; ls", bbs_home_directory);
@@ -918,11 +884,11 @@ void inprocess(void)
                        do {
 SKIP:                          ptr = fgets(sfilename, sizeof sfilename, ls);
                                if (ptr != NULL) {
+                                       sfilename[strlen(sfilename) - 1] = 0;
 #ifdef DEBUG
                                        syslog(LOG_DEBUG,
-                                               "Trying %s", sfilename);
+                                               "Trying <%s>", sfilename);
 #endif
-                                       sfilename[strlen(sfilename) - 1] = 0;
                                        if (!strcmp(sfilename, ".")) goto SKIP;
                                        if (!strcmp(sfilename, "..")) goto SKIP;
                                        if (!strcmp(sfilename, "CVS")) goto SKIP;
@@ -948,6 +914,7 @@ NXMSG:      /* Seek to the beginning of the next message */
                                goto ENDSTR;
 
                        /* This crates the temporary file. */
+                       valid_msg = 1;
                        message = fopen(tname, "wb");
                        if (message == NULL) {
                                syslog(LOG_ERR, "error creating %s: %s",
@@ -960,23 +927,35 @@ NXMSG:    /* Seek to the beginning of the next message */
                        a = getc(fp);
                        putc(a, message);       /* mode */
                        do {
-                               FieldID = getc(fp);     /* Header field ID */
-                               putc(FieldID, message);
-                               do {
-                                       a = getc(fp);
-                                       putc(a, message);
-                               } while (a > 0);
+                               FieldID = getc(fp); /* Header field ID */
+                               if (isalpha(FieldID)) {
+                                       putc(FieldID, message);
+                                       do {
+                                               a = getc(fp);
+                                               if (a < 127) putc(a, message);
+                                       } while (a > 0);
+                                       if (a != 0) putc(0, message);
+                               }
+                               else {  /* Invalid field ID; flush it */
+                                       do {
+                                               a = getc(fp);
+                                       } while (a > 0);
+                                       valid_msg = 0;
+                               }
                        } while ((FieldID != 'M') && (a >= 0));
                        /* M is always last */
+                       if (FieldID != 'M') valid_msg = 0;
 
                        msglen = ftell(message);
                        fclose(message);
 
+                       if (!valid_msg) {
+                               unlink(tname);
+                               goto NXMSG;
+                       }
+
                        /* process the individual mesage */
                        msgfind(tname, &minfo);
-                       strncpy(recentmsg.RMnodename, minfo.N, 9);
-                       recentmsg.RMnodename[9] = 0;
-                       recentmsg.RMnum = minfo.I;
                        syslog(LOG_NOTICE, "#%ld fm <%s> in <%s> @ <%s>",
                               minfo.I, minfo.A, minfo.O, minfo.N);
                        if (strlen(minfo.R) > 0) {
@@ -1034,7 +1013,7 @@ NXMSG:    /* Seek to the beginning of the next message */
                        /* Check the use table; reject message if it's been here before */
                        if (already_received(use_table, &minfo)) {
                                syslog(LOG_NOTICE, "rejected duplicate message");
-                               fprintf(duplist, "#%ld fm <%s> in <%s> @ <%s>\n",
+                               fprintf(duplist, "#<%s> fm <%s> in <%s> @ <%s>\n",
                                        minfo.I, minfo.A, minfo.O, minfo.N);
                        }
 
@@ -1131,20 +1110,6 @@ NXMSG:   /* Seek to the beginning of the next message */
 
                                fclose(message);
                                
-                               /* If this message supersedes an existing one,
-                                * add it to the zap list
-                                */
-                               if (strlen(minfo.Z) > 0) {
-                                       if (strlen(minfo.C) > 0) {
-                                               fprintf(zaplist, "%s", minfo.C);
-                                       } else {
-                                               fprintf(zaplist, "%s", minfo.O);
-                                       }
-                                       extract_token(buf, minfo.Z, 0, '@');
-                                       fprintf(zaplist, "|%s", minfo.Z);
-                                       extract_token(buf, minfo.Z, 1, '@');
-                                       fprintf(zaplist, "|%s\n", minfo.Z);
-                               }
                        }
 
                        unlink(tname);
@@ -1181,12 +1146,6 @@ ENDSTR:                  fclose(fp);
 
        fclose(duplist);
 
-
-       /* Now delete any messages which were zapped (superseded) by
-        * other incoming messages.
-        */
-       fclose(zaplist);
-       process_zaplist();
 }
 
 
@@ -1241,6 +1200,65 @@ int ismsgok(FILE *mmfp, char *sysname)
 
 
 
+
+/*
+ * Add a message to the list of messages to be deleted off the local server
+ * at the end of this run.
+ */
+void delete_locally(long msgid, char *roomname) {
+       struct msglist *mptr;
+
+       mptr = (struct msglist *) malloc(sizeof(struct msglist));
+       mptr->next = purgelist;
+       mptr->m_num = msgid;
+       strcpy(mptr->m_rmname, roomname);
+       purgelist = mptr;
+}
+
+
+
+/*
+ * Delete all messages on the purge list from the local server.
+ */
+void process_purgelist(void) {
+       char curr_rm[ROOMNAMELEN];
+       char buf[256];
+       struct msglist *mptr;
+
+
+       strcpy(curr_rm, "__nothing__");
+       while (purgelist != NULL) {
+               if (strcasecmp(curr_rm, purgelist->m_rmname)) {
+                       sprintf(buf, "GOTO %s", purgelist->m_rmname);
+                       serv_puts(buf);
+                       serv_gets(buf);
+                       if (buf[0] == '2') {
+                               extract(curr_rm, &buf[4], 0);
+                       }
+                       else {
+                               syslog(LOG_ERR, "%s", buf);
+                       }
+               }
+               if (!strcasecmp(curr_rm, purgelist->m_rmname)) {
+                       syslog(LOG_NOTICE, "Purging <%ld> in <%s>",
+                               purgelist->m_num, purgelist->m_rmname);
+                       sprintf(buf, "DELE %ld", purgelist->m_num);
+                       serv_puts(buf);
+                       serv_gets(buf);
+                       if (buf[0] != '2') {
+                               syslog(LOG_ERR, "%s", buf);
+                       }
+
+               }
+               mptr = purgelist->next;
+               free(purgelist);
+               purgelist = mptr;
+       }
+}
+
+
+
+
 /* spool list of messages to a file */
 /* returns # of msgs spooled */
 int spool_out(struct msglist *cmlist, FILE * destfp, char *sysname)
@@ -1306,6 +1324,9 @@ int spool_out(struct msglist *cmlist, FILE * destfp, char *sysname)
                                        fprintf(destfp, "%s!", NODENAME);
                                if (a != 'C')
                                        fwrite(fbuf, strlen(fbuf) + 1, 1, destfp);
+                               if (a == 'S') if (!strcasecmp(fbuf, "CANCEL")) {
+                                       delete_locally(cmptr->m_num, cmptr->m_rmname);
+                               }
                        }
                        if (a == 'M') {
                                fprintf(destfp, "C%s%c",
@@ -1485,14 +1506,11 @@ void outprocess(char *sysname)
 void np_attach_to_server(void)
 {
        char buf[256];
-       char portname[8];
        char *args[] =
-       {"netproc", "localhost", NULL, NULL};
+       { "netproc", NULL };
 
        syslog(LOG_NOTICE, "Attaching to server...");
-       sprintf(portname, "%d", config.c_port_number);
-       args[2] = portname;
-       attach_to_server(3, args);
+       attach_to_server(1, args, NULL, NULL);
        serv_gets(buf);
        syslog(LOG_NOTICE, "%s", &buf[4]);
        sprintf(buf, "IPGM %d", config.c_ipgm_secret);
@@ -1582,7 +1600,8 @@ int main(int argc, char **argv)
                if (allfp != NULL) {
                        while (fgets(allst, 32, allfp) != NULL) {
                                allst[strlen(allst) - 1] = 0;
-                               outprocess(allst);
+                               if (strcmp(allst, "CVS"))
+                                       outprocess(allst);
                        }
                        pclose(allfp);
                }
@@ -1593,6 +1612,10 @@ int main(int argc, char **argv)
        /* Update mail.sysinfo with new information we learned */
        rewrite_syslist();
 
+       /* Delete any messages which need to be purged locally */
+       syslog(LOG_NOTICE, "calling process_purgelist()");
+       process_purgelist();
+
        /* Close the use table */
        purge_use_table(use_table);
        gdbm_close(use_table);