057434152cc49e766edd68f02d56c8233c6a2663
[profile/ivi/ecore.git] / src / lib / ecore_con / ecore_con_private.h
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    int buf_size;
93    int buf_offset;
94    unsigned char *buf;
95    const char *ip;
96    int event_count;
97    struct sockaddr *client_addr;
98    int client_addr_len;
99    double start_time;
100    Ecore_Timer *until_deletion;
101    double disconnect_time;
102 #if USE_GNUTLS
103    gnutls_datum_t session_ticket;
104    gnutls_session_t session;
105 #elif USE_OPENSSL
106    SSL *ssl;
107    int ssl_err;
108 #endif
109    Eina_Bool handshaking : 1;
110    Ecore_Con_Ssl_State ssl_state;
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    int write_buf_size;
128    int write_buf_offset;
129    unsigned char *write_buf;
130    Eina_List *infos;
131    int event_count;
132    int client_limit;
133    pid_t ppid;
134 #if USE_GNUTLS
135    gnutls_session_t session;
136    gnutls_anon_client_credentials_t anoncred_c;
137    gnutls_anon_server_credentials_t anoncred_s;
138    gnutls_psk_client_credentials_t pskcred_c;
139    gnutls_psk_server_credentials_t pskcred_s;
140    gnutls_certificate_credentials_t cert;
141    char *cert_file;
142    gnutls_dh_params_t dh_params;
143 #elif USE_OPENSSL
144    SSL_CTX *ssl_ctx;
145    SSL *ssl;
146    int ssl_err;
147 #endif
148    double start_time;
149    double client_disconnect_time;
150    const char *ip;
151    Eina_Bool dead : 1;
152    Eina_Bool created : 1; /* EINA_TRUE if server is our listening server */
153    Eina_Bool connecting : 1; /* EINA_FALSE if just initialized or connected */
154    Eina_Bool handshaking : 1; /* EINA_TRUE if server is ssl handshaking */
155    Eina_Bool use_cert : 1; /* EINA_TRUE if using certificate auth */
156    Ecore_Con_Ssl_State ssl_state; /* current state of ssl handshake on the server */
157    Eina_Bool verify : 1; /* EINA_TRUE if certificates will be verified */
158    Eina_Bool reject_excess_clients : 1;
159    Eina_Bool delete_me : 1;
160 };
161
162 #ifdef HAVE_CURL
163 struct _Ecore_Con_Url
164 {
165    ECORE_MAGIC;
166    CURL *curl_easy;
167    struct curl_slist *headers;
168    Eina_List *additional_headers;
169    Eina_List *response_headers;
170    char *url;
171
172    Ecore_Con_Url_Time time_condition;
173    double timestamp;
174    void *data;
175
176    Ecore_Fd_Handler *fd_handler;
177    int fd;
178    int flags;
179
180    int received;
181    int write_fd;
182
183    Eina_Bool active : 1;
184 };
185 #endif
186
187 struct _Ecore_Con_Info
188 {
189    unsigned int size;
190    struct addrinfo info;
191    char ip[NI_MAXHOST];
192    char service[NI_MAXSERV];
193 };
194
195 struct _Ecore_Con_Lookup
196 {
197    Ecore_Con_Dns_Cb done_cb;
198    const void *data;
199 };
200
201 /* from ecore_con.c */
202 void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info);
203 void ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error);
204 void ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error);
205
206 /* from ecore_local.c */
207 int ecore_con_local_init(void);
208 int ecore_con_local_shutdown(void);
209 int ecore_con_local_connect(Ecore_Con_Server *svr,
210                             Eina_Bool (*cb_done)(
211                                void *data,
212                                Ecore_Fd_Handler *fd_handler),
213                             void *data,
214                             void (*cb_free)(
215                                void *data, void *ev));
216 int ecore_con_local_listen(Ecore_Con_Server *svr,
217                            Eina_Bool (*cb_listen)(
218                               void *data,
219                               Ecore_Fd_Handler *fd_handler),
220                            void *data);
221 /* from ecore_con_info.c */
222 int                 ecore_con_info_init(void);
223 int                 ecore_con_info_shutdown(void);
224 int                 ecore_con_info_tcp_connect(Ecore_Con_Server *svr,
225                                                Ecore_Con_Info_Cb done_cb,
226                                                void *data);
227 int                 ecore_con_info_tcp_listen(Ecore_Con_Server *svr,
228                                               Ecore_Con_Info_Cb done_cb,
229                                               void *data);
230 int                 ecore_con_info_udp_connect(Ecore_Con_Server *svr,
231                                                Ecore_Con_Info_Cb done_cb,
232                                                void *data);
233 int                 ecore_con_info_udp_listen(Ecore_Con_Server *svr,
234                                               Ecore_Con_Info_Cb done_cb,
235                                               void *data);
236 int                 ecore_con_info_mcast_listen(Ecore_Con_Server *svr,
237                                                 Ecore_Con_Info_Cb done_cb,
238                                                 void *data);
239 void                ecore_con_info_data_clear(void *info);
240
241 /* from ecore_con_ssl.c */
242 Ecore_Con_Ssl_Error ecore_con_ssl_init(void);
243 Ecore_Con_Ssl_Error ecore_con_ssl_shutdown(void);
244 Ecore_Con_Ssl_Error ecore_con_ssl_server_prepare(Ecore_Con_Server *svr, int ssl_type);
245 Ecore_Con_Ssl_Error ecore_con_ssl_server_init(Ecore_Con_Server *svr);
246 Ecore_Con_Ssl_Error ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr);
247 int                 ecore_con_ssl_server_read(Ecore_Con_Server *svr,
248                                               unsigned char *buf,
249                                               int size);
250 int                 ecore_con_ssl_server_write(Ecore_Con_Server *svr,
251                                                unsigned char *buf,
252                                                int size);
253 Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr);
254 Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr);
255 int                 ecore_con_ssl_client_read(Ecore_Con_Client *svr,
256                                               unsigned char *buf,
257                                               int size);
258 int                 ecore_con_ssl_client_write(Ecore_Con_Client *svr,
259                                                unsigned char *buf,
260                                                int size);
261
262 int                 ecore_con_info_get(Ecore_Con_Server *svr,
263                                        Ecore_Con_Info_Cb done_cb,
264                                        void *data,
265                                        struct addrinfo *hints);
266
267
268
269 #endif