]> code.citadel.org Git - citadel.git/commitdiff
*** empty log message ***
authorArt Cancro <ajc@citadel.org>
Wed, 16 Sep 1998 16:16:36 +0000 (16:16 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 16 Sep 1998 16:16:36 +0000 (16:16 +0000)
citadel/ChangeLog
citadel/proxy.c

index ec45b69a9bddb024a2d8983fa269c390e46d4383..f3f20891b3702a6c557c24b23d0abf411c2715bb 100644 (file)
@@ -1,3 +1,9 @@
+Wed Sep 16 11:42:42 EDT 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * ipc_c_tcp.c: Reversed any changes that have been made to this file,
+         because something was causing abominally slow response time.
+       * proxy.c: added.  This will eventually become a caching, pre-fetching
+         multiuser proxy server for the Citadel protocol.
+
 1998-09-15 Nathan Bryant <bryant@cs.usm.maine.edu>
        * Makefile.in: remove support.o from serv_chat.so, add -fPIC to compile
          flags for serv_chat.o
index d98aed99485b23c02ad21c11282a8f9c0d1ceca0..c2390a8c407375a0e61f30feed622b83910c2298 100644 (file)
@@ -8,20 +8,79 @@
  *
  */
 
+#define CACHE_DIR      "/var/citadelproxy"
+
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <errno.h>
 #include "citadel.h"
 
-
-extern int serv_sock;
-
 void logoff(int code) {
        exit(code);
        }
 
 
+void do_msg0(char cmd[]) {
+       long msgid;
+       char filename[32];
+       char temp[32];
+       char buf[256];
+       FILE *fp;
+
+       msgid = atol(&cmd[5]);
+       sprintf(filename, "%ld", msgid);
+
+       /* If the message is cached, use the copy on disk */
+       fp = fopen(filename, "r");
+       if (fp != NULL) {
+               printf("%d Cached message %ld:\n", LISTING_FOLLOWS, msgid);
+               while (fgets(buf, 256, fp) != NULL) {
+                       buf[strlen(buf)-1]=0;
+                       printf("%s\n", buf);
+                       }
+               fclose(fp);
+               printf("000\n");
+               fflush(stdout);
+               }
+
+       /* Otherwise, fetch the message from the server and cache it */
+       else {
+               sprintf(buf, "MSG0 %ld", msgid);
+               serv_puts(buf); 
+               serv_gets(buf);
+               printf("%s\n", buf);
+               fflush(stdout);
+               if (buf[0] != '1') {
+                       return;
+                       }
+
+               /* The message is written to a file with a temporary name, in
+                * order to avoid another user accidentally fetching a
+                * partially written message from the cache.
+                */
+               sprintf(temp, "%ld.%d", msgid, getpid());
+               fp = fopen(temp, "w");
+               while (serv_gets(buf), strcmp(buf, "000")) {
+                       printf("%s\n", buf);
+                       fprintf(fp, "%s\n", buf);
+                       }
+               printf("%s\n", buf);
+               fflush(stdout);
+               fclose(fp);
+
+               /* Now that the message is complete, it can be renamed to the
+                * filename that the cache manager will recognize it with.
+                */
+               link(temp, filename);
+               unlink(temp);
+               }
+
+       }
+
+
 void do_mainloop() {
        char cmd[256];
        char resp[256];
@@ -44,6 +103,15 @@ void do_mainloop() {
                        exit(0);
                        }
 
+               else if (!strncasecmp(cmd, "CHAT", 4)) {
+                       printf("%d Can't chat through the proxy ... yet.\n",
+                               ERROR);
+                       }
+
+               else if (!strncasecmp(cmd, "MSG0", 4)) {
+                       do_msg0(cmd);
+                       }
+
                /* Other commands, just pass through. */
                else {
                        
@@ -111,7 +179,15 @@ void do_mainloop() {
 void main(int argc, char *argv[]) {
        char buf[256];
 
-       
+       /* 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.
+        */
+       mkdir(CACHE_DIR, 0700);
+
+       /* Now go there */
+       if (chdir(CACHE_DIR) != 0) exit(errno);
+
        attach_to_server(argc, argv);
 
        serv_gets(buf);