* More code shuffle. Added some flags to CtdlSaveMessagePointerInRoom() and
authorArt Cancro <ajc@citadel.org>
Wed, 20 Oct 1999 16:46:28 +0000 (16:46 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 20 Oct 1999 16:46:28 +0000 (16:46 +0000)
  enabled the MOVE command to also do a "copy" operation (actually just
  creates a second link and bumps the ref count).  Implemented "<C>opy" in
  the client.

citadel/ChangeLog
citadel/messages.c
citadel/msgbase.c
citadel/msgbase.h
citadel/techdoc/session.txt

index 14e2a1cc42a662aa88bfe2a93e415430a1fd6903..ba2e7d2ac96125cff1f06bd629eec6f8a9941b60 100644 (file)
@@ -1,4 +1,10 @@
 $Log$
+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
+  creates a second link and bumps the ref count).  Implemented "<C>opy" in
+  the client.
+
 Revision 1.389  1999/10/20 16:07:48  ajc
 * Wholist fixes for users who are in chat mode
 
@@ -1331,4 +1337,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 3b0cc34d1965961807eabc6c13dcbde29d725e59..e8b1d208c04ec86f840f38e2d92ea27b95355a9f 100644 (file)
@@ -1065,7 +1065,7 @@ RMSGREAD: fflush(stdout);
 /* space key same as <N> */    if (e==32) e='n';
 /* del/move for aides only */  if ((!is_room_aide)
                                    &&((room_flags&QR_MAILBOX)==0)) {
-                                       if ((e=='d')||(e=='m')) e=0;
+                                       if ((e=='d')||(e=='m')||(e=='c')) e=0;
                                        }
 /* print only if available */  if ((e=='p')&&(strlen(printcmd)==0)) e=0;
 /* can't reply in public rms */        if ((e=='r')&&(is_mail!=1)) e=0;
@@ -1075,12 +1075,13 @@ RMSGREAD:       fflush(stdout);
                                        &&(e!='d')&&(e!='m')&&(e!='p')
                                        &&(e!='q')&&(e!='b')&&(e!='h')
                                        &&(e!='r')&&(e!='f')&&(e!='?')
-                                       &&(e!='u'));
+                                       &&(e!='u')&&(e!='c'));
                        switch(e) {
                                case 's':       printf("Stop\r");       break;
                                case 'a':       printf("Again\r");      break;
                                case 'd':       printf("Delete\r");     break;
                                case 'm':       printf("Move\r");       break;
+                               case 'c':       printf("Copy\r");       break;
                                case 'n':       printf("Next\r");       break;
                                case 'p':       printf("Print\r");      break;
                                case 'q':       printf("Quote\r");      break;
@@ -1108,6 +1109,7 @@ RMSGREAD: fflush(stdout);
                                    ||(room_flags&QR_MAILBOX)) {
                                        printf(" D  Delete this message\n");
                                        printf(" M  Move message to another room\n");
+                                       printf(" C  Copy message to another room\n");
                                        }
                                if (strlen(printcmd)>0)
                                        printf(" P  Print this message\n");
@@ -1137,11 +1139,14 @@ RMSGREAD:       fflush(stdout);
                   case 'a':    goto RAGAIN;
                   case 'b':    a=a-(rdir*2);
                                break;
-                  case 'm':    newprompt("Enter target room: ",
+                  case 'm':
+                  case 'c':
+                               newprompt("Enter target room: ",
                                        targ,ROOMNAMELEN-1);
                                if (strlen(targ)>0) {
-                                       sprintf(cmd,"MOVE %ld|%s",
-                                               msg_arr[a],targ);
+                                       sprintf(cmd,"MOVE %ld|%s|%d",
+                                               msg_arr[a],targ,
+                                               (e=='c' ? 1 : 0) );
                                        serv_puts(cmd);
                                        serv_gets(cmd);
                                        printf("%s\n",&cmd[4]);
index ffe22b771cc2dc84593f2944df1571f2cfda2c5b..5ea0841e8decf01c5f9e4374f5024010ce56011b 100644 (file)
@@ -1094,7 +1094,6 @@ void cmd_opna(char *cmdbuf)
 }                      
 
 
-
 /*
  * Save a message pointer into a specified room
  * (Returns 0 for success, nonzero for failure)
@@ -1106,12 +1105,22 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
         int num_msgs;
         long *msglist;
         long highest_msg = 0L;
+       struct CtdlMessage *msg = NULL;
 
        lprintf(9, "CtdlSaveMsgPointerInRoom(%s, %ld, %d)\n",
                roomname, msgid, flags);
 
+       /* We may need to check to see if this message is real */
+       if (  (flags & SM_VERIFY_GOODNESS)
+          || (flags & SM_DO_REPL_CHECK)
+          ) {
+               msg = CtdlFetchMessage(msgid);
+               if (msg == NULL) return(ERROR + ILLEGAL_VALUE);
+       }
+
        if (lgetroom(&qrbuf, roomname) != 0) {
                lprintf(9, "No such room <%s>\n", roomname);
+               if (msg != NULL) CtdlFreeMessage(msg);
                return(ERROR + ROOM_NOT_FOUND);
        }
 
@@ -1136,6 +1145,7 @@ 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 */
+                       if (msg != NULL) CtdlFreeMessage(msg);
                        return(ERROR + ALREADY_EXISTS);
                }
        }
@@ -1172,6 +1182,7 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) {
 
        /* Return success. */
        lprintf(9, "CtdlSaveMsgPointerInRoom() succeeded\n");
+       if (msg != NULL) CtdlFreeMessage(msg);
         return (0);
 }
 
@@ -2024,18 +2035,19 @@ void cmd_dele(char *delstr)
 
 
 /*
- * move a message to another room
+ * move or copy a message to another room
  */
 void cmd_move(char *args)
 {
        long num;
        char targ[32];
        struct quickroom qtemp;
-       int foundit;
        int err;
+       int is_copy = 0;
 
        num = extract_long(args, 0);
        extract(targ, args, 1);
+       is_copy = extract_int(args, 2);
 
        getuser(&CC->usersupp, CC->curr_user);
        if ((CC->usersupp.axlevel < 6)
@@ -2050,30 +2062,19 @@ void cmd_move(char *args)
                return;
        }
 
-       /* Temporarily bump the reference count to avoid having the message
-        * deleted while it's in transit.
-        */
-       AdjRefCount(num, 1);
-
-       /* yank the message out of the current room... */
-       foundit = CtdlDeleteMessages(CC->quickroom.QRname, num, NULL);
-
-       if (foundit) {
-               /* put the message into the target room */
-               if (err = CtdlSaveMsgPointerInRoom(targ, num, 0), (err !=0) ) {
-                       cprintf("%d Could not save message %ld in %s.\n",
-                               err, num, targ);
-               }
-               else {
-                       cprintf("%d Message moved.\n", OK);
-               }
-       }
-       else {
-               cprintf("%d No such message.\n", ERROR);
+       err = CtdlSaveMsgPointerInRoom(targ, num, SM_VERIFY_GOODNESS);
+       if (err != 0) {
+               cprintf("%d Cannot store message in %s: error %d\n",
+                       err, targ, err);
+               return;
        }
 
-       /* Fix the reference count. */
-       AdjRefCount(num, (-1)); 
+       /* Now delete the message from the source room,
+        * if this is a 'move' rather than a 'copy' operation.
+        */
+       if (is_copy == 0) CtdlDeleteMessages(CC->quickroom.QRname, num, NULL);
+
+       cprintf("%d Message %s.\n", OK, (is_copy ? "copied" : "moved") );
 }
 
 
index 511f440f912844afcd46e413236a61c0ebc2a90e..61638893e586c6775364eb2a5ab5b1712a05508c 100644 (file)
@@ -9,6 +9,12 @@
 #define MSGS_LAST       4
 #define MSGS_GT         5
 
+/*
+ * Flags which may be passed to CtdlSaveMsgPointerInRoom()
+ */
+#define SM_VERIFY_GOODNESS     1       /* Verify this is a real msg number */
+#define SM_DO_REPL_CHECK       2       /* Perform replication checks */
+
 
 struct ma_info {
        char prefix[256];       /* Prefix for a multipart/alternative */
index dcc7337cfa553022387e3c6f04835abb635a9cb5..bd94c8527e4ebaaba0201aec3ba14c9d2aadf214 100644 (file)
@@ -740,9 +740,12 @@ which will tell the client whether the file needs to be read (see GOTO above).
  Delete a message from the current room.  The one argument that should be
 passed to this command is the message number of the message to be deleted.
 The return value will be OK if the message was deleted, or an ERROR code.
+If the delete is successful, the message's reference count is decremented, and
+if the reference count reaches zero, the message is removed from the message
+base.
 
 
- MOVE   (MOVE a message to a different room)
+ MOVE   (MOVE or copy a message to a different room)
  
  Move a message to a different room.  The two arguments that should be passed
 to this command are the message number of the message to be deleted, and the
@@ -751,6 +754,13 @@ deleted from the current room and moved to the target room.  An ERROR code
 usually means that either the user does not have permission to perform this
 operation, or that the target room does not exist.
  
+ In Citadel/UX 5.55 and above, a third argument may be specified: 0 or 1 to
+designate whether the message should be moved (0) or copied (1) to the target
+room.  In the case of a "copy" operation, the message's reference count is
+incremented, and a pointer to the message will exist in both the source *and*
+target rooms.  In the case of a "move" operation, the message pointer is
+deleted from the source room and the reference count remains the same.
 
  KILL   (KILL current room)