]> code.citadel.org Git - citadel.git/blobdiff - citadel/netproc.c
fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / netproc.c
index e5a94fbfb3461967c92271a2f404eff9e5d9aedd..7645f4f8f41fa1fa299d526abec9bfd4b59ea334 100644 (file)
 #include <fcntl.h>
 #include <stdio.h>
 #include <ctype.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <signal.h>
 #include <errno.h>
 #include <syslog.h>
@@ -408,7 +419,7 @@ void load_filterlist(void)
        fp = fopen("./network/filterlist", "r");
        if (fp == NULL)
                return;
-       while (fgets(sbuf, 256, fp) != NULL) {
+       while (fgets(sbuf, sizeof sbuf, fp) != NULL) {
                if (sbuf[0] != '#') {
                        sbuf[strlen(sbuf) - 1] = 0;
                        fbuf = (struct filterlist *)
@@ -871,8 +882,8 @@ void inprocess(void)
        int valid_msg;
 
        /* temp file names */
-       strcpy(tname, tmpnam(NULL));
-       strcpy(iname, tmpnam(NULL));
+       sprintf(tname, "%s.netproc.%d", tmpnam(NULL), __LINE__);
+       sprintf(iname, "%s.netproc.%d", tmpnam(NULL), __LINE__);
 
        load_filterlist();
 
@@ -1274,7 +1285,7 @@ int spool_out(struct msglist *cmlist, FILE * destfp, char *sysname)
 {
        struct msglist *cmptr;
        FILE *mmfp;
-       char fbuf[128];
+       char fbuf[1024];
        int a;
        int msgs_spooled = 0;
        long msg_len;
@@ -1302,6 +1313,10 @@ int spool_out(struct msglist *cmlist, FILE * destfp, char *sysname)
                }
                /* download the message from the server... */
                mmfp = tmpfile();
+               if (mmfp == NULL) {
+                       syslog(LOG_NOTICE, "tmpfile() failed: %s\n",
+                               strerror(errno) );
+               }
                sprintf(buf, "MSG3 %ld", cmptr->m_num);
                serv_puts(buf);
                serv_gets(buf);
@@ -1373,14 +1388,15 @@ void outprocess(char *sysname)
        char tempflnm[64];
        char buf[256];
        struct msglist *cmlist = NULL;
+       struct msglist *cmlast = NULL;
        struct rmlist *crmlist = NULL;
        struct rmlist *rmptr, *rmptr2;
-       struct msglist *cmptr, *cmptr2;
+       struct msglist *cmptr;
        FILE *sysflfp, *tempflfp;
-       int outgoing_msgs;
+       int outgoing_msgs = 0;
        long thismsg;
 
-       strcpy(tempflnm, tmpnam(NULL));
+       sprintf(tempflnm, "%s.netproc.%d", tmpnam(NULL), __LINE__);
        tempflfp = fopen(tempflnm, "w");
        if (tempflfp == NULL)
                return;
@@ -1446,14 +1462,14 @@ void outprocess(char *sysname)
                                                cmptr->m_num = thismsg;
                                                strcpy(cmptr->m_rmname, rmptr->rm_name);
 
-                                               if (cmlist == NULL)
+                                               if (cmlist == NULL) {
                                                        cmlist = cmptr;
+                                               }
                                                else {
-                                                       cmptr2 = cmlist;
-                                                       while (cmptr2->next != NULL)
-                                                               cmptr2 = cmptr2->next;
-                                                       cmptr2->next = cmptr;
+                                                       cmlast->next = cmptr;
                                                }
+                                               cmlast = cmptr;
+                                               ++outgoing_msgs;
                                        }
                        } else {        /* print error from "msgs all" */
                                syslog(LOG_ERR, "%s", buf);
@@ -1461,22 +1477,17 @@ void outprocess(char *sysname)
                }
        }
 
-       outgoing_msgs = 0;
-       cmptr2 = cmlist;        /* this loop counts the messages */
-       while (cmptr2 != NULL) {
-               ++outgoing_msgs;
-               cmptr2 = cmptr2->next;
-       }
        syslog(LOG_NOTICE, "%d messages to be spooled to %s",
               outgoing_msgs, sysname);
 
 /*
  * Spool out the messages, but only if there are any.
  */
-       if (outgoing_msgs != 0)
+       if (outgoing_msgs != 0) {
                outgoing_msgs = spool_out(cmlist, tempflfp, sysname);
-       syslog(LOG_NOTICE, "%d messages actually spooled",
-              outgoing_msgs);
+       }
+
+       syslog(LOG_NOTICE, "%d messages actually spooled", outgoing_msgs);
 
 /*
  * Deallocate list of spooled messages.