]> code.citadel.org Git - citadel.git/blob - citadel/ipc.h
* Allow multiple simultaneous IPC connections. All changes necessary for
[citadel.git] / citadel / ipc.h
1 /* $Id$ */
2
3 #include "sysdep.h"
4 #include "client_crypto.h"
5
6 #ifdef HAVE_PTHREAD_H
7 #include <pthread.h>
8 #endif
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 /* Quick and dirty hack; we don't want to use malloc() in C++ */
15 #ifdef __cplusplus
16 #define ialloc(t)       new t()
17 #define ifree(o)        delete o
18 #else
19 #define ialloc(t)       malloc(sizeof(t))
20 #define ifree(o)        free(o);
21 #endif
22
23 /* This class is responsible for the server connection */
24 typedef struct _CtdlIPC {
25 #if defined(HAVE_OPENSSL)
26         /* NULL if not encrypted, non-NULL otherwise */
27         SSL *ssl;
28 #endif
29 #if defined(HAVE_PTHREAD_H)
30         /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
31         pthread_mutex_t mutex;
32 #endif
33         /* -1 if not connected, >= 0 otherwise */
34         int sock;
35         /* 1 if server is local, 0 otherwise or if not connected */
36         int isLocal;
37 } CtdlIPC;
38
39 /* C constructor */
40 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
41 /* C destructor */
42 void CtdlIPC_delete(CtdlIPC* ipc);
43 /* Convenience destructor; also nulls out caller's pointer */
44 void CtdlIPC_delete_ptr(CtdlIPC** pipc);
45 /* Read a line from server, discarding newline */
46 void CtdlIPC_getline(CtdlIPC* ipc, char *buf);
47 /* Write a line to server, adding newline */
48 void CtdlIPC_putline(CtdlIPC* ipc, const char *buf);
49
50 /* Internals */
51 int starttls(CtdlIPC *ipc);
52 void endtls(CtdlIPC *ipc);
53 void setCryptoStatusHook(void (*hook)(char *s));
54 void serv_read(CtdlIPC *ipc, char *buf, int bytes);
55 void serv_write(CtdlIPC *ipc, const char *buf, int nbytes);
56 #ifdef HAVE_OPENSSL
57 void serv_read_ssl(CtdlIPC *ipc, char *buf, int bytes);
58 void serv_write_ssl(CtdlIPC *ipc, const char *buf, int nbytes);
59 void ssl_lock(int mode, int n, const char *file, int line);
60 #endif /* HAVE_OPENSSL */
61 /* This is all Ford's doing.  FIXME: figure out what it's doing */
62 extern int (*error_printf)(char *s, ...);
63 void setIPCDeathHook(void (*hook)(void));
64 void setIPCErrorPrintf(int (*func)(char *s, ...));
65
66 #ifdef __cplusplus
67 }
68 #endif