Ok this is it, the best of both worlds.
authorArt Cancro <ajc@citadel.org>
Fri, 28 Jan 2011 17:07:34 +0000 (12:07 -0500)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 14:09:41 +0000 (14:09 +0000)
1. Go back to the 'cache the most recent msglist' and 'binary-search that list' method.
2. Make ONE attempt to reload the msglist if a search fails.

citadel/msgbase.c

index 3a12fcc0302c39de009bc844beaeb0915667f340..ab0176de0a9804b25a06856633373e75d3575420 100644 (file)
@@ -654,7 +654,6 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
        
                CC->cached_msglist = msglist;
                CC->cached_num_msgs = num_msgs;
-               syslog(LOG_DEBUG, "\033[34m RELOAD \033[0m\n");
        }
 
        /*
@@ -1565,7 +1564,6 @@ int check_cached_msglist(long msgnum) {
        int max = (CC->cached_num_msgs - 1);
 
        while (max >= min) {
-               syslog(LOG_DEBUG, "\033[35m Checking from %d to %d \033[0m\n", min, max);
                int middle = min + (max-min) / 2 ;
                if (msgnum == CC->cached_msglist[middle]) {
                        return om_ok;
@@ -1632,14 +1630,27 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
                return(r);
        }
 
+       /*
+        * Check to make sure the message is actually IN this room
+        */
        r = check_cached_msglist(msg_num);
-       if (r == om_ok) {
-               syslog(LOG_DEBUG, "\033[32m PASS \033[0m\n");
+       if (r == om_access_denied) {
+               /* Not in the cache?  We get ONE shot to check it again. */
+               CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, NULL, NULL);
+               r = check_cached_msglist(msg_num);
        }
-       else {
-               syslog(LOG_DEBUG, "\033[31m FAIL \033[0m\n");
+       if (r != om_ok) {
+               syslog(LOG_DEBUG, "\033[31m SECURITY CHECK FAIL \033[0m\n");
+               if (do_proto) {
+                       if (r == om_access_denied) {
+                               cprintf("%d message %ld was not found in this room\n",
+                                       ERROR + HIGHER_ACCESS_REQUIRED,
+                                       msg_num
+                               );
+                       }
+               }
+               return(r);
        }
-       /* FIXME after testing, this is where we deny access */
 
        /*
         * Fetch the message from disk.  If we're in HEADERS_FAST mode,