]> code.citadel.org Git - citadel.git/blobdiff - citadel/room_ops.c
* Buffered output needs to be flushed in several places. Added calls to
[citadel.git] / citadel / room_ops.c
index e4a66b7e9e4a806f7e62e60ec5fe179546f7796a..0566282098297fa7d46ddb6fcd2d8c81056e7882 100644 (file)
@@ -140,9 +140,10 @@ int CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf)
                }
        }
 
-       /* On some systems, Aides can gain access to mailboxes as well */
-       if ( (config.c_aide_mailboxes)
-          && (userbuf->axlevel >= 6)
+       /* Aides can gain access to mailboxes as well, but they don't show
+        * by default.
+        */
+       if ( (userbuf->axlevel >= 6)
           && (roombuf->QRflags & QR_MAILBOX) ) {
                retval = retval | UA_GOTOALLOWED;
        }
@@ -333,17 +334,31 @@ void lgetfloor(struct floor *flbuf, int floor_num)
 struct floor *cgetfloor(int floor_num) {
        static int initialized = 0;
        int i;
+       int fetch_new = 0;
+       struct floor *fl = NULL;
 
+       begin_critical_section(S_FLOORCACHE);
        if (initialized == 0) {
                for (i=0; i<MAXFLOORS; ++i) {
                        floorcache[floor_num] = NULL;
                }
        initialized = 1;
        }
-       
        if (floorcache[floor_num] == NULL) {
-               floorcache[floor_num] = mallok(sizeof(struct floor));
-               getfloor(floorcache[floor_num], floor_num);
+               fetch_new = 1;
+       }
+       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);
+               if (floorcache[floor_num] != NULL) {
+                       free(floorcache[floor_num]);
+               }
+               floorcache[floor_num] = fl;
+               end_critical_section(S_FLOORCACHE);
        }
 
        return(floorcache[floor_num]);
@@ -356,14 +371,17 @@ struct floor *cgetfloor(int floor_num) {
  */
 void putfloor(struct floor *flbuf, int floor_num)
 {
-       cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
-                 flbuf, sizeof(struct floor));
-
        /* If we've cached this, clear it out, 'cuz it's WRONG now! */
+       begin_critical_section(S_FLOORCACHE);
        if (floorcache[floor_num] != NULL) {
-               phree(floorcache[floor_num]);
-               floorcache[floor_num] = NULL;
+               free(floorcache[floor_num]);
+               floorcache[floor_num] = malloc(sizeof(struct floor));
+               memcpy(floorcache[floor_num], flbuf, sizeof(struct floor));
        }
+       end_critical_section(S_FLOORCACHE);
+
+       cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
+                 flbuf, sizeof(struct floor));
 }
 
 
@@ -788,7 +806,7 @@ 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 = mallok(cdbfr->len);
+               msglist = malloc(cdbfr->len);
                memcpy(msglist, cdbfr->ptr, cdbfr->len);
                num_msgs = cdbfr->len / sizeof(long);
                cdb_free(cdbfr);
@@ -803,7 +821,7 @@ void usergoto(char *where, int display_result, int transiently,
                }
        }
 
-       if (msglist != NULL) phree(msglist);
+       if (msglist != NULL) free(msglist);
 
        if (CC->room.QRflags & QR_MAILBOX)
                rmailflag = 1;
@@ -824,7 +842,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
        );
@@ -934,7 +952,7 @@ void cmd_goto(char *gargs)
                                   ((ra & UA_KNOWN) == 0) &&
                                   (CC->user.axlevel < 6)
                                   ) {
-                               lprintf(9, "Failed to acquire private room\n");
+                               lprintf(CTDL_DEBUG, "Failed to acquire private room\n");
                        } else {
                                memcpy(&CC->room, &QRscratch,
                                        sizeof(struct ctdlroom));
@@ -1101,7 +1119,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) {
@@ -1192,11 +1210,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(9, "Reference count for floor %d is now %d\n", old_floor, flbuf.f_ref_count);
+               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, new_floor);
-               lprintf(9, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
+               lprintf(CTDL_DEBUG, "Reference count for floor %d is now %d\n", new_floor, flbuf.f_ref_count);
        }
 
        /* ...and everybody say "YATTA!" */     
@@ -1450,7 +1468,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");
@@ -1580,9 +1598,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 */
        }
 
@@ -1692,7 +1710,12 @@ void cmd_cre8(char *args)
 
        if (num_parms(args) >= 5) {
                fl = cgetfloor(extract_int(args, 4));
-               if ((fl->f_flags & F_INUSE) == 0) {
+               if (fl == NULL) {
+                       cprintf("%d Invalid floor number.\n",
+                               ERROR + INVALID_FLOOR_OPERATION);
+                       return;
+               }
+               else if ((fl->f_flags & F_INUSE) == 0) {
                        cprintf("%d Invalid floor number.\n",
                                ERROR + INVALID_FLOOR_OPERATION);
                        return;
@@ -1720,8 +1743,7 @@ void cmd_cre8(char *args)
        }
 
        if (new_room_type == 5) {
-               if ((config.c_aide_mailboxes == 0)
-                  || (CC->user.axlevel < 6)) {
+               if (CC->user.axlevel < 6) {
                        cprintf("%d Higher access required\n", 
                                ERROR + HIGHER_ACCESS_REQUIRED);
                        return;
@@ -1783,15 +1805,16 @@ 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));
                return;
        }
        cprintf("%d Send info...\n", SEND_LISTING);
+       flush_output();
 
        do {
                client_gets(buf);