]> code.citadel.org Git - citadel.git/blobdiff - citadel/room_ops.c
* oops, an oversight ... CtdlRoomAccess() needs to convey UA_DELETEALLOWED for intern...
[citadel.git] / citadel / room_ops.c
index b82016ba558452923564cc482d870e7a943e6875..07ad2f5e061ab7e051f1f5388b82b933a06a3925 100644 (file)
@@ -42,6 +42,8 @@
 #include "citadel_dirs.h"
 #include "threads.h"
 
+#include "ctdl_module.h"
+
 struct floor *floorcache[MAXFLOORS];
 
 /*
@@ -55,7 +57,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
 
        /* for internal programs, always do everything */
        if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
-               retval = (UA_KNOWN | UA_GOTOALLOWED | UA_POSTALLOWED);
+               retval = (UA_KNOWN | UA_GOTOALLOWED | UA_POSTALLOWED | UA_DELETEALLOWED);
                vbuf.v_view = 0;
                goto SKIP_EVERYTHING;
        }
@@ -181,7 +183,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
        if ( (userbuf->axlevel >= 6)
           || (userbuf->usernum == roombuf->QRroomaide)
           ) {
-               retval = retval | UA_ADMINALLOWED | UA_DELETEALLOWED;
+               retval = retval | UA_ADMINALLOWED | UA_DELETEALLOWED | UA_POSTALLOWED;
        }
 
 NEWMSG:        /* By the way, we also check for the presence of new messages */
@@ -493,6 +495,15 @@ void delete_msglist(struct ctdlroom *whichroom)
 
 
 
+/*
+ * Message pointer compare function for sort_msglist()
+ */
+int sort_msglist_cmp(const void *m1, const void *m2) {
+       if ((*(const long *)m1) > (*(const long *)m2)) return(1);
+       if ((*(const long *)m1) < (*(const long *)m2)) return(-1);
+       return(0);
+}
+
 
 /*
  * sort message pointers
@@ -500,25 +511,15 @@ void delete_msglist(struct ctdlroom *whichroom)
  */
 int sort_msglist(long listptrs[], int oldcount)
 {
-       int a, b;
-       long hold1, hold2;
        int numitems;
 
        numitems = oldcount;
-       if (numitems < 2)
+       if (numitems < 2) {
                return (oldcount);
+       }
 
        /* do the sort */
-       for (a = numitems - 2; a >= 0; --a) {
-               for (b = 0; b <= a; ++b) {
-                       if (listptrs[b] > (listptrs[b + 1])) {
-                               hold1 = listptrs[b];
-                               hold2 = listptrs[b + 1];
-                               listptrs[b] = hold2;
-                               listptrs[b + 1] = hold1;
-                       }
-               }
-       }
+       qsort(listptrs, numitems, sizeof(long), sort_msglist_cmp);
 
        /* and yank any nulls */
        while ((numitems > 0) && (listptrs[0] == 0L)) {
@@ -933,7 +934,7 @@ void usergoto(char *where, int display_result, int transiently,
 
        if (retmsgs != NULL) *retmsgs = total_messages;
        if (retnew != NULL) *retnew = new_messages;
-       lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
+       CtdlLogPrintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
                CC->room.QRname,
                new_messages, total_messages
        );
@@ -976,6 +977,9 @@ void convert_room_name_macros(char *towhere, size_t maxlen) {
        else if (!strcasecmp(towhere, "_TRASH_")) {
                safestrncpy(towhere, USERTRASHROOM, maxlen);
        }
+       else if (!strcasecmp(towhere, "_DRAFTS_")) {
+               safestrncpy(towhere, USERDRAFTROOM, maxlen);
+       }
        else if (!strcasecmp(towhere, "_BITBUCKET_")) {
                safestrncpy(towhere, config.c_twitroom, maxlen);
        }
@@ -1073,7 +1077,7 @@ void cmd_goto(char *gargs)
                                   ((ra & UA_KNOWN) == 0) &&
                                   (CC->user.axlevel < 6)
                                   ) {
-                               lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
+                               CtdlLogPrintf(CTDL_DEBUG, "Failed to acquire private room\n");
                        } else {
                                memcpy(&CC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
@@ -1087,7 +1091,7 @@ void cmd_goto(char *gargs)
 }
 
 
-void cmd_whok(void)
+void cmd_whok(char *cmdbuf)
 {
        struct ctdluser temp;
        struct cdbdata *cdbus;
@@ -1113,7 +1117,7 @@ void cmd_whok(void)
 /*
  * RDIR command for room directory
  */
-void cmd_rdir(void)
+void cmd_rdir(char *cmdbuf)
 {
        char buf[256];
        char comment[256];
@@ -1168,8 +1172,11 @@ void cmd_rdir(void)
                        stat(buf, &statbuf);    /* stat the file */
                        if (!(statbuf.st_mode & S_IFREG))
                        {
-                               snprintf(buf2, sizeof buf2, "Command RDIR found something that is not a useable file. It should be cleaned up.\n RDIR found this non regular file:\n%s\n", buf);
-                               aide_message(buf2, "RDIR found bad file");
+                               snprintf(buf2, sizeof buf2,
+                                       "\"%s\" appears in the file directory for room \"%s\" but is not a regular file.  Directories, named pipes, sockets, etc. are not usable in Citadel room directories.\n",
+                                       buf, CC->room.QRname
+                               );
+                               aide_message(buf2, "Unusable data found in room directory");
                                continue;       /* not a useable file type so don't show it */
                        }
                        safestrncpy(comment, "", sizeof comment);
@@ -1203,7 +1210,7 @@ void cmd_rdir(void)
 /*
  * get room parameters (aide or room aide command)
  */
-void cmd_getr(void)
+void cmd_getr(char *cmdbuf)
 {
        if (CtdlAccessCheck(ac_room_aide)) return;
 
@@ -1249,7 +1256,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
        long owner = 0L;
        char actual_old_name[ROOMNAMELEN];
 
-       lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
+       CtdlLogPrintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
                old_name, new_name, new_floor);
 
        if (new_floor >= 0) {
@@ -1340,11 +1347,11 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
                lgetfloor(&flbuf, old_floor);
                --flbuf.f_ref_count;
                lputfloor(&flbuf, old_floor);
-               lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
+               CtdlLogPrintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
                lgetfloor(&flbuf, new_floor);
                ++flbuf.f_ref_count;
                lputfloor(&flbuf, new_floor);
-               lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
+               CtdlLogPrintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
        }
 
        /* ...and everybody say "YATTA!" */     
@@ -1499,7 +1506,7 @@ void cmd_setr(char *args)
 /* 
  * get the name of the room aide for this room
  */
-void cmd_geta(void)
+void cmd_geta(char *cmdbuf)
 {
        struct ctdluser usbuf;
 
@@ -1560,7 +1567,7 @@ void cmd_seta(char *new_ra)
 /* 
  * retrieve info file for this room
  */
-void cmd_rinf(void)
+void cmd_rinf(char *gargs)
 {
        char filename[128];
        char buf[SIZ];
@@ -1593,7 +1600,7 @@ 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",
+       CtdlLogPrintf(CTDL_NOTICE, "Scheduling room <%s> for deletion\n",
                qrbuf->QRname);
 
        safestrncpy(old_name, qrbuf->QRname, sizeof old_name);
@@ -1631,7 +1638,7 @@ void delete_room(struct ctdlroom *qrbuf)
        char filename[100];
        /* TODO: filename magic? does this realy work? */
 
-       lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
+       CtdlLogPrintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
 
        /* Delete the info file */
        assoc_file_name(filename, sizeof filename, qrbuf, ctdl_info_dir);
@@ -1762,11 +1769,11 @@ unsigned create_room(char *new_room_name,
        struct floor flbuf;
        struct visit vbuf;
 
-       lprintf(CTDL_DEBUG, "create_room(name=%s, type=%d, view=%d)\n",
+       CtdlLogPrintf(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);
+               CtdlLogPrintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
                return(0);
        }
 
@@ -1974,9 +1981,9 @@ void cmd_einf(char *ok)
                return;
        }
        assoc_file_name(infofilename, sizeof infofilename, &CC->room, ctdl_info_dir);
-       lprintf(CTDL_DEBUG, "opening\n");
+       CtdlLogPrintf(CTDL_DEBUG, "opening\n");
        fp = fopen(infofilename, "w");
-       lprintf(CTDL_DEBUG, "checking\n");
+       CtdlLogPrintf(CTDL_DEBUG, "checking\n");
        if (fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
                  ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
@@ -2001,7 +2008,7 @@ void cmd_einf(char *ok)
 /* 
  * cmd_lflr()   -  List all known floors
  */
-void cmd_lflr(void)
+void cmd_lflr(char *gargs)
 {
        int a;
        struct floor flbuf;
@@ -2158,3 +2165,35 @@ void cmd_eflr(char *argbuf)
 
        cprintf("%d Ok\n", CIT_OK);
 }
+
+
+/*****************************************************************************/
+/*                      MODULE INITIALIZATION STUFF                          */
+/*****************************************************************************/
+
+CTDL_MODULE_INIT(room_ops)
+{
+       CtdlRegisterProtoHook(cmd_lrms, "LRMS", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_lkra, "LKRA", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_lkrn, "LKRN", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_lkro, "LKRO", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_lzrm, "LZRM", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_lprm, "LPRM", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_goto, "GOTO", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_whok, "WHOK", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_rdir, "RDIR", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_getr, "GETR", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_setr, "SETR", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_geta, "GETA", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_seta, "SETA", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_rinf, "RINF", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_kill, "KILL", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_cre8, "CRE8", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_einf, "EINF", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_lflr, "LFLR", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_cflr, "CFLR", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_kflr, "KFLR", "Autoconverted. TODO: document me.");
+       CtdlRegisterProtoHook(cmd_eflr, "EFLR", "Autoconverted. TODO: document me.");
+        /* return our Subversion id for the Log */
+       return "$Id$";
+}