]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_network.c
fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / serv_network.c
index ae8e6410dd20653b48f6a128e7ab9c4cb17627b3..980160f32bdae55f623c8c61ad02dde3bb194d61 100644 (file)
@@ -7,14 +7,6 @@
  *
  */
 
-
-/* FIXME
-
-there's stuff in here that makes the assumption that /tmp is on the same
-filesystem as Citadel, and makes calls to link() on that basis.  fix this.
-
-*/
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -24,13 +16,23 @@ filesystem as Citadel, and makes calls to link() on that basis.  fix this.
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/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 <sys/wait.h>
 #include <string.h>
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
@@ -47,8 +49,8 @@ filesystem as Citadel, and makes calls to link() on that basis.  fix this.
 
 
 void cmd_gnet(char *argbuf) {
-       char filename[256];
-       char buf[256];
+       char filename[SIZ];
+       char buf[SIZ];
        FILE *fp;
 
        if (CtdlAccessCheck(ac_room_aide)) return;
@@ -71,9 +73,9 @@ void cmd_gnet(char *argbuf) {
 
 
 void cmd_snet(char *argbuf) {
-       char tempfilename[256];
-       char filename[256];
-       char buf[256];
+       char tempfilename[SIZ];
+       char filename[SIZ];
+       char buf[SIZ];
        FILE *fp;
 
        if (CtdlAccessCheck(ac_room_aide)) return;
@@ -94,10 +96,13 @@ void cmd_snet(char *argbuf) {
        }
        fclose(fp);
 
-       /* Now that we've got the whole file, put it in place */
+       /* Now copy the temp file to its permanent location
+        * (We use /bin/mv instead of link() because they may be on
+        * different filesystems)
+        */
        unlink(filename);
-       link(tempfilename, filename);
-       unlink(tempfilename);
+       snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename);
+       system(buf);
 }
 
 
@@ -110,6 +115,7 @@ void network_spool_msg(long msgnum, void *userdata) {
        struct namelist *nptr;
        int err;
        char *instr = NULL;
+       int instr_len = 0;
        struct CtdlMessage *imsg;
 
        sc = (struct SpoolControl *)userdata;
@@ -124,7 +130,8 @@ void network_spool_msg(long msgnum, void *userdata) {
        if (err != 0) return;
 
        lprintf(9, "Generating delivery instructions\n");
-       instr = mallok(2048);   /* FIXME this won't be enough */
+       instr_len = 4096;
+       instr = mallok(instr_len);
        sprintf(instr,
                "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
                "bounceto|postmaster@%s\n" ,
@@ -138,19 +145,22 @@ void network_spool_msg(long msgnum, void *userdata) {
        imsg->cm_fields['A'] = strdoop("Citadel");
        imsg->cm_fields['M'] = instr;
 
-
-       /* FIXME generate delivery instructions for each recipient */
+       /* Generate delivery instructions for each recipient */
        for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
+               if (instr_len - strlen(instr) < SIZ) {
+                       instr_len = instr_len * 2;
+                       instr = reallok(instr, instr_len);
+               }
                sprintf(&instr[strlen(instr)], "remote|%s|0||\n",
                        nptr->name);
        }
 
-       /* FIXME save delivery instructions in spoolout room */
+       /* Save delivery instructions in spoolout room */
        CtdlSaveMsg(imsg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL);
        CtdlFreeMessage(imsg);
 
-       /* FIXME update lastseen */
-
+       /* update lastsent */
+       sc->lastsent = msgnum;
 }
 
 
@@ -160,9 +170,9 @@ void network_spool_msg(long msgnum, void *userdata) {
  * Batch up and send all outbound traffic from the current room
  */
 void network_spoolout_current_room(void) {
-       char filename[256];
-       char buf[256];
-       char instr[256];
+       char filename[SIZ];
+       char buf[SIZ];
+       char instr[SIZ];
        FILE *fp;
        struct SpoolControl sc;
        /* struct namelist *digestrecps = NULL; */
@@ -201,16 +211,16 @@ void network_spoolout_current_room(void) {
        fclose(fp);
 
 
-
        /* Do something useful */
-       CtdlForEachMessage(MSGS_ALL, 0L, (-63), NULL, NULL, network_spool_msg, &sc);
-
+       CtdlForEachMessage(MSGS_GT, sc.lastsent, (-63), NULL, NULL,
+               network_spool_msg, &sc);
 
 
        /* Now rewrite the config file */
        fp = fopen(filename, "w");
        if (fp == NULL) {
-               lprintf(1, "ERROR: cannot open %s: %s\n", filename, strerror(errno));
+               lprintf(1, "ERROR: cannot open %s: %s\n",
+                       filename, strerror(errno));
        }
        else {
                fprintf(fp, "lastsent|%ld\n", sc.lastsent);