From b0d466c64b70ac95441dfe00262dd5c022fe48dd Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 21 Jul 1999 02:18:32 +0000 Subject: [PATCH] Moved the actual work done in cmd_msgs() into a new API function called CtdlForEachMessage() which is supplied a callback function. --- citadel/ChangeLog | 4 +++ citadel/msgbase.c | 89 ++++++++++++++++++++++++++++------------------- citadel/msgbase.h | 4 +++ 3 files changed, 61 insertions(+), 36 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index e396211a7..552226aaf 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,7 @@ +Tue Jul 20 22:14:54 EDT 1999 Art Cancro + * 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 * Keep the (unqualified) content-type in the SuppMsgInfo record. We'll be using this shortly to search rooms for specific object types. diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 420f24ddb..a53fc1e72 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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 */ diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 40bdab65b..c2a951657 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -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) ); + -- 2.30.2