* added message subject to all those tiny messages
[citadel.git] / citadel / room_ops.c
index 1b00fe4859352340cf4c9125b93efe8f98e3e353..d6ec55e4a43e64757a1b2ebe76bf51f0b904c708 100644 (file)
@@ -5,10 +5,6 @@
  *
  */
 
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -43,6 +39,7 @@
 #include "citserver.h"
 #include "control.h"
 #include "tools.h"
+#include "citadel_dirs.h"
 
 struct floor *floorcache[MAXFLOORS];
 
@@ -152,7 +149,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
        }
 
 NEWMSG:        /* By the way, we also check for the presence of new messages */
-       if (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
+       if (is_msg_in_sequence_set(vbuf.v_seen, roombuf->QRhighest) == 0) {
                retval = retval | UA_HASNEWMSGS;
        }
 
@@ -357,7 +354,6 @@ struct floor *cgetfloor(int floor_num) {
        end_critical_section(S_FLOORCACHE);
 
        if (fetch_new) {
-               lprintf(CTDL_DEBUG, "fetch_new is active ... going to disk\n");
                fl = malloc(sizeof(struct floor));
                getfloor(fl, floor_num);
                begin_critical_section(S_FLOORCACHE);
@@ -507,15 +503,15 @@ int is_noneditable(struct ctdlroom *qrbuf)
 /*
  * Back-back-end for all room listing commands
  */
-void list_roomname(struct ctdlroom *qrbuf, int ra, int view)
+void list_roomname(struct ctdlroom *qrbuf, int ra, int current_view, int default_view)
 {
        char truncated_roomname[ROOMNAMELEN];
 
        /* For my own mailbox rooms, chop off the owner prefix */
        if ( (qrbuf->QRflags & QR_MAILBOX)
             && (atol(qrbuf->QRname) == CC->user.usernum) ) {
-               strcpy(truncated_roomname, qrbuf->QRname);
-               strcpy(truncated_roomname, &truncated_roomname[11]);
+               safestrncpy(truncated_roomname, qrbuf->QRname, sizeof truncated_roomname);
+               safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
                cprintf("%s", truncated_roomname);
        }
        /* For all other rooms, just display the name in its entirety */
@@ -524,13 +520,15 @@ void list_roomname(struct ctdlroom *qrbuf, int ra, int view)
        }
 
        /* ...and now the other parameters */
-       cprintf("|%u|%d|%d|%d|%d|%d|\n",
+       cprintf("|%u|%d|%d|%d|%d|%d|%d|%ld|\n",
                qrbuf->QRflags,
                (int) qrbuf->QRfloor,
                (int) qrbuf->QRorder,
                (int) qrbuf->QRflags2,
                ra,
-               view
+               current_view,
+               default_view,
+               qrbuf->QRmtime
        );
 }
 
@@ -550,7 +548,7 @@ void cmd_lrms_backend(struct ctdlroom *qrbuf, void *data)
        if ((( ra & (UA_KNOWN | UA_ZAPPED)))
            && ((qrbuf->QRfloor == (FloorBeingSearched))
                || ((FloorBeingSearched) < 0)))
-               list_roomname(qrbuf, ra, view);
+               list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
 }
 
 void cmd_lrms(char *argbuf)
@@ -588,7 +586,7 @@ void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data)
        if ((( ra & (UA_KNOWN)))
            && ((qrbuf->QRfloor == (FloorBeingSearched))
                || ((FloorBeingSearched) < 0)))
-               list_roomname(qrbuf, ra, view);
+               list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
 }
 
 void cmd_lkra(char *argbuf)
@@ -624,7 +622,7 @@ void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data)
                && ((qrbuf->QRflags & QR_MAILBOX) == 0)
            && ((qrbuf->QRfloor == (FloorBeingSearched))
                || ((FloorBeingSearched) < 0)))
-               list_roomname(qrbuf, ra, view);
+               list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
 }
 
 void cmd_lprm(char *argbuf)
@@ -657,7 +655,7 @@ void cmd_lkrn_backend(struct ctdlroom *qrbuf, void *data)
            && (ra & UA_HASNEWMSGS)
            && ((qrbuf->QRfloor == (FloorBeingSearched))
                || ((FloorBeingSearched) < 0)))
-               list_roomname(qrbuf, ra, view);
+               list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
 }
 
 void cmd_lkrn(char *argbuf)
@@ -696,7 +694,7 @@ void cmd_lkro_backend(struct ctdlroom *qrbuf, void *data)
            && ((ra & UA_HASNEWMSGS) == 0)
            && ((qrbuf->QRfloor == (FloorBeingSearched))
                || ((FloorBeingSearched) < 0)))
-               list_roomname(qrbuf, ra, view);
+               list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
 }
 
 void cmd_lkro(char *argbuf)
@@ -735,7 +733,7 @@ void cmd_lzrm_backend(struct ctdlroom *qrbuf, void *data)
            && (ra & UA_ZAPPED)
            && ((qrbuf->QRfloor == (FloorBeingSearched))
                || ((FloorBeingSearched) < 0)))
-               list_roomname(qrbuf, ra, view);
+               list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview);
 }
 
 void cmd_lzrm(char *argbuf)
@@ -767,6 +765,7 @@ void usergoto(char *where, int display_result, int transiently,
 {
        int a;
        int new_messages = 0;
+       int old_messages = 0;
        int total_messages = 0;
        int info = 0;
        int rmailflag;
@@ -778,6 +777,11 @@ void usergoto(char *where, int display_result, int transiently,
        long *msglist = NULL;
        int num_msgs = 0;
        unsigned int original_v_flags;
+       int num_sets;
+       int s;
+       char setstr[128], lostr[64], histr[64];
+       long lo, hi;
+       int is_trash = 0;
 
        /* If the supplied room name is NULL, the caller wants us to know that
         * it has already copied the room record into CC->room, so
@@ -820,20 +824,42 @@ void usergoto(char *where, int display_result, int transiently,
        get_mm();
         cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
         if (cdbfr != NULL) {
-               msglist = malloc(cdbfr->len);
-               memcpy(msglist, cdbfr->ptr, cdbfr->len);
+               msglist = (long *) cdbfr->ptr;
+               cdbfr->ptr = NULL;      /* usergoto() now owns this memory */
                num_msgs = cdbfr->len / sizeof(long);
                cdb_free(cdbfr);
        }
 
-       if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
-               if (msglist[a] > 0L) {
-                       ++total_messages;
-                       if (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
-                               ++new_messages;
+       total_messages = 0;
+       for (a=0; a<num_msgs; ++a) {
+               if (msglist[a] > 0L) ++total_messages;
+       }
+       new_messages = num_msgs;
+       num_sets = num_tokens(vbuf.v_seen, ',');
+       for (s=0; s<num_sets; ++s) {
+               extract_token(setstr, vbuf.v_seen, s, ',', sizeof setstr);
+
+               extract_token(lostr, setstr, 0, ':', sizeof lostr);
+               if (num_tokens(setstr, ':') >= 2) {
+                       extract_token(histr, setstr, 1, ':', sizeof histr);
+                       if (!strcmp(histr, "*")) {
+                               snprintf(histr, sizeof histr, "%ld", LONG_MAX);
+                       }
+               } 
+               else {
+                       strcpy(histr, lostr);
+               }
+               lo = atol(lostr);
+               hi = atol(histr);
+
+               for (a=0; a<num_msgs; ++a) if (msglist[a] > 0L) {
+                       if ((msglist[a] >= lo) && (msglist[a] <= hi)) {
+                               ++old_messages;
+                               msglist[a] = 0L;
                        }
                }
        }
+       new_messages = total_messages - old_messages;
 
        if (msglist != NULL) free(msglist);
 
@@ -848,10 +874,14 @@ void usergoto(char *where, int display_result, int transiently,
        else
                raideflag = 0;
 
-       strcpy(truncated_roomname, CC->room.QRname);
+       safestrncpy(truncated_roomname, CC->room.QRname, sizeof truncated_roomname);
        if ( (CC->room.QRflags & QR_MAILBOX)
           && (atol(CC->room.QRname) == CC->user.usernum) ) {
-               strcpy(truncated_roomname, &truncated_roomname[11]);
+               safestrncpy(truncated_roomname, &truncated_roomname[11], sizeof truncated_roomname);
+       }
+
+       if (!strcasecmp(truncated_roomname, USERTRASHROOM)) {
+               is_trash = 1;
        }
 
        if (retmsgs != NULL) *retmsgs = total_messages;
@@ -864,7 +894,7 @@ void usergoto(char *where, int display_result, int transiently,
        CC->curr_view = (int)vbuf.v_view;
 
        if (display_result) {
-               cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|\n",
+               cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d|%d|%d|%d|\n",
                        CIT_OK, CtdlCheckExpress(),
                        truncated_roomname,
                        (int)new_messages,
@@ -878,12 +908,44 @@ void usergoto(char *where, int display_result, int transiently,
                        (int)newmailcount,
                        (int)CC->room.QRfloor,
                        (int)vbuf.v_view,
-                       (int)CC->room.QRdefaultview
+                       (int)CC->room.QRdefaultview,
+                       (int)is_trash
                );
        }
 }
 
 
+/*
+ * Handle some of the macro named rooms
+ */
+void convert_room_name_macros(char *towhere, size_t maxlen) {
+       if (!strcasecmp(towhere, "_BASEROOM_")) {
+               safestrncpy(towhere, config.c_baseroom, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_MAIL_")) {
+               safestrncpy(towhere, MAILROOM, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_TRASH_")) {
+               safestrncpy(towhere, USERTRASHROOM, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_BITBUCKET_")) {
+               safestrncpy(towhere, config.c_twitroom, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_CALENDAR_")) {
+               safestrncpy(towhere, USERCALENDARROOM, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_TASKS_")) {
+               safestrncpy(towhere, USERTASKSROOM, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_CONTACTS_")) {
+               safestrncpy(towhere, USERCONTACTSROOM, maxlen);
+       }
+       else if (!strcasecmp(towhere, "_NOTES_")) {
+               safestrncpy(towhere, USERNOTESROOM, maxlen);
+       }
+}
+
+
 /* 
  * cmd_goto()  -  goto a new room
  */
@@ -893,28 +955,23 @@ void cmd_goto(char *gargs)
        int c;
        int ok = 0;
        int ra;
-       char augmented_roomname[SIZ];
-       char towhere[SIZ];
-       char password[SIZ];
+       char augmented_roomname[ROOMNAMELEN];
+       char towhere[ROOMNAMELEN];
+       char password[32];
        int transiently = 0;
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       extract(towhere, gargs, 0);
-       extract(password, gargs, 1);
+       extract_token(towhere, gargs, 0, '|', sizeof towhere);
+       extract_token(password, gargs, 1, '|', sizeof password);
        transiently = extract_int(gargs, 2);
 
        getuser(&CC->user, CC->curr_user);
 
-       if (!strcasecmp(towhere, "_BASEROOM_"))
-               strcpy(towhere, config.c_baseroom);
-
-       if (!strcasecmp(towhere, "_MAIL_"))
-               strcpy(towhere, MAILROOM);
-
-       if (!strcasecmp(towhere, "_BITBUCKET_"))
-               strcpy(towhere, config.c_twitroom);
-
+       /*
+        * Handle some of the macro named rooms
+        */
+       convert_room_name_macros(towhere, sizeof towhere);
 
        /* First try a regular match */
        c = getroom(&QRscratch, towhere);
@@ -925,7 +982,7 @@ void cmd_goto(char *gargs)
                            &CC->user, towhere);
                c = getroom(&QRscratch, augmented_roomname);
                if (c == 0)
-                       strcpy(towhere, augmented_roomname);
+                       safestrncpy(towhere, augmented_roomname, sizeof towhere);
        }
 
        /* And if the room was found... */
@@ -1027,13 +1084,15 @@ void cmd_whok(void)
  */
 void cmd_rdir(void)
 {
-       char buf[SIZ];
-       char flnm[SIZ];
-       char comment[SIZ];
+       char buf[256];
+       char flnm[256];
+       char comment[256];
        FILE *ls, *fd;
        struct stat statbuf;
+       char tempfilename[PATH_MAX];
 
        if (CtdlAccessCheck(ac_logged_in)) return;
+       CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        
        getroom(&CC->room, CC->room.QRname);
        getuser(&CC->user, CC->curr_user);
@@ -1048,26 +1107,38 @@ void cmd_rdir(void)
                cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
                return;
        }
-       cprintf("%d %s|%s/files/%s\n",
-       LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->room.QRdirname);
-
-        snprintf(buf, sizeof buf, "ls %s/files/%s  >%s 2> /dev/null",
-                BBSDIR, CC->room.QRdirname, CC->temp);
-        system(buf);
+       cprintf("%d %s|%s/%s\n",
+                       LISTING_FOLLOWS, 
+                       config.c_fqdn,
+                       ctdl_file_dir, 
+                       CC->room.QRdirname);
 
-       snprintf(buf, sizeof buf, "%s/files/%s/filedir", BBSDIR, CC->room.QRdirname);
+       snprintf(buf, sizeof buf, 
+                        "ls %s/%s >%s 2>/dev/null",
+                        ctdl_file_dir,
+                        CC->room.QRdirname, 
+                        tempfilename);
+       system(buf);
+
+       snprintf(buf, sizeof buf, 
+                        "%s/%s/filedir",
+                        ctdl_file_dir,
+                        CC->room.QRdirname);
        fd = fopen(buf, "r");
        if (fd == NULL)
                fd = fopen("/dev/null", "r");
 
-       ls = fopen(CC->temp, "r");
+       ls = fopen(tempfilename, "r");
        while (fgets(flnm, sizeof flnm, ls) != NULL) {
                flnm[strlen(flnm) - 1] = 0;
                if (strcasecmp(flnm, "filedir")) {
-                       snprintf(buf, sizeof buf, "%s/files/%s/%s",
-                               BBSDIR, CC->room.QRdirname, flnm);
+                       snprintf(buf, sizeof buf, 
+                                        "%s/%s/%s",
+                                        ctdl_file_dir,
+                                        CC->room.QRdirname,
+                                        flnm);
                        stat(buf, &statbuf);
-                       strcpy(comment, "");
+                       safestrncpy(comment, "", sizeof comment);
                        fseek(fd, 0L, 0);
                        while ((fgets(buf, sizeof buf, fd) != NULL)
                               && (strlen(comment) == 0)) {
@@ -1083,7 +1154,7 @@ void cmd_rdir(void)
        }
        fclose(ls);
        fclose(fd);
-       unlink(CC->temp);
+       unlink(tempfilename);
 
        cprintf("000\n");
 }
@@ -1135,7 +1206,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
        struct floor *fl;
        struct floor flbuf;
        long owner = 0L;
-       char actual_old_name[SIZ];
+       char actual_old_name[ROOMNAMELEN];
 
        lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
                old_name, new_name, new_floor);
@@ -1158,7 +1229,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
                ret = crr_room_not_found;
        }
 
-       else if ( (CC->user.axlevel < 6)
+       else if ( (CC->user.axlevel < 6) && (!CC->internal_pgm)
                  && (CC->user.usernum != qrbuf.QRroomaide)
                  && ( (((qrbuf.QRflags & QR_MAILBOX) == 0) || (atol(qrbuf.QRname) != CC->user.usernum))) )  {
                ret = crr_access_denied;
@@ -1170,7 +1241,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
 
        else {
                /* Rename it */
-               strcpy(actual_old_name, qrbuf.QRname);
+               safestrncpy(actual_old_name, qrbuf.QRname, sizeof actual_old_name);
                if (qrbuf.QRflags & QR_MAILBOX) {
                        owner = atol(qrbuf.QRname);
                }
@@ -1245,7 +1316,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
  */
 void cmd_setr(char *args)
 {
-       char buf[SIZ];
+       char buf[256];
        int new_order = 0;
        int r;
        int new_floor;
@@ -1265,9 +1336,9 @@ void cmd_setr(char *args)
        if (CC->room.QRflags & QR_MAILBOX) {
                sprintf(new_name, "%010ld.", atol(CC->room.QRname) );
        } else {
-               strcpy(new_name, "");
+               safestrncpy(new_name, "", sizeof new_name);
        }
-       extract(&new_name[strlen(new_name)], args, 0);
+       extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
 
        r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
 
@@ -1309,7 +1380,7 @@ void cmd_setr(char *args)
        lgetroom(&CC->room, CC->room.QRname);
 
        /* Directory room */
-       extract(buf, args, 2);
+       extract_token(buf, args, 2, '|', sizeof buf);
        buf[15] = 0;
        safestrncpy(CC->room.QRdirname, buf,
                sizeof CC->room.QRdirname);
@@ -1347,7 +1418,7 @@ void cmd_setr(char *args)
                if (num_parms(args) >= 7)
                        CC->room.QRorder = (char) new_order;
                /* Room password */
-               extract(buf, args, 1);
+               extract_token(buf, args, 1, '|', sizeof buf);
                buf[10] = 0;
                safestrncpy(CC->room.QRpasswd, buf,
                            sizeof CC->room.QRpasswd);
@@ -1371,12 +1442,14 @@ void cmd_setr(char *args)
 
        /* Create a room directory if necessary */
        if (CC->room.QRflags & QR_DIRECTORY) {
-               snprintf(buf, sizeof buf, "./files/%s",
-                       CC->room.QRdirname);
+               snprintf(buf, sizeof buf,"%s/%s",
+                                ctdl_file_dir,
+                                CC->room.QRdirname);
                mkdir(buf, 0755);
        }
-       snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->room.QRname, CC->curr_user);
-       aide_message(buf);
+       snprintf(buf, sizeof buf, "The room \"%s\" has been edited by %s.\n",
+               CC->room.QRname, CC->curr_user);
+       aide_message(buf, "Room modification Message");
        cprintf("%d Ok\n", CIT_OK);
 }
 
@@ -1432,26 +1505,17 @@ void cmd_seta(char *new_ra)
        if (post_notice == 1) {
                if (strlen(usbuf.fullname) > 0)
                        snprintf(buf, sizeof buf,
-                               "%s is now room aide for %s>\n",
+                               "%s is now the room aide for \"%s\".\n",
                                usbuf.fullname, CC->room.QRname);
                else
                        snprintf(buf, sizeof buf,
-                               "There is now no room aide for %s>\n",
+                               "There is now no room aide for \"%s\".\n",
                                CC->room.QRname);
-               aide_message(buf);
+               aide_message(buf, "Aide Room Modification");
        }
        cprintf("%d Ok\n", CIT_OK);
 }
 
-/*
- * Generate an associated file name for a room
- */
-void assoc_file_name(char *buf, size_t n,
-                    struct ctdlroom *qrbuf, const char *prefix)
-{
-       snprintf(buf, n, "./%s/%ld", prefix, qrbuf->QRnumber);
-}
-
 /* 
  * retrieve info file for this room
  */
@@ -1461,7 +1525,7 @@ void cmd_rinf(void)
        char buf[SIZ];
        FILE *info_fp;
 
-       assoc_file_name(filename, sizeof filename, &CC->room, "info");
+       assoc_file_name(filename, sizeof filename, &CC->room, ctdl_info_dir);
        info_fp = fopen(filename, "r");
 
        if (info_fp == NULL) {
@@ -1478,32 +1542,72 @@ void cmd_rinf(void)
        fclose(info_fp);
 }
 
+/*
+ * Asynchronously schedule a room for deletion.  The room will appear
+ * deleted to the user(s), but it won't actually get purged from the
+ * database until THE DREADED AUTO-PURGER makes its next run.
+ */
+void schedule_room_for_deletion(struct ctdlroom *qrbuf)
+{
+       char old_name[ROOMNAMELEN];
+       static int seq = 0;
+
+       lprintf(CTDL_NOTICE, "Scheduling room <%s> for deletion\n",
+               qrbuf->QRname);
+
+       safestrncpy(old_name, qrbuf->QRname, sizeof old_name);
+
+       getroom(qrbuf, qrbuf->QRname);
+
+       /* Turn the room into a private mailbox owned by a user who doesn't
+        * exist.  This will immediately make the room invisible to everyone,
+        * and qualify the room for purging.
+        */
+       snprintf(qrbuf->QRname, sizeof qrbuf->QRname, "9999999999.%08lx.%04d.%s",
+               time(NULL),
+               ++seq,
+               old_name
+       );
+       qrbuf->QRflags |= QR_MAILBOX;
+       time(&qrbuf->QRgen);    /* Use a timestamp as the new generation number  */
+
+       putroom(qrbuf);
+
+       b_deleteroom(old_name);
+}
+
+
+
 /*
  * Back end processing to delete a room and everything associated with it
+ * (This one is synchronous and should only get called by THE DREADED
+ * AUTO-PURGER in serv_expire.c.  All user-facing code should call
+ * the asynchronous schedule_room_for_deletion() instead.)
  */
 void delete_room(struct ctdlroom *qrbuf)
 {
        struct floor flbuf;
        char filename[100];
+       /* TODO: filename magic? does this realy work? */
 
        lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
 
        /* Delete the info file */
-       assoc_file_name(filename, sizeof filename, qrbuf, "info");
+       assoc_file_name(filename, sizeof filename, qrbuf, ctdl_info_dir);
        unlink(filename);
 
        /* Delete the image file */
-       assoc_file_name(filename, sizeof filename, qrbuf, "images");
+       assoc_file_name(filename, sizeof filename, qrbuf, ctdl_image_dir);
        unlink(filename);
 
        /* Delete the room's network config file */
-       assoc_file_name(filename, sizeof filename, qrbuf, "netconfigs");
+       assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
        unlink(filename);
 
        /* Delete the messages in the room
         * (Careful: this opens an S_ROOMS critical section!)
         */
-       CtdlDeleteMessages(qrbuf->QRname, 0L, "");
+       CtdlDeleteMessages(qrbuf->QRname, NULL, 0, "", 0);
 
        /* Flag the room record as not in use */
        lgetroom(qrbuf, qrbuf->QRname);
@@ -1546,7 +1650,7 @@ int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr) {
                }
 
                /* Can't delete your Mail> room */
-               if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
+               if (!strcasecmp(&qr->QRname[11], MAILROOM)) return(0);
 
                /* Otherwise it's ok */
                return(1);
@@ -1575,22 +1679,22 @@ void cmd_kill(char *argbuf)
        }
        if (kill_ok) {
                if (CC->room.QRflags & QR_MAILBOX) {
-                       strcpy(deleted_room_name, &CC->room.QRname[11]);
+                       safestrncpy(deleted_room_name, &CC->room.QRname[11], sizeof deleted_room_name);
                }
                else {
-                       strcpy(deleted_room_name, CC->room.QRname);
+                       safestrncpy(deleted_room_name, CC->room.QRname, sizeof deleted_room_name);
                }
 
                /* Do the dirty work */
-               delete_room(&CC->room);
+               schedule_room_for_deletion(&CC->room);
 
                /* Return to the Lobby */
                usergoto(config.c_baseroom, 0, 0, NULL, NULL);
 
                /* tell the world what we did */
-               snprintf(msg, sizeof msg, "%s> killed by %s\n",
+               snprintf(msg, sizeof msg, "The room \"%s\" has been deleted by %s.\n",
                         deleted_room_name, CC->curr_user);
-               aide_message(msg);
+               aide_message(msg, "Room Purger Message");
                cprintf("%d '%s' deleted.\n", CIT_OK, deleted_room_name);
        } else {
                cprintf("%d ok to delete.\n", CIT_OK);
@@ -1617,13 +1721,14 @@ unsigned create_room(char *new_room_name,
        struct floor flbuf;
        struct visit vbuf;
 
-       lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name);
+       lprintf(CTDL_DEBUG, "create_room(name=%s, type=%d, view=%d)\n",
+               new_room_name, new_room_type, new_room_view);
+
        if (getroom(&qrbuf, new_room_name) == 0) {
                lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
-               return (0);     /* already exists */
+               return(0);
        }
 
-
        memset(&qrbuf, 0, sizeof(struct ctdlroom));
        safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
        qrbuf.QRflags = QR_INUSE;
@@ -1679,13 +1784,11 @@ unsigned create_room(char *new_room_name,
        /* Grant the creator access to the room unless the avoid_access
         * parameter was specified.
         */
-       if (avoid_access == 0) {
-               lgetuser(&CC->user, CC->curr_user);
+       if ( (CC->logged_in) && (avoid_access == 0) ) {
                CtdlGetRelationship(&vbuf, &CC->user, &qrbuf);
                vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
                vbuf.v_flags = vbuf.v_flags | V_ACCESS;
                CtdlSetRelationship(&vbuf, &CC->user, &qrbuf);
-               lputuser(&CC->user);
        }
 
        /* resume our happy day */
@@ -1699,21 +1802,21 @@ unsigned create_room(char *new_room_name,
 void cmd_cre8(char *args)
 {
        int cre8_ok;
-       char new_room_name[SIZ];
+       char new_room_name[ROOMNAMELEN];
        int new_room_type;
-       char new_room_pass[SIZ];
+       char new_room_pass[32];
        int new_room_floor;
        int new_room_view;
-       char aaa[SIZ];
+       char *notification_message = NULL;
        unsigned newflags;
        struct floor *fl;
        int avoid_access = 0;
 
        cre8_ok = extract_int(args, 0);
-       extract(new_room_name, args, 1);
+       extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
        new_room_name[ROOMNAMELEN - 1] = 0;
        new_room_type = extract_int(args, 2);
-       extract(new_room_pass, args, 3);
+       extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
        avoid_access = extract_int(args, 5);
        new_room_view = extract_int(args, 6);
        new_room_pass[9] = 0;
@@ -1748,7 +1851,7 @@ void cmd_cre8(char *args)
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       if (CC->user.axlevel < config.c_createax) {
+       if (CC->user.axlevel < config.c_createax || CC->internal_pgm) {
                cprintf("%d You need higher access to create rooms.\n",
                        ERROR + HIGHER_ACCESS_REQUIRED);
                return;
@@ -1794,21 +1897,19 @@ void cmd_cre8(char *args)
                           new_room_view);
 
        /* post a message in Aide> describing the new room */
-       safestrncpy(aaa, new_room_name, sizeof aaa);
-       strcat(aaa, "> created by ");
-       strcat(aaa, CC->user.fullname);
-       if (newflags & QR_MAILBOX)
-               strcat(aaa, " [personal]");
-       else if (newflags & QR_PRIVATE)
-               strcat(aaa, " [private]");
-       if (newflags & QR_GUESSNAME)
-               strcat(aaa, "[guessname] ");
-       if (newflags & QR_PASSWORDED) {
-               strcat(aaa, "\n Password: ");
-               strcat(aaa, new_room_pass);
-       }
-       strcat(aaa, "\n");
-       aide_message(aaa);
+       notification_message = malloc(1024);
+       snprintf(notification_message, 1024,
+               "A new room called \"%s\" has been created by %s%s%s%s%s%s\n",
+               new_room_name,
+               CC->user.fullname,
+               ((newflags & QR_MAILBOX) ? " [personal]" : ""),
+               ((newflags & QR_PRIVATE) ? " [private]" : ""),
+               ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
+               ((newflags & QR_PASSWORDED) ? " Password: " : ""),
+               ((newflags & QR_PASSWORDED) ? new_room_pass : "")
+       );
+       aide_message(notification_message, "Room Creation Message");
+       free(notification_message);
 
        cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
 }
@@ -1829,7 +1930,7 @@ void cmd_einf(char *ok)
                cprintf("%d Ok.\n", CIT_OK);
                return;
        }
-       assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
+       assoc_file_name(infofilename, sizeof infofilename, &CC->room, ctdl_info_dir);
        lprintf(CTDL_DEBUG, "opening\n");
        fp = fopen(infofilename, "w");
        lprintf(CTDL_DEBUG, "checking\n");
@@ -1841,7 +1942,7 @@ void cmd_einf(char *ok)
        cprintf("%d Send info...\n", SEND_LISTING);
 
        do {
-               client_gets(buf);
+               client_getln(buf, sizeof buf);
                if (strcmp(buf, "000"))
                        fprintf(fp, "%s\n", buf);
        } while (strcmp(buf, "000"));
@@ -1885,13 +1986,13 @@ void cmd_lflr(void)
  */
 void cmd_cflr(char *argbuf)
 {
-       char new_floor_name[SIZ];
+       char new_floor_name[256];
        struct floor flbuf;
        int cflr_ok;
        int free_slot = (-1);
        int a;
 
-       extract(new_floor_name, argbuf, 0);
+       extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
        cflr_ok = extract_int(argbuf, 1);
 
        if (CtdlAccessCheck(ac_aide)) return;
@@ -2009,7 +2110,7 @@ void cmd_eflr(char *argbuf)
                return;
        }
        if (np >= 2)
-               extract(flbuf.f_name, argbuf, 1);
+               extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
        lputfloor(&flbuf, floor_num);
 
        cprintf("%d Ok\n", CIT_OK);