]> code.citadel.org Git - citadel.git/blobdiff - citadel/aidepost.c
* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / aidepost.c
index cd5599a715ed1373306edf347c66af44f30727dc..935df22b7af9491ddfecb18c3837aed1149cfa9e 100644 (file)
@@ -1,7 +1,7 @@
-/* aidepost.c
- * This is just a little hack to copy standard input to a message in Aide>
- * v2.0
+/*
  * $Id$
+ *
+ * This is just a little hack to copy standard input to a message in Aide>
  */
 
 #include <stdlib.h>
 #include <time.h>
 #include <limits.h>
 #include <errno.h>
+#include <string.h>
 #include "citadel.h"
 #include "config.h"
 
-void make_message(FILE *fp)
+void make_message(FILE *fp, char *target_room)
 {
        int a;
        long bb, cc;
@@ -28,7 +29,7 @@ void make_message(FILE *fp)
        putc(0, fp);
        fprintf(fp, "ACitadel");
        putc(0, fp);
-       fprintf(fp, "OAide");
+       fprintf(fp, "O%s", target_room);
        putc(0, fp);
        fprintf(fp, "N%s", NODENAME);
        putc(0, fp);
@@ -50,28 +51,38 @@ void make_message(FILE *fp)
 
 int main(int argc, char **argv)
 {
-       char tempbase[32];
-       char temptmp[64];
        char tempspool[64];
+       char target_room[ROOMNAMELEN];
        FILE *tempfp, *spoolfp;
        int ch;
+       int i;
 
        get_config();
-       snprintf(tempbase, sizeof tempbase, "ap.%d", getpid());
-       snprintf(temptmp, sizeof temptmp, "/tmp/%s", tempbase);
-       snprintf(tempspool, sizeof tempspool, "./network/spoolin/%s", tempbase);
 
-       tempfp = fopen(temptmp, "wb+");
+       strcpy(target_room, "Aide");
+       for (i=1; i<argc; ++i) {
+               if (!strncasecmp(argv[i], "-r", 2)) {
+                       strncpy(target_room, &argv[i][2], sizeof(target_room));
+                       target_room[sizeof(target_room)-1] = 0;
+               } else {
+                       fprintf(stderr, "%s: usage: %s [-rTargetRoom]\n",
+                               argv[0], argv[0]);
+                       exit(1);
+               }
+       }
+
+
+       snprintf(tempspool, sizeof tempspool, "./network/spoolin/ap.%d",
+               getpid());
+
+       tempfp = tmpfile();
        if (tempfp == NULL) {
                perror("cannot open temp file");
                exit(errno);
        }
-       /* Unlink the temp file, so it automatically gets deleted by the OS if
-        * this program is interrupted or crashes.
-        */ unlink(temptmp);
 
        /* Generate a message from stdin */
-       make_message(tempfp);
+       make_message(tempfp, target_room);
 
        /* Copy it to a new temp file in the spool directory */
        rewind(tempfp);