]> code.citadel.org Git - citadel.git/blobdiff - citadel/citserver.c
* MSG4 (and CtdlOutputMsg() as well) now accepts an optional MIME part
[citadel.git] / citadel / citserver.c
index 868f2daab498b6d80e50f4e13317a9bdbeae3cfd..aa366e25f7571faf44f4e38d744ec7e7f8178597 100644 (file)
@@ -5,10 +5,6 @@
  *
  */
 
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -32,6 +28,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include <dirent.h>
 #include <errno.h>
 #include <limits.h>
 /* #include <dlfcn.h> */
@@ -57,6 +54,7 @@
 #include "policy.h"
 #include "control.h"
 #include "tools.h"
+#include "euidindex.h"
 
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
@@ -452,28 +450,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);
 
-       dirs[0] = strdup(
 #ifdef HAVE_DATA_DIR
-                                        DATA_DIR"/"
+       dirs[0] = strdup(DATA_DIR "/messages");
+#else
+       dirs[0] = strdup("messages");
 #endif
-                                        "messages");
-       dirs[1] = strdup(
+
 #ifdef HAVE_DATA_DIR
-                                        DATA_DIR"/"
+       dirs[1] = strdup(DATA_DIR "/help");
+#else
+       dirs[1] = strdup("help");
 #endif
-                                        "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);
+
+       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]);
 
@@ -521,16 +547,18 @@ void cmd_emsg(char *mname)
                if (buf[a] == '/') buf[a] = '.';
        }
 
-       dirs[0] = strdup(
 #ifdef HAVE_DATA_DIR
-                                        DATA_DIR"/"
+       dirs[0] = strdup(DATA_DIR "/messages");
+#else
+       dirs[0] = strdup("messages");
 #endif
-                                        "messages");
-       dirs[1] = strdup(
+
 #ifdef HAVE_DATA_DIR
-                                        DATA_DIR"/"
+       dirs[1] = strdup(DATA_DIR "/help");
+#else
+       dirs[1] = strdup("help");
 #endif
-                                        "help");
+
        mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
        free(dirs[0]);
        free(dirs[1]);
@@ -876,12 +904,12 @@ 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 */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
-               lprintf(CTDL_ERR, "Client socket is broken; ending session\n");
+               lprintf(CTDL_ERR, "Client disconnected: ending session.\n");
                CC->kill_me = 1;
                return;
        }
@@ -1007,6 +1035,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]);
        }