]> code.citadel.org Git - citadel.git/blob - citadel/ipc_c_tcp.c
e558932b032db1e11bf1d44dc89aeb379c787f0e
[citadel.git] / citadel / ipc_c_tcp.c
1 /*
2  * $Id$
3  * 
4  * Client-side IPC functions
5  *
6  */
7
8
9 #include "sysdep.h"
10 #undef NDEBUG
11 #include <assert.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include <signal.h>
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <sys/un.h>
21 #include <netdb.h>
22 #include <string.h>
23 #include <pwd.h>
24 #include <errno.h>
25 #include <stdarg.h>
26 #include "citadel.h"
27 #include "citadel_ipc.h"
28 #include "citadel_decls.h"
29 #include "tools.h"
30 #ifndef HAVE_SNPRINTF
31 #include "snprintf.h"
32 #endif
33
34 /*
35  * FIXME: rewrite all of Ford's stuff here, it won't work with multiple
36  * instances
37  */
38
39 static void (*deathHook)(void) = NULL;
40 int (*error_printf)(char *s, ...) = (int (*)(char *, ...))printf;
41
42 void setIPCDeathHook(void (*hook)(void)) {
43         deathHook = hook;
44 }
45
46 void setIPCErrorPrintf(int (*func)(char *s, ...)) {
47         error_printf = func;
48 }
49
50 void connection_died(CtdlIPC *ipc) {
51         if (deathHook != NULL)
52                 deathHook();
53
54         error_printf("\rYour connection to this Citadel server is broken.\n"
55                         "Last error: %s\n"
56                         "Please re-connect and log in again.\n",
57                         strerror(errno));
58         fflush(stderr);
59         fflush(stdout);
60
61 #ifdef HAVE_OPENSSL
62         /*  ...don't try to shut down a connection on a dead socket?
63         SSL_shutdown(ipc->ssl);
64         */
65
66         SSL_free(ipc->ssl);
67         ipc->ssl = NULL;
68 #endif
69         shutdown(ipc->sock, 2);
70         ipc->sock = -1;
71 }
72
73
74 /*
75 static void ipc_timeout(int signum)
76 {
77         error_printf("\rConnection timed out.\n");
78         logoff(NULL, 3);
79 }
80 */