]> code.citadel.org Git - citadel.git/blobdiff - citadel/rooms.c
*** empty log message ***
[citadel.git] / citadel / rooms.c
index e6e3e8fda4a1d84e338e34837057125637087317..4790107433b6f7bf0a12a306f6849e9f798055fa 100644 (file)
@@ -47,7 +47,6 @@ extern char room_name[];
 extern char temp[];
 extern char tempdir[];
 extern int editor_pid;
-extern char editor_path[];
 extern int screenwidth;
 extern int screenheight;
 extern char fullname[];
@@ -166,52 +165,57 @@ int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
 /*
  * Common code for all room listings
  */
-static void listrms(CtdlIPC *ipc, enum RoomList variety, int floor)
+static void listrms(struct march *listing, int new_only, int floor_only)
 {
-       char buf[SIZ];
-       struct march *listing = NULL;
-       struct march *tmp = NULL;
+       struct march *mptr;
        struct roomlisting *rl = NULL;
        struct roomlisting *rp;
        struct roomlisting *rs;
-       int r;          /* IPC response code */
-
-       /* Ask the server for a room list */
-       r = CtdlIPCKnownRooms(ipc, variety, floor, &listing, buf);
-       if (r / 100 != 1) {
-               return;
-       }
-       while (listing) {
-               rp = malloc(sizeof(struct roomlisting));
-               strncpy(rp->rlname, listing->march_name, ROOMNAMELEN);
-               rp->rlflags = listing->march_flags;
-               rp->rlfloor = listing->march_floor;
-               rp->rlorder = listing->march_order;
-               rp->lnext = NULL;
-               rp->rnext = NULL;
-
-               tmp = listing->next;
-               free(listing);
-               listing = tmp;
-
-               rs = rl;
-               if (rl == NULL) {
-                       rl = rp;
-               } else {
-                       while (rp != NULL) {
-                               if (rordercmp(rp, rs) < 0) {
-                                       if (rs->lnext == NULL) {
-                                               rs->lnext = rp;
-                                               rp = NULL;
-                                       } else {
-                                               rs = rs->lnext;
-                                       }
-                               } else {
-                                       if (rs->rnext == NULL) {
-                                               rs->rnext = rp;
-                                               rp = NULL;
+       int list_it;
+
+       for (mptr = listing; mptr != NULL; mptr = mptr->next) {
+               list_it = 1;
+
+               if ( (new_only == LISTRMS_NEW_ONLY)
+                  && ((mptr->march_access & UA_HASNEWMSGS) == 0)) 
+                       list_it = 0;
+
+               if ( (new_only == LISTRMS_OLD_ONLY)
+                  && ((mptr->march_access & UA_HASNEWMSGS) != 0)) 
+                       list_it = 0;
+
+               if ( (floor_only >= 0)
+                  && (mptr->march_floor != floor_only))
+                       list_it = 0;
+
+               if (list_it) {
+                       rp = malloc(sizeof(struct roomlisting));
+                       strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
+                       rp->rlflags = mptr->march_flags;
+                       rp->rlfloor = mptr->march_floor;
+                       rp->rlorder = mptr->march_order;
+                       rp->lnext = NULL;
+                       rp->rnext = NULL;
+       
+                       rs = rl;
+                       if (rl == NULL) {
+                               rl = rp;
+                       } else {
+                               while (rp != NULL) {
+                                       if (rordercmp(rp, rs) < 0) {
+                                               if (rs->lnext == NULL) {
+                                                       rs->lnext = rp;
+                                                       rp = NULL;
+                                               } else {
+                                                       rs = rs->lnext;
+                                               }
                                        } else {
-                                               rs = rs->rnext;
+                                               if (rs->rnext == NULL) {
+                                                       rs->rnext = rp;
+                                                       rp = NULL;
+                                               } else {
+                                                       rs = rs->rnext;
+                                               }
                                        }
                                }
                        }
@@ -249,16 +253,28 @@ void list_other_floors(void)
 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
 {
        int a;
+       struct march *listing = NULL;
+       struct march *mptr;
+       int r;          /* IPC response code */
+       char buf[SIZ];
+
+
+       /* Ask the server for a room list */
+       r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
+       if (r / 100 != 1) {
+               listing = NULL;
+       }
 
        load_floorlist(ipc);
 
+
        if (kn_floor_mode == 0) {
                color(BRIGHT_CYAN);
                pprintf("\n   Rooms with unread messages:\n");
-               listrms(ipc, SubscribedRoomsWithNewMessages, -1);
+               listrms(listing, LISTRMS_NEW_ONLY, -1);
                color(BRIGHT_CYAN);
                pprintf("\n\n   No unseen messages in:\n");
-               listrms(ipc, SubscribedRoomsWithNoNewMessages, -1);
+               listrms(listing, LISTRMS_OLD_ONLY, -1);
                pprintf("\n");
        }
 
@@ -266,11 +282,11 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
                color(BRIGHT_CYAN);
                pprintf("\n   Rooms with unread messages on %s:\n",
                        floorlist[(int) curr_floor]);
-               listrms(ipc, SubscribedRoomsWithNewMessages, curr_floor);
+               listrms(listing, LISTRMS_NEW_ONLY, curr_floor);
                color(BRIGHT_CYAN);
                pprintf("\n\n   Rooms with no new messages on %s:\n",
                        floorlist[(int) curr_floor]);
-               listrms(ipc, SubscribedRoomsWithNoNewMessages, curr_floor);
+               listrms(listing, LISTRMS_OLD_ONLY, curr_floor);
                color(BRIGHT_CYAN);
                pprintf("\n\n   Other floors:\n");
                list_other_floors();
@@ -283,12 +299,19 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
                                color(BRIGHT_CYAN);
                                pprintf("\n   Rooms on %s:\n",
                                        floorlist[a]);
-                               listrms(ipc, AllAccessibleRooms, a);
+                               listrms(listing, LISTRMS_ALL, a);
                                pprintf("\n");
                        }
                }
        }
 
+       /* Free the room list */
+       while (listing) {
+               mptr = listing->next;
+               free(listing);
+               listing = mptr;
+       };
+
        color(DIM_WHITE);
        IFNEXPERT hit_any_key();
 }
@@ -296,10 +319,30 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
 
 void listzrooms(CtdlIPC *ipc)
 {                              /* list public forgotten rooms */
+       struct march *listing = NULL;
+       struct march *mptr;
+       int r;          /* IPC response code */
+       char buf[SIZ];
+
+
+       /* Ask the server for a room list */
+       r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, 1, &listing, buf);
+       if (r / 100 != 1) {
+               listing = NULL;
+       }
+
        color(BRIGHT_CYAN);
        pprintf("\n   Forgotten public rooms:\n");
-       listrms(ipc, UnsubscribedRooms, -1);
+       listrms(listing, LISTRMS_ALL, -1);
        pprintf("\n");
+
+       /* Free the room list */
+       while (listing) {
+               mptr = listing->next;
+               free(listing);
+               listing = mptr;
+       };
+
        color(DIM_WHITE);
        IFNEXPERT hit_any_key();
 }
@@ -338,6 +381,7 @@ int select_floor(CtdlIPC *ipc, int rfloor)
                        newfloor = (-1);
                        safestrncpy(floorstr, floorlist[rfloor],
                                    sizeof floorstr);
+                       strprompt("Which floor", floorstr, 255);
                        for (a = 0; a < 128; ++a) {
                                if (!strcasecmp
                                    (floorstr, &floorlist[a][0]))
@@ -365,6 +409,12 @@ int select_floor(CtdlIPC *ipc, int rfloor)
                } while (newfloor < 0);
                return (newfloor);
        }
+
+       else {
+               scr_printf("Floor selection bypassed because you have "
+                       "floor mode disabled.\n");
+       }
+
        return (rfloor);
 }
 
@@ -379,7 +429,7 @@ void editthisroom(CtdlIPC *ipc)
        int rbump = 0;
        char raide[USERNAME_SIZE];
        char buf[SIZ];
-       struct quickroom *attr = NULL;
+       struct room *attr = NULL;
        struct ExpirePolicy *eptr = NULL;
        int r;                          /* IPC response code */
 
@@ -409,6 +459,7 @@ void editthisroom(CtdlIPC *ipc)
 
        /* Now interact with the user. */
 
+       strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
        attr->QRfloor = select_floor(ipc, attr->QRfloor);
        attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
        if (attr->QRflags & QR_PRIVATE) {
@@ -443,21 +494,28 @@ void editthisroom(CtdlIPC *ipc)
                rbump = boolprompt("Cause current users to forget room", 0);
        }
 
-       attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
-       attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
-       attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
-       attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
+       attr->QRflags = set_room_attr(ipc, attr->QRflags,
+                                       "Preferred users only", QR_PREFONLY);
+       attr->QRflags = set_room_attr(ipc, attr->QRflags,
+                                       "Read-only room", QR_READONLY);
+       attr->QRflags = set_room_attr(ipc, attr->QRflags,
+                                       "Directory room", QR_DIRECTORY);
+       attr->QRflags = set_room_attr(ipc, attr->QRflags,
+                                       "Permanent room", QR_PERMANENT);
        if (attr->QRflags & QR_DIRECTORY) {
                strprompt("Directory name", attr->QRdirname, 14);
                attr->QRflags =
-                   set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
+                   set_room_attr(ipc, attr->QRflags,
+                                               "Uploading allowed", QR_UPLOAD);
                attr->QRflags =
                    set_room_attr(ipc, attr->QRflags, "Downloading allowed",
                                  QR_DOWNLOAD);
                attr->QRflags =
-                   set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
+                   set_room_attr(ipc, attr->QRflags,
+                                               "Visible directory", QR_VISDIR);
        }
-       attr->QRflags = set_room_attr(ipc, attr->QRflags, "Network shared room", QR_NETWORK);
+       attr->QRflags = set_room_attr(ipc, attr->QRflags,
+                                       "Network shared room", QR_NETWORK);
        attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
                                "Self-service list subscribe/unsubscribe",
                                QR2_SELFLIST);
@@ -542,31 +600,88 @@ void editthisroom(CtdlIPC *ipc)
 
 
 /*
- * un-goto the previous room
+ * un-goto the previous room, or a specified room
  */
+void dotungoto(CtdlIPC *ipc, char *towhere)
+  {
+    /* Find this 'towhere' room in the list ungoto from this room to
+       that at the messagepointer position in that room in our ungoto list.
+       I suppose I could be a real dick and just ungoto that many places
+       in our list. */
+    int found = -1;
+    int lp;
+       char buf[SIZ];
+       struct ctdlipcroom *rret = NULL;        /* ignored */
+       int r;
+
+       if (uglistsize == 0)
+      {
+               scr_printf("No rooms to ungoto.\n");
+               return;
+      }
+       if (towhere == NULL)
+      {
+               scr_printf("Must specify a room to ungoto.\n");
+               return;
+      }
+       if (strlen(towhere) == 0)
+      {
+               scr_printf("Must specify a room to ungoto.\n");
+               return;
+      }
+    for (lp = uglistsize-1; lp >= 0; lp--)
+      {
+        if (strcasecmp(towhere, uglist[lp]) == 0)
+          {
+            found = lp;
+            break;
+          }
+      }
+    if (found == -1)
+      {
+               scr_printf("Room: %s not in ungoto list.\n", towhere);
+       return;
+      }
+
+       r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
+       if (rret) free(rret);   /* ignored */
+       if (r / 100 != 2) {
+               scr_printf("%s\n", buf);
+               return;
+       }
+       r = CtdlIPCSetLastRead(ipc, uglistlsn[found], buf);
+       if (r / 100 != 2) {
+               scr_printf("%s\n", buf);
+       }
+       safestrncpy(buf, uglist[found], sizeof(buf));
+    /* we queue ungoto information here, because we're not really
+       ungotoing, we're really going to a random spot in some arbitrary
+       room list. */
+       dotgoto(ipc, buf, 0, 0);
+  }
+
 void ungoto(CtdlIPC *ipc)
 {
        char buf[SIZ];
+       struct ctdlipcroom *rret = NULL;        /* ignored */
+       int r;
 
        if (uglistsize == 0)
                return;
 
-       snprintf(buf, sizeof buf, "GOTO %s", uglist[uglistsize-1]); 
-       CtdlIPC_putline(ipc, buf);
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] != '2') {
-               scr_printf("%s\n", &buf[4]);
+       r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
+       if (rret) free(rret);   /* ignored */
+       if (r / 100 != 2) {
+               scr_printf("%s\n", buf);
                return;
        }
-       snprintf(buf, sizeof buf, "SLRP %ld", uglistlsn[uglistsize-1]); 
-       CtdlIPC_putline(ipc, buf);
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] != '2') {
-               scr_printf("%s\n", &buf[4]);
+       r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1], buf);
+       if (r / 100 != 2) {
+               scr_printf("%s\n", buf);
        }
-    safestrncpy (buf, uglist[uglistsize-1], sizeof(buf));
-    uglistsize--;
-    free(uglist[uglistsize]);
+       safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
+       uglistsize--;
+       free(uglist[uglistsize]);
        /* Don't queue ungoto info or we end up in a loop */
        dotgoto(ipc, buf, 0, 1);
 }
@@ -700,7 +815,7 @@ void download(CtdlIPC *ipc, int proto)
 
        /* clean up the temporary directory */
        nukedir(tempdir);
-       scr_putc(7);    /* Beep beep! */
+       ctdl_beep();    /* Beep beep! */
 }
 
 
@@ -940,16 +1055,21 @@ void readinfo(CtdlIPC *ipc)
 void whoknows(CtdlIPC *ipc)
 {
        char buf[SIZ];
-       CtdlIPC_putline(ipc, "WHOK");
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] != '1') {
-               pprintf("%s\n", &buf[4]);
+       char *listing = NULL;
+       int r;
+
+       r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
+       if (r / 100 != 1) {
+               pprintf("%s\n", buf);
                return;
        }
-       while (CtdlIPC_getline(ipc, buf), strncmp(buf, "000", 3)) {
+       while (strlen(listing) > 0) {
+               extract_token(buf, listing, 0, '\n');
+               remove_token(listing, 0, '\n');
                if (sigcaught == 0)
                        pprintf("%s\n", buf);
        }
+       free(listing);
 }
 
 
@@ -960,8 +1080,7 @@ void do_edit(CtdlIPC *ipc,
        char cmd[SIZ];
        int b, cksum, editor_exit;
 
-
-       if (strlen(editor_path) == 0) {
+       if (strlen(editor_paths[0]) == 0) {
                scr_printf("Do you wish to re-enter %s? ", desc);
                if (yesno() == 0)
                        return;
@@ -977,7 +1096,7 @@ void do_edit(CtdlIPC *ipc,
                return;
        }
 
-       if (strlen(editor_path) > 0) {
+       if (strlen(editor_paths[0]) > 0) {
                CtdlIPC_putline(ipc, read_cmd);
                CtdlIPC_getline(ipc, cmd);
                if (cmd[0] == '1') {
@@ -991,26 +1110,26 @@ void do_edit(CtdlIPC *ipc,
 
        cksum = file_checksum(temp);
 
-       if (strlen(editor_path) > 0) {
+       if (strlen(editor_paths[0]) > 0) {
                char tmp[SIZ];
 
                snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
                putenv(tmp);
+               screen_reset();
+               sttybbs(SB_RESTORE);
                editor_pid = fork();
                if (editor_pid == 0) {
                        chmod(temp, 0600);
-                       screen_reset();
-                       sttybbs(SB_RESTORE);
-                       execlp(editor_path, editor_path, temp, NULL);
+                       execlp(editor_paths[0], editor_paths[0], temp, NULL);
                        exit(1);
                }
                if (editor_pid > 0)
                        do {
                                editor_exit = 0;
-                               b = wait(&editor_exit);
+                               b = ka_wait(&editor_exit);
                        } while ((b != editor_pid) && (b >= 0));
                editor_pid = (-1);
-               scr_printf("Executed %s\n", editor_path);
+               scr_printf("Executed %s\n", editor_paths[0]);
                sttybbs(0);
                screen_set();
        } else {
@@ -1070,7 +1189,7 @@ void create_floor(CtdlIPC *ipc)
        load_floorlist(ipc);
 
        r = CtdlIPCCreateFloor(ipc, 0, "", buf);
-       if (r / 100 != 2) {
+       if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
                scr_printf("%s\n", buf);
                return;
        }