From 4f0a46fc946ddc739758c6be5532543a4fff3c2b Mon Sep 17 00:00:00 2001 From: Michael Hampton Date: Thu, 26 Feb 2004 20:17:30 +0000 Subject: [PATCH] * Client stability and enhancements: * CtdlServInfo structure moved inside CtdlIPC; eliminates unnecessary global and makes IPC more self-contained * Removed redundant serv_ from variable names in CtdlServInfo struct * Send SIGHUP to process group when connection_died(). Kills self and children (e.g. external editor). --- citadel/ChangeLog | 9 ++++- citadel/citadel.c | 24 ++++++------- citadel/citadel_ipc.c | 84 +++++++++++++++++++++++-------------------- citadel/citadel_ipc.h | 39 ++++++++++++++------ citadel/client_chat.c | 5 ++- citadel/commands.c | 10 +++--- citadel/ipc_c_tcp.c | 21 ++++++++--- citadel/ipcdef.h | 16 --------- citadel/messages.c | 11 +++--- citadel/rooms.c | 2 +- citadel/routines.c | 19 +++++----- citadel/routines.h | 6 ++-- citadel/routines2.c | 4 +-- citadel/screen.c | 8 ++--- citadel/screen.h | 2 +- citadel/whobbs.c | 7 ++-- 16 files changed, 146 insertions(+), 121 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 49859b5d3..f7aae480c 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,12 @@ $Log$ + Revision 614.51 2004/02/26 20:17:29 error + * Client stability and enhancements: + * CtdlServInfo structure moved inside CtdlIPC; eliminates unnecessary + global and makes IPC more self-contained + * Removed redundant serv_ from variable names in CtdlServInfo struct + * Send SIGHUP to process group when connection_died(). Kills self and + children (e.g. external editor). + Revision 614.50 2004/02/25 01:35:34 error Missing parameter to a printf() function. No idea where it went, but I put it back. @@ -5402,4 +5410,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/citadel.c b/citadel/citadel.c index 4caa66956..d31c8ae2d 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -68,7 +68,6 @@ char editor_paths[MAX_EDITORS][SIZ]; /* paths to external editors */ char printcmd[SIZ]; /* print command */ int editor_pid = (-1); char fullname[USERNAME_SIZE]; -struct CtdlServInfo serv_info; /* Info on the server connected */ int screenwidth; int screenheight; unsigned room_flags; @@ -480,7 +479,7 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto) system(rc_gotmail_cmd); } } - status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, + status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city, room_name, secure, newmailcount); } @@ -700,9 +699,9 @@ void check_screen_dims(void) /* * set floor mode depending on client, server, and user settings */ -void set_floor_mode(void) +void set_floor_mode(CtdlIPC* ipc) { - if (serv_info.serv_ok_floors == 0) { + if (ipc->ServInfo.ok_floors == 0) { floor_mode = 0; /* Don't use floors if the server */ } /* doesn't support them! */ @@ -758,14 +757,14 @@ void get_serv_info(CtdlIPC *ipc, char *supplied_hostname) { char buf[SIZ]; - CtdlIPCServerInfo(ipc, &serv_info, buf); + CtdlIPCServerInfo(ipc, buf); /* be nice and identify ourself to the server */ CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL, (ipc->isLocal ? "local" : CITADEL), (supplied_hostname) ? supplied_hostname : /* Look up the , in the bible if you're confused */ - (locate_host(buf), buf), buf); + (locate_host(ipc, buf), buf), buf); /* Tell the server what our preferred content formats are */ if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) { @@ -1024,6 +1023,7 @@ int main(int argc, char **argv) load_command_set(); /* parse the citadel.rc file */ sttybbs(SB_NO_INTR); /* Install the new ones */ signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */ + signal(SIGPIPE, dropcarr); /* Cleanup gracefully if local conn. dropped */ signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */ signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */ #ifdef SIGWINCH @@ -1167,11 +1167,11 @@ int main(int argc, char **argv) #endif 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_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode, + ipc->ServInfo.bbs_city); scr_flush(); - status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL, + status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city, NULL, secure, -1); screenwidth = 80; /* default screen dimensions */ @@ -1348,7 +1348,7 @@ NEWUSR: if (strlen(rc_password) == 0) { check_screen_dims(); #endif - set_floor_mode(); + set_floor_mode(ipc); /* Enter the lobby */ dotgoto(ipc, "_BASEROOM_", 1, 0); @@ -1708,12 +1708,12 @@ NEWUSR: if (strlen(rc_password) == 0) { case 37: enter_config(ipc, 0); - set_floor_mode(); + set_floor_mode(ipc); break; case 59: enter_config(ipc, 3); - set_floor_mode(); + set_floor_mode(ipc); break; case 60: diff --git a/citadel/citadel_ipc.c b/citadel/citadel_ipc.c index 9ef8c5174..87dbc631c 100644 --- a/citadel/citadel_ipc.c +++ b/citadel/citadel_ipc.c @@ -604,7 +604,7 @@ int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret) /* INFO */ -int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret) +int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret) { register int ret; size_t bytes; @@ -612,7 +612,6 @@ int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret) char buf[SIZ]; if (!cret) return -2; - if (!ServInfo) return -2; ret = CtdlIPCGenericCommand(ipc, "INFO", NULL, 0, &listing, &bytes, cret); if (ret / 100 == 1) { @@ -622,30 +621,31 @@ int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret) extract_token(buf, listing, 0, '\n'); remove_token(listing, 0, '\n'); switch (line++) { - case 0: ServInfo->serv_pid = atoi(buf); + case 0: ipc->ServInfo.pid = atoi(buf); break; - case 1: strcpy(ServInfo->serv_nodename,buf); + case 1: strcpy(ipc->ServInfo.nodename,buf); break; - case 2: strcpy(ServInfo->serv_humannode,buf); + case 2: strcpy(ipc->ServInfo.humannode,buf); break; - case 3: strcpy(ServInfo->serv_fqdn,buf); + case 3: strcpy(ipc->ServInfo.fqdn,buf); break; - case 4: strcpy(ServInfo->serv_software,buf); + case 4: strcpy(ipc->ServInfo.software,buf); break; - case 5: ServInfo->serv_rev_level = atoi(buf); + case 5: ipc->ServInfo.rev_level = atoi(buf); break; - case 6: strcpy(ServInfo->serv_bbs_city,buf); + case 6: strcpy(ipc->ServInfo.bbs_city,buf); break; - case 7: strcpy(ServInfo->serv_sysadm,buf); + case 7: strcpy(ipc->ServInfo.sysadm,buf); break; - case 9: strcpy(ServInfo->serv_moreprompt,buf); + case 9: strcpy(ipc->ServInfo.moreprompt,buf); break; - case 10: ServInfo->serv_ok_floors = atoi(buf); + case 10: ipc->ServInfo.ok_floors = atoi(buf); break; - case 11: ServInfo->serv_paging_level = atoi(buf); + case 11: ipc->ServInfo.paging_level = atoi(buf); break; - case 13: ServInfo->serv_supports_qnop = atoi(buf); - case 14: ServInfo->serv_supports_ldap = atoi(buf); + case 13: ipc->ServInfo.supports_qnop = atoi(buf); + break; + case 14: ipc->ServInfo.supports_ldap = atoi(buf); break; } } @@ -1129,7 +1129,8 @@ int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret) /* OPEN */ int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf, size_t resume, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register int ret; @@ -1175,7 +1176,8 @@ int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf, /* OPNA */ int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part, void **buf, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register int ret; @@ -1213,7 +1215,8 @@ int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part, /* OIMG */ int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register int ret; @@ -1253,7 +1256,8 @@ int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf, /* UOPN */ int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment, const char *path, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register int ret; @@ -1285,7 +1289,8 @@ int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment, /* UIMG */ int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path, const char *save_as, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register int ret; @@ -2139,7 +2144,8 @@ int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats) { /* READ */ int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register size_t len; @@ -2151,7 +2157,7 @@ int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, len = resume; if (progress_gauge_callback) - progress_gauge_callback(len, bytes); + progress_gauge_callback(ipc, len, bytes); while (len < bytes) { register size_t block; @@ -2162,7 +2168,7 @@ int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, } len += block; if (progress_gauge_callback) - progress_gauge_callback(len, bytes); + progress_gauge_callback(ipc, len, bytes); } return len; } @@ -2170,7 +2176,8 @@ int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, /* READ - pipelined */ int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register size_t len; @@ -2189,7 +2196,7 @@ int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, len = 0; CtdlIPC_lock(ipc); if (progress_gauge_callback) - progress_gauge_callback(len, bytes); + progress_gauge_callback(ipc, len, bytes); /* How many calls will be in the pipeline? */ calls = (bytes - resume) / 4096; @@ -2212,7 +2219,7 @@ int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, serv_read(ipc, ((*buf) + (i * 4096)), len); } if (progress_gauge_callback) - progress_gauge_callback(i * 4096 + len, bytes); + progress_gauge_callback(ipc, i * 4096 + len, bytes); } CtdlIPC_unlock(ipc); return len; @@ -2237,7 +2244,8 @@ int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret) /* WRIT */ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback) + (CtdlIPC*, unsigned long, unsigned long), char *cret) { register int ret = -1; @@ -2259,7 +2267,7 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, rewind(fd); if (progress_gauge_callback) - progress_gauge_callback(0, bytes); + progress_gauge_callback(ipc, 0, bytes); while (offset < bytes) { register size_t to_write; @@ -2280,7 +2288,7 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, serv_write(ipc, buf, to_write); offset += to_write; if (progress_gauge_callback) - progress_gauge_callback(offset, bytes); + progress_gauge_callback(ipc, offset, bytes); /* Detect short reads and back up if needed */ /* offset will never be negative anyway */ fseek(fd, (signed)offset, SEEK_SET); @@ -2289,7 +2297,7 @@ int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, } } if (progress_gauge_callback) - progress_gauge_callback(1, 1); + progress_gauge_callback(ipc, 1, 1); return (!ferror(fd) ? ret : -2); } @@ -2538,7 +2546,7 @@ static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes) while (len < bytes) { rlen = read(ipc->sock, &buf[len], bytes - len); if (rlen < 1) { - connection_died(ipc); + connection_died(ipc, 0); return; } len += rlen; @@ -2564,7 +2572,7 @@ static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes) retval = write(ipc->sock, &buf[bytes_written], nbytes - bytes_written); if (retval < 1) { - connection_died(ipc); + connection_died(ipc, 0); return; } bytes_written += retval; @@ -2604,9 +2612,9 @@ static void serv_read_ssl(CtdlIPC* ipc, char *buf, unsigned int bytes) serv_read(ipc, &buf[len], bytes - len); return; } - error_printf("SSL_read in serv_read:\n"); - ERR_print_errors_fp(stderr); - connection_died(ipc); + error_printf("SSL_read in serv_read: %s\n", + ERR_reason_error_string(ERR_peek_error())); + connection_died(ipc, 1); return; } len += rlen; @@ -2647,9 +2655,9 @@ static void serv_write_ssl(CtdlIPC *ipc, const char *buf, unsigned int nbytes) nbytes - bytes_written); return; } - error_printf("SSL_write in serv_write:\n"); - ERR_print_errors_fp(stderr); - connection_died(ipc); + error_printf("SSL_write in serv_write: %s\n", + ERR_reason_error_string(ERR_peek_error())); + connection_died(ipc, 1); return; } bytes_written += retval; diff --git a/citadel/citadel_ipc.h b/citadel/citadel_ipc.h index 15b4abc19..953c6337c 100644 --- a/citadel/citadel_ipc.h +++ b/citadel/citadel_ipc.h @@ -32,8 +32,27 @@ extern "C" { #define ifree(o) free(o); #endif +struct CtdlServInfo { + int pid; + char nodename[32]; + char humannode[64]; + char fqdn[64]; + char software[64]; + int rev_level; + char bbs_city[64]; + char sysadm[64]; + char moreprompt[256]; + int ok_floors; + int paging_level; + int supports_qnop; + int supports_ldap; +}; + /* This class is responsible for the server connection */ typedef struct _CtdlIPC { + /* The server info for this connection */ + struct CtdlServInfo ServInfo; + #if defined(HAVE_OPENSSL) /* NULL if not encrypted, non-NULL otherwise */ SSL *ssl; @@ -182,7 +201,7 @@ int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg, int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime, struct ctdlipcmessage **mret, char *cret); int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret); -int CtdlIPCServerInfo(CtdlIPC *ipc, struct CtdlServInfo *ServInfo, char *cret); +int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret); /* int CtdlIPCReadDirectory(CtdlIPC *ipc, struct ctdlipcfile **files, char *cret); */ int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret); int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret); @@ -223,22 +242,22 @@ int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret); int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf, size_t resume, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part, void **buf, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment, const char *path, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path, const char *save_as, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret); int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret); @@ -301,15 +320,15 @@ size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret); int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret); int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret); int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume, - void (*progress_gauge_callback)(unsigned long, unsigned long), + void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long), char *cret); int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command, const char *to_send, size_t bytes_to_send, char **to_receive, @@ -323,7 +342,7 @@ void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state)); extern int (*error_printf)(char *s, ...); void setIPCDeathHook(void (*hook)(void)); void setIPCErrorPrintf(int (*func)(char *s, ...)); -void connection_died(CtdlIPC *ipc); +void connection_died(CtdlIPC* ipc, int using_ssl); int CtdlIPC_getsockfd(CtdlIPC* ipc); char CtdlIPC_get(CtdlIPC* ipc); diff --git a/citadel/client_chat.c b/citadel/client_chat.c index f32241154..5b1351f72 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -48,7 +48,6 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) -extern struct CtdlServInfo serv_info; extern char temp[]; void getline(char *, int); @@ -237,7 +236,7 @@ void page_user(CtdlIPC *ipc) strprompt("Page who", touser, 30); /* old server -- use inline paging */ - if (serv_info.serv_paging_level == 0) { + if (ipc->ServInfo.paging_level == 0) { newprompt("Message: ", msg, 69); snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg); CtdlIPC_putline(ipc, buf); @@ -249,7 +248,7 @@ void page_user(CtdlIPC *ipc) return; } /* new server -- use extended paging */ - else if (serv_info.serv_paging_level >= 1) { + else if (ipc->ServInfo.paging_level >= 1) { snprintf(buf, sizeof buf, "SEXP %s||", touser); CtdlIPC_putline(ipc, buf); CtdlIPC_getline(ipc, buf); diff --git a/citadel/commands.c b/citadel/commands.c index 25b879907..c00d389af 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -270,7 +270,7 @@ void print_express(void) fprintf(outpipe, "at %d:%02dam", stamp->tm_hour, stamp->tm_min); fprintf(outpipe, " from %s", sender); - if (strncmp(serv_info.serv_nodename, node, 32)) + if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32)) fprintf(outpipe, " @%s", node); fprintf(outpipe, ":\n%s\n", listing); pclose(outpipe); @@ -307,7 +307,7 @@ void print_express(void) scr_printf(" from %s", sender); /* Remote node, if any */ - if (strncmp(serv_info.serv_nodename, node, 32)) + if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32)) scr_printf(" @%s", node); scr_printf(":\n"); @@ -376,7 +376,7 @@ static void really_do_keepalive(void) { * server supports it) and then do nothing. */ if ( (keepalives_enabled == KA_HALF) - && (serv_info.serv_supports_qnop > 0) ) { + && (ipc_for_signal_handlers->ServInfo.supports_qnop > 0) ) { CtdlIPC_putline(ipc_for_signal_handlers, "QNOP"); } } @@ -478,9 +478,9 @@ int inkey(void) * necessary and then waits again. */ do { - scr_set_windowsize(); + scr_set_windowsize(ipc_for_signal_handlers); do_keepalive(); - scr_set_windowsize(); + scr_set_windowsize(ipc_for_signal_handlers); FD_ZERO(&rfds); FD_SET(0, &rfds); diff --git a/citadel/ipc_c_tcp.c b/citadel/ipc_c_tcp.c index e558932b0..dd7afb33a 100644 --- a/citadel/ipc_c_tcp.c +++ b/citadel/ipc_c_tcp.c @@ -47,14 +47,22 @@ void setIPCErrorPrintf(int (*func)(char *s, ...)) { error_printf = func; } -void connection_died(CtdlIPC *ipc) { +void connection_died(CtdlIPC* ipc, int using_ssl) { if (deathHook != NULL) deathHook(); - error_printf("\rYour connection to this Citadel server is broken.\n" - "Last error: %s\n" - "Please re-connect and log in again.\n", - strerror(errno)); + error_printf("\r\nYour connection to %s is broken.\n", + ipc->ServInfo.humannode); + +#ifdef HAVE_OPENSSL + if (using_ssl) { + error_printf("Last error: %s\n", + ERR_reason_error_string(ERR_get_error())); + } else +#endif + error_printf("Last error: %s\n", strerror(errno)); + + error_printf("Please re-connect and log in again.\n"); fflush(stderr); fflush(stdout); @@ -68,6 +76,9 @@ void connection_died(CtdlIPC *ipc) { #endif shutdown(ipc->sock, 2); ipc->sock = -1; + + /* Hangup - let any children know as well */ + kill(0, SIGHUP); } diff --git a/citadel/ipcdef.h b/citadel/ipcdef.h index 94b781203..5b566c0a1 100644 --- a/citadel/ipcdef.h +++ b/citadel/ipcdef.h @@ -37,22 +37,6 @@ extern "C" { #define ASYNC_MSG 900 #define ASYNC_GEXP 01 -struct CtdlServInfo { - int serv_pid; - char serv_nodename[32]; - char serv_humannode[64]; - char serv_fqdn[64]; - char serv_software[64]; - int serv_rev_level; - char serv_bbs_city[64]; - char serv_sysadm[64]; - char serv_moreprompt[256]; - int serv_ok_floors; - int serv_paging_level; - int serv_supports_qnop; - int serv_supports_ldap; -}; - #define QR_PERMANENT 1 /* Room does not purge */ #define QR_INUSE 2 /* Set if in use, clear if avail */ #define QR_PRIVATE 4 /* Set for any type of private room */ diff --git a/citadel/messages.c b/citadel/messages.c index 54d8557eb..1e7bdb394 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -63,7 +63,7 @@ void sttybbs(int cmd); int haschar(const char *st, int ch); void getline(char *string, int lim); int file_checksum(char *filename); -void progress(unsigned long curr, unsigned long cmax); +void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax); unsigned long *msg_arr = NULL; int msg_arr_size = 0; @@ -73,7 +73,6 @@ char rc_reply_extedit; extern char room_name[]; extern unsigned room_flags; extern long highest_msg_read; -extern struct CtdlServInfo serv_info; extern char temp[]; extern char temp2[]; extern int screenwidth; @@ -510,8 +509,8 @@ int read_message(CtdlIPC *ipc, } if (strlen(message->node)) { if ((room_flags & QR_NETWORK) - || ((strcasecmp(message->node, serv_info.serv_nodename) - && (strcasecmp(message->node, serv_info.serv_fqdn))))) { + || ((strcasecmp(message->node, ipc->ServInfo.nodename) + && (strcasecmp(message->node, ipc->ServInfo.fqdn))))) { if (strlen(message->email) == 0) { if (dest) { fprintf(dest, "@%s ", message->node); @@ -524,7 +523,7 @@ int read_message(CtdlIPC *ipc, } } } - if (strcasecmp(message->hnod, serv_info.serv_humannode) + if (strcasecmp(message->hnod, ipc->ServInfo.humannode) && (strlen(message->hnod)) && (!strlen(message->email))) { if (dest) { fprintf(dest, "(%s) ", message->hnod); @@ -1434,7 +1433,7 @@ void image_view(CtdlIPC *ipc, unsigned long msg) size_t len; len = (size_t)extract_long(buf, 0); - progress(len, len); + progress(ipc, len, len); scr_flush(); snprintf(tmp, sizeof tmp, "%s.%s", tmpnam(NULL), diff --git a/citadel/rooms.c b/citadel/rooms.c index 2a7f886dd..431403aa8 100644 --- a/citadel/rooms.c +++ b/citadel/rooms.c @@ -37,7 +37,7 @@ void sttybbs(int cmd); void hit_any_key(void); void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto); -void progress(unsigned long curr, unsigned long cmax); +void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax); int pattern(char *search, char *patn); int file_checksum(char *filename); int nukedir(char *dirname); diff --git a/citadel/routines.c b/citadel/routines.c index c8ab5bc21..cfae5d183 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -61,7 +61,6 @@ struct utmp *getutline(struct utmp *ut); extern unsigned userflags; extern char *axdefs[7]; extern char sigcaught; -extern struct CtdlServInfo serv_info; extern char rc_floor_mode; extern int rc_ansi_color; extern int rc_prompt_control; @@ -81,11 +80,11 @@ void hit_any_key(CtdlIPC *ipc) { /* hit any key to continue */ color(COLOR_PUSH); color(DIM_RED); - scr_printf("%s\r",serv_info.serv_moreprompt); + scr_printf("%s\r", ipc->ServInfo.moreprompt); color(COLOR_POP); sttybbs(0); b=inkey(); - for (a=0; aServInfo.moreprompt); ++a) scr_putc(' '); scr_putc(13); sttybbs(1); @@ -382,7 +381,7 @@ char *strerror(int e) #endif -void progress(unsigned long curr, unsigned long cmax) +void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax) { static char dots[] = "**************************************************"; @@ -392,7 +391,7 @@ void progress(unsigned long curr, unsigned long cmax) if (curr >= cmax) { sln_printf("\r%79s\r",""); - status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, + status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city, room_name, secure, 0); } else { /* a will be range 0-50 rather than 0-100 */ @@ -411,7 +410,7 @@ void progress(unsigned long curr, unsigned long cmax) * NOT the same locate_host() in locate_host.c. This one just does a * 'who am i' to try to discover where the user is... */ -void locate_host(char *hbuf) +void locate_host(CtdlIPC* ipc, char *hbuf) { #ifndef HAVE_UTMP_H char buf[SIZ]; @@ -420,7 +419,7 @@ void locate_host(char *hbuf) who = (FILE *)popen("who am i","r"); if (who==NULL) { - strcpy(hbuf,serv_info.serv_fqdn); + strcpy(hbuf, ipc->ServInfo.fqdn); return; } fgets(buf,sizeof buf,who); @@ -431,7 +430,7 @@ void locate_host(char *hbuf) if ((buf[a]=='(')||(buf[a]==')')) ++b; } if (b<2) { - strcpy(hbuf,serv_info.serv_fqdn); + strcpy(hbuf, ipc->ServInfo.fqdn); return; } @@ -444,7 +443,7 @@ void locate_host(char *hbuf) if (buf[a]==')') buf[a] = 0; } - if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn); + if (strlen(buf)==0) strcpy(hbuf, ipc->ServInfo.fqdn); else strncpy(hbuf,buf,24); #else char *tty = ttyname(0); @@ -456,7 +455,7 @@ void locate_host(char *hbuf) if (tty == NULL) { fail: - safestrncpy(hbuf, serv_info.serv_fqdn, 24); + safestrncpy(hbuf, ipc->ServInfo.fqdn, 24); return; } diff --git a/citadel/routines.h b/citadel/routines.h index f6637394b..c1b0131e6 100644 --- a/citadel/routines.h +++ b/citadel/routines.h @@ -3,12 +3,12 @@ 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(CtdlIPC *ipc, int mode); -void locate_host(char *hbuf); +void enter_config(CtdlIPC* ipc, int mode); +void locate_host(CtdlIPC* ipc, char *hbuf); void misc_server_cmd(CtdlIPC *ipc, char *cmd); int nukedir(char *dirname); int num_parms(char *source); void strproc(char *string); void back(int spaces); -void progress(unsigned long curr, unsigned long cmax); +void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax); int set_attr(CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, int backwards); diff --git a/citadel/routines2.c b/citadel/routines2.c index 6b366f098..320f40c1c 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -161,7 +161,7 @@ void entregis(CtdlIPC *ipc) striplt(diruser); striplt(dirnode); if ((strcasecmp(diruser, fullname)) - || (strcasecmp(dirnode, serv_info.serv_nodename))) { + || (strcasecmp(dirnode, ipc->ServInfo.nodename))) { scr_printf( "\nYou can't use %s as your address.\n", tmpemail); @@ -752,7 +752,7 @@ void do_system_configuration(CtdlIPC *ipc) snprintf(sc[25], sizeof sc[25], "%d", a); /* LDAP settings */ - if (serv_info.serv_supports_ldap) { + if (ipc->ServInfo.supports_ldap) { a = strlen(&sc[32][0]); a = (a ? 1 : 0); /* Set only to 1 or 0 */ a = boolprompt("Connect this Citadel to an LDAP directory", a); diff --git a/citadel/screen.c b/citadel/screen.c index 0785cef0b..2acfcd2d1 100644 --- a/citadel/screen.c +++ b/citadel/screen.c @@ -5,7 +5,6 @@ */ #include "sysdep.h" -#include "screen.h" #include #include #include @@ -25,6 +24,7 @@ #include "citadel_ipc.h" #include "citadel_decls.h" #include "commands.h" +#include "screen.h" #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES) static SCREEN *myscreen = NULL; @@ -463,7 +463,7 @@ static volatile int caught_sigwinch = 0; /* * this is not supposed to be called from a signal handler. */ -int scr_set_windowsize() +int scr_set_windowsize(CtdlIPC* ipc) { #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES) if (mainwindow && caught_sigwinch) { @@ -476,8 +476,8 @@ int scr_set_windowsize() wresize(statuswindow, 1, screenwidth); #endif mvwin(statuswindow, screenheight, 0); - status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, - room_name, secure, -1); + status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city, + room_name, secure, -1); wnoutrefresh(mainwindow); wnoutrefresh(statuswindow); doupdate(); diff --git a/citadel/screen.h b/citadel/screen.h index 4c82a430f..f71fa2f3c 100644 --- a/citadel/screen.h +++ b/citadel/screen.h @@ -31,7 +31,7 @@ int scr_color(int colornum); void scr_flush(void); void err_flush(void); void sln_flush(void); -int scr_set_windowsize(void); +int scr_set_windowsize(CtdlIPC* ipc); void windows_new(void); void windows_delete(void); int scr_blockread(void); diff --git a/citadel/whobbs.c b/citadel/whobbs.c index 1ccd5a6b4..2dd59ef79 100644 --- a/citadel/whobbs.c +++ b/citadel/whobbs.c @@ -60,7 +60,6 @@ int main(int argc, char **argv) int r; /* IPC response code */ time_t timenow; char *listing = NULL; - struct CtdlServInfo serv_info; CtdlIPC *ipc = NULL; /* If this environment variable is set, we assume that the program @@ -80,10 +79,10 @@ int main(int argc, char **argv) logoff(atoi(buf)); } strcpy(nodetitle, "this BBS"); - r = CtdlIPCServerInfo(ipc, &serv_info, buf); + r = CtdlIPCServerInfo(ipc, buf); if (r / 100 == 1) { - my_pid = serv_info.serv_pid; - strcpy(nodetitle, serv_info.serv_humannode); + my_pid = ipc->ServInfo.pid; + strcpy(nodetitle, ipc->ServInfo.humannode); } if (www) { -- 2.39.2