]> code.citadel.org Git - citadel.git/blobdiff - citadel/aidepost.c
centralized filename calculation
[citadel.git] / citadel / aidepost.c
index 1d38d92ef712dc58cc56459d219c77652a33e39f..3e60dc97664b97b49aba54b47c66574674534300 100644 (file)
 #include <errno.h>
 #include <string.h>
 #include "citadel.h"
+#include "citadel_dirs.h"
 #include "config.h"
 
-static void make_message(FILE *fp, char *target_room, char *author)
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
+
+
+/*
+ * Simplified function to generate a message in our format
+ */
+static void ap_make_message(FILE *fp, char *target_room, char *author)
 {
        int a;
        long bb, cc;
@@ -69,6 +78,15 @@ int main(int argc, char **argv)
        int ch;
        int i;
 
+       int relh=0;
+       int home=0;
+       char relhome[PATH_MAX]="";
+       char ctdldir[PATH_MAX]=CTDLDIR;
+
+       /* TODO: should we be able to calculate relative dirs? */
+       calc_dirs_n_files(relh, home, relhome, ctdldir);
+
+
        get_config();
 
        strcpy(target_room, "Aide");
@@ -89,19 +107,22 @@ int main(int argc, char **argv)
                }
        }
 
-
        snprintf(tempspool, sizeof tempspool,
-               "./network/spoolin/ap.%04x",
-               getpid());
+                        "%s/ap.%04lx",
+                        ctdl_netin_dir,
+               (long)getpid());
 
-       tempfp = tmpfile();
+       unlink(tempspool);
+
+       tempfp = fopen(tempspool, "w+b");
+       unlink(tempspool);
        if (tempfp == NULL) {
                perror("cannot open temp file");
                exit(errno);
        }
 
        /* Generate a message from stdin */
-       make_message(tempfp, target_room, author);
+       ap_make_message(tempfp, target_room, author);
 
        /* Copy it to a new temp file in the spool directory */
        rewind(tempfp);
@@ -111,8 +132,9 @@ int main(int argc, char **argv)
                perror("cannot open spool file");
                exit(errno);
        }
-       while (ch = getc(tempfp), (ch >= 0))
+       while (ch = getc(tempfp), (ch >= 0)) {
                putc(ch, spoolfp);
+       }
 
        fclose(tempfp);
        fclose(spoolfp);