From 9cfecc9db607a862e1220b96c1bec319bedecb8c Mon Sep 17 00:00:00 2001 From: Michael Hampton Date: Fri, 27 Sep 2002 06:53:20 +0000 Subject: [PATCH] * Allow multiple simultaneous IPC connections. All changes necessary for the client to use the new code are necessarily included. --- citadel/ChangeLog | 5 + citadel/Makefile.in | 16 +- citadel/citadel.c | 394 +++++++++++++++-------------- citadel/citadel.h | 8 + citadel/citadel_decls.h | 5 +- citadel/citadel_ipc.c | 506 ++++++++++++++++++++----------------- citadel/citadel_ipc.h | 197 ++++++++------- citadel/citmail.c | 2 - citadel/client_chat.c | 122 ++++----- citadel/client_chat.h | 8 +- citadel/client_crypto.c | 132 +++++----- citadel/client_crypto.h | 26 +- citadel/client_passwords.c | 3 +- citadel/commands.c | 31 ++- citadel/commands.h | 5 +- citadel/ipc.h | 69 ++++- citadel/ipc_c_tcp.c | 149 +++++++---- citadel/messages.c | 110 ++++---- citadel/messages.h | 13 +- citadel/migratenet.c | 72 +++--- citadel/rooms.c | 271 ++++++++++---------- citadel/rooms.h | 40 +-- citadel/routines.c | 53 ++-- citadel/routines.h | 6 +- citadel/routines2.c | 217 ++++++++-------- citadel/routines2.h | 33 +-- citadel/screen.c | 3 +- citadel/sendcommand.c | 28 +- citadel/stats.c | 13 +- citadel/userlist.c | 46 ++-- citadel/whobbs.c | 12 +- 31 files changed, 1372 insertions(+), 1223 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 552bb63f6..ba660c009 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,8 @@ $Log$ + Revision 601.9 2002/09/27 06:53:20 error + * Allow multiple simultaneous IPC connections. All changes necessary for + the client to use the new code are necessarily included. + Revision 601.8 2002/09/22 02:48:04 ajc * axdefs.h: add "Notes" view @@ -4012,3 +4016,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/Makefile.in b/citadel/Makefile.in index c2e82861e..e308160e6 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -228,18 +228,18 @@ chkpwd: chkpwd.o auth.o config.o whobbs$(EXEEXT): whobbs.o ipc_c_tcp.o tools.o client_crypto.o citadel_ipc.o $(LIBOBJS) $(CC) whobbs.o ipc_c_tcp.o tools.o client_crypto.o citadel_ipc.o $(LIBOBJS) $(LDFLAGS) -o whobbs $(LIBS) -migratenet$(EXEEXT): migratenet.o config.o ipc_c_tcp.o client_crypto.o tools.o libcitserver.la $(LIBOBJS) - $(LIBTOOL) $(CC) migratenet.o config.o ipc_c_tcp.o client_crypto.o tools.o libcitserver.la $(LIBOBJS) $(LDFLAGS) -o migratenet $(LIBS) +migratenet$(EXEEXT): migratenet.o config.o ipc_c_tcp.o client_crypto.o citadel_ipc.o tools.o libcitserver.la $(LIBOBJS) + $(LIBTOOL) $(CC) migratenet.o config.o ipc_c_tcp.o client_crypto.o citadel_ipc.o tools.o libcitserver.la $(LIBOBJS) $(LDFLAGS) -o migratenet $(LIBS) -sendcommand: sendcommand.o ipc_c_tcp.o client_crypto.o libcitserver.la $(LIBOBJS) - $(LIBTOOL) $(CC) sendcommand.o ipc_c_tcp.o client_crypto.o libcitserver.la \ +sendcommand: sendcommand.o ipc_c_tcp.o client_crypto.o citadel_ipc.o libcitserver.la $(LIBOBJS) + $(LIBTOOL) $(CC) sendcommand.o ipc_c_tcp.o client_crypto.o citadel_ipc.o libcitserver.la \ $(LIBOBJS) $(LDFLAGS) -o sendcommand $(LIBS) base64: base64.o $(CC) base64.o $(LDFLAGS) -o base64 -userlist: userlist.o ipc_c_tcp.o client_crypto.o tools.o $(LIBOBJS) - $(CC) userlist.o ipc_c_tcp.o client_crypto.o tools.o \ +userlist: userlist.o ipc_c_tcp.o client_crypto.o citadel_ipc.o tools.o $(LIBOBJS) + $(CC) userlist.o ipc_c_tcp.o client_crypto.o citadel_ipc.o tools.o \ $(LIBOBJS) $(LDFLAGS) -o userlist $(LIBS) msgform: msgform.o @@ -248,8 +248,8 @@ msgform: msgform.o readlog: readlog.o config.o $(CC) readlog.o config.o $(LDFLAGS) -o readlog -stats: stats.o ipc_c_tcp.o client_crypto.o libcitserver.la $(LIBOBJS) - $(LIBTOOL) $(CC) stats.o ipc_c_tcp.o client_crypto.o libcitserver.la $(LIBOBJS) $(LDFLAGS) -o stats $(LIBS) +stats: stats.o ipc_c_tcp.o client_crypto.o citadel_ipc.o libcitserver.la $(LIBOBJS) + $(LIBTOOL) $(CC) stats.o ipc_c_tcp.o client_crypto.o citadel_ipc.o libcitserver.la $(LIBOBJS) $(LDFLAGS) -o stats $(LIBS) .PHONY: install-data install-doc install-exec clean cleaner distclean diff --git a/citadel/citadel.c b/citadel/citadel.c index fd7ae878b..7ad8d3397 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -34,14 +34,13 @@ #include #include "citadel.h" +#include "citadel_ipc.h" #include "axdefs.h" #include "routines.h" #include "routines2.h" #include "rooms.h" #include "messages.h" #include "commands.h" -#include "ipc.h" -#include "citadel_ipc.h" #include "client_chat.h" #include "client_passwords.h" #include "citadel_decls.h" @@ -108,10 +107,12 @@ extern char express_msgs; /* express messages waiting! */ extern int rc_ansi_color; /* ansi color value from citadel.rc */ extern int next_lazy_cmd; +CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */ + /* * here is our 'clean up gracefully and exit' routine */ -void logoff(int code) +void logoff(CtdlIPC *ipc, int code) { int lp; if (editor_pid > 0) { /* kill the editor if it's running */ @@ -126,7 +127,7 @@ void logoff(int code) * that means we're exiting because we already lost the server */ if (code != 3) - CtdlIPCQuit(); + CtdlIPCQuit(ipc); /* * now clean up various things @@ -146,6 +147,7 @@ void logoff(int code) sleep(1); kill(0 - getpgrp(), SIGKILL); } + color(ORIGINAL_PAIR); /* Restore the old color settings */ sttybbs(SB_RESTORE); /* return the old terminal settings */ exit(code); /* exit with the proper exit code */ } @@ -157,7 +159,7 @@ void logoff(int code) */ void dropcarr(int signum) { - logoff(SIGHUP); + logoff(NULL, 3); /* No IPC when server's already gone! */ } @@ -176,13 +178,13 @@ void catch_sigcont(int signum) /* general purpose routines */ /* display a file */ -void formout(char *name) +void formout(CtdlIPC *ipc, char *name) { int r; /* IPC return code */ char buf[SIZ]; char *text = NULL; - r = CtdlIPCSystemMessage(name, &text, buf); + r = CtdlIPCSystemMessage(ipc, name, &text, buf); if (r / 100 != 1) { scr_printf("%s\n", buf); return; @@ -196,7 +198,7 @@ void formout(char *name) } -void userlist(char *patn) +void userlist(CtdlIPC *ipc, char *patn) { char buf[SIZ]; char fl[SIZ]; @@ -205,7 +207,7 @@ void userlist(char *patn) int r; /* IPC response code */ char *listing = NULL; - r = CtdlIPCUserListing(&listing, buf); + r = CtdlIPCUserListing(ipc, &listing, buf); if (r / 100 != 1) { pprintf("%s\n", buf); return; @@ -331,7 +333,7 @@ char *pop_march(int desired_floor) /* * jump directly to a room */ -void dotgoto(char *towhere, int display_name, int fromungoto) +void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto) { char aaa[SIZ], bbb[SIZ], psearch[SIZ]; static long ls = 0L; @@ -362,10 +364,10 @@ void dotgoto(char *towhere, int display_name, int fromungoto) } /* first try an exact match */ - r = CtdlIPCGotoRoom(towhere, "", &roomrec, aaa); + r = CtdlIPCGotoRoom(ipc, towhere, "", &roomrec, aaa); if (r / 10 == 54) { newprompt("Enter room password: ", bbb, 9); - r = CtdlIPCGotoRoom(towhere, bbb, &roomrec, aaa); + r = CtdlIPCGotoRoom(ipc, towhere, bbb, &roomrec, aaa); if (r / 10 == 54) { scr_printf("Wrong password.\n"); return; @@ -381,10 +383,10 @@ void dotgoto(char *towhere, int display_name, int fromungoto) if (r / 100 != 2) { best_match = 0; strcpy(bbb, ""); - serv_puts("LKRA"); - serv_gets(aaa); + CtdlIPC_putline(ipc, "LKRA"); + CtdlIPC_getline(ipc, aaa); if (aaa[0] == '1') - while (serv_gets(aaa), strcmp(aaa, "000")) { + while (CtdlIPC_getline(ipc, aaa), strcmp(aaa, "000")) { extract(psearch, aaa, 0); partial_match = 0; if (pattern(psearch, towhere) >= 0) { @@ -403,7 +405,7 @@ void dotgoto(char *towhere, int display_name, int fromungoto) return; } roomrec = NULL; - r = CtdlIPCGotoRoom(bbb, "", &roomrec, aaa); + r = CtdlIPCGotoRoom(ipc, bbb, "", &roomrec, aaa); } if (r / 100 != 2) { scr_printf("%s\n", aaa); @@ -421,7 +423,7 @@ void dotgoto(char *towhere, int display_name, int fromungoto) next_lazy_cmd = 5; /* Don't read new if no new msgs */ if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) { if (floorlist[(int) curr_floor][0] == 0) - load_floorlist(); + load_floorlist(ipc); scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]); } if (display_name == 1) { @@ -448,7 +450,7 @@ void dotgoto(char *towhere, int display_name, int fromungoto) /* read info file if necessary */ if (roomrec->RRinfoupdated > 0) - readinfo(); + readinfo(ipc); /* check for newly arrived mail if we can */ newmailcount = roomrec->RRnewmail; @@ -475,7 +477,7 @@ void dotgoto(char *towhere, int display_name, int fromungoto) * user back to the lobby when done. The room we end up in is placed in * newroom - which is set to 0 (the lobby) initially. */ -void gotonext(void) +void gotonext(CtdlIPC *ipc) { char buf[SIZ]; struct march *mptr, *mptr2; @@ -486,7 +488,7 @@ void gotonext(void) * If it is, pop the first room off the list and go there. */ if (march == NULL) { - r = CtdlIPCKnownRooms(1, -1, &march, buf); + r = CtdlIPCKnownRooms(ipc, 1, -1, &march, buf); /* add _BASEROOM_ to the end of the march list, so the user will end up * in the system base room (usually the Lobby>) at the end of the loop */ @@ -513,13 +515,13 @@ void gotonext(void) strcpy(next_room, "_BASEROOM_"); } remove_march(next_room, 0); - dotgoto(next_room, 1, 0); + dotgoto(ipc, next_room, 1, 0); } /* * forget all rooms on a given floor */ -void forget_all_rooms_on(int ffloor) +void forget_all_rooms_on(CtdlIPC *ipc, int ffloor) { char buf[SIZ]; struct march *flist, *fptr; @@ -529,23 +531,23 @@ void forget_all_rooms_on(int ffloor) scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]); scr_flush(); snprintf(buf, sizeof buf, "LKRA %d", ffloor); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { scr_printf("%-72s\n", &buf[4]); return; } flist = NULL; - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { fptr = (struct march *) malloc(sizeof(struct march)); fptr->next = flist; flist = fptr; extract(fptr->march_name, buf, 0); } while (flist != NULL) { - r = CtdlIPCGotoRoom(flist->march_name, "", &roomrec, buf); + r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &roomrec, buf); if (r / 100 == 2) { - r = CtdlIPCForgetRoom(buf); + r = CtdlIPCForgetRoom(ipc, buf); } fptr = flist; flist = flist->next; @@ -558,24 +560,24 @@ void forget_all_rooms_on(int ffloor) /* * routine called by gotofloor() to move to a new room on a new floor */ -void gf_toroom(char *towhere, int mode) +void gf_toroom(CtdlIPC *ipc, char *towhere, int mode) { int floor_being_left; floor_being_left = curr_floor; if (mode == GF_GOTO) { /* <;G>oto mode */ - updatels(); - dotgoto(towhere, 1, 0); + updatels(ipc); + dotgoto(ipc, towhere, 1, 0); } if (mode == GF_SKIP) { /* <;S>kip mode */ - dotgoto(towhere, 1, 0); + dotgoto(ipc, towhere, 1, 0); remove_march("_FLOOR_", floor_being_left); } if (mode == GF_ZAP) { /* <;Z>ap mode */ - dotgoto(towhere, 1, 0); + dotgoto(ipc, towhere, 1, 0); remove_march("_FLOOR_", floor_being_left); - forget_all_rooms_on(floor_being_left); + forget_all_rooms_on(ipc, floor_being_left); } } @@ -583,14 +585,14 @@ void gf_toroom(char *towhere, int mode) /* * go to a new floor */ -void gotofloor(char *towhere, int mode) +void gotofloor(CtdlIPC *ipc, char *towhere, int mode) { int a, tofloor; struct march *mptr; char buf[SIZ], targ[SIZ]; if (floorlist[0][0] == 0) - load_floorlist(); + load_floorlist(ipc); tofloor = (-1); for (a = 0; a < 128; ++a) if (!strcasecmp(&floorlist[a][0], towhere)) @@ -614,21 +616,21 @@ void gotofloor(char *towhere, int mode) } for (mptr = march; mptr != NULL; mptr = mptr->next) { if ((mptr->march_floor) == tofloor) - gf_toroom(mptr->march_name, mode); + gf_toroom(ipc, mptr->march_name, mode); return; } strcpy(targ, ""); snprintf(buf, sizeof buf, "LKRA %d", tofloor); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] == '1') - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0)) extract(targ, buf, 0); } if (strlen(targ) > 0) { - gf_toroom(targ, mode); + gf_toroom(ipc, targ, mode); } else { scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]); } @@ -638,7 +640,7 @@ void gotofloor(char *towhere, int mode) /* * forget all rooms on current floor */ -void forget_this_floor(void) +void forget_this_floor(CtdlIPC *ipc) { if (curr_floor == 0) { @@ -646,13 +648,13 @@ void forget_this_floor(void) return; } if (floorlist[0][0] == 0) - load_floorlist(); + load_floorlist(ipc); scr_printf("Are you sure you want to forget all rooms on %s? ", &floorlist[(int) curr_floor][0]); if (yesno() == 0) return; - gf_toroom("_BASEROOM_", GF_ZAP); + gf_toroom(ipc, "_BASEROOM_", GF_ZAP); } @@ -707,7 +709,7 @@ void set_floor_mode(void) /* * Set or change the user's password */ -int set_password(void) +int set_password(CtdlIPC *ipc) { char pass1[20]; char pass2[20]; @@ -717,14 +719,14 @@ int set_password(void) strcpy(pass1, rc_password); strcpy(pass2, rc_password); } else { - IFNEXPERT formout("changepw"); + IFNEXPERT formout(ipc, "changepw"); newprompt("Enter a new password: ", pass1, -19); newprompt("Enter it again to confirm: ", pass2, -19); } strproc(pass1); strproc(pass2); if (!strcasecmp(pass1, pass2)) { - CtdlIPCChangePassword(pass1, buf); + CtdlIPCChangePassword(ipc, pass1, buf); scr_printf("%s\n", buf); offer_to_remember_password(hostbuf, portbuf, fullname, pass1); return (0); @@ -739,20 +741,20 @@ int set_password(void) /* * get info about the server we've connected to */ -void get_serv_info(char *supplied_hostname) +void get_serv_info(CtdlIPC *ipc, char *supplied_hostname) { char buf[SIZ]; - CtdlIPCServerInfo(&serv_info, buf); + CtdlIPCServerInfo(ipc, &serv_info, buf); /* be nice and identify ourself to the server */ - CtdlIPCIdentifySoftware(SERVER_TYPE, 0, REV_LEVEL, - (server_is_local ? "local" : CITADEL), + CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL, + (ipc->isLocal ? "local" : CITADEL), (supplied_hostname) ? supplied_hostname : "", buf); /* (locate_host(buf), buf)); */ /* Tell the server what our preferred content formats are */ - if ((CtdlIPCSpecifyPreferredFormats(buf, "text/html|text/plain") / 100 )== 2) { + if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) { can_do_msg4 = 1; } } @@ -764,7 +766,7 @@ void get_serv_info(char *supplied_hostname) /* * Display list of users currently logged on to the server */ -void who_is_online(int longlist) +void who_is_online(CtdlIPC *ipc, int longlist) { char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ]; char flags[SIZ]; @@ -788,7 +790,7 @@ void who_is_online(int longlist) color(DIM_WHITE); pprintf("--- --- ------------------------- -------------------- ------------------------\n"); } - r = CtdlIPCOnlineUsers(&listing, &timenow, buf); + r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf); if (r / 100 == 1) { while (strlen(listing) > 0) { int isidle = 0; @@ -869,7 +871,7 @@ void who_is_online(int longlist) free(listing); } -void enternew(char *desc, char *buf, int maxlen) +void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen) { char bbb[128]; snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc); @@ -909,6 +911,7 @@ int main(int argc, char **argv) char password[SIZ]; struct ctdlipcmisc chek; struct usersupp *myself = NULL; + CtdlIPC* ipc; /* Our server connection */ int r; /* IPC result code */ setIPCDeathHook(screen_delete); @@ -918,10 +921,10 @@ int main(int argc, char **argv) /* Permissions sanity check - don't run citadel setuid/setgid */ if (getuid() != geteuid()) { err_printf("Please do not run citadel setuid!\n"); - logoff(3); + logoff(NULL, 3); } else if (getgid() != getegid()) { err_printf("Please do not run citadel setgid!\n"); - logoff(3); + logoff(NULL, 3); } sttybbs(SB_SAVE); /* Store the old terminal parameters */ @@ -982,7 +985,7 @@ int main(int argc, char **argv) if (chdir(BBSDIR) < 0) { perror("can't change to " BBSDIR); - logoff(3); + logoff(NULL, 3); } /* @@ -993,15 +996,15 @@ int main(int argc, char **argv) if (!getuid() || !getgid()) { if (stat(BBSDIR "/citadel.config", &st) < 0) { perror("couldn't stat citadel.config"); - logoff(3); + logoff(NULL, 3); } if (!getgid() && (setgid(st.st_gid) < 0)) { perror("couldn't change gid"); - logoff(3); + logoff(NULL, 3); } if (!getuid() && (setuid(st.st_uid) < 0)) { perror("couldn't change uid"); - logoff(3); + logoff(NULL, 3); } /* scr_printf("Privileges changed to uid %d gid %d\n", @@ -1016,12 +1019,13 @@ int main(int argc, char **argv) sln_printf("Attaching to server... \r"); sln_flush(); - attach_to_server(argc, argv, hostbuf, portbuf); + ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf); + ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */ - serv_gets(aaa); + CtdlIPC_getline(ipc, aaa); if (aaa[0] != '2') { scr_printf("%s\n", &aaa[4]); - logoff(atoi(aaa)); + logoff(ipc, atoi(aaa)); } /* If there is a [nonce] at the end, put the nonce in , else nonce @@ -1046,13 +1050,13 @@ int main(int argc, char **argv) } } - get_serv_info(telnet_client_host); + get_serv_info(ipc, telnet_client_host); scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode, serv_info.serv_bbs_city); scr_flush(); - secure = starttls(); + secure = starttls(ipc); status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL, secure, -1); @@ -1061,7 +1065,7 @@ int main(int argc, char **argv) scr_printf(" pause next stop\n"); scr_printf(" ctrl-s ctrl-o ctrl-c\n\n"); - formout("hello"); /* print the opening greeting */ + formout(ipc, "hello"); /* print the opening greeting */ scr_printf("\n"); GSTA: /* See if we have a username and password on disk */ @@ -1069,8 +1073,8 @@ GSTA: /* See if we have a username and password on disk */ get_stored_password(hostbuf, portbuf, fullname, password); if (strlen(fullname) > 0) { snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname); - serv_puts(aaa); - serv_gets(aaa); + CtdlIPC_putline(ipc, aaa); + CtdlIPC_getline(ipc, aaa); if (nonce[0]) { snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring)); @@ -1080,8 +1084,8 @@ GSTA: /* See if we have a username and password on disk */ snprintf(aaa, sizeof(aaa)-1, "PASS %s", password); } - serv_puts(aaa); - serv_gets(aaa); + CtdlIPC_putline(ipc, aaa); + CtdlIPC_getline(ipc, aaa); if (aaa[0] == '2') { load_user_info(&aaa[4]); stored_password = 1; @@ -1115,7 +1119,7 @@ GSTA: /* See if we have a username and password on disk */ goto TERMN8; } /* sign on to the server */ - r = CtdlIPCTryLogin(fullname, aaa); + r = CtdlIPCTryLogin(ipc, fullname, aaa); if (r / 100 != 3) goto NEWUSR; @@ -1136,8 +1140,8 @@ GSTA: /* See if we have a username and password on disk */ snprintf(aaa, sizeof aaa, "PASS %s", password); } - serv_puts(aaa); - serv_gets(aaa); + CtdlIPC_putline(ipc, aaa); + CtdlIPC_getline(ipc, aaa); if (aaa[0] == '2') { load_user_info(&aaa[4]); offer_to_remember_password(hostbuf, portbuf, @@ -1146,7 +1150,7 @@ GSTA: /* See if we have a username and password on disk */ } scr_printf("<< wrong password >>\n"); if (strlen(rc_password) > 0) - logoff(0); + logoff(ipc, 0); goto GSTA; NEWUSR: if (strlen(rc_password) == 0) { @@ -1155,18 +1159,18 @@ NEWUSR: if (strlen(rc_password) == 0) { goto GSTA; } snprintf(aaa, sizeof aaa, "NEWU %s", fullname); - serv_puts(aaa); - serv_gets(aaa); + CtdlIPC_putline(ipc, aaa); + CtdlIPC_getline(ipc, aaa); if (aaa[0] != '2') { scr_printf("%s\n", aaa); goto GSTA; } load_user_info(&aaa[4]); - while (set_password() != 0);; + while (set_password(ipc) != 0);; newnow = 1; - enter_config(1); + enter_config(ipc, 1); PWOK: /* Switch color support on or off if we're in user mode */ @@ -1187,7 +1191,7 @@ PWOK: } scr_printf("\n"); - r = CtdlIPCMiscCheck(&chek, aaa); + r = CtdlIPCMiscCheck(ipc, &chek, aaa); if (r / 100 == 2) { b = chek.newmail; if (b > 0) { @@ -1206,8 +1210,8 @@ PWOK: } if (chek.needregis > 0) { scr_printf("*** Please register.\n"); - formout("register"); - entregis(); + formout(ipc, "register"); + entregis(ipc); } } /* Make up some temporary filenames for use in various parts of the @@ -1226,7 +1230,7 @@ PWOK: */ screenwidth = 80; screenheight = 24; - r = CtdlIPCGetConfig(&myself, aaa); + r = CtdlIPCGetConfig(ipc, &myself, aaa); if (r == 2) { screenwidth = myself->USscreenwidth; screenheight = myself->USscreenheight; @@ -1243,19 +1247,19 @@ PWOK: /* Enter the lobby */ - dotgoto("_BASEROOM_", 1, 0); + dotgoto(ipc, "_BASEROOM_", 1, 0); /* Main loop for the system... user is logged in. */ uglistsize = 0; if (newnow == 1) - readmsgs(3, 1, 5); + readmsgs(ipc, 3, 1, 5); else - readmsgs(1, 1, 0); + readmsgs(ipc, 1, 1, 0); /* MAIN COMMAND LOOP */ do { - mcmd = getcmd(argbuf); /* Get keyboard command */ + mcmd = getcmd(ipc, argbuf); /* Get keyboard command */ #ifdef TIOCGWINSZ check_screen_dims(); /* if xterm, get screen size */ @@ -1264,208 +1268,208 @@ PWOK: if (termn8 == 0) switch (mcmd) { case 1: - formout("help"); + formout(ipc, "help"); break; case 4: - entmsg(0, 0); + entmsg(ipc, 0, 0); break; case 36: - entmsg(0, 1); + entmsg(ipc, 0, 1); break; case 46: - entmsg(0, 2); + entmsg(ipc, 0, 2); break; case 78: newprompt("What do you want your username to be? ", aaa, 32); snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa); - serv_puts(bbb); - serv_gets(aaa); + CtdlIPC_putline(ipc, bbb); + CtdlIPC_getline(ipc, aaa); if (strncmp("200", aaa, 3)) scr_printf("\n%s\n", aaa); else - entmsg(0, 0); + entmsg(ipc, 0, 0); break; case 5: - updatels(); - gotonext(); + updatels(ipc); + gotonext(ipc); break; case 47: if (!rc_alt_semantics) - updatelsa(); - gotonext(); + updatelsa(ipc); + gotonext(ipc); break; case 90: if (!rc_alt_semantics) - updatelsa(); - dotgoto(argbuf, 0, 0); + updatelsa(ipc); + dotgoto(ipc, argbuf, 0, 0); break; case 58: - updatelsa(); - dotgoto("_MAIL_", 1, 0); + updatelsa(ipc); + dotgoto(ipc, "_MAIL_", 1, 0); break; case 20: - updatels(); - dotgoto(argbuf, 0, 0); + updatels(ipc); + dotgoto(ipc, argbuf, 0, 0); break; case 52: if (rc_alt_semantics) - updatelsa(); - dotgoto(argbuf, 0, 0); + updatelsa(ipc); + dotgoto(ipc, argbuf, 0, 0); break; case 10: - readmsgs(0, 1, 0); + readmsgs(ipc, 0, 1, 0); break; case 9: - readmsgs(3, 1, 5); + readmsgs(ipc, 3, 1, 5); break; case 13: - readmsgs(1, 1, 0); + readmsgs(ipc, 1, 1, 0); break; case 11: - readmsgs(0, (-1), 0); + readmsgs(ipc, 0, (-1), 0); break; case 12: - readmsgs(2, (-1), 0); + readmsgs(ipc, 2, (-1), 0); break; case 71: - readmsgs(3, 1, atoi(argbuf)); + readmsgs(ipc, 3, 1, atoi(argbuf)); break; case 7: - forget(); + forget(ipc); break; case 18: subshell(); break; case 38: - updatels(); - entroom(); + updatels(ipc); + entroom(ipc); break; case 22: - killroom(); + killroom(ipc); break; case 32: - userlist(argbuf); + userlist(ipc, argbuf); break; case 27: - invite(); + invite(ipc); break; case 28: - kickout(); + kickout(ipc); break; case 23: - editthisroom(); + editthisroom(ipc); break; case 14: - roomdir(); + roomdir(ipc); break; case 33: - download(0); + download(ipc, 0); break; case 34: - download(1); + download(ipc, 1); break; case 31: - download(2); + download(ipc, 2); break; case 43: - download(3); + download(ipc, 3); break; case 45: - download(4); + download(ipc, 4); break; case 55: - download(5); + download(ipc, 5); break; case 39: - upload(0); + upload(ipc, 0); break; case 40: - upload(1); + upload(ipc, 1); break; case 42: - upload(2); + upload(ipc, 2); break; case 44: - upload(3); + upload(ipc, 3); break; case 57: - cli_upload(); + cli_upload(ipc); break; case 16: - ungoto(); + ungoto(ipc); break; case 24: - whoknows(); + whoknows(ipc); break; case 26: - validate(); + validate(ipc); break; case 29: if (!rc_alt_semantics) - updatels(); + updatels(ipc); termn8 = 1; break; case 30: if (!rc_alt_semantics) - updatels(); + updatels(ipc); termn8 = 1; break; case 48: - enterinfo(); + enterinfo(ipc); break; case 49: - readinfo(); + readinfo(ipc); break; case 72: - cli_image_upload("_userpic_"); + cli_image_upload(ipc, "_userpic_"); break; case 73: - cli_image_upload("_roompic_"); + cli_image_upload(ipc, "_roompic_"); break; case 74: snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor); - cli_image_upload(aaa); + cli_image_upload(ipc, aaa); break; case 75: - enternew("roomname", aaa, 20); - r = CtdlIPCChangeRoomname(aaa, bbb); + enternew(ipc, "roomname", aaa, 20); + r = CtdlIPCChangeRoomname(ipc, aaa, bbb); if (r / 100 != 2) scr_printf("\n%s\n", aaa); break; case 76: - enternew("hostname", aaa, 25); - r = CtdlIPCChangeHostname(aaa, bbb); + enternew(ipc, "hostname", aaa, 25); + r = CtdlIPCChangeHostname(ipc, aaa, bbb); if (r / 100 != 2) scr_printf("\n%s\n", aaa); break; case 77: - enternew("username", aaa, 32); - r = CtdlIPCChangeUsername(aaa, bbb); + enternew(ipc, "username", aaa, 32); + r = CtdlIPCChangeUsername(ipc, aaa, bbb); if (r / 100 != 2) scr_printf("\n%s\n", aaa); break; case 35: - set_password(); + set_password(ipc); break; case 21: if (argbuf[0] == 0) strcpy(aaa, "?"); - display_help(argbuf); + display_help(ipc, argbuf); break; case 41: - formout("register"); - entregis(); + formout(ipc, "register"); + entregis(ipc); break; case 15: scr_printf("Are you sure (y/n)? "); if (yesno() == 1) { - updatels(); + updatels(ipc); a = 0; termn8 = 1; } @@ -1475,10 +1479,10 @@ PWOK: scr_printf("All users will be disconnected! " "Really terminate the server? "); if (yesno() == 1) { - r = CtdlIPCTerminateServerNow(aaa); + r = CtdlIPCTerminateServerNow(ipc, aaa); scr_printf("%s\n", aaa); if (r / 100 == 2) { - updatels(); + updatels(ipc); a = 0; termn8 = 1; } @@ -1489,7 +1493,7 @@ PWOK: scr_printf("Do you really want to schedule a " "server shutdown? "); if (yesno() == 1) { - r = CtdlIPCTerminateServerScheduled(1, aaa); + r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa); if (r / 100 == 2) { if (atoi(aaa)) { scr_printf( @@ -1505,40 +1509,40 @@ PWOK: break; case 87: - network_config_management("listrecp", + network_config_management(ipc, "listrecp", "Message-by-message mailing list recipients"); break; case 94: - network_config_management("digestrecp", + network_config_management(ipc, "digestrecp", "Digest mailing list recipients"); break; case 89: - network_config_management("ignet_push_share", + network_config_management(ipc, "ignet_push_share", "Nodes with which we share this room"); break; case 88: - do_ignet_configuration(); + do_ignet_configuration(ipc); break; case 92: - do_filterlist_configuration(); + do_filterlist_configuration(ipc); break; case 6: if (rc_alt_semantics) - updatelsa(); - gotonext(); + updatelsa(ipc); + gotonext(ipc); break; case 3: - chatmode(); + chatmode(ipc); break; case 2: - if (server_is_local) { + if (ipc->isLocal) { screen_reset(); sttybbs(SB_RESTORE); snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;" @@ -1553,99 +1557,99 @@ PWOK: break; case 17: - who_is_online(0); + who_is_online(ipc, 0); break; case 79: - who_is_online(1); + who_is_online(ipc, 1); break; case 91: - who_is_online(2); + who_is_online(ipc, 2); break; case 80: - do_system_configuration(); + do_system_configuration(ipc); break; case 82: - do_internet_configuration(); + do_internet_configuration(ipc); break; case 83: - check_message_base(); + check_message_base(ipc); break; case 84: - quiet_mode(); + quiet_mode(ipc); break; case 93: - stealth_mode(); + stealth_mode(ipc); break; case 50: - enter_config(2); + enter_config(ipc, 2); break; case 37: - enter_config(0); + enter_config(ipc, 0); set_floor_mode(); break; case 59: - enter_config(3); + enter_config(ipc, 3); set_floor_mode(); break; case 60: - gotofloor(argbuf, GF_GOTO); + gotofloor(ipc, argbuf, GF_GOTO); break; case 61: - gotofloor(argbuf, GF_SKIP); + gotofloor(ipc, argbuf, GF_SKIP); break; case 62: - forget_this_floor(); + forget_this_floor(ipc); break; case 63: - create_floor(); + create_floor(ipc); break; case 64: - edit_floor(); + edit_floor(ipc); break; case 65: - kill_floor(); + kill_floor(ipc); break; case 66: - enter_bio(); + enter_bio(ipc); break; case 67: - read_bio(); + read_bio(ipc); break; case 25: - edituser(); + edituser(ipc); break; case 8: - knrooms(floor_mode); + knrooms(ipc, floor_mode); scr_printf("\n"); break; case 68: - knrooms(2); + knrooms(ipc, 2); scr_printf("\n"); break; case 69: - misc_server_cmd(argbuf); + misc_server_cmd(ipc, argbuf); break; case 70: @@ -1653,24 +1657,24 @@ PWOK: break; case 19: - listzrooms(); + listzrooms(ipc); scr_printf("\n"); break; case 51: - deletefile(); + deletefile(ipc); break; case 53: - netsendfile(); + netsendfile(ipc); break; case 54: - movefile(); + movefile(ipc); break; case 56: - page_user(); + page_user(ipc); break; } /* end switch */ @@ -1683,12 +1687,12 @@ TERMN8: scr_printf("%s logged out.\n", fullname); if (mcmd == 30) { sln_printf("\n\nType 'off' to disconnect, or next user...\n"); } - CtdlIPCLogout(); + CtdlIPCLogout(ipc); if ((mcmd == 29) || (mcmd == 15)) { screen_delete(); sttybbs(SB_RESTORE); - formout("goodbye"); - logoff(0); + formout(ipc, "goodbye"); + logoff(ipc, 0); } goto GSTA; diff --git a/citadel/citadel.h b/citadel/citadel.h index 311288389..ed51301c2 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -15,6 +15,10 @@ #include "sysconfig.h" #include "ipcdef.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Text description of this software */ @@ -309,4 +313,8 @@ enum { #define VIEW_MAILBOX 1 /* Mailbox summary */ #define VIEW_ADDRESSBOOK 2 /* Address book view */ +#ifdef __cplusplus +} +#endif + #endif /* CITADEL_H */ diff --git a/citadel/citadel_decls.h b/citadel/citadel_decls.h index b66c8e1ff..371aa5de6 100644 --- a/citadel/citadel_decls.h +++ b/citadel/citadel_decls.h @@ -24,9 +24,8 @@ extern char arg_screen; #endif extern char rc_alt_semantics; extern char express_msgs; -void logoff(int code); -void formout(char *name); +void logoff(CtdlIPC *ipc, int code); +void formout(CtdlIPC *ipc, char *name); void sighandler(int which_sig); -void do_system_configuration(void); extern int secure; extern int can_do_msg4; diff --git a/citadel/citadel_ipc.c b/citadel/citadel_ipc.c index 6ca729fff..7c7193a96 100644 --- a/citadel/citadel_ipc.c +++ b/citadel/citadel_ipc.c @@ -39,11 +39,11 @@ static volatile int upload_in_progress = 0; /* upload file open */ /* * Does nothing. The server should always return 200. */ -int CtdlIPCNoop(void) +int CtdlIPCNoop(CtdlIPC *ipc) { char aaa[128]; - return CtdlIPCGenericCommand("NOOP", NULL, 0, NULL, NULL, aaa); + return CtdlIPCGenericCommand(ipc, "NOOP", NULL, 0, NULL, NULL, aaa); } @@ -51,7 +51,7 @@ int CtdlIPCNoop(void) * Does nothing interesting. The server should always return 200 * along with your string. */ -int CtdlIPCEcho(const char *arg, char *cret) +int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret) { register int ret; char *aaa; @@ -63,7 +63,7 @@ int CtdlIPCEcho(const char *arg, char *cret) if (!aaa) return -1; sprintf(aaa, "ECHO %s", arg); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -73,16 +73,16 @@ int CtdlIPCEcho(const char *arg, char *cret) * Asks the server to close the connecction. * Should always return 200. */ -int CtdlIPCQuit(void) +int CtdlIPCQuit(CtdlIPC *ipc) { register int ret; char aaa[128]; - netio_lock(); - serv_puts("QUIT"); - serv_gets(aaa); + CtdlIPC_lock(ipc); + CtdlIPC_putline(ipc, "QUIT"); + CtdlIPC_getline(ipc, aaa); ret = atoi(aaa); - netio_unlock(); + CtdlIPC_unlock(ipc); return ret; } @@ -91,16 +91,16 @@ int CtdlIPCQuit(void) * Asks the server to logout. Should always return 200, even if no user * was logged in. The user will not be logged in after this! */ -int CtdlIPCLogout(void) +int CtdlIPCLogout(CtdlIPC *ipc) { register int ret; char aaa[128]; - netio_lock(); - serv_puts("LOUT"); - serv_gets(aaa); + CtdlIPC_lock(ipc); + CtdlIPC_putline(ipc, "LOUT"); + CtdlIPC_getline(ipc, aaa); ret = atoi(aaa); - netio_unlock(); + CtdlIPC_unlock(ipc); return ret; } @@ -110,7 +110,7 @@ int CtdlIPCLogout(void) * username is able to log in, with the username correctly spelled in cret. * Returns various 500 error codes if the user doesn't exist, etc. */ -int CtdlIPCTryLogin(const char *username, char *cret) +int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret) { register int ret; char *aaa; @@ -122,7 +122,7 @@ int CtdlIPCTryLogin(const char *username, char *cret) if (!aaa) return -1; sprintf(aaa, "USER %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -132,7 +132,7 @@ int CtdlIPCTryLogin(const char *username, char *cret) * Second stage of authentication - provide password. The server returns * 200 and several arguments in cret relating to the user's account. */ -int CtdlIPCTryPassword(const char *passwd, char *cret) +int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret) { register int ret; char *aaa; @@ -144,7 +144,7 @@ int CtdlIPCTryPassword(const char *passwd, char *cret) if (!aaa) return -1; sprintf(aaa, "PASS %s", passwd); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -157,7 +157,7 @@ int CtdlIPCTryPassword(const char *passwd, char *cret) * user - intended for use by system administrators to create accounts on * behalf of other users. */ -int CtdlIPCCreateUser(const char *username, int selfservice, char *cret) +int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice, char *cret) { register int ret; char *aaa; @@ -169,7 +169,7 @@ int CtdlIPCCreateUser(const char *username, int selfservice, char *cret) if (!aaa) return -1; sprintf(aaa, "%s %s", selfservice ? "NEWU" : "CREU", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -178,7 +178,7 @@ int CtdlIPCCreateUser(const char *username, int selfservice, char *cret) /* * Changes the user's password. Returns 200 if changed, errors otherwise. */ -int CtdlIPCChangePassword(const char *passwd, char *cret) +int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret) { register int ret; char *aaa; @@ -190,7 +190,7 @@ int CtdlIPCChangePassword(const char *passwd, char *cret) if (!aaa) return -1; sprintf(aaa, "SETP %s", passwd); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -200,7 +200,7 @@ int CtdlIPCChangePassword(const char *passwd, char *cret) /* Caller must free the march list */ /* which is 0 = LRMS, 1 = LKRN, 2 = LKRO, 3 = LKRA, 4 = LZRM */ /* floor is -1 for all, or floornum */ -int CtdlIPCKnownRooms(int which, int floor, struct march **listing, char *cret) +int CtdlIPCKnownRooms(CtdlIPC *ipc, int which, int floor, struct march **listing, char *cret) { register int ret; struct march *march = NULL; @@ -216,7 +216,7 @@ int CtdlIPCKnownRooms(int which, int floor, struct march **listing, char *cret) if (floor < -1) return -2; /* Can't validate upper bound, sorry */ sprintf(aaa, "%s %d", proto[which], floor); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, &bbb, &bbbsize, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret); if (ret / 100 == 1) { struct march *mptr; @@ -252,7 +252,7 @@ int CtdlIPCKnownRooms(int which, int floor, struct march **listing, char *cret) /* GETU */ /* Caller must free the struct usersupp; caller may pass an existing one */ -int CtdlIPCGetConfig(struct usersupp **uret, char *cret) +int CtdlIPCGetConfig(CtdlIPC *ipc, struct usersupp **uret, char *cret) { register int ret; @@ -261,7 +261,7 @@ int CtdlIPCGetConfig(struct usersupp **uret, char *cret) if (!*uret) *uret = (struct usersupp *)calloc(1, sizeof (struct usersupp)); if (!*uret) return -1; - ret = CtdlIPCGenericCommand("GETU", NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, "GETU", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { uret[0]->USscreenwidth = extract_int(cret, 0); uret[0]->USscreenheight = extract_int(cret, 1); @@ -272,7 +272,7 @@ int CtdlIPCGetConfig(struct usersupp **uret, char *cret) /* SETU */ -int CtdlIPCSetConfig(struct usersupp *uret, char *cret) +int CtdlIPCSetConfig(CtdlIPC *ipc, struct usersupp *uret, char *cret) { char aaa[48]; @@ -282,12 +282,12 @@ int CtdlIPCSetConfig(struct usersupp *uret, char *cret) sprintf(aaa, "SETU %d|%d|%d", uret->USscreenwidth, uret->USscreenheight, uret->flags); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* GOTO */ -int CtdlIPCGotoRoom(const char *room, const char *passwd, +int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd, struct ctdlipcroom **rret, char *cret) { register int ret; @@ -313,7 +313,7 @@ int CtdlIPCGotoRoom(const char *room, const char *passwd, } sprintf(aaa, "GOTO %s", room); } - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { extract(rret[0]->RRname, cret, 0); rret[0]->RRunread = extract_long(cret, 1); @@ -336,7 +336,7 @@ int CtdlIPCGotoRoom(const char *room, const char *passwd, /* MSGS */ /* which is 0 = all, 1 = old, 2 = new, 3 = last, 4 = first, 5 = gt, 6 = lt */ /* whicharg is number of messages, applies to last, first, gt, lt */ -int CtdlIPCGetMessages(int which, int whicharg, const char *template, +int CtdlIPCGetMessages(CtdlIPC *ipc, int which, int whicharg, const char *template, long **mret, char *cret) { register int ret; @@ -359,7 +359,7 @@ int CtdlIPCGetMessages(int which, int whicharg, const char *template, sprintf(aaa, "MSGS %s|%d|%d", proto[which], whicharg, (template) ? 1 : 0); if (template) count = strlen(template); - ret = CtdlIPCGenericCommand(aaa, template, count, &bbb, &bbbsize, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, template, count, &bbb, &bbbsize, cret); count = 0; while (strlen(bbb)) { int a; @@ -378,7 +378,7 @@ int CtdlIPCGetMessages(int which, int whicharg, const char *template, /* MSG0, MSG2 */ -int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime, +int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime, struct ctdlipcmessage **mret, char *cret) { register int ret; @@ -396,7 +396,7 @@ int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime, strcpy(mret[0]->content_type, ""); sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, &bbb, &bbbsize, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret); if (ret / 100 == 1) { if (as_mime != 2) { strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */ @@ -513,7 +513,7 @@ int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime, /* WHOK */ -int CtdlIPCWhoKnowsRoom(char **listing, char *cret) +int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret) { register int ret; size_t bytes; @@ -522,13 +522,13 @@ int CtdlIPCWhoKnowsRoom(char **listing, char *cret) if (!listing) return -2; if (*listing) return -2; - ret = CtdlIPCGenericCommand("WHOK", NULL, 0, listing, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, "WHOK", NULL, 0, listing, &bytes, cret); return ret; } /* INFO */ -int CtdlIPCServerInfo(struct CtdlServInfo *ServInfo, char *cret) +int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret) { register int ret; size_t bytes; @@ -538,7 +538,7 @@ int CtdlIPCServerInfo(struct CtdlServInfo *ServInfo, char *cret) if (!cret) return -2; if (!ServInfo) return -2; - ret = CtdlIPCGenericCommand("INFO", NULL, 0, &listing, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, "INFO", NULL, 0, &listing, &bytes, cret); if (ret / 100 == 1) { int line = 0; @@ -579,7 +579,7 @@ int CtdlIPCServerInfo(struct CtdlServInfo *ServInfo, char *cret) /* RDIR */ -int CtdlIPCReadDirectory(char **listing, char *cret) +int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret) { register int ret; size_t bytes; @@ -588,7 +588,7 @@ int CtdlIPCReadDirectory(char **listing, char *cret) if (!listing) return -2; if (*listing) return -2; - ret = CtdlIPCGenericCommand("RDIR", NULL, 0, listing, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, "RDIR", NULL, 0, listing, &bytes, cret); return ret; } @@ -596,7 +596,7 @@ int CtdlIPCReadDirectory(char **listing, char *cret) /* * Set last-read pointer in this room to msgnum, or 0 for HIGHEST. */ -int CtdlIPCSetLastRead(long msgnum, char *cret) +int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret) { register int ret; char aaa[16]; @@ -607,13 +607,13 @@ int CtdlIPCSetLastRead(long msgnum, char *cret) sprintf(aaa, "SLRP %ld", msgnum); else sprintf(aaa, "SLRP HIGHEST"); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); return ret; } /* INVT */ -int CtdlIPCInviteUserToRoom(const char *username, char *cret) +int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret) { register int ret; char *aaa; @@ -625,14 +625,14 @@ int CtdlIPCInviteUserToRoom(const char *username, char *cret) if (!aaa) return -1; sprintf(aaa, "INVT %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* KICK */ -int CtdlIPCKickoutUserFromRoom(const char *username, char *cret) +int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret) { register int ret; char *aaa; @@ -643,14 +643,14 @@ int CtdlIPCKickoutUserFromRoom(const char *username, char *cret) aaa = (char *)malloc(strlen(username) + 6); sprintf(aaa, "KICK %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* GETR */ -int CtdlIPCGetRoomAttributes(struct quickroom **qret, char *cret) +int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct quickroom **qret, char *cret) { register int ret; @@ -659,7 +659,7 @@ int CtdlIPCGetRoomAttributes(struct quickroom **qret, char *cret) if (!*qret) *qret = (struct quickroom *)calloc(1, sizeof (struct quickroom)); if (!*qret) return -1; - ret = CtdlIPCGenericCommand("GETR", NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { extract(qret[0]->QRname, cret, 0); extract(qret[0]->QRpasswd, cret, 1); @@ -674,7 +674,7 @@ int CtdlIPCGetRoomAttributes(struct quickroom **qret, char *cret) /* SETR */ /* set forget to kick all users out of room */ -int CtdlIPCSetRoomAttributes(int forget, struct quickroom *qret, char *cret) +int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct quickroom *qret, char *cret) { register int ret; char *aaa; @@ -689,23 +689,23 @@ int CtdlIPCSetRoomAttributes(int forget, struct quickroom *qret, char *cret) sprintf(aaa, "SETR %s|%s|%s|%d|%d|%d|%d", qret->QRname, qret->QRpasswd, qret->QRdirname, qret->QRflags, forget, qret->QRfloor, qret->QRorder); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* GETA */ -int CtdlIPCGetRoomAide(char *cret) +int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret) { if (!cret) return -1; - return CtdlIPCGenericCommand("GETA", NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, "GETA", NULL, 0, NULL, NULL, cret); } /* SETA */ -int CtdlIPCSetRoomAide(const char *username, char *cret) +int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret) { register int ret; char *aaa; @@ -717,14 +717,14 @@ int CtdlIPCSetRoomAide(const char *username, char *cret) if (!aaa) return -1; sprintf(aaa, "SETA %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* ENT0 */ -int CtdlIPCPostMessage(int flag, const struct ctdlipcmessage *mr, char *cret) +int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret) { register int ret; char *aaa; @@ -737,7 +737,7 @@ int CtdlIPCPostMessage(int flag, const struct ctdlipcmessage *mr, char *cret) sprintf(aaa, "ENT0 %d|%s|%d|%d|%s", flag, mr->recipient, mr->anonymous, mr->type, mr->author); - ret = CtdlIPCGenericCommand(aaa, mr->text, strlen(mr->text), NULL, + ret = CtdlIPCGenericCommand(ipc, aaa, mr->text, strlen(mr->text), NULL, NULL, cret); free(aaa); return ret; @@ -745,7 +745,7 @@ int CtdlIPCPostMessage(int flag, const struct ctdlipcmessage *mr, char *cret) /* RINF */ -int CtdlIPCRoomInfo(char **iret, char *cret) +int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret) { size_t bytes; @@ -753,12 +753,12 @@ int CtdlIPCRoomInfo(char **iret, char *cret) if (!iret) return -2; if (*iret) return -2; - return CtdlIPCGenericCommand("RINF", NULL, 0, iret, &bytes, cret); + return CtdlIPCGenericCommand(ipc, "RINF", NULL, 0, iret, &bytes, cret); } /* DELE */ -int CtdlIPCDeleteMessage(long msgnum, char *cret) +int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret) { char aaa[16]; @@ -766,12 +766,12 @@ int CtdlIPCDeleteMessage(long msgnum, char *cret) if (!msgnum) return -2; sprintf(aaa, "DELE %ld", msgnum); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* MOVE */ -int CtdlIPCMoveMessage(int copy, long msgnum, const char *destroom, char *cret) +int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum, const char *destroom, char *cret) { register int ret; char *aaa; @@ -784,26 +784,26 @@ int CtdlIPCMoveMessage(int copy, long msgnum, const char *destroom, char *cret) if (!aaa) return -1; sprintf(aaa, "MOVE %ld|%s|%d", msgnum, destroom, copy); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* KILL */ -int CtdlIPCDeleteRoom(int for_real, char *cret) +int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret) { char aaa[16]; if (!cret) return -2; sprintf(aaa, "KILL %d", for_real); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* CRE8 */ -int CtdlIPCCreateRoom(int for_real, const char *roomname, int type, +int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname, int type, const char *password, int floor, char *cret) { register int ret; @@ -823,23 +823,23 @@ int CtdlIPCCreateRoom(int for_real, const char *roomname, int type, sprintf(aaa, "CRE8 %d|%s|%d||%d", for_real, roomname, type, floor); } - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* FORG */ -int CtdlIPCForgetRoom(char *cret) +int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret) { if (!cret) return -2; - return CtdlIPCGenericCommand("FORG", NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, "FORG", NULL, 0, NULL, NULL, cret); } /* MESG */ -int CtdlIPCSystemMessage(const char *message, char **mret, char *cret) +int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret, char *cret) { register int ret; char *aaa; @@ -854,23 +854,23 @@ int CtdlIPCSystemMessage(const char *message, char **mret, char *cret) if (!aaa) return -1; sprintf(aaa, "MESG %s", message); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, mret, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, mret, &bytes, cret); free(aaa); return ret; } /* GNUR */ -int CtdlIPCNextUnvalidatedUser(char *cret) +int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret) { if (!cret) return -2; - return CtdlIPCGenericCommand("GNUR", NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, "GNUR", NULL, 0, NULL, NULL, cret); } /* GREG */ -int CtdlIPCGetUserRegistration(const char *username, char **rret, char *cret) +int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret, char *cret) { register int ret; char *aaa; @@ -890,14 +890,14 @@ int CtdlIPCGetUserRegistration(const char *username, char **rret, char *cret) sprintf(aaa, "GREG %s", username); else sprintf(aaa, "GREG _SELF_"); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, rret, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, rret, &bytes, cret); free(aaa); return ret; } /* VALI */ -int CtdlIPCValidateUser(const char *username, int axlevel, char *cret) +int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel, char *cret) { register int ret; char *aaa; @@ -910,14 +910,14 @@ int CtdlIPCValidateUser(const char *username, int axlevel, char *cret) if (!aaa) return -1; sprintf(aaa, "VALI %s|%d", username, axlevel); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* EINF */ -int CtdlIPCSetRoomInfo(int for_real, const char *info, char *cret) +int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info, char *cret) { char aaa[16]; @@ -925,12 +925,12 @@ int CtdlIPCSetRoomInfo(int for_real, const char *info, char *cret) if (!info) return -1; sprintf(aaa, "EINF %d", for_real); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* LIST */ -int CtdlIPCUserListing(char **listing, char *cret) +int CtdlIPCUserListing(CtdlIPC *ipc, char **listing, char *cret) { size_t bytes; @@ -938,30 +938,30 @@ int CtdlIPCUserListing(char **listing, char *cret) if (!listing) return -1; if (*listing) return -1; - return CtdlIPCGenericCommand("LIST", NULL, 0, listing, &bytes, cret); + return CtdlIPCGenericCommand(ipc, "LIST", NULL, 0, listing, &bytes, cret); } /* REGI */ -int CtdlIPCSetRegistration(const char *info, char *cret) +int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret) { if (!cret) return -1; if (!info) return -1; - return CtdlIPCGenericCommand("REGI", info, strlen(info), + return CtdlIPCGenericCommand(ipc, "REGI", info, strlen(info), NULL, NULL, cret); } /* CHEK */ -int CtdlIPCMiscCheck(struct ctdlipcmisc *chek, char *cret) +int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret) { register int ret; if (!cret) return -1; if (!chek) return -1; - ret = CtdlIPCGenericCommand("CHEK", NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, "CHEK", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { chek->newmail = extract_long(cret, 0); chek->needregis = extract_int(cret, 1); @@ -972,7 +972,7 @@ int CtdlIPCMiscCheck(struct ctdlipcmisc *chek, char *cret) /* DELF */ -int CtdlIPCDeleteFile(const char *filename, char *cret) +int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret) { register int ret; char *aaa; @@ -984,14 +984,14 @@ int CtdlIPCDeleteFile(const char *filename, char *cret) if (!aaa) return -1; sprintf(aaa, "DELF %s", filename); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* MOVF */ -int CtdlIPCMoveFile(const char *filename, const char *destroom, char *cret) +int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret) { register int ret; char *aaa; @@ -1004,14 +1004,14 @@ int CtdlIPCMoveFile(const char *filename, const char *destroom, char *cret) if (!aaa) return -1; sprintf(aaa, "MOVF %s|%s", filename, destroom); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* NETF */ -int CtdlIPCNetSendFile(const char *filename, const char *destnode, char *cret) +int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret) { register int ret; char *aaa; @@ -1024,14 +1024,14 @@ int CtdlIPCNetSendFile(const char *filename, const char *destnode, char *cret) if (!aaa) return -1; sprintf(aaa, "NETF %s|%s", filename, destnode); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* RWHO */ -int CtdlIPCOnlineUsers(char **listing, time_t *stamp, char *cret) +int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret) { register int ret; size_t bytes; @@ -1040,16 +1040,16 @@ int CtdlIPCOnlineUsers(char **listing, time_t *stamp, char *cret) if (!listing) return -1; if (*listing) return -1; - *stamp = CtdlIPCServerTime(cret); + *stamp = CtdlIPCServerTime(ipc, cret); if (!*stamp) *stamp = time(NULL); - ret = CtdlIPCGenericCommand("RWHO", NULL, 0, listing, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, "RWHO", NULL, 0, listing, &bytes, cret); return ret; } /* OPEN */ -int CtdlIPCFileDownload(const char *filename, void **buf, char *cret) +int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf, char *cret) { register int ret; size_t bytes; @@ -1067,7 +1067,7 @@ int CtdlIPCFileDownload(const char *filename, void **buf, char *cret) if (!aaa) return -1; sprintf(aaa, "OPEN %s", filename); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); /* FIXME: Possible race condition */ if (ret / 100 == 2) { @@ -1075,8 +1075,8 @@ int CtdlIPCFileDownload(const char *filename, void **buf, char *cret) bytes = extract_long(cret, 0); last_mod = extract_int(cret, 1); extract(mimetype, cret, 2); - ret = CtdlIPCReadDownload(buf, bytes, cret); - ret = CtdlIPCEndDownload(cret); + ret = CtdlIPCReadDownload(ipc, buf, bytes, cret); + ret = CtdlIPCEndDownload(ipc, cret); if (ret / 100 == 2) sprintf(cret, "%d|%ld|%s|%s", bytes, last_mod, filename, mimetype); @@ -1086,7 +1086,7 @@ int CtdlIPCFileDownload(const char *filename, void **buf, char *cret) /* OPNA */ -int CtdlIPCAttachmentDownload(long msgnum, const char *part, void **buf, +int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part, void **buf, char *cret) { register int ret; @@ -1107,7 +1107,7 @@ int CtdlIPCAttachmentDownload(long msgnum, const char *part, void **buf, if (!aaa) return -1; sprintf(aaa, "OPNA %ld|%s", msgnum, part); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); /* FIXME: Possible race condition */ if (ret / 100 == 2) { @@ -1115,8 +1115,8 @@ int CtdlIPCAttachmentDownload(long msgnum, const char *part, void **buf, bytes = extract_long(cret, 0); last_mod = extract_int(cret, 1); extract(mimetype, cret, 2); - ret = CtdlIPCReadDownload(buf, bytes, cret); - ret = CtdlIPCEndDownload(cret); + ret = CtdlIPCReadDownload(ipc, buf, bytes, cret); + ret = CtdlIPCEndDownload(ipc, cret); if (ret / 100 == 2) sprintf(cret, "%d|%ld|%s|%s", bytes, last_mod, filename, mimetype); @@ -1126,7 +1126,7 @@ int CtdlIPCAttachmentDownload(long msgnum, const char *part, void **buf, /* OIMG */ -int CtdlIPCImageDownload(const char *filename, void **buf, char *cret) +int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf, char *cret) { register int ret; size_t bytes; @@ -1144,7 +1144,7 @@ int CtdlIPCImageDownload(const char *filename, void **buf, char *cret) if (!aaa) return -1; sprintf(aaa, "OIMG %s", filename); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); /* FIXME: Possible race condition */ if (ret / 100 == 2) { @@ -1152,8 +1152,8 @@ int CtdlIPCImageDownload(const char *filename, void **buf, char *cret) bytes = extract_long(cret, 0); last_mod = extract_int(cret, 1); extract(mimetype, cret, 2); - ret = CtdlIPCReadDownload(buf, bytes, cret); - ret = CtdlIPCEndDownload(cret); + ret = CtdlIPCReadDownload(ipc, buf, bytes, cret); + ret = CtdlIPCEndDownload(ipc, cret); if (ret / 100 == 2) sprintf(cret, "%d|%ld|%s|%s", bytes, last_mod, filename, mimetype); @@ -1163,7 +1163,7 @@ int CtdlIPCImageDownload(const char *filename, void **buf, char *cret) /* UOPN */ -int CtdlIPCFileUpload(const char *filename, const char *comment, void *buf, +int CtdlIPCFileUpload(CtdlIPC *ipc, const char *filename, const char *comment, void *buf, size_t bytes, char *cret) { register int ret; @@ -1178,19 +1178,19 @@ int CtdlIPCFileUpload(const char *filename, const char *comment, void *buf, if (!aaa) return -1; sprintf(aaa, "UOPN %s|%s", filename, comment); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); /* FIXME: Possible race condition */ if (ret / 100 == 2) upload_in_progress = 1; - ret = CtdlIPCWriteUpload(buf, bytes, cret); - ret = CtdlIPCEndUpload(cret); + ret = CtdlIPCWriteUpload(ipc, buf, bytes, cret); + ret = CtdlIPCEndUpload(ipc, cret); return ret; } /* UIMG */ -int CtdlIPCImageUpload(int for_real, const char *filename, size_t bytes, +int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *filename, size_t bytes, char *cret) { register int ret; @@ -1204,7 +1204,7 @@ int CtdlIPCImageUpload(int for_real, const char *filename, size_t bytes, if (!aaa) return -1; sprintf(aaa, "UIMG %d|%s", for_real, filename); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); /* FIXME: Possible race condition */ if (ret / 100 == 2) @@ -1214,7 +1214,7 @@ int CtdlIPCImageUpload(int for_real, const char *filename, size_t bytes, /* QUSR */ -int CtdlIPCQueryUsername(const char *username, char *cret) +int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret) { register int ret; char *aaa; @@ -1226,14 +1226,14 @@ int CtdlIPCQueryUsername(const char *username, char *cret) if (!aaa) return -1; sprintf(aaa, "QUSR %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* LFLR */ -int CtdlIPCFloorListing(char **listing, char *cret) +int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret) { size_t bytes; @@ -1241,12 +1241,12 @@ int CtdlIPCFloorListing(char **listing, char *cret) if (!listing) return -2; if (*listing) return -2; - return CtdlIPCGenericCommand("LFLR", NULL, 0, listing, &bytes, cret); + return CtdlIPCGenericCommand(ipc, "LFLR", NULL, 0, listing, &bytes, cret); } /* CFLR */ -int CtdlIPCCreateFloor(int for_real, const char *name, char *cret) +int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret) { register int ret; char *aaa; @@ -1258,14 +1258,14 @@ int CtdlIPCCreateFloor(int for_real, const char *name, char *cret) if (!aaa) return -1; sprintf(aaa, "CFLR %s|%d", name, for_real); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* KFLR */ -int CtdlIPCDeleteFloor(int for_real, int floornum, char *cret) +int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret) { char aaa[27]; @@ -1273,12 +1273,12 @@ int CtdlIPCDeleteFloor(int for_real, int floornum, char *cret) if (floornum < 0) return -1; sprintf(aaa, "KFLR %d|%d", floornum, for_real); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* EFLR */ -int CtdlIPCEditFloor(int floornum, const char *floorname, char *cret) +int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret) { register int ret; char *aaa; @@ -1291,14 +1291,14 @@ int CtdlIPCEditFloor(int floornum, const char *floorname, char *cret) if (!aaa) return -1; sprintf(aaa, "EFLR %d|%s", floornum, floorname); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* IDEN */ -int CtdlIPCIdentifySoftware(int developerid, int clientid, int revision, +int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid, int revision, const char *software_name, const char *hostname, char *cret) { register int ret; @@ -1315,14 +1315,14 @@ int CtdlIPCIdentifySoftware(int developerid, int clientid, int revision, sprintf(aaa, "IDEN %d|%d|%d|%s|%s", developerid, clientid, revision, software_name, hostname); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* SEXP */ -int CtdlIPCSendInstantMessage(const char *username, const char *text, +int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text, char *cret) { register int ret; @@ -1336,11 +1336,11 @@ int CtdlIPCSendInstantMessage(const char *username, const char *text, if (text) { sprintf(aaa, "SEXP %s|-", username); - ret = CtdlIPCGenericCommand(aaa, text, strlen(text), + ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret); } else { sprintf(aaa, "SEXP %s||", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } free(aaa); return ret; @@ -1348,7 +1348,7 @@ int CtdlIPCSendInstantMessage(const char *username, const char *text, /* GEXP */ -int CtdlIPCGetInstantMessage(char **listing, char *cret) +int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret) { size_t bytes; @@ -1356,36 +1356,36 @@ int CtdlIPCGetInstantMessage(char **listing, char *cret) if (!listing) return -2; if (*listing) return -2; - return CtdlIPCGenericCommand("GEXP", NULL, 0, listing, &bytes, cret); + return CtdlIPCGenericCommand(ipc, "GEXP", NULL, 0, listing, &bytes, cret); } /* DEXP */ /* mode is 0 = enable, 1 = disable, 2 = status */ -int CtdlIPCEnableInstantMessageReceipt(int mode, char *cret) +int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret) { char aaa[16]; if (!cret) return -2; sprintf(aaa, "DEXP %d", mode); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* EBIO */ -int CtdlIPCSetBio(char *bio, char *cret) +int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret) { if (!cret) return -2; if (!bio) return -2; - return CtdlIPCGenericCommand("EBIO", bio, strlen(bio), + return CtdlIPCGenericCommand(ipc, "EBIO", bio, strlen(bio), NULL, NULL, cret); } /* RBIO */ -int CtdlIPCGetBio(const char *username, char **listing, char *cret) +int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret) { register int ret; size_t bytes; @@ -1400,14 +1400,14 @@ int CtdlIPCGetBio(const char *username, char **listing, char *cret) if (!aaa) return -1; sprintf(aaa, "RBIO %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, listing, &bytes, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, listing, &bytes, cret); free(aaa); return ret; } /* LBIO */ -int CtdlIPCListUsersWithBios(char **listing, char *cret) +int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret) { size_t bytes; @@ -1415,57 +1415,57 @@ int CtdlIPCListUsersWithBios(char **listing, char *cret) if (!listing) return -2; if (*listing) return -2; - return CtdlIPCGenericCommand("LBIO", NULL, 0, listing, &bytes, cret); + return CtdlIPCGenericCommand(ipc, "LBIO", NULL, 0, listing, &bytes, cret); } /* STEL */ -int CtdlIPCStealthMode(int mode, char *cret) +int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret) { char aaa[16]; if (!cret) return -1; sprintf(aaa, "STEL %d", mode ? 1 : 0); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* TERM */ -int CtdlIPCTerminateSession(int sid, char *cret) +int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret) { char aaa[16]; if (!cret) return -1; sprintf(aaa, "TERM %d", sid); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* DOWN */ -int CtdlIPCTerminateServerNow(char *cret) +int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret) { if (!cret) return -1; - return CtdlIPCGenericCommand("DOWN", NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, "DOWN", NULL, 0, NULL, NULL, cret); } /* SCDN */ -int CtdlIPCTerminateServerScheduled(int mode, char *cret) +int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret) { char aaa[16]; if (!cret) return -1; sprintf(aaa, "SCDN %d", mode ? 1 : 0); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* EMSG */ -int CtdlIPCEnterSystemMessage(const char *filename, const char *text, +int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text, char *cret) { register int ret; @@ -1479,14 +1479,14 @@ int CtdlIPCEnterSystemMessage(const char *filename, const char *text, if (!aaa) return -1; sprintf(aaa, "EMSG %s", filename); - ret = CtdlIPCGenericCommand(aaa, text, strlen(text), NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, text, strlen(text), NULL, NULL, cret); free(aaa); return ret; } /* HCHG */ -int CtdlIPCChangeHostname(const char *hostname, char *cret) +int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret) { register int ret; char *aaa; @@ -1498,14 +1498,14 @@ int CtdlIPCChangeHostname(const char *hostname, char *cret) if (!aaa) return -1; sprintf(aaa, "HCHG %s", hostname); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* RCHG */ -int CtdlIPCChangeRoomname(const char *roomname, char *cret) +int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret) { register int ret; char *aaa; @@ -1517,14 +1517,14 @@ int CtdlIPCChangeRoomname(const char *roomname, char *cret) if (!aaa) return -1; sprintf(aaa, "RCHG %s", roomname); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } /* UCHG */ -int CtdlIPCChangeUsername(const char *username, char *cret) +int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret) { register int ret; char *aaa; @@ -1536,7 +1536,7 @@ int CtdlIPCChangeUsername(const char *username, char *cret) if (!aaa) return -1; sprintf(aaa, "UCHG %s", username); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -1544,12 +1544,12 @@ int CtdlIPCChangeUsername(const char *username, char *cret) /* TIME */ /* This function returns the actual server time reported, or 0 if error */ -time_t CtdlIPCServerTime(char *cret) +time_t CtdlIPCServerTime(CtdlIPC *ipc, char *cret) { register time_t tret; register int ret; - ret = CtdlIPCGenericCommand("TIME", NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, "TIME", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { tret = extract_long(cret, 0); } else { @@ -1560,7 +1560,7 @@ time_t CtdlIPCServerTime(char *cret) /* AGUP */ -int CtdlIPCAideGetUserParameters(const char *who, +int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who, struct usersupp **uret, char *cret) { register int ret; @@ -1572,7 +1572,7 @@ int CtdlIPCAideGetUserParameters(const char *who, if (!*uret) return -1; sprintf(aaa, "AGUP %s", who); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { extract(uret[0]->fullname, cret, 0); @@ -1590,7 +1590,7 @@ int CtdlIPCAideGetUserParameters(const char *who, /* ASUP */ -int CtdlIPCAideSetUserParameters(const struct usersupp *uret, char *cret) +int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct usersupp *uret, char *cret) { register int ret; char *aaa; @@ -1605,7 +1605,7 @@ int CtdlIPCAideSetUserParameters(const struct usersupp *uret, char *cret) uret->fullname, uret->password, uret->flags, uret->timescalled, uret->posted, uret->axlevel, uret->usernum, uret->lastcall, uret->USuserpurge); - ret = CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); free(aaa); return ret; } @@ -1613,7 +1613,7 @@ int CtdlIPCAideSetUserParameters(const struct usersupp *uret, char *cret) /* GPEX */ /* which is 0 = room, 1 = floor, 2 = site */ -int CtdlIPCGetMessageExpirationPolicy(int which, char *cret) +int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which, char *cret) { static char *proto[] = {"room", "floor", "site"}; char aaa[11]; @@ -1622,14 +1622,14 @@ int CtdlIPCGetMessageExpirationPolicy(int which, char *cret) if (which < 0 || which > 2) return -2; sprintf(aaa, "GPEX %s", proto[which]); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* SPEX */ /* which is 0 = room, 1 = floor, 2 = site */ /* policy is 0 = inherit, 1 = no purge, 2 = by count, 3 = by age (days) */ -int CtdlIPCSetMessageExpirationPolicy(int which, int policy, int value, +int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which, int policy, int value, char *cret) { char aaa[38]; @@ -1640,12 +1640,12 @@ int CtdlIPCSetMessageExpirationPolicy(int which, int policy, int value, if (policy >= 2 && value < 1) return -2; sprintf(aaa, "SPEX %d|%d|%d", which, policy, value); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* CONF GET */ -int CtdlGetSystemConfig(char **listing, char *cret) +int CtdlGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret) { size_t bytes; @@ -1653,24 +1653,61 @@ int CtdlGetSystemConfig(char **listing, char *cret) if (!listing) return -2; if (*listing) return -2; - return CtdlIPCGenericCommand("CONF GET", NULL, 0, + return CtdlIPCGenericCommand(ipc, "CONF GET", NULL, 0, listing, &bytes, cret); } /* CONF SET */ -int CtdlSetSystemConfig(const char *listing, char *cret) +int CtdlSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret) { if (!cret) return -2; if (!listing) return -2; - return CtdlIPCGenericCommand("CONF SET", listing, strlen(listing), + return CtdlIPCGenericCommand(ipc, "CONF SET", listing, strlen(listing), NULL, NULL, cret); } +/* CONF GETSYS */ +int CtdlGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype, + char **listing, char *cret) +{ + char *aaa; + size_t bytes; + + if (!cret) return -2; + if (!mimetype) return -2; + if (!listing) return -2; + if (*listing) return -2; + + aaa = malloc(strlen(mimetype) + 13); + if (!aaa) return -1; + sprintf(aaa, "CONF GETSYS|%s", mimetype); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, + listing, &bytes, cret); +} + + +/* CONF PUTSYS */ +int CtdlSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype, + const char *listing, char *cret) +{ + char *aaa; + + if (!cret) return -2; + if (!mimetype) return -2; + if (!listing) return -2; + + aaa = malloc(strlen(mimetype) + 13); + if (!aaa) return -1; + sprintf(aaa, "CONF PUTSYS|%s", mimetype); + return CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing), + NULL, NULL, cret); +} + /* MMOD */ -int CtdlIPCModerateMessage(long msgnum, int level, char *cret) +int CtdlIPCModerateMessage(CtdlIPC *ipc, long msgnum, int level, char *cret) { char aaa[27]; @@ -1678,12 +1715,12 @@ int CtdlIPCModerateMessage(long msgnum, int level, char *cret) if (!msgnum) return -2; sprintf(aaa, "MMOD %ld|%d", msgnum, level); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* REQT */ -int CtdlIPCRequestClientLogout(int session, char *cret) +int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret) { char aaa[16]; @@ -1691,12 +1728,12 @@ int CtdlIPCRequestClientLogout(int session, char *cret) if (session < 0) return -2; sprintf(aaa, "REQT %d", session); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* SEEN */ -int CtdlIPCSetMessageSeen(long msgnum, int seen, char *cret) +int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret) { char aaa[27]; @@ -1704,19 +1741,19 @@ int CtdlIPCSetMessageSeen(long msgnum, int seen, char *cret) if (msgnum < 0) return -2; sprintf(aaa, "SEEN %ld|%d", msgnum, seen ? 1 : 0); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } /* STLS */ -int CtdlIPCStartEncryption(char *cret) +int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret) { - return CtdlIPCGenericCommand("STLS", NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, "STLS", NULL, 0, NULL, NULL, cret); } /* QDIR */ -int CtdlIPCDirectoryLookup(const char *address, char *cret) +int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret) { char *aaa; @@ -1727,7 +1764,18 @@ int CtdlIPCDirectoryLookup(const char *address, char *cret) if (!aaa) return -1; sprintf(aaa, "QDIR %s", address); - return CtdlIPCGenericCommand(aaa, NULL, 0, NULL, NULL, cret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); +} + + +/* IPGM */ +int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret) +{ + char aaa[30]; + + if (!cret) return -2; + sprintf(aaa, "IPGM %d", secret); + return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } @@ -1739,7 +1787,6 @@ int CtdlIPCDirectoryLookup(const char *address, char *cret) * EXPI * GTLS * IGAB - * IPGM * MSG3 * MSG4 * NDOP @@ -1754,24 +1801,24 @@ int CtdlIPCDirectoryLookup(const char *address, char *cret) /* ************************************************************************** */ -inline void netio_lock(void) +inline void CtdlIPC_lock(CtdlIPC *ipc) { #ifdef THREADED_CLIENT - pthread_mutex_lock(&rwlock); + pthread_mutex_lock(&(ipc->mutex)); #endif } -inline void netio_unlock(void) +inline void CtdlIPC_unlock(CtdlIPC *ipc) { #ifdef THREADED_CLIENT - pthread_mutex_unlock(&rwlock); + pthread_mutex_unlock(&(ipc->mutex)); #endif } /* Read a listing from the server up to 000. Append to dest if it exists */ -char *CtdlIPCReadListing(char *dest) +char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest) { size_t length = 0; size_t linelength; @@ -1787,7 +1834,7 @@ char *CtdlIPCReadListing(char *dest) length = 0; } - while (serv_gets(aaa), strcmp(aaa, "000")) { + while (CtdlIPC_getline(ipc, aaa), strcmp(aaa, "000")) { linelength = strlen(aaa); ret = (char *)realloc(ret, (size_t)(length + linelength + 2)); if (ret) { @@ -1802,7 +1849,7 @@ char *CtdlIPCReadListing(char *dest) /* Send a listing to the server; generate the ending 000. */ -int CtdlIPCSendListing(const char *listing) +int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing) { char *text; @@ -1812,21 +1859,21 @@ int CtdlIPCSendListing(const char *listing) while (text[strlen(text) - 1] == '\n') text[strlen(text) - 1] = '\0'; strcat(text, "\n000"); - serv_puts(text); + CtdlIPC_putline(ipc, text); free(text); text = NULL; } else { /* Malloc failed but we are committed to send */ /* This may result in extra blanks at the bottom */ - serv_puts(text); - serv_puts("000"); + CtdlIPC_putline(ipc, text); + CtdlIPC_putline(ipc, "000"); } return 0; } /* Partial read of file from server */ -size_t CtdlIPCPartialRead(void **buf, size_t offset, size_t bytes, char *cret) +size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret) { register size_t len = 0; char aaa[SIZ]; @@ -1836,10 +1883,10 @@ size_t CtdlIPCPartialRead(void **buf, size_t offset, size_t bytes, char *cret) if (bytes < 1) return -1; if (offset < 0) return -1; - netio_lock(); + CtdlIPC_lock(ipc); sprintf(aaa, "READ %d|%d", offset, bytes); - serv_puts(aaa); - serv_gets(aaa); + CtdlIPC_putline(ipc, aaa); + CtdlIPC_getline(ipc, aaa); if (aaa[0] != '6') strcpy(cret, &aaa[4]); else { @@ -1847,27 +1894,27 @@ size_t CtdlIPCPartialRead(void **buf, size_t offset, size_t bytes, char *cret) *buf = (void *)realloc(*buf, (size_t)(offset + len)); if (*buf) { /* I know what I'm doing */ - serv_read((char *)&buf[offset], len); + serv_read(ipc, (char *)&buf[offset], len); } else { /* We have to read regardless */ - serv_read(aaa, len); + serv_read(ipc, aaa, len); len = -1; } } - netio_unlock(); + CtdlIPC_unlock(ipc); return len; } /* CLOS */ -int CtdlIPCEndDownload(char *cret) +int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret) { register int ret; if (!cret) return -2; if (!download_in_progress) return -2; - ret = CtdlIPCGenericCommand("CLOS", NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, "CLOS", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) download_in_progress = 0; return ret; @@ -1875,19 +1922,19 @@ int CtdlIPCEndDownload(char *cret) /* MSGP */ -int CtdlIPCSpecifyPreferredFormats(char *cret, char *formats) { +int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats) { register int ret; char cmd[SIZ]; snprintf(cmd, sizeof cmd, "MSGP %s", formats); - ret = CtdlIPCGenericCommand(cmd, NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret); return ret; } /* READ */ -int CtdlIPCReadDownload(void **buf, size_t bytes, char *cret) +int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, char *cret) { register size_t len; @@ -1898,7 +1945,7 @@ int CtdlIPCReadDownload(void **buf, size_t bytes, char *cret) len = 0; while (len < bytes) { - len = CtdlIPCPartialRead(buf, len, 4096, cret); + len = CtdlIPCPartialRead(ipc, buf, len, 4096, cret); if (len == -1) { free(*buf); return 0; @@ -1909,14 +1956,14 @@ int CtdlIPCReadDownload(void **buf, size_t bytes, char *cret) /* UCLS */ -int CtdlIPCEndUpload(char *cret) +int CtdlIPCEndUpload(CtdlIPC *ipc, char *cret) { register int ret; if (!cret) return -1; if (!upload_in_progress) return -1; - ret = CtdlIPCGenericCommand("UCLS", NULL, 0, NULL, NULL, cret); + ret = CtdlIPCGenericCommand(ipc, "UCLS", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) upload_in_progress = 0; return ret; @@ -1924,7 +1971,7 @@ int CtdlIPCEndUpload(char *cret) /* WRIT */ -int CtdlIPCWriteUpload(void *buf, size_t bytes, char *cret) +int CtdlIPCWriteUpload(CtdlIPC *ipc, void *buf, size_t bytes, char *cret) { register int ret = -1; register size_t offset; @@ -1937,15 +1984,15 @@ int CtdlIPCWriteUpload(void *buf, size_t bytes, char *cret) offset = 0; while (offset < bytes) { sprintf(aaa, "WRIT %d", bytes - offset); - serv_puts(aaa); - serv_gets(aaa); + CtdlIPC_putline(ipc, aaa); + CtdlIPC_getline(ipc, aaa); strcpy(cret, &aaa[4]); ret = atoi(aaa); if (aaa[0] == '7') { register size_t to_write; to_write = extract_long(&aaa[4], 0); - serv_write(buf + offset, to_write); + serv_write(ipc, buf + offset, to_write); offset += to_write; } else { break; @@ -1959,6 +2006,7 @@ int CtdlIPCWriteUpload(void *buf, size_t bytes, char *cret) * Generic command method. This method should handle any server command * except for CHAT. It takes the following arguments: * + * ipc The server to speak with * command Preformatted command to send to server * to_send A text or binary file to send to server * (only sent if server requests it) @@ -1981,20 +2029,24 @@ int CtdlIPCWriteUpload(void *buf, size_t bytes, char *cret) * protocol_response as described above. Some commands send additional * data in this string. */ -int CtdlIPCGenericCommand(const char *command, const char *to_send, +int CtdlIPCGenericCommand(CtdlIPC *ipc, + const char *command, const char *to_send, size_t bytes_to_send, char **to_receive, size_t *bytes_to_receive, char *proto_response) { char buf[SIZ]; register int ret; + int watch_ssl = 0; if (!command) return -2; if (!proto_response) return -2; - netio_lock(); - serv_puts((char *)command); + if (ipc->ssl) watch_ssl = 1; + + CtdlIPC_lock(ipc); + CtdlIPC_putline(ipc, command); while (1) { - serv_gets(proto_response); + CtdlIPC_getline(ipc, proto_response); if (proto_response[3] == '*') express_msgs = 1; ret = atoi(proto_response); @@ -2008,18 +2060,18 @@ int CtdlIPCGenericCommand(const char *command, const char *to_send, break; case 1: /* LISTING_FOLLOWS */ if (to_receive && !*to_receive && bytes_to_receive) { - *to_receive = CtdlIPCReadListing(NULL); + *to_receive = CtdlIPCReadListing(ipc, NULL); } else { /* Drain */ - while (serv_gets(buf), strcmp(buf, "000")) ; + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) ; ret = -ret; } break; case 4: /* SEND_LISTING */ if (to_send) { - CtdlIPCSendListing(to_send); + CtdlIPCSendListing(ipc, to_send); } else { /* No listing given, fake it */ - serv_puts("000"); + CtdlIPC_putline(ipc, "000"); ret = -ret; } break; @@ -2032,7 +2084,7 @@ int CtdlIPCGenericCommand(const char *command, const char *to_send, if (!*to_receive) { ret = -1; } else { - serv_read(*to_receive, + serv_read(ipc, *to_receive, *bytes_to_receive); } } else { @@ -2041,16 +2093,16 @@ int CtdlIPCGenericCommand(const char *command, const char *to_send, drain = extract_long(proto_response, 0); while (drain > SIZ) { - serv_read(buf, SIZ); + serv_read(ipc, buf, SIZ); drain -= SIZ; } - serv_read(buf, drain); + serv_read(ipc, buf, drain); ret = -ret; } break; case 7: /* SEND_BINARY */ if (to_send && bytes_to_send) { - serv_write((char *)to_send, bytes_to_send); + serv_write(ipc, to_send, bytes_to_send); } else if (bytes_to_send) { /* Fake it, send nulls */ size_t fake; @@ -2058,32 +2110,32 @@ int CtdlIPCGenericCommand(const char *command, const char *to_send, fake = bytes_to_send; memset(buf, '\0', SIZ); while (fake > SIZ) { - serv_write(buf, SIZ); + serv_write(ipc, buf, SIZ); fake -= SIZ; } - serv_write(buf, fake); + serv_write(ipc, buf, fake); ret = -ret; } /* else who knows? DANGER WILL ROBINSON */ break; case 8: /* START_CHAT_MODE */ if (!strncasecmp(command, "CHAT", 4)) { /* Don't call chatmode with generic! */ - serv_puts("/quit"); + CtdlIPC_putline(ipc, "/quit"); ret = -ret; } else { /* In this mode we send then receive listing */ if (to_send) { - CtdlIPCSendListing(to_send); + CtdlIPCSendListing(ipc, to_send); } else { /* No listing given, fake it */ - serv_puts("000"); + CtdlIPC_putline(ipc, "000"); ret = -ret; } if (to_receive && !*to_receive && bytes_to_receive) { - *to_receive = CtdlIPCReadListing(NULL); + *to_receive = CtdlIPCReadListing(ipc, NULL); } else { /* Drain */ - while (serv_gets(buf), + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) ; ret = -ret; } @@ -2091,12 +2143,12 @@ int CtdlIPCGenericCommand(const char *command, const char *to_send, break; case 9: /* ASYNC_MSG */ /* CtdlIPCDoAsync(ret, proto_response); */ - free(CtdlIPCReadListing(NULL)); /* STUB FIXME */ + free(CtdlIPCReadListing(ipc, NULL)); /* STUB FIXME */ break; } if (ret / 100 != 9) break; } - netio_unlock(); + CtdlIPC_unlock(ipc); return ret; } diff --git a/citadel/citadel_ipc.h b/citadel/citadel_ipc.h index 565c6e541..824befc61 100644 --- a/citadel/citadel_ipc.h +++ b/citadel/citadel_ipc.h @@ -1,5 +1,11 @@ /* $Id$ */ +#include "ipc.h" + +#ifdef __cplusplus +extern "C" { +#endif + struct ctdlipcroom { char RRname[ROOMNAMELEN]; /* Name of room */ long RRunread; /* Number of unread messages */ @@ -54,118 +60,119 @@ struct ctdlipcmisc { char needvalid; /* Nonzero if users need validation */ }; -#ifdef __cplusplus -extern "C" { -#endif - -int CtdlIPCNoop(void); -int CtdlIPCEcho(const char *arg, char *cret); -int CtdlIPCQuit(void); -int CtdlIPCLogout(void); -int CtdlIPCTryLogin(const char *username, char *cret); -int CtdlIPCTryPassword(const char *passwd, char *cret); -int CtdlIPCCreateUser(const char *username, int selfservice, char *cret); -int CtdlIPCChangePassword(const char *passwd, char *cret); -int CtdlIPCKnownRooms(int which, int floor, struct march **listing, char *cret); -int CtdlIPCGetConfig(struct usersupp **uret, char *cret); -int CtdlIPCSetConfig(struct usersupp *uret, char *cret); -int CtdlIPCGotoRoom(const char *room, const char *passwd, +int CtdlIPCNoop(CtdlIPC *ipc); +int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret); +int CtdlIPCQuit(CtdlIPC *ipc); +int CtdlIPCLogout(CtdlIPC *ipc); +int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret); +int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret); +int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice, char *cret); +int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret); +int CtdlIPCKnownRooms(CtdlIPC *ipc, int which, int floor, struct march **listing, char *cret); +int CtdlIPCGetConfig(CtdlIPC *ipc, struct usersupp **uret, char *cret); +int CtdlIPCSetConfig(CtdlIPC *ipc, struct usersupp *uret, char *cret); +int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd, struct ctdlipcroom **rret, char *cret); -int CtdlIPCGetMessages(int which, int whicharg, const char *template, +int CtdlIPCGetMessages(CtdlIPC *ipc, int which, int whicharg, const char *template, long **mret, char *cret); -int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime, +int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime, struct ctdlipcmessage **mret, char *cret); -int CtdlIPCWhoKnowsRoom(char **listing, char *cret); -int CtdlIPCServerInfo(struct CtdlServInfo *ServInfo, char *cret); -int CtdlIPCReadDirectory(char **listing, char *cret); -int CtdlIPCSetLastRead(long msgnum, char *cret); -int CtdlIPCInviteUserToRoom(const char *username, char *cret); -int CtdlIPCKickoutUserFromRoom(const char *username, char *cret); -int CtdlIPCGetRoomAttributes(struct quickroom **qret, char *cret); -int CtdlIPCSetRoomAttributes(int forget, struct quickroom *qret, char *cret); -int CtdlIPCGetRoomAide(char *cret); -int CtdlIPCSetRoomAide(const char *username, char *cret); -int CtdlIPCPostMessage(int flag, const struct ctdlipcmessage *mr, char *cret); -int CtdlIPCRoomInfo(char **iret, char *cret); -int CtdlIPCDeleteMessage(long msgnum, char *cret); -int CtdlIPCMoveMessage(int copy, long msgnum, const char *destroom, char *cret); -int CtdlIPCDeleteRoom(int for_real, char *cret); -int CtdlIPCCreateRoom(int for_real, const char *roomname, int type, +int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret); +int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret); +int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret); +int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret); +int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret); +int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret); +int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct quickroom **qret, char *cret); +int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct quickroom *qret, char *cret); +int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret); +int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret); +int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret); +int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret); +int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret); +int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum, const char *destroom, char *cret); +int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret); +int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname, int type, const char *password, int floor, char *cret); -int CtdlIPCForgetRoom(char *cret); -int CtdlIPCSystemMessage(const char *message, char **mret, char *cret); -int CtdlIPCNextUnvalidatedUser(char *cret); -int CtdlIPCGetUserRegistration(const char *username, char **rret, char *cret); -int CtdlIPCValidateUser(const char *username, int axlevel, char *cret); -int CtdlIPCSetRoomInfo(int for_real, const char *info, char *cret); -int CtdlIPCUserListing(char **list, char *cret); -int CtdlIPCSetRegistration(const char *info, char *cret); -int CtdlIPCMiscCheck(struct ctdlipcmisc *chek, char *cret); -int CtdlIPCDeleteFile(const char *filename, char *cret); -int CtdlIPCMoveFile(const char *filename, const char *destroom, char *cret); -int CtdlIPCNetSendFile(const char *filename, const char *destnode, char *cret); -int CtdlIPCOnlineUsers(char **listing, time_t *stamp, char *cret); -int CtdlIPCFileDownload(const char *filename, void **buf, char *cret); -int CtdlIPCAttachmentDownload(long msgnum, const char *part, void **buf, +int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret); +int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret, char *cret); +int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret); +int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret, char *cret); +int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel, char *cret); +int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info, char *cret); +int CtdlIPCUserListing(CtdlIPC *ipc, char **list, char *cret); +int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret); +int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret); +int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret); +int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret); +int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret); +int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret); +int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf, char *cret); +int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part, void **buf, char *cret); -int CtdlIPCImageDownload(const char *filename, void **buf, char *cret); -int CtdlIPCFileUpload(const char *filename, const char *comment, void *buf, +int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf, char *cret); +int CtdlIPCFileUpload(CtdlIPC *ipc, const char *filename, const char *comment, void *buf, size_t bytes, char *cret); -int CtdlIPCImageUpload(int for_real, const char *filename, size_t bytes, +int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *filename, size_t bytes, char *cret); -int CtdlIPCQueryUsername(const char *username, char *cret); -int CtdlIPCFloorListing(char **listing, char *cret); -int CtdlIPCCreateFloor(int for_real, const char *name, char *cret); -int CtdlIPCDeleteFloor(int for_real, int floornum, char *cret); -int CtdlIPCEditFloor(int floornum, const char *floorname, char *cret); -int CtdlIPCIdentifySoftware(int developerid, int clientid, int revision, +int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret); +int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret); +int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret); +int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret); +int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret); +int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid, int revision, const char *software_name, const char *hostname, char *cret); -int CtdlIPCSendInstantMessage(const char *username, const char *text, +int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text, char *cret); -int CtdlIPCGetInstantMessage(char **listing, char *cret); -int CtdlIPCEnableInstantMessageReceipt(int mode, char *cret); -int CtdlIPCSetBio(char *bio, char *cret); -int CtdlIPCGetBio(const char *username, char **listing, char *cret); -int CtdlIPCListUsersWithBios(char **listing, char *cret); -int CtdlIPCStealthMode(int mode, char *cret); -int CtdlIPCTerminateSession(int sid, char *cret); -int CtdlIPCTerminateServerNow(char *cret); -int CtdlIPCTerminateServerScheduled(int mode, char *cret); -int CtdlIPCEnterSystemMessage(const char *filename, const char *text, +int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret); +int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret); +int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret); +int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret); +int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret); +int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret); +int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret); +int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret); +int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret); +int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text, char *cret); -int CtdlIPCChangeHostname(const char *hostname, char *cret); -int CtdlIPCChangeRoomname(const char *roomname, char *cret); -int CtdlIPCChangeUsername(const char *username, char *cret); -time_t CtdlIPCServerTime(char *crert); -int CtdlIPCAideGetUserParameters(const char *who, +int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret); +int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret); +int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret); +time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert); +int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who, struct usersupp **uret, char *cret); -int CtdlIPCAideSetUserParameters(const struct usersupp *uret, char *cret); -int CtdlIPCGetMessageExpirationPolicy(int which, char *cret); -int CtdlIPCSetMessageExpirationPolicy(int which, int policy, int value, +int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct usersupp *uret, char *cret); +int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which, char *cret); +int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which, int policy, int value, char *cret); -int CtdlGetSystemConfig(char **listing, char *cret); -int CtdlSetSystemConfig(const char *listing, char *cret); -int CtdlIPCModerateMessage(long msgnum, int level, char *cret); -int CtdlIPCRequestClientLogout(int session, char *cret); -int CtdlIPCSetMessageSeen(long msgnum, int seen, char *cret); -int CtdlIPCStartEncryption(char *cret); -int CtdlIPCDirectoryLookup(const char *address, char *cret); -int CtdlIPCSpecifyPreferredFormats(char *cret, char *formats); +int CtdlGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret); +int CtdlSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret); +int CtdlGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype, + char **listing, char *cret); +int CtdlSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype, + const char *listing, char *cret); +int CtdlIPCModerateMessage(CtdlIPC *ipc, long msgnum, int level, char *cret); +int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret); +int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret); +int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret); +int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret); +int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats); +int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret); /* ************************************************************************** */ /* Stuff below this line is not for public consumption */ /* ************************************************************************** */ -inline void netio_lock(void); -inline void netio_unlock(void); -char *CtdlIPCReadListing(char *dest); -int CtdlIPCSendListing(const char *listing); -size_t CtdlIPCPartialRead(void **buf, size_t offset, size_t bytes, char *cret); -int CtdlIPCEndUpload(char *cret); -int CtdlIPCWriteUpload(void *buf, size_t bytes, char *cret); -int CtdlIPCEndDownload(char *cret); -int CtdlIPCReadDownload(void **buf, size_t bytes, char *cret); -int CtdlIPCGenericCommand(const char *command, const char *to_send, +inline void CtdlIPC_lock(CtdlIPC *ipc); +inline void CtdlIPC_unlock(CtdlIPC *ipc); +char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest); +int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing); +size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret); +int CtdlIPCEndUpload(CtdlIPC *ipc, char *cret); +int CtdlIPCWriteUpload(CtdlIPC *ipc, void *buf, size_t bytes, char *cret); +int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret); +int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, char *cret); +int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command, const char *to_send, size_t bytes_to_send, char **to_receive, size_t *bytes_to_receive, char *proto_response); diff --git a/citadel/citmail.c b/citadel/citmail.c index 1c54a5d40..f1b8d7431 100644 --- a/citadel/citmail.c +++ b/citadel/citmail.c @@ -23,8 +23,6 @@ #include #include #include "citadel.h" -#include "citadel_decls.h" -#include "ipc.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif diff --git a/citadel/client_chat.c b/citadel/client_chat.c index 49e24ea8b..de9ced5fd 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -33,10 +33,10 @@ #endif #include #include "citadel.h" +#include "citadel_ipc.h" #include "client_chat.h" #include "commands.h" #include "routines.h" -#include "ipc.h" #include "citadel_decls.h" #include "tools.h" #include "rooms.h" @@ -54,7 +54,7 @@ void getline(char *, int); char last_paged[SIZ] = ""; -void chatmode(void) +void chatmode(CtdlIPC *ipc) { char wbuf[SIZ]; char buf[SIZ]; @@ -72,8 +72,8 @@ void chatmode(void) struct timeval tv; int retval; - serv_puts("CHAT"); - serv_gets(buf); + CtdlIPC_putline(ipc, "CHAT"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '8') { scr_printf("%s\n", &buf[4]); return; @@ -94,13 +94,13 @@ void chatmode(void) sln_flush(); FD_ZERO(&rfds); FD_SET(0, &rfds); - FD_SET(getsockfd(), &rfds); + FD_SET(CtdlIPC_getsockfd(ipc), &rfds); tv.tv_sec = S_KEEPALIVE; tv.tv_usec = 0; - retval = select(getsockfd() + 1, &rfds, NULL, NULL, &tv); + retval = select(CtdlIPC_getsockfd(ipc) + 1, &rfds, NULL, NULL, &tv); - if (FD_ISSET(getsockfd(), &rfds)) { - ch = serv_getc(); + if (FD_ISSET(CtdlIPC_getsockfd(ipc), &rfds)) { + ch = CtdlIPC_get(ipc); if (ch == 10) { recv_complete_line = 1; goto RCL; /* ugly, but we've gotta get out! */ @@ -127,7 +127,7 @@ void chatmode(void) } /* if the user hit return, send the line */ RCL:if (send_complete_line) { - serv_puts(wbuf); + CtdlIPC_putline(ipc, wbuf); last_transmit = time(NULL); strcpy(wbuf, ""); send_complete_line = 0; @@ -140,13 +140,13 @@ void chatmode(void) pos = a; } if (pos == 0) { - serv_puts(wbuf); + CtdlIPC_putline(ipc, wbuf); last_transmit = time(NULL); strcpy(wbuf, ""); send_complete_line = 0; } else { wbuf[pos] = 0; - serv_puts(wbuf); + CtdlIPC_putline(ipc, wbuf); last_transmit = time(NULL); strcpy(wbuf, &wbuf[pos + 1]); } @@ -164,9 +164,9 @@ void chatmode(void) * This little dialog forces everything to be * hunky-dory. */ - serv_puts("ECHO __ExitingChat__"); + CtdlIPC_putline(ipc, "ECHO __ExitingChat__"); do { - serv_gets(buf); + CtdlIPC_getline(ipc, buf); } while (strcmp(buf, "200 __ExitingChat__")); @@ -218,7 +218,7 @@ void chatmode(void) * server to prevent session timeout. */ if ((time(NULL) - last_transmit) >= S_KEEPALIVE) { - serv_puts("NOOP"); + CtdlIPC_putline(ipc, "NOOP"); last_transmit = time(NULL); } @@ -228,7 +228,7 @@ void chatmode(void) /* * send an express message */ -void page_user() +void page_user(CtdlIPC *ipc) { char buf[SIZ], touser[SIZ], msg[SIZ]; FILE *pagefp; @@ -240,8 +240,8 @@ void page_user() if (serv_info.serv_paging_level == 0) { newprompt("Message: ", msg, 69); snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (!strncmp(buf, "200", 3)) { strcpy(last_paged, touser); } @@ -251,29 +251,29 @@ void page_user() /* new server -- use extended paging */ else if (serv_info.serv_paging_level >= 1) { snprintf(buf, sizeof buf, "SEXP %s||", touser); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); return; } - if (client_make_message(temp, touser, 0, 0, 0, NULL) != 0) { + if (client_make_message(ipc, temp, touser, 0, 0, 0, NULL) != 0) { scr_printf("No message sent.\n"); return; } pagefp = fopen(temp, "r"); unlink(temp); snprintf(buf, sizeof buf, "SEXP %s|-", touser); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] == '4') { strcpy(last_paged, touser); while (fgets(buf, sizeof buf, pagefp) != NULL) { buf[strlen(buf) - 1] = 0; - serv_puts(buf); + CtdlIPC_putline(ipc, buf); } fclose(pagefp); - serv_puts("000"); + CtdlIPC_putline(ipc, "000"); scr_printf("Message sent.\n"); } else { scr_printf("%s\n", &buf[4]); @@ -282,67 +282,37 @@ void page_user() } - - -void quiet_mode(void) +void quiet_mode(CtdlIPC *ipc) { - int qstate; - char buf[SIZ]; + static int quiet = 0; + char cret[SIZ]; + int r; - serv_puts("DEXP 2"); - serv_gets(buf); - if (buf[0] != '2') { - scr_printf("%s\n", &buf[4]); - return; - } - qstate = atoi(&buf[4]); - if (qstate == 0) - qstate = 1; - else - qstate = 0; - snprintf(buf, sizeof buf, "DEXP %d", qstate); - serv_puts(buf); - serv_gets(buf); - if (buf[0] != '2') { - scr_printf("%s\n", &buf[4]); - return; - } - qstate = atoi(&buf[4]); - if (qstate) { - scr_printf("Quiet mode enabled (no other users may page you)\n"); + r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret); + if (r / 100 == 2) { + quiet = !quiet; + scr_printf("Quiet mode %sabled (%sother users may page you)\n", + (quiet) ? "en" : "dis", + (quiet) ? "no " : ""); } else { - scr_printf("Quiet mode disabled (other users may page you)\n"); + scr_printf("Unable to change quiet mode: %s\n", cret); } } -void stealth_mode(void) +void stealth_mode(CtdlIPC *ipc) { - int qstate; - char buf[SIZ]; + static int stealth = 0; + char cret[SIZ]; + int r; - serv_puts("STEL 2"); - serv_gets(buf); - if (buf[0] != '2') { - scr_printf("%s\n", &buf[4]); - return; - } - qstate = atoi(&buf[4]); - if (qstate == 0) - qstate = 1; - else - qstate = 0; - snprintf(buf, sizeof buf, "STEL %d", qstate); - serv_puts(buf); - serv_gets(buf); - if (buf[0] != '2') { - scr_printf("%s\n", &buf[4]); - return; - } - qstate = atoi(&buf[4]); - if (qstate) { - scr_printf("Stealth mode enabled (you are invisible)\n"); + r = CtdlIPCStealthMode(ipc, !stealth, cret); + if (r / 100 == 2) { + stealth = !stealth; + scr_printf("Stealth mode %sabled (you are %s)\n", + (stealth) ? "en" : "dis", + (stealth) ? "invisible" : "listed as online"); } else { - scr_printf("Stealth mode disabled (you are listed as online)\n"); + scr_printf("Unable to change stealth mode: %s\n", cret); } } diff --git a/citadel/client_chat.h b/citadel/client_chat.h index 2c427692a..b8948aba9 100644 --- a/citadel/client_chat.h +++ b/citadel/client_chat.h @@ -1,7 +1,7 @@ /* $Id$ */ -void chatmode(void); -void page_user(void); -void quiet_mode(void); -void stealth_mode(void); +void chatmode(CtdlIPC *ipc); +void page_user(CtdlIPC *ipc); +void quiet_mode(CtdlIPC *ipc); +void stealth_mode(CtdlIPC *ipc); extern char last_paged[]; diff --git a/citadel/client_crypto.c b/citadel/client_crypto.c index 3da98af1d..fa732cbff 100644 --- a/citadel/client_crypto.c +++ b/citadel/client_crypto.c @@ -1,33 +1,22 @@ /* $Id$ */ #include "sysdep.h" -#ifdef HAVE_OPENSSL -#include -#include -#include -#endif #ifdef HAVE_PTHREAD_H #include #endif #include #include #include "citadel.h" -#include "client_crypto.h" #include "citadel_ipc.h" -#include "ipc.h" #ifdef HAVE_OPENSSL -SSL *ssl; -SSL_CTX *ssl_ctx; -int ssl_is_connected = 0; +static SSL_CTX *ssl_ctx; char arg_encrypt; char rc_encrypt; #ifdef THREADED_CLIENT pthread_mutex_t **Critters; /* Things that need locking */ #endif /* THREADED_CLIENT */ -extern int serv_sock; -extern int server_is_local; #endif /* HAVE_OPENSSL */ @@ -42,24 +31,24 @@ void setCryptoStatusHook(void (*hook)(char *s)) { /* * input binary data from encrypted connection */ -void serv_read_ssl(char *buf, int bytes) +void serv_read_ssl(CtdlIPC* ipc, char *buf, int bytes) { int len, rlen; char junk[1]; len = 0; while (len < bytes) { - if (SSL_want_read(ssl)) { - if ((SSL_write(ssl, junk, 0)) < 1) { + if (SSL_want_read(ipc->ssl)) { + if ((SSL_write(ipc->ssl, junk, 0)) < 1) { error_printf("SSL_write in serv_read:\n"); ERR_print_errors_fp(stderr); } } - rlen = SSL_read(ssl, &buf[len], bytes - len); + rlen = SSL_read(ipc->ssl, &buf[len], bytes - len); if (rlen < 1) { long errval; - errval = SSL_get_error(ssl, rlen); + errval = SSL_get_error(ipc->ssl, rlen); if (errval == SSL_ERROR_WANT_READ || errval == SSL_ERROR_WANT_WRITE) { sleep(1); @@ -67,8 +56,7 @@ void serv_read_ssl(char *buf, int bytes) } if (errval == SSL_ERROR_ZERO_RETURN || errval == SSL_ERROR_SSL) { - endtls(); - serv_read(&buf[len], bytes - len); + serv_read(ipc, &buf[len], bytes - len); return; } error_printf("SSL_read in serv_read:\n"); @@ -84,25 +72,25 @@ void serv_read_ssl(char *buf, int bytes) /* * send binary to server encrypted */ -void serv_write_ssl(char *buf, int nbytes) +void serv_write_ssl(CtdlIPC *ipc, const char *buf, int nbytes) { int bytes_written = 0; int retval; char junk[1]; while (bytes_written < nbytes) { - if (SSL_want_write(ssl)) { - if ((SSL_read(ssl, junk, 0)) < 1) { + if (SSL_want_write(ipc->ssl)) { + if ((SSL_read(ipc->ssl, junk, 0)) < 1) { error_printf("SSL_read in serv_write:\n"); ERR_print_errors_fp(stderr); } } - retval = SSL_write(ssl, &buf[bytes_written], + retval = SSL_write(ipc->ssl, &buf[bytes_written], nbytes - bytes_written); if (retval < 1) { long errval; - errval = SSL_get_error(ssl, retval); + errval = SSL_get_error(ipc->ssl, retval); if (errval == SSL_ERROR_WANT_READ || errval == SSL_ERROR_WANT_WRITE) { sleep(1); @@ -110,8 +98,7 @@ void serv_write_ssl(char *buf, int nbytes) } if (errval == SSL_ERROR_ZERO_RETURN || errval == SSL_ERROR_SSL) { - endtls(); - serv_write(&buf[bytes_written], + serv_write(ipc, &buf[bytes_written], nbytes - bytes_written); return; } @@ -142,15 +129,16 @@ static unsigned long id_callback(void) { } #endif +/* FIXME: per application not per ipc */ /* * starttls() starts SSL/TLS if possible * Returns 1 if the session is encrypted, 0 otherwise */ -int starttls(void) +int starttls(CtdlIPC *ipc) { #ifdef HAVE_OPENSSL int a; - /* int r; */ /* IPC response code */ + int r; /* IPC response code */ char buf[SIZ]; SSL_METHOD *ssl_method; DH *dh; @@ -162,12 +150,12 @@ int starttls(void) } /* User expressed no preference */ else if (rc_encrypt == RC_DEFAULT && arg_encrypt == RC_DEFAULT && - server_is_local) { + ipc->isLocal) { return 0; } /* Get started */ - ssl = NULL; + ipc->ssl = NULL; ssl_ctx = NULL; dh = NULL; SSL_load_error_strings(); @@ -184,8 +172,7 @@ int starttls(void) /* Any reasonable cipher we can get */ if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) { error_printf("No ciphers available for encryption\n"); - SSL_CTX_free(ssl_ctx); - ssl_ctx = NULL; + endtls(ipc); return 0; } SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_BOTH); @@ -195,16 +182,21 @@ int starttls(void) if (!dh) { error_printf("Can't allocate a DH object: %s\n", ERR_reason_error_string(ERR_get_error())); + endtls(ipc); return 0; } if (!(BN_hex2bn(&(dh->p), DH_P))) { error_printf("Can't assign DH_P: %s\n", ERR_reason_error_string(ERR_get_error())); + DH_free(dh); + endtls(ipc); return 0; } if (!(BN_hex2bn(&(dh->g), DH_G))) { error_printf("Can't assign DH_G: %s\n", ERR_reason_error_string(ERR_get_error())); + DH_free(dh); + endtls(ipc); return 0; } dh->length = DH_L; @@ -234,17 +226,16 @@ int starttls(void) #endif /* THREADED_CLIENT */ /* New SSL object */ - ssl = SSL_new(ssl_ctx); - if (!ssl) { + ipc->ssl = SSL_new(ssl_ctx); + if (!ipc->ssl) { error_printf("SSL_new failed: %s\n", ERR_reason_error_string(ERR_get_error())); - SSL_CTX_free(ssl_ctx); - ssl_ctx = NULL; + endtls(ipc); return 0; } /* Pointless flag waving */ #if SSLEAY_VERSION_NUMBER >= 0x0922 - SSL_set_session_id_context(ssl, "Citadel/UX SID", 14); + SSL_set_session_id_context(ipc->ssl, "Citadel/UX SID", 14); #endif if (!access("/var/run/egd-pool", F_OK)) @@ -252,17 +243,15 @@ int starttls(void) if (!RAND_status()) { error_printf("PRNG not properly seeded\n"); + endtls(ipc); return 0; } /* Associate network connection with SSL object */ - if (SSL_set_fd(ssl, serv_sock) < 1) { + if (SSL_set_fd(ipc->ssl, ipc->sock) < 1) { error_printf("SSL_set_fd failed: %s\n", ERR_reason_error_string(ERR_get_error())); - SSL_CTX_free(ssl_ctx); - ssl_ctx = NULL; - SSL_free(ssl); - ssl = NULL; + endtls(ipc); return 0; } @@ -270,42 +259,48 @@ int starttls(void) status_hook("Requesting encryption...\r"); /* Ready to start SSL/TLS */ - serv_puts("STLS"); - serv_gets(buf); + /* Old code + CtdlIPC_putline(ipc, "STLS"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { error_printf("Server can't start TLS: %s\n", buf); return 0; } - - /* New code - r = CtdlIPCStartEncryption(buf); - if (r / 100 != 2) { - error_printf("Server can't start TLS: %s\n", buf); - return 0; - } */ + { + /* + * We can't have ipc->ssl set when we call StartEncryption() + * because the connection isn't yet encrypted. So we fake it. + */ + SSL *temp_ssl; + + temp_ssl = ipc->ssl; + ipc->ssl = NULL; + r = CtdlIPCStartEncryption(ipc, buf); + ipc->ssl = temp_ssl; + if (r / 100 != 2) { + error_printf("Server can't start TLS: %s\n", buf); + return 0; + } + } /* Do SSL/TLS handshake */ - if ((a = SSL_connect(ssl)) < 1) { + if ((a = SSL_connect(ipc->ssl)) < 1) { error_printf("SSL_connect failed: %s\n", ERR_reason_error_string(ERR_get_error())); - SSL_CTX_free(ssl_ctx); - ssl_ctx = NULL; - SSL_free(ssl); - ssl = NULL; + endtls(ipc); return 0; } - BIO_set_close(ssl->rbio, BIO_NOCLOSE); + BIO_set_close(ipc->ssl->rbio, BIO_NOCLOSE); { int bits, alg_bits; - bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &alg_bits); + bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ipc->ssl), &alg_bits); error_printf("Encrypting with %s cipher %s (%d of %d bits)\n", - SSL_CIPHER_get_version(SSL_get_current_cipher(ssl)), - SSL_CIPHER_get_name(SSL_get_current_cipher(ssl)), + SSL_CIPHER_get_version(SSL_get_current_cipher(ipc->ssl)), + SSL_CIPHER_get_name(SSL_get_current_cipher(ipc->ssl)), bits, alg_bits); } - ssl_is_connected = 1; return 1; #else return 0; @@ -316,18 +311,13 @@ int starttls(void) /* * void endtls() - end SSL/TLS session */ -void endtls(void) +void endtls(CtdlIPC *ipc) { #ifdef HAVE_OPENSSL - if (ssl) { - SSL_shutdown(ssl); - SSL_free(ssl); - ssl = NULL; - } - ssl_is_connected = 0; - if (ssl_ctx) { - SSL_CTX_free(ssl_ctx); - ssl_ctx = NULL; + if (ipc->ssl) { + SSL_shutdown(ipc->ssl); + SSL_free(ipc->ssl); + ipc->ssl = NULL; } #endif } diff --git a/citadel/client_crypto.h b/citadel/client_crypto.h index 0ee5ced6a..e757d9d2a 100644 --- a/citadel/client_crypto.h +++ b/citadel/client_crypto.h @@ -1,21 +1,21 @@ /* $Id$ */ +#ifdef HAVE_OPENSSL +#include +#include +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + /* Shared Diffie-Hellman parameters */ #define DH_P "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383" #define DH_G "2" #define DH_L 1024 #define CIT_CIPHERS "ALL:RC4+RSA:+SSLv2:@STRENGTH" /* see ciphers(1) */ -int starttls(void); -void endtls(void); -void serv_read(char *buf, int bytes); -void serv_write(char *buf, int nbytes); -#ifdef HAVE_OPENSSL -void serv_read_ssl(char *buf, int bytes); -void serv_write_ssl(char *buf, int nbytes); -void ssl_lock(int mode, int n, const char *file, int line); -#endif /* HAVE_OPENSSL */ - -extern int ssl_is_connected; - -void setCryptoStatusHook(void (*hook)(char *s)); +#ifdef __cplusplus +} +#endif diff --git a/citadel/client_passwords.c b/citadel/client_passwords.c index ebc8a6644..d755f363b 100644 --- a/citadel/client_passwords.c +++ b/citadel/client_passwords.c @@ -17,6 +17,7 @@ #include #include #include "citadel.h" +#include "citadel_ipc.h" #include "tools.h" #include "commands.h" @@ -126,7 +127,7 @@ void set_stored_password( /* * Set the password if the user wants to, clear it otherwise */ -void offer_to_remember_password( +void offer_to_remember_password(CtdlIPC *ipc, char *host, char *port, char *username, diff --git a/citadel/commands.c b/citadel/commands.c index 30e9a1480..49c0710c4 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -44,6 +44,7 @@ #include #include #include "citadel.h" +#include "citadel_ipc.h" #include "commands.h" #include "messages.h" #include "citadel_decls.h" @@ -52,7 +53,6 @@ #include "tools.h" #include "rooms.h" #include "client_chat.h" -#include "citadel_ipc.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif @@ -88,6 +88,7 @@ int next_lazy_cmd = 5; int lines_printed = 0; /* line count for paginator */ extern int screenwidth, screenheight; extern int termn8; +extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */ struct citcmd *cmdlist = NULL; @@ -225,7 +226,7 @@ void print_express(void) } while (express_msgs != 0) { - r = CtdlIPCGetInstantMessage(&listing, buf); + r = CtdlIPCGetInstantMessage(ipc_for_signal_handlers, &listing, buf); if (r / 100 != 1) return; @@ -354,7 +355,7 @@ static void really_do_keepalive(void) { * wait for a response. */ if (keepalives_enabled == KA_YES) { - r = CtdlIPCNoop(); + r = CtdlIPCNoop(ipc_for_signal_handlers); if (express_msgs > 0) { if (ok_to_interrupt == 1) { scr_printf("\r%64s\r", ""); @@ -371,7 +372,7 @@ static void really_do_keepalive(void) { */ if ( (keepalives_enabled == KA_HALF) && (serv_info.serv_supports_qnop > 0) ) { - serv_puts("QNOP"); + CtdlIPC_putline(ipc_for_signal_handlers, "QNOP"); } } @@ -764,7 +765,7 @@ void load_command_set(void) } if (ccfile == NULL) { perror("commands: cannot open citadel.rc"); - logoff(errno); + logoff(NULL, 3); } while (fgets(buf, sizeof buf, ccfile) != NULL) { while ((strlen(buf) > 0) ? (isspace(buf[strlen(buf) - 1])) : 0) @@ -776,7 +777,7 @@ void load_command_set(void) rc_encrypt = RC_YES; #else fprintf(stderr, "citadel.rc requires encryption support but citadel is not compiled with OpenSSL"); - logoff(1); + logoff(NULL, 3); #endif } #ifdef HAVE_OPENSSL @@ -1020,7 +1021,7 @@ int requires_string(struct citcmd *cptr, int ncomp) * This function returns an integer command number. If the command prompts * for a string then it is placed in the supplied buffer. */ -int getcmd(char *argbuf) +int getcmd(CtdlIPC *ipc, char *argbuf) { char cmdbuf[5]; int cmdspaces[5]; @@ -1046,9 +1047,9 @@ int getcmd(char *argbuf) enable_color = 0; } /* if we're running in idiot mode, display a cute little menu */ - IFNEXPERT formout("mainmenu"); + IFNEXPERT formout(ipc, "mainmenu"); - print_express(); /* print express messages if there are any */ + print_express(); strcpy(argbuf, ""); cmdpos = 0; for (a = 0; a < 5; ++a) @@ -1251,9 +1252,9 @@ void sttybbs(int cmd) /* * display_help() - help file viewer */ -void display_help(char *name) +void display_help(CtdlIPC *ipc, char *name) { - formout(name); + formout(ipc, name); } @@ -1403,7 +1404,7 @@ FMTA: while ((eof_flag == 0) && (strlen(buffer) < 126)) { /* keypress caught; drain the server */ OOPS: /* do { - serv_gets(aaa); + CtdlIPC_getline(ipc, aaa); } while (strcmp(aaa, "000")); */ FMTEND: @@ -1444,9 +1445,11 @@ void color(int colornum) #endif /* When switching to dim white, actually output an 'original * pair' sequence -- this looks better on black-on-white - * terminals. + * terminals. - Changed to ORIGINAL_PAIR as this actually + * wound up looking horrible on black-on-white terminals, not + * to mention transparent terminals. */ - if (colornum == DIM_WHITE) + if (colornum == ORIGINAL_PAIR) printf("\033[39;49m"); else printf("\033[3%d;40m", (colornum & 7)); diff --git a/citadel/commands.h b/citadel/commands.h index da20deaca..6b15ddab9 100644 --- a/citadel/commands.h +++ b/citadel/commands.h @@ -24,6 +24,7 @@ #define BRIGHT_WHITE 15 #define COLOR_PUSH 16 /* Save current color */ #define COLOR_POP 17 /* Restore saved color */ +#define ORIGINAL_PAIR -1 /* Default terminal colors */ #define MAXURLS 50 /* Max embedded URL's per message */ @@ -38,8 +39,8 @@ int boolprompt(char *prompt, int prev_val); int intprompt(char *prompt, int ival, int imin, int imax); int fmout(int width, FILE *fpin, char *text, FILE *fpout, char pagin, int height, int starting_lp, char subst); -int getcmd(char *argbuf); -void display_help(char *name); +int getcmd(CtdlIPC *ipc, char *argbuf); +void display_help(CtdlIPC *ipc, char *name); void color(int colornum); void cls(int colornum); void send_ansi_detect(void); diff --git a/citadel/ipc.h b/citadel/ipc.h index ab99d9724..2181bf722 100644 --- a/citadel/ipc.h +++ b/citadel/ipc.h @@ -1,9 +1,68 @@ /* $Id$ */ -void attach_to_server(int argc, char **argv, char *hostbuf, char *portbuf); -extern int server_is_local; -int getsockfd(void); -char serv_getc(void); -int is_connected(void); + +#include "sysdep.h" +#include "client_crypto.h" + +#ifdef HAVE_PTHREAD_H +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Quick and dirty hack; we don't want to use malloc() in C++ */ +#ifdef __cplusplus +#define ialloc(t) new t() +#define ifree(o) delete o +#else +#define ialloc(t) malloc(sizeof(t)) +#define ifree(o) free(o); +#endif + +/* This class is responsible for the server connection */ +typedef struct _CtdlIPC { +#if defined(HAVE_OPENSSL) + /* NULL if not encrypted, non-NULL otherwise */ + SSL *ssl; +#endif +#if defined(HAVE_PTHREAD_H) + /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */ + pthread_mutex_t mutex; +#endif + /* -1 if not connected, >= 0 otherwise */ + int sock; + /* 1 if server is local, 0 otherwise or if not connected */ + int isLocal; +} CtdlIPC; + +/* C constructor */ +CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf); +/* C destructor */ +void CtdlIPC_delete(CtdlIPC* ipc); +/* Convenience destructor; also nulls out caller's pointer */ +void CtdlIPC_delete_ptr(CtdlIPC** pipc); +/* Read a line from server, discarding newline */ +void CtdlIPC_getline(CtdlIPC* ipc, char *buf); +/* Write a line to server, adding newline */ +void CtdlIPC_putline(CtdlIPC* ipc, const char *buf); + +/* Internals */ +int starttls(CtdlIPC *ipc); +void endtls(CtdlIPC *ipc); +void setCryptoStatusHook(void (*hook)(char *s)); +void serv_read(CtdlIPC *ipc, char *buf, int bytes); +void serv_write(CtdlIPC *ipc, const char *buf, int nbytes); +#ifdef HAVE_OPENSSL +void serv_read_ssl(CtdlIPC *ipc, char *buf, int bytes); +void serv_write_ssl(CtdlIPC *ipc, const char *buf, int nbytes); +void ssl_lock(int mode, int n, const char *file, int line); +#endif /* HAVE_OPENSSL */ +/* This is all Ford's doing. FIXME: figure out what it's doing */ extern int (*error_printf)(char *s, ...); void setIPCDeathHook(void (*hook)(void)); void setIPCErrorPrintf(int (*func)(char *s, ...)); + +#ifdef __cplusplus +} +#endif diff --git a/citadel/ipc_c_tcp.c b/citadel/ipc_c_tcp.c index 1680bcbf5..dd0994e4c 100644 --- a/citadel/ipc_c_tcp.c +++ b/citadel/ipc_c_tcp.c @@ -12,6 +12,8 @@ #include "sysdep.h" +#undef NDEBUG +#include #include #include #include @@ -27,8 +29,8 @@ #include #include #include "citadel.h" -#include "citadel_decls.h" #include "ipc.h" +#include "citadel_decls.h" #include "tools.h" #if defined(HAVE_OPENSSL) #include "client_crypto.h" @@ -38,9 +40,9 @@ #endif /* - * If server_is_local is set to nonzero, the client assumes that it is running - * on the same computer as the server. Several things happen when this is - * the case, including the ability to map a specific tty to a particular login + * If ipc->isLocal is set to nonzero, the client assumes that it is running on + * the same computer as the server. Several things happen when this is the + * case, including the ability to map a specific tty to a particular login * session in the "ho is online" listing, the ability to run external * programs, and the ability to download files directly off the disk without * having to first fetch them from the server. @@ -48,13 +50,15 @@ * network session to the local machine) or 0 if the server is executing on * a remote computer. */ -int server_is_local = 0; #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff #endif -int serv_sock; +/* + * FIXME: rewrite all of Ford's stuff here, it won't work with multiple + * instances + */ static void (*deathHook)(void) = NULL; int (*error_printf)(char *s, ...) = (int (*)(char *, ...))printf; @@ -67,7 +71,7 @@ void setIPCErrorPrintf(int (*func)(char *s, ...)) { error_printf = func; } -void connection_died(void) { +void connection_died(CtdlIPC *ipc) { if (deathHook != NULL) deathHook(); @@ -75,15 +79,23 @@ void connection_died(void) { "Last error: %s\n" "Please re-connect and log in again.\n", strerror(errno)); - logoff(3); +#ifdef HAVE_OPENSSL + SSL_shutdown(ipc->ssl); + SSL_free(ipc->ssl); + ipc->ssl = NULL; +#endif + shutdown(ipc->sock, 2); + ipc->sock = -1; } +/* static void ipc_timeout(int signum) { error_printf("\rConnection timed out.\n"); - logoff(3); + logoff(NULL, 3); } +*/ static int connectsock(char *host, char *service, char *protocol, int defaultPort) @@ -113,12 +125,12 @@ static int connectsock(char *host, char *service, char *protocol, int defaultPor } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) { error_printf("Can't get %s host entry: %s\n", host, strerror(errno)); - logoff(3); + return -1; } if ((ppe = getprotobyname(protocol)) == 0) { error_printf("Can't get %s protocol entry: %s\n", protocol, strerror(errno)); - logoff(3); + return -1; } if (!strcmp(protocol, "udp")) { type = SOCK_DGRAM; @@ -129,23 +141,27 @@ static int connectsock(char *host, char *service, char *protocol, int defaultPor s = socket(PF_INET, type, ppe->p_proto); if (s < 0) { error_printf("Can't create socket: %s\n", strerror(errno)); - logoff(3); + return -1; } + /* signal(SIGALRM, ipc_timeout); alarm(30); + */ if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) { - error_printf("can't connect to %s:%s: %s\n", + error_printf("Can't connect to %s:%s: %s\n", host, service, strerror(errno)); - logoff(3); + return -1; } + /* alarm(0); signal(SIGALRM, SIG_IGN); + */ return (s); } -int uds_connectsock(char *sockpath) +static int uds_connectsock(int *isLocal, char *sockpath) { struct sockaddr_un addr; int s; @@ -157,15 +173,15 @@ int uds_connectsock(char *sockpath) s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) { error_printf("Can't create socket: %s\n", strerror(errno)); - logoff(3); + return -1; } if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { error_printf("can't connect: %s\n", strerror(errno)); - logoff(3); + return -1; } - server_is_local = 1; + *isLocal = 1; return s; } @@ -173,21 +189,21 @@ int uds_connectsock(char *sockpath) /* * input binary data from socket */ -void serv_read(char *buf, int bytes) +void serv_read(CtdlIPC *ipc, char *buf, int bytes) { int len, rlen; #if defined(HAVE_OPENSSL) - if (ssl_is_connected) { - serv_read_ssl(buf, bytes); + if (ipc->ssl) { + serv_read_ssl(ipc, buf, bytes); return; } #endif len = 0; while (len < bytes) { - rlen = read(serv_sock, &buf[len], bytes - len); + rlen = read(ipc->sock, &buf[len], bytes - len); if (rlen < 1) { - connection_died(); + connection_died(ipc); return; } len += rlen; @@ -198,22 +214,22 @@ void serv_read(char *buf, int bytes) /* * send binary to server */ -void serv_write(char *buf, int nbytes) +void serv_write(CtdlIPC *ipc, const char *buf, int nbytes) { int bytes_written = 0; int retval; #if defined(HAVE_OPENSSL) - if (ssl_is_connected) { - serv_write_ssl(buf, nbytes); + if (ipc->ssl) { + serv_write_ssl(ipc, buf, nbytes); return; } #endif while (bytes_written < nbytes) { - retval = write(serv_sock, &buf[bytes_written], + retval = write(ipc->sock, &buf[bytes_written], nbytes - bytes_written); if (retval < 1) { - connection_died(); + connection_died(ipc); return; } bytes_written += retval; @@ -225,23 +241,21 @@ void serv_write(char *buf, int nbytes) /* * input string from socket - implemented in terms of serv_read() */ -void serv_gets(char *buf) +void CtdlIPC_getline(CtdlIPC* ipc, char *buf) { int i; - /* Read one character at a time. - */ + /* Read one character at a time. */ for (i = 0;; i++) { - serv_read(&buf[i], 1); + serv_read(ipc, &buf[i], 1); if (buf[i] == '\n' || i == (SIZ-1)) break; } - /* If we got a long line, discard characters until the newline. - */ + /* If we got a long line, discard characters until the newline. */ if (i == (SIZ-1)) while (buf[i] != '\n') - serv_read(&buf[i], 1); + serv_read(ipc, &buf[i], 1); /* Strip the trailing newline. */ @@ -252,24 +266,43 @@ void serv_gets(char *buf) /* * send line to server - implemented in terms of serv_write() */ -void serv_puts(char *buf) +void CtdlIPC_putline(CtdlIPC *ipc, const char *buf) { /* error_printf("< %s\n", buf); */ - serv_write(buf, strlen(buf)); - serv_write("\n", 1); + int watch_ssl = 0; + if (ipc->ssl) watch_ssl = 1; + assert(!watch_ssl || ipc->ssl); + serv_write(ipc, buf, strlen(buf)); + assert(!watch_ssl || ipc->ssl); + serv_write(ipc, "\n", 1); + assert(!watch_ssl || ipc->ssl); } /* * attach to server */ -void attach_to_server(int argc, char **argv, char *hostbuf, char *portbuf) +CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf) { int a; char cithost[SIZ]; char citport[SIZ]; char sockpath[SIZ]; + CtdlIPC *ipc = ialloc(CtdlIPC); + if (!ipc) { + error_printf("Out of memory creating CtdlIPC!\n"); + return 0; + } +#if defined(HAVE_OPENSSL) + ipc->ssl = NULL; +#endif +#if defined(HAVE_PTHREAD_H) + pthread_mutex_init(&(ipc->mutex), NULL); /* Default fast mutex */ +#endif + ipc->sock = -1; /* Not connected */ + ipc->isLocal = 0; /* Not local, of course! */ + strcpy(cithost, DEFAULT_HOST); /* default host */ strcpy(citport, DEFAULT_PORT); /* default port */ @@ -280,52 +313,66 @@ void attach_to_server(int argc, char **argv, char *hostbuf, char *portbuf) strcpy(cithost, argv[a]); } else if (a == 2) { strcpy(citport, argv[a]); - } - else { + } else { error_printf("%s: usage: ",argv[0]); error_printf("%s [host] [port] ",argv[0]); - logoff(2); + ifree(ipc); + return 0; } } if ((!strcmp(cithost, "localhost")) || (!strcmp(cithost, "127.0.0.1"))) { - server_is_local = 1; + ipc->isLocal = 1; } /* If we're using a unix domain socket we can do a bunch of stuff */ if (!strcmp(cithost, UDS)) { snprintf(sockpath, sizeof sockpath, "citadel.socket"); - serv_sock = uds_connectsock(sockpath); + ipc->sock = uds_connectsock(&(ipc->isLocal), sockpath); + if (ipc->sock == -1) { + ifree(ipc); + return 0; + } if (hostbuf != NULL) strcpy(hostbuf, cithost); if (portbuf != NULL) strcpy(portbuf, sockpath); - return; + return ipc; } - serv_sock = connectsock(cithost, citport, "tcp", 504); + ipc->sock = connectsock(cithost, citport, "tcp", 504); + if (ipc->sock == -1) { + ifree(ipc); + return 0; + } if (hostbuf != NULL) strcpy(hostbuf, cithost); if (portbuf != NULL) strcpy(portbuf, citport); - return; + return ipc; } /* * return the file descriptor of the server socket so we can select() on it. + * + * FIXME: This is only used in chat mode; eliminate it when chat mode gets + * rewritten... */ -int getsockfd(void) +int CtdlIPC_getsockfd(CtdlIPC* ipc) { - return serv_sock; + return ipc->sock; } /* * return one character + * + * FIXME: This is only used in chat mode; eliminate it when chat mode gets + * rewritten... */ -char serv_getc(void) +char CtdlIPC_get(CtdlIPC* ipc) { char buf[2]; char ch; - serv_read(buf, 1); + serv_read(ipc, buf, 1); ch = (int) buf[0]; return (ch); diff --git a/citadel/messages.c b/citadel/messages.c index 6d9c1f3b2..e2fd7e761 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -32,13 +32,13 @@ #include #include "citadel.h" +#include "citadel_ipc.h" #include "citadel_decls.h" #include "messages.h" #include "commands.h" #include "rooms.h" #include "tools.h" #include "html.h" -#include "citadel_ipc.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif @@ -57,11 +57,7 @@ struct cittext { void sttybbs(int cmd); int haschar(const char *st, int ch); -int checkpagin(int lp, int pagin, int height); void getline(char *string, int lim); -void formout(char *name); -int yesno(void); -void newprompt(char *prompt, char *str, int len); int file_checksum(char *filename); void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd); @@ -90,14 +86,14 @@ extern char printcmd[]; extern int rc_allow_attachments; extern int rc_display_message_numbers; extern int rc_force_mail_prompts; - extern int editor_pid; +extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */ void ka_sigcatch(int signum) { alarm(S_KEEPALIVE); signal(SIGALRM, ka_sigcatch); - CtdlIPCNoop(); + CtdlIPCNoop(ipc_for_signal_handlers); } @@ -204,7 +200,7 @@ void add_word(struct cittext *textlist, char *wordbuf) /* * begin editing of an opened file pointed to by fp */ -void citedit(FILE * fp) +void citedit(CtdlIPC *ipc, FILE * fp) { int a, prev, finished, b, last_space; int appending = 0; @@ -353,7 +349,7 @@ void citedit(FILE * fp) /* Read a message from the server */ -int read_message( +int read_message(CtdlIPC *ipc, long num, /* message number */ char pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */ FILE *dest) /* Destination file, NULL for screen */ @@ -373,7 +369,7 @@ int read_message( strcpy(reply_to, NO_REPLY_TO); strcpy(reply_subject, ""); - r = CtdlIPCGetSingleMessage(num, (pagin == READ_HEADER ? 1 : 0), + r = CtdlIPCGetSingleMessage(ipc, num, (pagin == READ_HEADER ? 1 : 0), (can_do_msg4 ? 4 : 0), &message, buf); if (r / 100 != 1) { @@ -712,7 +708,8 @@ void replace_string(char *filename, long int startpos) /* * Function to begin composing a new message */ -int client_make_message(char *filename, /* temporary file name */ +int client_make_message(CtdlIPC *ipc, + char *filename, /* temporary file name */ char *recipient, /* NULL if it's not mail */ int anon_type, /* see MES_ types in header file */ int format_type, @@ -787,7 +784,7 @@ ME1: switch (mode) { filename, strerror(errno)); return(1); } - citedit(fp); + citedit(ipc, fp); fclose(fp); goto MECR; @@ -910,7 +907,7 @@ MEABT2: unlink(filename); * This loop also implements a "tick" counter that displays the progress, if * we're sending something that will take a long time to transmit. */ -void transmit_message(FILE *fp) +void transmit_message(CtdlIPC *ipc, FILE *fp) { char buf[SIZ]; int ch, a; @@ -926,7 +923,7 @@ void transmit_message(FILE *fp) if (ch == 10) { if (!strcmp(buf, "000")) strcpy(buf, ">000"); - serv_puts(buf); + CtdlIPC_putline(ipc, buf); strcpy(buf, ""); } else { a = strlen(buf); @@ -936,13 +933,13 @@ void transmit_message(FILE *fp) buf[a] = 0; if (!strcmp(buf, "000")) strcpy(buf, ">000"); - serv_puts(buf); + CtdlIPC_putline(ipc, buf); strcpy(buf, ""); } if (strlen(buf) > 250) { if (!strcmp(buf, "000")) strcpy(buf, ">000"); - serv_puts(buf); + CtdlIPC_putline(ipc, buf); strcpy(buf, ""); } } @@ -955,7 +952,7 @@ void transmit_message(FILE *fp) } } - serv_puts(buf); + CtdlIPC_putline(ipc, buf); scr_printf(" \r"); scr_flush(); } @@ -977,7 +974,8 @@ void check_msg_arr_size(void) { * entmsg() - edit and create a message * returns 0 if message was saved */ -int entmsg(int is_reply, /* nonzero if this was a eply command */ +int entmsg(CtdlIPC *ipc, + int is_reply, /* nonzero if this was a eply command */ int c) /* */ { char buf[300]; @@ -1001,8 +999,8 @@ int entmsg(int is_reply, /* nonzero if this was a eply command */ * this room. The server will return an error code if we can't. */ snprintf(cmd, sizeof cmd, "ENT0 0||0|%d", mode); - serv_puts(cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, cmd); if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) { scr_printf("%s\n", &cmd[4]); @@ -1018,7 +1016,7 @@ int entmsg(int is_reply, /* nonzero if this was a eply command */ /* If the user is a dumbass, tell them how to type. */ if ((userflags & US_EXPERT) == 0) { - formout("entermsg"); + formout(ipc, "entermsg"); } /* Handle the selection of a recipient, if necessary. */ @@ -1062,8 +1060,8 @@ int entmsg(int is_reply, /* nonzero if this was a eply command */ /* If it's mail, we've got to check the validity of the recipient... */ if (strlen(buf) > 0) { snprintf(cmd, sizeof cmd, "ENT0 0|%s|%d|%d|%s", buf, b, mode, subject); - serv_puts(cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] != '2') { scr_printf("%s\n", &cmd[4]); return (1); @@ -1074,19 +1072,19 @@ int entmsg(int is_reply, /* nonzero if this was a eply command */ * tell upon saving whether someone else has posted too. */ num_msgs = 0; - serv_puts("MSGS LAST|1"); - serv_gets(cmd); + CtdlIPC_putline(ipc, "MSGS LAST|1"); + CtdlIPC_getline(ipc, cmd); if (cmd[0] != '1') { scr_printf("%s\n", &cmd[5]); } else { - while (serv_gets(cmd), strcmp(cmd, "000")) { + while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) { check_msg_arr_size(); msg_arr[num_msgs++] = atol(cmd); } } /* Now compose the message... */ - if (client_make_message(temp, buf, b, 0, c, subject) != 0) { + if (client_make_message(ipc, temp, buf, b, 0, c, subject) != 0) { return (2); } @@ -1105,26 +1103,26 @@ int entmsg(int is_reply, /* nonzero if this was a eply command */ /* Transmit message to the server */ snprintf(cmd, sizeof cmd, "ENT0 1|%s|%d|%d|%s|", buf, b, mode, subject); - serv_puts(cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] != '4') { scr_printf("%s\n", &cmd[4]); return (1); } - transmit_message(fp); - serv_puts("000"); + transmit_message(ipc, fp); + CtdlIPC_putline(ipc, "000"); fclose(fp); if (num_msgs >= 1) highmsg = msg_arr[num_msgs - 1]; num_msgs = 0; - serv_puts("MSGS NEW"); - serv_gets(cmd); + CtdlIPC_putline(ipc, "MSGS NEW"); + CtdlIPC_getline(ipc, cmd); if (cmd[0] != '1') { scr_printf("%s\n", &cmd[5]); } else { - while (serv_gets(cmd), strcmp(cmd, "000")) { + while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) { check_msg_arr_size(); msg_arr[num_msgs++] = atol(cmd); } @@ -1206,7 +1204,7 @@ void process_quote(void) /* * List the URL's which were embedded in the previous message */ -void list_urls() +void list_urls(CtdlIPC *ipc) { int i; char cmd[SIZ]; @@ -1231,7 +1229,7 @@ void list_urls() /* * Read the messages in the current room */ -void readmsgs( +void readmsgs(CtdlIPC *ipc, int c, /* 0=Read all 1=Read new 2=Read old 3=Read last q */ int rdir, /* 1=Forward (-1)=Reverse */ int q /* Number of msgs to read (if c==3) */ @@ -1273,12 +1271,12 @@ void readmsgs( snprintf(&cmd[5], sizeof cmd - 5, "LAST|%d", q); break; } - serv_puts(cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] != '1') { scr_printf("%s\n", &cmd[5]); } else { - while (serv_gets(cmd), strcmp(cmd, "000")) { + while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) { check_msg_arr_size(); msg_arr[num_msgs++] = atol(cmd); } @@ -1321,7 +1319,7 @@ RAGAIN: pagin = ((arcflag == 0) } /* now read the message... */ - e = read_message(msg_arr[a], pagin, dest); + e = read_message(ipc, msg_arr[a], pagin, dest); /* ...and set the screenwidth back if we have to */ if ((quotflag) || (arcflag)) { @@ -1361,7 +1359,7 @@ RMSGREAD: scr_flush(); if (rc_alt_semantics && c == 1) { char buf[SIZ]; - r = CtdlIPCSetMessageSeen(msg_arr[a], 1, buf); + r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf); } if (e == 3) return; @@ -1521,7 +1519,7 @@ RMSGREAD: scr_flush(); newprompt("Enter target room: ", targ, ROOMNAMELEN - 1); if (strlen(targ) > 0) { - r = CtdlIPCMoveMessage((e == 'c' ? 1 : 0), + r = CtdlIPCMoveMessage(ipc, (e == 'c' ? 1 : 0), msg_arr[a], targ, cmd); scr_printf("%s\n", cmd); if (r / 100 == 2) @@ -1537,11 +1535,11 @@ RMSGREAD: scr_flush(); ((sizeof filename) - 1)); snprintf(cmd, sizeof cmd, "OPNA %ld|%s", msg_arr[a], filename); - serv_puts(cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] == '2') { extract(filename, &cmd[4], 2); - download_to_local_disk(filename, + download_to_local_disk(ipc, filename, extract_int(&cmd[4], 0)); } else { @@ -1551,7 +1549,7 @@ RMSGREAD: scr_flush(); case 'd': scr_printf("*** Delete this message? "); if (yesno() == 1) { - r = CtdlIPCDeleteMessage(msg_arr[a], cmd); + r = CtdlIPCDeleteMessage(ipc, msg_arr[a], cmd); scr_printf("%s\n", cmd); if (r / 100 == 2) msg_arr[a] = 0L; @@ -1560,15 +1558,15 @@ RMSGREAD: scr_flush(); } break; case 'h': - read_message(msg_arr[a], READ_HEADER, NULL); + read_message(ipc, msg_arr[a], READ_HEADER, NULL); goto RMSGREAD; case 'r': savedpos = num_msgs; - entmsg(1, (DEFAULT_ENTRY == 46 ? 2 : 0)); + entmsg(ipc, 1, (DEFAULT_ENTRY == 46 ? 2 : 0)); num_msgs = savedpos; goto RMSGREAD; case 'u': - list_urls(); + list_urls(ipc); goto RMSGREAD; case 'y': { /* hack hack hack */ @@ -1583,9 +1581,9 @@ RMSGREAD: scr_flush(); int founda = 0; snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]); /* read the header so we can get 'from=' */ - serv_puts(buf); - serv_gets(buf); - while (serv_gets(buf), strcmp(buf, "000")) + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { if ((!strncasecmp(buf, "from=", 5)) && (finda != a)) /* Skip current message. */ { @@ -1630,7 +1628,7 @@ void edit_system_message(char *which_message) /* * Verify the message base */ -void check_message_base(void) +void check_message_base(CtdlIPC *ipc) { char buf[SIZ]; @@ -1640,14 +1638,14 @@ void check_message_base(void) if (yesno() == 0) return; - serv_puts("FSCK"); - serv_gets(buf); + CtdlIPC_putline(ipc, "FSCK"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { scr_printf("%s\n", &buf[4]); return; } - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { scr_printf("%s\n", buf); } } diff --git a/citadel/messages.h b/citadel/messages.h index c848472f4..0f65e744c 100644 --- a/citadel/messages.h +++ b/citadel/messages.h @@ -1,16 +1,17 @@ /* $Id$ */ int ka_system(char *shc); -int entmsg(int is_reply, int c); -void readmsgs(int c, int rdir, int q); +int entmsg(CtdlIPC *ipc, int is_reply, int c); +void readmsgs(CtdlIPC *ipc, int c, int rdir, int q); void edit_system_message(char *which_message); pid_t ka_wait(int *kstatus); -void list_urls(void); -void check_message_base(void); -int client_make_message(char *filename, /* temporary file name */ +void list_urls(CtdlIPC *ipc); +void check_message_base(CtdlIPC *ipc); +int client_make_message(CtdlIPC *ipc, + char *filename, /* temporary file name */ char *recipient, /* NULL if it's not mail */ int anon_type, /* see MES_ types in header file */ int format_type, int mode, char *subject); -void citedit(FILE *); +void citedit(CtdlIPC *ipc, FILE *); int file_checksum(char *filename); diff --git a/citadel/migratenet.c b/citadel/migratenet.c index ded52ff64..026c3ea5f 100644 --- a/citadel/migratenet.c +++ b/citadel/migratenet.c @@ -16,7 +16,7 @@ #include #endif #include "citadel.h" -#include "ipc.h" +#include "citadel_ipc.h" #include "tools.h" #include "config.h" @@ -46,8 +46,11 @@ int main(int argc, char **argv) char roomfilename[SIZ]; FILE *nodefp; char nodefilename[SIZ]; + char *listing = NULL; struct mn_roomlist *mn = NULL; struct mn_roomlist *mnptr = NULL; + CtdlIPC *ipc = NULL; + int r; printf("\n\n\n\n\n" "This utility migrates your network settings (room sharing with other\n" @@ -61,19 +64,17 @@ int main(int argc, char **argv) get_config(); - attach_to_server(argc, argv, hostbuf, portbuf); - serv_gets(buf); + ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf); + CtdlIPC_getline(ipc, buf); printf("%s\n", &buf[4]); if ( (buf[0]!='2') && (strncmp(buf,"551",3)) ) { fprintf(stderr, "%s: %s\n", argv[0], &buf[4]); logoff(atoi(buf)); } - snprintf(buf, sizeof buf, "IPGM %d", config.c_ipgm_secret); - serv_puts(buf); - serv_gets(buf); - fprintf(stderr, "%s\n", &buf[4]); - if (buf[0] != '2') { + r = CtdlIPCInternalProgram(ipc, config.c_ipgm_secret, buf); + fprintf(stderr, "%s\n", buf); + if (r / 100 != 2) { exit(2); } @@ -146,30 +147,27 @@ int main(int argc, char **argv) fclose(nodefp); /* Point of no return */ + nodefp = fopen(nodefilename, "r"); + if (nodefp != NULL) { + fseek(nodefp, 0L, SEEK_END); + listing = malloc(ftell(nodefp) + 1); + *listing = 0; + while (fgets(buf, sizeof buf, nodefp) != NULL) { + strcat(listing, buf); + } + fclose(nodefp); + } /* Set up the node table */ printf("Creating neighbor node table\n"); - snprintf(buf, sizeof buf, "CONF putsys|%s", IGNETCFG); - serv_puts(buf); - serv_gets(buf); - if (buf[0] == '4') { - nodefp = fopen(nodefilename, "r"); - if (nodefp != NULL) { - while (fgets(buf, sizeof buf, nodefp) != NULL) { - buf[strlen(buf)-1] = 0; - serv_puts(buf); - } - fclose(nodefp); - } - serv_puts("000"); - } - else { - printf("%s\n", &buf[4]); + r = CtdlSetSystemConfigByType(ipc, IGNETCFG, listing, buf); + free(listing); + listing = NULL; + if (r / 100 != 4) { + printf("%s\n", buf); } - /* Now go through the table looking for node names to enter */ - snprintf(buf, sizeof buf, "cat %s |awk -F \"|\" '{ print $2 }' |sort -f |uniq -i", roomfilename); roomfp = popen(buf, "r"); @@ -193,20 +191,22 @@ int main(int argc, char **argv) /* Enter configurations for each room... */ while (mn != NULL) { + struct ctdlipcroom *current_room = NULL; + printf("Room <%s>\n", mn->roomname); - snprintf(buf, sizeof buf, "GOTO %s", mn->roomname); - serv_puts(buf); - serv_gets(buf); - printf("%s\n", &buf[4]); - if (buf[0] != '2') goto roomerror; + r = CtdlIPCGotoRoom(ipc, mn->roomname, NULL, + ¤t_room, buf); + printf("%s\n", buf); + if (r / 100 != 2) goto roomerror; - serv_puts("SNET"); - serv_gets(buf); + /* Hey IG, what the hell is SNET? */ + CtdlIPC_putline(ipc, "SNET"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '4') goto roomerror; snprintf(buf, sizeof buf, "lastsent|%ld", highest); - serv_puts(buf); + CtdlIPC_putline(ipc, buf); roomfp = fopen(roomfilename, "r"); if (roomfp != NULL) { @@ -217,13 +217,13 @@ int main(int argc, char **argv) if (!strcasecmp(room, mn->roomname)) { snprintf(buf, sizeof buf, "ignet_push_share|%s", node); - serv_puts(buf); + CtdlIPC_putline(ipc, buf); } } fclose(roomfp); } - serv_puts("000"); + CtdlIPC_putline(ipc, "000"); roomerror: /* free this record */ mnptr = mn->next; diff --git a/citadel/rooms.c b/citadel/rooms.c index 7f6263420..62ec79e00 100644 --- a/citadel/rooms.c +++ b/citadel/rooms.c @@ -21,6 +21,7 @@ #include #include "citadel.h" #include "citadel_ipc.h" +#include "citadel_decls.h" #include "rooms.h" #include "commands.h" #include "tools.h" @@ -35,13 +36,7 @@ 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); -void dotgoto(char *towhere, int display_name, int fromungoto); -void serv_read(char *buf, int bytes); -void formout(char *name); -int inkey(void); +void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto); void progress(long int curr, long int cmax); int pattern(char *search, char *patn); int file_checksum(char *filename); @@ -56,7 +51,6 @@ 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; @@ -71,7 +65,7 @@ extern int uglistsize; extern char floorlist[128][SIZ]; -void load_floorlist(void) +void load_floorlist(CtdlIPC *ipc) { int a; char buf[SIZ]; @@ -81,7 +75,7 @@ void load_floorlist(void) for (a = 0; a < 128; ++a) floorlist[a][0] = 0; - r = CtdlIPCFloorListing(&listing, buf); + r = CtdlIPCFloorListing(ipc, &listing, buf); if (r / 100 != 1) { strcpy(floorlist[0], "Main Floor"); return; @@ -172,7 +166,7 @@ int rordercmp(struct roomlisting *r1, struct roomlisting *r2) /* * Common code for all room listings */ -void listrms(char *variety) +void listrms(CtdlIPC *ipc, char *variety) { char buf[SIZ]; @@ -182,12 +176,12 @@ void listrms(char *variety) /* Ask the server for a room list */ - serv_puts(variety); - serv_gets(buf); + CtdlIPC_putline(ipc, variety); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { return; } - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { rp = malloc(sizeof(struct roomlisting)); extract(rp->rlname, buf, 0); rp->rlflags = extract_int(buf, 1); @@ -248,20 +242,20 @@ void list_other_floors(void) * 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[SIZ]; int a; - load_floorlist(); + load_floorlist(ipc); if (kn_floor_mode == 0) { color(BRIGHT_CYAN); pprintf("\n Rooms with unread messages:\n"); - listrms("LKRN"); + listrms(ipc, "LKRN"); color(BRIGHT_CYAN); pprintf("\n\n No unseen messages in:\n"); - listrms("LKRO"); + listrms(ipc, "LKRO"); pprintf("\n"); } @@ -270,12 +264,12 @@ void knrooms(int kn_floor_mode) pprintf("\n Rooms with unread messages on %s:\n", floorlist[(int) curr_floor]); snprintf(buf, sizeof buf, "LKRN %d", curr_floor); - listrms(buf); + listrms(ipc, buf); color(BRIGHT_CYAN); pprintf("\n\n Rooms with no new messages on %s:\n", floorlist[(int) curr_floor]); snprintf(buf, sizeof buf, "LKRO %d", curr_floor); - listrms(buf); + listrms(ipc, buf); color(BRIGHT_CYAN); pprintf("\n\n Other floors:\n"); list_other_floors(); @@ -289,7 +283,7 @@ void knrooms(int kn_floor_mode) pprintf("\n Rooms on %s:\n", floorlist[a]); snprintf(buf, sizeof buf, "LKRA %d", a); - listrms(buf); + listrms(ipc, buf); pprintf("\n"); } } @@ -300,18 +294,18 @@ void knrooms(int kn_floor_mode) } -void listzrooms(void) +void listzrooms(CtdlIPC *ipc) { /* list public forgotten rooms */ color(BRIGHT_CYAN); pprintf("\n Forgotten public rooms:\n"); - listrms("LZRM"); + listrms(ipc, "LZRM"); pprintf("\n"); color(DIM_WHITE); IFNEXPERT hit_any_key(); } -int set_room_attr(int ibuf, char *prompt, unsigned int sbit) +int set_room_attr(CtdlIPC *ipc, int ibuf, char *prompt, unsigned int sbit) { int a; @@ -330,21 +324,20 @@ int set_room_attr(int ibuf, char *prompt, unsigned int sbit) * 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[SIZ]; if (floor_mode == 1) { if (floorlist[(int) curr_floor][0] == 0) { - load_floorlist(); + load_floorlist(ipc); } do { newfloor = (-1); safestrncpy(floorstr, floorlist[rfloor], sizeof floorstr); - strprompt("Which floor", floorstr, SIZ); for (a = 0; a < 128; ++a) { if (!strcasecmp (floorstr, &floorlist[a][0])) @@ -381,7 +374,7 @@ int select_floor(int rfloor) /* * .ide dit room */ -void editthisroom(void) +void editthisroom(CtdlIPC *ipc) { char rname[ROOMNAMELEN]; char rpass[10]; @@ -399,8 +392,8 @@ void editthisroom(void) int r; /* IPC response code */ /* Fetch the existing room config */ - serv_puts("GETR"); - serv_gets(buf); + CtdlIPC_putline(ipc, "GETR"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); return; @@ -417,8 +410,8 @@ void editthisroom(void) rbump = 0; /* Fetch the name of the current room aide */ - serv_puts("GETA"); - serv_gets(buf); + CtdlIPC_putline(ipc, "GETA"); + CtdlIPC_getline(ipc, buf); if (buf[0] == '2') { safestrncpy(raide, &buf[4], sizeof raide); } @@ -432,20 +425,19 @@ void editthisroom(void) /* Fetch the expire policy (this will silently fail on old servers, * resulting in "default" policy) */ - serv_puts("GPEX room"); - serv_gets(buf); + CtdlIPC_putline(ipc, "GPEX room"); + CtdlIPC_getline(ipc, buf); if (buf[0] == '2') { expire_mode = extract_int(&buf[4], 0); expire_value = extract_int(&buf[4], 1); } /* Now interact with the user. */ - strprompt("Room name", rname, ROOMNAMELEN - 1); - rfloor = select_floor(rfloor); - rflags = set_room_attr(rflags, "Private room", QR_PRIVATE); + rfloor = select_floor(ipc, rfloor); + rflags = set_room_attr(ipc, rflags, "Private room", QR_PRIVATE); if (rflags & QR_PRIVATE) { - rflags = set_room_attr(rflags, + rflags = set_room_attr(ipc, rflags, "Accessible by guessing room name", QR_GUESSNAME); } @@ -463,7 +455,7 @@ void editthisroom(void) /* if it's private, choose the privacy classes */ if ((rflags & QR_PRIVATE) && ((rflags & QR_GUESSNAME) == 0)) { - rflags = set_room_attr(rflags, + rflags = set_room_attr(ipc, rflags, "Accessible by entering a password", QR_PASSWORDED); } @@ -478,29 +470,29 @@ void editthisroom(void) } 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); + set_room_attr(ipc, rflags, "Preferred users only", QR_PREFONLY); + rflags = set_room_attr(ipc, rflags, "Read-only room", QR_READONLY); + rflags = set_room_attr(ipc, rflags, "Directory room", QR_DIRECTORY); + rflags = set_room_attr(ipc, rflags, "Permanent room", QR_PERMANENT); if (rflags & QR_DIRECTORY) { strprompt("Directory name", rdir, 14); rflags = - set_room_attr(rflags, "Uploading allowed", QR_UPLOAD); + set_room_attr(ipc, rflags, "Uploading allowed", QR_UPLOAD); rflags = - set_room_attr(rflags, "Downloading allowed", + set_room_attr(ipc, rflags, "Downloading allowed", QR_DOWNLOAD); rflags = - set_room_attr(rflags, "Visible directory", QR_VISDIR); + set_room_attr(ipc, rflags, "Visible directory", QR_VISDIR); } - rflags = set_room_attr(rflags, "Network shared room", QR_NETWORK); - rflags2 = set_room_attr(rflags2, + rflags = set_room_attr(ipc, rflags, "Network shared room", QR_NETWORK); + rflags2 = set_room_attr(ipc, rflags2, "Self-service list subscribe/unsubscribe", QR2_SELFLIST); - rflags = set_room_attr(rflags, + rflags = set_room_attr(ipc, rflags, "Automatically make all messages anonymous", QR_ANONONLY); if ((rflags & QR_ANONONLY) == 0) { - rflags = set_room_attr(rflags, + rflags = set_room_attr(ipc, rflags, "Ask users whether to make messages anonymous", QR_ANONOPT); } @@ -513,7 +505,7 @@ void editthisroom(void) strcpy(raide, ""); break; } else { - r = CtdlIPCQueryUsername(raide, buf); + r = CtdlIPCQueryUsername(ipc, raide, buf); if (r / 100 != 2) scr_printf("%s\n", buf); } @@ -555,22 +547,22 @@ void editthisroom(void) scr_printf("Save changes (y/n)? "); if (yesno() == 1) { - r = CtdlIPCSetRoomAide(raide, buf); + r = CtdlIPCSetRoomAide(ipc, raide, buf); if (r != 2) { scr_printf("%s\n", buf); } - r = CtdlIPCSetMessageExpirationPolicy(0, expire_mode, + r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, expire_mode, expire_value, buf); snprintf(buf, sizeof buf, "SETR %s|%s|%s|%d|%d|%d|%d|%d|%d", rname, rpass, rdir, rflags, rbump, rfloor, rorder, rview, rflags2); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); scr_printf("%s\n", &buf[4]); if (buf[0] == '2') - dotgoto(rname, 2, 0); + dotgoto(ipc, rname, 2, 0); } } @@ -578,7 +570,7 @@ void editthisroom(void) /* * un-goto the previous room */ -void ungoto(void) +void ungoto(CtdlIPC *ipc) { char buf[SIZ]; @@ -586,22 +578,23 @@ void ungoto(void) return; snprintf(buf, sizeof buf, "GOTO %s", uglist[uglistsize-1]); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); return; } snprintf(buf, sizeof buf, "SLRP %ld", uglistlsn[uglistsize-1]); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); } safestrncpy (buf, uglist[uglistsize-1], sizeof(buf)); uglistsize--; free(uglist[uglistsize]); - dotgoto(buf, 0, 1); /* Don't queue ungoto info or we end up in a loop */ + /* Don't queue ungoto info or we end up in a loop */ + dotgoto(ipc, buf, 0, 1); } @@ -610,7 +603,8 @@ void ungoto(void) * the [XYZ]modem code below... * (This function assumes that a download file is already open on the server) */ -void download_to_local_disk(char *supplied_filename, long total_bytes) +void download_to_local_disk(CtdlIPC *ipc, + char *supplied_filename, long total_bytes) { char buf[SIZ]; char dbuf[4096]; @@ -638,8 +632,8 @@ void download_to_local_disk(char *supplied_filename, long total_bytes) if (savefp == NULL) { scr_printf("Cannot open '%s': %s\n", dbuf, strerror(errno)); /* close the download file at the server */ - serv_puts("CLOS"); - serv_gets(buf); + CtdlIPC_putline(ipc, "CLOS"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); } @@ -650,14 +644,14 @@ void download_to_local_disk(char *supplied_filename, long total_bytes) bb = total_bytes - transmitted_bytes; aa = ((bb < 4096) ? bb : 4096); snprintf(buf, sizeof buf, "READ %ld|%ld", transmitted_bytes, aa); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '6') { scr_printf("%s\n", &buf[4]); return; } packet = extract_int(&buf[4], 0); - serv_read(dbuf, packet); + serv_read(ipc, dbuf, packet); if (fwrite(dbuf, packet, 1, savefp) < 1) broken = 1; transmitted_bytes = transmitted_bytes + (long) packet; @@ -665,8 +659,8 @@ void download_to_local_disk(char *supplied_filename, long total_bytes) } fclose(savefp); /* close the download file at the server */ - serv_puts("CLOS"); - serv_gets(buf); + CtdlIPC_putline(ipc, "CLOS"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); } @@ -679,7 +673,7 @@ void download_to_local_disk(char *supplied_filename, long total_bytes) * 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[SIZ]; char filename[SIZ]; @@ -701,8 +695,8 @@ void download(int proto) newprompt("Enter filename: ", filename, 255); snprintf(buf, sizeof buf, "OPEN %s", filename); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); return; @@ -711,7 +705,7 @@ void download(int proto) /* Save to local disk, for folks with their own copy of the client */ if (proto == 5) { - download_to_local_disk(filename, total_bytes); + download_to_local_disk(ipc, filename, total_bytes); return; } @@ -725,13 +719,13 @@ void download(int proto) bb = total_bytes - transmitted_bytes; aa = ((bb < 4096) ? bb : 4096); snprintf(buf, sizeof buf, "READ %ld|%ld", transmitted_bytes, aa); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '6') { scr_printf("%s\n", &buf[4]); } packet = extract_int(&buf[4], 0); - serv_read(dbuf, packet); + serv_read(ipc, dbuf, packet); if (fwrite(dbuf, packet, 1, tpipe) < 1) { broken = 1; } @@ -741,8 +735,8 @@ void download(int proto) progress(transmitted_bytes, total_bytes); /* close the download file at the server */ - serv_puts("CLOS"); - serv_gets(buf); + CtdlIPC_putline(ipc, "CLOS"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); } @@ -776,15 +770,15 @@ void download(int proto) /* * read directory of this room */ -void roomdir(void) +void roomdir(CtdlIPC *ipc) { char flnm[SIZ]; char flsz[32]; char comment[SIZ]; char buf[SIZ]; - serv_puts("RDIR"); - serv_gets(buf); + CtdlIPC_putline(ipc, "RDIR"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { pprintf("%s\n", &buf[4]); return; @@ -794,7 +788,7 @@ void roomdir(void) extract(flnm, &buf[4], 1); pprintf("\nDirectory of %s on %s\n", flnm, comment); pprintf("-----------------------\n"); - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { extract(flnm, buf, 0); extract(flsz, buf, 1); extract(comment, buf, 2); @@ -810,7 +804,7 @@ void roomdir(void) /* * add a user to a private room */ -void invite(void) +void invite(CtdlIPC *ipc) { char username[USERNAME_SIZE]; char buf[SIZ]; @@ -820,7 +814,7 @@ void invite(void) if (username[0] == 0) return; - r = CtdlIPCInviteUserToRoom(username, buf); + r = CtdlIPCInviteUserToRoom(ipc, username, buf); scr_printf("%s\n", buf); } @@ -828,7 +822,7 @@ void invite(void) /* * kick a user out of a room */ -void kickout(void) +void kickout(CtdlIPC *ipc) { char username[USERNAME_SIZE]; char buf[SIZ]; @@ -838,7 +832,7 @@ void kickout(void) if (username[0] == 0) return; - r = CtdlIPCKickoutUserFromRoom(username, buf); + r = CtdlIPCKickoutUserFromRoom(ipc, username, buf); scr_printf("%s\n", buf); } @@ -846,12 +840,12 @@ void kickout(void) /* * aide command: kill the current room */ -void killroom(void) +void killroom(CtdlIPC *ipc) { char aaa[100]; int r; - r = CtdlIPCDeleteRoom(0, aaa); + r = CtdlIPCDeleteRoom(ipc, 0, aaa); if (r / 100 != 2) { scr_printf("%s\n", aaa); return; @@ -861,14 +855,14 @@ void killroom(void) if (yesno() == 0) return; - r = CtdlIPCDeleteRoom(1, aaa); + r = CtdlIPCDeleteRoom(ipc, 1, aaa); scr_printf("%s\n", aaa); if (r / 100 != 2) return; - dotgoto("_BASEROOM_", 0, 0); + dotgoto(ipc, "_BASEROOM_", 0, 0); } -void forget(void) +void forget(CtdlIPC *ipc) { /* forget the current room */ char buf[SIZ]; @@ -876,20 +870,20 @@ void forget(void) if (yesno() == 0) return; - if (CtdlIPCForgetRoom(buf) / 100 != 2) { + if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) { scr_printf("%s\n", buf); return; } /* now return to the lobby */ - dotgoto("_BASEROOM_", 0, 0); + dotgoto(ipc, "_BASEROOM_", 0, 0); } /* * create a new room */ -void entroom(void) +void entroom(CtdlIPC *ipc) { char buf[SIZ]; char new_room_name[ROOMNAMELEN]; @@ -900,7 +894,7 @@ void entroom(void) int r; /* IPC response code */ /* Check permission to create room */ - r = CtdlIPCCreateRoom(0, "", 1, "", 0, buf); + r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf); if (r / 100 != 2) { scr_printf("%s\n", buf); return; @@ -916,9 +910,9 @@ void entroom(void) } } - 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 { scr_printf("Help\n<1>Public room\n<2>Guess-name room\n" "<3>Passworded room\n<4>Invitation-only room\n" @@ -929,7 +923,7 @@ void entroom(void) } while (((b < '1') || (b > '5')) && (b != '?')); if (b == '?') { scr_printf("?\n"); - formout("roomaccess"); + formout(ipc, "roomaccess"); } } while ((b < '1') || (b > '5')); b -= '0'; /* Portable */ @@ -960,7 +954,7 @@ void entroom(void) return; } - r = CtdlIPCCreateRoom(1, new_room_name, new_room_type, + 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); @@ -968,12 +962,12 @@ void entroom(void) } /* command succeeded... now GO to the new room! */ - dotgoto(new_room_name, 0, 0); + dotgoto(ipc, new_room_name, 0, 0); } -void readinfo(void) +void readinfo(CtdlIPC *ipc) { /* read info file for current room */ char buf[SIZ]; char raide[64]; @@ -981,7 +975,7 @@ void readinfo(void) char *text = NULL; /* Name of currernt room aide */ - r = CtdlIPCGetRoomAide(buf); + r = CtdlIPCGetRoomAide(ipc, buf); if (r / 100 == 2) safestrncpy(raide, buf, sizeof raide); else @@ -990,7 +984,7 @@ void readinfo(void) if (strlen(raide) > 0) scr_printf("Room aide is %s.\n\n", raide); - r = CtdlIPCRoomInfo(&text, buf); + r = CtdlIPCRoomInfo(ipc, &text, buf); if (r / 100 != 1) return; @@ -1006,23 +1000,24 @@ void readinfo(void) /* * ho knows room... */ -void whoknows(void) +void whoknows(CtdlIPC *ipc) { char buf[SIZ]; - serv_puts("WHOK"); - serv_gets(buf); + CtdlIPC_putline(ipc, "WHOK"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { pprintf("%s\n", &buf[4]); return; } - while (serv_gets(buf), strncmp(buf, "000", 3)) { + while (CtdlIPC_getline(ipc, buf), strncmp(buf, "000", 3)) { if (sigcaught == 0) pprintf("%s\n", buf); } } -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[SIZ]; @@ -1038,19 +1033,19 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd) fp = fopen(temp, "w"); fclose(fp); - serv_puts(check_cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, check_cmd); + CtdlIPC_getline(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); + CtdlIPC_putline(ipc, read_cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] == '1') { fp = fopen(temp, "w"); - while (serv_gets(cmd), strcmp(cmd, "000")) { + while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) { fprintf(fp, "%s\n", cmd); } fclose(fp); @@ -1085,7 +1080,7 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd) scr_printf("Entering %s. " "Press return twice when finished.\n", desc); fp = fopen(temp, "r+"); - citedit(fp); + citedit(ipc, fp); fclose(fp); } @@ -1094,8 +1089,8 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd) } else { - serv_puts(write_cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, write_cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] != '4') { scr_printf("%s\n", &cmd[4]); return; @@ -1104,72 +1099,72 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd) fp = fopen(temp, "r"); while (fgets(cmd, SIZ - 1, fp) != NULL) { cmd[strlen(cmd) - 1] = 0; - serv_puts(cmd); + CtdlIPC_putline(ipc, cmd); } fclose(fp); - serv_puts("000"); + CtdlIPC_putline(ipc, "000"); } unlink(temp); } -void enterinfo(void) +void enterinfo(CtdlIPC *ipc) { /* edit info file for current room */ - do_edit("the Info file for this room", "RINF", "EINF 0", "EINF 1"); + do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1"); } -void enter_bio(void) +void enter_bio(CtdlIPC *ipc) { char cmd[SIZ]; snprintf(cmd, sizeof cmd, "RBIO %s", fullname); - do_edit("your Bio", cmd, "NOOP", "EBIO"); + do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO"); } /* * create a new floor */ -void create_floor(void) +void create_floor(CtdlIPC *ipc) { char buf[SIZ]; char newfloorname[SIZ]; int r; /* IPC response code */ - load_floorlist(); + load_floorlist(ipc); - r = CtdlIPCCreateFloor(0, "", buf); + r = CtdlIPCCreateFloor(ipc, 0, "", buf); if (r / 100 != 2) { scr_printf("%s\n", buf); return; } newprompt("Name for new floor: ", newfloorname, 255); - r = CtdlIPCCreateFloor(1, newfloorname, buf); + 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(); + load_floorlist(ipc); } /* * edit the current floor */ -void edit_floor(void) +void edit_floor(CtdlIPC *ipc) { char buf[SIZ]; int expire_mode = 0; int expire_value = 0; int r; /* IPC response code */ - load_floorlist(); + load_floorlist(ipc); /* Fetch the expire policy (this will silently fail on old servers, * resulting in "default" policy) */ - r = CtdlIPCGetMessageExpirationPolicy(1, buf); + r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, buf); if (r / 100 == 2) { expire_mode = extract_int(buf, 0); expire_value = extract_int(buf, 1); @@ -1210,11 +1205,11 @@ void edit_floor(void) } /* Save it */ - r = CtdlIPCSetMessageExpirationPolicy(1, expire_mode, + r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, expire_mode, expire_value, buf); - r = CtdlIPCEditFloor(curr_floor, &floorlist[(int)curr_floor][0], buf); + r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf); scr_printf("%s\n", buf); - load_floorlist(); + load_floorlist(ipc); } @@ -1223,12 +1218,12 @@ void edit_floor(void) /* * kill the current floor */ -void kill_floor(void) +void kill_floor(CtdlIPC *ipc) { int floornum_to_delete, a; char buf[SIZ]; - load_floorlist(); + load_floorlist(ipc); do { floornum_to_delete = (-1); scr_printf("(Press return to abort)\n"); @@ -1245,7 +1240,7 @@ void kill_floor(void) scr_printf("%s\n", &floorlist[a][0]); } } while (floornum_to_delete < 0); - CtdlIPCDeleteFloor(1, floornum_to_delete, buf); + CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf); scr_printf("%s\n", buf); - load_floorlist(); + load_floorlist(ipc); } diff --git a/citadel/rooms.h b/citadel/rooms.h index 4f9b98c10..1b54cdd41 100644 --- a/citadel/rooms.h +++ b/citadel/rooms.h @@ -1,24 +1,24 @@ /* $Id$ */ -void listzrooms(void); -void readinfo(void); -void forget(void); -void entroom(void); -void killroom(void); -void invite(void); -void kickout(void); -void editthisroom(void); -void roomdir(void); -void download(int proto); -void ungoto(void); -void whoknows(void); -void enterinfo(void); -void knrooms(int kn_floor_mode); -void load_floorlist(void); -void create_floor(void); -void edit_floor(void); -void kill_floor(void); -void enter_bio(void); -void download_to_local_disk(char *, long); +void listzrooms(CtdlIPC *ipc); +void readinfo(CtdlIPC *ipc); +void forget(CtdlIPC *ipc); +void entroom(CtdlIPC *ipc); +void killroom(CtdlIPC *ipc); +void invite(CtdlIPC *ipc); +void kickout(CtdlIPC *ipc); +void editthisroom(CtdlIPC *ipc); +void roomdir(CtdlIPC *ipc); +void download(CtdlIPC *ipc, int proto); +void ungoto(CtdlIPC *ipc); +void whoknows(CtdlIPC *ipc); +void enterinfo(CtdlIPC *ipc); +void knrooms(CtdlIPC *ipc, int kn_floor_mode); +void load_floorlist(CtdlIPC *ipc); +void create_floor(CtdlIPC *ipc); +void edit_floor(CtdlIPC *ipc); +void kill_floor(CtdlIPC *ipc); +void enter_bio(CtdlIPC *ipc); +void download_to_local_disk(CtdlIPC *ipc, char *, long); void hit_any_key(void); diff --git a/citadel/routines.c b/citadel/routines.c index b86493d29..fd96cbaea 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -76,7 +76,7 @@ void back(int spaces) { } } -void hit_any_key(void) { /* hit any key to continue */ +void hit_any_key(CtdlIPC *ipc) { /* hit any key to continue */ int a,b; color(COLOR_PUSH); @@ -103,7 +103,7 @@ void hit_any_key(void) { /* hit any key to continue */ /* * change a user's access level */ -void edituser(void) +void edituser(CtdlIPC *ipc) { char buf[SIZ]; char who[USERNAME_SIZE]; @@ -112,11 +112,11 @@ void edituser(void) int r; /* IPC response code */ newprompt("User name: ", who, 25); - while ((r = CtdlIPCAideGetUserParameters(who, &user, buf)) / 100 != 2) { + while ((r = CtdlIPCAideGetUserParameters(ipc, who, &user, buf)) / 100 != 2) { scr_printf("%s\n", buf); scr_printf("Do you want to create this user? "); if (yesno()) { - r = CtdlIPCCreateUser(who, 0, buf); + r = CtdlIPCCreateUser(ipc, who, 0, buf); if (r / 100 == 2) { newnow = 1; continue; @@ -127,7 +127,7 @@ void edituser(void) return; } - val_user(user->fullname, 0); /* Display registration */ + val_user(ipc, user->fullname, 0); /* Display registration */ if (newnow || boolprompt("Change password", 0)) { /* I'm lazy */ strprompt("Password", user->password, -19); @@ -147,7 +147,7 @@ void edituser(void) user->USuserpurge = intprompt("Purge time (in days, 0 for system default", user->USuserpurge, 0, INT_MAX); - r = CtdlIPCAideSetUserParameters(user, buf); + r = CtdlIPCAideSetUserParameters(ipc, user, buf); if (r / 100 != 2) { scr_printf("%s\n", buf); } @@ -159,7 +159,7 @@ void edituser(void) * yes or no. Yes=1 and No=0, unless 'backwards' is set to a nonzero value * in which case No=1 and Yes=0. */ -int set_attr(int sval, char *prompt, unsigned int sbit, int backwards) +int set_attr(CtdlIPC *ipc, int sval, char *prompt, unsigned int sbit, int backwards) { int a; int temp; @@ -196,13 +196,13 @@ int set_attr(int sval, char *prompt, unsigned int sbit, int backwards) * modes are: 0 - .EC command, 1 - .EC for new user, * 2 - toggle Xpert mode 3 - toggle floor mode */ -void enter_config(int mode) +void enter_config(CtdlIPC *ipc, int mode) { char buf[SIZ]; struct usersupp *user = NULL; int r; /* IPC response code */ - r = CtdlIPCGetConfig(&user, buf); + r = CtdlIPCGetConfig(ipc, &user, buf); if (r / 100 != 2) { scr_printf("%s\n", buf); free(user); @@ -216,7 +216,7 @@ void enter_config(int mode) user->USscreenheight = intprompt("Enter your screen height", user->USscreenheight, 3, 255); - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Are you an experienced Citadel user", US_EXPERT, 0); if ((user->flags & US_EXPERT) == 0 && mode == 1) { @@ -224,42 +224,42 @@ void enter_config(int mode) return; } - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Print last old message on New message request", US_LASTOLD, 0); - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Prompt after each message", US_NOPROMPT, 1); if ((user->flags & US_NOPROMPT) == 0) - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Use 'disappearing' prompts", US_DISAPPEAR, 0); - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Pause after each screenful of text", US_PAGINATOR, 0); if (rc_prompt_control == 3 && (user->flags & US_PAGINATOR)) - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "ext and top work at paginator prompt", US_PROMPTCTL, 0); if (rc_floor_mode == RC_DEFAULT) - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "View rooms by floor", US_FLOORS, 0); if (rc_ansi_color == 3) - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Enable color support", US_COLOR, 0); if ((user->flags & US_EXPERT) == 0) - formout("unlisted"); + formout(ipc, "unlisted"); - user->flags = set_attr(user->flags, + user->flags = set_attr(ipc, user->flags, "Be unlisted in userlog", US_UNLISTED, 0); } @@ -284,7 +284,7 @@ void enter_config(int mode) } } - r = CtdlIPCSetConfig(user, buf); + r = CtdlIPCSetConfig(ipc, user, buf); if (r / 100 != 2) scr_printf("%s\n", buf); userflags = user->flags; free(user); @@ -327,12 +327,15 @@ int pattern(char *search, char *patn) { /* display internal error as defined in errmsgs */ +/* void interr(int errnum) { scr_printf("*** INTERNAL ERROR %d\n" "(Press any key to continue)\n", errnum); inkey(); logoff(errnum); } +*/ + void strproc(char *string) { @@ -495,15 +498,15 @@ void locate_host(char *hbuf) /* * miscellaneous server commands (testing, etc.) */ -void misc_server_cmd(char *cmd) { +void misc_server_cmd(CtdlIPC *ipc, char *cmd) { char buf[SIZ]; - serv_puts(cmd); - serv_gets(buf); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, buf); scr_printf("%s\n",buf); if (buf[0]=='1') { set_keepalives(KA_HALF); - while (serv_gets(buf), strcmp(buf,"000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf,"000")) { scr_printf("%s\n",buf); } set_keepalives(KA_YES); @@ -512,7 +515,7 @@ void misc_server_cmd(char *cmd) { if (buf[0]=='4') { do { newprompt("> ",buf,255); - serv_puts(buf); + CtdlIPC_putline(ipc, buf); } while(strcmp(buf,"000")); return; } diff --git a/citadel/routines.h b/citadel/routines.h index af723b694..10b49f412 100644 --- a/citadel/routines.h +++ b/citadel/routines.h @@ -1,11 +1,11 @@ /* $Id$ */ -void edituser(void); +void edituser(CtdlIPC *ipc); void interr(int errnum); int struncmp(char *lstr, char *rstr, int len); int pattern(char *search, char *patn); -void enter_config(int mode); +void enter_config(CtdlIPC *ipc, int mode); void locate_host(char *hbuf); -void misc_server_cmd(char *cmd); +void misc_server_cmd(CtdlIPC *ipc, char *cmd); int nukedir(char *dirname); int num_parms(char *source); void strproc(char *string); diff --git a/citadel/routines2.c b/citadel/routines2.c index 8d10f9ed3..2bee0b63a 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -33,12 +33,12 @@ #include #include #include "citadel.h" +#include "citadel_ipc.h" #include "citadel_decls.h" #include "routines2.h" #include "routines.h" #include "commands.h" #include "tools.h" -#include "citadel_ipc.h" #include "messages.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" @@ -55,6 +55,7 @@ extern unsigned room_flags; extern int screenwidth; +/* int eopen(char *name, int mode) { int ret; @@ -66,6 +67,7 @@ int eopen(char *name, int mode) } return (ret); } +*/ int room_prompt(int qrflags) @@ -81,7 +83,7 @@ int room_prompt(int qrflags) return (a); } -void entregis(void) +void entregis(CtdlIPC *ipc) { /* register with name and address */ char buf[SIZ]; @@ -109,7 +111,7 @@ void entregis(void) strcpy(tmpemail, ""); strcpy(tmpcountry, ""); - r = CtdlIPCGetUserRegistration(NULL, ®, buf); + r = CtdlIPCGetUserRegistration(ipc, NULL, ®, buf); if (r / 100 == 1) { int a = 0; @@ -149,7 +151,7 @@ void entregis(void) ok = 1; strcpy(holdemail, tmpemail); strprompt("Email address", tmpemail, 31); - r = CtdlIPCDirectoryLookup(tmpemail, buf); + r = CtdlIPCDirectoryLookup(ipc, tmpemail, buf); if (r / 100 == 2) { extract_token(diruser, buf, 0, '@'); extract_token(dirnode, buf, 1, '@'); @@ -175,7 +177,7 @@ void entregis(void) sprintf(reg, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", tmpname, tmpaddr, tmpcity, tmpstate, tmpzip, tmpphone, tmpemail, tmpcountry); - r = CtdlIPCSetRegistration(reg, buf); + r = CtdlIPCSetRegistration(ipc, reg, buf); if (r / 100 != 4) scr_printf("%s\n", buf); free(reg); @@ -183,7 +185,7 @@ void entregis(void) scr_printf("\n"); } -void updatels(void) +void updatels(CtdlIPC *ipc) { /* make all messages old in current room */ char buf[SIZ]; int r; /* IPC response code */ @@ -193,10 +195,10 @@ void updatels(void) /* err_printf("maxmsgnum == highest_msg_read == 0\n"); */ return; } - r = CtdlIPCSetLastRead((maxmsgnum > highest_msg_read) ? + r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ? maxmsgnum : highest_msg_read, buf); } else { - r = CtdlIPCSetLastRead(0, buf); + r = CtdlIPCSetLastRead(ipc, 0, buf); } if (r / 100 != 2) scr_printf("%s\n", buf); @@ -205,12 +207,12 @@ void updatels(void) /* * only make messages old in this room that have been read */ -void updatelsa(void) +void updatelsa(CtdlIPC *ipc) { char buf[SIZ]; int r; /* IPC response code */ - r = CtdlIPCSetLastRead(highest_msg_read, buf); + r = CtdlIPCSetLastRead(ipc, highest_msg_read, buf); if (r / 100 != 2) scr_printf("%s\n", &buf[4]); } @@ -219,7 +221,7 @@ void updatelsa(void) /* * This routine completes a client upload */ -void do_upload(int fd) +void do_upload(CtdlIPC *ipc, int fd) { char buf[SIZ]; char tbuf[4096]; @@ -237,11 +239,11 @@ void do_upload(int fd) bytes_to_send = read(fd, tbuf, 4096); if (bytes_to_send > 0) { snprintf(buf, sizeof buf, "WRIT %d", bytes_to_send); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] == '7') { bytes_expected = atoi(&buf[4]); - serv_write(tbuf, bytes_expected); + serv_write(ipc, tbuf, bytes_expected); } else { scr_printf("%s\n", &buf[4]); } @@ -252,8 +254,8 @@ void do_upload(int fd) /* close the upload file, locally and at the server */ close(fd); - serv_puts("UCLS 1"); - serv_gets(buf); + CtdlIPC_putline(ipc, "UCLS 1"); + CtdlIPC_getline(ipc, buf); scr_printf("%s\n", &buf[4]); } @@ -261,7 +263,7 @@ void do_upload(int fd) /* * client-based uploads (for users with their own clientware) */ -void cli_upload(void) +void cli_upload(CtdlIPC *ipc) { char flnm[SIZ]; char desc[151]; @@ -296,30 +298,30 @@ void cli_upload(void) snprintf(&buf[tmp], sizeof buf - tmp, "%d", a); } snprintf(tbuf, sizeof tbuf, "UOPN %s|%s", buf, desc); - serv_puts(tbuf); - serv_gets(buf); + CtdlIPC_putline(ipc, tbuf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') scr_printf("%s\n", &buf[4]); ++a; } while (buf[0] != '2'); /* at this point we have an open upload file at the server */ - do_upload(fd); + do_upload(ipc, fd); } /* * Function used for various image upload commands */ -void cli_image_upload(char *keyname) +void cli_image_upload(CtdlIPC *ipc, char *keyname) { char flnm[SIZ]; char buf[SIZ]; int fd; snprintf(buf, sizeof buf, "UIMG 0|%s", keyname); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); return; @@ -331,20 +333,20 @@ void cli_image_upload(char *keyname) return; } snprintf(buf, sizeof buf, "UIMG 1|%s", keyname); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '2') { scr_printf("%s\n", &buf[4]); return; } - do_upload(fd); + do_upload(ipc, fd); } /* * protocol-based uploads (Xmodem, Ymodem, Zmodem) */ -void upload(int c) +void upload(CtdlIPC *ipc, int c) { /* c = upload mode */ char flnm[SIZ]; char desc[151]; @@ -447,23 +449,23 @@ void upload(int c) ".%d", a); } ++a; - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); } while ((buf[0] != '2') && (a < 100)); if (buf[0] == '2') do { a = read(fd, tbuf, 4096); if (a > 0) { snprintf(buf, sizeof buf, "WRIT %d", a); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] == '7') - serv_write(tbuf, a); + serv_write(ipc, tbuf, a); } } while (a > 0); close(fd); - serv_puts("UCLS 1"); - serv_gets(buf); + CtdlIPC_putline(ipc, "UCLS 1"); + CtdlIPC_getline(ipc, buf); scr_printf("%s\n", &buf[4]); } } @@ -475,7 +477,7 @@ void upload(int c) /* * validate a user */ -void val_user(char *user, int do_validate) +void val_user(CtdlIPC *ipc, char *user, int do_validate) { int a; char cmd[SIZ]; @@ -484,12 +486,12 @@ void val_user(char *user, int do_validate) int r; /* IPC response code */ snprintf(cmd, sizeof cmd, "GREG %s", user); - serv_puts(cmd); - serv_gets(cmd); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, cmd); if (cmd[0] == '1') { a = 0; do { - serv_gets(buf); + CtdlIPC_getline(ipc, buf); ++a; if (a == 1) scr_printf("User #%s - %s ", buf, &cmd[4]); @@ -522,7 +524,7 @@ void val_user(char *user, int do_validate) if (do_validate) { /* now set the access level */ ax = intprompt("Access level", ax, 0, 6); - r = CtdlIPCValidateUser(user, ax, cmd); + r = CtdlIPCValidateUser(ipc, user, ax, cmd); if (r / 100 != 2) scr_printf("%s\n", cmd); } @@ -530,7 +532,7 @@ void val_user(char *user, int do_validate) } -void validate(void) +void validate(CtdlIPC *ipc) { /* validate new users */ char cmd[SIZ]; char buf[SIZ]; @@ -538,14 +540,14 @@ void validate(void) int r; /* IPC response code */ do { - r = CtdlIPCNextUnvalidatedUser(cmd); + r = CtdlIPCNextUnvalidatedUser(ipc, cmd); if (r / 100 != 3) finished = 1; if (r / 100 == 2) scr_printf("%s\n", cmd); if (r / 100 == 3) { extract(buf, cmd, 0); - val_user(buf, 1); + val_user(ipc, buf, 1); } } while (finished == 0); } @@ -573,7 +575,7 @@ void subshell(void) /* * <.A>ide ile elete command */ -void deletefile(void) +void deletefile(CtdlIPC *ipc) { char filename[32]; char buf[SIZ]; @@ -581,14 +583,14 @@ void deletefile(void) newprompt("Filename: ", filename, 31); if (strlen(filename) == 0) return; - CtdlIPCDeleteFile(filename, buf); + CtdlIPCDeleteFile(ipc, filename, buf); err_printf("%s\n", buf); } /* * <.A>ide ile end command */ -void netsendfile(void) +void netsendfile(CtdlIPC *ipc) { char filename[32], destsys[20], buf[SIZ]; @@ -596,7 +598,7 @@ void netsendfile(void) if (strlen(filename) == 0) return; newprompt("System to send to: ", destsys, 19); - CtdlIPCNetSendFile(filename, destsys, buf); + CtdlIPCNetSendFile(ipc, filename, destsys, buf); err_printf("%s\n", buf); return; } @@ -604,7 +606,7 @@ void netsendfile(void) /* * <.A>ide ile ove command */ -void movefile(void) +void movefile(CtdlIPC *ipc) { char filename[64]; char newroom[ROOMNAMELEN]; @@ -614,7 +616,7 @@ void movefile(void) if (strlen(filename) == 0) return; newprompt("Enter target room: ", newroom, ROOMNAMELEN - 1); - CtdlIPCMoveFile(filename, newroom, buf); + CtdlIPCMoveFile(ipc, filename, newroom, buf); err_printf("%s\n", buf); } @@ -622,18 +624,18 @@ void movefile(void) /* * list of users who have filled out a bio */ -void list_bio(void) +void list_bio(CtdlIPC *ipc) { char buf[SIZ]; int pos = 1; - serv_puts("LBIO"); - serv_gets(buf); + CtdlIPC_putline(ipc, "LBIO"); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { pprintf("%s\n", &buf[4]); return; } - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { if ((pos + strlen(buf) + 5) > screenwidth) { pprintf("\n"); pos = 1; @@ -648,7 +650,7 @@ void list_bio(void) /* * read bio */ -void read_bio(void) +void read_bio(CtdlIPC *ipc) { char who[SIZ]; char buf[SIZ]; @@ -657,16 +659,16 @@ void read_bio(void) newprompt("Read bio for who ('?' for list) : ", who, 25); pprintf("\n"); if (!strcmp(who, "?")) - list_bio(); + list_bio(ipc); } while (!strcmp(who, "?")); snprintf(buf, sizeof buf, "RBIO %s", who); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] != '1') { pprintf("%s\n", &buf[4]); return; } - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { pprintf("%s\n", buf); } } @@ -675,7 +677,7 @@ void read_bio(void) /* * General system configuration command */ -void do_system_configuration(void) +void do_system_configuration(CtdlIPC *ipc) { char buf[SIZ]; char sc[31][SIZ]; @@ -688,11 +690,11 @@ void do_system_configuration(void) memset(&sc[0][0], 0, sizeof(sc)); /* Fetch the current config */ - serv_puts("CONF get"); - serv_gets(buf); + CtdlIPC_putline(ipc, "CONF get"); + CtdlIPC_getline(ipc, buf); if (buf[0] == '1') { a = 0; - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { if (a < 31) { strcpy(&sc[a][0], buf); } @@ -702,8 +704,8 @@ void do_system_configuration(void) /* Fetch the expire policy (this will silently fail on old servers, * resulting in "default" policy) */ - serv_puts("GPEX site"); - serv_gets(buf); + CtdlIPC_putline(ipc, "GPEX site"); + CtdlIPC_getline(ipc, buf); if (buf[0] == '2') { expire_mode = extract_int(&buf[4], 0); expire_value = extract_int(&buf[4], 1); @@ -809,17 +811,17 @@ void do_system_configuration(void) /* Save it */ scr_printf("Save this configuration? "); if (yesno()) { - serv_puts("CONF set"); - serv_gets(buf); + CtdlIPC_putline(ipc, "CONF set"); + CtdlIPC_getline(ipc, buf); if (buf[0] == '4') { for (a = 0; a < 31; ++a) - serv_puts(&sc[a][0]); - serv_puts("000"); + CtdlIPC_putline(ipc, &sc[a][0]); + CtdlIPC_putline(ipc, "000"); } snprintf(buf, sizeof buf, "SPEX site|%d|%d", expire_mode, expire_value); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); } } @@ -827,7 +829,7 @@ void do_system_configuration(void) /* * support function for do_internet_configuration() */ -void get_inet_rec_type(char *buf) { +void get_inet_rec_type(CtdlIPC *ipc, char *buf) { int sel; keyopt(" <1> localhost (Alias for this computer)\n"); @@ -854,7 +856,8 @@ void get_inet_rec_type(char *buf) { /* * Internet mail configuration */ -void do_internet_configuration(void) { +void do_internet_configuration(CtdlIPC *ipc) +{ char buf[SIZ]; int num_recs = 0; char **recs = NULL; @@ -865,9 +868,9 @@ void do_internet_configuration(void) { snprintf(buf, sizeof buf, "CONF getsys|%s", INTERNETCFG); - serv_puts(buf); - serv_gets(buf); - if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) { + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); + if (buf[0] == '1') while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { ++num_recs; if (num_recs == 1) recs = malloc(sizeof(char *)); else recs = realloc(recs, (sizeof(char *)) * num_recs); @@ -904,7 +907,7 @@ void do_internet_configuration(void) { newprompt("Enter host name: ", buf, 50); strcat(buf, "|"); - get_inet_rec_type(&buf[strlen(buf)]); + get_inet_rec_type(ipc, &buf[strlen(buf)]); recs[num_recs-1] = strdup(buf); break; case 'd': @@ -918,13 +921,13 @@ void do_internet_configuration(void) { case 's': snprintf(buf, sizeof buf, "CONF putsys|%s", INTERNETCFG); - serv_puts(buf); - serv_gets(buf); + CtdlIPC_putline(ipc, buf); + CtdlIPC_getline(ipc, buf); if (buf[0] == '4') { for (i=0; i #include "citadel.h" #include "tools.h" -#include "ipc.h" +#include "citadel_ipc.h" #include "server.h" #include "dynloader.h" #include "config.h" #define LOCKFILE "/tmp/LCK.sendcommand" +static CtdlIPC *ipc = NULL; + /* * make sure only one copy of sendcommand runs at a time, using lock files */ @@ -83,7 +85,7 @@ void cleanup(int e) alarm(30); signal(SIGALRM, nq_cleanup); if (nested++ < 1) - serv_puts("QUIT"); + CtdlIPCQuit(ipc); nq_cleanup(e); } @@ -106,16 +108,16 @@ void np_attach_to_server(void) char buf[SIZ]; char *args[] = {"sendcommand", NULL}; + int r; fprintf(stderr, "Attaching to server...\n"); - attach_to_server(1, args, hostbuf, portbuf); - serv_gets(buf); + ipc = CtdlIPC_new(1, args, hostbuf, portbuf); + CtdlIPC_getline(ipc, buf); fprintf(stderr, "%s\n", &buf[4]); snprintf(buf, sizeof buf, "IPGM %d", config.c_ipgm_secret); - serv_puts(buf); - serv_gets(buf); - fprintf(stderr, "%s\n", &buf[4]); - if (buf[0] != '2') { + r = CtdlIPCInternalProgram(ipc, config.c_ipgm_secret, buf); + fprintf(stderr, "%s\n", buf); + if (r / 100 != 2) { cleanup(2); } } @@ -165,12 +167,12 @@ int main(int argc, char **argv) fflush(stderr); fprintf(stderr, "%s\n", cmd); - serv_puts(cmd); - serv_gets(buf); + CtdlIPC_putline(ipc, cmd); + CtdlIPC_getline(ipc, buf); fprintf(stderr, "%s\n", buf); if (buf[0] == '1') { - while (serv_gets(buf), strcmp(buf, "000")) { + while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { printf("%s\n", buf); } } else if (buf[0] == '4') { @@ -184,9 +186,9 @@ int main(int argc, char **argv) if (buf[strlen(buf) - 1] == '\r') buf[strlen(buf) - 1] = 0; if (strcmp(buf, "000")) - serv_puts(buf); + CtdlIPC_putline(ipc, buf); } while (strcmp(buf, "000")); - serv_puts("000"); + CtdlIPC_putline(ipc, "000"); } fprintf(stderr, "sendcommand: processing ended.\n"); cleanup(0); diff --git a/citadel/stats.c b/citadel/stats.c index cd9c6e26a..10cd4bb55 100644 --- a/citadel/stats.c +++ b/citadel/stats.c @@ -25,8 +25,8 @@ #include #include #include "citadel.h" +#include "citadel_ipc.h" #include "config.h" -#include "ipc.h" #include "tools.h" #define disply(x,y) printf("%20s %4.1f %4.1f %4d\n",x,((float)y)/calls,((float)y)/days,y) @@ -126,6 +126,7 @@ int main(int argc, char **argv) char buf[SIZ]; FILE *logfp; char *fakeargs[4]; + CtdlIPC *ipc = NULL; for (a = 0; a < argc; ++a) { if (!strcmp(argv[a], "-b")) @@ -346,16 +347,16 @@ int main(int argc, char **argv) fakeargs[2] = malloc(64); snprintf(fakeargs[2], 64, "%d", config.c_port_number); fakeargs[3] = NULL; - attach_to_server(3, fakeargs, hostbuf, portbuf); + ipc = CtdlIPC_new(3, fakeargs, hostbuf, portbuf); free(fakeargs[2]); - serv_gets(buf); + CtdlIPC_getline(ipc, buf); if ((buf[0]!='2')&&(strncmp(buf,"551",3))) { fprintf(stderr,"%s: %s\n",argv[0],&buf[4]); } else { - serv_puts("LIST"); - serv_gets(buf); - if (buf[0]=='1') while (serv_gets(buf), + CtdlIPC_putline(ipc, "LIST"); + CtdlIPC_getline(ipc, buf); + if (buf[0]=='1') while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) { extract(LogName, buf, 0); fprintf(sortpipe, "%9.2f %-30s\n", diff --git a/citadel/userlist.c b/citadel/userlist.c index 2570a7df1..7df54c9e5 100644 --- a/citadel/userlist.c +++ b/citadel/userlist.c @@ -23,29 +23,32 @@ #include "citadel.h" #include -#include "ipc.h" +#include "citadel_ipc.h" #include "tools.h" void logoff(int code) { exit(code); - } +} -void userlist(void) { +void userlist(CtdlIPC *ipc) { char buf[SIZ]; char fl[SIZ]; struct tm *tmbuf; time_t lc; + char *listing = NULL; + int r; - serv_puts("LIST"); - serv_gets(buf); - if (buf[0]!='1') { - printf("%s\n",&buf[4]); + r = CtdlIPCUserListing(ipc, &listing, buf); + if (r / 100 != 1) { + printf("%s\n", buf); return; - } + } printf(" User Name Num L LastCall Calls Posts\n"); printf("------------------------- ----- - ---------- ----- -----\n"); - while (serv_gets(buf), strcmp(buf,"000")) { + while (strlen(listing) > 0) { + extract_token(buf, listing, 0, '\n'); + remove_token(listing, 0, '\n'); extract(fl,buf,0); printf("%-25s ",fl); printf("%5ld %d ",extract_long(buf,2), @@ -58,29 +61,29 @@ void userlist(void) { (tmbuf->tm_year + 1900)); printf("%5ld %5ld\n", extract_long(buf,4),extract_long(buf,5)); - } - printf("\n"); } + printf("\n"); +} int main(int argc, char **argv) { char buf[SIZ]; char hostbuf[SIZ], portbuf[SIZ]; + CtdlIPC *ipc = NULL; - attach_to_server(argc, argv, hostbuf, portbuf); - serv_gets(buf); + ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf); + CtdlIPC_getline(ipc, buf); if ((buf[0]!='2')&&(strncmp(buf,"551",3))) { fprintf(stderr,"%s: %s\n",argv[0],&buf[4]); logoff(atoi(buf)); - } + } - userlist(); + userlist(ipc); - serv_puts("QUIT"); - serv_gets(buf); + CtdlIPCQuit(ipc); exit(0); - } +} #ifndef HAVE_STRERROR @@ -93,10 +96,5 @@ char *strerror(int e) snprintf(buf, sizeof buf, "errno = %d",e); return(buf); - } +} #endif - - - - - diff --git a/citadel/whobbs.c b/citadel/whobbs.c index e78983c2e..7540831ea 100644 --- a/citadel/whobbs.c +++ b/citadel/whobbs.c @@ -12,7 +12,6 @@ #include #include "citadel.h" #include "citadel_ipc.h" -#include "ipc.h" #include "tools.h" void logoff(int code) @@ -61,6 +60,7 @@ int main(int argc, char **argv) time_t timenow; char *listing = NULL; struct CtdlServInfo *serv_info = NULL; + CtdlIPC *ipc = NULL; /* If this environment variable is set, we assume that the program * is being called as a cgi-bin from a webserver and will output @@ -68,14 +68,14 @@ int main(int argc, char **argv) */ if (getenv("REQUEST_METHOD") != NULL) www = 1; - attach_to_server(argc, argv, hostbuf, portbuf); - serv_gets(buf); + ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf); + CtdlIPC_getline(ipc, buf); if ((buf[0]!='2')&&(strncmp(buf,"551",3))) { fprintf(stderr,"%s: %s\n",argv[0],&buf[4]); logoff(atoi(buf)); } strcpy(nodetitle, "this BBS"); - r = CtdlIPCServerInfo(serv_info, buf); + r = CtdlIPCServerInfo(ipc, serv_info, buf); if (r / 100 == 1) { my_pid = serv_info->serv_pid; strcpy(nodetitle, serv_info->serv_humannode); @@ -103,7 +103,7 @@ int main(int argc, char **argv) printf("\n"); } - r = CtdlIPCOnlineUsers(&listing, &timenow, buf); + r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf); if (r / 100 != 1) { fprintf(stderr,"%s: %s\n",argv[0], buf); logoff(atoi(buf)); @@ -158,7 +158,7 @@ int main(int argc, char **argv) "once per minute)\n" "\n"); - r = CtdlIPCQuit(); + r = CtdlIPCQuit(ipc); return (r / 100 == 2) ? 0 : r; } -- 2.39.2