]> code.citadel.org Git - citadel.git/blobdiff - citadel/proxy.c
* added RCS Id keyword strings to sources
[citadel.git] / citadel / proxy.c
index e7853ccdba29a35f7d9f7fea8b2e46ea6bd1e73f..13c20d2abf6ab75b56298f43c46ab0331f011755 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Session layer proxy for Citadel
  * (c) 1998 by Art Cancro, All Rights Reserved, released under GNU GPL v2
+ * $Id$
  */
 
 /*
@@ -8,8 +9,20 @@
  *
  */
 
+/* Directory to put the message cache in */
 #define CACHE_DIR      "/var/citadelproxy"
 
+/* Number of days to keep messages in the cache */
+#define CACHE_EXPIRE   60
+
+/* Uncomment to enable prefetch */
+/* #define ENABLE_PREFETCH */
+
+/* Name and password to use for caching */
+#define PREFETCH_USER_NAME     "cypherpunks"
+#define PREFETCH_USER_PASSWORD "cypherpunks"
+
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -135,26 +148,28 @@ void do_prefetch() {
        close(1);
        close(2);
 
-
        serv_gets(buf);
        if (buf[0] != '2') {
                exit(0);
                }
 
-
        /* Log in (this is kind of arbitrary) */
-       serv_puts("USER cypherpunks");
+       sprintf(buf, "USER %s", PREFETCH_USER_NAME);
+       serv_puts(buf);
        serv_gets(buf);
        if (buf[0]=='3') {
-               serv_puts("PASS cypherpunks");
+               sprintf(buf, "PASS %s", PREFETCH_USER_PASSWORD);
+               serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') exit(1);
                }
        else {
-               serv_puts("NEWU cypherpunks");
+               sprintf(buf, "NEWU %s", PREFETCH_USER_NAME);
+               serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') exit(1);
-               serv_puts("SETP cypherpunks");
+               sprintf(buf, "SETP %s", PREFETCH_USER_PASSWORD);
+               serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') exit(1);
                }
@@ -286,6 +301,10 @@ void do_mainloop() {
                        serv_puts("QUIT");
                        printf("%d Proxy says: Bye!\n", OK);
                        fflush(stdout);
+                       sprintf(buf,
+                         "/usr/bin/find %s -mtime +%d -exec rm -f {} \\; &",
+                         CACHE_DIR, CACHE_EXPIRE);
+                       system(buf);
                        exit(0);
                        }
 
@@ -366,18 +385,28 @@ void main(int argc, char *argv[]) {
        char buf[256];
        int pid;
 
-       /* Create the cache directory.  Ignore any error return, 'cuz that
-        * just means it's already there.  FIX... this really should check
-        * for that particular error.
+       /* Create the cache directory.  Die on any error *except* EEXIST
+        * because it's perfectly ok if the cache already exists.
         */
-       mkdir(CACHE_DIR, 0700);
+       if (mkdir(CACHE_DIR, 0700)!=0) {
+               if (errno != EEXIST) {
+                       printf("%d Error creating cache directory: %s\n",
+                               ERROR+INTERNAL_ERROR,
+                               strerror(errno));
+                       exit(errno);
+                       }
+               }
 
        /* Now go there */
        if (chdir(CACHE_DIR) != 0) exit(errno);
 
+#ifdef ENABLE_PREFETCH
        pid = fork();
+#endif
        attach_to_server(argc, argv);
+#ifdef ENABLE_PREFETCH
        if (pid == 0) do_prefetch();
+#endif
 
        serv_gets(buf);
        strcat(buf, " (VIA PROXY)");