/*
* Session layer proxy for Citadel
* (c) 1998 by Art Cancro, All Rights Reserved, released under GNU GPL v2
+ * $Id$
*/
/*
*
*/
+/* 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>
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);
}
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);
}
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)");