the client to use the new code are necessarily included.
$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
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
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
#include <stdarg.h>
#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"
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 */
* that means we're exiting because we already lost the server
*/
if (code != 3)
- CtdlIPCQuit();
+ CtdlIPCQuit(ipc);
/*
* now clean up various things
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 */
}
*/
void dropcarr(int signum)
{
- logoff(SIGHUP);
+ logoff(NULL, 3); /* No IPC when server's already gone! */
}
/* 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;
}
-void userlist(char *patn)
+void userlist(CtdlIPC *ipc, char *patn)
{
char buf[SIZ];
char fl[SIZ];
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;
/*
* 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;
}
/* 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;
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) {
return;
}
roomrec = NULL;
- r = CtdlIPCGotoRoom(bbb, "", &roomrec, aaa);
+ r = CtdlIPCGotoRoom(ipc, bbb, "", &roomrec, aaa);
}
if (r / 100 != 2) {
scr_printf("%s\n", aaa);
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) {
/* read info file if necessary */
if (roomrec->RRinfoupdated > 0)
- readinfo();
+ readinfo(ipc);
/* check for newly arrived mail if we can */
newmailcount = roomrec->RRnewmail;
* 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;
* 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
*/
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;
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;
/*
* 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);
}
}
/*
* 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))
}
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]);
}
/*
* forget all rooms on current floor
*/
-void forget_this_floor(void)
+void forget_this_floor(CtdlIPC *ipc)
{
if (curr_floor == 0) {
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);
}
/*
* Set or change the user's password
*/
-int set_password(void)
+int set_password(CtdlIPC *ipc)
{
char pass1[20];
char pass2[20];
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);
/*
* 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;
}
}
/*
* 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];
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;
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);
char password[SIZ];
struct ctdlipcmisc chek;
struct usersupp *myself = NULL;
+ CtdlIPC* ipc; /* Our server connection */
int r; /* IPC result code */
setIPCDeathHook(screen_delete);
/* 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 */
if (chdir(BBSDIR) < 0) {
perror("can't change to " BBSDIR);
- logoff(3);
+ logoff(NULL, 3);
}
/*
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",
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 <nonce>, else nonce
}
}
- 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);
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 */
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));
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;
goto TERMN8;
}
/* sign on to the server */
- r = CtdlIPCTryLogin(fullname, aaa);
+ r = CtdlIPCTryLogin(ipc, fullname, aaa);
if (r / 100 != 3)
goto NEWUSR;
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,
}
scr_printf("<< wrong password >>\n");
if (strlen(rc_password) > 0)
- logoff(0);
+ logoff(ipc, 0);
goto GSTA;
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 */
}
scr_printf("\n");
- r = CtdlIPCMiscCheck(&chek, aaa);
+ r = CtdlIPCMiscCheck(ipc, &chek, aaa);
if (r / 100 == 2) {
b = chek.newmail;
if (b > 0) {
}
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
*/
screenwidth = 80;
screenheight = 24;
- r = CtdlIPCGetConfig(&myself, aaa);
+ r = CtdlIPCGetConfig(ipc, &myself, aaa);
if (r == 2) {
screenwidth = myself->USscreenwidth;
screenheight = myself->USscreenheight;
/* 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 */
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;
}
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;
}
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(
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;"
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:
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 */
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;
#include "sysconfig.h"
#include "ipcdef.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Text description of this software
*/
#define VIEW_MAILBOX 1 /* Mailbox summary */
#define VIEW_ADDRESSBOOK 2 /* Address book view */
+#ifdef __cplusplus
+}
+#endif
+
#endif /* CITADEL_H */
#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;
/*
* 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);
}
* 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;
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;
}
* 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;
}
* 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;
}
* 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;
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;
}
* 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;
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;
}
* 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;
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;
}
/*
* 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;
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;
}
/* 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;
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;
/* 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;
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);
/* SETU */
-int CtdlIPCSetConfig(struct usersupp *uret, char *cret)
+int CtdlIPCSetConfig(CtdlIPC *ipc, struct usersupp *uret, char *cret)
{
char aaa[48];
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;
}
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);
/* 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;
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;
/* 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;
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" */
/* WHOK */
-int CtdlIPCWhoKnowsRoom(char **listing, char *cret)
+int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret)
{
register int ret;
size_t bytes;
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;
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;
/* RDIR */
-int CtdlIPCReadDirectory(char **listing, char *cret)
+int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret)
{
register int ret;
size_t bytes;
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;
}
/*
* 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];
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;
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;
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;
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);
/* 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;
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;
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;
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;
/* RINF */
-int CtdlIPCRoomInfo(char **iret, char *cret)
+int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret)
{
size_t bytes;
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];
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;
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;
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;
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;
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;
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];
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;
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);
/* DELF */
-int CtdlIPCDeleteFile(const char *filename, char *cret)
+int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret)
{
register int ret;
char *aaa;
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;
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;
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;
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;
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) {
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);
/* 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;
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) {
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);
/* 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;
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) {
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);
/* 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;
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;
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)
/* QUSR */
-int CtdlIPCQueryUsername(const char *username, char *cret)
+int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret)
{
register int ret;
char *aaa;
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;
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;
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];
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;
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;
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;
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;
/* GEXP */
-int CtdlIPCGetInstantMessage(char **listing, char *cret)
+int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret)
{
size_t bytes;
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;
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;
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;
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;
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;
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;
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;
}
/* 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 {
/* AGUP */
-int CtdlIPCAideGetUserParameters(const char *who,
+int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
struct usersupp **uret, char *cret)
{
register int ret;
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);
/* ASUP */
-int CtdlIPCAideSetUserParameters(const struct usersupp *uret, char *cret)
+int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct usersupp *uret, char *cret)
{
register int ret;
char *aaa;
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;
}
/* 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];
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];
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;
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];
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];
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];
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;
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);
}
* EXPI
* GTLS
* IGAB
- * IPGM
* MSG3
* MSG4
* NDOP
/* ************************************************************************** */
-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;
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) {
/* Send a listing to the server; generate the ending 000. */
-int CtdlIPCSendListing(const char *listing)
+int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing)
{
char *text;
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];
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 {
*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;
/* 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;
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;
/* 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;
/* 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;
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;
* 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)
* 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);
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;
if (!*to_receive) {
ret = -1;
} else {
- serv_read(*to_receive,
+ serv_read(ipc, *to_receive,
*bytes_to_receive);
}
} else {
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;
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;
}
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;
}
/* $Id$ */
+#include "ipc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct ctdlipcroom {
char RRname[ROOMNAMELEN]; /* Name of room */
long RRunread; /* Number of unread messages */
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);
#include <stdarg.h>
#include <limits.h>
#include "citadel.h"
-#include "citadel_decls.h"
-#include "ipc.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
#endif
#include <stdarg.h>
#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"
char last_paged[SIZ] = "";
-void chatmode(void)
+void chatmode(CtdlIPC *ipc)
{
char wbuf[SIZ];
char buf[SIZ];
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;
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! */
}
/* 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;
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]);
}
* 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__"));
* server to prevent session timeout.
*/
if ((time(NULL) - last_transmit) >= S_KEEPALIVE) {
- serv_puts("NOOP");
+ CtdlIPC_putline(ipc, "NOOP");
last_transmit = time(NULL);
}
/*
* send an express message
*/
-void page_user()
+void page_user(CtdlIPC *ipc)
{
char buf[SIZ], touser[SIZ], msg[SIZ];
FILE *pagefp;
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);
}
/* 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]);
}
-
-
-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);
}
}
/* $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[];
/* $Id$ */
#include "sysdep.h"
-#ifdef HAVE_OPENSSL
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/rand.h>
-#endif
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
#include <unistd.h>
#include <sys/types.h>
#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 */
/*
* 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);
}
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");
/*
* 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);
}
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;
}
}
#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;
}
/* 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();
/* 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);
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;
#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))
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;
}
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;
/*
* 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
}
/* $Id$ */
+#ifdef HAVE_OPENSSL
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/rand.h>
+#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
#include <limits.h>
#include <stdio.h>
#include "citadel.h"
+#include "citadel_ipc.h"
#include "tools.h"
#include "commands.h"
/*
* 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,
#include <errno.h>
#include <stdarg.h>
#include "citadel.h"
+#include "citadel_ipc.h"
#include "commands.h"
#include "messages.h"
#include "citadel_decls.h"
#include "tools.h"
#include "rooms.h"
#include "client_chat.h"
-#include "citadel_ipc.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
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;
}
while (express_msgs != 0) {
- r = CtdlIPCGetInstantMessage(&listing, buf);
+ r = CtdlIPCGetInstantMessage(ipc_for_signal_handlers, &listing, buf);
if (r / 100 != 1)
return;
* 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", "");
*/
if ( (keepalives_enabled == KA_HALF)
&& (serv_info.serv_supports_qnop > 0) ) {
- serv_puts("QNOP");
+ CtdlIPC_putline(ipc_for_signal_handlers, "QNOP");
}
}
}
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)
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
* 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];
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)
/*
* display_help() - help file viewer
*/
-void display_help(char *name)
+void display_help(CtdlIPC *ipc, char *name)
{
- formout(name);
+ formout(ipc, name);
}
/* keypress caught; drain the server */
OOPS: /* do {
- serv_gets(aaa);
+ CtdlIPC_getline(ipc, aaa);
} while (strcmp(aaa, "000")); */
FMTEND:
#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));
#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 */
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);
/* $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 <pthread.h>
+#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
#include "sysdep.h"
+#undef NDEBUG
+#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#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"
#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 "<W>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.
* 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;
error_printf = func;
}
-void connection_died(void) {
+void connection_died(CtdlIPC *ipc) {
if (deathHook != NULL)
deathHook();
"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)
} 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;
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;
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;
}
/*
* 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;
/*
* 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;
/*
* 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.
*/
/*
* 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 */
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);
#include <stdarg.h>
#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
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);
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);
}
/*
* 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;
/* 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 */
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) {
/*
* 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,
filename, strerror(errno));
return(1);
}
- citedit(fp);
+ citedit(ipc, fp);
fclose(fp);
goto MECR;
* 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;
if (ch == 10) {
if (!strcmp(buf, "000"))
strcpy(buf, ">000");
- serv_puts(buf);
+ CtdlIPC_putline(ipc, buf);
strcpy(buf, "");
} else {
a = strlen(buf);
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, "");
}
}
}
}
- serv_puts(buf);
+ CtdlIPC_putline(ipc, buf);
scr_printf(" \r");
scr_flush();
}
* entmsg() - edit and create a message
* returns 0 if message was saved
*/
-int entmsg(int is_reply, /* nonzero if this was a <R>eply command */
+int entmsg(CtdlIPC *ipc,
+ int is_reply, /* nonzero if this was a <R>eply command */
int c) /* */
{
char buf[300];
* 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]);
/* 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. */
/* 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);
* 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);
}
/* 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);
}
/*
* List the URL's which were embedded in the previous message
*/
-void list_urls()
+void list_urls(CtdlIPC *ipc)
{
int i;
char cmd[SIZ];
/*
* 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) */
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);
}
}
/* 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)) {
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;
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)
((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 {
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;
}
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 */
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. */
{
/*
* Verify the message base
*/
-void check_message_base(void)
+void check_message_base(CtdlIPC *ipc)
{
char buf[SIZ];
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);
}
}
/* $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);
#include <limits.h>
#endif
#include "citadel.h"
-#include "ipc.h"
+#include "citadel_ipc.h"
#include "tools.h"
#include "config.h"
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"
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);
}
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");
/* 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) {
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;
#include <stdarg.h>
#include "citadel.h"
#include "citadel_ipc.h"
+#include "citadel_decls.h"
#include "rooms.h"
#include "commands.h"
#include "tools.h"
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);
extern int screenwidth;
extern int screenheight;
extern char fullname[];
-extern int userflags;
extern char sigcaught;
extern char floor_mode;
extern char curr_floor;
extern char floorlist[128][SIZ];
-void load_floorlist(void)
+void load_floorlist(CtdlIPC *ipc)
{
int a;
char buf[SIZ];
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;
/*
* Common code for all room listings
*/
-void listrms(char *variety)
+void listrms(CtdlIPC *ipc, char *variety)
{
char buf[SIZ];
/* 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);
* 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");
}
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();
pprintf("\n Rooms on %s:\n",
floorlist[a]);
snprintf(buf, sizeof buf, "LKRA %d", a);
- listrms(buf);
+ listrms(ipc, buf);
pprintf("\n");
}
}
}
-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;
* 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]))
/*
* .<A>ide <E>dit room
*/
-void editthisroom(void)
+void editthisroom(CtdlIPC *ipc)
{
char rname[ROOMNAMELEN];
char rpass[10];
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;
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);
}
/* 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);
}
/* 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);
}
}
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);
}
strcpy(raide, "");
break;
} else {
- r = CtdlIPCQueryUsername(raide, buf);
+ r = CtdlIPCQueryUsername(ipc, raide, buf);
if (r / 100 != 2)
scr_printf("%s\n", buf);
}
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);
}
}
/*
* un-goto the previous room
*/
-void ungoto(void)
+void ungoto(CtdlIPC *ipc)
{
char buf[SIZ];
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);
}
* 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];
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]);
}
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;
}
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]);
}
* 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];
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;
/* 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;
}
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;
}
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]);
}
/*
* 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;
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);
/*
* add a user to a private room
*/
-void invite(void)
+void invite(CtdlIPC *ipc)
{
char username[USERNAME_SIZE];
char buf[SIZ];
if (username[0] == 0)
return;
- r = CtdlIPCInviteUserToRoom(username, buf);
+ r = CtdlIPCInviteUserToRoom(ipc, username, buf);
scr_printf("%s\n", buf);
}
/*
* kick a user out of a room
*/
-void kickout(void)
+void kickout(CtdlIPC *ipc)
{
char username[USERNAME_SIZE];
char buf[SIZ];
if (username[0] == 0)
return;
- r = CtdlIPCKickoutUserFromRoom(username, buf);
+ r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
scr_printf("%s\n", buf);
}
/*
* aide command: kill the current room
*/
-void killroom(void)
+void killroom(CtdlIPC *ipc)
{
char aaa[100];
int r;
- r = CtdlIPCDeleteRoom(0, aaa);
+ r = CtdlIPCDeleteRoom(ipc, 0, aaa);
if (r / 100 != 2) {
scr_printf("%s\n", aaa);
return;
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];
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];
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;
}
}
- 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"
} while (((b < '1') || (b > '5')) && (b != '?'));
if (b == '?') {
scr_printf("?\n");
- formout("roomaccess");
+ formout(ipc, "roomaccess");
}
} while ((b < '1') || (b > '5'));
b -= '0'; /* Portable */
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);
}
/* 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];
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
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;
/*
* <W>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];
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);
scr_printf("Entering %s. "
"Press return twice when finished.\n", desc);
fp = fopen(temp, "r+");
- citedit(fp);
+ citedit(ipc, fp);
fclose(fp);
}
}
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;
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);
}
/* 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);
}
/*
* 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");
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);
}
/* $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);
}
}
-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);
/*
* change a user's access level
*/
-void edituser(void)
+void edituser(CtdlIPC *ipc)
{
char buf[SIZ];
char who[USERNAME_SIZE];
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;
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);
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);
}
* 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;
* 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);
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) {
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,
"<N>ext and <S>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);
}
}
}
- r = CtdlIPCSetConfig(user, buf);
+ r = CtdlIPCSetConfig(ipc, user, buf);
if (r / 100 != 2) scr_printf("%s\n", buf);
userflags = user->flags;
free(user);
/* 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)
{
/*
* 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);
if (buf[0]=='4') {
do {
newprompt("> ",buf,255);
- serv_puts(buf);
+ CtdlIPC_putline(ipc, buf);
} while(strcmp(buf,"000"));
return;
}
/* $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);
#include <errno.h>
#include <stdarg.h>
#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"
extern int screenwidth;
+/*
int eopen(char *name, int mode)
{
int ret;
}
return (ret);
}
+*/
int room_prompt(int qrflags)
return (a);
}
-void entregis(void)
+void entregis(CtdlIPC *ipc)
{ /* register with name and address */
char buf[SIZ];
strcpy(tmpemail, "");
strcpy(tmpcountry, "");
- r = CtdlIPCGetUserRegistration(NULL, ®, buf);
+ r = CtdlIPCGetUserRegistration(ipc, NULL, ®, buf);
if (r / 100 == 1) {
int a = 0;
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, '@');
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);
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 */
/* 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);
/*
* 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]);
}
/*
* This routine completes a client upload
*/
-void do_upload(int fd)
+void do_upload(CtdlIPC *ipc, int fd)
{
char buf[SIZ];
char tbuf[4096];
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]);
}
/* 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]);
}
/*
* client-based uploads (for users with their own clientware)
*/
-void cli_upload(void)
+void cli_upload(CtdlIPC *ipc)
{
char flnm[SIZ];
char desc[151];
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;
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];
".%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]);
}
}
/*
* 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];
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]);
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);
}
}
-void validate(void)
+void validate(CtdlIPC *ipc)
{ /* validate new users */
char cmd[SIZ];
char buf[SIZ];
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);
}
/*
* <.A>ide <F>ile <D>elete command
*/
-void deletefile(void)
+void deletefile(CtdlIPC *ipc)
{
char filename[32];
char buf[SIZ];
newprompt("Filename: ", filename, 31);
if (strlen(filename) == 0)
return;
- CtdlIPCDeleteFile(filename, buf);
+ CtdlIPCDeleteFile(ipc, filename, buf);
err_printf("%s\n", buf);
}
/*
* <.A>ide <F>ile <S>end command
*/
-void netsendfile(void)
+void netsendfile(CtdlIPC *ipc)
{
char filename[32], destsys[20], buf[SIZ];
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;
}
/*
* <.A>ide <F>ile <M>ove command
*/
-void movefile(void)
+void movefile(CtdlIPC *ipc)
{
char filename[64];
char newroom[ROOMNAMELEN];
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);
}
/*
* 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;
/*
* read bio
*/
-void read_bio(void)
+void read_bio(CtdlIPC *ipc)
{
char who[SIZ];
char buf[SIZ];
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);
}
}
/*
* General system configuration command
*/
-void do_system_configuration(void)
+void do_system_configuration(CtdlIPC *ipc)
{
char buf[SIZ];
char sc[31][SIZ];
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);
}
/* 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);
/* 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);
}
}
/*
* 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");
/*
* Internet mail configuration
*/
-void do_internet_configuration(void) {
+void do_internet_configuration(CtdlIPC *ipc)
+{
char buf[SIZ];
int num_recs = 0;
char **recs = NULL;
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);
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':
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<num_recs; ++i) {
- serv_puts(recs[i]);
+ CtdlIPC_putline(ipc, recs[i]);
}
- serv_puts("000");
+ CtdlIPC_putline(ipc, "000");
}
else {
scr_printf("%s\n", &buf[4]);
/*
* Edit network configuration for room sharing, mailing lists, etc.
*/
-void network_config_management(char *entrytype, char *comment) {
+void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
+{
char filename[PATH_MAX];
char changefile[PATH_MAX];
int e_ex_code;
fprintf(tempfp, "# Specify one per line.\n"
"\n\n");
- serv_puts("GNET");
- serv_gets(buf);
+ CtdlIPC_putline(ipc, "GNET");
+ CtdlIPC_getline(ipc, buf);
if (buf[0] == '1') {
- while(serv_gets(buf), strcmp(buf, "000")) {
+ while(CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
extract(instr, buf, 0);
if (!strcasecmp(instr, entrytype)) {
extract(addr, buf, 1);
if (e_ex_code == 0) { /* Save changes */
changefp = fopen(changefile, "w");
- serv_puts("GNET");
- serv_gets(buf);
+ CtdlIPC_putline(ipc, "GNET");
+ CtdlIPC_getline(ipc, buf);
if (buf[0] == '1') {
- while(serv_gets(buf), strcmp(buf, "000")) {
+ while(CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
extract(instr, buf, 0);
if (strcasecmp(instr, entrytype)) {
fprintf(changefp, "%s\n", buf);
fclose(changefp);
/* now write it to the server... */
- serv_puts("SNET");
- serv_gets(buf);
+ CtdlIPC_putline(ipc, "SNET");
+ CtdlIPC_getline(ipc, buf);
if (buf[0] == '4') {
changefp = fopen(changefile, "r");
if (changefp != NULL) {
while (fgets(buf, sizeof buf,
changefp) != NULL) {
buf[strlen(buf) - 1] = 0;
- serv_puts(buf);
+ CtdlIPC_putline(ipc, buf);
}
fclose(changefp);
}
- serv_puts("000");
+ CtdlIPC_putline(ipc, "000");
}
}
/*
* IGnet node configuration
*/
-void do_ignet_configuration(void) {
+void do_ignet_configuration(CtdlIPC *ipc) {
char buf[SIZ];
int num_recs = 0;
char **recs = NULL;
snprintf(buf, sizeof buf, "CONF getsys|%s", IGNETCFG);
- 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);
break;
case 's':
snprintf(buf, sizeof buf, "CONF putsys|%s", IGNETCFG);
- serv_puts(buf);
- serv_gets(buf);
+ CtdlIPC_putline(ipc, buf);
+ CtdlIPC_getline(ipc, buf);
if (buf[0] == '4') {
for (i=0; i<num_recs; ++i) {
- serv_puts(recs[i]);
+ CtdlIPC_putline(ipc, recs[i]);
}
- serv_puts("000");
+ CtdlIPC_putline(ipc, "000");
}
else {
scr_printf("%s\n", &buf[4]);
/*
* Filter list configuration
*/
-void do_filterlist_configuration(void) {
+void do_filterlist_configuration(CtdlIPC *ipc)
+{
char buf[SIZ];
int num_recs = 0;
char **recs = NULL;
snprintf(buf, sizeof buf, "CONF getsys|%s", FILTERLIST);
- 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);
break;
case 's':
snprintf(buf, sizeof buf, "CONF putsys|%s", FILTERLIST);
- serv_puts(buf);
- serv_gets(buf);
+ CtdlIPC_putline(ipc, buf);
+ CtdlIPC_getline(ipc, buf);
if (buf[0] == '4') {
for (i=0; i<num_recs; ++i) {
- serv_puts(recs[i]);
+ CtdlIPC_putline(ipc, recs[i]);
}
- serv_puts("000");
+ CtdlIPC_putline(ipc, "000");
}
else {
scr_printf("%s\n", &buf[4]);
/* $Id$ */
-void updatels(void);
-void updatelsa(void);
-void movefile(void);
-void deletefile(void);
-void netsendfile(void);
-void entregis(void);
+void updatels(CtdlIPC *ipc);
+void updatelsa(CtdlIPC *ipc);
+void movefile(CtdlIPC *ipc);
+void deletefile(CtdlIPC *ipc);
+void netsendfile(CtdlIPC *ipc);
+void entregis(CtdlIPC *ipc);
void subshell(void);
-void upload(int c);
-void cli_upload(void);
-void validate(void);
-void read_bio(void);
-void cli_image_upload(char *keyname);
+void upload(CtdlIPC *ipc, int c);
+void cli_upload(CtdlIPC *ipc);
+void validate(CtdlIPC *ipc);
+void read_bio(CtdlIPC *ipc);
+void cli_image_upload(CtdlIPC *ipc, char *keyname);
int room_prompt(int qrflags);
-void do_internet_configuration(void);
-void do_ignet_configuration(void);
-void network_config_management(char *entrytype, char *comment);
-void do_filterlist_configuration(void);
-void val_user(char *user, int do_validate);
+void do_internet_configuration(CtdlIPC *ipc);
+void do_ignet_configuration(CtdlIPC *ipc);
+void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment);
+void do_filterlist_configuration(CtdlIPC *ipc);
+void val_user(CtdlIPC *ipc, char *user, int do_validate);
+void do_system_configuration(CtdlIPC *ipc);
#include "snprintf.h"
#endif
#include "citadel.h"
-#include "commands.h"
+#include "citadel_ipc.h"
#include "citadel_decls.h"
+#include "commands.h"
#ifdef HAVE_CURSES_H
static SCREEN *myscreen = NULL;
#include <limits.h>
#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
*/
alarm(30);
signal(SIGALRM, nq_cleanup);
if (nested++ < 1)
- serv_puts("QUIT");
+ CtdlIPCQuit(ipc);
nq_cleanup(e);
}
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);
}
}
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') {
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);
#include <string.h>
#include <limits.h>
#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)
char buf[SIZ];
FILE *logfp;
char *fakeargs[4];
+ CtdlIPC *ipc = NULL;
for (a = 0; a < argc; ++a) {
if (!strcmp(argv[a], "-b"))
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",
#include "citadel.h"
#include <unistd.h>
-#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),
(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
snprintf(buf, sizeof buf, "errno = %d",e);
return(buf);
- }
+}
#endif
-
-
-
-
-
#include <string.h>
#include "citadel.h"
#include "citadel_ipc.h"
-#include "ipc.h"
#include "tools.h"
void logoff(int code)
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
*/
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);
printf("</H1>\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));
"once per minute)</FONT>\n"
"</BODY></HTML>\n");
- r = CtdlIPCQuit();
+ r = CtdlIPCQuit(ipc);
return (r / 100 == 2) ? 0 : r;
}