* serv_expire.c: expire-by-age now calls CtdlFetchMessage() instead of
authorArt Cancro <ajc@citadel.org>
Wed, 28 Jul 1999 03:50:25 +0000 (03:50 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 28 Jul 1999 03:50:25 +0000 (03:50 +0000)
  calling output_message() in MT_DATE mode.
* msgbase.c: removed MT_DATE mode ('twas a sleazy hack)

citadel/ChangeLog
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_expire.c
citadel/server.h

index 2a4f4b39f225ae28b419031cfb42a45ca35e70f9..e59326b4953a2b999b9e91a00c012c45dbdde563 100644 (file)
@@ -1,4 +1,9 @@
 $Log$
+Revision 1.335  1999/07/28 03:50:24  ajc
+* serv_expire.c: expire-by-age now calls CtdlFetchMessage() instead of
+  calling output_message() in MT_DATE mode.
+* msgbase.c: removed MT_DATE mode ('twas a sleazy hack)
+
 Revision 1.334  1999/07/27 22:47:26  ajc
 * Implemented new data type "CtdlMessage" which will eventually be used as
   widely as possible to represent a message in memory.
@@ -1128,4 +1133,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import
-
index 449102910c92ac03abc950870f31dd18a2ddab5e..51e776c33d0875ff4b6510ef9337e5a97ecff1c4 100644 (file)
@@ -483,8 +483,8 @@ void mime_download(char *name, char *filename, char *partnum, char *disp,
  * Load a message from disk into memory.
  * (This will replace a big piece of output_message() eventually)
  *
- * NOTE: Caller is responsible for _recursively_ freeing the returned
- * CtdlMessage data structure!
+ * NOTE: Caller is responsible for freeing the returned CtdlMessage struct
+ *       using the CtdlMessageFree() function.
  */
 struct CtdlMessage *CtdlFetchMessage(long msgnum) {
        struct cdbdata *dmsgtext;
@@ -504,7 +504,7 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum) {
        mptr = dmsgtext->ptr;
 
        /* Parse the three bytes that begin EVERY message on disk.
-        * The first is always 0xFF, the universal start-of-message byte.
+        * The first is always 0xFF, the on-disk magic number.
         * The second is the anonymous/public type byte.
         * The third is the format type byte (vari, fixed, or MIME).
         */
@@ -518,6 +518,7 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum) {
        ret = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage));
        memset(ret, 0, sizeof(struct CtdlMessage));
 
+       ret->cm_magic = CTDLMESSAGE_MAGIC;
        ret->cm_anon_type = *mptr++;            /* Anon type byte */
        ret->cm_format_type = *mptr++;          /* Format type byte */
 
@@ -541,6 +542,24 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum) {
        return(ret);
 }
 
+/*
+ * 'Destructor' for struct CtdlMessage
+ */
+void CtdlFreeMessage(struct CtdlMessage *msg) {
+       int i;
+
+       if (msg == NULL) return;
+       if ((msg->cm_magic) != CTDLMESSAGE_MAGIC) {
+               lprintf(3, "CtdlFreeMessage() -- self-check failed\n");
+               return;
+       }
+
+       for (i=0; i<256; ++i)
+               if (msg->cm_fields[i] != NULL)
+                       phree(msg->cm_fields[i]);
+
+       phree(msg);
+}
 
 
 
@@ -548,7 +567,7 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum) {
  * Get a message off disk.  (return value is the message's timestamp)
  * 
  */
-time_t output_message(char *msgid, int mode, int headers_only)
+void output_message(char *msgid, int mode, int headers_only)
 {
        long msg_num;
        int a;
@@ -556,7 +575,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
        CIT_UBYTE format_type, anon_flag;
        char buf[1024];
        long msg_len;
-       int msg_ok = 0;
+       time_t xtime;
 
        struct cdbdata *dmsgtext;
        char *mptr;
@@ -567,15 +586,13 @@ time_t output_message(char *msgid, int mode, int headers_only)
        char snode[256];
        char lnode[256];
        char mid[256];
-       time_t xtime = 0L;
        /*                                       */
 
        msg_num = atol(msgid);
 
-
-       if ((!(CC->logged_in)) && (!(CC->internal_pgm)) && (mode != MT_DATE)) {
+       if ( (!(CC->logged_in)) && (!(CC->internal_pgm)) ) {
                cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
-               return (xtime);
+               return;
        }
 
        /* FIX ... small security issue
@@ -583,22 +600,21 @@ time_t output_message(char *msgid, int mode, int headers_only)
         * in the current room, and set msg_ok to 1 only if it is.  This
         * functionality is currently missing because I'm in a hurry to replace
         * broken production code with nonbroken pre-beta code.  :(   -- ajc
-        */
-       msg_ok = 1;
-
+        *
        if (!msg_ok) {
-               if (mode != MT_DATE)
-                       cprintf("%d Message %ld is not in this room.\n",
-                               ERROR, msg_num);
-               return (xtime);
+               cprintf("%d Message %ld is not in this room.\n",
+                       ERROR, msg_num);
+               return;
        }
+        */
+
+
        dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
 
        if (dmsgtext == NULL) {
-               if (mode != MT_DATE)
-                       cprintf("%d Can't find message %ld\n",
-                               (ERROR + INTERNAL_ERROR), msg_num);
-               return (xtime);
+               cprintf("%d Can't find message %ld\n",
+                       (ERROR + INTERNAL_ERROR), msg_num);
+               return;
        }
        msg_len = (long) dmsgtext->len;
        mptr = dmsgtext->ptr;
@@ -608,7 +624,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
                cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
                client_write(dmsgtext->ptr, (int) msg_len);
                cdb_free(dmsgtext);
-               return (xtime);
+               return;
        }
        /* Otherwise, we'll start parsing it field by field... */
        ch = *mptr++;
@@ -616,7 +632,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
                cprintf("%d Illegal message format on disk\n",
                        ERROR + INTERNAL_ERROR);
                cdb_free(dmsgtext);
-               return (xtime);
+               return;
        }
        anon_flag = *mptr++;
        format_type = *mptr++;
@@ -651,24 +667,9 @@ time_t output_message(char *msgid, int mode, int headers_only)
                        }
                }
                cdb_free(dmsgtext);
-               return (xtime);
+               return;
        }
-       /* Are we just looking for the message date? */
-       if (mode == MT_DATE)
-               while (ch = *mptr++, (ch != 'M' && ch != 0)) {
-                       buf[0] = 0;
-                       do {
-                               buf[strlen(buf) + 1] = 0;
-                               rch = *mptr++;
-                               buf[strlen(buf)] = rch;
-                       } while (rch > 0);
 
-                       if (ch == 'T') {
-                               xtime = atol(buf);
-                               cdb_free(dmsgtext);
-                               return (xtime);
-                       }
-               }
        /* now for the user-mode message reading loops */
        cprintf("%d Message %ld:\n", LISTING_FOLLOWS, msg_num);
 
@@ -777,7 +778,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
        if (ch == 0) {
                cprintf("text\n*** ?Message truncated\n000\n");
                cdb_free(dmsgtext);
-               return (xtime);
+               return;
        }
        /* do some sort of MIME output */
        if (format_type == 4) {
@@ -787,7 +788,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
                if (mode == MT_MIME) {  /* If MT_MIME then it's parts only */
                        cprintf("000\n");
                        cdb_free(dmsgtext);
-                       return (xtime);
+                       return;
                }
        }
        if (headers_only) {
@@ -799,7 +800,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
                cprintf("mlen=%ld\n", msg_len);
                cprintf("000\n");
                cdb_free(dmsgtext);
-               return (xtime);
+               return;
        }
        /* signify start of msg text */
        if (mode == MT_CITADEL)
@@ -848,7 +849,7 @@ time_t output_message(char *msgid, int mode, int headers_only)
        /* now we're done */
        cprintf("000\n");
        cdb_free(dmsgtext);
-       return (xtime);
+       return;
 }
 
 
index 98341c57c140e7f87e62cf1b6187cbb34c83d14c..c0d5563ec2b634202c0ca693400f2192c83362b3 100644 (file)
@@ -6,7 +6,7 @@ void help_subst (char *strbuf, char *source, char *dest);
 void do_help_subst (char *buffer);
 void memfmout (int width, char *mptr, char subst);
 void output_mime_parts(char *);
-time_t output_message (char *, int, int);
+void output_message (char *, int, int);
 void cmd_msg0 (char *cmdbuf);
 void cmd_msg2 (char *cmdbuf);
 void cmd_msg3 (char *cmdbuf);
@@ -35,3 +35,4 @@ void CtdlForEachMessage(int mode, long ref,
 int CtdlDeleteMessages(char *, long, char *);
 void CtdlWriteObject(char *, char *, char *, int, int, int);
 struct CtdlMessage *CtdlFetchMessage(long msgnum);
+void CtdlFreeMessage(struct CtdlMessage *msg);
index 5bfb0be56970b1cda60cc934ce1ed052c4bbf9c3..721e12b83706bb3a63e782ab034cf4b9e952bbe3 100644 (file)
@@ -113,7 +113,7 @@ void DoPurgeMessages(struct quickroom *qrbuf) {
        struct ExpirePolicy epbuf;
        long delnum;
        time_t xtime, now;
-       char msgid[64];
+       struct CtdlMessage *msg;
        int a;
         struct cdbdata *cdbfr;
        long *msglist = NULL;
@@ -164,8 +164,14 @@ void DoPurgeMessages(struct quickroom *qrbuf) {
        if (epbuf.expire_mode == EXPIRE_AGE) {
                for (a=0; a<num_msgs; ++a) {
                        delnum = msglist[a];
-                       sprintf(msgid, "%ld", delnum);
-                       xtime = output_message(msgid, MT_DATE, 0);
+
+                       msg = CtdlFetchMessage(delnum);
+                       if (msg != NULL) {
+                               xtime = atol(msg->cm_fields['T']);
+                               CtdlFreeMessage(msg);
+                       } else {
+                               xtime = 0L;
+                       }
 
                        if ((xtime > 0L)
                           && (now - xtime > (time_t)(epbuf.expire_value * 86400L))) {
index b3835f9b86f44cc5c86d6214e43fd50c5cfcc1ee..2232fc3ea093901d0dcaeacb1bfa08be8675f59a 100644 (file)
@@ -155,7 +155,6 @@ enum {
  */
 enum {
        MT_CITADEL,             /* Citadel proprietary */
-       MT_DATE,                /* We're only looking for the date */
        MT_RFC822,              /* RFC822 */
        MT_RAW,                 /* IGnet raw format */
        MT_MIME,                /* MIME-formatted message */
@@ -305,7 +304,9 @@ extern struct TheHeap *heap;
 /*
  * New format for a message in memory
  */
+#define        CTDLMESSAGE_MAGIC               0x159d
 struct CtdlMessage {
+       int cm_magic;                   /* Self-check */
        char cm_anon_type;              /* Anonymous or author-visible */
        char cm_format_type;            /* Format type */
        char *cm_fields[256];           /* Data fields */