* New back end function CtdlRenameRoom() which is used to rename a room and/or
authorArt Cancro <ajc@citadel.org>
Sun, 14 Apr 2002 22:11:22 +0000 (22:11 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 14 Apr 2002 22:11:22 +0000 (22:11 +0000)
  move it to a different floor.
* cmd_setr() now uses CtdlRenameRoom() to do part of its work

citadel/ChangeLog
citadel/room_ops.c
citadel/room_ops.h
citadel/server_main.c

index 5b0f4a9c7945c346de0b17881a18c4af9d01e9e4..5de84d1fba062195d6fbb5480a985c2fdd95f01f 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 613c4dfada08e1cfd249f0a0f4d934f8df2621b9..19a60e78d59dad498539439d5abca76228b9f0c2 100644 (file)
@@ -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,
index 573644320018a01a154daecc2f035f16b2085ce8..832a35f65b9be4c0cc86cd7c9c9f4dad60fdfc6c 100644 (file)
@@ -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 */
+};
index c7b73329c1dd59659502e25e9912886beb6e8f20..fb7100cfa155cfe7b99e49e850378a1a021535ff 100644 (file)
@@ -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),