5 * Client-side functions which perform room operations
17 #include <sys/types.h>
23 #include "citadel_ipc.h"
24 #include "citadel_decls.h"
34 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
37 void sttybbs(int cmd);
38 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
39 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
40 int pattern(char *search, char *patn);
41 int file_checksum(char *filename);
42 int nukedir(char *dirname);
44 extern unsigned room_flags;
45 extern char room_name[];
47 extern char tempdir[];
48 extern int editor_pid;
49 extern int screenwidth;
50 extern int screenheight;
51 extern char fullname[];
52 extern char sigcaught;
53 extern char floor_mode;
54 extern char curr_floor;
59 extern char *uglist[];
60 extern long uglistlsn[];
61 extern int uglistsize;
63 extern char floorlist[128][SIZ];
66 void load_floorlist(CtdlIPC *ipc)
71 int r; /* IPC response code */
73 for (a = 0; a < 128; ++a)
76 r = CtdlIPCFloorListing(ipc, &listing, buf);
78 strcpy(floorlist[0], "Main Floor");
81 while (*listing && strlen(listing)) {
82 extract_token(buf, listing, 0, '\n');
83 remove_token(listing, 0, '\n');
84 extract(floorlist[extract_int(buf, 0)], buf, 1);
90 void room_tree_list(struct ctdlroomlisting *rp)
93 char rmname[ROOMNAMELEN];
101 if (rp->lnext != NULL) {
102 room_tree_list(rp->lnext);
105 if (sigcaught == 0) {
106 strcpy(rmname, rp->rlname);
108 if ((c + strlen(rmname) + 4) > screenwidth) {
110 /* line break, check the paginator */
114 if (f & QR_MAILBOX) {
115 color(BRIGHT_YELLOW);
116 } else if (f & QR_PRIVATE) {
121 pprintf("%s", rmname);
122 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
124 else if (f & QR_DIRECTORY)
126 else if (f & QR_NETWORK)
130 c = c + strlen(rmname) + 3;
133 if (rp->rnext != NULL) {
134 room_tree_list(rp->rnext);
142 * Room ordering stuff (compare first by floor, then by order)
144 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
146 if ((r1 == NULL) && (r2 == NULL))
152 if (r1->rlfloor < r2->rlfloor)
154 if (r1->rlfloor > r2->rlfloor)
156 if (r1->rlorder < r2->rlorder)
158 if (r1->rlorder > r2->rlorder)
165 * Common code for all room listings
167 static void listrms(struct march *listing, int new_only, int floor_only)
170 struct ctdlroomlisting *rl = NULL;
171 struct ctdlroomlisting *rp;
172 struct ctdlroomlisting *rs;
175 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
178 if ( (new_only == LISTRMS_NEW_ONLY)
179 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
182 if ( (new_only == LISTRMS_OLD_ONLY)
183 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
186 if ( (floor_only >= 0)
187 && (mptr->march_floor != floor_only))
191 rp = malloc(sizeof(struct ctdlroomlisting));
192 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
193 rp->rlflags = mptr->march_flags;
194 rp->rlfloor = mptr->march_floor;
195 rp->rlorder = mptr->march_order;
204 if (rordercmp(rp, rs) < 0) {
205 if (rs->lnext == NULL) {
212 if (rs->rnext == NULL) {
224 room_tree_list(NULL);
230 void list_other_floors(void)
235 for (a = 0; a < 128; ++a) {
236 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
237 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
241 pprintf("%s: ", floorlist[a]);
242 c = c + strlen(floorlist[a]) + 3;
249 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
250 * 1 to list rooms on the current floor, or 1 to list rooms on all floors.
252 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
255 struct march *listing = NULL;
257 int r; /* IPC response code */
261 /* Ask the server for a room list */
262 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
270 if (kn_floor_mode == 0) {
272 pprintf("\n Rooms with unread messages:\n");
273 listrms(listing, LISTRMS_NEW_ONLY, -1);
275 pprintf("\n\n No unseen messages in:\n");
276 listrms(listing, LISTRMS_OLD_ONLY, -1);
280 if (kn_floor_mode == 1) {
282 pprintf("\n Rooms with unread messages on %s:\n",
283 floorlist[(int) curr_floor]);
284 listrms(listing, LISTRMS_NEW_ONLY, curr_floor);
286 pprintf("\n\n Rooms with no new messages on %s:\n",
287 floorlist[(int) curr_floor]);
288 listrms(listing, LISTRMS_OLD_ONLY, curr_floor);
290 pprintf("\n\n Other floors:\n");
295 if (kn_floor_mode == 2) {
296 for (a = 0; a < 128; ++a) {
297 if (floorlist[a][0] != 0) {
299 pprintf("\n Rooms on %s:\n",
301 listrms(listing, LISTRMS_ALL, a);
307 /* Free the room list */
309 mptr = listing->next;
315 IFNEXPERT hit_any_key(ipc);
319 void listzrooms(CtdlIPC *ipc)
320 { /* list public forgotten rooms */
321 struct march *listing = NULL;
323 int r; /* IPC response code */
327 /* Ask the server for a room list */
328 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, 1, &listing, buf);
334 pprintf("\n Forgotten public rooms:\n");
335 listrms(listing, LISTRMS_ALL, -1);
338 /* Free the room list */
340 mptr = listing->next;
346 IFNEXPERT hit_any_key(ipc);
350 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
354 a = boolprompt(prompt, (ibuf & sbit));
355 ibuf = (ibuf | sbit);
357 ibuf = (ibuf ^ sbit);
365 * Select a floor (used in several commands)
366 * The supplied argument is the 'default' floor number.
367 * This function returns the selected floor number.
369 int select_floor(CtdlIPC *ipc, int rfloor)
374 if (floor_mode == 1) {
375 if (floorlist[(int) curr_floor][0] == 0) {
381 safestrncpy(floorstr, floorlist[rfloor],
383 strprompt("Which floor", floorstr, 255);
384 for (a = 0; a < 128; ++a) {
386 (floorstr, &floorlist[a][0]))
391 (floorstr, &floorlist[a][0],
395 && (pattern(&floorlist[a][0], floorstr)
400 scr_printf("\n One of:\n");
401 for (a = 0; a < 128; ++a) {
402 if (floorlist[a][0] != 0) {
408 } while (newfloor < 0);
413 scr_printf("Floor selection bypassed because you have "
414 "floor mode disabled.\n");
424 * .<A>ide <E>dit room
426 void editthisroom(CtdlIPC *ipc)
429 char raide[USERNAME_SIZE];
431 struct ctdlroom *attr = NULL;
432 struct ExpirePolicy *eptr = NULL;
433 int r; /* IPC response code */
435 /* Fetch the existing room config */
436 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
438 scr_printf("%s\n", buf);
441 eptr = &(attr->QRep);
443 /* Fetch the name of the current room aide */
444 r = CtdlIPCGetRoomAide(ipc, buf);
446 safestrncpy(raide, buf, sizeof raide);
450 if (strlen(raide) == 0) {
451 strcpy(raide, "none");
454 /* Fetch the expire policy (this will silently fail on old servers,
455 * resulting in "default" policy)
457 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
459 /* Now interact with the user. */
461 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
462 attr->QRfloor = select_floor(ipc, attr->QRfloor);
463 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
464 if (attr->QRflags & QR_PRIVATE) {
465 attr->QRflags = set_room_attr(ipc, attr->QRflags,
466 "Accessible by guessing room name",
470 /* if it's public, clear the privacy classes */
471 if ((attr->QRflags & QR_PRIVATE) == 0) {
472 if (attr->QRflags & QR_GUESSNAME) {
473 attr->QRflags = attr->QRflags - QR_GUESSNAME;
475 if (attr->QRflags & QR_PASSWORDED) {
476 attr->QRflags = attr->QRflags - QR_PASSWORDED;
480 /* if it's private, choose the privacy classes */
481 if ((attr->QRflags & QR_PRIVATE)
482 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
483 attr->QRflags = set_room_attr(ipc, attr->QRflags,
484 "Accessible by entering a password",
487 if ((attr->QRflags & QR_PRIVATE)
488 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
489 strprompt("Room password", attr->QRpasswd, 9);
492 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
493 rbump = boolprompt("Cause current users to forget room", 0);
496 attr->QRflags = set_room_attr(ipc, attr->QRflags,
497 "Preferred users only", QR_PREFONLY);
498 attr->QRflags = set_room_attr(ipc, attr->QRflags,
499 "Read-only room", QR_READONLY);
500 attr->QRflags = set_room_attr(ipc, attr->QRflags,
501 "Directory room", QR_DIRECTORY);
502 attr->QRflags = set_room_attr(ipc, attr->QRflags,
503 "Permanent room", QR_PERMANENT);
504 if (attr->QRflags & QR_DIRECTORY) {
505 strprompt("Directory name", attr->QRdirname, 14);
507 set_room_attr(ipc, attr->QRflags,
508 "Uploading allowed", QR_UPLOAD);
510 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
513 set_room_attr(ipc, attr->QRflags,
514 "Visible directory", QR_VISDIR);
516 attr->QRflags = set_room_attr(ipc, attr->QRflags,
517 "Network shared room", QR_NETWORK);
518 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
519 "Self-service list subscribe/unsubscribe",
521 attr->QRflags = set_room_attr(ipc, attr->QRflags,
522 "Automatically make all messages anonymous",
524 if ((attr->QRflags & QR_ANONONLY) == 0) {
525 attr->QRflags = set_room_attr(ipc, attr->QRflags,
526 "Ask users whether to make messages anonymous",
529 attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
531 /* Ask about the room aide */
533 strprompt("Room aide (or 'none')", raide, 29);
534 if (!strcasecmp(raide, "none")) {
538 r = CtdlIPCQueryUsername(ipc, raide, buf);
540 scr_printf("%s\n", buf);
542 } while (r / 100 != 2);
544 /* FIXME: Duplicate code??? */
545 if (!strcasecmp(raide, "none")) {
549 /* Angels and demons dancing in my head... */
551 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
552 strprompt("Message expire policy (? for list)", buf, 1);
555 "0. Use the default for this floor\n"
556 "1. Never automatically expire messages\n"
557 "2. Expire by message count\n"
558 "3. Expire by message age\n");
560 } while ((buf[0] < 48) || (buf[0] > 51));
561 attr->QRep.expire_mode = buf[0] - 48;
563 /* ...lunatics and monsters underneath my bed */
564 if (attr->QRep.expire_mode == 2) {
565 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
566 strprompt("Keep how many messages online?", buf, 10);
567 attr->QRep.expire_value = atol(buf);
570 if (attr->QRep.expire_mode == 3) {
571 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
572 strprompt("Keep messages for how many days?", buf, 10);
573 attr->QRep.expire_value = atol(buf);
576 /* Give 'em a chance to change their minds */
577 scr_printf("Save changes (y/n)? ");
580 r = CtdlIPCSetRoomAide(ipc, raide, buf);
582 scr_printf("%s\n", buf);
585 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
587 scr_printf("%s\n", buf);
590 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
591 scr_printf("%s\n", buf);
592 strncpy(buf, attr->QRname, ROOMNAMELEN);
595 dotgoto(ipc, buf, 2, 0);
602 * un-goto the previous room, or a specified room
604 void dotungoto(CtdlIPC *ipc, char *towhere)
606 /* Find this 'towhere' room in the list ungoto from this room to
607 that at the messagepointer position in that room in our ungoto list.
608 I suppose I could be a real dick and just ungoto that many places
613 struct ctdlipcroom *rret = NULL; /* ignored */
618 scr_printf("No rooms to ungoto.\n");
623 scr_printf("Must specify a room to ungoto.\n");
626 if (strlen(towhere) == 0)
628 scr_printf("Must specify a room to ungoto.\n");
631 for (lp = uglistsize-1; lp >= 0; lp--)
633 if (strcasecmp(towhere, uglist[lp]) == 0)
641 scr_printf("Room: %s not in ungoto list.\n", towhere);
645 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
646 if (rret) free(rret); /* ignored */
648 scr_printf("%s\n", buf);
651 r = CtdlIPCSetLastRead(ipc, uglistlsn[found], buf);
653 scr_printf("%s\n", buf);
655 safestrncpy(buf, uglist[found], sizeof(buf));
656 /* we queue ungoto information here, because we're not really
657 ungotoing, we're really going to a random spot in some arbitrary
659 dotgoto(ipc, buf, 0, 0);
662 void ungoto(CtdlIPC *ipc)
665 struct ctdlipcroom *rret = NULL; /* ignored */
671 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
672 if (rret) free(rret); /* ignored */
674 scr_printf("%s\n", buf);
677 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1], buf);
679 scr_printf("%s\n", buf);
681 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
683 free(uglist[uglistsize]);
684 /* Don't queue ungoto info or we end up in a loop */
685 dotgoto(ipc, buf, 0, 1);
690 * saves filelen bytes from file at pathname
692 int save_buffer(void *file, size_t filelen, const char *pathname)
695 size_t bytes_written = 0;
698 fp = fopen(pathname, "w");
700 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
704 block = fwrite(file + bytes_written, 1,
705 filelen - bytes_written, fp);
706 bytes_written += block;
707 } while (errno == EINTR && bytes_written < filelen);
710 if (bytes_written < filelen) {
711 err_printf("Trouble saving '%s': %s\n", pathname,
720 * Save supplied_filename in dest directory; gets the name only
722 void destination_directory(char *dest, const char *supplied_filename)
724 static char save_dir[SIZ] = { 0 };
726 if (strlen(save_dir) == 0) {
727 if (getenv("HOME") == NULL) {
728 strcpy(save_dir, ".");
731 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
732 if (access(save_dir, W_OK) != 0) {
733 sprintf(save_dir, "%s", getenv("HOME"));
734 if (access(save_dir, W_OK) != 0) {
735 sprintf(save_dir, ".");
741 sprintf(dest, "%s/%s", save_dir, supplied_filename);
742 strprompt("Save as", dest, PATH_MAX);
744 /* Remember the directory for next time */
745 strcpy(save_dir, dest);
746 if (strrchr(save_dir, '/') != NULL) {
747 strcpy(strrchr(save_dir, '/'), "");
750 strcpy(save_dir, ".");
756 * download() - download a file or files. The argument passed to this
757 * function determines which protocol to use.
758 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
760 void download(CtdlIPC *ipc, int proto)
763 char filename[PATH_MAX];
764 char tempname[PATH_MAX];
765 char transmit_cmd[SIZ];
769 void *file = NULL; /* The downloaded file */
770 size_t filelen = 0L; /* The downloaded file length */
772 if ((room_flags & QR_DOWNLOAD) == 0) {
773 scr_printf("*** You cannot download from this room.\n");
777 newprompt("Enter filename: ", filename, PATH_MAX);
779 /* Save to local disk, for folks with their own copy of the client */
781 destination_directory(tempname, filename);
782 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
784 scr_printf("%s\n", buf);
787 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
792 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
794 scr_printf("%s\n", buf);
797 filelen = extract_unsigned_long(buf, 0);
799 /* Meta-download for public clients */
800 /* scr_printf("Fetching file from Citadel server...\n"); */
801 mkdir(tempdir, 0700);
802 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
803 tpipe = fopen(tempname, "wb");
804 if (fwrite(file, filelen, 1, tpipe) < filelen) {
805 /* FIXME: restart syscall on EINTR */
809 if (file) free(file);
812 /* FIXME: display internally instead */
813 snprintf(transmit_cmd, sizeof transmit_cmd,
814 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
818 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
820 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
822 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
824 /* FIXME: display internally instead */
825 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
829 system(transmit_cmd);
833 /* clean up the temporary directory */
835 ctdl_beep(); /* Beep beep! */
840 * read directory of this room
842 void roomdir(CtdlIPC *ipc)
848 char *listing = NULL; /* Returned directory listing */
851 r = CtdlIPCReadDirectory(ipc, &listing, buf);
853 pprintf("%s\n", buf);
857 extract(comment, buf, 0);
858 extract(flnm, buf, 1);
859 pprintf("\nDirectory of %s on %s\n", flnm, comment);
860 pprintf("-----------------------\n");
861 while (*listing && strlen(listing)) {
862 extract_token(buf, listing, 0, '\n');
863 remove_token(listing, 0, '\n');
865 extract(flnm, buf, 0);
866 extract(flsz, buf, 1);
867 extract(comment, buf, 2);
868 if (strlen(flnm) <= 14)
869 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
871 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
878 * add a user to a private room
880 void invite(CtdlIPC *ipc)
882 char username[USERNAME_SIZE];
884 int r; /* IPC response code */
886 newprompt("Name of user? ", username, USERNAME_SIZE);
887 if (username[0] == 0)
890 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
891 scr_printf("%s\n", buf);
896 * kick a user out of a room
898 void kickout(CtdlIPC *ipc)
900 char username[USERNAME_SIZE];
902 int r; /* IPC response code */
904 newprompt("Name of user? ", username, USERNAME_SIZE);
905 if (username[0] == 0)
908 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
909 scr_printf("%s\n", buf);
914 * aide command: kill the current room
916 void killroom(CtdlIPC *ipc)
921 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
923 scr_printf("%s\n", aaa);
927 scr_printf("Are you sure you want to kill this room? ");
931 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
932 scr_printf("%s\n", aaa);
935 dotgoto(ipc, "_BASEROOM_", 0, 0);
938 void forget(CtdlIPC *ipc)
939 { /* forget the current room */
942 scr_printf("Are you sure you want to forget this room? ");
946 remove_march(room_name, 0);
947 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
948 scr_printf("%s\n", buf);
952 /* now return to the lobby */
953 dotgoto(ipc, "_BASEROOM_", 0, 0);
960 void entroom(CtdlIPC *ipc)
963 char new_room_name[ROOMNAMELEN];
965 char new_room_pass[10];
968 int r; /* IPC response code */
970 /* Check permission to create room */
971 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
973 scr_printf("%s\n", buf);
977 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
978 if (strlen(new_room_name) == 0) {
981 for (a = 0; a < strlen(new_room_name); ++a) {
982 if (new_room_name[a] == '|') {
983 new_room_name[a] = '_';
987 new_room_floor = select_floor(ipc, (int) curr_floor);
989 IFNEXPERT formout(ipc, "roomaccess");
991 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
992 "<3>Passworded room\n<4>Invitation-only room\n"
994 "Enter room type: ");
997 } while (((b < '1') || (b > '5')) && (b != '?'));
1000 formout(ipc, "roomaccess");
1002 } while ((b < '1') || (b > '5'));
1003 b -= '0'; /* Portable */
1004 scr_printf("%d\n", b);
1005 new_room_type = b - 1;
1006 if (new_room_type == 2) {
1007 newprompt("Enter a room password: ", new_room_pass, 9);
1008 for (a = 0; a < strlen(new_room_pass); ++a)
1009 if (new_room_pass[a] == '|')
1010 new_room_pass[a] = '_';
1012 strcpy(new_room_pass, "");
1015 scr_printf("\042%s\042, a", new_room_name);
1017 scr_printf(" public room.");
1019 scr_printf(" guess-name room.");
1021 scr_printf(" passworded room, password: %s", new_room_pass);
1023 scr_printf("n invitation-only room.");
1025 scr_printf(" personal room.");
1026 scr_printf("\nInstall it? (y/n) : ");
1031 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1032 new_room_pass, new_room_floor, buf);
1034 scr_printf("%s\n", buf);
1038 /* command succeeded... now GO to the new room! */
1039 dotgoto(ipc, new_room_name, 0, 0);
1044 void readinfo(CtdlIPC *ipc)
1045 { /* read info file for current room */
1048 int r; /* IPC response code */
1051 /* Name of currernt room aide */
1052 r = CtdlIPCGetRoomAide(ipc, buf);
1054 safestrncpy(raide, buf, sizeof raide);
1058 if (strlen(raide) > 0)
1059 scr_printf("Room aide is %s.\n\n", raide);
1061 r = CtdlIPCRoomInfo(ipc, &text, buf);
1066 fmout(screenwidth, NULL, text, NULL,
1067 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1068 (*raide) ? 2 : 0, 1);
1075 * <W>ho knows room...
1077 void whoknows(CtdlIPC *ipc)
1080 char *listing = NULL;
1083 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1085 pprintf("%s\n", buf);
1088 while (strlen(listing) > 0) {
1089 extract_token(buf, listing, 0, '\n');
1090 remove_token(listing, 0, '\n');
1092 pprintf("%s\n", buf);
1098 void do_edit(CtdlIPC *ipc,
1099 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1103 int b, cksum, editor_exit;
1105 if (strlen(editor_paths[0]) == 0) {
1106 scr_printf("Do you wish to re-enter %s? ", desc);
1111 fp = fopen(temp, "w");
1114 CtdlIPC_chat_send(ipc, check_cmd);
1115 CtdlIPC_chat_recv(ipc, cmd);
1116 if (cmd[0] != '2') {
1117 scr_printf("%s\n", &cmd[4]);
1121 if (strlen(editor_paths[0]) > 0) {
1122 CtdlIPC_chat_send(ipc, read_cmd);
1123 CtdlIPC_chat_recv(ipc, cmd);
1124 if (cmd[0] == '1') {
1125 fp = fopen(temp, "w");
1126 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1127 fprintf(fp, "%s\n", cmd);
1133 cksum = file_checksum(temp);
1135 if (strlen(editor_paths[0]) > 0) {
1138 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1141 sttybbs(SB_RESTORE);
1142 editor_pid = fork();
1143 if (editor_pid == 0) {
1145 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1151 b = ka_wait(&editor_exit);
1152 } while ((b != editor_pid) && (b >= 0));
1154 scr_printf("Executed %s\n", editor_paths[0]);
1158 scr_printf("Entering %s. "
1159 "Press return twice when finished.\n", desc);
1160 fp = fopen(temp, "r+");
1165 if (file_checksum(temp) == cksum) {
1166 scr_printf("*** Aborted.\n");
1170 CtdlIPC_chat_send(ipc, write_cmd);
1171 CtdlIPC_chat_recv(ipc, cmd);
1172 if (cmd[0] != '4') {
1173 scr_printf("%s\n", &cmd[4]);
1177 fp = fopen(temp, "r");
1178 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1179 cmd[strlen(cmd) - 1] = 0;
1180 CtdlIPC_chat_send(ipc, cmd);
1183 CtdlIPC_chat_send(ipc, "000");
1190 void enterinfo(CtdlIPC *ipc)
1191 { /* edit info file for current room */
1192 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1195 void enter_bio(CtdlIPC *ipc)
1198 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1199 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1203 * create a new floor
1205 void create_floor(CtdlIPC *ipc)
1208 char newfloorname[SIZ];
1209 int r; /* IPC response code */
1211 load_floorlist(ipc);
1213 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1214 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1215 scr_printf("%s\n", buf);
1219 newprompt("Name for new floor: ", newfloorname, 255);
1220 if (!*newprompt) return;
1221 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1223 scr_printf("Floor has been created.\n");
1225 scr_printf("%s\n", buf);
1228 load_floorlist(ipc);
1232 * edit the current floor
1234 void edit_floor(CtdlIPC *ipc)
1237 struct ExpirePolicy *ep = NULL;
1238 int r; /* IPC response code */
1240 load_floorlist(ipc);
1242 /* Fetch the expire policy (this will silently fail on old servers,
1243 * resulting in "default" policy)
1245 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1247 /* Interact with the user */
1248 scr_printf("You are editing the floor called \"%s\"\n",
1249 &floorlist[(int) curr_floor][0] );
1250 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1252 /* Angels and demons dancing in my head... */
1254 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1256 ("Floor default message expire policy (? for list)",
1258 if (buf[0] == '?') {
1260 "0. Use the system default\n"
1261 "1. Never automatically expire messages\n"
1262 "2. Expire by message count\n"
1263 "3. Expire by message age\n");
1265 } while ((buf[0] < '0') || (buf[0] > '3'));
1266 ep->expire_mode = buf[0] - '0';
1268 /* ...lunatics and monsters underneath my bed */
1269 if (ep->expire_mode == 2) {
1270 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1271 strprompt("Keep how many messages online?", buf, 10);
1272 ep->expire_value = atol(buf);
1275 if (ep->expire_mode == 3) {
1276 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1277 strprompt("Keep messages for how many days?", buf, 10);
1278 ep->expire_value = atol(buf);
1282 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1283 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1284 scr_printf("%s\n", buf);
1285 load_floorlist(ipc);
1292 * kill the current floor
1294 void kill_floor(CtdlIPC *ipc)
1296 int floornum_to_delete, a;
1299 load_floorlist(ipc);
1301 floornum_to_delete = (-1);
1302 scr_printf("(Press return to abort)\n");
1303 newprompt("Delete which floor? ", buf, 255);
1304 if (strlen(buf) == 0)
1306 for (a = 0; a < 128; ++a)
1307 if (!strcasecmp(&floorlist[a][0], buf))
1308 floornum_to_delete = a;
1309 if (floornum_to_delete < 0) {
1310 scr_printf("No such floor. Select one of:\n");
1311 for (a = 0; a < 128; ++a)
1312 if (floorlist[a][0] != 0)
1313 scr_printf("%s\n", &floorlist[a][0]);
1315 } while (floornum_to_delete < 0);
1316 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1317 scr_printf("%s\n", buf);
1318 load_floorlist(ipc);