X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=textclient%2Fsrc%2Fipc_c_tcp.c;fp=textclient%2Fsrc%2Fipc_c_tcp.c;h=a6cae96c7335bc297006b518e7a7687caa27365b;hb=5a202656af01ddc9db0640e4cc7a84f5974bc2d4;hp=0000000000000000000000000000000000000000;hpb=0bfb63b329df2e5408213edb383ece0a7775245d;p=citadel.git diff --git a/textclient/src/ipc_c_tcp.c b/textclient/src/ipc_c_tcp.c new file mode 100644 index 000000000..a6cae96c7 --- /dev/null +++ b/textclient/src/ipc_c_tcp.c @@ -0,0 +1,69 @@ +/* + * Client-side IPC functions + */ + + +#include "sysdep.h" +#undef NDEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "citadel.h" +#include "citadel_ipc.h" +#include "citadel_decls.h" +#ifndef HAVE_SNPRINTF +#include "snprintf.h" +#endif +#include "commands.h" + +/* Note that some of these functions may not work with multiple instances. */ + +static void (*deathHook)(void) = NULL; +int (*error_printf)(char *s, ...) = (int (*)(char *, ...))printf; + +void setIPCDeathHook(void (*hook)(void)) { + deathHook = hook; +} + +void setIPCErrorPrintf(int (*func)(char *s, ...)) { + error_printf = func; +} + +void connection_died(CtdlIPC* ipc, int using_ssl) { + if (deathHook != NULL) { + deathHook(); + } + + stty_ctdl(SB_RESTORE); + fprintf(stderr, "\r\n\n\n"); + fprintf(stderr, "Your connection to %s is broken.\n", ipc->ServInfo.humannode); + +#ifdef HAVE_OPENSSL + if (using_ssl) { + fprintf(stderr, "Last error: %s\n", ERR_reason_error_string(ERR_get_error())); + SSL_free(ipc->ssl); + ipc->ssl = NULL; + } else +#endif + fprintf(stderr, "Last error: %s\n", strerror(errno)); + + fprintf(stderr, "Please re-connect and log in again.\n"); + fflush(stderr); + fflush(stdout); + shutdown(ipc->sock, 2); + ipc->sock = -1; + exit(1); +}