]> code.citadel.org Git - citadel.git/blobdiff - citadel/room_ops.c
* Use syslog-compatible logging levels in lprintf(); the loglevel chosen
[citadel.git] / citadel / room_ops.c
index e2a3310489ff1ff2a7429d1a2f788149f3bb37f6..2b80cabae660df0fc16f066de762ac9edbc49721 100644 (file)
@@ -305,7 +305,8 @@ void getfloor(struct floor *flbuf, int floor_num)
                cdb_free(cdbfl);
        } else {
                if (floor_num == 0) {
-                       strcpy(flbuf->f_name, "Main Floor");
+                       safestrncpy(flbuf->f_name, "Main Floor", 
+                               sizeof flbuf->f_name);
                        flbuf->f_flags = F_INUSE;
                        flbuf->f_ref_count = 3;
                }
@@ -744,13 +745,14 @@ void usergoto(char *where, int display_result, int transiently,
         struct cdbdata *cdbfr;
        long *msglist = NULL;
        int num_msgs = 0;
+       unsigned int original_v_flags;
 
        /* 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
         * we can skip the extra database fetch.
         */
        if (where != NULL) {
-               strcpy(CC->room.QRname, where);
+               safestrncpy(CC->room.QRname, where, sizeof CC->room.QRname);
                getroom(&CC->room, where);
        }
 
@@ -758,6 +760,7 @@ void usergoto(char *where, int display_result, int transiently,
 
        begin_critical_section(S_USERS);
        CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
+       original_v_flags = vbuf.v_flags;
 
        /* Know the room ... but not if it's the page log room, or if the
         * caller specified that we're only entering this room transiently.
@@ -767,7 +770,11 @@ void usergoto(char *where, int display_result, int transiently,
                vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
                vbuf.v_flags = vbuf.v_flags | V_ACCESS;
        }
-       CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
+       
+       /* Only rewrite the database record if we changed something */
+       if (vbuf.v_flags != original_v_flags) {
+               CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
+       }
        end_critical_section(S_USERS);
 
        /* Check for new mail */
@@ -817,7 +824,7 @@ void usergoto(char *where, int display_result, int transiently,
 
        if (retmsgs != NULL) *retmsgs = total_messages;
        if (retnew != NULL) *retnew = new_messages;
-       lprintf(9, "<%s> %d new of %d total messages\n",
+       lprintf(CTDL_DEBUG, "<%s> %d new of %d total messages\n",
                CC->room.QRname,
                new_messages, total_messages
        );
@@ -927,8 +934,7 @@ void cmd_goto(char *gargs)
                                   ((ra & UA_KNOWN) == 0) &&
                                   (CC->user.axlevel < 6)
                                   ) {
-                               lprintf(9, "Failed to acquire private room\n");
-                               goto NOPE;
+                               lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
                        } else {
                                memcpy(&CC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
@@ -938,7 +944,7 @@ void cmd_goto(char *gargs)
                }
        }
 
-NOPE:  cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
+       cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
 }
 
 
@@ -1095,7 +1101,7 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
        long owner = 0L;
        char actual_old_name[SIZ];
 
-       lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n",
+       lprintf(CTDL_DEBUG, "CtdlRenameRoom(%s, %s, %d)\n",
                old_name, new_name, new_floor);
 
        if (new_floor >= 0) {
@@ -1186,9 +1192,11 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
                lgetfloor(&flbuf, old_floor);
                --flbuf.f_ref_count;
                lputfloor(&flbuf, old_floor);
-               lgetfloor(&flbuf, CC->room.QRfloor);
+               lprintf(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, CC->room.QRfloor);
+               lputfloor(&flbuf, new_floor);
+               lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
        }
 
        /* ...and everybody say "YATTA!" */     
@@ -1228,12 +1236,12 @@ void cmd_setr(char *args)
        r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
 
        if (r == crr_room_not_found) {
-               cprintf("%d Internal error - room not found?\n", ERROR);
+               cprintf("%d Internal error - room not found?\n", ERROR + INTERNAL_ERROR);
        } else if (r == crr_already_exists) {
                cprintf("%d '%s' already exists.\n",
                        ERROR + ALREADY_EXISTS, new_name);
        } else if (r == crr_noneditable) {
-               cprintf("%d Cannot edit this room.\n", ERROR);
+               cprintf("%d Cannot edit this room.\n", ERROR + NOT_HERE);
        } else if (r == crr_invalid_floor) {
                cprintf("%d Target floor does not exist.\n",
                        ERROR + INVALID_FLOOR_OPERATION);
@@ -1243,7 +1251,7 @@ void cmd_setr(char *args)
                        CC->room.QRname);
        } else if (r != crr_ok) {
                cprintf("%d Error: CtdlRenameRoom() returned %d\n",
-                       ERROR, r);
+                       ERROR + INTERNAL_ERROR, r);
        }
 
        if (r != crr_ok) {
@@ -1421,7 +1429,7 @@ void cmd_rinf(void)
        info_fp = fopen(filename, "r");
 
        if (info_fp == NULL) {
-               cprintf("%d No info file.\n", ERROR);
+               cprintf("%d No info file.\n", ERROR + FILE_NOT_FOUND);
                return;
        }
        cprintf("%d Info:\n", LISTING_FOLLOWS);
@@ -1442,7 +1450,7 @@ void delete_room(struct ctdlroom *qrbuf)
        struct floor flbuf;
        char filename[100];
 
-       lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
+       lprintf(CTDL_NOTICE, "Deleting room <%s>\n", qrbuf->QRname);
 
        /* Delete the info file */
        assoc_file_name(filename, sizeof filename, qrbuf, "info");
@@ -1572,9 +1580,9 @@ unsigned create_room(char *new_room_name,
        struct floor flbuf;
        struct visit vbuf;
 
-       lprintf(9, "create_room(%s)\n", new_room_name);
+       lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name);
        if (getroom(&qrbuf, new_room_name) == 0) {
-               lprintf(9, "%s already exists.\n", new_room_name);
+               lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name);
                return (0);     /* already exists */
        }
 
@@ -1672,7 +1680,7 @@ void cmd_cre8(char *args)
        new_room_floor = 0;
 
        if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
-               cprintf("%d Invalid room name.\n", ERROR);
+               cprintf("%d Invalid room name.\n", ERROR + ILLEGAL_VALUE);
                return;
        }
 
@@ -1707,7 +1715,7 @@ void cmd_cre8(char *args)
        }
 
        if ((new_room_type < 0) || (new_room_type > 5)) {
-               cprintf("%d Invalid room type.\n", ERROR);
+               cprintf("%d Invalid room type.\n", ERROR + ILLEGAL_VALUE);
                return;
        }
 
@@ -1715,7 +1723,7 @@ void cmd_cre8(char *args)
                if ((config.c_aide_mailboxes == 0)
                   || (CC->user.axlevel < 6)) {
                        cprintf("%d Higher access required\n", 
-                               ERROR+HIGHER_ACCESS_REQUIRED);
+                               ERROR + HIGHER_ACCESS_REQUIRED);
                        return;
                }
        }
@@ -1775,9 +1783,9 @@ void cmd_einf(char *ok)
                return;
        }
        assoc_file_name(infofilename, sizeof infofilename, &CC->room, "info");
-       lprintf(9, "opening\n");
+       lprintf(CTDL_DEBUG, "opening\n");
        fp = fopen(infofilename, "w");
-       lprintf(9, "checking\n");
+       lprintf(CTDL_DEBUG, "checking\n");
        if (fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
                  ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
@@ -1843,7 +1851,7 @@ void cmd_cflr(char *argbuf)
 
        if (strlen(new_floor_name) == 0) {
                cprintf("%d Blank floor name not allowed.\n",
-                       ERROR+ILLEGAL_VALUE);
+                       ERROR + ILLEGAL_VALUE);
                return;
        }
 
@@ -1939,7 +1947,7 @@ void cmd_eflr(char *argbuf)
 
        np = num_parms(argbuf);
        if (np < 1) {
-               cprintf("%d Usage error.\n", ERROR);
+               cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
                return;
        }