diff options
Diffstat (limited to 'libraries/ecore/src/lib/ecore_con/ecore_con_private.h')
-rw-r--r-- | libraries/ecore/src/lib/ecore_con/ecore_con_private.h | 321 |
1 files changed, 321 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_con/ecore_con_private.h b/libraries/ecore/src/lib/ecore_con/ecore_con_private.h new file mode 100644 index 0000000..f601465 --- /dev/null +++ b/libraries/ecore/src/lib/ecore_con/ecore_con_private.h | |||
@@ -0,0 +1,321 @@ | |||
1 | #ifndef _ECORE_CON_PRIVATE_H | ||
2 | #define _ECORE_CON_PRIVATE_H | ||
3 | |||
4 | #include "ecore_private.h" | ||
5 | #include "Ecore_Con.h" | ||
6 | |||
7 | #define ECORE_MAGIC_CON_SERVER 0x77665544 | ||
8 | #define ECORE_MAGIC_CON_CLIENT 0x77556677 | ||
9 | #define ECORE_MAGIC_CON_URL 0x77074255 | ||
10 | |||
11 | #define ECORE_CON_TYPE 0x0f | ||
12 | #define ECORE_CON_SSL 0xf0 | ||
13 | |||
14 | #if USE_GNUTLS | ||
15 | # include <gnutls/gnutls.h> | ||
16 | #elif USE_OPENSSL | ||
17 | # include <openssl/ssl.h> | ||
18 | #endif | ||
19 | #ifdef HAVE_CURL | ||
20 | #include <curl/curl.h> | ||
21 | #endif | ||
22 | |||
23 | #define READBUFSIZ 65536 | ||
24 | |||
25 | extern int _ecore_con_log_dom; | ||
26 | |||
27 | #ifdef ECORE_CON_DEFAULT_LOG_COLOR | ||
28 | #undef ECORE_LOG_DEFAULT_LOG_COLOR | ||
29 | #endif | ||
30 | #define ECORE_CON_DEFAULT_LOG_COLOR EINA_COLOR_BLUE | ||
31 | |||
32 | #ifdef ERR | ||
33 | # undef ERR | ||
34 | #endif | ||
35 | #define ERR(...) EINA_LOG_DOM_ERR(_ecore_con_log_dom, __VA_ARGS__) | ||
36 | |||
37 | #ifdef DBG | ||
38 | # undef DBG | ||
39 | #endif | ||
40 | #define DBG(...) EINA_LOG_DOM_DBG(_ecore_con_log_dom, __VA_ARGS__) | ||
41 | |||
42 | #ifdef INF | ||
43 | # undef INF | ||
44 | #endif | ||
45 | #define INF(...) EINA_LOG_DOM_INFO(_ecore_con_log_dom, __VA_ARGS__) | ||
46 | |||
47 | #ifdef WRN | ||
48 | # undef WRN | ||
49 | #endif | ||
50 | #define WRN(...) EINA_LOG_DOM_WARN(_ecore_con_log_dom, __VA_ARGS__) | ||
51 | |||
52 | #ifdef CRIT | ||
53 | # undef CRIT | ||
54 | #endif | ||
55 | #define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_con_log_dom, __VA_ARGS__) | ||
56 | |||
57 | typedef struct _Ecore_Con_Lookup Ecore_Con_Lookup; | ||
58 | typedef struct _Ecore_Con_Info Ecore_Con_Info; | ||
59 | |||
60 | typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos); | ||
61 | |||
62 | typedef enum _Ecore_Con_State | ||
63 | { | ||
64 | ECORE_CON_CONNECTED, | ||
65 | ECORE_CON_DISCONNECTED, | ||
66 | ECORE_CON_INPROGRESS | ||
67 | } Ecore_Con_State; | ||
68 | |||
69 | typedef enum _Ecore_Con_Ssl_Error | ||
70 | { | ||
71 | ECORE_CON_SSL_ERROR_NONE = 0, | ||
72 | ECORE_CON_SSL_ERROR_NOT_SUPPORTED, | ||
73 | ECORE_CON_SSL_ERROR_INIT_FAILED, | ||
74 | ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED, | ||
75 | ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED | ||
76 | } Ecore_Con_Ssl_Error; | ||
77 | |||
78 | typedef enum _Ecore_Con_Ssl_Handshake | ||
79 | { | ||
80 | ECORE_CON_SSL_STATE_DONE = 0, | ||
81 | ECORE_CON_SSL_STATE_HANDSHAKING, | ||
82 | ECORE_CON_SSL_STATE_INIT | ||
83 | } Ecore_Con_Ssl_State; | ||
84 | |||
85 | struct _Ecore_Con_Client | ||
86 | { | ||
87 | ECORE_MAGIC; | ||
88 | int fd; | ||
89 | Ecore_Con_Server *host_server; | ||
90 | void *data; | ||
91 | Ecore_Fd_Handler *fd_handler; | ||
92 | unsigned int buf_offset; | ||
93 | Eina_Binbuf *buf; | ||
94 | const char *ip; | ||
95 | Eina_List *event_count; | ||
96 | struct sockaddr *client_addr; | ||
97 | int client_addr_len; | ||
98 | double start_time; | ||
99 | Ecore_Timer *until_deletion; | ||
100 | double disconnect_time; | ||
101 | #if USE_GNUTLS | ||
102 | gnutls_datum_t session_ticket; | ||
103 | gnutls_session_t session; | ||
104 | #elif USE_OPENSSL | ||
105 | SSL *ssl; | ||
106 | int ssl_err; | ||
107 | #endif | ||
108 | Ecore_Con_Ssl_State ssl_state; | ||
109 | Eina_Bool handshaking : 1; | ||
110 | Eina_Bool upgrade : 1; | ||
111 | Eina_Bool dead : 1; | ||
112 | Eina_Bool delete_me : 1; | ||
113 | }; | ||
114 | |||
115 | struct _Ecore_Con_Server | ||
116 | { | ||
117 | ECORE_MAGIC; | ||
118 | int fd; | ||
119 | Ecore_Con_Type type; | ||
120 | char *name; | ||
121 | int port; | ||
122 | char *path; | ||
123 | void *data; | ||
124 | Ecore_Fd_Handler *fd_handler; | ||
125 | Eina_List *clients; | ||
126 | unsigned int client_count; | ||
127 | Eina_Binbuf *buf; | ||
128 | unsigned int write_buf_offset; | ||
129 | Eina_List *infos; | ||
130 | Eina_List *event_count; | ||
131 | int client_limit; | ||
132 | pid_t ppid; | ||
133 | #if USE_GNUTLS | ||
134 | gnutls_session_t session; | ||
135 | gnutls_anon_client_credentials_t anoncred_c; | ||
136 | gnutls_anon_server_credentials_t anoncred_s; | ||
137 | gnutls_psk_client_credentials_t pskcred_c; | ||
138 | gnutls_psk_server_credentials_t pskcred_s; | ||
139 | gnutls_certificate_credentials_t cert; | ||
140 | char *cert_file; | ||
141 | gnutls_dh_params_t dh_params; | ||
142 | #elif USE_OPENSSL | ||
143 | SSL_CTX *ssl_ctx; | ||
144 | SSL *ssl; | ||
145 | int ssl_err; | ||
146 | #endif | ||
147 | double start_time; | ||
148 | Ecore_Timer *until_deletion; | ||
149 | double disconnect_time; | ||
150 | double client_disconnect_time; | ||
151 | const char *ip; | ||
152 | Eina_Bool dead : 1; | ||
153 | Eina_Bool created : 1; /* EINA_TRUE if server is our listening server */ | ||
154 | Eina_Bool connecting : 1; /* EINA_FALSE if just initialized or connected */ | ||
155 | Eina_Bool handshaking : 1; /* EINA_TRUE if server is ssl handshaking */ | ||
156 | Eina_Bool upgrade : 1; | ||
157 | Eina_Bool ssl_prepared : 1; | ||
158 | Eina_Bool use_cert : 1; /* EINA_TRUE if using certificate auth */ | ||
159 | Ecore_Con_Ssl_State ssl_state; /* current state of ssl handshake on the server */ | ||
160 | Eina_Bool verify : 1; /* EINA_TRUE if certificates will be verified */ | ||
161 | Eina_Bool verify_basic : 1; /* EINA_TRUE if certificates will be verified only against the hostname */ | ||
162 | Eina_Bool reject_excess_clients : 1; | ||
163 | Eina_Bool delete_me : 1; | ||
164 | #ifdef _WIN32 | ||
165 | Eina_Bool want_write : 1; | ||
166 | Eina_Bool read_stop : 1; | ||
167 | Eina_Bool read_stopped : 1; | ||
168 | HANDLE pipe; | ||
169 | HANDLE thread_read; | ||
170 | HANDLE event_read; | ||
171 | HANDLE event_peek; | ||
172 | DWORD nbr_bytes; | ||
173 | #endif | ||
174 | }; | ||
175 | |||
176 | #ifdef HAVE_CURL | ||
177 | struct _Ecore_Con_Url | ||
178 | { | ||
179 | ECORE_MAGIC; | ||
180 | CURL *curl_easy; | ||
181 | struct curl_slist *headers; | ||
182 | Eina_List *additional_headers; | ||
183 | Eina_List *response_headers; | ||
184 | const char *url; | ||
185 | |||
186 | Ecore_Con_Url_Time time_condition; | ||
187 | double timestamp; | ||
188 | void *data; | ||
189 | |||
190 | Ecore_Fd_Handler *fd_handler; | ||
191 | int fd; | ||
192 | int flags; | ||
193 | |||
194 | int received; | ||
195 | int write_fd; | ||
196 | |||
197 | Eina_Bool active : 1; | ||
198 | }; | ||
199 | #endif | ||
200 | |||
201 | struct _Ecore_Con_Info | ||
202 | { | ||
203 | unsigned int size; | ||
204 | struct addrinfo info; | ||
205 | char ip[NI_MAXHOST]; | ||
206 | char service[NI_MAXSERV]; | ||
207 | }; | ||
208 | |||
209 | struct _Ecore_Con_Lookup | ||
210 | { | ||
211 | Ecore_Con_Dns_Cb done_cb; | ||
212 | const void *data; | ||
213 | }; | ||
214 | |||
215 | /* from ecore_con.c */ | ||
216 | void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info); | ||
217 | void ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate); | ||
218 | void ecore_con_event_server_del(Ecore_Con_Server *svr); | ||
219 | void ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error); | ||
220 | void ecore_con_event_client_add(Ecore_Con_Client *cl); | ||
221 | void ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate); | ||
222 | void ecore_con_event_client_del(Ecore_Con_Client *cl); | ||
223 | void ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error); | ||
224 | |||
225 | /* from ecore_local_win32.c */ | ||
226 | #ifdef _WIN32 | ||
227 | Eina_Bool ecore_con_local_listen(Ecore_Con_Server *svr); | ||
228 | Eina_Bool ecore_con_local_connect(Ecore_Con_Server *svr, | ||
229 | Eina_Bool (*cb_done)(void *data, | ||
230 | Ecore_Fd_Handler *fd_handler)); | ||
231 | Eina_Bool ecore_con_local_win32_server_flush(Ecore_Con_Server *svr); | ||
232 | Eina_Bool ecore_con_local_win32_client_flush(Ecore_Con_Client *cl); | ||
233 | void ecore_con_local_win32_server_del(Ecore_Con_Server *svr); | ||
234 | void ecore_con_local_win32_client_del(Ecore_Con_Client *cl); | ||
235 | #else | ||
236 | /* from ecore_local.c */ | ||
237 | int ecore_con_local_init(void); | ||
238 | int ecore_con_local_shutdown(void); | ||
239 | int ecore_con_local_connect(Ecore_Con_Server *svr, | ||
240 | Eina_Bool (*cb_done)( | ||
241 | void *data, | ||
242 | Ecore_Fd_Handler *fd_handler), | ||
243 | void *data); | ||
244 | int ecore_con_local_listen(Ecore_Con_Server *svr, | ||
245 | Eina_Bool (*cb_listen)( | ||
246 | void *data, | ||
247 | Ecore_Fd_Handler *fd_handler), | ||
248 | void *data); | ||
249 | #endif | ||
250 | |||
251 | /* from ecore_con_info.c */ | ||
252 | int ecore_con_info_init(void); | ||
253 | int ecore_con_info_shutdown(void); | ||
254 | int ecore_con_info_tcp_connect(Ecore_Con_Server *svr, | ||
255 | Ecore_Con_Info_Cb done_cb, | ||
256 | void *data); | ||
257 | int ecore_con_info_tcp_listen(Ecore_Con_Server *svr, | ||
258 | Ecore_Con_Info_Cb done_cb, | ||
259 | void *data); | ||
260 | int ecore_con_info_udp_connect(Ecore_Con_Server *svr, | ||
261 | Ecore_Con_Info_Cb done_cb, | ||
262 | void *data); | ||
263 | int ecore_con_info_udp_listen(Ecore_Con_Server *svr, | ||
264 | Ecore_Con_Info_Cb done_cb, | ||
265 | void *data); | ||
266 | int ecore_con_info_mcast_listen(Ecore_Con_Server *svr, | ||
267 | Ecore_Con_Info_Cb done_cb, | ||
268 | void *data); | ||
269 | void ecore_con_info_data_clear(void *info); | ||
270 | |||
271 | void ecore_con_event_server_add(Ecore_Con_Server *svr); | ||
272 | |||
273 | |||
274 | /* from ecore_con_ssl.c */ | ||
275 | Ecore_Con_Ssl_Error ecore_con_ssl_init(void); | ||
276 | Ecore_Con_Ssl_Error ecore_con_ssl_shutdown(void); | ||
277 | Ecore_Con_Ssl_Error ecore_con_ssl_server_prepare(Ecore_Con_Server *svr, int ssl_type); | ||
278 | Ecore_Con_Ssl_Error ecore_con_ssl_server_init(Ecore_Con_Server *svr); | ||
279 | Ecore_Con_Ssl_Error ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr); | ||
280 | int ecore_con_ssl_server_read(Ecore_Con_Server *svr, | ||
281 | unsigned char *buf, | ||
282 | int size); | ||
283 | int ecore_con_ssl_server_write(Ecore_Con_Server *svr, | ||
284 | const unsigned char *buf, | ||
285 | int size); | ||
286 | Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr); | ||
287 | Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr); | ||
288 | int ecore_con_ssl_client_read(Ecore_Con_Client *svr, | ||
289 | unsigned char *buf, | ||
290 | int size); | ||
291 | int ecore_con_ssl_client_write(Ecore_Con_Client *svr, | ||
292 | const unsigned char *buf, | ||
293 | int size); | ||
294 | |||
295 | int ecore_con_info_get(Ecore_Con_Server *svr, | ||
296 | Ecore_Con_Info_Cb done_cb, | ||
297 | void *data, | ||
298 | struct addrinfo *hints); | ||
299 | |||
300 | |||
301 | #define GENERIC_ALLOC_FREE_HEADER(TYPE, Type) \ | ||
302 | TYPE *Type##_alloc(void); \ | ||
303 | void Type##_free(TYPE *e); | ||
304 | |||
305 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Add, ecore_con_event_client_add); | ||
306 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Del, ecore_con_event_client_del); | ||
307 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Write, ecore_con_event_client_write); | ||
308 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Data, ecore_con_event_client_data); | ||
309 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Error, ecore_con_event_server_error); | ||
310 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Error, ecore_con_event_client_error); | ||
311 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Add, ecore_con_event_server_add); | ||
312 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Del, ecore_con_event_server_del); | ||
313 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Write, ecore_con_event_server_write); | ||
314 | GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Data, ecore_con_event_server_data); | ||
315 | |||
316 | void ecore_con_mempool_init(void); | ||
317 | void ecore_con_mempool_shutdown(void); | ||
318 | |||
319 | #undef GENERIC_ALLOC_FREE_HEADER | ||
320 | |||
321 | #endif | ||