stable now but there are GIANT PIECES MISSING
[citadel.git] / citadel / modules / expire / serv_expire.c
index 09e9eab1093fada7ae5418c40d64024448c755b8..ec1e5aec642754925d68ec4a7a10f6889129c64e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * You might also see this module affectionately referred to as TDAP (The Dreaded Auto-Purger).
  *
- * Copyright (c) 1988-2019 by citadel.org (Art Cancro, Wilifried Goesgens, and others)
+ * Copyright (c) 1988-2020 by citadel.org (Art Cancro, Wilifried Goesgens, and others)
  *
  * This program is open source software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as published
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-
-#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 <time.h>
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
@@ -169,7 +158,7 @@ void GatherPurgeMessages(struct ctdlroom *qrbuf, void *data) {
                for (a=0; a<num_msgs; ++a) {
                        delnum = msglist[a];
 
-                       msg = CtdlFetchMessage(delnum, 0, 1); /* dont need body */
+                       msg = CtdlFetchMessage(delnum, 0);      /* don't need body */
                        if (msg != NULL) {
                                xtime = atol(msg->cm_fields[eTimestamp]);
                                CM_Free(msg);
@@ -712,7 +701,7 @@ int PurgeEuidIndexTable(void) {
 
                memcpy(&msgnum, cdbei->ptr, sizeof(long));
 
-               msg = CtdlFetchMessage(msgnum, 0, 1);
+               msg = CtdlFetchMessage(msgnum, 0);
                if (msg != NULL) {
                        CM_Free(msg);   /* it still exists, so do nothing */
                }
@@ -807,71 +796,59 @@ void purge_databases(void)
         */
        now = time(NULL);
        localtime_r(&now, &tm);
-       if (((tm.tm_hour != CtdlGetConfigInt("c_purge_hour")) || ((now - last_purge) < 43200)) && (force_purge_now == 0))
-       {
-                       return;
+       if (((tm.tm_hour != CtdlGetConfigInt("c_purge_hour")) || ((now - last_purge) < 43200)) && (force_purge_now == 0)) {
+               return;
        }
 
        syslog(LOG_INFO, "Auto-purger: starting.");
 
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                retval = PurgeUsers();
                syslog(LOG_NOTICE, "Purged %d users.", retval);
        }
                
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                PurgeMessages();
                syslog(LOG_NOTICE, "Expired %d messages.", messages_purged);
        }
 
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                        retval = PurgeRooms();
                        syslog(LOG_NOTICE, "Expired %d rooms.", retval);
        }
 
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                        retval = PurgeVisits();
                        syslog(LOG_NOTICE, "Purged %d visits.", retval);
        }
 
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                StrBuf *ErrMsg;
-
-               ErrMsg = NewStrBuf ();
+               ErrMsg = NewStrBuf();
                retval = PurgeUseTable(ErrMsg);
                        syslog(LOG_NOTICE, "Purged %d entries from the use table.", retval);
                FreeStrBuf(&ErrMsg);
        }
 
-       if (!server_shutting_down)
-       {
-               retval = PurgeEuidIndexTable();
-               syslog(LOG_NOTICE, "Purged %d entries from the EUID index.", retval);
+       if (!server_shutting_down) {
+                       retval = PurgeEuidIndexTable();
+                       syslog(LOG_NOTICE, "Purged %d entries from the EUID index.", retval);
        }
 
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                retval = PurgeStaleExtAuthAssociations();
                syslog(LOG_NOTICE, "Purged %d stale external auth associations.", retval);
        }
 
-       //if (!server_shutting_down)
-       //{
+       //if (!server_shutting_down) {
        //      FIXME this is where we could do a non-interactive delete of zero-refcount messages
        //}
 
-       if ( (!server_shutting_down) && (CtdlGetConfigInt("c_shrink_db_files") != 0) )
-       {
+       if ( (!server_shutting_down) && (CtdlGetConfigInt("c_shrink_db_files") != 0) ) {
                cdb_compact();                                  // Shrink the DB files on disk
        }
 
-       if (!server_shutting_down)
-       {
+       if (!server_shutting_down) {
                syslog(LOG_INFO, "Auto-purger: finished.");
                last_purge = now;                               // So we don't do it again soon
                force_purge_now = 0;