2003-09-23 01:09:32 -07:00
|
|
|
#ifndef _ECORE_CON_PRIVATE_H
|
|
|
|
#define _ECORE_CON_PRIVATE_H
|
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
#include "ecore_private.h"
|
2006-11-05 08:49:55 -08:00
|
|
|
#include "Ecore_Con.h"
|
2005-09-05 03:17:08 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
#define ECORE_MAGIC_CON_SERVER 0x77665544
|
|
|
|
#define ECORE_MAGIC_CON_CLIENT 0x77556677
|
2007-09-26 09:01:04 -07:00
|
|
|
#define ECORE_MAGIC_CON_URL 0x77074255
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2008-01-08 13:06:43 -08:00
|
|
|
#define ECORE_CON_TYPE 0x0f
|
2012-06-04 02:16:19 -07:00
|
|
|
#define ECORE_CON_SSL 0xf0
|
|
|
|
#define ECORE_CON_SUPER_SSL 0xf00
|
2008-01-08 13:06:43 -08:00
|
|
|
|
2012-12-05 16:11:14 -08:00
|
|
|
#if HAVE_GNUTLS
|
2008-10-30 08:26:11 -07:00
|
|
|
# include <gnutls/gnutls.h>
|
2012-12-05 16:11:14 -08:00
|
|
|
#elif HAVE_OPENSSL
|
2008-10-30 08:26:11 -07:00
|
|
|
# include <openssl/ssl.h>
|
2004-03-31 08:47:45 -08:00
|
|
|
#endif
|
|
|
|
|
2004-04-03 07:03:33 -08:00
|
|
|
#define READBUFSIZ 65536
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
extern int _ecore_con_log_dom;
|
2010-01-06 16:30:05 -08:00
|
|
|
|
|
|
|
#ifdef ECORE_CON_DEFAULT_LOG_COLOR
|
|
|
|
#undef ECORE_LOG_DEFAULT_LOG_COLOR
|
|
|
|
#endif
|
|
|
|
#define ECORE_CON_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
|
|
|
|
|
2009-12-21 09:32:19 -08:00
|
|
|
#ifdef ERR
|
|
|
|
# undef ERR
|
|
|
|
#endif
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_ecore_con_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
# undef DBG
|
|
|
|
#endif
|
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_ecore_con_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef INF
|
|
|
|
# undef INF
|
|
|
|
#endif
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_ecore_con_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef WRN
|
|
|
|
# undef WRN
|
|
|
|
#endif
|
|
|
|
#define WRN(...) EINA_LOG_DOM_WARN(_ecore_con_log_dom, __VA_ARGS__)
|
|
|
|
|
2013-12-25 19:22:05 -08:00
|
|
|
#ifdef CRI
|
|
|
|
# undef CRI
|
2009-12-21 09:32:19 -08:00
|
|
|
#endif
|
2013-12-25 19:22:05 -08:00
|
|
|
#define CRI(...) EINA_LOG_DOM_CRIT(_ecore_con_log_dom, __VA_ARGS__)
|
2009-12-21 09:32:19 -08:00
|
|
|
|
2010-07-22 04:32:55 -07:00
|
|
|
typedef struct _Ecore_Con_Lookup Ecore_Con_Lookup;
|
|
|
|
typedef struct _Ecore_Con_Info Ecore_Con_Info;
|
2012-02-14 21:53:50 -08:00
|
|
|
typedef struct Ecore_Con_Socks Ecore_Con_Socks_v4;
|
2011-12-05 19:32:16 -08:00
|
|
|
typedef struct Ecore_Con_Socks_v5 Ecore_Con_Socks_v5;
|
2010-07-22 04:32:55 -07:00
|
|
|
typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos);
|
|
|
|
|
2008-10-01 08:27:52 -07:00
|
|
|
typedef enum _Ecore_Con_State
|
2010-07-26 23:30:27 -07:00
|
|
|
{
|
|
|
|
ECORE_CON_CONNECTED,
|
|
|
|
ECORE_CON_DISCONNECTED,
|
|
|
|
ECORE_CON_INPROGRESS
|
|
|
|
} Ecore_Con_State;
|
2008-10-01 08:27:52 -07:00
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
typedef enum _Ecore_Con_Ssl_Error
|
2010-07-26 23:30:27 -07:00
|
|
|
{
|
|
|
|
ECORE_CON_SSL_ERROR_NONE = 0,
|
|
|
|
ECORE_CON_SSL_ERROR_NOT_SUPPORTED,
|
|
|
|
ECORE_CON_SSL_ERROR_INIT_FAILED,
|
|
|
|
ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED,
|
2015-11-02 14:11:09 -08:00
|
|
|
ECORE_CON_SSL_ERROR_SSL2_NOT_SUPPORTED,
|
|
|
|
ECORE_CON_SSL_ERROR_SSL3_NOT_SUPPORTED
|
2010-07-26 23:30:27 -07:00
|
|
|
} Ecore_Con_Ssl_Error;
|
2008-10-30 08:26:11 -07:00
|
|
|
|
2010-09-23 21:15:42 -07:00
|
|
|
typedef enum _Ecore_Con_Ssl_Handshake
|
|
|
|
{
|
|
|
|
ECORE_CON_SSL_STATE_DONE = 0,
|
|
|
|
ECORE_CON_SSL_STATE_HANDSHAKING,
|
|
|
|
ECORE_CON_SSL_STATE_INIT
|
|
|
|
} Ecore_Con_Ssl_State;
|
|
|
|
|
2012-02-14 21:53:50 -08:00
|
|
|
typedef enum Ecore_Con_Proxy_State
|
|
|
|
{ /* named PROXY instead of SOCKS in case some handsome and enterprising
|
|
|
|
* developer decides to add HTTP CONNECT support
|
|
|
|
*/
|
|
|
|
ECORE_CON_PROXY_STATE_DONE = 0,
|
|
|
|
ECORE_CON_PROXY_STATE_RESOLVED,
|
|
|
|
ECORE_CON_PROXY_STATE_INIT,
|
|
|
|
ECORE_CON_PROXY_STATE_READ,
|
|
|
|
ECORE_CON_PROXY_STATE_AUTH,
|
|
|
|
ECORE_CON_PROXY_STATE_REQUEST,
|
|
|
|
ECORE_CON_PROXY_STATE_CONFIRM,
|
|
|
|
} Ecore_Con_Proxy_State;
|
2011-12-05 19:32:16 -08:00
|
|
|
|
2016-02-12 12:02:01 -08:00
|
|
|
struct _Efl_Network_Client_Data
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2015-01-30 02:03:00 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
SOCKET fd;
|
|
|
|
#else
|
2010-07-26 23:30:27 -07:00
|
|
|
int fd;
|
2015-01-30 02:03:00 -08:00
|
|
|
#endif
|
2010-09-18 12:26:05 -07:00
|
|
|
Ecore_Con_Server *host_server;
|
2010-07-26 23:30:27 -07:00
|
|
|
void *data;
|
2003-09-23 01:09:32 -07:00
|
|
|
Ecore_Fd_Handler *fd_handler;
|
2014-04-04 03:35:16 -07:00
|
|
|
size_t buf_offset;
|
2011-07-16 06:07:39 -07:00
|
|
|
Eina_Binbuf *buf;
|
2010-11-16 13:32:50 -08:00
|
|
|
const char *ip;
|
2011-11-10 18:44:16 -08:00
|
|
|
Eina_List *event_count;
|
2010-07-26 23:30:27 -07:00
|
|
|
struct sockaddr *client_addr;
|
|
|
|
int client_addr_len;
|
2010-09-21 21:48:09 -07:00
|
|
|
double start_time;
|
|
|
|
Ecore_Timer *until_deletion;
|
|
|
|
double disconnect_time;
|
2012-12-05 16:11:14 -08:00
|
|
|
#if HAVE_GNUTLS
|
2010-09-23 23:54:49 -07:00
|
|
|
gnutls_datum_t session_ticket;
|
|
|
|
gnutls_session_t session;
|
2012-12-05 16:11:14 -08:00
|
|
|
#elif HAVE_OPENSSL
|
2010-07-26 23:30:27 -07:00
|
|
|
SSL *ssl;
|
|
|
|
int ssl_err;
|
2008-10-30 08:26:11 -07:00
|
|
|
#endif
|
2010-09-23 21:15:42 -07:00
|
|
|
Ecore_Con_Ssl_State ssl_state;
|
2011-06-15 11:58:34 -07:00
|
|
|
Eina_Bool handshaking : 1;
|
2011-12-21 02:02:30 -08:00
|
|
|
Eina_Bool upgrade : 1; /* STARTTLS queued */
|
|
|
|
Eina_Bool delete_me : 1; /* del event has been queued */
|
2003-09-23 01:09:32 -07:00
|
|
|
};
|
|
|
|
|
2016-02-12 12:02:01 -08:00
|
|
|
typedef struct _Efl_Network_Client_Data Efl_Network_Client_Data;
|
2014-08-22 05:14:59 -07:00
|
|
|
|
2016-02-04 23:09:53 -08:00
|
|
|
struct _Efl_Network_Server_Data
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2015-01-30 02:03:00 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
SOCKET fd;
|
|
|
|
#else
|
2010-07-26 23:30:27 -07:00
|
|
|
int fd;
|
2015-01-30 02:03:00 -08:00
|
|
|
#endif
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Type type;
|
|
|
|
char *name;
|
|
|
|
int port;
|
|
|
|
char *path;
|
|
|
|
void *data;
|
2003-09-23 01:09:32 -07:00
|
|
|
Ecore_Fd_Handler *fd_handler;
|
2010-07-26 23:30:27 -07:00
|
|
|
Eina_List *clients;
|
2010-09-20 12:31:11 -07:00
|
|
|
unsigned int client_count;
|
2011-07-16 06:07:39 -07:00
|
|
|
Eina_Binbuf *buf;
|
2014-04-04 03:35:16 -07:00
|
|
|
size_t write_buf_offset;
|
2011-01-21 02:01:04 -08:00
|
|
|
Eina_List *infos;
|
2011-11-10 18:44:16 -08:00
|
|
|
Eina_List *event_count;
|
2010-07-26 23:30:27 -07:00
|
|
|
int client_limit;
|
|
|
|
pid_t ppid;
|
2011-12-05 19:32:16 -08:00
|
|
|
/* socks */
|
|
|
|
Ecore_Con_Socks *ecs;
|
2012-02-14 21:53:50 -08:00
|
|
|
Ecore_Con_Proxy_State ecs_state;
|
2011-12-05 19:32:16 -08:00
|
|
|
int ecs_addrlen;
|
|
|
|
unsigned char ecs_addr[16];
|
2014-04-04 03:35:16 -07:00
|
|
|
size_t ecs_buf_offset;
|
2011-12-05 19:32:16 -08:00
|
|
|
Eina_Binbuf *ecs_buf;
|
|
|
|
Eina_Binbuf *ecs_recvbuf;
|
|
|
|
const char *proxyip;
|
|
|
|
int proxyport;
|
|
|
|
/* endsocks */
|
2011-12-07 17:14:55 -08:00
|
|
|
const char *verify_name;
|
2012-12-05 16:11:14 -08:00
|
|
|
#if HAVE_GNUTLS
|
2010-09-23 23:54:49 -07:00
|
|
|
gnutls_session_t session;
|
2008-10-30 08:26:11 -07:00
|
|
|
gnutls_anon_client_credentials_t anoncred_c;
|
|
|
|
gnutls_anon_server_credentials_t anoncred_s;
|
2010-09-21 17:10:10 -07:00
|
|
|
gnutls_psk_client_credentials_t pskcred_c;
|
|
|
|
gnutls_psk_server_credentials_t pskcred_s;
|
2010-07-26 23:30:27 -07:00
|
|
|
gnutls_certificate_credentials_t cert;
|
2010-09-27 20:16:08 -07:00
|
|
|
char *cert_file;
|
2010-09-19 12:25:47 -07:00
|
|
|
gnutls_dh_params_t dh_params;
|
2012-12-05 16:11:14 -08:00
|
|
|
#elif HAVE_OPENSSL
|
2010-07-26 23:30:27 -07:00
|
|
|
SSL_CTX *ssl_ctx;
|
|
|
|
SSL *ssl;
|
|
|
|
int ssl_err;
|
2004-03-31 08:47:45 -08:00
|
|
|
#endif
|
2010-09-21 21:48:09 -07:00
|
|
|
double start_time;
|
2011-06-17 04:16:50 -07:00
|
|
|
Ecore_Timer *until_deletion;
|
|
|
|
double disconnect_time;
|
2010-09-21 21:48:09 -07:00
|
|
|
double client_disconnect_time;
|
2010-11-16 13:32:50 -08:00
|
|
|
const char *ip;
|
2012-04-11 20:51:36 -07:00
|
|
|
Eina_Bool created : 1; /* @c EINA_TRUE if server is our listening server */
|
|
|
|
Eina_Bool connecting : 1; /* @c EINA_FALSE if just initialized or connected */
|
|
|
|
Eina_Bool handshaking : 1; /* @c EINA_TRUE if server is ssl handshaking */
|
2011-12-21 02:02:30 -08:00
|
|
|
Eina_Bool upgrade : 1; /* STARTTLS queued */
|
2012-06-04 02:03:04 -07:00
|
|
|
Eina_Bool disable_proxy : 1; /* proxy should never be used with this connection */
|
2011-06-15 11:58:34 -07:00
|
|
|
Eina_Bool ssl_prepared : 1;
|
2012-04-11 20:51:36 -07:00
|
|
|
Eina_Bool use_cert : 1; /* @c EINA_TRUE if using certificate auth */
|
2010-09-27 20:16:08 -07:00
|
|
|
Ecore_Con_Ssl_State ssl_state; /* current state of ssl handshake on the server */
|
2012-04-11 20:51:36 -07:00
|
|
|
Eina_Bool verify : 1; /* @c EINA_TRUE if certificates will be verified */
|
|
|
|
Eina_Bool verify_basic : 1; /* @c EINA_TRUE if certificates will be verified only against the hostname */
|
2010-09-17 23:30:13 -07:00
|
|
|
Eina_Bool reject_excess_clients : 1;
|
2011-12-21 02:02:30 -08:00
|
|
|
Eina_Bool delete_me : 1; /* del event has been queued */
|
2011-05-14 10:52:30 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
Eina_Bool want_write : 1;
|
|
|
|
Eina_Bool read_stop : 1;
|
|
|
|
Eina_Bool read_stopped : 1;
|
|
|
|
HANDLE pipe;
|
|
|
|
HANDLE thread_read;
|
|
|
|
HANDLE event_read;
|
|
|
|
HANDLE event_peek;
|
|
|
|
DWORD nbr_bytes;
|
|
|
|
#endif
|
2003-09-23 01:09:32 -07:00
|
|
|
};
|
|
|
|
|
2016-02-04 23:09:53 -08:00
|
|
|
typedef struct _Efl_Network_Server_Data Efl_Network_Server_Data;
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
struct _Ecore_Con_Info
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
unsigned int size;
|
2008-10-09 05:30:19 -07:00
|
|
|
struct addrinfo info;
|
2010-07-26 23:30:27 -07:00
|
|
|
char ip[NI_MAXHOST];
|
|
|
|
char service[NI_MAXSERV];
|
2008-10-09 05:30:19 -07:00
|
|
|
};
|
|
|
|
|
2010-07-22 04:32:55 -07:00
|
|
|
struct _Ecore_Con_Lookup
|
|
|
|
{
|
|
|
|
Ecore_Con_Dns_Cb done_cb;
|
|
|
|
const void *data;
|
|
|
|
};
|
|
|
|
|
2012-02-14 21:53:50 -08:00
|
|
|
struct Ecore_Con_Socks /* v4 */
|
2011-12-05 19:32:16 -08:00
|
|
|
{
|
|
|
|
unsigned char version;
|
|
|
|
|
|
|
|
const char *ip;
|
|
|
|
int port;
|
|
|
|
const char *username;
|
2012-02-14 21:53:50 -08:00
|
|
|
unsigned int ulen;
|
2011-12-05 19:32:16 -08:00
|
|
|
Eina_Bool lookup : 1;
|
|
|
|
Eina_Bool bind : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Ecore_Con_Socks_v5
|
|
|
|
{
|
|
|
|
unsigned char version;
|
|
|
|
|
|
|
|
const char *ip;
|
|
|
|
int port;
|
|
|
|
const char *username;
|
2012-02-14 21:53:50 -08:00
|
|
|
unsigned int ulen;
|
2011-12-05 19:32:16 -08:00
|
|
|
Eina_Bool lookup : 1;
|
|
|
|
Eina_Bool bind : 1;
|
2012-02-14 21:53:50 -08:00
|
|
|
/* v5 only */
|
|
|
|
unsigned char method;
|
|
|
|
const char *password;
|
|
|
|
unsigned int plen;
|
2011-12-05 19:32:16 -08:00
|
|
|
};
|
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
|
|
|
extern int sd_fd_index;
|
|
|
|
extern int sd_fd_max;
|
|
|
|
#endif
|
|
|
|
|
2016-09-18 23:19:16 -07:00
|
|
|
#ifdef HAVE_LIBPROXY
|
|
|
|
# include <proxy.h>
|
|
|
|
extern pxProxyFactory *_ecore_con_libproxy_factory;
|
|
|
|
#endif
|
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
extern Ecore_Con_Socks *_ecore_con_proxy_once;
|
|
|
|
extern Ecore_Con_Socks *_ecore_con_proxy_global;
|
|
|
|
void ecore_con_socks_init(void);
|
|
|
|
void ecore_con_socks_shutdown(void);
|
|
|
|
Eina_Bool ecore_con_socks_svr_init(Ecore_Con_Server *svr);
|
|
|
|
void ecore_con_socks_read(Ecore_Con_Server *svr, unsigned char *buf, int num);
|
|
|
|
void ecore_con_socks_dns_cb(const char *canonname, const char *ip, struct sockaddr *addr, int addrlen, Ecore_Con_Server *svr);
|
2015-05-14 00:15:41 -07:00
|
|
|
|
2011-01-21 02:01:04 -08:00
|
|
|
/* from ecore_con.c */
|
|
|
|
void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info);
|
2011-12-05 19:32:16 -08:00
|
|
|
void ecore_con_event_proxy_bind(Ecore_Con_Server *svr);
|
2011-05-14 10:52:30 -07:00
|
|
|
void ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate);
|
|
|
|
void ecore_con_event_server_del(Ecore_Con_Server *svr);
|
2011-12-09 21:09:47 -08:00
|
|
|
#define ecore_con_event_server_error(svr, error) _ecore_con_event_server_error((svr), (char*)(error), EINA_TRUE)
|
|
|
|
void _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate);
|
2011-05-14 10:52:30 -07:00
|
|
|
void ecore_con_event_client_add(Ecore_Con_Client *cl);
|
|
|
|
void ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate);
|
|
|
|
void ecore_con_event_client_del(Ecore_Con_Client *cl);
|
2011-02-10 00:49:23 -08:00
|
|
|
void ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error);
|
2011-12-05 19:32:16 -08:00
|
|
|
void _ecore_con_server_kill(Ecore_Con_Server *svr);
|
2012-01-19 00:02:41 -08:00
|
|
|
void _ecore_con_client_kill(Ecore_Con_Client *cl);
|
2015-05-14 00:15:41 -07:00
|
|
|
|
|
|
|
int ecore_con_local_init(void);
|
|
|
|
int ecore_con_local_shutdown(void);
|
2011-05-14 10:52:30 -07:00
|
|
|
/* from ecore_local_win32.c */
|
|
|
|
#ifdef _WIN32
|
|
|
|
Eina_Bool ecore_con_local_listen(Ecore_Con_Server *svr);
|
|
|
|
Eina_Bool ecore_con_local_connect(Ecore_Con_Server *svr,
|
|
|
|
Eina_Bool (*cb_done)(void *data,
|
2011-07-04 17:06:27 -07:00
|
|
|
Ecore_Fd_Handler *fd_handler));
|
2011-05-14 10:52:30 -07:00
|
|
|
Eina_Bool ecore_con_local_win32_server_flush(Ecore_Con_Server *svr);
|
|
|
|
Eina_Bool ecore_con_local_win32_client_flush(Ecore_Con_Client *cl);
|
|
|
|
void ecore_con_local_win32_server_del(Ecore_Con_Server *svr);
|
|
|
|
void ecore_con_local_win32_client_del(Ecore_Con_Client *cl);
|
|
|
|
#else
|
2010-01-04 11:35:21 -08:00
|
|
|
/* from ecore_local.c */
|
2010-07-26 23:30:27 -07:00
|
|
|
int ecore_con_local_connect(Ecore_Con_Server *svr,
|
|
|
|
Eina_Bool (*cb_done)(
|
|
|
|
void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler),
|
2011-07-04 17:06:27 -07:00
|
|
|
void *data);
|
2010-07-26 23:30:27 -07:00
|
|
|
int ecore_con_local_listen(Ecore_Con_Server *svr,
|
|
|
|
Eina_Bool (*cb_listen)(
|
|
|
|
void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler),
|
|
|
|
void *data);
|
2011-05-14 10:52:30 -07:00
|
|
|
#endif
|
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
/* from ecore_con_info.c */
|
2010-07-26 23:30:27 -07:00
|
|
|
int ecore_con_info_init(void);
|
|
|
|
int ecore_con_info_shutdown(void);
|
|
|
|
int ecore_con_info_tcp_connect(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Info_Cb done_cb,
|
|
|
|
void *data);
|
|
|
|
int ecore_con_info_tcp_listen(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Info_Cb done_cb,
|
|
|
|
void *data);
|
|
|
|
int ecore_con_info_udp_connect(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Info_Cb done_cb,
|
|
|
|
void *data);
|
|
|
|
int ecore_con_info_udp_listen(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Info_Cb done_cb,
|
|
|
|
void *data);
|
|
|
|
int ecore_con_info_mcast_listen(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Info_Cb done_cb,
|
|
|
|
void *data);
|
2011-01-21 02:01:04 -08:00
|
|
|
void ecore_con_info_data_clear(void *info);
|
|
|
|
|
2011-07-04 17:06:27 -07:00
|
|
|
void ecore_con_event_server_add(Ecore_Con_Server *svr);
|
|
|
|
|
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
/* from ecore_con_ssl.c */
|
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_init(void);
|
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_shutdown(void);
|
2010-09-18 12:26:05 -07:00
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_server_prepare(Ecore_Con_Server *svr, int ssl_type);
|
2008-12-15 09:59:19 -08:00
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_server_init(Ecore_Con_Server *svr);
|
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_server_shutdown(Ecore_Con_Server *svr);
|
2010-07-26 23:30:27 -07:00
|
|
|
int ecore_con_ssl_server_read(Ecore_Con_Server *svr,
|
|
|
|
unsigned char *buf,
|
|
|
|
int size);
|
|
|
|
int ecore_con_ssl_server_write(Ecore_Con_Server *svr,
|
2011-07-16 06:07:39 -07:00
|
|
|
const unsigned char *buf,
|
2010-07-26 23:30:27 -07:00
|
|
|
int size);
|
2008-12-15 09:59:19 -08:00
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr);
|
|
|
|
Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr);
|
2010-07-26 23:30:27 -07:00
|
|
|
int ecore_con_ssl_client_read(Ecore_Con_Client *svr,
|
|
|
|
unsigned char *buf,
|
|
|
|
int size);
|
|
|
|
int ecore_con_ssl_client_write(Ecore_Con_Client *svr,
|
2011-07-16 06:07:39 -07:00
|
|
|
const unsigned char *buf,
|
2010-07-26 23:30:27 -07:00
|
|
|
int size);
|
|
|
|
|
|
|
|
int ecore_con_info_get(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Info_Cb done_cb,
|
|
|
|
void *data,
|
|
|
|
struct addrinfo *hints);
|
2010-07-22 04:32:55 -07:00
|
|
|
|
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
#define GENERIC_ALLOC_FREE_HEADER(TYPE, Type) \
|
|
|
|
TYPE *Type##_alloc(void); \
|
|
|
|
void Type##_free(TYPE *e);
|
|
|
|
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Add, ecore_con_event_client_add);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Del, ecore_con_event_client_del);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Write, ecore_con_event_client_write);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Data, ecore_con_event_client_data);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Error, ecore_con_event_server_error);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Error, ecore_con_event_client_error);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Add, ecore_con_event_server_add);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Del, ecore_con_event_server_del);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Write, ecore_con_event_server_write);
|
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Data, ecore_con_event_server_data);
|
2011-12-05 19:32:16 -08:00
|
|
|
GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Proxy_Bind, ecore_con_event_proxy_bind);
|
2011-11-06 04:26:00 -08:00
|
|
|
|
|
|
|
void ecore_con_mempool_init(void);
|
|
|
|
void ecore_con_mempool_shutdown(void);
|
|
|
|
|
|
|
|
#undef GENERIC_ALLOC_FREE_HEADER
|
2008-10-09 05:30:19 -07:00
|
|
|
|
efl.net: socket, server and dialer for TCP.
Efl.Net.Server defines how to accept new connections, doing the
bind(), listen() and accept() for protocols such as TCP.
Efl.Net.Dialer defines to to reach a server.
Both are based on Efl.Net.Socket as communication interface that is
based on Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus being
usable with code such as Efl.Io.Copier.
The Server will emit an event "client,add" with the established
Socket, which is a child and can be closed by both the server or the
user.
The Dialer extends the Socket and allows for creating one given an
address, that will be resolved and connected.
TCP is the initial implementation so we an validate the
interfaces. UDP, Unix-Local and SSL will come later as derivate
classes.
The examples are documented and should cover the basic principles:
- efl_io_copier_example can accept "tcp://IP:PORT" and will work as a
"netcat", can send data from socket, file or stdin to a socket,
file, stdout or stderr.
- efl_net_server_example listens for connections and can either reply
"Hello World!" and take some data or work as an echo-server,
looping back all received data to the user.
More complex interactions that require a "chat" between client and
server will be covered with new classes later, such as a queue that
empties itself once data is read.
2016-08-17 21:53:16 -07:00
|
|
|
Eina_Bool efl_net_ip_port_fmt(char *buf, int buflen, const struct sockaddr *addr);
|
|
|
|
|
2016-09-09 16:09:51 -07:00
|
|
|
/**
|
|
|
|
* @brief splits an address in the format "host:port" in two
|
|
|
|
* null-terminated strings.
|
|
|
|
*
|
|
|
|
* The address may be 'server.com:1234', 'server.com:http',
|
|
|
|
* 'server.com' (@c *p_port will be NULL), IPv4 127.0.0.1:456 or
|
|
|
|
* IPv6 [::1]:456
|
|
|
|
*
|
|
|
|
* @param[inout] buf contains the string to be split and will be modified.
|
|
|
|
* @param[out] p_host returns a pointer inside @a buf with
|
|
|
|
* null-terminated host part.
|
|
|
|
* @param[out] p_port returns a pointer with null-terminated port
|
|
|
|
* part. The pointer may be inside @a buf if port was
|
|
|
|
* specified or #NULL if it wasn't specified.
|
|
|
|
*
|
|
|
|
* @return #EINA_TRUE on success, #EINA_FALSE on errors.
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
Eina_Bool efl_net_ip_port_split(char *buf, const char **p_host, const char **p_port);
|
|
|
|
|
2016-08-24 08:34:59 -07:00
|
|
|
int efl_net_socket4(int domain, int type, int protocol, Eina_Bool close_on_exec);
|
|
|
|
|
2016-09-09 16:09:51 -07:00
|
|
|
/**
|
|
|
|
* @brief callback to notify of connection.
|
|
|
|
*
|
|
|
|
* The callback is given the ownership of the socket (sockfd), thus
|
|
|
|
* must close().
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
typedef void (*Efl_Net_Connect_Async_Cb)(void *data, const struct sockaddr *addr, socklen_t addrlen, int sockfd, Eina_Error error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief asynchronously create a socket and connect to the address.
|
|
|
|
*
|
|
|
|
* This will call socket() and connect() in a thread, taking care to
|
|
|
|
* return the result to the main loop and calling @a cb with given
|
|
|
|
* user @a data.
|
|
|
|
*
|
efl_net_dialer_tcp: add SOCKS proxy support.
SOCKS is implemented in its own thread using synchronous/blocking
primitives, which simplifies the code a lot -- as well as simulate the
usage of Ecore_Thread as our users will likely do.
Since SOCKSv4a and SOCKSv5 allow name resolution, the whole
getaddrinfo() is done in the same thread, when needed, instead of a
separate thread to do that, which should also save some resources.
Instead of the legacy ECORE_CON_SOCKS_V4 and ECORE_CON_SOCKS_V5, now
we use socks_proxy, all_proxy and no_proxy. This matches our other
dialers http/websocket (which will use http_proxy, all_proxy and
no_proxy). If desired it's easy to add back support for those
variables, but I think we should just deprecate them. (The legacy code
will keep unchanged, thus direct users of ecore_con_server will still
use those -- just the previous users of ecore_con_server will be
converted to use the new API).
2016-09-18 20:56:18 -07:00
|
|
|
* For name resolution and proxy support use
|
|
|
|
* efl_net_ip_connect_async_new()
|
|
|
|
*
|
2016-09-09 16:09:51 -07:00
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
Ecore_Thread *efl_net_connect_async_new(const struct sockaddr *addr, socklen_t addrlen, int type, int protocol, Eina_Bool close_on_exec, Efl_Net_Connect_Async_Cb cb, const void *data);
|
|
|
|
|
efl_net_dialer_tcp: add SOCKS proxy support.
SOCKS is implemented in its own thread using synchronous/blocking
primitives, which simplifies the code a lot -- as well as simulate the
usage of Ecore_Thread as our users will likely do.
Since SOCKSv4a and SOCKSv5 allow name resolution, the whole
getaddrinfo() is done in the same thread, when needed, instead of a
separate thread to do that, which should also save some resources.
Instead of the legacy ECORE_CON_SOCKS_V4 and ECORE_CON_SOCKS_V5, now
we use socks_proxy, all_proxy and no_proxy. This matches our other
dialers http/websocket (which will use http_proxy, all_proxy and
no_proxy). If desired it's easy to add back support for those
variables, but I think we should just deprecate them. (The legacy code
will keep unchanged, thus direct users of ecore_con_server will still
use those -- just the previous users of ecore_con_server will be
converted to use the new API).
2016-09-18 20:56:18 -07:00
|
|
|
/**
|
|
|
|
* @brief asynchronously create a socket and connect to the IP address.
|
|
|
|
*
|
|
|
|
* This wil resolve the address using getaddrinfo(), create a socket
|
|
|
|
* and connect in a thread.
|
|
|
|
*
|
|
|
|
* If a @a proxy is given, then it's always used. Otherwise the
|
|
|
|
* environment variable @a proxy_env is used unless it matches @a
|
|
|
|
* no_proxy_env. Some systems may do special queries for proxy from
|
|
|
|
* the thread.
|
|
|
|
*
|
|
|
|
* @param address the host:port to connect. Host may be a name or an
|
|
|
|
* IP address, IPv6 addresses should be enclosed in braces.
|
|
|
|
* @param proxy a mandatory proxy to use. If "" (empty string), it's
|
|
|
|
* disabled. If NULL, then @a proxy_env is used unless it
|
|
|
|
* matches @a no_proxy_env.
|
|
|
|
* @param proxy_env if @a proxy is NULL, then this will be used as the
|
|
|
|
* proxy unless it matches @a no_proxy_env.
|
|
|
|
* @param no_proxy_env a comma-separated list of matches that will
|
|
|
|
* avoid using @a proxy_env. "server.com" will inhibit proxy
|
|
|
|
* for "server.com", "host.server.com" but not "xserver.com".
|
|
|
|
* @param type the socket type, such as SOCK_STREAM or SOCK_DGRAM.
|
|
|
|
* @param protocol the socket protocol, such as IPPROTO_TCP.
|
|
|
|
* @param close_on_exec if EINA_TRUE, will set SOCK_CLOEXEC.
|
|
|
|
* @param cb the callback to report connection
|
|
|
|
* @param data data to give to callback
|
|
|
|
*
|
|
|
|
* @return an Ecore_Thread that will execute the connection.
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
Ecore_Thread *efl_net_ip_connect_async_new(const char *address, const char *proxy, const char *proxy_env, const char *no_proxy_env, int type, int protocol, Eina_Bool close_on_exec, Efl_Net_Connect_Async_Cb cb, const void *data);
|
|
|
|
|
2016-09-08 12:12:18 -07:00
|
|
|
static inline Eina_Error
|
|
|
|
efl_net_socket_error_get(void)
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
return errno;
|
|
|
|
#else
|
|
|
|
Eina_Error err = WSAGetLastError();
|
|
|
|
|
|
|
|
if (0) { }
|
|
|
|
|
|
|
|
/* used by send() */
|
|
|
|
#if defined(WSAEACCES) && (WSAEACCES != EACCES)
|
|
|
|
else if (err == WSAEACCES) err = EACCES;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEWOULDBLOCK) && (WSAEWOULDBLOCK != EAGAIN)
|
|
|
|
else if (err == WSAEWOULDBLOCK) err = EAGAIN;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEBADF) && (WSAEBADF != EBADF)
|
|
|
|
else if (err == WSAEBADF) err = EBADF;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAECONNRESET) && (WSAECONNRESET != ECONNRESET)
|
|
|
|
else if (err == WSAECONNRESET) err = ECONNRESET;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEDESTADDRREQ) && (WSAEDESTADDRREQ != EDESTADDRREQ)
|
|
|
|
else if (err == WSAEDESTADDRREQ) err = EDESTADDRREQ;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEFAULT) && (WSAEFAULT != EFAULT)
|
|
|
|
else if (err == WSAEFAULT) err = EFAULT;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEINTR) && (WSAEINTR != EINTR)
|
|
|
|
else if (err == WSAEINTR) err = EINTR;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEINVAL) && (WSAEINVAL != EINVAL)
|
|
|
|
else if (err == WSAEINVAL) err = EINVAL;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEISCONN) && (WSAEISCONN != EISCONN)
|
|
|
|
else if (err == WSAEISCONN) err = EISCONN;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEMSGSIZE) && (WSAEMSGSIZE != EMSGSIZE)
|
|
|
|
else if (err == WSAEMSGSIZE) err = EMSGSIZE;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAENOBUFS) && (WSAENOBUFS != ENOBUFS)
|
|
|
|
else if (err == WSAENOBUFS) err = ENOBUFS;
|
|
|
|
#endif
|
|
|
|
#if defined(WSA_NOT_ENOUGH_MEMORY) && (WSA_NOT_ENOUGH_MEMORY != ENOMEM)
|
|
|
|
else if (err == WSA_NOT_ENOUGH_MEMORY) err = ENOMEM;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAENOTCONN) && (WSAENOTCONN != ENOTCONN)
|
|
|
|
else if (err == WSAENOTCONN) err = ENOTCONN;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAENOTSOCK) && (WSAENOTSOCK != ENOTSOCK)
|
|
|
|
else if (err == WSAENOTSOCK) err = ENOTSOCK;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAEOPNOTSUPP) && (WSAEOPNOTSUPP != EOPNOTSUPP)
|
|
|
|
else if (err == WSAEOPNOTSUPP) err = EOPNOTSUPP;
|
|
|
|
#endif
|
|
|
|
#if defined(WSAESHUTDOWN) && (WSAESHUTDOWN != EPIPE)
|
|
|
|
else if (err == WSAESHUTDOWN) err = EPIPE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* extras used by recv() */
|
|
|
|
#if defined(WSAECONNREFUSED) && (WSAECONNREFUSED != ECONNREFUSED)
|
|
|
|
else if (err == WSAECONNREFUSED) err = ECONNREFUSED;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* extras used by getsockopt() */
|
|
|
|
#if defined(WSAENOPROTOOPT) && (WSAENOPROTOOPT != ENOPROTOOPT)
|
|
|
|
else if (err == WSAENOPROTOOPT) err = ENOPROTOOPT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return err;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
#endif
|