HUGE PATCH. This moves all of mime_parser.c and all
[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 <libcitadel.h>
27 #include "citadel.h"
28 #include "citadel_ipc.h"
29 #include "citadel_decls.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, int using_ssl) {
51         if (deathHook != NULL)
52                 deathHook();
53
54         error_printf("\r\nYour connection to %s is broken.\n",
55                         ipc->ServInfo.humannode);
56
57 #ifdef HAVE_OPENSSL
58         if (using_ssl) {
59                 error_printf("Last error: %s\n",
60                                 ERR_reason_error_string(ERR_get_error()));
61         } else
62 #endif
63                 error_printf("Last error: %s\n", strerror(errno));
64
65         error_printf("Please re-connect and log in again.\n");
66         fflush(stderr);
67         fflush(stdout);
68
69 #ifdef HAVE_OPENSSL
70         SSL_free(ipc->ssl);
71         ipc->ssl = NULL;
72 #endif
73         shutdown(ipc->sock, 2);
74         ipc->sock = -1;
75         printf ("About to exit because of dead socket.\n");
76         exit (1);
77 }
78
79
80 /*
81 static void ipc_timeout(int signum)
82 {
83         error_printf("\rConnection timed out.\n");
84         logoff(NULL, 3);
85 }
86 */