LOOK AT ME I AM COMMITTING AGAIN
[citadel.git] / citadel / room_ops.c
index 0d90bc3b300ea0eb7bb73dce6565f95e8fd56bdc..c545e4dde2abfcce76da25395fd131c8b4e65581 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * Server functions which perform operations on room objects.
  *
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2015 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 3.
  * GNU General Public License for more details.
  */
 
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
 #include <stdio.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <string.h>
-#include <dirent.h>    /* for cmd_rdir to read contents of the directory */
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <limits.h>
-#include <errno.h>
-#include "citadel.h"
 #include <libcitadel.h>
-#include "server.h"
-#include "database.h"
-#include "config.h"
-#include "room_ops.h"
-#include "sysdep_decls.h"
-#include "support.h"
-#include "msgbase.h"
+
 #include "citserver.h"
-#include "control.h"
-#include "citadel_dirs.h"
-#include "threads.h"
 
 #include "ctdl_module.h"
+#include "config.h"
+#include "control.h"
 #include "user_ops.h"
+#include "room_ops.h"
 
 struct floor *floorcache[MAXFLOORS];
 
@@ -60,7 +32,7 @@ struct floor *floorcache[MAXFLOORS];
 int CtdlDoIHavePermissionToReadMessagesInThisRoom(void) {
        if (    (!(CC->logged_in))
                && (!(CC->internal_pgm))
-               && (!config.c_guest_logins)
+               && (!CtdlGetConfigInt("c_guest_logins"))
        ) {
                return(om_not_logged_in);
        }
@@ -167,7 +139,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
                is_me = 1;
        }
 
-       if ((is_me) && (config.c_guest_logins) && (!CC->logged_in)) {
+       if ((is_me) && (CtdlGetConfigInt("c_guest_logins")) && (!CC->logged_in)) {
                is_guest = 1;
        }
 
@@ -194,7 +166,7 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
        }
 
        /* Force the properties of the Aide room */
-       if (!strcasecmp(roombuf->QRname, config.c_aideroom)) {
+       if (!strcasecmp(roombuf->QRname, CtdlGetConfigStr("c_aideroom"))) {
                if (userbuf->axlevel >= AxAideU) {
                        retval = UA_KNOWN | UA_GOTOALLOWED | UA_POSTALLOWED | UA_DELETEALLOWED | UA_REPLYALLOWED;
                } else {
@@ -367,9 +339,9 @@ void room_sanity_check(struct ctdlroom *qrbuf)
        /* Listing order of 0 is illegal except for base rooms */
        if (qrbuf->QRorder == 0)
                if (!(qrbuf->QRflags & QR_MAILBOX) &&
-                   strncasecmp(qrbuf->QRname, config.c_baseroom, ROOMNAMELEN)
+                   strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)
                    &&
-                   strncasecmp(qrbuf->QRname, config.c_aideroom, ROOMNAMELEN))
+                   strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN))
                        qrbuf->QRorder = 64;
 }
 
@@ -426,7 +398,7 @@ int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
 /*
  * CtdlGetRoomLock()  -  same as getroom() but locks the record (if supported)
  */
-int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name)
+int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name)
 {
        register int retval;
        retval = CtdlGetRoom(qrbuf, room_name);
@@ -804,13 +776,15 @@ int CtdlIsNonEditable(struct ctdlroom *qrbuf)
  * specified room exists and is ok to access.
  */
 void CtdlUserGoto(char *where, int display_result, int transiently,
-               int *retmsgs, int *retnew)
+               int *retmsgs, int *retnew, long *retoldest, long *retnewest)
 {
        struct CitContext *CCC = CC;
        int a;
        int new_messages = 0;
        int old_messages = 0;
        int total_messages = 0;
+       long oldest_message = 0;
+       long newest_message = 0;
        int info = 0;
        int rmailflag;
        int raideflag;
@@ -845,8 +819,8 @@ void CtdlUserGoto(char *where, int display_result, int transiently,
        /* 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.
         */
-       if ((strcasecmp(CCC->room.QRname, config.c_logpages))
-          && (transiently == 0) ) {
+       if ((strcasecmp(CCC->room.QRname, CtdlGetConfigStr("c_logpages"))) && (transiently == 0))
+       {
                vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
                vbuf.v_flags = vbuf.v_flags | V_ACCESS;
        }
@@ -878,6 +852,11 @@ void CtdlUserGoto(char *where, int display_result, int transiently,
                if (msglist[a] > 0L) ++total_messages;
        }
 
+       if (total_messages > 0) {
+               oldest_message = msglist[0];
+               newest_message = msglist[num_msgs - 1];
+       }
+
        num_sets = num_tokens(vbuf.v_seen, ',');
        for (s=0; s<num_sets; ++s) {
                extract_token(setstr, vbuf.v_seen, s, ',', sizeof setstr);
@@ -929,10 +908,11 @@ void CtdlUserGoto(char *where, int display_result, int transiently,
 
        if (retmsgs != NULL) *retmsgs = total_messages;
        if (retnew != NULL) *retnew = new_messages;
-       MSG_syslog(LOG_INFO, "<%s> %d new of %d total messages\n",
-                  CCC->room.QRname,
-                  new_messages, total_messages
-               );
+       if (retoldest != NULL) *retoldest = oldest_message;
+       if (retnewest != NULL) *retnewest = newest_message;
+       MSG_syslog(LOG_INFO, "<%s> %d new of %d total messages, oldest=%ld, newest=%ld\n",
+                  CCC->room.QRname, new_messages, total_messages, oldest_message, newest_message
+       );
 
        CCC->curr_view = (int)vbuf.v_view;
 
@@ -965,7 +945,7 @@ void CtdlUserGoto(char *where, int display_result, int transiently,
  */
 void convert_room_name_macros(char *towhere, size_t maxlen) {
        if (!strcasecmp(towhere, "_BASEROOM_")) {
-               safestrncpy(towhere, config.c_baseroom, maxlen);
+               safestrncpy(towhere, CtdlGetConfigStr("c_baseroom"), maxlen);
        }
        else if (!strcasecmp(towhere, "_MAIL_")) {
                safestrncpy(towhere, MAILROOM, maxlen);
@@ -977,7 +957,7 @@ void convert_room_name_macros(char *towhere, size_t maxlen) {
                safestrncpy(towhere, USERDRAFTROOM, maxlen);
        }
        else if (!strcasecmp(towhere, "_BITBUCKET_")) {
-               safestrncpy(towhere, config.c_twitroom, maxlen);
+               safestrncpy(towhere, CtdlGetConfigStr("c_twitroom"), maxlen);
        }
        else if (!strcasecmp(towhere, "_CALENDAR_")) {
                safestrncpy(towhere, USERCALENDARROOM, maxlen);
@@ -1059,8 +1039,8 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
                }
 
                /* Reject change of floor for baseroom/aideroom */
-               if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN) ||
-                   !strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
+               if (!strncasecmp(old_name, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN) ||
+                   !strncasecmp(old_name, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)) {
                        new_floor = 0;
                }
 
@@ -1075,13 +1055,11 @@ int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) {
                begin_critical_section(S_CONFIG);
        
                /* If baseroom/aideroom name changes, update config */
-               if (!strncasecmp(old_name, config.c_baseroom, ROOMNAMELEN)) {
-                       safestrncpy(config.c_baseroom, new_name, ROOMNAMELEN);
-                       put_config();
+               if (!strncasecmp(old_name, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)) {
+                       CtdlSetConfigStr("c_baseroom", new_name);
                }
-               if (!strncasecmp(old_name, config.c_aideroom, ROOMNAMELEN)) {
-                       safestrncpy(config.c_aideroom, new_name, ROOMNAMELEN);
-                       put_config();
+               if (!strncasecmp(old_name, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)) {
+                       CtdlSetConfigStr("c_aideroom", new_name);
                }
        
                end_critical_section(S_CONFIG);