}
-
/*
* Save a message pointer into a specified room
* (Returns 0 for success, nonzero for failure)
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);
}
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);
}
}
/* Return success. */
lprintf(9, "CtdlSaveMsgPointerInRoom() succeeded\n");
+ if (msg != NULL) CtdlFreeMessage(msg);
return (0);
}
/*
- * 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)
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") );
}