]> code.citadel.org Git - citadel.git/blob - citadel/ipc_c_tcp.c
* citadel_ipc.c: when issuing a SPEX command, send the string value for
[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 #ifdef HAVE_OPENSSL
59
60         /*  ...don't try to shut down a connection on a dead socket?
61         SSL_shutdown(ipc->ssl);
62         */
63
64         SSL_free(ipc->ssl);
65         ipc->ssl = NULL;
66 #endif
67         shutdown(ipc->sock, 2);
68         ipc->sock = -1;
69 }
70
71
72 /*
73 static void ipc_timeout(int signum)
74 {
75         error_printf("\rConnection timed out.\n");
76         logoff(NULL, 3);
77 }
78 */