From 4946f71b9d3dd544a6d7faf2b8a8e4a455206ec8 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 14 Apr 2002 22:11:22 +0000 Subject: [PATCH] * New back end function CtdlRenameRoom() which is used to rename a room and/or move it to a different floor. * cmd_setr() now uses CtdlRenameRoom() to do part of its work --- citadel/ChangeLog | 6 +- citadel/room_ops.c | 191 +++++++++++++++++++++++++++++------------- citadel/room_ops.h | 12 +++ citadel/server_main.c | 2 +- 4 files changed, 153 insertions(+), 58 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 5b0f4a9c7..5de84d1fb 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,9 @@ $Log$ + Revision 591.7 2002/04/14 22:11:22 ajc + * New back end function CtdlRenameRoom() which is used to rename a room and/or + move it to a different floor. + * cmd_setr() now uses CtdlRenameRoom() to do part of its work + Revision 591.6 2002/04/10 03:58:40 ajc * Began work on IMAP RENAME @@ -3591,4 +3596,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 613c4dfad..19a60e78d 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -983,59 +983,164 @@ void cmd_getr(void) { if (CtdlAccessCheck(ac_room_aide)) return; - /******** - if (is_noneditable(&CC->quickroom)) { - cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE); - return; - } - ************/ - getroom(&CC->quickroom, CC->quickroom.QRname); cprintf("%d%c%s|%s|%s|%d|%d|%d\n", - CIT_OK, CtdlCheckExpress(), - CC->quickroom.QRname, - ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""), - ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""), + CIT_OK, + CtdlCheckExpress(), + + ((CC->quickroom.QRflags & QR_MAILBOX) ? + &CC->quickroom.QRname[11] : CC->quickroom.QRname), + + ((CC->quickroom.QRflags & QR_PASSWORDED) ? + CC->quickroom.QRpasswd : ""), + + ((CC->quickroom.QRflags & QR_DIRECTORY) ? + CC->quickroom.QRdirname : ""), + CC->quickroom.QRflags, (int) CC->quickroom.QRfloor, (int) CC->quickroom.QRorder); } +/* + * Back end function to rename a room. + * You can also specify which floor to move the room to, or specify -1 to + * keep the room on the same floor it was on. + * + * This function is unaware of namespaces. If you are renaming a mailbox + * room, you must supply the namespace prefix in both the old and new names! + */ +int CtdlRenameRoom(char *old_name, char *new_name, int new_floor) { + int old_floor = 0; + struct quickroom qrbuf; + struct quickroom qrtmp; + int ret = 0; + struct floor *fl; + struct floor flbuf; + + + lprintf(9, "CtdlRenameRoom(%s, %s, %d)\n", + old_name, new_name, new_floor); + + if (new_floor >= 0) { + fl = cgetfloor(new_floor); + if ((fl->f_flags & F_INUSE) == 0) { + return(crr_invalid_floor); + } + } + + begin_critical_section(S_QUICKROOM); + + if ( (getroom(&qrtmp, new_name) == 0) + && (strcasecmp(new_name, old_name)) ) { + ret = crr_already_exists; + } + + else if (getroom(&qrbuf, old_name) != 0) { + ret = crr_room_not_found; + } + + else if (is_noneditable(&qrbuf)) { + ret = crr_noneditable; + } + + else { + safestrncpy(qrbuf.QRname, new_name, sizeof(qrbuf.QRname)); + old_floor = qrbuf.QRfloor; + if (new_floor < 0) { + new_floor = old_floor; + } + qrbuf.QRfloor = new_floor; + putroom(&qrbuf); + + /* If the room name changed, then there are now two room + * records, so we have to delete the old one. + */ + if (strcasecmp(new_name, old_name)) { + b_deleteroom(old_name); + } + + ret = crr_ok; + } + + end_critical_section(S_QUICKROOM); + + /* Adjust the floor reference counts if necessary */ + if (new_floor != old_floor) { + lgetfloor(&flbuf, old_floor); + --flbuf.f_ref_count; + lputfloor(&flbuf, old_floor); + lgetfloor(&flbuf, CC->quickroom.QRfloor); + ++flbuf.f_ref_count; + lputfloor(&flbuf, CC->quickroom.QRfloor); + } + + /* ...and everybody say "YATTA!" */ + return(ret); +} + + /* * set room parameters (aide or room aide command) */ void cmd_setr(char *args) { char buf[SIZ]; - struct floor *fl; - struct floor flbuf; - char old_name[ROOMNAMELEN]; - int old_floor; int new_order = 0; - int ne = 0; + int r; + int new_floor; + char new_name[ROOMNAMELEN]; if (CtdlAccessCheck(ac_room_aide)) return; - if (is_noneditable(&CC->quickroom)) { - ne = 1; + if (num_parms(args) >= 6) { + new_floor = extract_int(args, 5); + } + else { + new_floor = (-1); /* don't change the floor */ } - /*** - cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE); - return; + /* When is a new name more than just a new name? When the old name + * has a namespace prefix. + */ + if (CC->quickroom.QRflags & QR_MAILBOX) { + sprintf(new_name, "%010ld.", atol(CC->quickroom.QRname) ); + } + else { + strcpy(new_name, ""); } - ***/ + extract(&new_name[strlen(new_name)], args, 0); + r = CtdlRenameRoom(CC->quickroom.QRname, new_name, new_floor); - if (num_parms(args) >= 6) { - fl = cgetfloor(extract_int(args, 5)); - if ((fl->f_flags & F_INUSE) == 0) { - cprintf("%d Invalid floor number.\n", - ERROR + INVALID_FLOOR_OPERATION); - return; - } + if (r == crr_room_not_found) { + cprintf("%d Internal error - room not found?\n", ERROR); + } + else if (r == crr_already_exists) { + cprintf("%d '%s' already exists.\n", + ERROR + ALREADY_EXISTS, new_name); + } + else if (r == crr_noneditable) { + cprintf("%d Cannot edit this room.\n", ERROR); + } + else if (r == crr_invalid_floor) { + cprintf("%d Target floor does not exist.\n", + ERROR + INVALID_FLOOR_OPERATION); + } + else if (r != crr_ok) { + cprintf("%d Error: CtdlRenameRoom() returned %d\n", + ERROR, r); + } + + if (r != crr_ok) { + return; } + + getroom(&CC->quickroom, new_name); + + /* Now we have to do a bunch of other stuff */ + if (num_parms(args) >= 7) { new_order = extract_int(args, 6); if (new_order < 1) @@ -1045,15 +1150,6 @@ void cmd_setr(char *args) } lgetroom(&CC->quickroom, CC->quickroom.QRname); - /* Non-editable base rooms can't be renamed */ - strcpy(old_name, CC->quickroom.QRname); - if (!ne) { - extract(buf, args, 0); - buf[ROOMNAMELEN] = 0; - safestrncpy(CC->quickroom.QRname, buf, - sizeof CC->quickroom.QRname); - } - extract(buf, args, 1); buf[10] = 0; safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd); @@ -1079,27 +1175,10 @@ void cmd_setr(char *args) if (extract_int(args, 4)) { time(&CC->quickroom.QRgen); } - old_floor = CC->quickroom.QRfloor; - if (num_parms(args) >= 6) { - CC->quickroom.QRfloor = extract_int(args, 5); - } + /* Write the room record back to disk */ lputroom(&CC->quickroom); - /* If the room name changed, then there are now two room records, - * so we have to delete the old one. - */ - if (strcasecmp(CC->quickroom.QRname, old_name)) { - b_deleteroom(old_name); - } - /* adjust the floor reference counts */ - lgetfloor(&flbuf, old_floor); - --flbuf.f_ref_count; - lputfloor(&flbuf, old_floor); - lgetfloor(&flbuf, CC->quickroom.QRfloor); - ++flbuf.f_ref_count; - lputfloor(&flbuf, CC->quickroom.QRfloor); - /* create a room directory if necessary */ if (CC->quickroom.QRflags & QR_DIRECTORY) { snprintf(buf, sizeof buf, diff --git a/citadel/room_ops.h b/citadel/room_ops.h index 573644320..832a35f65 100644 --- a/citadel/room_ops.h +++ b/citadel/room_ops.h @@ -52,3 +52,15 @@ void list_roomname(struct quickroom *qrbuf); int is_noneditable(struct quickroom *qrbuf); int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf); int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr); + +int CtdlRenameRoom(char *old_name, char *new_name, int new_floor); +/* + * Possible return values for CtdlRenameRoom() + */ +enum { + crr_ok, /* success */ + crr_room_not_found, /* room not found */ + crr_already_exists, /* new name already exists */ + crr_noneditable, /* cannot edit this room */ + crr_invalid_floor /* target floor does not exist */ +}; diff --git a/citadel/server_main.c b/citadel/server_main.c index c7b73329c..fb7100cfa 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -131,7 +131,7 @@ int main(int argc, char **argv) lprintf(1, "\n" "Citadel/UX messaging server engine v%d.%02d\n" -"Copyright (C) 1987-2001 by the Citadel/UX development team.\n" +"Copyright (C) 1987-2002 by the Citadel/UX development team.\n" "Citadel/UX is released under the terms of the GNU General Public License.\n" "If you paid for this software, someone is ripping you off.\n\n", (REV_LEVEL/100), -- 2.39.2