]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_expire.c
Fixes for Cygwin (see ChangeLog)
[citadel.git] / citadel / serv_expire.c
index 817a8af2f7d71979a8d83070ece6f9b86f524541..e1293d6c44764ba0f85e4ba4f5a5b4a3ba033337 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -35,7 +36,9 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
+#endif
 #include "citadel.h"
 #include "server.h"
 #include <syslog.h>
@@ -95,8 +98,8 @@ extern struct CitContext *ContextList;
 #define MODULE_NAME    "Expire old messages, users, rooms"
 #define MODULE_AUTHOR  "Art Cancro"
 #define MODULE_EMAIL   "ajc@uncnsrd.mt-kisco.ny.us"
-#define MAJOR_VERSION  0
-#define MINOR_VERSION  1
+#define MAJOR_VERSION  1
+#define MINOR_VERSION  0
 
 static struct DLModule_Info info = {
        MODULE_NAME,
@@ -113,7 +116,6 @@ void DoPurgeMessages(struct quickroom *qrbuf) {
        char msgid[64];
        int a;
 
-       messages_purged = 0;
        time(&now);
        GetExpirePolicy(&epbuf, qrbuf);
        
@@ -153,13 +155,14 @@ void DoPurgeMessages(struct quickroom *qrbuf) {
                for (a=0; a<(CC->num_msgs); ++a) {
                        delnum = MessageFromList(a);
                        sprintf(msgid, "%ld", delnum);
-                       xtime = output_message(msgid, MT_DATE, 0, 0);
+                       xtime = output_message(msgid, MT_DATE, 0);
 
                        if ((xtime > 0L)
                           && (now - xtime > (time_t)(epbuf.expire_value * 86400L))) {
+                               lprintf(5, "Expiring message %ld\n", delnum);
                                cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
                                SetMessageInList(a, 0L);
-                               lprintf(5, "Expiring message %ld\n", delnum);
+                               ++messages_purged;
                                }
                        }
                }
@@ -170,12 +173,13 @@ void DoPurgeMessages(struct quickroom *qrbuf) {
 
 void PurgeMessages(void) {
        lprintf(5, "PurgeMessages() called\n");
+       messages_purged = 0;
        ForEachRoom(DoPurgeMessages);
        }
 
 
 void DoPurgeRooms(struct quickroom *qrbuf) {
-       time_t now, age;
+       time_t age, purge_secs;
        struct PurgeList *pptr;
 
        /* Any of these attributes render a room non-purgable */
@@ -185,14 +189,18 @@ void DoPurgeRooms(struct quickroom *qrbuf) {
        if (qrbuf->QRflags & QR_MAILBOX) return;
        if (is_noneditable(qrbuf)) return;
 
+       /* If we don't know the modification date, be safe and don't purge */
+       if (qrbuf->QRmtime <= (time_t)0) return;
+
        /* Otherwise, check the date of last modification */
-       time(&now);
-       age = now - (qrbuf->QRmtime);
+       age = time(NULL) - (qrbuf->QRmtime);
+       purge_secs = (time_t)config.c_roompurge * (time_t)86400;
+       if (purge_secs <= (time_t)0) return;
        lprintf(9, "<%s> is <%ld> seconds old\n", qrbuf->QRname, age);
-       if ( (qrbuf->QRmtime > 0L)
-          && (age > (time_t)(config.c_roompurge * 86400L))) {
+
+       if (age > purge_secs) {
                
-               pptr = (struct PurgeList *) malloc(sizeof(struct PurgeList));
+               pptr = (struct PurgeList *) mallok(sizeof(struct PurgeList));
                pptr->next = RoomPurgeList;
                strcpy(pptr->name, qrbuf->QRname);
                RoomPurgeList = pptr;
@@ -216,7 +224,7 @@ int PurgeRooms(void) {
                        delete_room(&qrbuf);
                        }
                pptr = RoomPurgeList->next;
-               free(RoomPurgeList);
+               phree(RoomPurgeList);
                RoomPurgeList = pptr;
                ++num_rooms_purged;
                }
@@ -270,7 +278,7 @@ void do_user_purge(struct usersupp *us) {
        if (us->timescalled == 0) purge = 1;
 
        if (purge == 1) {
-               pptr = (struct PurgeList *) malloc(sizeof(struct PurgeList));
+               pptr = (struct PurgeList *) mallok(sizeof(struct PurgeList));
                pptr->next = UserPurgeList;
                strcpy(pptr->name, us->fullname);
                UserPurgeList = pptr;
@@ -292,7 +300,7 @@ int PurgeUsers(void) {
        while (UserPurgeList != NULL) {
                purge_user(UserPurgeList->name);
                pptr = UserPurgeList->next;
-               free(UserPurgeList);
+               phree(UserPurgeList);
                UserPurgeList = pptr;
                ++num_users_purged;
                }
@@ -304,7 +312,7 @@ int PurgeUsers(void) {
 void AddValidUser(struct usersupp *usbuf) {
        struct ValidUser *vuptr;
 
-       vuptr = (struct ValidUser *)malloc(sizeof(struct ValidUser));
+       vuptr = (struct ValidUser *)mallok(sizeof(struct ValidUser));
        vuptr->next = ValidUserList;
        vuptr->vu_usernum = usbuf->usernum;
        ValidUserList = vuptr;
@@ -313,7 +321,7 @@ void AddValidUser(struct usersupp *usbuf) {
 void AddValidRoom(struct quickroom *qrbuf) {
        struct ValidRoom *vrptr;
 
-       vrptr = (struct ValidRoom *)malloc(sizeof(struct ValidRoom));
+       vrptr = (struct ValidRoom *)mallok(sizeof(struct ValidRoom));
        vrptr->next = ValidRoomList;
        vrptr->vr_roomnum = qrbuf->QRnumber;
        vrptr->vr_roomgen = qrbuf->QRgen;
@@ -379,7 +387,7 @@ int PurgeVisits(void) {
                /* Put the record on the purge list if it's dead */
                if ((RoomIsValid==0) || (UserIsValid==0)) {
                        vptr = (struct VPurgeList *)
-                               malloc(sizeof(struct VPurgeList));
+                               mallok(sizeof(struct VPurgeList));
                        vptr->next = VisitPurgeList;
                        vptr->vp_roomnum = vbuf.v_roomnum;
                        vptr->vp_roomgen = vbuf.v_roomgen;
@@ -392,14 +400,14 @@ int PurgeVisits(void) {
        /* Free the valid room/gen combination list */
        while (ValidRoomList != NULL) {
                vrptr = ValidRoomList->next;
-               free(ValidRoomList);
+               phree(ValidRoomList);
                ValidRoomList = vrptr;
                }
 
        /* Free the valid user list */
        while (ValidUserList != NULL) {
                vuptr = ValidUserList->next;
-               free(ValidUserList);
+               phree(ValidUserList);
                ValidUserList = vuptr;
                }
 
@@ -411,7 +419,7 @@ int PurgeVisits(void) {
                                VisitPurgeList->vp_usernum);
                cdb_delete(CDB_VISIT, IndexBuf, IndexLen);
                vptr = VisitPurgeList->next;
-               free(VisitPurgeList);
+               phree(VisitPurgeList);
                VisitPurgeList = vptr;
                ++purged;
                }