From: Art Cancro Date: Thu, 15 Oct 1998 23:29:08 +0000 (+0000) Subject: * msgbase.c: reimplemented cmd_move() X-Git-Tag: v7.86~8262 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=c374d75226ed7d7150aa5ad83227e3e2e3e7fbb1;p=citadel.git * msgbase.c: reimplemented cmd_move() room_ops.c: wrote AddMessageToRoom() which is used for both entering and moving messages. --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 778e6ee40..3bd2c2e2a 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,6 +1,10 @@ +Thu Oct 15 19:27:32 EDT 1998 Art Cancro + * msgbase.c: reimplemented cmd_move() + room_ops.c: wrote AddMessageToRoom() which is used for both entering + and moving messages. + Wed Oct 14 22:41:16 EDT 1998 Art Cancro * Misc code cleanup - * Initial work on new implementation of move_message() 1998-10-13 Nathan Bryant * configure.in: don't check for -lcrypt unless autologin is enabled diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 4a6a1a735..9b825fbb2 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -743,21 +743,9 @@ void save_message(char *mtmp, /* file containing proper message */ /* read in the quickroom record, obtaining a lock... */ lgetroom(&CC->quickroom, actual_rm); - get_msglist(&CC->quickroom); - - /* FIX here's where we have to handle message expiry!! */ - - /* Now add the new message */ - CC->num_msgs = CC->num_msgs + 1; - CC->msglist = realloc(CC->msglist, - ((CC->num_msgs) * sizeof(long)) ); - if (CC->msglist == NULL) { - lprintf(3, "ERROR: can't realloc message list!\n"); - } - SetMessageInList(CC->num_msgs - 1, newmsgid); - /* Write it back to disk. */ - put_msglist(&CC->quickroom); + /* Add the message pointer to the room */ + AddMessageToRoom(&CC->quickroom, newmsgid); /* update quickroom */ CC->quickroom.QRhighest = newmsgid; @@ -1192,13 +1180,8 @@ void cmd_move(char *args) /* put the message into the target room */ lgetroom(&qtemp, targ); - get_msglist(&qtemp); - CC->num_msgs = CC->num_msgs + 1; - CC->msglist = realloc(CC->msglist, (CC->num_msgs * sizeof(long)) ); - SetMessageInList(CC->num_msgs - 1, num); - CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs); - put_msglist(&qtemp); + AddMessageToRoom(&qtemp, num); lputroom(&qtemp, targ); - cprintf("%d I think this worked, FIX check to make sure\n", OK); + cprintf("%d Message moved.\n", OK); } diff --git a/citadel/room_ops.c b/citadel/room_ops.c index b412c54b9..241d15876 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -259,15 +259,23 @@ void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) { /* - * get_msglist() - retrieve room message pointers + * Create a database key for storage of message lists */ -void get_msglist(struct quickroom *whichroom) { - struct cdbdata *cdbfr; - char dbkey[256]; +void msglist_key(char *dbkey, struct quickroom *whichroom) { int a; sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen); for (a=0; amsglist != NULL) { free(CC->msglist); @@ -276,7 +284,6 @@ void get_msglist(struct quickroom *whichroom) { CC->num_msgs = 0; cdbfr = cdb_fetch(CDB_MSGLISTS, dbkey, strlen(dbkey)); - if (cdbfr == NULL) { return; } @@ -293,11 +300,8 @@ void get_msglist(struct quickroom *whichroom) { */ void put_msglist(struct quickroom *whichroom) { char dbkey[256]; - int a; - - sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen); - for (a=0; amsglist, CC->num_msgs * sizeof(long)); } @@ -308,15 +312,57 @@ void put_msglist(struct quickroom *whichroom) { */ void delete_msglist(struct quickroom *whichroom) { char dbkey[256]; - int a; - - sprintf(dbkey, "%s%ld", whichroom->QRname, whichroom->QRgen); - for (a=0; alen); + num_msgs = cdbfr->len / sizeof(long); + memcpy(msglist, cdbfr->ptr, cdbfr->len); + cdb_free(cdbfr); + } + + /* Now add the new message */ + ++num_msgs; + msglist = realloc(msglist, + (num_msgs * sizeof(long)) ); + + if (msglist == NULL) { + lprintf(3, "ERROR: can't realloc message list!\n"); + } + + msglist[num_msgs - 1] = newmsgid; + + /* Write it back to disk. */ + cdb_store(CDB_MSGLISTS, dbkey, strlen(dbkey), + msglist, num_msgs * sizeof(long)); + + /* And finally, free up the memory we used. */ + free(msglist); + } + + /* * MessageFromList() - get a message number from the list currently in memory */ diff --git a/citadel/room_ops.h b/citadel/room_ops.h index 6caffbb33..77aac6828 100644 --- a/citadel/room_ops.h +++ b/citadel/room_ops.h @@ -14,6 +14,7 @@ void putfloor (struct floor *flbuf, int floor_num); void lputfloor (struct floor *flbuf, int floor_num); void get_msglist (struct quickroom *whichroom); void put_msglist (struct quickroom *whichroom); +void AddMessageToRoom(struct quickroom *whichroom, long newmsgid); long int MessageFromList (int whichpos); void SetMessageInList (int whichpos, long int newmsgnum); int sort_msglist (long int *listptrs, int oldcount);