[ecore] merged svn latest code (svn54830)
[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    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    int 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    double client_disconnect_time;
149    char *ip;
150    Eina_Bool dead : 1;
151    Eina_Bool created : 1; /* EINA_TRUE if server is our listening server */
152    Eina_Bool connecting : 1; /* EINA_FALSE if just initialized or connected */
153    Eina_Bool handshaking : 1; /* EINA_TRUE if server is ssl handshaking */
154    Eina_Bool use_cert : 1; /* EINA_TRUE if using certificate auth */
155    Ecore_Con_Ssl_State ssl_state; /* current state of ssl handshake on the server */
156    Eina_Bool verify : 1; /* EINA_TRUE if certificates will be verified */
157    Eina_Bool reject_excess_clients : 1;
158    Eina_Bool delete_me : 1;
159 };
160
161 #ifdef HAVE_CURL
162 struct _Ecore_Con_Url
163 {
164    ECORE_MAGIC;
165    CURL *curl_easy;
166    struct curl_slist *headers;
167    Eina_List *additional_headers;
168    Eina_List *response_headers;
169    char *url;
170
171    Ecore_Con_Url_Time time_condition;
172    double timestamp;
173    void *data;
174
175    Ecore_Fd_Handler *fd_handler;
176    int fd;
177    int flags;
178
179    int received;
180    int write_fd;
181
182    Eina_Bool active : 1;
183 };
184 #endif
185
186 struct _Ecore_Con_Info
187 {
188    unsigned int size;
189    struct addrinfo info;
190    char ip[NI_MAXHOST];
191    char service[NI_MAXSERV];
192 };
193
194 struct _Ecore_Con_Lookup
195 {
196    Ecore_Con_Dns_Cb done_cb;
197    const void *data;
198 };
199
200 /* from ecore_local.c */
201 int ecore_con_local_init(void);
202 int ecore_con_local_shutdown(void);
203 int ecore_con_local_connect(Ecore_Con_Server *svr,
204                             Eina_Bool (*cb_done)(
205                                void *data,
206                                Ecore_Fd_Handler *fd_handler),
207                             void *data,
208                             void (*cb_free)(
209                                void *data, void *ev));
210 int ecore_con_local_listen(Ecore_Con_Server *svr,
211                            Eina_Bool (*cb_listen)(
212                               void *data,
213                               Ecore_Fd_Handler *fd_handler),
214                            void *data);
215 /* from ecore_con_info.c */
216 int                 ecore_con_info_init(void);
217 int                 ecore_con_info_shutdown(void);
218 int                 ecore_con_info_tcp_connect(Ecore_Con_Server *svr,
219                                                Ecore_Con_Info_Cb done_cb,
220                                                void *data);
221 int                 ecore_con_info_tcp_listen(Ecore_Con_Server *svr,
222                                               Ecore_Con_Info_Cb done_cb,
223                                               void *data);
224 int                 ecore_con_info_udp_connect(Ecore_Con_Server *svr,
225                                                Ecore_Con_Info_Cb done_cb,
226                                                void *data);
227 int                 ecore_con_info_udp_listen(Ecore_Con_Server *svr,
228                                               Ecore_Con_Info_Cb done_cb,
229                                               void *data);
230 int                 ecore_con_info_mcast_listen(Ecore_Con_Server *svr,
231                                                 Ecore_Con_Info_Cb done_cb,
232                                                 void *data);
233 /* from ecore_con_ssl.c */
234 Ecore_Con_Ssl_Error ecore_con_ssl_init(void);
235 Ecore_Con_Ssl_Error ecore_con_ssl_shutdown(void);
236 Ecore_Con_Ssl_Error ecore_con_ssl_server_prepare(Ecore_Con_Server *svr, int ssl_type);
237 Ecore_Con_Ssl_Error ecore_con_ssl_server_init(Ecore_Con_Server *svr);
238 Ecore_Con_Ssl_Error ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr);
239 int                 ecore_con_ssl_server_read(Ecore_Con_Server *svr,
240                                               unsigned char *buf,
241                                               int size);
242 int                 ecore_con_ssl_server_write(Ecore_Con_Server *svr,
243                                                unsigned char *buf,
244                                                int size);
245 Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr);
246 Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr);
247 int                 ecore_con_ssl_client_read(Ecore_Con_Client *svr,
248                                               unsigned char *buf,
249                                               int size);
250 int                 ecore_con_ssl_client_write(Ecore_Con_Client *svr,
251                                                unsigned char *buf,
252                                                int size);
253
254 int                 ecore_con_info_get(Ecore_Con_Server *svr,
255                                        Ecore_Con_Info_Cb done_cb,
256                                        void *data,
257                                        struct addrinfo *hints);
258
259
260
261 #endif