Updated the boilerplate on each file
[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, and/or
6 // disclosure are subject to the GNU General Purpose License version 3.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12
13
14 #include "textclient.h"
15
16
17 /* Note that some of these functions may not work with multiple instances. */
18
19 static void (*deathHook) (void) = NULL;
20 int (*error_printf) (char *s, ...) = (int (*)(char *, ...)) printf;
21
22 void setIPCDeathHook(void (*hook) (void))
23 {
24         deathHook = hook;
25 }
26
27 void setIPCErrorPrintf(int (*func) (char *s, ...))
28 {
29         error_printf = func;
30 }
31
32 void connection_died(CtdlIPC * ipc, int using_ssl)
33 {
34         if (deathHook != NULL) {
35                 deathHook();
36         }
37
38         stty_ctdl(SB_RESTORE);
39         fprintf(stderr, "\r\n\n\n");
40         fprintf(stderr, "Your connection to %s is broken.\n", ipc->ServInfo.humannode);
41
42 #ifdef HAVE_OPENSSL
43         if (using_ssl) {
44                 fprintf(stderr, "Last error: %s\n", ERR_reason_error_string(ERR_get_error()));
45                 SSL_free(ipc->ssl);
46                 ipc->ssl = NULL;
47         } else
48 #endif
49                 fprintf(stderr, "Last error: %s\n", strerror(errno));
50
51         fprintf(stderr, "Please re-connect and log in again.\n");
52         fflush(stderr);
53         fflush(stdout);
54         shutdown(ipc->sock, 2);
55         ipc->sock = -1;
56         exit(1);
57 }