* Finished up the flags and replication checks in CtdlSaveMsgPointerInRoom().
authorArt Cancro <ajc@citadel.org>
Thu, 21 Oct 1999 00:50:15 +0000 (00:50 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 21 Oct 1999 00:50:15 +0000 (00:50 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/msgbase.h

index ba2e7d2ac96125cff1f06bd629eec6f8a9941b60..a286e807a7effb2b468ba9f29721aaae036cb246 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.391  1999/10/21 00:50:14  ajc
+* Finished up the flags and replication checks in CtdlSaveMsgPointerInRoom().
+
 Revision 1.390  1999/10/20 16:46:27  ajc
 * More code shuffle.  Added some flags to CtdlSaveMessagePointerInRoom() and
   enabled the MOVE command to also do a "copy" operation (actually just
@@ -1337,3 +1340,4 @@ 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 5ea0841e8decf01c5f9e4374f5024010ce56011b..a0c0a857e97a6b9b87dcea211ef56add76274215 100644 (file)
@@ -1100,7 +1100,7 @@ void cmd_opna(char *cmdbuf)
  */
 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
        int i;
-       struct quickroom qrbuf;
+       char hold_rm[ROOMNAMELEN];
         struct cdbdata *cdbfr;
         int num_msgs;
         long *msglist;
@@ -1110,6 +1110,8 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
        lprintf(9, "CtdlSaveMsgPointerInRoom(%s, %ld, %d)\n",
                roomname, msgid, flags);
 
+       strcpy(hold_rm, CC->quickroom.QRname);
+
        /* We may need to check to see if this message is real */
        if (  (flags & SM_VERIFY_GOODNESS)
           || (flags & SM_DO_REPL_CHECK)
@@ -1118,13 +1120,15 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
                if (msg == NULL) return(ERROR + ILLEGAL_VALUE);
        }
 
-       if (lgetroom(&qrbuf, roomname) != 0) {
+       if (lgetroom(&CC->quickroom,
+          ((roomname != NULL) ? roomname : CC->quickroom.QRname) )
+          != 0) {
                lprintf(9, "No such room <%s>\n", roomname);
                if (msg != NULL) CtdlFreeMessage(msg);
                return(ERROR + ROOM_NOT_FOUND);
        }
 
-        cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long));
+        cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
         if (cdbfr == NULL) {
                 msglist = NULL;
                 num_msgs = 0;
@@ -1144,12 +1148,24 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
         */
         if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
                if (msglist[i] == msgid) {
-                       lputroom(&qrbuf);       /* unlock the room */
+                       lputroom(&CC->quickroom);       /* unlock the room */
+                       getroom(&CC->quickroom, hold_rm);
                        if (msg != NULL) CtdlFreeMessage(msg);
                        return(ERROR + ALREADY_EXISTS);
                }
        }
 
+       /* Perform replication checks if necessary */
+       if ( (flags & SM_DO_REPL_CHECK) && (msg != NULL) ) {
+               if (ReplicationChecks(msg) != 0) {
+                       lputroom(&CC->quickroom);       /* unlock the room */
+                       getroom(&CC->quickroom, hold_rm);
+                       if (msg != NULL) CtdlFreeMessage(msg);
+                       lprintf(9, "Did replication, and newer exists\n");
+                       return(0);
+               }
+       }
+
         /* Now add the new message */
         ++num_msgs;
         msglist = reallok(msglist,
@@ -1167,15 +1183,16 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
         highest_msg = msglist[num_msgs - 1];
 
         /* Write it back to disk. */
-        cdb_store(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long),
+        cdb_store(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long),
                   msglist, num_msgs * sizeof(long));
 
         /* Free up the memory we used. */
         phree(msglist);
 
        /* Update the highest-message pointer and unlock the room. */
-       qrbuf.QRhighest = highest_msg;
-       lputroom(&qrbuf);
+       CC->quickroom.QRhighest = highest_msg;
+       lputroom(&CC->quickroom);
+       getroom(&CC->quickroom, hold_rm);
 
        /* Bump the reference count for this message. */
        AdjRefCount(msgid, +1);
@@ -2062,7 +2079,8 @@ void cmd_move(char *args)
                return;
        }
 
-       err = CtdlSaveMsgPointerInRoom(targ, num, SM_VERIFY_GOODNESS);
+       err = CtdlSaveMsgPointerInRoom(targ, num,
+               (SM_VERIFY_GOODNESS | SM_DO_REPL_CHECK) );
        if (err != 0) {
                cprintf("%d Cannot store message in %s: error %d\n",
                        err, targ, err);
index 61638893e586c6775364eb2a5ab5b1712a05508c..56e5e424aed9e173c2bb37b9fdbc582d02137d8f 100644 (file)
@@ -68,3 +68,4 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum);
 void CtdlFreeMessage(struct CtdlMessage *msg);
 void serialize_message(struct ser_ret *, struct CtdlMessage *);
 int is_valid_message(struct CtdlMessage *);
+int ReplicationChecks(struct CtdlMessage *);