-/* Citadel/UX room-oriented routines */
-/* $Id$ */
+/*
+ * $Id$
+ *
+ *
+ * Client-side functions which perform room operations
+ *
+ */
#include "sysdep.h"
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include "citadel.h"
+#include "citadel_ipc.h"
+#include "citadel_decls.h"
#include "rooms.h"
#include "commands.h"
#include "tools.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
+#include "screen.h"
+#include "citadel_dirs.h"
#define IFNEXPERT if ((userflags&US_EXPERT)==0)
-void sttybbs(int cmd);
-void hit_any_key(void);
-int yesno(void);
-void strprompt(char *prompt, char *str, int len);
-void newprompt(char *prompt, char *str, int len);
-int struncmp(char *lstr, char *rstr, int len);
-void dotgoto(char *towhere, int display_name);
-void serv_read(char *buf, int bytes);
-void formout(char *name);
-int inkey(void);
-int fmout(int width, FILE *fp, char pagin, int height, int starting_lp, char subst);
-void progress(long int curr, long int cmax);
+void stty_ctdl(int cmd);
+void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
+void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
int pattern(char *search, char *patn);
int file_checksum(char *filename);
int nukedir(char *dirname);
-int checkpagin(int lp, int pagin, int height);
extern unsigned room_flags;
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[];
-extern int userflags;
extern char sigcaught;
extern char floor_mode;
extern char curr_floor;
extern int ugnum;
extern long uglsn;
-extern char ugname[];
-
-extern char floorlist[128][256];
+extern char *uglist[];
+extern long uglistlsn[];
+extern int uglistsize;
-int knlinecount;
+extern char floorlist[128][SIZ];
-void load_floorlist(void) {
+void load_floorlist(CtdlIPC *ipc)
+{
int a;
- char buf[256];
+ char buf[SIZ];
+ char *listing = NULL;
+ int r; /* IPC response code */
- for (a=0; a<128; ++a) floorlist[a][0] = 0;
+ for (a = 0; a < 128; ++a)
+ floorlist[a][0] = 0;
- serv_puts("LFLR");
- serv_gets(buf);
- if (buf[0]!='1') {
- strcpy(floorlist[0],"Main Floor");
+ r = CtdlIPCFloorListing(ipc, &listing, buf);
+ if (r / 100 != 1) {
+ strcpy(floorlist[0], "Main Floor");
return;
- }
- while (serv_gets(buf), strcmp(buf,"000")) {
- extract(floorlist[extract_int(buf,0)],buf,1);
- }
}
+ while (*listing && strlen(listing)) {
+ extract_token(buf, listing, 0, '\n', sizeof buf);
+ remove_token(listing, 0, '\n');
+ extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
+ }
+ free(listing);
+}
-void room_tree_list(struct roomlisting *rp) {
+void room_tree_list(struct ctdlroomlisting *rp)
+{
static int c = 0;
char rmname[ROOMNAMELEN];
int f;
if (rp == NULL) {
c = 1;
return;
- }
+ }
if (rp->lnext != NULL) {
room_tree_list(rp->lnext);
- }
+ }
if (sigcaught == 0) {
strcpy(rmname, rp->rlname);
if ((c + strlen(rmname) + 4) > screenwidth) {
/* line break, check the paginator */
- printf("\n");
- knlinecount = knlinecount + 1;
- knlinecount = checkpagin(knlinecount,
- ((userflags & US_PAGINATOR) ? 1 : 0),
- screenheight);
-
+ pprintf("\n");
c = 1;
- }
- if (f & QR_MAILBOX) {
- color(BRIGHT_YELLOW);
- }
- else if (f & QR_PRIVATE) {
+ }
+ if (f & QR_MAILBOX) {
+ color(BRIGHT_YELLOW);
+ } else if (f & QR_PRIVATE) {
color(BRIGHT_RED);
- }
- else {
+ } else {
color(DIM_WHITE);
- }
- printf("%s",rmname);
- if ((f & QR_DIRECTORY) && (f & QR_NETWORK)) printf("} ");
- else if (f & QR_DIRECTORY) printf("] ");
- else if (f & QR_NETWORK) printf(") ");
- else printf("> ");
- c = c + strlen(rmname) + 3;
}
+ pprintf("%s", rmname);
+ if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
+ pprintf("} ");
+ else if (f & QR_DIRECTORY)
+ pprintf("] ");
+ else if (f & QR_NETWORK)
+ pprintf(") ");
+ else
+ pprintf("> ");
+ c = c + strlen(rmname) + 3;
+ }
if (rp->rnext != NULL) {
room_tree_list(rp->rnext);
- }
+ }
free(rp);
- }
+}
/*
* Room ordering stuff (compare first by floor, then by order)
*/
-int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
+int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
{
- if ((r1==NULL)&&(r2==NULL)) return(0);
- if (r1==NULL) return(-1);
- if (r2==NULL) return(1);
- if (r1->rlfloor < r2->rlfloor) return(-1);
- if (r1->rlfloor > r2->rlfloor) return(1);
- if (r1->rlorder < r2->rlorder) return(-1);
- if (r1->rlorder > r2->rlorder) return(1);
- return(0);
- }
+ if ((r1 == NULL) && (r2 == NULL))
+ return (0);
+ if (r1 == NULL)
+ return (-1);
+ if (r2 == NULL)
+ return (1);
+ if (r1->rlfloor < r2->rlfloor)
+ return (-1);
+ if (r1->rlfloor > r2->rlfloor)
+ return (1);
+ if (r1->rlorder < r2->rlorder)
+ return (-1);
+ if (r1->rlorder > r2->rlorder)
+ return (1);
+ return (0);
+}
/*
* Common code for all room listings
*/
-void listrms(char *variety)
+static void listrms(struct march *listing, int new_only, int floor_only)
{
- char buf[256];
-
- struct roomlisting *rl = NULL;
- struct roomlisting *rp;
- struct roomlisting *rs;
-
-
- /* Ask the server for a room list */
- serv_puts(variety);
- serv_gets(buf);
- if (buf[0]!='1') return;
- while (serv_gets(buf), strcmp(buf, "000")) {
- rp = malloc(sizeof(struct roomlisting));
- extract(rp->rlname, buf, 0);
- rp->rlflags = extract_int(buf, 1);
- rp->rlfloor = extract_int(buf, 2);
- rp->rlorder = extract_int(buf, 3);
- 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 {
- if (rs->rnext == NULL) {
- rs->rnext = rp;
- rp = NULL;
- }
- else {
- rs = rs->rnext;
+ struct march *mptr;
+ struct ctdlroomlisting *rl = NULL;
+ struct ctdlroomlisting *rp;
+ struct ctdlroomlisting *rs;
+ 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 ctdlroomlisting));
+ 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 {
+ if (rs->rnext == NULL) {
+ rs->rnext = rp;
+ rp = NULL;
+ } else {
+ rs = rs->rnext;
+ }
}
}
}
}
+ }
- sigcaught = 0;
- sttybbs(SB_YES_INTR);
room_tree_list(NULL);
room_tree_list(rl);
color(DIM_WHITE);
- sttybbs(SB_NO_INTR);
- }
+}
-void list_other_floors(void) {
- int a,c;
+void list_other_floors(void)
+{
+ int a, c;
c = 1;
- for (a=0; a<128; ++a) if ((strlen(floorlist[a])>0)&&(a!=curr_floor)) {
- if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
- printf("\n");
- c = 1;
+ for (a = 0; a < 128; ++a) {
+ if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
+ if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
+ pprintf("\n");
+ c = 1;
}
- printf("%s: ",floorlist[a]);
- c = c + strlen(floorlist[a]) + 3;
+ pprintf("%s: ", floorlist[a]);
+ c = c + strlen(floorlist[a]) + 3;
}
}
+}
/*
* List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
* 1 to list rooms on the current floor, or 1 to list rooms on all floors.
*/
-void knrooms(int kn_floor_mode)
+void knrooms(CtdlIPC *ipc, int kn_floor_mode)
{
- char buf[256];
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);
- load_floorlist();
- knlinecount = 0;
if (kn_floor_mode == 0) {
color(BRIGHT_CYAN);
- printf("\n Rooms with unread messages:\n");
- knlinecount = knlinecount + 2;
- listrms("LKRN");
+ pprintf("\n Rooms with unread messages:\n");
+ listrms(listing, LISTRMS_NEW_ONLY, -1);
color(BRIGHT_CYAN);
- printf("\n\n No unseen messages in:\n");
- knlinecount = knlinecount + 3;
- listrms("LKRO");
- printf("\n");
- knlinecount = knlinecount + 1;
- }
+ pprintf("\n\n No unseen messages in:\n");
+ listrms(listing, LISTRMS_OLD_ONLY, -1);
+ pprintf("\n");
+ }
if (kn_floor_mode == 1) {
color(BRIGHT_CYAN);
- printf("\n Rooms with unread messages on %s:\n",
- floorlist[(int)curr_floor]);
- knlinecount = knlinecount + 2;
- sprintf(buf,"LKRN %d",curr_floor);
- listrms(buf);
+ pprintf("\n Rooms with unread messages on %s:\n",
+ floorlist[(int) curr_floor]);
+ listrms(listing, LISTRMS_NEW_ONLY, curr_floor);
color(BRIGHT_CYAN);
- printf("\n\n Rooms with no new messages on %s:\n",
- floorlist[(int)curr_floor]);
- knlinecount = knlinecount + 3;
- sprintf(buf,"LKRO %d",curr_floor);
- listrms(buf);
+ pprintf("\n\n Rooms with no new messages on %s:\n",
+ floorlist[(int) curr_floor]);
+ listrms(listing, LISTRMS_OLD_ONLY, curr_floor);
color(BRIGHT_CYAN);
- printf("\n\n Other floors:\n");
- knlinecount = knlinecount + 3;
+ pprintf("\n\n Other floors:\n");
list_other_floors();
- printf("\n");
- knlinecount = knlinecount + 1;
- }
+ pprintf("\n");
+ }
if (kn_floor_mode == 2) {
- for (a=0; a<128; ++a) if (floorlist[a][0]!=0) {
- color(BRIGHT_CYAN);
- printf("\n Rooms on %s:\n",floorlist[a]);
- knlinecount = knlinecount + 2;
- sprintf(buf,"LKRA %d",a);
- listrms(buf);
- printf("\n");
- knlinecount = knlinecount + 1;
+ for (a = 0; a < 128; ++a) {
+ if (floorlist[a][0] != 0) {
+ color(BRIGHT_CYAN);
+ pprintf("\n Rooms on %s:\n",
+ floorlist[a]);
+ listrms(listing, LISTRMS_ALL, a);
+ pprintf("\n");
}
}
-
- color(DIM_WHITE);
- IFNEXPERT hit_any_key();
}
+ /* Free the room list */
+ while (listing) {
+ mptr = listing->next;
+ free(listing);
+ listing = mptr;
+ };
-void listzrooms(void) { /* list public forgotten rooms */
- color(BRIGHT_CYAN);
- printf("\n Forgotten public rooms:\n");
- listrms("LZRM");
- printf("\n");
color(DIM_WHITE);
- IFNEXPERT hit_any_key();
+ IFNEXPERT hit_any_key(ipc);
+}
+
+
+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(listing, LISTRMS_ALL, -1);
+ pprintf("\n");
-int set_room_attr(int ibuf, char *prompt, unsigned int sbit)
+ /* Free the room list */
+ while (listing) {
+ mptr = listing->next;
+ free(listing);
+ listing = mptr;
+ };
+
+ color(DIM_WHITE);
+ IFNEXPERT hit_any_key(ipc);
+}
+
+
+int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
{
int a;
- a = boolprompt(prompt, (ibuf&sbit));
- ibuf=(ibuf|sbit);
- if (!a) ibuf=(ibuf^sbit);
- return(ibuf);
+ a = boolprompt(prompt, (ibuf & sbit));
+ ibuf = (ibuf | sbit);
+ if (!a) {
+ ibuf = (ibuf ^ sbit);
}
+ return (ibuf);
+}
* The supplied argument is the 'default' floor number.
* This function returns the selected floor number.
*/
-int select_floor(int rfloor)
+int select_floor(CtdlIPC *ipc, int rfloor)
{
int a, newfloor;
- char floorstr[256];
+ char floorstr[SIZ];
if (floor_mode == 1) {
- if (floorlist[(int)curr_floor][0]==0) load_floorlist();
+ if (floorlist[(int) curr_floor][0] == 0) {
+ load_floorlist(ipc);
+ }
do {
newfloor = (-1);
- safestrncpy(floorstr,floorlist[rfloor],sizeof floorstr);
- strprompt("Which floor",floorstr,256);
- for (a=0; a<128; ++a) {
- if (!strucmp(floorstr,&floorlist[a][0]))
+ safestrncpy(floorstr, floorlist[rfloor],
+ sizeof floorstr);
+ strprompt("Which floor", floorstr, 255);
+ for (a = 0; a < 128; ++a) {
+ if (!strcasecmp
+ (floorstr, &floorlist[a][0]))
newfloor = a;
- if ((newfloor<0)&&(!struncmp(floorstr,
- &floorlist[a][0],strlen(floorstr))))
- newfloor = a;
- if ((newfloor<0)&&(pattern(&floorlist[a][0],
- floorstr)>=0)) newfloor = a;
- }
- if (newfloor<0) {
- printf("\n One of:\n");
- for (a=0; a<128; ++a)
- if (floorlist[a][0]!=0)
- printf("%s\n",
- &floorlist[a][0]);
+ if ((newfloor < 0)
+ &&
+ (!strncasecmp
+ (floorstr, &floorlist[a][0],
+ strlen(floorstr))))
+ newfloor = a;
+ if ((newfloor < 0)
+ && (pattern(&floorlist[a][0], floorstr)
+ >= 0))
+ newfloor = a;
+ }
+ if (newfloor < 0) {
+ scr_printf("\n One of:\n");
+ for (a = 0; a < 128; ++a) {
+ if (floorlist[a][0] != 0) {
+ scr_printf("%s\n",
+ &floorlist[a][0]);
+ }
}
- } while(newfloor < 0);
- return(newfloor);
- }
- return(rfloor);
+ }
+ } while (newfloor < 0);
+ return (newfloor);
}
+ else {
+ scr_printf("Floor selection bypassed because you have "
+ "floor mode disabled.\n");
+ }
+
+ return (rfloor);
+}
+
/*
* .<A>ide <E>dit room
*/
-void editthisroom(void) {
- char rname[ROOMNAMELEN];
- char rpass[10];
- char rdir[15];
- unsigned rflags;
- int rbump;
- char raide[32];
- char buf[256];
- int rfloor;
- int rorder;
- int expire_mode = 0;
- int expire_value = 0;
+void editthisroom(CtdlIPC *ipc)
+{
+ int rbump = 0;
+ char raide[USERNAME_SIZE];
+ char buf[SIZ];
+ struct ctdlroom *attr = NULL;
+ struct ExpirePolicy *eptr = NULL;
+ int r; /* IPC response code */
/* Fetch the existing room config */
- serv_puts("GETR");
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
+ r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
return;
- }
-
- extract(rname,&buf[4],0);
- extract(rpass,&buf[4],1);
- extract(rdir, &buf[4],2);
- rflags = extract_int(&buf[4],3);
- rfloor = extract_int(&buf[4],4);
- rorder = extract_int(&buf[4],5);
- rbump = 0;
+ }
+ eptr = &(attr->QRep);
/* Fetch the name of the current room aide */
- serv_puts("GETA");
- serv_gets(buf);
- if (buf[0]=='2') safestrncpy(raide,&buf[4],sizeof raide);
- else strcpy(raide,"");
- if (strlen(raide)==0) strcpy(raide,"none");
+ r = CtdlIPCGetRoomAide(ipc, buf);
+ if (r / 100 == 2) {
+ safestrncpy(raide, buf, sizeof raide);
+ } else {
+ strcpy(raide, "");
+ }
+ if (strlen(raide) == 0) {
+ strcpy(raide, "none");
+ }
/* Fetch the expire policy (this will silently fail on old servers,
* resulting in "default" policy)
*/
- serv_puts("GPEX room");
- serv_gets(buf);
- if (buf[0]=='2') {
- expire_mode = extract_int(&buf[4], 0);
- expire_value = extract_int(&buf[4], 1);
- }
+ r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
/* Now interact with the user. */
- strprompt("Room name",rname,ROOMNAMELEN-1);
- rfloor = select_floor(rfloor);
- rflags = set_room_attr(rflags,"Private room",QR_PRIVATE);
- if (rflags & QR_PRIVATE)
- rflags = set_room_attr(rflags,
- "Accessible by guessing room name",QR_GUESSNAME);
+ 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) {
+ attr->QRflags = set_room_attr(ipc, attr->QRflags,
+ "Accessible by guessing room name",
+ QR_GUESSNAME);
+ }
/* if it's public, clear the privacy classes */
- if ((rflags & QR_PRIVATE)==0) {
- if (rflags & QR_GUESSNAME) rflags = rflags - QR_GUESSNAME;
- if (rflags & QR_PASSWORDED) rflags = rflags - QR_PASSWORDED;
+ if ((attr->QRflags & QR_PRIVATE) == 0) {
+ if (attr->QRflags & QR_GUESSNAME) {
+ attr->QRflags = attr->QRflags - QR_GUESSNAME;
}
+ if (attr->QRflags & QR_PASSWORDED) {
+ attr->QRflags = attr->QRflags - QR_PASSWORDED;
+ }
+ }
/* if it's private, choose the privacy classes */
- if ( (rflags & QR_PRIVATE)
- && ( (rflags & QR_GUESSNAME) == 0) ) {
- rflags = set_room_attr(rflags,
- "Accessible by entering a password",QR_PASSWORDED);
- }
- if ( (rflags & QR_PRIVATE)
- && ((rflags&QR_PASSWORDED)==QR_PASSWORDED) ) {
- strprompt("Room password",rpass,9);
- }
+ if ((attr->QRflags & QR_PRIVATE)
+ && ((attr->QRflags & QR_GUESSNAME) == 0)) {
+ attr->QRflags = set_room_attr(ipc, attr->QRflags,
+ "Accessible by entering a password",
+ QR_PASSWORDED);
+ }
+ if ((attr->QRflags & QR_PRIVATE)
+ && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
+ strprompt("Room password", attr->QRpasswd, 9);
+ }
- if ((rflags&QR_PRIVATE)==QR_PRIVATE) {
+ if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
rbump = boolprompt("Cause current users to forget room", 0);
- }
+ }
- rflags = set_room_attr(rflags,"Preferred users only",QR_PREFONLY);
- rflags = set_room_attr(rflags,"Read-only room",QR_READONLY);
- rflags = set_room_attr(rflags,"Directory room",QR_DIRECTORY);
- rflags = set_room_attr(rflags,"Permanent room",QR_PERMANENT);
- if (rflags & QR_DIRECTORY) {
- strprompt("Directory name",rdir,14);
- rflags = set_room_attr(rflags,"Uploading allowed",QR_UPLOAD);
- rflags = set_room_attr(rflags,"Downloading allowed",
- QR_DOWNLOAD);
- rflags = set_room_attr(rflags,"Visible directory",QR_VISDIR);
- }
- rflags = set_room_attr(rflags,"Network shared room",QR_NETWORK);
- rflags = set_room_attr(rflags,
- "Automatically make all messages anonymous",QR_ANONONLY);
- if ( (rflags & QR_ANONONLY) == 0) {
- rflags = set_room_attr(rflags,
- "Ask users whether to make messages anonymous",
- QR_ANONOPT);
- }
- rorder = intprompt("Listing order", rorder, 1, 127);
+ 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);
+ attr->QRflags =
+ set_room_attr(ipc, attr->QRflags, "Downloading allowed",
+ QR_DOWNLOAD);
+ attr->QRflags =
+ set_room_attr(ipc, attr->QRflags,
+ "Visible directory", QR_VISDIR);
+ }
+ 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);
+ attr->QRflags = set_room_attr(ipc, attr->QRflags,
+ "Automatically make all messages anonymous",
+ QR_ANONONLY);
+ if ((attr->QRflags & QR_ANONONLY) == 0) {
+ attr->QRflags = set_room_attr(ipc, attr->QRflags,
+ "Ask users whether to make messages anonymous",
+ QR_ANONOPT);
+ }
+ attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
/* Ask about the room aide */
do {
- strprompt("Room aide (or 'none')",raide,29);
- if (!strucmp(raide,"none")) {
- strcpy(raide,"");
- strcpy(buf,"200");
- }
- else {
- snprintf(buf,sizeof buf,"QUSR %s",raide);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') printf("%s\n",&buf[4]);
- }
- } while(buf[0]!='2');
-
- if (!strucmp(raide,"none")) strcpy(raide,"");
+ strprompt("Room aide (or 'none')", raide, 29);
+ if (!strcasecmp(raide, "none")) {
+ strcpy(raide, "");
+ break;
+ } else {
+ r = CtdlIPCQueryUsername(ipc, raide, buf);
+ if (r / 100 != 2)
+ scr_printf("%s\n", buf);
+ }
+ } while (r / 100 != 2);
+ /* FIXME: Duplicate code??? */
+ if (!strcasecmp(raide, "none")) {
+ strcpy(raide, "");
+ }
/* Angels and demons dancing in my head... */
do {
- sprintf(buf, "%d", expire_mode);
+ snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
strprompt("Message expire policy (? for list)", buf, 1);
if (buf[0] == '?') {
- printf("\n");
- printf("0. Use the default for this floor\n");
- printf("1. Never automatically expire messages\n");
- printf("2. Expire by message count\n");
- printf("3. Expire by message age\n");
- }
- } while((buf[0]<48)||(buf[0]>51));
- expire_mode = buf[0] - 48;
+ scr_printf("\n"
+ "0. Use the default for this floor\n"
+ "1. Never automatically expire messages\n"
+ "2. Expire by message count\n"
+ "3. Expire by message age\n");
+ }
+ } while ((buf[0] < 48) || (buf[0] > 51));
+ attr->QRep.expire_mode = buf[0] - 48;
/* ...lunatics and monsters underneath my bed */
- if (expire_mode == 2) {
- sprintf(buf, "%d", expire_value);
+ if (attr->QRep.expire_mode == 2) {
+ snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
strprompt("Keep how many messages online?", buf, 10);
- expire_value = atol(buf);
- }
+ attr->QRep.expire_value = atol(buf);
+ }
- if (expire_mode == 3) {
- sprintf(buf, "%d", expire_value);
+ if (attr->QRep.expire_mode == 3) {
+ snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
strprompt("Keep messages for how many days?", buf, 10);
- expire_value = atol(buf);
- }
+ attr->QRep.expire_value = atol(buf);
+ }
/* Give 'em a chance to change their minds */
- printf("Save changes (y/n)? ");
-
- if (yesno()==1) {
- snprintf(buf,sizeof buf,"SETA %s",raide);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') printf("%s\n",&buf[4]);
-
- snprintf(buf, sizeof buf, "SPEX room|%d|%d",
- expire_mode, expire_value);
- serv_puts(buf);
- serv_gets(buf);
-
- snprintf(buf,sizeof buf,"SETR %s|%s|%s|%d|%d|%d|%d",
- rname,rpass,rdir,rflags,rbump,rfloor,rorder);
- serv_puts(buf);
- serv_gets(buf);
- printf("%s\n",&buf[4]);
- if (buf[0]=='2') dotgoto(rname,2);
+ scr_printf("Save changes (y/n)? ");
+
+ if (yesno() == 1) {
+ r = CtdlIPCSetRoomAide(ipc, raide, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ }
+
+ r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
}
+
+ r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
+ scr_printf("%s\n", buf);
+ strncpy(buf, attr->QRname, ROOMNAMELEN);
+ free(attr);
+ if (r / 100 == 2)
+ dotgoto(ipc, buf, 2, 0);
}
+ else free(attr);
+}
/*
- * un-goto the previous room
+ * un-goto the previous room, or a specified room
*/
-void ungoto(void) {
- char buf[256];
-
- if (!strcmp(ugname,"")) return;
- snprintf(buf,sizeof buf,"GOTO %s",ugname);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
+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;
- }
- sprintf(buf,"SLRP %ld",uglsn);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') printf("%s\n",&buf[4]);
- safestrncpy(buf,ugname,sizeof buf);
- strcpy(ugname,"");
- dotgoto(buf,0);
+ }
+ 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;
+
+ r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
+ if (rret) free(rret); /* ignored */
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ return;
+ }
+ 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]);
+ /* Don't queue ungoto info or we end up in a loop */
+ dotgoto(ipc, buf, 0, 1);
+}
-/* Here's the code for simply transferring the file to the client,
- * for folks who have their own clientware. It's a lot simpler than
- * the [XYZ]modem code below...
- * (This function assumes that a download file is already open on the server)
+/*
+ * saves filelen bytes from file at pathname
*/
-void download_to_local_disk(char *supplied_filename, long total_bytes)
+int save_buffer(void *file, size_t filelen, const char *pathname)
{
- char buf[256];
- char dbuf[4096];
- long transmitted_bytes = 0L;
- long aa,bb;
- FILE *savefp;
- int broken = 0;
- int packet;
- char filename[256];
+ size_t block = 0;
+ size_t bytes_written = 0;
+ FILE *fp;
- strcpy(filename, supplied_filename);
- if (strlen(filename)==0) {
- newprompt("Filename: ", filename, 250);
- }
+ fp = fopen(pathname, "w");
+ if (!fp) {
+ err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
+ return 0;
+ }
+ do {
+ block = fwrite((char *)file + bytes_written, 1,
+ filelen - bytes_written, fp);
+ bytes_written += block;
+ } while (errno == EINTR && bytes_written < filelen);
+ fclose(fp);
- printf("Enter the name of the directory to save '%s'\n",
- filename);
- printf("to, or press return for the current directory.\n");
- newprompt("Directory: ",dbuf,256);
- if (strlen(dbuf)==0) strcpy(dbuf,".");
- strcat(dbuf,"/");
- strcat(dbuf,filename);
-
- savefp = fopen(dbuf,"w");
- if (savefp == NULL) {
- printf("Cannot open '%s': %s\n",dbuf,strerror(errno));
- /* close the download file at the server */
- serv_puts("CLOS");
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
- }
- return;
+ if (bytes_written < filelen) {
+ err_printf("Trouble saving '%s': %s\n", pathname,
+ strerror(errno));
+ return 0;
+ }
+ return 1;
+}
+
+
+/*
+ * Save supplied_filename in dest directory; gets the name only
+ */
+void destination_directory(char *dest, const char *supplied_filename)
+{
+ static char save_dir[SIZ] = { 0 };
+
+ if (strlen(save_dir) == 0) {
+ if (getenv("HOME") == NULL) {
+ strcpy(save_dir, ".");
}
- progress(0,total_bytes);
- while ( (transmitted_bytes < total_bytes) && (broken == 0) ) {
- bb = total_bytes - transmitted_bytes;
- aa = ((bb < 4096) ? bb : 4096);
- sprintf(buf,"READ %ld|%ld",transmitted_bytes,aa);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='6') {
- printf("%s\n",&buf[4]);
- return;
+ else {
+ sprintf(save_dir, "%s/Desktop", getenv("HOME"));
+ if (access(save_dir, W_OK) != 0) {
+ sprintf(save_dir, "%s", getenv("HOME"));
+ if (access(save_dir, W_OK) != 0) {
+ sprintf(save_dir, ".");
+ }
}
- packet = extract_int(&buf[4],0);
- serv_read(dbuf,packet);
- if (fwrite(dbuf,packet,1,savefp) < 1) broken = 1;
- transmitted_bytes = transmitted_bytes + (long)packet;
- progress(transmitted_bytes,total_bytes);
- }
- fclose(savefp);
- /* close the download file at the server */
- serv_puts("CLOS");
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
}
- return;
}
+ sprintf(dest, "%s/%s", save_dir, supplied_filename);
+ strprompt("Save as", dest, PATH_MAX);
+
+ /* Remember the directory for next time */
+ strcpy(save_dir, dest);
+ if (strrchr(save_dir, '/') != NULL) {
+ strcpy(strrchr(save_dir, '/'), "");
+ }
+ else {
+ strcpy(save_dir, ".");
+ }
+}
+
/*
* download() - download a file or files. The argument passed to this
* function determines which protocol to use.
* proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
*/
-void download(int proto)
+void download(CtdlIPC *ipc, int proto)
{
- char buf[256];
- char filename[256];
- char tempname[256];
- char transmit_cmd[256];
- long total_bytes = 0L;
- char dbuf[4096];
- long transmitted_bytes = 0L;
- long aa,bb;
- int packet;
+ char buf[SIZ];
+ char filename[PATH_MAX];
+ char tempname[PATH_MAX];
+ char transmit_cmd[SIZ];
FILE *tpipe = NULL;
int broken = 0;
+ int r;
+ void *file = NULL; /* The downloaded file */
+ size_t filelen = 0L; /* The downloaded file length */
if ((room_flags & QR_DOWNLOAD) == 0) {
- printf("*** You cannot download from this room.\n");
+ scr_printf("*** You cannot download from this room.\n");
return;
- }
-
- newprompt("Enter filename: ",filename,255);
+ }
- snprintf(buf,sizeof buf,"OPEN %s",filename);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
- return;
- }
- total_bytes = extract_long(&buf[4],0);
+ newprompt("Enter filename: ", filename, PATH_MAX);
/* Save to local disk, for folks with their own copy of the client */
if (proto == 5) {
- download_to_local_disk(filename, total_bytes);
- return;
+ destination_directory(tempname, filename);
+ r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ return;
}
+ save_buffer(file, (size_t)extract_long(buf, 0), tempname);
+ free(file);
+ return;
+ }
+
+ r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ return;
+ }
+ filelen = extract_unsigned_long(buf, 0);
/* Meta-download for public clients */
- printf("Fetching file from Citadel server...\n");
+ /* scr_printf("Fetching file from Citadel server...\n"); */
mkdir(tempdir, 0700);
snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
tpipe = fopen(tempname, "wb");
- while ( (transmitted_bytes < total_bytes) && (broken == 0) ) {
- progress(transmitted_bytes, total_bytes);
- bb = total_bytes - transmitted_bytes;
- aa = ((bb < 4096) ? bb : 4096);
- sprintf(buf,"READ %ld|%ld",transmitted_bytes,aa);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]!='6') {
- printf("%s\n",&buf[4]);
- }
- packet = extract_int(&buf[4],0);
- serv_read(dbuf,packet);
- if (fwrite(dbuf,packet,1,tpipe) < 1) broken = 1;
- transmitted_bytes = transmitted_bytes + (long)packet;
+ if (fwrite(file, filelen, 1, tpipe) < filelen) {
+ /* FIXME: restart syscall on EINTR */
+ broken = 1;
}
fclose(tpipe);
- progress(transmitted_bytes, total_bytes);
+ if (file) free(file);
- /* close the download file at the server */
- serv_puts("CLOS");
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
+ if (proto == 0) {
+ /* FIXME: display internally instead */
+ snprintf(transmit_cmd, sizeof transmit_cmd,
+ "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
+ tempname);
}
-
- if (proto==0) sprintf(transmit_cmd, "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",tempname);
- else if (proto==1) sprintf(transmit_cmd, "exec sx %s", tempname);
- else if (proto==3) sprintf(transmit_cmd, "exec sb %s", tempname);
- else if (proto==4) sprintf(transmit_cmd, "exec sz %s", tempname);
- else sprintf(transmit_cmd, "exec cat %s", tempname);
-
- sttybbs(SB_RESTORE);
+ else if (proto == 1)
+ snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
+ else if (proto == 3)
+ snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
+ else if (proto == 4)
+ snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
+ else
+ /* FIXME: display internally instead */
+ snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
+
+ screen_reset();
+ stty_ctdl(SB_RESTORE);
system(transmit_cmd);
- sttybbs(SB_NO_INTR);
-
+ stty_ctdl(SB_NO_INTR);
+ screen_set();
+
/* clean up the temporary directory */
nukedir(tempdir);
- putc(7,stdout);
+ ctdl_beep(); /* Beep beep! */
}
/*
* read directory of this room
*/
-void roomdir(void) {
+void roomdir(CtdlIPC *ipc)
+{
char flnm[256];
char flsz[32];
char comment[256];
char buf[256];
+ char *listing = NULL; /* Returned directory listing */
+ int r;
- serv_puts("RDIR");
- serv_gets(buf);
- if (buf[0]!='1') {
- printf("%s\n",&buf[4]);
+ r = CtdlIPCReadDirectory(ipc, &listing, buf);
+ if (r / 100 != 1) {
+ pprintf("%s\n", buf);
return;
- }
+ }
- extract(comment,&buf[4],0);
- extract(flnm,&buf[4],1);
- printf("\nDirectory of %s on %s\n",flnm,comment);
- printf("-----------------------\n");
- while (serv_gets(buf), strcmp(buf,"000")) {
- extract(flnm,buf,0);
- extract(flsz,buf,1);
- extract(comment,buf,2);
- if (strlen(flnm)<=14)
- printf("%-14s %8s %s\n",flnm,flsz,comment);
+ extract_token(comment, buf, 0, '|', sizeof comment);
+ extract_token(flnm, buf, 1, '|', sizeof flnm);
+ pprintf("\nDirectory of %s on %s\n", flnm, comment);
+ pprintf("-----------------------\n");
+ while (*listing && strlen(listing)) {
+ extract_token(buf, listing, 0, '\n', sizeof buf);
+ remove_token(listing, 0, '\n');
+
+ extract_token(flnm, buf, 0, '|', sizeof flnm);
+ extract_token(flsz, buf, 1, '|', sizeof flsz);
+ extract_token(comment, buf, 2, '|', sizeof comment);
+ if (strlen(flnm) <= 14)
+ pprintf("%-14s %8s %s\n", flnm, flsz, comment);
else
- printf("%s\n%14s %8s %s\n",flnm,"",flsz,comment);
- }
+ pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
+ comment);
}
+}
/*
* add a user to a private room
*/
-void invite(void) {
- char aaa[31],bbb[256];
+void invite(CtdlIPC *ipc)
+{
+ char username[USERNAME_SIZE];
+ char buf[SIZ];
+ int r; /* IPC response code */
- if ((room_flags & QR_PRIVATE)==0) {
- printf("This is not a private room.\n");
+ newprompt("Name of user? ", username, USERNAME_SIZE);
+ if (username[0] == 0)
return;
- }
- newprompt("Name of user? ",aaa,30);
- if (aaa[0]==0) return;
-
- snprintf(bbb,sizeof bbb,"INVT %s",aaa);
- serv_puts(bbb);
- serv_gets(bbb);
- printf("%s\n",&bbb[4]);
- }
+ r = CtdlIPCInviteUserToRoom(ipc, username, buf);
+ scr_printf("%s\n", buf);
+}
/*
* kick a user out of a room
*/
-void kickout(void) {
- char aaa[31],bbb[256];
+void kickout(CtdlIPC *ipc)
+{
+ char username[USERNAME_SIZE];
+ char buf[SIZ];
+ int r; /* IPC response code */
- newprompt("Name of user? ",aaa,30);
- if (aaa[0]==0) return;
+ newprompt("Name of user? ", username, USERNAME_SIZE);
+ if (username[0] == 0)
+ return;
- snprintf(bbb,sizeof bbb,"KICK %s",aaa);
- serv_puts(bbb);
- serv_gets(bbb);
- printf("%s\n",&bbb[4]);
- }
+ r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
+ scr_printf("%s\n", buf);
+}
/*
* aide command: kill the current room
*/
-void killroom(void) {
+void killroom(CtdlIPC *ipc)
+{
char aaa[100];
+ int r;
- serv_puts("KILL 0");
- serv_gets(aaa);
- if (aaa[0]!='2') {
- printf("%s\n",&aaa[4]);
+ r = CtdlIPCDeleteRoom(ipc, 0, aaa);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", aaa);
return;
- }
+ }
- printf("Are you sure you want to kill this room? ");
- if (yesno()==0) return;
+ scr_printf("Are you sure you want to kill this room? ");
+ if (yesno() == 0)
+ return;
- serv_puts("KILL 1");
- serv_gets(aaa);
- printf("%s\n",&aaa[4]);
- if (aaa[0]!='2') return;
- dotgoto("_BASEROOM_",0);
- }
+ r = CtdlIPCDeleteRoom(ipc, 1, aaa);
+ scr_printf("%s\n", aaa);
+ if (r / 100 != 2)
+ return;
+ dotgoto(ipc, "_BASEROOM_", 0, 0);
+}
-void forget(void) { /* forget the current room */
- char cmd[256];
+void forget(CtdlIPC *ipc)
+{ /* forget the current room */
+ char buf[SIZ];
- printf("Are you sure you want to forget this room? ");
- if (yesno()==0) return;
+ scr_printf("Are you sure you want to forget this room? ");
+ if (yesno() == 0)
+ return;
- serv_puts("FORG");
- serv_gets(cmd);
- if (cmd[0]!='2') {
- printf("%s\n",&cmd[4]);
+ remove_march(room_name, 0);
+ if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
+ scr_printf("%s\n", buf);
return;
- }
+ }
/* now return to the lobby */
- dotgoto("_BASEROOM_",0);
- }
+ dotgoto(ipc, "_BASEROOM_", 0, 0);
+}
/*
* create a new room
*/
-void entroom(void) {
- char cmd[256];
+void entroom(CtdlIPC *ipc)
+{
+ char buf[SIZ];
char new_room_name[ROOMNAMELEN];
int new_room_type;
char new_room_pass[10];
int new_room_floor;
- int a,b;
+ int a, b;
+ int r; /* IPC response code */
- serv_puts("CRE8 0");
- serv_gets(cmd);
-
- if (cmd[0]!='2') {
- printf("%s\n",&cmd[4]);
+ /* Check permission to create room */
+ r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
return;
+ }
+
+ newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
+ if (strlen(new_room_name) == 0) {
+ return;
+ }
+ for (a = 0; a < strlen(new_room_name); ++a) {
+ if (new_room_name[a] == '|') {
+ new_room_name[a] = '_';
}
-
- newprompt("Name for new room? ",new_room_name,ROOMNAMELEN-1);
- if (strlen(new_room_name)==0) return;
- for (a=0; a<strlen(new_room_name); ++a)
- if (new_room_name[a] == '|') new_room_name[a]='_';
+ }
- new_room_floor = select_floor((int)curr_floor);
+ new_room_floor = select_floor(ipc, (int) curr_floor);
- IFNEXPERT formout("roomaccess");
+ IFNEXPERT formout(ipc, "roomaccess");
do {
- printf( "<?>Help\n<1>Public room\n<2>Guess-name room\n"
- "<3>Passworded room\n<4>Invitation-only room\n"
- "<5>Personal room\n");
- printf("Enter room type: ");
+ scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
+ "<3>Passworded room\n<4>Invitation-only room\n"
+ "<5>Personal room\n"
+ "Enter room type: ");
do {
- b=inkey();
- } while (((b<'1')||(b>'5')) && (b!='?'));
- if (b=='?') {
- printf("?\n");
- formout("roomaccess");
- }
- } while ((b<'1')||(b>'5'));
- b=b-48;
- printf("%d\n",b);
- new_room_type = b - 1;
- if (new_room_type==2) {
- newprompt("Enter a room password: ",new_room_pass,9);
- for (a=0; a<strlen(new_room_pass); ++a)
- if (new_room_pass[a] == '|') new_room_pass[a]='_';
+ b = inkey();
+ } while (((b < '1') || (b > '5')) && (b != '?'));
+ if (b == '?') {
+ scr_printf("?\n");
+ formout(ipc, "roomaccess");
}
- else strcpy(new_room_pass,"");
-
- printf("\042%s\042, a",new_room_name);
- if (b==1) printf(" public room.");
- if (b==2) printf(" guess-name room.");
- if (b==3) printf(" passworded room, password: %s",new_room_pass);
- if (b==4) printf("n invitation-only room.");
- if (b==5) printf(" personal room.");
- printf("\nInstall it? (y/n) : ");
- a=yesno();
- if (a==0) return;
-
- snprintf(cmd, sizeof cmd, "CRE8 1|%s|%d|%s|%d", new_room_name,
- new_room_type, new_room_pass, new_room_floor);
- serv_puts(cmd);
- serv_gets(cmd);
- if (cmd[0]!='2') {
- printf("%s\n",&cmd[4]);
+ } while ((b < '1') || (b > '5'));
+ b -= '0'; /* Portable */
+ scr_printf("%d\n", b);
+ new_room_type = b - 1;
+ if (new_room_type == 2) {
+ newprompt("Enter a room password: ", new_room_pass, 9);
+ for (a = 0; a < strlen(new_room_pass); ++a)
+ if (new_room_pass[a] == '|')
+ new_room_pass[a] = '_';
+ } else {
+ strcpy(new_room_pass, "");
+ }
+
+ scr_printf("\042%s\042, a", new_room_name);
+ if (b == 1)
+ scr_printf(" public room.");
+ if (b == 2)
+ scr_printf(" guess-name room.");
+ if (b == 3)
+ scr_printf(" passworded room, password: %s", new_room_pass);
+ if (b == 4)
+ scr_printf("n invitation-only room.");
+ if (b == 5)
+ scr_printf(" personal room.");
+ scr_printf("\nInstall it? (y/n) : ");
+ if (yesno() == 0) {
return;
- }
+ }
- /* command succeeded... now GO to the new room! */
- dotgoto(new_room_name,0);
+ r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
+ new_room_pass, new_room_floor, buf);
+ if (r / 100 != 2) {
+ scr_printf("%s\n", buf);
+ return;
}
+ /* command succeeded... now GO to the new room! */
+ dotgoto(ipc, new_room_name, 0, 0);
+}
-void readinfo(void) { /* read info file for current room */
- char cmd[256];
-
- sprintf(cmd,"RINF");
- serv_puts(cmd);
- serv_gets(cmd);
- if (cmd[0]!='1') return;
+void readinfo(CtdlIPC *ipc)
+{ /* read info file for current room */
+ char buf[SIZ];
+ char raide[64];
+ int r; /* IPC response code */
+ char *text = NULL;
+
+ /* Name of currernt room aide */
+ r = CtdlIPCGetRoomAide(ipc, buf);
+ if (r / 100 == 2)
+ safestrncpy(raide, buf, sizeof raide);
+ else
+ strcpy(raide, "");
- fmout(screenwidth,NULL,
- ((userflags & US_PAGINATOR) ? 1 : 0),
- screenheight,0,1);
+ if (strlen(raide) > 0)
+ scr_printf("Room aide is %s.\n\n", raide);
+
+ r = CtdlIPCRoomInfo(ipc, &text, buf);
+ if (r / 100 != 1)
+ return;
+
+ if (text) {
+ fmout(screenwidth, NULL, text, NULL,
+ ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
+ (*raide) ? 2 : 0, 1);
+ free(text);
}
+}
/*
* <W>ho knows room...
*/
-void whoknows(void) {
+void whoknows(CtdlIPC *ipc)
+{
char buf[256];
- serv_puts("WHOK");
- serv_gets(buf);
- if (buf[0]!='1') {
- printf("%s\n",&buf[5]);
+ char *listing = NULL;
+ int r;
+
+ r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
+ if (r / 100 != 1) {
+ pprintf("%s\n", buf);
return;
- }
- sigcaught = 0;
- sttybbs(SB_YES_INTR);
- while (serv_gets(buf), strncmp(buf,"000",3)) {
- if (sigcaught==0) printf("%s\n",buf);
- }
- sttybbs(SB_NO_INTR);
}
+ while (strlen(listing) > 0) {
+ extract_token(buf, listing, 0, '\n', sizeof buf);
+ remove_token(listing, 0, '\n');
+ if (sigcaught == 0)
+ pprintf("%s\n", buf);
+ }
+ free(listing);
+}
-void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
+void do_edit(CtdlIPC *ipc,
+ char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
{
FILE *fp;
- char cmd[256];
- int b,cksum,editor_exit;
+ char cmd[SIZ];
+ int b, cksum, editor_exit;
+ if (strlen(editor_paths[0]) == 0) {
+ scr_printf("Do you wish to re-enter %s? ", desc);
+ if (yesno() == 0)
+ return;
+ }
- if (strlen(editor_path)==0) {
- printf("Do you wish to re-enter %s? ",desc);
- if (yesno()==0) return;
- }
-
- fp = fopen(temp,"w");
+ fp = fopen(temp, "w");
fclose(fp);
- serv_puts(check_cmd);
- serv_gets(cmd);
- if (cmd[0]!='2') {
- printf("%s\n",&cmd[4]);
+ CtdlIPC_chat_send(ipc, check_cmd);
+ CtdlIPC_chat_recv(ipc, cmd);
+ if (cmd[0] != '2') {
+ scr_printf("%s\n", &cmd[4]);
return;
- }
+ }
- if (strlen(editor_path)>0) {
- serv_puts(read_cmd);
- serv_gets(cmd);
- if (cmd[0]=='1') {
- fp = fopen(temp,"w");
- while (serv_gets(cmd), strcmp(cmd,"000")) {
- fprintf(fp,"%s\n",cmd);
- }
- fclose(fp);
+ if (strlen(editor_paths[0]) > 0) {
+ CtdlIPC_chat_send(ipc, read_cmd);
+ CtdlIPC_chat_recv(ipc, cmd);
+ if (cmd[0] == '1') {
+ fp = fopen(temp, "w");
+ while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
+ fprintf(fp, "%s\n", cmd);
}
+ fclose(fp);
}
+ }
cksum = file_checksum(temp);
- if (strlen(editor_path)>0) {
- editor_pid=fork();
- if (editor_pid==0) {
- chmod(temp,0600);
- sttybbs(SB_RESTORE);
- execlp(editor_path,editor_path,temp,NULL);
+ if (strlen(editor_paths[0]) > 0) {
+ char tmp[SIZ];
+
+ snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
+ putenv(tmp);
+ screen_reset();
+ stty_ctdl(SB_RESTORE);
+ editor_pid = fork();
+ if (editor_pid == 0) {
+ chmod(temp, 0600);
+ execlp(editor_paths[0], editor_paths[0], temp, NULL);
exit(1);
- }
- if (editor_pid>0) do {
- editor_exit = 0;
- b=wait(&editor_exit);
- } while((b!=editor_pid)&&(b>=0));
- editor_pid = (-1);
- printf("Executed %s\n", editor_path);
- sttybbs(0);
}
- else {
- printf("Entering %s. ",desc);
- printf("Press return twice when finished.\n");
- fp=fopen(temp,"r+");
- citedit(fp);
+ if (editor_pid > 0)
+ do {
+ editor_exit = 0;
+ b = ka_wait(&editor_exit);
+ } while ((b != editor_pid) && (b >= 0));
+ editor_pid = (-1);
+ scr_printf("Executed %s\n", editor_paths[0]);
+ stty_ctdl(0);
+ screen_set();
+ } else {
+ scr_printf("Entering %s. "
+ "Press return twice when finished.\n", desc);
+ fp = fopen(temp, "r+");
+ citedit(ipc, fp);
fclose(fp);
- }
+ }
if (file_checksum(temp) == cksum) {
- printf("*** Aborted.\n");
- }
+ scr_printf("*** Aborted.\n");
+ }
else {
- serv_puts(write_cmd);
- serv_gets(cmd);
- if (cmd[0]!='4') {
- printf("%s\n",&cmd[4]);
+ CtdlIPC_chat_send(ipc, write_cmd);
+ CtdlIPC_chat_recv(ipc, cmd);
+ if (cmd[0] != '4') {
+ scr_printf("%s\n", &cmd[4]);
return;
- }
+ }
- fp=fopen(temp,"r");
- while (fgets(cmd,255,fp)!=NULL) {
- cmd[strlen(cmd)-1] = 0;
- serv_puts(cmd);
- }
- fclose(fp);
- serv_puts("000");
+ fp = fopen(temp, "r");
+ while (fgets(cmd, SIZ - 1, fp) != NULL) {
+ cmd[strlen(cmd) - 1] = 0;
+ CtdlIPC_chat_send(ipc, cmd);
}
+ fclose(fp);
+ CtdlIPC_chat_send(ipc, "000");
+ }
unlink(temp);
- }
+}
-void enterinfo(void) { /* edit info file for current room */
- do_edit("the Info file for this room","RINF","EINF 0","EINF 1");
- }
+void enterinfo(CtdlIPC *ipc)
+{ /* edit info file for current room */
+ do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
+}
-void enter_bio(void) {
- char cmd[256];
- snprintf(cmd,sizeof cmd,"RBIO %s",fullname);
- do_edit("your Bio",cmd,"NOOP","EBIO");
- }
+void enter_bio(CtdlIPC *ipc)
+{
+ char cmd[SIZ];
+ snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
+ do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
+}
/*
* create a new floor
*/
-void create_floor(void) {
- char buf[256];
- char newfloorname[256];
+void create_floor(CtdlIPC *ipc)
+{
+ char buf[SIZ];
+ char newfloorname[SIZ];
+ int r; /* IPC response code */
- serv_puts("CFLR xx|0");
- serv_gets(buf);
- if (buf[0]!='2') {
- printf("%s\n",&buf[4]);
+ load_floorlist(ipc);
+
+ r = CtdlIPCCreateFloor(ipc, 0, "", buf);
+ if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
+ scr_printf("%s\n", buf);
return;
- }
+ }
- newprompt("Name for new floor: ",newfloorname,255);
- snprintf(buf,sizeof buf,"CFLR %s|1",newfloorname);
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0]=='2') {
- printf("Floor has been created.\n");
- }
- else {
- printf("%s\n",&buf[4]);
- }
+ newprompt("Name for new floor: ", newfloorname, 255);
+ if (!*newfloorname) return;
+ r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
+ if (r / 100 == 2) {
+ scr_printf("Floor has been created.\n");
+ } else {
+ scr_printf("%s\n", buf);
}
+ load_floorlist(ipc);
+}
+
/*
* edit the current floor
*/
-void edit_floor(void) {
- char buf[256];
- int expire_mode = 0;
- int expire_value = 0;
+void edit_floor(CtdlIPC *ipc)
+{
+ char buf[SIZ];
+ struct ExpirePolicy *ep = NULL;
+ int r; /* IPC response code */
- if (floorlist[(int)curr_floor][0]==0) load_floorlist();
+ load_floorlist(ipc);
/* Fetch the expire policy (this will silently fail on old servers,
* resulting in "default" policy)
*/
- serv_puts("GPEX floor");
- serv_gets(buf);
- if (buf[0]=='2') {
- expire_mode = extract_int(&buf[4], 0);
- expire_value = extract_int(&buf[4], 1);
- }
+ r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
/* Interact with the user */
- strprompt("Floor name",&floorlist[(int)curr_floor][0],255);
+ scr_printf("You are editing the floor called \"%s\"\n",
+ &floorlist[(int) curr_floor][0] );
+ strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
/* Angels and demons dancing in my head... */
do {
- sprintf(buf, "%d", expire_mode);
- strprompt("Floor default essage expire policy (? for list)",
- buf, 1);
+ snprintf(buf, sizeof buf, "%d", ep->expire_mode);
+ strprompt
+ ("Floor default message expire policy (? for list)",
+ buf, 1);
if (buf[0] == '?') {
- printf("\n");
- printf("0. Use the system default\n");
- printf("1. Never automatically expire messages\n");
- printf("2. Expire by message count\n");
- printf("3. Expire by message age\n");
- }
- } while((buf[0]<48)||(buf[0]>51));
- expire_mode = buf[0] - 48;
+ scr_printf("\n"
+ "0. Use the system default\n"
+ "1. Never automatically expire messages\n"
+ "2. Expire by message count\n"
+ "3. Expire by message age\n");
+ }
+ } while ((buf[0] < '0') || (buf[0] > '3'));
+ ep->expire_mode = buf[0] - '0';
/* ...lunatics and monsters underneath my bed */
- if (expire_mode == 2) {
- sprintf(buf, "%d", expire_value);
+ if (ep->expire_mode == 2) {
+ snprintf(buf, sizeof buf, "%d", ep->expire_value);
strprompt("Keep how many messages online?", buf, 10);
- expire_value = atol(buf);
- }
+ ep->expire_value = atol(buf);
+ }
- if (expire_mode == 3) {
- sprintf(buf, "%d", expire_value);
+ if (ep->expire_mode == 3) {
+ snprintf(buf, sizeof buf, "%d", ep->expire_value);
strprompt("Keep messages for how many days?", buf, 10);
- expire_value = atol(buf);
- }
+ ep->expire_value = atol(buf);
+ }
/* Save it */
- snprintf(buf, sizeof buf, "SPEX floor|%d|%d",
- expire_mode, expire_value);
- serv_puts(buf);
- serv_gets(buf);
-
- snprintf(buf,sizeof buf,"EFLR %d|%s",curr_floor,
- &floorlist[(int)curr_floor][0]);
- serv_puts(buf);
- serv_gets(buf);
- printf("%s\n",&buf[4]);
- load_floorlist();
- }
+ r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
+ r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
+ scr_printf("%s\n", buf);
+ load_floorlist(ipc);
+}
/*
* kill the current floor
*/
-void kill_floor(void) {
- int floornum_to_delete,a;
- char buf[256];
+void kill_floor(CtdlIPC *ipc)
+{
+ int floornum_to_delete, a;
+ char buf[SIZ];
- if (floorlist[(int)curr_floor][0]==0) load_floorlist();
+ load_floorlist(ipc);
do {
floornum_to_delete = (-1);
- printf("(Press return to abort)\n");
- newprompt("Delete which floor? ",buf,255);
- if (strlen(buf)==0) return;
- for (a=0; a<128; ++a)
- if (!strucmp(&floorlist[a][0],buf))
+ scr_printf("(Press return to abort)\n");
+ newprompt("Delete which floor? ", buf, 255);
+ if (strlen(buf) == 0)
+ return;
+ for (a = 0; a < 128; ++a)
+ if (!strcasecmp(&floorlist[a][0], buf))
floornum_to_delete = a;
if (floornum_to_delete < 0) {
- printf("No such floor. Select one of:\n");
- for (a=0; a<128; ++a)
- if (floorlist[a][0]!=0)
- printf("%s\n",&floorlist[a][0]);
- }
- } while (floornum_to_delete < 0);
- sprintf(buf,"KFLR %d|1",floornum_to_delete);
- serv_puts(buf);
- serv_gets(buf);
- printf("%s\n",&buf[4]);
- }
+ scr_printf("No such floor. Select one of:\n");
+ for (a = 0; a < 128; ++a)
+ if (floorlist[a][0] != 0)
+ scr_printf("%s\n", &floorlist[a][0]);
+ }
+ } while (floornum_to_delete < 0);
+ CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
+ scr_printf("%s\n", buf);
+ load_floorlist(ipc);
+}