Moved the actual work done in cmd_msgs() into a new API function
authorArt Cancro <ajc@citadel.org>
Wed, 21 Jul 1999 02:18:32 +0000 (02:18 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 21 Jul 1999 02:18:32 +0000 (02:18 +0000)
          called CtdlForEachMessage() which is supplied a callback function.

citadel/ChangeLog
citadel/msgbase.c
citadel/msgbase.h

index e396211a7e474506102c459721da267717c14a9d..552226aaf6980eeb6f07e5dd48d9d89bd135ffcf 100644 (file)
@@ -1,3 +1,7 @@
+Tue Jul 20 22:14:54 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * Moved the actual work done in cmd_msgs() into a new API function
+         called CtdlForEachMessage() which is supplied a callback function.
+
 Mon Jul 19 23:24:18 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Keep the (unqualified) content-type in the SuppMsgInfo record.  We'll
          be using this shortly to search rooms for specific object types.
index 420f24ddb19d457b2cdb0f1a003b1e107caf09ec..a53fc1e72462515944c56241a233e9e7298c9f69 100644 (file)
@@ -181,71 +181,88 @@ void get_mm(void)
        fclose(fp);
 }
 
+
+
+void simple_listing(long msgnum) {
+       cprintf("%ld\n", msgnum);
+}
+
+
+/*
+ * API function to perform an operation for each qualifying message in the
+ * current room.
+ */
+void CtdlForEachMessage(int mode, long ref,
+                       void (*CallBack) (long msgnum) ) {
+
+       int a;
+       struct visit vbuf;
+
+       get_mm();
+       get_msglist(&CC->quickroom);
+       getuser(&CC->usersupp, CC->curr_user);
+       CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
+
+       if (CC->num_msgs != 0) for (a = 0; a < (CC->num_msgs); ++a) {
+               if ((MessageFromList(a) >= 0)
+                   && (
+
+                              (mode == MSGS_ALL)
+                              || ((mode == MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
+                              || ((mode == MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
+                              || ((mode == MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
+                           && (CC->usersupp.flags & US_LASTOLD))
+                              || ((mode == MSGS_LAST) && (a >= (CC->num_msgs - ref)))
+                   || ((mode == MSGS_FIRST) && (a < ref))
+                              || ((mode == MSGS_GT) && (MessageFromList(a) > ref))
+                   )
+                   ) {
+                       CallBack(MessageFromList(a));
+               }
+       }
+}
+
+
+
 /*
  * cmd_msgs()  -  get list of message #'s in this room
+ *                implements the MSGS server command using CtdlForEachMessage()
  */
 void cmd_msgs(char *cmdbuf)
 {
-       int a = 0;
        int mode = 0;
        char which[256];
-       int cm_howmany = 0;
-       long cm_gt = 0L;
-       struct visit vbuf;
+       int cm_ref = 0;
 
        extract(which, cmdbuf, 0);
+       cm_ref = extract_int(cmdbuf, 1);
 
        mode = MSGS_ALL;
        strcat(which, "   ");
        if (!strncasecmp(which, "OLD", 3))
                mode = MSGS_OLD;
-       if (!strncasecmp(which, "NEW", 3))
+       else if (!strncasecmp(which, "NEW", 3))
                mode = MSGS_NEW;
-       if (!strncasecmp(which, "FIRST", 5)) {
+       else if (!strncasecmp(which, "FIRST", 5))
                mode = MSGS_FIRST;
-               cm_howmany = extract_int(cmdbuf, 1);
-       }
-       if (!strncasecmp(which, "LAST", 4)) {
+       else if (!strncasecmp(which, "LAST", 4))
                mode = MSGS_LAST;
-               cm_howmany = extract_int(cmdbuf, 1);
-       }
-       if (!strncasecmp(which, "GT", 2)) {
+       else if (!strncasecmp(which, "GT", 2))
                mode = MSGS_GT;
-               cm_gt = extract_long(cmdbuf, 1);
-       }
+
        if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
                cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
                return;
        }
-       get_mm();
-       get_msglist(&CC->quickroom);
-       getuser(&CC->usersupp, CC->curr_user);
-       CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
 
        cprintf("%d Message list...\n", LISTING_FOLLOWS);
-       if (CC->num_msgs != 0) {
-               for (a = 0; a < (CC->num_msgs); ++a)
-                       if ((MessageFromList(a) >= 0)
-                           && (
-
-                                      (mode == MSGS_ALL)
-                                      || ((mode == MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
-                                      || ((mode == MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
-                                      || ((mode == MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
-                                   && (CC->usersupp.flags & US_LASTOLD))
-                                      || ((mode == MSGS_LAST) && (a >= (CC->num_msgs - cm_howmany)))
-                           || ((mode == MSGS_FIRST) && (a < cm_howmany))
-                                      || ((mode == MSGS_GT) && (MessageFromList(a) > cm_gt))
-                           )
-                           ) {
-                               cprintf("%ld\n", MessageFromList(a));
-                       }
-       }
+       CtdlForEachMessage(mode, cm_ref, simple_listing);
        cprintf("000\n");
 }
 
 
 
+
 /* 
  * help_subst()  -  support routine for help file viewer
  */
index 40bdab65b16d4055b5b2b0aac0374eacdba7f99c..c2a951657286cf92ea53c184117b94be57a40f66 100644 (file)
@@ -28,3 +28,7 @@ void cmd_move (char *args);
 void GetSuppMsgInfo(struct SuppMsgInfo *, long);
 void PutSuppMsgInfo(struct SuppMsgInfo *);
 void AdjRefCount(long, int);
+void simple_listing(long);
+void CtdlForEachMessage(int mode, long ref,
+                        void (*CallBack) (long msgnum) );