+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
*
*/
+#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];
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 {
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);