stringbuf.c: random idle style cleanup.
[citadel.git] / textclient / ipc_c_tcp.c
1 // Client-side IPC functions
2 //
3 // Copyright (c) 1987-2018 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License version 3.
6
7 #include "textclient.h"
8
9
10 /* Note that some of these functions may not work with multiple instances. */
11
12 static void (*deathHook)(void) = NULL;
13 int (*error_printf)(char *s, ...) = (int (*)(char *, ...)) printf;
14
15 void setIPCDeathHook(void (*hook)(void)) {
16         deathHook = hook;
17 }
18
19 void setIPCErrorPrintf(int (*func)(char *s, ...)) {
20         error_printf = func;
21 }
22
23 void connection_died(CtdlIPC * ipc, int using_ssl) {
24         if (deathHook != NULL) {
25                 deathHook();
26         }
27
28         stty_ctdl(SB_RESTORE);
29         fprintf(stderr, "\r\n\n\n");
30         fprintf(stderr, "Your connection to %s is broken.\n", ipc->ServInfo.humannode);
31
32 #ifdef HAVE_OPENSSL
33         if (using_ssl) {
34                 fprintf(stderr, "Last error: %s\n", ERR_reason_error_string(ERR_get_error()));
35                 SSL_free(ipc->ssl);
36                 ipc->ssl = NULL;
37         }
38         else
39 #endif
40                 fprintf(stderr, "Last error: %s\n", strerror(errno));
41
42         fprintf(stderr, "Please re-connect and log in again.\n");
43         fflush(stderr);
44         fflush(stdout);
45         shutdown(ipc->sock, 2);
46         ipc->sock = -1;
47         exit(1);
48 }