summaryrefslogtreecommitdiff
path: root/src/lib/ecore_ipc
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
commit7d6010b12c47a20e492da808e3192c3f87dab619 (patch)
tree26c6fd189e046a76560c0bc740b85f4d767ae399 /src/lib/ecore_ipc
parent53fc441d5475155965d92da89502fe4634a561b2 (diff)
merge: add escape ecore, fix several bugs
SVN revision: 79995
Diffstat (limited to 'src/lib/ecore_ipc')
-rw-r--r--src/lib/ecore_ipc/Ecore_Ipc.h328
-rw-r--r--src/lib/ecore_ipc/ecore_ipc.c1599
-rw-r--r--src/lib/ecore_ipc/ecore_ipc_private.h105
3 files changed, 2032 insertions, 0 deletions
diff --git a/src/lib/ecore_ipc/Ecore_Ipc.h b/src/lib/ecore_ipc/Ecore_Ipc.h
new file mode 100644
index 0000000000..f77870f84d
--- /dev/null
+++ b/src/lib/ecore_ipc/Ecore_Ipc.h
@@ -0,0 +1,328 @@
1#ifndef _ECORE_IPC_H
2#define _ECORE_IPC_H
3
4#include <Eina.h>
5
6#ifdef EAPI
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# ifdef EFL_ECORE_IPC_BUILD
12# ifdef DLL_EXPORT
13# define EAPI __declspec(dllexport)
14# else
15# define EAPI
16# endif
17# else
18# define EAPI __declspec(dllimport)
19# endif
20#else
21# ifdef __GNUC__
22# if __GNUC__ >= 4
23# define EAPI __attribute__ ((visibility("default")))
24# else
25# define EAPI
26# endif
27# else
28# define EAPI
29# endif
30#endif
31
32/**
33 * @file Ecore_Ipc.h
34 * @brief Ecore inter-process communication functions.
35 */
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41typedef struct _Ecore_Ipc_Server Ecore_Ipc_Server; /**< An IPC connection handle */
42typedef struct _Ecore_Ipc_Client Ecore_Ipc_Client; /**< An IPC connection handle */
43
44EAPI unsigned short _ecore_ipc_swap_16(unsigned short v);
45EAPI unsigned int _ecore_ipc_swap_32(unsigned int v);
46EAPI unsigned long long _ecore_ipc_swap_64(unsigned long long v);
47
48#ifdef WORDS_BIGENDIAN
49#define ECORE_IPC_SWAP2NET64(x) _ecore_ipc_swap_64(x)
50#define ECORE_IPC_SWAP2CPU64(x) _ecore_ipc_swap_64(x)
51#define ECORE_IPC_SWAP2NET32(x) _ecore_ipc_swap_32(x)
52#define ECORE_IPC_SWAP2CPU32(x) _ecore_ipc_swap_32(x)
53#define ECORE_IPC_SWAP2NET16(x) _ecore_ipc_swap_16(x)
54#define ECORE_IPC_SWAP2CPU16(x) _ecore_ipc_swap_16(x)
55#define ECORE_IPC_SWAP2NET8(x) (x)
56#define ECORE_IPC_SWAP2CPU8(x) (x)
57#else
58#define ECORE_IPC_SWAP2NET64(x) (x)
59#define ECORE_IPC_SWAP2CPU64(x) (x)
60#define ECORE_IPC_SWAP2NET32(x) (x)
61#define ECORE_IPC_SWAP2CPU32(x) (x)
62#define ECORE_IPC_SWAP2NET16(x) (x)
63#define ECORE_IPC_SWAP2CPU16(x) (x)
64#define ECORE_IPC_SWAP2NET8(x) (x)
65#define ECORE_IPC_SWAP2CPU8(x) (x)
66#endif
67
68/* 1, 2, 4 and 8 byte datatypes */
69/* unpacking */
70#define ECORE_IPC_GET64(v)\
71 { \
72 p->v = ECORE_IPC_SWAP2CPU64(*(long long *)(ptr)); \
73 ptr += 8; \
74 }
75#define ECORE_IPC_GET32(v)\
76 { \
77 p->v = ECORE_IPC_SWAP2CPU32(*(int *)(ptr)); \
78 ptr += 4; \
79 }
80#define ECORE_IPC_GET16(v)\
81 { \
82 p->v = ECORE_IPC_SWAP2CPU16(*(short *)(ptr)); \
83 ptr += 2; \
84 }
85#define ECORE_IPC_GET8(v) \
86 { \
87 p->v = ECORE_IPC_SWAP2CPU8(*(char *)(ptr)); \
88 ptr += 1; \
89 }
90/* packing */
91#define ECORE_IPC_PUT64(v)\
92 { \
93 *(long long *)(ptr) = ECORE_IPC_SWAP2NET64(p->v); \
94 ptr += 8; \
95 }
96#define ECORE_IPC_PUT32(v)\
97 { \
98 *(int *)(ptr) = ECORE_IPC_SWAP2NET32(p->v); \
99 ptr += 4; \
100 }
101#define ECORE_IPC_PUT16(v)\
102 { \
103 *(short *)(ptr) = ECORE_IPC_SWAP2NET16(p->v); \
104 ptr += 2; \
105 }
106#define ECORE_IPC_PUT8(v) \
107 { \
108 *(char *)(ptr) = ECORE_IPC_SWAP2NET8(p->v); \
109 ptr += 1; \
110 }
111/* padding data */
112#define ECORE_IPC_PAD8() ptr += 1
113#define ECORE_IPC_PAD16() ptr += 2
114#define ECORE_IPC_PAD32() ptr += 4
115#define ECORE_IPC_PAD64() ptr += 8
116
117/* counting data when encoding lists */
118#define ECORE_IPC_CNT8() len += 1
119#define ECORE_IPC_CNT16() len += 2
120#define ECORE_IPC_CNT32() len += 4
121#define ECORE_IPC_CNT64() len += 8
122
123/* strings */
124#define ECORE_IPC_CHEKS() if (*((unsigned char *)d + s - 1) != 0) return 0;
125#define ECORE_IPC_GETS(v) \
126 { \
127 if (ptr < ((unsigned char *)d + s)) \
128 { \
129 p->v = (char *)ptr; \
130 ptr += strlen(p->v) + 1; \
131 } \
132 }
133#define ECORE_IPC_PUTS(v, l)\
134 { \
135 strcpy((char *)ptr, p->v); \
136 ptr += l + 1; \
137 }
138
139/* handy to calculate what sized block we need to alloc */
140#define ECORE_IPC_SLEN(l, v) ((l = strlen(p->v)) + 1)
141#define ECORE_IPC_CNTS(v) len += strlen(p->v) + 1
142
143/* saves typing function headers */
144#define ECORE_IPC_DEC_STRUCT_PROTO(x) static int x(void *d, int s, void *pp)
145#define ECORE_IPC_ENC_STRUCT_PROTO(x) static void *x(void *pp, int *s)
146#define ECORE_IPC_DEC_EINA_LIST_PROTO(x) static Eina_List *x(void *d, int s)
147#define ECORE_IPC_ENC_EINA_LIST_PROTO(x) static void *x(Eina_List *lp, int *s)
148
149
150/* decoder setup - saves typing. requires data packet of exact size, or fail */
151#define ECORE_IPC_DEC_STRUCT_HEAD_EXACT(typ, x) \
152 typ *p; \
153 unsigned char *ptr; \
154 p = (typ *)pp; \
155 if (!d) return 0; if (s != (x)) return 0; \
156 ptr = d;
157/* decoder setup - saves typing. requires data packet of a minimum size */
158#define ECORE_IPC_DEC_STRUCT_HEAD_MIN(typ, x) \
159 typ *p; \
160 unsigned char *ptr; \
161 p = (typ *)pp; \
162 if (!d) return 0; if (s < (x)) return 0; \
163 ptr = d;
164/* footer for the hell of it */
165#define ECORE_IPC_DEC_STRUCT_FOOT() return 1
166/* header for encoder - gives native strct type and size of flattened packet */
167#define ECORE_IPC_ENC_STRUCT_HEAD(typ, sz) \
168 typ *p; \
169 unsigned char *d, *ptr; \
170 int len; \
171 *s = 0; \
172 if(!pp) return NULL; \
173 p = (typ *)pp; \
174 len = sz; \
175 d = malloc(len); \
176 if (!d) return NULL; \
177 *s = len; \
178 ptr = d;
179/* footer for the hell of it */
180#define ECORE_IPC_ENC_STRUCT_FOOT() return d
181
182#define ECORE_IPC_DEC_EINA_LIST_HEAD(typ) \
183 unsigned char *ptr; \
184 Eina_List *l; \
185 typ *p; \
186 l = NULL; \
187 ptr = d; \
188 while(ptr < (unsigned char *)(d + s)) \
189 { \
190 p = malloc(sizeof(typ));
191
192#define ECORE_IPC_DEC_EINA_LIST_FOOT() \
193 l = eina_list_append(l, p); \
194 } \
195 return l
196#define ECORE_IPC_ENC_EINA_LIST_HEAD_START(typ) \
197 Eina_List *l; \
198 typ *p; \
199 unsigned char *d, *ptr; \
200 int len; \
201 *s = 0; \
202 len = 0; \
203 for (l = lp; l; l = l->next) \
204 { \
205 p = l->data;
206#define ECORE_IPC_ENC_EINA_LIST_HEAD_FINISH() \
207 } \
208 d = malloc(len); \
209 if(!d) return NULL; \
210 *s = len; \
211 ptr = d; \
212 for (l = lp; l; l = l->next) \
213 { \
214 p = l->data;
215
216#define ECORE_IPC_ENC_EINA_LIST_FOOT() \
217 } \
218 return d
219
220typedef enum _Ecore_Ipc_Type
221{
222 ECORE_IPC_LOCAL_USER,
223 ECORE_IPC_LOCAL_SYSTEM,
224 ECORE_IPC_REMOTE_SYSTEM,
225 ECORE_IPC_USE_SSL = (1 << 4),
226 ECORE_IPC_NO_PROXY = (1 << 5)
227} Ecore_Ipc_Type;
228
229typedef struct _Ecore_Ipc_Event_Client_Add Ecore_Ipc_Event_Client_Add;
230typedef struct _Ecore_Ipc_Event_Client_Del Ecore_Ipc_Event_Client_Del;
231typedef struct _Ecore_Ipc_Event_Server_Add Ecore_Ipc_Event_Server_Add;
232typedef struct _Ecore_Ipc_Event_Server_Del Ecore_Ipc_Event_Server_Del;
233typedef struct _Ecore_Ipc_Event_Client_Data Ecore_Ipc_Event_Client_Data;
234typedef struct _Ecore_Ipc_Event_Server_Data Ecore_Ipc_Event_Server_Data;
235
236struct _Ecore_Ipc_Event_Client_Add
237{
238 Ecore_Ipc_Client *client;
239};
240
241struct _Ecore_Ipc_Event_Client_Del
242{
243 Ecore_Ipc_Client *client;
244};
245
246struct _Ecore_Ipc_Event_Server_Add
247{
248 Ecore_Ipc_Server *server;
249};
250
251struct _Ecore_Ipc_Event_Server_Del
252{
253 Ecore_Ipc_Server *server;
254};
255
256struct _Ecore_Ipc_Event_Client_Data
257{
258 Ecore_Ipc_Client *client;
259 /* FIXME: this needs to become an ipc message */
260 int major;
261 int minor;
262 int ref;
263 int ref_to;
264 int response;
265 void *data;
266 int size;
267};
268
269struct _Ecore_Ipc_Event_Server_Data
270{
271 Ecore_Ipc_Server *server;
272 /* FIXME: this needs to become an ipc message */
273 int major;
274 int minor;
275 int ref;
276 int ref_to;
277 int response;
278 void *data;
279 int size;
280};
281
282EAPI extern int ECORE_IPC_EVENT_CLIENT_ADD;
283EAPI extern int ECORE_IPC_EVENT_CLIENT_DEL;
284EAPI extern int ECORE_IPC_EVENT_SERVER_ADD;
285EAPI extern int ECORE_IPC_EVENT_SERVER_DEL;
286EAPI extern int ECORE_IPC_EVENT_CLIENT_DATA;
287EAPI extern int ECORE_IPC_EVENT_SERVER_DATA;
288
289EAPI int ecore_ipc_init(void);
290EAPI int ecore_ipc_shutdown(void);
291
292/* FIXME: need to add protocol type parameter */
293EAPI Ecore_Ipc_Server *ecore_ipc_server_add(Ecore_Ipc_Type type, const char *name, int port, const void *data);
294
295/* FIXME: need to add protocol type parameter */
296EAPI Ecore_Ipc_Server *ecore_ipc_server_connect(Ecore_Ipc_Type type, char *name, int port, const void *data);
297EAPI void *ecore_ipc_server_del(Ecore_Ipc_Server *svr);
298EAPI void *ecore_ipc_server_data_get(Ecore_Ipc_Server *svr);
299EAPI Eina_Bool ecore_ipc_server_connected_get(Ecore_Ipc_Server *svr);
300EAPI Eina_List *ecore_ipc_server_clients_get(Ecore_Ipc_Server *svr);
301/* FIXME: this needs to become an ipc message */
302EAPI int ecore_ipc_server_send(Ecore_Ipc_Server *svr, int major, int minor, int ref, int ref_to, int response, const void *data, int size);
303EAPI void ecore_ipc_server_client_limit_set(Ecore_Ipc_Server *svr, int client_limit, char reject_excess_clients);
304EAPI void ecore_ipc_server_data_size_max_set(Ecore_Ipc_Server *srv, int size);
305EAPI int ecore_ipc_server_data_size_max_get(Ecore_Ipc_Server *srv);
306EAPI const char *ecore_ipc_server_ip_get(Ecore_Ipc_Server *svr);
307EAPI void ecore_ipc_server_flush(Ecore_Ipc_Server *svr);
308
309/* FIXME: this needs to become an ipc message */
310EAPI int ecore_ipc_client_send(Ecore_Ipc_Client *cl, int major, int minor, int ref, int ref_to, int response, const void *data, int size);
311EAPI Ecore_Ipc_Server *ecore_ipc_client_server_get(Ecore_Ipc_Client *cl);
312EAPI void *ecore_ipc_client_del(Ecore_Ipc_Client *cl);
313EAPI void ecore_ipc_client_data_set(Ecore_Ipc_Client *cl, const void *data);
314EAPI void *ecore_ipc_client_data_get(Ecore_Ipc_Client *cl);
315EAPI void ecore_ipc_client_data_size_max_set(Ecore_Ipc_Client *cl, int size);
316EAPI int ecore_ipc_client_data_size_max_get(Ecore_Ipc_Client *cl);
317EAPI const char *ecore_ipc_client_ip_get(Ecore_Ipc_Client *cl);
318EAPI void ecore_ipc_client_flush(Ecore_Ipc_Client *cl);
319
320EAPI int ecore_ipc_ssl_available_get(void);
321/* FIXME: need to add a callback to "ok" large ipc messages greater than */
322/* a certain size (seurity/DOS attack safety) */
323
324#ifdef __cplusplus
325}
326#endif
327
328#endif
diff --git a/src/lib/ecore_ipc/ecore_ipc.c b/src/lib/ecore_ipc/ecore_ipc.c
new file mode 100644
index 0000000000..a421febdf9
--- /dev/null
+++ b/src/lib/ecore_ipc/ecore_ipc.c
@@ -0,0 +1,1599 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <string.h>
6
7#ifdef HAVE_NETINET_IN_H
8# include <sys/types.h>
9# include <netinet/in.h>
10#endif
11
12#ifdef HAVE_WINSOCK2_H
13# include <winsock2.h>
14#endif
15
16#include <Ecore.h>
17#include <ecore_private.h>
18#include <Ecore_Con.h>
19
20#include "Ecore_Ipc.h"
21#include "ecore_ipc_private.h"
22
23#define DLT_ZERO 0
24#define DLT_ONE 1
25#define DLT_SAME 2
26#define DLT_SHL 3
27#define DLT_SHR 4
28#define DLT_ADD8 5
29#define DLT_DEL8 6
30#define DLT_ADDU8 7
31#define DLT_DELU8 8
32#define DLT_ADD16 9
33#define DLT_DEL16 10
34#define DLT_ADDU16 11
35#define DLT_DELU16 12
36#define DLT_SET 13
37#define DLT_R1 14
38#define DLT_R2 15
39
40int _ecore_ipc_log_dom = -1;
41
42EAPI unsigned short
43_ecore_ipc_swap_16(unsigned short v)
44{
45 unsigned char *s, t;
46
47 s = (unsigned char *)(&v);
48 t = s[0]; s[0] = s[1]; s[1] = t;
49 return v;
50}
51
52EAPI unsigned int
53_ecore_ipc_swap_32(unsigned int v)
54{
55 unsigned char *s, t;
56
57 s = (unsigned char *)(&v);
58 t = s[0]; s[0] = s[3]; s[3] = t;
59 t = s[1]; s[1] = s[2]; s[2] = t;
60 return v;
61}
62
63EAPI unsigned long long
64_ecore_ipc_swap_64(unsigned long long v)
65{
66 unsigned char *s, t;
67
68 s = (unsigned char *)(&v);
69 t = s[0]; s[0] = s[7]; s[7] = t;
70 t = s[1]; s[1] = s[6]; s[6] = t;
71 t = s[2]; s[2] = s[5]; s[5] = t;
72 t = s[3]; s[3] = s[4]; s[4] = t;
73 return v;
74}
75
76static int _ecore_ipc_dlt_int(int out, int prev, int *mode);
77static int _ecore_ipc_ddlt_int(int in, int prev, int mode);
78
79static int
80_ecore_ipc_dlt_int(int out, int prev, int *mode)
81{
82 int dlt;
83
84 /* 0 byte */
85 if (out == 0)
86 {
87 *mode = DLT_ZERO;
88 return 0;
89 }
90 if (out == (int)0xffffffff)
91 {
92 *mode = DLT_ONE;
93 return 0;
94 }
95 if (out == prev)
96 {
97 *mode = DLT_SAME;
98 return 0;
99 }
100 if (out == prev << 1)
101 {
102 *mode = DLT_SHL;
103 return 0;
104 }
105 if (out == prev >> 1)
106 {
107 *mode = DLT_SHR;
108 return 0;
109 }
110 /* 1 byte */
111 dlt = out - prev;
112 if (!(dlt & 0xffffff00))
113 {
114 *mode = DLT_ADD8;
115 return dlt & 0xff;
116 }
117 dlt = prev - out;
118 if (!(dlt & 0xffffff00))
119 {
120 *mode = DLT_DEL8;
121 return dlt & 0xff;
122 }
123 dlt = out - prev;
124 if (!(dlt & 0x00ffffff))
125 {
126 *mode = DLT_ADDU8;
127 return (dlt >> 24) & 0xff;
128 }
129 dlt = prev - out;
130 if (!(dlt & 0x00ffffff))
131 {
132 *mode = DLT_DELU8;
133 return (dlt >> 24) & 0xff;
134 }
135 /* 2 byte */
136 dlt = out - prev;
137 if (!(dlt & 0xffff0000))
138 {
139 *mode = DLT_ADD16;
140 return dlt & 0xffff;
141 }
142 dlt = prev - out;
143 if (!(dlt & 0xffff0000))
144 {
145 *mode = DLT_DEL16;
146 return dlt & 0xffff;
147 }
148 dlt = out - prev;
149 if (!(dlt & 0x0000ffff))
150 {
151 *mode = DLT_ADDU16;
152 return (dlt >> 16) & 0xffff;
153 }
154 dlt = prev - out;
155 if (!(dlt & 0x0000ffff))
156 {
157 *mode = DLT_DELU16;
158 return (dlt >> 16) & 0xffff;
159 }
160 /* 4 byte */
161 *mode = DLT_SET;
162 return out;
163}
164
165static int
166_ecore_ipc_ddlt_int(int in, int prev, int mode)
167{
168 switch (mode)
169 {
170 case DLT_ZERO:
171 return 0;
172 break;
173 case DLT_ONE:
174 return 0xffffffff;
175 break;
176 case DLT_SAME:
177 return prev;
178 break;
179 case DLT_SHL:
180 return prev << 1;
181 break;
182 case DLT_SHR:
183 return prev >> 1;
184 break;
185 case DLT_ADD8:
186 return prev + in;
187 break;
188 case DLT_DEL8:
189 return prev - in;
190 break;
191 case DLT_ADDU8:
192 return prev + (in << 24);
193 break;
194 case DLT_DELU8:
195 return prev - (in << 24);
196 break;
197 case DLT_ADD16:
198 return prev + in;
199 break;
200 case DLT_DEL16:
201 return prev - in;
202 break;
203 case DLT_ADDU16:
204 return prev + (in << 16);
205 break;
206 case DLT_DELU16:
207 return prev - (in << 16);
208 break;
209 case DLT_SET:
210 return in;
211 break;
212 case DLT_R1:
213 return 0;
214 break;
215 case DLT_R2:
216 return 0;
217 break;
218 default:
219 break;
220 }
221 return 0;
222}
223
224static Eina_Bool _ecore_ipc_event_client_add(void *data, int ev_type, void *ev);
225static Eina_Bool _ecore_ipc_event_client_del(void *data, int ev_type, void *ev);
226static Eina_Bool _ecore_ipc_event_server_add(void *data, int ev_type, void *ev);
227static Eina_Bool _ecore_ipc_event_server_del(void *data, int ev_type, void *ev);
228static Eina_Bool _ecore_ipc_event_client_data(void *data, int ev_type, void *ev);
229static Eina_Bool _ecore_ipc_event_server_data(void *data, int ev_type, void *ev);
230static void _ecore_ipc_event_client_add_free(void *data, void *ev);
231static void _ecore_ipc_event_client_del_free(void *data, void *ev);
232static void _ecore_ipc_event_client_data_free(void *data, void *ev);
233static void _ecore_ipc_event_server_add_free(void *data, void *ev);
234static void _ecore_ipc_event_server_del_free(void *data, void *ev);
235static void _ecore_ipc_event_server_data_free(void *data, void *ev);
236
237EAPI int ECORE_IPC_EVENT_CLIENT_ADD = 0;
238EAPI int ECORE_IPC_EVENT_CLIENT_DEL = 0;
239EAPI int ECORE_IPC_EVENT_SERVER_ADD = 0;
240EAPI int ECORE_IPC_EVENT_SERVER_DEL = 0;
241EAPI int ECORE_IPC_EVENT_CLIENT_DATA = 0;
242EAPI int ECORE_IPC_EVENT_SERVER_DATA = 0;
243
244static int _ecore_ipc_init_count = 0;
245static Eina_List *servers = NULL;
246static Ecore_Event_Handler *handler[6];
247
248/**
249 * @defgroup Ecore_IPC_Library_Group IPC Library Functions
250 *
251 * Functions that set up and shut down the Ecore IPC Library.
252 */
253
254/**
255 * Initialises the Ecore IPC library.
256 * @return Number of times the library has been initialised without
257 * being shut down.
258 * @ingroup Ecore_IPC_Library_Group
259 */
260EAPI int
261ecore_ipc_init(void)
262{
263 int i = 0;
264
265 if (++_ecore_ipc_init_count != 1)
266 return _ecore_ipc_init_count;
267 _ecore_ipc_log_dom = eina_log_domain_register
268 ("ecore_ipc", ECORE_IPC_DEFAULT_LOG_COLOR);
269 if(_ecore_ipc_log_dom < 0)
270 {
271 EINA_LOG_ERR("Impossible to create a log domain for the Ecore IPC module.");
272 return --_ecore_ipc_init_count;
273 }
274 if (!ecore_con_init())
275 return --_ecore_ipc_init_count;
276
277 ECORE_IPC_EVENT_CLIENT_ADD = ecore_event_type_new();
278 ECORE_IPC_EVENT_CLIENT_DEL = ecore_event_type_new();
279 ECORE_IPC_EVENT_SERVER_ADD = ecore_event_type_new();
280 ECORE_IPC_EVENT_SERVER_DEL = ecore_event_type_new();
281 ECORE_IPC_EVENT_CLIENT_DATA = ecore_event_type_new();
282 ECORE_IPC_EVENT_SERVER_DATA = ecore_event_type_new();
283
284 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD,
285 _ecore_ipc_event_client_add, NULL);
286 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL,
287 _ecore_ipc_event_client_del, NULL);
288 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
289 _ecore_ipc_event_server_add, NULL);
290 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
291 _ecore_ipc_event_server_del, NULL);
292 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA,
293 _ecore_ipc_event_client_data, NULL);
294 handler[i] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
295 _ecore_ipc_event_server_data, NULL);
296 return _ecore_ipc_init_count;
297}
298
299/**
300 * Shuts down the Ecore IPC library.
301 * @return Number of times the library has been initialised without being
302 * shut down.
303 * @ingroup Ecore_IPC_Library_Group
304 */
305EAPI int
306ecore_ipc_shutdown(void)
307{
308 int i;
309
310 if (--_ecore_ipc_init_count != 0)
311 return _ecore_ipc_init_count;
312
313 Eina_List *l, *l2;
314 Ecore_Ipc_Server *svr;
315 EINA_LIST_FOREACH_SAFE(servers, l, l2, svr)
316 ecore_ipc_server_del(svr);
317
318 for (i = 0; i < 6; i++)
319 ecore_event_handler_del(handler[i]);
320
321 ecore_con_shutdown();
322 eina_log_domain_unregister(_ecore_ipc_log_dom);
323 _ecore_ipc_log_dom = -1;
324 return _ecore_ipc_init_count;
325}
326
327/**
328 * @defgroup Ecore_IPC_Server_Group IPC Server Functions
329 *
330 * Functions the deal with IPC server objects.
331 */
332
333/**
334 * Creates an IPC server that listens for connections.
335 *
336 * For more details about the @p compl_type, @p name and @p port
337 * parameters, see the @ref ecore_con_server_add documentation.
338 *
339 * @param compl_type The connection type.
340 * @param name Name to associate with the socket used for connection.
341 * @param port Number to identify with socket used for connection.
342 * @param data Data to associate with the IPC server.
343 * @return New IPC server. If there is an error, @c NULL is returned.
344 * @ingroup Ecore_IPC_Server_Group
345 * @todo Need to add protocol type parameter to this function.
346 */
347EAPI Ecore_Ipc_Server *
348ecore_ipc_server_add(Ecore_Ipc_Type compl_type, const char *name, int port, const void *data)
349{
350 Ecore_Ipc_Server *svr;
351 Ecore_Ipc_Type type;
352 Ecore_Con_Type extra = 0;
353
354 if (!name) return NULL;
355
356 svr = calloc(1, sizeof(Ecore_Ipc_Server));
357 if (!svr) return NULL;
358 type = compl_type;
359 type &= ~ECORE_IPC_USE_SSL;
360 if (compl_type & ECORE_IPC_USE_SSL) extra = ECORE_CON_USE_SSL;
361 switch (type)
362 {
363 case ECORE_IPC_LOCAL_USER:
364 svr->server = ecore_con_server_add(ECORE_CON_LOCAL_USER | extra, name, port, svr);
365 break;
366 case ECORE_IPC_LOCAL_SYSTEM:
367 svr->server = ecore_con_server_add(ECORE_CON_LOCAL_SYSTEM | extra, name, port, svr);
368 break;
369 case ECORE_IPC_REMOTE_SYSTEM:
370 svr->server = ecore_con_server_add(ECORE_CON_REMOTE_SYSTEM | extra, name, port, svr);
371 break;
372 default:
373 free(svr);
374 return NULL;
375 }
376 if (!svr->server)
377 {
378 free(svr);
379 return NULL;
380 }
381 svr->max_buf_size = 32 * 1024;
382 svr->data = (void *)data;
383 servers = eina_list_append(servers, svr);
384 ECORE_MAGIC_SET(svr, ECORE_MAGIC_IPC_SERVER);
385 return svr;
386}
387
388/**
389 * Creates an IPC server object to represent the IPC server listening
390 * on the given port.
391 *
392 * For more details about the @p compl_type, @p name and @p port
393 * parameters, see the @ref ecore_con_server_connect documentation.
394 *
395 * @param compl_type The IPC connection type.
396 * @param name Name used to determine which socket to use for the
397 * IPC connection.
398 * @param port Number used to identify the socket to use for the
399 * IPC connection.
400 * @param data Data to associate with the server.
401 * @return A new IPC server. @c NULL is returned on error.
402 * @ingroup Ecore_IPC_Server_Group
403 * @todo Need to add protocol type parameter.
404 */
405EAPI Ecore_Ipc_Server *
406ecore_ipc_server_connect(Ecore_Ipc_Type compl_type, char *name, int port, const void *data)
407{
408 Ecore_Ipc_Server *svr;
409 Ecore_Ipc_Type type;
410 Ecore_Con_Type extra = 0;
411 int features;
412
413 svr = calloc(1, sizeof(Ecore_Ipc_Server));
414 if (!svr) return NULL;
415 type = compl_type & ECORE_IPC_TYPE;
416 features = compl_type & ECORE_IPC_SSL;
417 if ((features & ECORE_IPC_USE_SSL) == ECORE_IPC_USE_SSL)
418 extra |= ECORE_CON_USE_SSL;
419 if ((features & ECORE_IPC_NO_PROXY) == ECORE_IPC_NO_PROXY)
420 extra |= ECORE_CON_NO_PROXY;
421 switch (type)
422 {
423 case ECORE_IPC_LOCAL_USER:
424 svr->server = ecore_con_server_connect(ECORE_CON_LOCAL_USER | extra, name, port, svr);
425 break;
426 case ECORE_IPC_LOCAL_SYSTEM:
427 svr->server = ecore_con_server_connect(ECORE_CON_LOCAL_SYSTEM | extra, name, port, svr);
428 break;
429 case ECORE_IPC_REMOTE_SYSTEM:
430 svr->server = ecore_con_server_connect(ECORE_CON_REMOTE_SYSTEM | extra, name, port, svr);
431 break;
432 default:
433 free(svr);
434 return NULL;
435 }
436 if (!svr->server)
437 {
438 free(svr);
439 return NULL;
440 }
441 svr->max_buf_size = -1;
442 svr->data = (void *)data;
443 servers = eina_list_append(servers, svr);
444 ECORE_MAGIC_SET(svr, ECORE_MAGIC_IPC_SERVER);
445 return svr;
446}
447
448/**
449 * Closes the connection and frees the given IPC server.
450 * @param svr The given IPC server.
451 * @return The data associated with the server when it was created.
452 * @ingroup Ecore_IPC_Server_Group
453 */
454EAPI void *
455ecore_ipc_server_del(Ecore_Ipc_Server *svr)
456{
457 void *data;
458
459 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
460 {
461 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
462 "ecore_ipc_server_del");
463 return NULL;
464 }
465 if (svr->delete_me) return NULL;
466
467 data = svr->data;
468 svr->data = NULL;
469 svr->delete_me = 1;
470 if (svr->event_count == 0)
471 {
472 Ecore_Ipc_Client *cl;
473
474 EINA_LIST_FREE(svr->clients, cl)
475 ecore_ipc_client_del(cl);
476 if (svr->server) ecore_con_server_del(svr->server);
477 servers = eina_list_remove(servers, svr);
478
479 if (svr->buf) free(svr->buf);
480 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
481 free(svr);
482 }
483 return data;
484}
485
486/**
487 * Retrieves the data associated with the given IPC server.
488 * @param svr The given IPC server.
489 * @return The associated data.
490 * @ingroup Ecore_IPC_Server_Group
491 */
492EAPI void *
493ecore_ipc_server_data_get(Ecore_Ipc_Server *svr)
494{
495 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
496 {
497 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
498 "ecore_ipc_server_data_get");
499 return NULL;
500 }
501 return svr->data;
502}
503
504/**
505 * Retrieves whether the given IPC server is currently connected.
506 * @param svr The given IPC server.
507 * @return @c EINA_TRUE if the server is connected, @c EINA_FALSE otherwise.
508 * @ingroup Ecore_IPC_Server_Group
509 */
510EAPI Eina_Bool
511ecore_ipc_server_connected_get(Ecore_Ipc_Server *svr)
512{
513 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
514 {
515 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
516 "ecore_ipc_server_connected_get");
517 return EINA_FALSE;
518 }
519 return ecore_con_server_connected_get(svr->server);
520}
521
522/**
523 * Retrieves the list of clients for this server.
524 * @param svr The given IPC server.
525 * @return An Eina_List with the clients.
526 * @ingroup Ecore_IPC_Server_Group
527 */
528EAPI Eina_List *
529ecore_ipc_server_clients_get(Ecore_Ipc_Server *svr)
530{
531 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
532 {
533 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
534 "ecore_ipc_server_clients_get");
535 return NULL;
536 }
537 return svr->clients;
538}
539
540#define SVENC(_member) \
541 d = _ecore_ipc_dlt_int(msg._member, svr->prev.o._member, &md); \
542 if (md >= DLT_SET) \
543 { \
544 unsigned int v; \
545 unsigned char *dd; \
546 dd = (unsigned char *)&v; \
547 v = d; \
548 v = htonl(v); \
549 *(dat + s + 0) = dd[0]; \
550 *(dat + s + 1) = dd[1]; \
551 *(dat + s + 2) = dd[2]; \
552 *(dat + s + 3) = dd[3]; \
553 s += 4; \
554 } \
555 else if (md >= DLT_ADD16) \
556 { \
557 unsigned short v; \
558 unsigned char *dd; \
559 dd = (unsigned char *)&v; \
560 v = d; \
561 v = htons(v); \
562 *(dat + s + 0) = dd[0]; \
563 *(dat + s + 1) = dd[1]; \
564 s += 2; \
565 } \
566 else if (md >= DLT_ADD8) \
567 { \
568 *(dat + s + 0) = (unsigned char)d; \
569 s += 1; \
570 }
571
572/**
573 * Sends a message to the given IPC server.
574 *
575 * The content of the parameters, excluding the @p svr paramter, is up to
576 * the client.
577 *
578 * @param svr The given IPC server.
579 * @param major Major opcode of the message.
580 * @param minor Minor opcode of the message.
581 * @param ref Message reference number.
582 * @param ref_to Reference number of the message this message refers to.
583 * @param response Requires response.
584 * @param data The data to send as part of the message.
585 * @param size Length of the data, in bytes, to send.
586 * @return Number of bytes sent. @c 0 is returned if there is an error.
587 * @ingroup Ecore_IPC_Server_Group
588 * @todo This function needs to become an IPC message.
589 * @todo Fix up the documentation: Make sure what ref_to and response are.
590 */
591EAPI int
592ecore_ipc_server_send(Ecore_Ipc_Server *svr, int major, int minor, int ref, int ref_to, int response, const void *data, int size)
593{
594 Ecore_Ipc_Msg_Head msg;
595 int ret;
596 int *head, md = 0, d, s;
597 unsigned char dat[sizeof(Ecore_Ipc_Msg_Head)];
598
599 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
600 {
601 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
602 "ecore_ipc_server_send");
603 return 0;
604 }
605 if (size < 0) size = 0;
606 msg.major = major;
607 msg.minor = minor;
608 msg.ref = ref;
609 msg.ref_to = ref_to;
610 msg.response = response;
611 msg.size = size;
612 head = (int *)dat;
613 s = 4;
614 SVENC(major);
615 *head = md;
616 SVENC(minor);
617 *head |= md << (4 * 1);
618 SVENC(ref);
619 *head |= md << (4 * 2);
620 SVENC(ref_to);
621 *head |= md << (4 * 3);
622 SVENC(response);
623 *head |= md << (4 * 4);
624 SVENC(size);
625 *head |= md << (4 * 5);
626 *head = htonl(*head);
627 svr->prev.o = msg;
628 ret = ecore_con_server_send(svr->server, dat, s);
629 if (size > 0) ret += ecore_con_server_send(svr->server, data, size);
630 return ret;
631}
632
633/**
634 * Sets a limit on the number of clients that can be handled concurrently
635 * by the given server, and a policy on what to do if excess clients try to
636 * connect.
637 * Beware that if you set this once ecore is already running, you may
638 * already have pending CLIENT_ADD events in your event queue. Those
639 * clients have already connected and will not be affected by this call.
640 * Only clients subsequently trying to connect will be affected.
641 * @param svr The given server.
642 * @param client_limit The maximum number of clients to handle
643 * concurrently. -1 means unlimited (default). 0
644 * effectively disables the server.
645 * @param reject_excess_clients Set to 1 to automatically disconnect
646 * excess clients as soon as they connect if you are
647 * already handling client_limit clients. Set to 0
648 * (default) to just hold off on the "accept()"
649 * system call until the number of active clients
650 * drops. This causes the kernel to queue up to 4096
651 * connections (or your kernel's limit, whichever is
652 * lower).
653 * @ingroup Ecore_Ipc_Server_Group
654 */
655EAPI void
656ecore_ipc_server_client_limit_set(Ecore_Ipc_Server *svr, int client_limit, char reject_excess_clients)
657{
658 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
659 {
660 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
661 "ecore_ipc_server_client_limit_set");
662 return;
663 }
664 ecore_con_server_client_limit_set(svr->server, client_limit, reject_excess_clients);
665}
666
667/**
668 * Sets the max data payload size for an Ipc message in bytes
669 *
670 * @param svr The given server.
671 * @param size The maximum data payload size in bytes.
672 * @ingroup Ecore_Ipc_Server_Group
673 */
674EAPI void
675ecore_ipc_server_data_size_max_set(Ecore_Ipc_Server *svr, int size)
676{
677 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
678 {
679 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
680 "ecore_ipc_server_data_size_max_set");
681 return;
682 }
683 svr->max_buf_size = size;
684}
685
686/**
687 * Gets the max data payload size for an Ipc message in bytes
688 *
689 * @param svr The given server.
690 * @return The maximum data payload in bytes.
691 * @ingroup Ecore_Ipc_Server_Group
692 */
693EAPI int
694ecore_ipc_server_data_size_max_get(Ecore_Ipc_Server *svr)
695{
696 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
697 {
698 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
699 "ecore_ipc_server_data_size_max_get");
700 return -1;
701 }
702 return svr->max_buf_size;
703}
704
705/**
706 * Gets the IP address of a server that has been connected to.
707 *
708 * @param svr The given server.
709 * @return A pointer to an internal string that contains the IP address of
710 * the connected server in the form "XXX.YYY.ZZZ.AAA" IP notation.
711 * This string should not be modified or trusted to stay valid after
712 * deletion for the @p svr object. If no IP is known NULL is returned.
713 * @ingroup Ecore_Ipc_Server_Group
714 */
715EAPI const char *
716ecore_ipc_server_ip_get(Ecore_Ipc_Server *svr)
717{
718 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
719 {
720 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
721 "ecore_ipc_server_ip_get");
722 return NULL;
723 }
724 return ecore_con_server_ip_get(svr->server);
725}
726
727/**
728 * Flushes all pending data to the given server. Will return when done.
729 *
730 * @param svr The given server.
731 * @ingroup Ecore_Ipc_Server_Group
732 */
733EAPI void
734ecore_ipc_server_flush(Ecore_Ipc_Server *svr)
735{
736 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_IPC_SERVER))
737 {
738 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_IPC_SERVER,
739 "ecore_ipc_server_server_flush");
740 return;
741 }
742 ecore_con_server_flush(svr->server);
743}
744
745#define CLENC(_member) \
746 d = _ecore_ipc_dlt_int(msg._member, cl->prev.o._member, &md); \
747 if (md >= DLT_SET) \
748 { \
749 unsigned int v; \
750 unsigned char *dd; \
751 dd = (unsigned char *)&v; \
752 v = d; \
753 v = htonl(v); \
754 *(dat + s + 0) = dd[0]; \
755 *(dat + s + 1) = dd[1]; \
756 *(dat + s + 2) = dd[2]; \
757 *(dat + s + 3) = dd[3]; \
758 s += 4; \
759 } \
760 else if (md >= DLT_ADD16) \
761 { \
762 unsigned short v; \
763 unsigned char *dd; \
764 dd = (unsigned char *)&v; \
765 v = d; \
766 v = htons(v); \
767 *(dat + s + 0) = dd[0]; \
768 *(dat + s + 1) = dd[1]; \
769 s += 2; \
770 } \
771 else if (md >= DLT_ADD8) \
772 { \
773 *(dat + s) = (unsigned char)d; \
774 s += 1; \
775 }
776
777/**
778 * @defgroup Ecore_IPC_Client_Group IPC Client Functions
779 *
780 * Functions that deal with IPC client objects.
781 */
782
783/**
784 * Sends a message to the given IPC client.
785 * @param cl The given IPC client.
786 * @param major Major opcode of the message.
787 * @param minor Minor opcode of the message.
788 * @param ref Reference number of the message.
789 * @param ref_to Reference number of the message this message refers to.
790 * @param response Requires response.
791 * @param data The data to send as part of the message.
792 * @param size Length of the data, in bytes, to send.
793 * @return The number of bytes sent. @c 0 will be returned if there is
794 * an error.
795 * @ingroup Ecore_IPC_Client_Group
796 * @todo This function needs to become an IPC message.
797 * @todo Make sure ref_to and response parameters are described correctly.
798 */
799EAPI int
800ecore_ipc_client_send(Ecore_Ipc_Client *cl, int major, int minor, int ref, int ref_to, int response, const void *data, int size)
801{
802 Ecore_Ipc_Msg_Head msg;
803 int ret;
804 int *head, md = 0, d, s;
805 unsigned char dat[sizeof(Ecore_Ipc_Msg_Head)];
806
807 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
808 {
809 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
810 "ecore_ipc_client_send");
811 return 0;
812 }
813 EINA_SAFETY_ON_TRUE_RETURN_VAL(!cl->client, 0);
814 EINA_SAFETY_ON_TRUE_RETURN_VAL(!ecore_con_client_connected_get(cl->client), 0);
815 if (size < 0) size = 0;
816 msg.major = major;
817 msg.minor = minor;
818 msg.ref = ref;
819 msg.ref_to = ref_to;
820 msg.response = response;
821 msg.size = size;
822 head = (int *)dat;
823 s = 4;
824 CLENC(major);
825 *head = md;
826 CLENC(minor);
827 *head |= md << (4 * 1);
828 CLENC(ref);
829 *head |= md << (4 * 2);
830 CLENC(ref_to);
831 *head |= md << (4 * 3);
832 CLENC(response);
833 *head |= md << (4 * 4);
834 CLENC(size);
835 *head |= md << (4 * 5);
836 *head = htonl(*head);
837 cl->prev.o = msg;
838 ret = ecore_con_client_send(cl->client, dat, s);
839 if (size > 0) ret += ecore_con_client_send(cl->client, data, size);
840 return ret;
841}
842
843/**
844 * Retrieves the IPC server that the given IPC client is connected to.
845 * @param cl The given IPC client.
846 * @return The IPC server the IPC client is connected to.
847 * @ingroup Ecore_IPC_Client_Group
848 */
849EAPI Ecore_Ipc_Server *
850ecore_ipc_client_server_get(Ecore_Ipc_Client *cl)
851{
852 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
853 {
854 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
855 "ecore_ipc_client_server_get");
856 return NULL;
857 }
858 return cl->svr;
859}
860
861/**
862 * Closes the connection and frees memory allocated to the given IPC
863 * client.
864 * @param cl The given client.
865 * @return Data associated with the client.
866 * @ingroup Ecore_IPC_Client_Group
867 */
868EAPI void *
869ecore_ipc_client_del(Ecore_Ipc_Client *cl)
870{
871 void *data;
872 Ecore_Ipc_Server *svr;
873
874 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
875 {
876 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
877 "ecore_ipc_client_del");
878 return NULL;
879 }
880 data = cl->data;
881 cl->data = NULL;
882 cl->delete_me = 1;
883 if (cl->event_count == 0)
884 {
885 svr = cl->svr;
886 if (cl->client) ecore_con_client_del(cl->client);
887 svr->clients = eina_list_remove(svr->clients, cl);
888 if (cl->buf) free(cl->buf);
889 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
890 free(cl);
891 }
892 return data;
893}
894
895/**
896 * Sets the IPC data associated with the given IPC client to @p data.
897 * @param cl The given IPC client.
898 * @param data The data to associate with the IPC client.
899 * @ingroup Ecore_IPC_Client_Group
900 */
901EAPI void
902ecore_ipc_client_data_set(Ecore_Ipc_Client *cl, const void *data)
903{
904 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
905 {
906 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
907 "ecore_ipc_client_data_set");
908 return;
909 }
910 cl->data = (void *)data;
911}
912
913/**
914 * Retrieves the data that has been associated with the given IPC client.
915 * @param cl The given client.
916 * @return The data associated with the IPC client.
917 * @ingroup Ecore_IPC_Client_Group
918 */
919EAPI void *
920ecore_ipc_client_data_get(Ecore_Ipc_Client *cl)
921{
922 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
923 {
924 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
925 "ecore_ipc_client_data_get");
926 return NULL;
927 }
928 return cl->data;
929}
930
931/**
932 * Sets the max data payload size for an Ipc message in bytes
933 *
934 * @param cl The given client.
935 * @param size The maximum data payload size in bytes.
936 * @ingroup Ecore_Ipc_Client_Group
937 */
938EAPI void
939ecore_ipc_client_data_size_max_set(Ecore_Ipc_Client *cl, int size)
940{
941 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
942 {
943 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
944 "ecore_ipc_client_data_size_max_set");
945 return;
946 }
947 cl->max_buf_size = size;
948}
949
950/**
951 * Gets the max data payload size for an Ipc message in bytes
952 *
953 * @param cl The given client.
954 * @return The maximum data payload size in bytes on success, @c -1 on failure.
955 * @ingroup Ecore_Ipc_Client_Group
956 */
957EAPI int
958ecore_ipc_client_data_size_max_get(Ecore_Ipc_Client *cl)
959{
960 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
961 {
962 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
963 "ecore_ipc_client_data_size_max_get");
964 return -1;
965 }
966 return cl->max_buf_size;
967}
968
969/**
970 * Gets the IP address of a client that has been connected to.
971 *
972 * @param cl The given client.
973 * @return A pointer to an internal string that contains the IP address of
974 * the connected server in the form "XXX.YYY.ZZZ.AAA" IP notation.
975 * This string should not be modified or trusted to stay valid after
976 * deletion for the @p cl object. If no IP is known @c NULL is
977 * returned.
978 * @ingroup Ecore_Ipc_Client_Group
979 */
980EAPI const char *
981ecore_ipc_client_ip_get(Ecore_Ipc_Client *cl)
982{
983 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
984 {
985 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
986 "ecore_ipc_client_ip_get");
987 return NULL;
988 }
989 return ecore_con_client_ip_get(cl->client);
990}
991
992/**
993 * Flushes all pending data to the given client. Will return when done.
994 *
995 * @param cl The given client.
996 * @ingroup Ecore_Ipc_Client_Group
997 */
998EAPI void
999ecore_ipc_client_flush(Ecore_Ipc_Client *cl)
1000{
1001 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_IPC_CLIENT))
1002 {
1003 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_IPC_CLIENT,
1004 "ecore_ipc_client_flush");
1005 return;
1006 }
1007 ecore_con_client_flush(cl->client);
1008}
1009
1010/**
1011 * Returns if SSL support is available
1012 * @return 1 if SSL is available, 0 if it is not.
1013 * @ingroup Ecore_Con_Client_Group
1014 */
1015EAPI int
1016ecore_ipc_ssl_available_get(void)
1017{
1018 return ecore_con_ssl_available_get();
1019}
1020
1021
1022static Eina_Bool
1023_ecore_ipc_event_client_add(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1024{
1025 Ecore_Con_Event_Client_Add *e;
1026 Ecore_Ipc_Server *svr;
1027
1028 e = ev;
1029 svr = ecore_con_server_data_get(ecore_con_client_server_get(e->client));
1030 if (!eina_list_data_find(servers, svr)) return ECORE_CALLBACK_RENEW;
1031 /* handling code here */
1032 {
1033 Ecore_Ipc_Client *cl;
1034
1035 cl = calloc(1, sizeof(Ecore_Ipc_Client));
1036 if (!cl) return ECORE_CALLBACK_CANCEL;
1037 cl->svr = svr;
1038 ECORE_MAGIC_SET(cl, ECORE_MAGIC_IPC_CLIENT);
1039 cl->client = e->client;
1040 cl->max_buf_size = 32 * 1024;
1041 ecore_con_client_data_set(cl->client, (void *)cl);
1042 svr->clients = eina_list_append(svr->clients, cl);
1043 if (!cl->delete_me)
1044 {
1045 Ecore_Ipc_Event_Client_Add *e2;
1046
1047 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Client_Add));
1048 if (e2)
1049 {
1050 cl->event_count++;
1051 e2->client = cl;
1052 ecore_event_add(ECORE_IPC_EVENT_CLIENT_ADD, e2,
1053 _ecore_ipc_event_client_add_free, NULL);
1054 }
1055 }
1056 }
1057 return ECORE_CALLBACK_CANCEL;
1058}
1059
1060static Eina_Bool
1061_ecore_ipc_event_client_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1062{
1063 Ecore_Con_Event_Client_Del *e;
1064 Ecore_Ipc_Server *svr;
1065
1066 e = ev;
1067 if (!e->client) return ECORE_CALLBACK_RENEW;
1068 svr = ecore_con_server_data_get(ecore_con_client_server_get(e->client));
1069 if (!eina_list_data_find(servers, svr)) return ECORE_CALLBACK_RENEW;
1070 /* handling code here */
1071 {
1072 Ecore_Ipc_Client *cl;
1073
1074 cl = ecore_con_client_data_get(e->client);
1075 cl->client = NULL;
1076 {
1077 Ecore_Ipc_Event_Client_Del *e2;
1078
1079 if (!cl->delete_me)
1080 {
1081 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Client_Del));
1082 if (e2)
1083 {
1084 cl->event_count++;
1085 e2->client = cl;
1086 ecore_event_add(ECORE_IPC_EVENT_CLIENT_DEL, e2,
1087 _ecore_ipc_event_client_del_free, NULL);
1088 }
1089 }
1090 }
1091 }
1092 return ECORE_CALLBACK_CANCEL;
1093}
1094
1095static Eina_Bool
1096_ecore_ipc_event_server_add(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1097{
1098 Ecore_Con_Event_Server_Add *e;
1099
1100 e = ev;
1101 if (!eina_list_data_find(servers, ecore_con_server_data_get(e->server))) return ECORE_CALLBACK_RENEW;
1102 /* handling code here */
1103 {
1104 Ecore_Ipc_Server *svr;
1105
1106 svr = ecore_con_server_data_get(e->server);
1107 if (!svr->delete_me)
1108 {
1109 Ecore_Ipc_Event_Server_Add *e2;
1110
1111 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Server_Add));
1112 if (e2)
1113 {
1114 svr->event_count++;
1115 e2->server = svr;
1116 ecore_event_add(ECORE_IPC_EVENT_SERVER_ADD, e2,
1117 _ecore_ipc_event_server_add_free, NULL);
1118 }
1119 }
1120 }
1121 return ECORE_CALLBACK_CANCEL;
1122}
1123
1124static Eina_Bool
1125_ecore_ipc_event_server_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1126{
1127 Ecore_Con_Event_Server_Del *e;
1128
1129 e = ev;
1130 if (!eina_list_data_find(servers, ecore_con_server_data_get(e->server))) return ECORE_CALLBACK_RENEW;
1131 /* handling code here */
1132 {
1133 Ecore_Ipc_Server *svr;
1134
1135 svr = ecore_con_server_data_get(e->server);
1136 svr->server = NULL;
1137 if (!svr->delete_me)
1138 {
1139 Ecore_Ipc_Event_Server_Del *e2;
1140
1141 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Server_Del));
1142 if (e2)
1143 {
1144 svr->event_count++;
1145 e2->server = svr;
1146 ecore_event_add(ECORE_IPC_EVENT_SERVER_DEL, e2,
1147 _ecore_ipc_event_server_del_free, NULL);
1148 }
1149 }
1150 }
1151 return ECORE_CALLBACK_CANCEL;
1152}
1153
1154#define CLSZ(_n) \
1155 md = ((head >> (4 * _n)) & 0xf); \
1156 if (md >= DLT_SET) s += 4; \
1157 else if (md >= DLT_ADD16) s += 2; \
1158 else if (md >= DLT_ADD8) s += 1;
1159
1160#define CLDEC(_n, _member) \
1161 md = ((head >> (4 * _n)) & 0xf); \
1162 if (md >= DLT_SET) \
1163 { \
1164 unsigned int v; \
1165 unsigned char *dv; \
1166 dv = (unsigned char *)&v; \
1167 dv[0] = *(cl->buf + offset + s + 0); \
1168 dv[1] = *(cl->buf + offset + s + 1); \
1169 dv[2] = *(cl->buf + offset + s + 2); \
1170 dv[3] = *(cl->buf + offset + s + 3); \
1171 d = (int)ntohl(v); \
1172 s += 4; \
1173 } \
1174 else if (md >= DLT_ADD16) \
1175 { \
1176 unsigned short v; \
1177 unsigned char *dv; \
1178 dv = (unsigned char *)&v; \
1179 dv[0] = *(cl->buf + offset + s + 0); \
1180 dv[1] = *(cl->buf + offset + s + 1); \
1181 d = (int)ntohs(v); \
1182 s += 2; \
1183 } \
1184 else if (md >= DLT_ADD8) \
1185 { \
1186 unsigned char v; \
1187 unsigned char *dv; \
1188 dv = (unsigned char *)&v; \
1189 dv[0] = *(cl->buf + offset + s + 0); \
1190 d = (int)v; \
1191 s += 1; \
1192 } \
1193 msg._member = _ecore_ipc_ddlt_int(d, cl->prev.i._member, md);
1194
1195static Eina_Bool
1196_ecore_ipc_event_client_data(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1197{
1198 Ecore_Con_Event_Client_Data *e;
1199 Ecore_Ipc_Server *svr;
1200
1201 e = ev;
1202 svr = ecore_con_server_data_get(ecore_con_client_server_get(e->client));
1203 if (!eina_list_data_find(servers, svr)) return ECORE_CALLBACK_RENEW;
1204 /* handling code here */
1205 {
1206 Ecore_Ipc_Client *cl;
1207 Ecore_Ipc_Msg_Head msg;
1208 int offset = 0;
1209 unsigned char *buf;
1210
1211 cl = ecore_con_client_data_get(e->client);
1212
1213 if (!cl->buf)
1214 {
1215 cl->buf_size = e->size;
1216 cl->buf = e->data;
1217 e->data = NULL; /* take it out of the old event */
1218 }
1219 else
1220 {
1221 buf = realloc(cl->buf, cl->buf_size + e->size);
1222 if (!buf)
1223 {
1224 free(cl->buf);
1225 cl->buf = 0;
1226 cl->buf_size = 0;
1227 return ECORE_CALLBACK_CANCEL;
1228 }
1229 cl->buf = buf;
1230 memcpy(cl->buf + cl->buf_size, e->data, e->size);
1231 cl->buf_size += e->size;
1232 }
1233 /* examine header */
1234 redo:
1235 if ((cl->buf_size - offset) >= (int)sizeof(int))
1236 {
1237 int s, md, d = 0, head;
1238 unsigned char *dd;
1239
1240 dd = (unsigned char *)&head;
1241 dd[0] = *(cl->buf + offset + 0);
1242 dd[1] = *(cl->buf + offset + 1);
1243 dd[2] = *(cl->buf + offset + 2);
1244 dd[3] = *(cl->buf + offset + 3);
1245 head = ntohl(head);
1246 dd = (unsigned char *)&d;
1247 s = 4;
1248 CLSZ(0);
1249 CLSZ(1);
1250 CLSZ(2);
1251 CLSZ(3);
1252 CLSZ(4);
1253 CLSZ(5);
1254 if ((cl->buf_size - offset) < s)
1255 {
1256 if (offset > 0) goto scroll;
1257 return ECORE_CALLBACK_CANCEL;
1258 }
1259
1260 s = 4;
1261 CLDEC(0, major);
1262 CLDEC(1, minor);
1263 CLDEC(2, ref);
1264 CLDEC(3, ref_to);
1265 CLDEC(4, response);
1266 CLDEC(5, size);
1267 if (msg.size < 0) msg.size = 0;
1268 /* there is enough data in the buffer for a full message */
1269 if ((cl->buf_size - offset) >= (s + msg.size))
1270 {
1271 Ecore_Ipc_Event_Client_Data *e2;
1272 int max, max2;
1273
1274 buf = NULL;
1275 max = svr->max_buf_size;
1276 max2 = cl->max_buf_size;
1277 if ((max >= 0) && (max2 >= 0))
1278 {
1279 if (max2 < max) max = max2;
1280 }
1281 else
1282 {
1283 if (max < 0) max = max2;
1284 }
1285 if ((max < 0) || (msg.size <= max))
1286 {
1287 if (msg.size > 0)
1288 {
1289 buf = malloc(msg.size);
1290 if (!buf) return ECORE_CALLBACK_CANCEL;
1291 memcpy(buf, cl->buf + offset + s, msg.size);
1292 }
1293 if (!cl->delete_me)
1294 {
1295 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Client_Data));
1296 if (e2)
1297 {
1298 cl->event_count++;
1299 e2->client = cl;
1300 e2->major = msg.major;
1301 e2->minor = msg.minor;
1302 e2->ref = msg.ref;
1303 e2->ref_to = msg.ref_to;
1304 e2->response = msg.response;
1305 e2->size = msg.size;
1306 e2->data = buf;
1307 ecore_event_add(ECORE_IPC_EVENT_CLIENT_DATA, e2,
1308 _ecore_ipc_event_client_data_free,
1309 NULL);
1310 }
1311 }
1312 }
1313 cl->prev.i = msg;
1314 offset += (s + msg.size);
1315 if (cl->buf_size == offset)
1316 {
1317 free(cl->buf);
1318 cl->buf = NULL;
1319 cl->buf_size = 0;
1320 return ECORE_CALLBACK_CANCEL;
1321 }
1322 goto redo;
1323 }
1324 else goto scroll;
1325 }
1326 else
1327 {
1328 scroll:
1329 buf = malloc(cl->buf_size - offset);
1330 if (!buf)
1331 {
1332 free(cl->buf);
1333 cl->buf = NULL;
1334 cl->buf_size = 0;
1335 return ECORE_CALLBACK_CANCEL;
1336 }
1337 memcpy(buf, cl->buf + offset, cl->buf_size - offset);
1338 free(cl->buf);
1339 cl->buf = buf;
1340 cl->buf_size -= offset;
1341 }
1342 }
1343 return ECORE_CALLBACK_CANCEL;
1344}
1345
1346#define SVSZ(_n) \
1347 md = ((head >> (4 * _n)) & 0xf); \
1348 if (md >= DLT_SET) s += 4; \
1349 else if (md >= DLT_ADD16) s += 2; \
1350 else if (md >= DLT_ADD8) s += 1;
1351
1352#define SVDEC(_n, _member) \
1353 md = ((head >> (4 * _n)) & 0xf); \
1354 if (md >= DLT_SET) \
1355 { \
1356 unsigned int v; \
1357 unsigned char *dv; \
1358 dv = (unsigned char *)&v; \
1359 dv[0] = *(svr->buf + offset + s + 0); \
1360 dv[1] = *(svr->buf + offset + s + 1); \
1361 dv[2] = *(svr->buf + offset + s + 2); \
1362 dv[3] = *(svr->buf + offset + s + 3); \
1363 d = (int)ntohl(v); \
1364 s += 4; \
1365 } \
1366 else if (md >= DLT_ADD16) \
1367 { \
1368 unsigned short v; \
1369 unsigned char *dv; \
1370 dv = (unsigned char *)&v; \
1371 dv[0] = *(svr->buf + offset + s + 0); \
1372 dv[1] = *(svr->buf + offset + s + 1); \
1373 d = (int)ntohs(v); \
1374 s += 2; \
1375 } \
1376 else if (md >= DLT_ADD8) \
1377 { \
1378 unsigned char v; \
1379 unsigned char *dv; \
1380 dv = (unsigned char *)&v; \
1381 dv[0] = *(svr->buf + offset + s + 0); \
1382 d = (int)v; \
1383 s += 1; \
1384 } \
1385 msg._member = _ecore_ipc_ddlt_int(d, svr->prev.i._member, md);
1386
1387static Eina_Bool
1388_ecore_ipc_event_server_data(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1389{
1390 Ecore_Con_Event_Server_Data *e;
1391
1392 e = ev;
1393 if (!eina_list_data_find(servers, ecore_con_server_data_get(e->server))) return ECORE_CALLBACK_RENEW;
1394 /* handling code here */
1395 {
1396 Ecore_Ipc_Server *svr;
1397 Ecore_Ipc_Msg_Head msg;
1398 int offset = 0;
1399 unsigned char *buf;
1400
1401 svr = ecore_con_server_data_get(e->server);
1402
1403 if (!svr->buf)
1404 {
1405 svr->buf_size = e->size;
1406 svr->buf = e->data;
1407 e->data = NULL; /* take it out of the old event */
1408 }
1409 else
1410 {
1411 buf = realloc(svr->buf, svr->buf_size + e->size);
1412 if (!buf)
1413 {
1414 free(svr->buf);
1415 svr->buf = 0;
1416 svr->buf_size = 0;
1417 return ECORE_CALLBACK_CANCEL;
1418 }
1419 svr->buf = buf;
1420 memcpy(svr->buf + svr->buf_size, e->data, e->size);
1421 svr->buf_size += e->size;
1422 }
1423 /* examine header */
1424 redo:
1425 if ((svr->buf_size - offset) >= (int)sizeof(int))
1426 {
1427 int s, md, d = 0, head;
1428 unsigned char *dd;
1429
1430 dd = (unsigned char *)&head;
1431 dd[0] = *(svr->buf + offset + 0);
1432 dd[1] = *(svr->buf + offset + 1);
1433 dd[2] = *(svr->buf + offset + 2);
1434 dd[3] = *(svr->buf + offset + 3);
1435 head = ntohl(head);
1436 dd = (unsigned char *)&d;
1437 s = 4;
1438 SVSZ(0);
1439 SVSZ(1);
1440 SVSZ(2);
1441 SVSZ(3);
1442 SVSZ(4);
1443 SVSZ(5);
1444 if ((svr->buf_size - offset) < s)
1445 {
1446 if (offset > 0) goto scroll;
1447 return ECORE_CALLBACK_CANCEL;
1448 }
1449
1450 s = 4;
1451 SVDEC(0, major);
1452 SVDEC(1, minor);
1453 SVDEC(2, ref);
1454 SVDEC(3, ref_to);
1455 SVDEC(4, response);
1456 SVDEC(5, size);
1457 if (msg.size < 0) msg.size = 0;
1458 /* there is enough data in the buffer for a full message */
1459 if ((svr->buf_size - offset) >= (s + msg.size))
1460 {
1461 Ecore_Ipc_Event_Server_Data *e2;
1462 int max;
1463
1464 buf = NULL;
1465 max = svr->max_buf_size;
1466 if ((max < 0) || (msg.size <= max))
1467 {
1468 if (msg.size > 0)
1469 {
1470 buf = malloc(msg.size);
1471 if (!buf) return ECORE_CALLBACK_CANCEL;
1472 memcpy(buf, svr->buf + offset + s, msg.size);
1473 }
1474 if (!svr->delete_me)
1475 {
1476 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Server_Data));
1477 if (e2)
1478 {
1479 svr->event_count++;
1480 e2->server = svr;
1481 e2->major = msg.major;
1482 e2->minor = msg.minor;
1483 e2->ref = msg.ref;
1484 e2->ref_to = msg.ref_to;
1485 e2->response = msg.response;
1486 e2->size = msg.size;
1487 e2->data = buf;
1488 ecore_event_add(ECORE_IPC_EVENT_SERVER_DATA, e2,
1489 _ecore_ipc_event_server_data_free,
1490 NULL);
1491 }
1492 }
1493 }
1494 svr->prev.i = msg;
1495 offset += (s + msg.size);
1496 if (svr->buf_size == offset)
1497 {
1498 free(svr->buf);
1499 svr->buf = NULL;
1500 svr->buf_size = 0;
1501 return ECORE_CALLBACK_CANCEL;
1502 }
1503 goto redo;
1504 }
1505 else goto scroll;
1506 }
1507 else
1508 {
1509 scroll:
1510 buf = malloc(svr->buf_size - offset);
1511 if (!buf)
1512 {
1513 free(svr->buf);
1514 svr->buf = NULL;
1515 svr->buf_size = 0;
1516 return ECORE_CALLBACK_CANCEL;
1517 }
1518 memcpy(buf, svr->buf + offset, svr->buf_size - offset);
1519 free(svr->buf);
1520 svr->buf = buf;
1521 svr->buf_size -= offset;
1522 }
1523 }
1524 return ECORE_CALLBACK_CANCEL;
1525}
1526
1527static void
1528_ecore_ipc_event_client_add_free(void *data EINA_UNUSED, void *ev)
1529{
1530 Ecore_Ipc_Event_Client_Add *e;
1531
1532 e = ev;
1533 e->client->event_count--;
1534 if ((e->client->event_count == 0) && (e->client->delete_me))
1535 ecore_ipc_client_del(e->client);
1536 free(e);
1537}
1538
1539static void
1540_ecore_ipc_event_client_del_free(void *data EINA_UNUSED, void *ev)
1541{
1542 Ecore_Ipc_Event_Client_Del *e;
1543
1544 e = ev;
1545 e->client->event_count--;
1546 if ((e->client->event_count == 0) && (e->client->delete_me))
1547 ecore_ipc_client_del(e->client);
1548 free(e);
1549}
1550
1551static void
1552_ecore_ipc_event_client_data_free(void *data EINA_UNUSED, void *ev)
1553{
1554 Ecore_Ipc_Event_Client_Data *e;
1555
1556 e = ev;
1557 e->client->event_count--;
1558 if (e->data) free(e->data);
1559 if ((e->client->event_count == 0) && (e->client->delete_me))
1560 ecore_ipc_client_del(e->client);
1561 free(e);
1562}
1563
1564static void
1565_ecore_ipc_event_server_add_free(void *data EINA_UNUSED, void *ev)
1566{
1567 Ecore_Ipc_Event_Server_Add *e;
1568
1569 e = ev;
1570 e->server->event_count--;
1571 if ((e->server->event_count == 0) && (e->server->delete_me))
1572 ecore_ipc_server_del(e->server);
1573 free(e);
1574}
1575
1576static void
1577_ecore_ipc_event_server_del_free(void *data EINA_UNUSED, void *ev)
1578{
1579 Ecore_Ipc_Event_Server_Add *e;
1580
1581 e = ev;
1582 e->server->event_count--;
1583 if ((e->server->event_count == 0) && (e->server->delete_me))
1584 ecore_ipc_server_del(e->server);
1585 free(e);
1586}
1587
1588static void
1589_ecore_ipc_event_server_data_free(void *data EINA_UNUSED, void *ev)
1590{
1591 Ecore_Ipc_Event_Server_Data *e;
1592
1593 e = ev;
1594 if (e->data) free(e->data);
1595 e->server->event_count--;
1596 if ((e->server->event_count == 0) && (e->server->delete_me))
1597 ecore_ipc_server_del(e->server);
1598 free(e);
1599}
diff --git a/src/lib/ecore_ipc/ecore_ipc_private.h b/src/lib/ecore_ipc/ecore_ipc_private.h
new file mode 100644
index 0000000000..bedaab167c
--- /dev/null
+++ b/src/lib/ecore_ipc/ecore_ipc_private.h
@@ -0,0 +1,105 @@
1#ifndef _ECORE_IPC_PRIVATE_H
2#define _ECORE_IPC_PRIVATE_H
3
4
5extern int _ecore_ipc_log_dom;
6
7#ifdef ECORE_IPC_DEFAULT_LOG_COLOR
8# undef ECORE_IPC_DEFAULT_LOG_COLOR
9#endif
10#define ECORE_IPC_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
11
12#ifdef ERR
13# undef ERR
14#endif
15#define ERR(...) EINA_LOG_DOM_ERR(_ecore_ipc_log_dom, __VA_ARGS__)
16
17#ifdef DBG
18# undef DBG
19#endif
20#define DBG(...) EINA_LOG_DOM_DBG(_ecore_ipc_log_dom, __VA_ARGS__)
21
22#ifdef INF
23# undef INF
24#endif
25#define INF(...) EINA_LOG_DOM_INFO(_ecore_ipc_log_dom, __VA_ARGS__)
26
27#ifdef WRN
28# undef WRN
29#endif
30#define WRN(...) EINA_LOG_DOM_WARN(_ecore_ipc_log_dom, __VA_ARGS__)
31
32#ifdef CRIT
33# undef CRIT
34#endif
35#define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_ipc_log_dom, __VA_ARGS__)
36
37#define ECORE_MAGIC_IPC_SERVER 0x87786556
38#define ECORE_MAGIC_IPC_CLIENT 0x78875665
39
40typedef struct _Ecore_Ipc_Msg_Head Ecore_Ipc_Msg_Head;
41#define ECORE_IPC_TYPE 0x0f
42#define ECORE_IPC_SSL 0xf0
43
44#if defined (_MSC_VER) || (defined (__SUNPRO_C) && __SUNPRO_C < 0x5100)
45# pragma pack(1)
46# define ECORE_IPC_STRUCT_PACKED
47#elif defined (__GNUC__) || (defined (__SUNPRO_C) && __SUNPRO_C >= 0x5100)
48# define ECORE_IPC_STRUCT_PACKED __attribute__((packed))
49#else
50# define ECORE_IPC_STRUCT_PACKED
51#endif
52
53#ifdef __sgi
54#pragma pack 4
55#endif
56struct _Ecore_Ipc_Msg_Head
57{
58 int major;
59 int minor;
60 int ref;
61 int ref_to;
62 int response;
63 int size;
64} ECORE_IPC_STRUCT_PACKED;
65#ifdef __sgi
66#pragma pack 0
67#endif
68
69struct _Ecore_Ipc_Client
70{
71 ECORE_MAGIC;
72 Ecore_Con_Client *client;
73 Ecore_Ipc_Server *svr;
74 void *data;
75 unsigned char *buf;
76 int buf_size;
77 int max_buf_size;
78
79 struct {
80 Ecore_Ipc_Msg_Head i, o;
81 } prev;
82
83 int event_count;
84 char delete_me : 1;
85};
86
87struct _Ecore_Ipc_Server
88{
89 ECORE_MAGIC;
90 Ecore_Con_Server *server;
91 Eina_List *clients;
92 void *data;
93 unsigned char *buf;
94 int buf_size;
95 int max_buf_size;
96
97 struct {
98 Ecore_Ipc_Msg_Head i, o;
99 } prev;
100
101 int event_count;
102 char delete_me : 1;
103};
104
105#endif