]> code.citadel.org Git - citadel.git/blobdiff - citadel/citserver.c
* Added the EUID command to search for a message by EUID
[citadel.git] / citadel / citserver.c
index b076e274b19918089430a8ff2e0e7b158f838c7e..4e8e90143f3a456498832df8ea8710cddfb7935b 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include <dirent.h>
 #include <errno.h>
 #include <limits.h>
 /* #include <dlfcn.h> */
@@ -57,6 +58,7 @@
 #include "policy.h"
 #include "control.h"
 #include "tools.h"
+#include "euidindex.h"
 
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
@@ -112,6 +114,27 @@ void master_startup(void) {
                 lputroom(&qrbuf);
         }
 
+       /*
+        * Create a room in which we can deposit "deleted" messages for
+        * deferred deletion.  This will silently fail if the room already
+        * exists, and that's perfectly ok, because we want it to exist.
+        */
+       create_room(DELETED_MSGS_ROOM, 3, "", 0, 1, 0, VIEW_MAILBOX);
+
+       /*
+        * Make sure it's set to be a "system room" so it doesn't show up
+        * in the <K>nown rooms list for Aides.  Also set the message expire
+        * policy to "by count, 1 message" so everything gets deleted all
+        * the time (we can't set it to 0 because that's invalid, so we keep
+        * a single message around).
+        */
+       if (lgetroom(&qrbuf, DELETED_MSGS_ROOM) == 0) {
+               qrbuf.QRflags2 |= QR2_SYSTEM;
+               qrbuf.QRep.expire_mode = EXPIRE_NUMMSGS;
+               qrbuf.QRep.expire_value = 1;
+               lputroom(&qrbuf);
+       }
+
        lprintf(CTDL_INFO, "Seeding the pseudo-random number generator...\n");
        urandom = fopen("/dev/urandom", "r");
        if (urandom != NULL) {
@@ -288,7 +311,11 @@ int is_public_client(void)
        static time_t pc_timestamp = 0;
        static char public_clients[SIZ];
 
+#ifndef HAVE_ETC
 #define PUBLIC_CLIENTS "./public_clients"
+#else
+#define PUBLIC_CLIENTS ETC_DIR"/public_clients"
+#endif
 
        /*
         * Check the time stamp on the public_clients file.  If it's been
@@ -312,7 +339,13 @@ int is_public_client(void)
                        strcat(public_clients, addrbuf);
                }
 
-               fp = fopen("public_clients", "r");
+               fp = fopen(
+#ifndef HAVE_ETC
+                                  "."
+#else
+                                  ETC_DIR
+#endif
+                                  "/public_clients", "r");
                if (fp != NULL) while (fgets(buf, sizeof buf, fp)!=NULL) {
                        for (i=0; i<strlen(buf); ++i) {
                                if (buf[i] == '#') buf[i] = 0;
@@ -421,20 +454,56 @@ void cmd_mesg(char *mname)
        char buf[256];
        char buf2[256];
        char *dirs[2];
+       DIR *dp;
+       struct dirent *d;
 
        extract_token(buf, mname, 0, '|', sizeof buf);
 
+#ifdef HAVE_DATA_DIR
+       dirs[0] = strdup(DATA_DIR "/messages");
+#else
        dirs[0] = strdup("messages");
+#endif
+
+#ifdef HAVE_DATA_DIR
+       dirs[1] = strdup(DATA_DIR "/help");
+#else
        dirs[1] = strdup("help");
-       snprintf(buf2, sizeof buf2, "%s.%d.%d", buf, CC->cs_clientdev, CC->cs_clienttyp);
-       mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
-       if (strlen(targ) == 0) {
-               snprintf(buf2, sizeof buf2, "%s.%d", buf, CC->cs_clientdev);
+#endif
+
+       snprintf(buf2, sizeof buf2, "%s.%d.%d",
+               buf, CC->cs_clientdev, CC->cs_clienttyp);
+
+       /* If the client requested "?" then produce a listing */
+       if (!strcmp(buf, "?")) {
+               cprintf("%d %s\n",LISTING_FOLLOWS,buf);
+               dp = opendir(dirs[1]);
+               if (dp != NULL) {
+                       while (d = readdir(dp), d != NULL) {
+                               if (d->d_name[0] != '.') {
+                                       cprintf(" %s\n", d->d_name);
+                               }
+                       }
+                       closedir(dp);
+               }
+               cprintf("000\n");
+       }
+
+       /* Otherwise, look for the requested file by name. */
+       else {
                mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
                if (strlen(targ) == 0) {
-                       mesg_locate(targ, sizeof targ, buf, 2, (const char **)dirs);
-               }       
+                       snprintf(buf2, sizeof buf2, "%s.%d",
+                                                       buf, CC->cs_clientdev);
+                       mesg_locate(targ, sizeof targ, buf2, 2,
+                                                       (const char **)dirs);
+                       if (strlen(targ) == 0) {
+                               mesg_locate(targ, sizeof targ, buf, 2,
+                                                       (const char **)dirs);
+                       }       
+               }
        }
+
        free(dirs[0]);
        free(dirs[1]);
 
@@ -482,14 +551,30 @@ void cmd_emsg(char *mname)
                if (buf[a] == '/') buf[a] = '.';
        }
 
+#ifdef HAVE_DATA_DIR
+       dirs[0] = strdup(DATA_DIR "/messages");
+#else
        dirs[0] = strdup("messages");
+#endif
+
+#ifdef HAVE_DATA_DIR
+       dirs[1] = strdup(DATA_DIR "/help");
+#else
        dirs[1] = strdup("help");
+#endif
+
        mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
        free(dirs[0]);
        free(dirs[1]);
 
        if (strlen(targ)==0) {
-               snprintf(targ, sizeof targ, "./help/%s", buf);
+               snprintf(targ, sizeof targ, 
+#ifndef HAVE_DATA_DIR
+                        "."
+#else
+                        DATA_DIR
+#endif
+                                "/help/%s", buf);
        }
 
        mfp = fopen(targ,"w");
@@ -823,7 +908,7 @@ void citproto_begin_session() {
  * This loop recognizes all server commands.
  */
 void do_command_loop(void) {
-       char cmdbuf[1024];
+       char cmdbuf[SIZ];
 
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
@@ -954,6 +1039,10 @@ void do_command_loop(void) {
                cmd_rdir();
        }
 
+       else if (!strncasecmp(cmdbuf,"EUID",4)) {
+               cmd_euid(&cmdbuf[5]);
+       }
+
        else if (!strncasecmp(cmdbuf,"MSG0",4)) {
                cmd_msg0(&cmdbuf[5]);
        }
@@ -1206,6 +1295,22 @@ void do_command_loop(void) {
                cmd_isme(&cmdbuf[5]);
        }
 
+       else if (!strncasecmp(cmdbuf, "FUCK", 4)) {
+               cprintf("100\n");
+
+               struct CtdlMessage *msg;
+               msg = CtdlFetchMessage(3115, 1);
+               cprintf("\nCtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);\n--\n");
+               CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);
+               cprintf("--\nCtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_NONE, 0, 1);\n--\n");
+               CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_NONE, 0, 1);
+               cprintf("--\nCtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1);\n--\n");
+               CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1);
+               cprintf("--\n");
+               cprintf("000\n");
+               CtdlFreeMessage(msg);
+       }
+
        else if (!DLoader_Exec_Cmd(cmdbuf)) {
                cprintf("%d Unrecognized or unsupported command.\n",
                        ERROR + CMD_NOT_SUPPORTED);