summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-12-06 03:32:16 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-12-06 03:32:16 +0000
commit0099b08234a454b3daa10701b1b7497482e22cc3 (patch)
tree5a790148c13c0038312cef1882376b58b3de4ca3
parent9935288eaa634ae88eb5ad8cf32714ae312cc2ff (diff)
introducinggggggggggggggg <drum roll>:
ECORE-CON-SOCKS! SOCKS ON!!!! now ecore_con supports socks (v4 and v4a only, so no ipv6) connections natively for making remote connections for those of you who want their apps to start proxying immediately, just update and export this handy environment variable: ECORE_CON_SOCKS_V4=[user@]PROXY_IP_ADDRESS:PROXY_PORT[:1] <--use :1 here to enable dns lookups on the proxy SVN revision: 65934
-rw-r--r--legacy/ecore/ChangeLog4
-rw-r--r--legacy/ecore/NEWS2
-rw-r--r--legacy/ecore/configure.ac2
-rw-r--r--legacy/ecore/src/lib/ecore_con/Ecore_Con.h44
-rw-r--r--legacy/ecore/src/lib/ecore_con/Makefile.am1
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con.c139
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c4
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_ares.c14
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_info.c4
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_private.h75
10 files changed, 250 insertions, 39 deletions
diff --git a/legacy/ecore/ChangeLog b/legacy/ecore/ChangeLog
index 019b5a0c6c..793a600668 100644
--- a/legacy/ecore/ChangeLog
+++ b/legacy/ecore/ChangeLog
@@ -380,3 +380,7 @@
3802011-12-04 Mike Blumenkrantz 3802011-12-04 Mike Blumenkrantz
381 381
382 * added ecore_timer_reset() 382 * added ecore_timer_reset()
383
3842011-12-05 Mike Blumenkrantz
385
386 * added ecore_con_socks api
diff --git a/legacy/ecore/NEWS b/legacy/ecore/NEWS
index df034e6c33..6fff5308d6 100644
--- a/legacy/ecore/NEWS
+++ b/legacy/ecore/NEWS
@@ -6,6 +6,8 @@ Changes since Ecore 1.1.0:
6Additions: 6Additions:
7 * ecore 7 * ecore
8 - ecore_timer_reset() 8 - ecore_timer_reset()
9 * ecore_con
10 - ecore_con_socks api
9 * ecore_x: 11 * ecore_x:
10 - ecore_x_randr_output_backlight_available() 12 - ecore_x_randr_output_backlight_available()
11 13
diff --git a/legacy/ecore/configure.ac b/legacy/ecore/configure.ac
index 41ebbf1273..60c7636fe2 100644
--- a/legacy/ecore/configure.ac
+++ b/legacy/ecore/configure.ac
@@ -1190,7 +1190,7 @@ esac
1190 1190
1191# ecore_con 1191# ecore_con
1192 1192
1193AC_CHECK_HEADERS([arpa/inet.h arpa/nameser.h netinet/tcp.h netinet/in.h sys/socket.h sys/un.h ws2tcpip.h netdb.h]) 1193AC_CHECK_HEADERS([arpa/inet.h arpa/nameser.h netinet/tcp.h net/if.h netinet/in.h sys/socket.h sys/un.h ws2tcpip.h netdb.h])
1194 1194
1195if test "x${ac_cv_header_netdb_h}" = "xyes" ; then 1195if test "x${ac_cv_header_netdb_h}" = "xyes" ; then
1196 have_addrinfo="yes" 1196 have_addrinfo="yes"
diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
index e3b68c4a98..66c8c26c02 100644
--- a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
+++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
@@ -234,6 +234,13 @@ typedef struct _Ecore_Con_Server Ecore_Con_Server;
234typedef struct _Ecore_Con_Client Ecore_Con_Client; 234typedef struct _Ecore_Con_Client Ecore_Con_Client;
235 235
236/** 236/**
237 * @typedef Ecore_Con_Socks
238 * An object representing a SOCKS proxy
239 * @ingroup Ecore_Con_Socks_Group
240 */
241typedef struct Ecore_Con_Socks Ecore_Con_Socks;
242
243/**
237 * @typedef Ecore_Con_Url 244 * @typedef Ecore_Con_Url
238 * A handle to an http upload/download object 245 * A handle to an http upload/download object
239 * @ingroup Ecore_Con_Url_Group 246 * @ingroup Ecore_Con_Url_Group
@@ -325,6 +332,13 @@ typedef struct _Ecore_Con_Event_Client_Write Ecore_Con_Event_Client_Write;
325typedef struct _Ecore_Con_Event_Server_Write Ecore_Con_Event_Server_Write; 332typedef struct _Ecore_Con_Event_Server_Write Ecore_Con_Event_Server_Write;
326 333
327/** 334/**
335 * @typedef Ecore_Con_Event_Proxy_Bind
336 * Used as the @p data param for the corresponding event
337 * @since 1.2
338 */
339typedef struct _Ecore_Con_Event_Proxy_Bind Ecore_Con_Event_Proxy_Bind;
340
341/**
328 * @typedef Ecore_Con_Event_Url_Data 342 * @typedef Ecore_Con_Event_Url_Data
329 * Used as the @p data param for the corresponding event 343 * Used as the @p data param for the corresponding event
330 * @ingroup Ecore_Con_Url_Group 344 * @ingroup Ecore_Con_Url_Group
@@ -464,6 +478,18 @@ struct _Ecore_Con_Event_Server_Write
464}; 478};
465 479
466/** 480/**
481 * @struct _Ecore_Con_Event_Proxy_Bind
482 * Used as the @p data param for the @ref ECORE_CON_EVENT_PROXY_BIND event
483 * @ingroup Ecore_Con_Socks_Group
484 */
485struct _Ecore_Con_Event_Proxy_Bind
486{
487 Ecore_Con_Server *server; /**< the server object connected to the proxy */
488 const char *ip; /**< the proxy-bound ip address */
489 int port; /**< the proxy-bound port */
490};
491
492/**
467 * @struct _Ecore_Con_Event_Url_Data 493 * @struct _Ecore_Con_Event_Url_Data
468 * Used as the @p data param for the @ref ECORE_CON_EVENT_URL_DATA event 494 * Used as the @p data param for the @ref ECORE_CON_EVENT_URL_DATA event
469 * @ingroup Ecore_Con_Url_Group 495 * @ingroup Ecore_Con_Url_Group
@@ -542,6 +568,10 @@ EAPI extern int ECORE_CON_EVENT_SERVER_WRITE;
542EAPI extern int ECORE_CON_EVENT_CLIENT_DATA; 568EAPI extern int ECORE_CON_EVENT_CLIENT_DATA;
543/** A server connection object has data */ 569/** A server connection object has data */
544EAPI extern int ECORE_CON_EVENT_SERVER_DATA; 570EAPI extern int ECORE_CON_EVENT_SERVER_DATA;
571/** A server connection has successfully negotiated an ip:port binding
572 * @since 1.2
573 */
574EAPI extern int ECORE_CON_EVENT_PROXY_BIND;
545/** A URL object has data */ 575/** A URL object has data */
546EAPI extern int ECORE_CON_EVENT_URL_DATA; 576EAPI extern int ECORE_CON_EVENT_URL_DATA;
547/** A URL object has completed its transfer to and from the server and can be reused */ 577/** A URL object has completed its transfer to and from the server and can be reused */
@@ -682,6 +712,18 @@ EAPI Eina_Bool ecore_con_ssl_client_upgrade(Ecore_Con_Client *cl, Ecore_
682 * @} 712 * @}
683 */ 713 */
684 714
715EAPI Ecore_Con_Socks *ecore_con_socks4_remote_add(const char *ip, int port, const char *username);
716EAPI void ecore_con_socks4_lookup_set(Ecore_Con_Socks *ecs, Eina_Bool enable);
717EAPI Eina_Bool ecore_con_socks4_lookup_get(Ecore_Con_Socks *ecs);
718EAPI Eina_Bool ecore_con_socks4_remote_exists(const char *ip, int port, const char *username);
719EAPI void ecore_con_socks4_remote_del(const char *ip, int port, const char *username);
720EAPI void ecore_con_socks_bind_set(Ecore_Con_Socks *ecs, Eina_Bool is_bind);
721EAPI Eina_Bool ecore_con_socks_bind_get(Ecore_Con_Socks *ecs);
722EAPI unsigned int ecore_con_socks_version_get(Ecore_Con_Socks *ecs);
723EAPI void ecore_con_socks_remote_del(Ecore_Con_Socks *ecs);
724EAPI void ecore_con_socks_apply_once(Ecore_Con_Socks *ecs);
725EAPI void ecore_con_socks_apply_always(Ecore_Con_Socks *ecs);
726
685/** 727/**
686 * @defgroup Ecore_Con_Server_Group Ecore Connection Server Functions 728 * @defgroup Ecore_Con_Server_Group Ecore Connection Server Functions
687 * 729 *
@@ -1185,6 +1227,8 @@ EAPI Eina_Bool ecore_con_client_connected_get(Ecore_Con_Client *cl);
1185 */ 1227 */
1186EAPI int ecore_con_client_port_get(Ecore_Con_Client *cl); 1228EAPI int ecore_con_client_port_get(Ecore_Con_Client *cl);
1187 1229
1230
1231
1188/** 1232/**
1189 * @} 1233 * @}
1190 */ 1234 */
diff --git a/legacy/ecore/src/lib/ecore_con/Makefile.am b/legacy/ecore/src/lib/ecore_con/Makefile.am
index 300586dd10..929b30e9c4 100644
--- a/legacy/ecore/src/lib/ecore_con/Makefile.am
+++ b/legacy/ecore/src/lib/ecore_con/Makefile.am
@@ -19,6 +19,7 @@ includesdir = $(includedir)/ecore-@VMAJ@
19 19
20libecore_con_la_SOURCES = \ 20libecore_con_la_SOURCES = \
21ecore_con.c \ 21ecore_con.c \
22ecore_con_socks.c \
22ecore_con_ssl.c \ 23ecore_con_ssl.c \
23ecore_con_url.c \ 24ecore_con_url.c \
24ecore_con_alloc.c 25ecore_con_alloc.c
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con.c b/legacy/ecore/src/lib/ecore_con/ecore_con.c
index a05f7b3009..4d22bbad54 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con.c
@@ -114,11 +114,14 @@ EAPI int ECORE_CON_EVENT_CLIENT_WRITE = 0;
114EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0; 114EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0;
115EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0; 115EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
116EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0; 116EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
117EAPI int ECORE_CON_EVENT_PROXY_BIND = 0;
117 118
118static Eina_List *servers = NULL; 119static Eina_List *servers = NULL;
119static int _ecore_con_init_count = 0; 120static int _ecore_con_init_count = 0;
120static int _ecore_con_event_count = 0; 121static int _ecore_con_event_count = 0;
121int _ecore_con_log_dom = -1; 122int _ecore_con_log_dom = -1;
123Ecore_Con_Socks *_ecore_con_proxy_once = NULL;
124Ecore_Con_Socks *_ecore_con_proxy_global = NULL;
122 125
123EAPI int 126EAPI int
124ecore_con_init(void) 127ecore_con_init(void)
@@ -156,6 +159,7 @@ ecore_con_init(void)
156 ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new(); 159 ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new();
157 ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new(); 160 ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
158 ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new(); 161 ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
162 ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new();
159 163
160 164
161 eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server"); 165 eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
@@ -163,6 +167,7 @@ ecore_con_init(void)
163 eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url"); 167 eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url");
164 168
165 /* TODO Remember return value, if it fails, use gethostbyname() */ 169 /* TODO Remember return value, if it fails, use gethostbyname() */
170 ecore_con_socks_init();
166 ecore_con_ssl_init(); 171 ecore_con_ssl_init();
167 ecore_con_info_init(); 172 ecore_con_info_init();
168 173
@@ -190,6 +195,7 @@ ecore_con_shutdown(void)
190 _ecore_con_server_free(svr); 195 _ecore_con_server_free(svr);
191 } 196 }
192 197
198 ecore_con_socks_shutdown();
193 if (!_ecore_con_event_count) ecore_con_mempool_shutdown(); 199 if (!_ecore_con_event_count) ecore_con_mempool_shutdown();
194 200
195 ecore_con_info_shutdown(); 201 ecore_con_info_shutdown();
@@ -400,11 +406,30 @@ ecore_con_server_connect(Ecore_Con_Type compl_type,
400 svr->reject_excess_clients = EINA_FALSE; 406 svr->reject_excess_clients = EINA_FALSE;
401 svr->clients = NULL; 407 svr->clients = NULL;
402 svr->client_limit = -1; 408 svr->client_limit = -1;
403 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
404 goto error;
405 409
406 type = compl_type & ECORE_CON_TYPE; 410 type = compl_type & ECORE_CON_TYPE;
407 411
412 if (type > ECORE_CON_LOCAL_ABSTRACT)
413 {
414 /* never use proxies on local connections */
415 if (_ecore_con_proxy_once)
416 svr->ecs = _ecore_con_proxy_once;
417 else if (_ecore_con_proxy_global)
418 svr->ecs = _ecore_con_proxy_global;
419 _ecore_con_proxy_once = NULL;
420 if (svr->ecs)
421 {
422 if ((!svr->ecs->lookup) &&
423 (!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
424 goto error;
425 if (svr->ecs->lookup)
426 svr->ecs_state = ECORE_CON_SOCKS_STATE_RESOLVED;
427 }
428
429 }
430 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
431 goto error;
432
408 if (((type == ECORE_CON_REMOTE_TCP) || 433 if (((type == ECORE_CON_REMOTE_TCP) ||
409 (type == ECORE_CON_REMOTE_NODELAY) || 434 (type == ECORE_CON_REMOTE_NODELAY) ||
410 (type == ECORE_CON_REMOTE_UDP) || 435 (type == ECORE_CON_REMOTE_UDP) ||
@@ -940,6 +965,25 @@ ecore_con_client_fd_get(Ecore_Con_Client *cl)
940 */ 965 */
941 966
942void 967void
968ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
969{
970 Ecore_Con_Event_Proxy_Bind *e;
971 int ev = ECORE_CON_EVENT_PROXY_BIND;
972
973 e = ecore_con_event_proxy_bind_alloc();
974 EINA_SAFETY_ON_NULL_RETURN(e);
975
976 svr->event_count = eina_list_append(svr->event_count, e);
977 _ecore_con_server_timer_update(svr);
978 e->server = svr;
979 e->ip = svr->proxyip;
980 e->port = svr->proxyport;
981 ecore_event_add(ev, e,
982 _ecore_con_event_server_add_free, NULL);
983 _ecore_con_event_count++;
984}
985
986void
943ecore_con_event_server_add(Ecore_Con_Server *svr) 987ecore_con_event_server_add(Ecore_Con_Server *svr)
944{ 988{
945 /* we got our server! */ 989 /* we got our server! */
@@ -949,6 +993,8 @@ ecore_con_event_server_add(Ecore_Con_Server *svr)
949 e = ecore_con_event_server_add_alloc(); 993 e = ecore_con_event_server_add_alloc();
950 EINA_SAFETY_ON_NULL_RETURN(e); 994 EINA_SAFETY_ON_NULL_RETURN(e);
951 995
996 svr->connecting = EINA_FALSE;
997 svr->start_time = ecore_time_get();
952 svr->event_count = eina_list_append(svr->event_count, e); 998 svr->event_count = eina_list_append(svr->event_count, e);
953 _ecore_con_server_timer_update(svr); 999 _ecore_con_server_timer_update(svr);
954 e->server = svr; 1000 e->server = svr;
@@ -1212,6 +1258,9 @@ _ecore_con_server_free(Ecore_Con_Server *svr)
1212 1258
1213 eina_stringshare_del(svr->ip); 1259 eina_stringshare_del(svr->ip);
1214 1260
1261 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1262 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1263
1215 if (svr->fd_handler) 1264 if (svr->fd_handler)
1216 ecore_main_fd_handler_del(svr->fd_handler); 1265 ecore_main_fd_handler_del(svr->fd_handler);
1217 1266
@@ -1288,7 +1337,7 @@ _ecore_con_client_free(Ecore_Con_Client *cl)
1288 return; 1337 return;
1289} 1338}
1290 1339
1291static void 1340void
1292_ecore_con_server_kill(Ecore_Con_Server *svr) 1341_ecore_con_server_kill(Ecore_Con_Server *svr)
1293{ 1342{
1294 if (!svr->delete_me) 1343 if (!svr->delete_me)
@@ -1666,7 +1715,8 @@ _ecore_con_cb_tcp_connect(void *data,
1666 goto error; 1715 goto error;
1667 } 1716 }
1668 1717
1669 svr->ip = eina_stringshare_add(net_info->ip); 1718 if ((!svr->ecs) || (svr->ecs->lookup))
1719 svr->ip = eina_stringshare_add(net_info->ip);
1670 1720
1671 return; 1721 return;
1672 1722
@@ -1739,7 +1789,8 @@ _ecore_con_cb_udp_connect(void *data,
1739 goto error; 1789 goto error;
1740 } 1790 }
1741 1791
1742 svr->ip = eina_stringshare_add(net_info->ip); 1792 if ((!svr->ecs) || (svr->ecs->lookup))
1793 svr->ip = eina_stringshare_add(net_info->ip);
1743 1794
1744 return; 1795 return;
1745 1796
@@ -1783,9 +1834,13 @@ svr_try_connect_plain(Ecore_Con_Server *svr)
1783 1834
1784 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting) 1835 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1785 { 1836 {
1786 svr->connecting = EINA_FALSE; 1837 if (svr->ecs)
1787 svr->start_time = ecore_time_get(); 1838 {
1788 ecore_con_event_server_add(svr); 1839 if (ecore_con_socks_svr_init(svr))
1840 return ECORE_CON_INPROGRESS;
1841 }
1842 else
1843 ecore_con_event_server_add(svr);
1789 } 1844 }
1790 1845
1791 if (svr->fd_handler && (!svr->buf)) 1846 if (svr->fd_handler && (!svr->buf))
@@ -1936,11 +1991,12 @@ _ecore_con_svr_tcp_handler(void *data,
1936static void 1991static void
1937_ecore_con_cl_read(Ecore_Con_Server *svr) 1992_ecore_con_cl_read(Ecore_Con_Server *svr)
1938{ 1993{
1939 DBG("svr=%p", svr);
1940 int num = 0; 1994 int num = 0;
1941 Eina_Bool lost_server = EINA_TRUE; 1995 Eina_Bool lost_server = EINA_TRUE;
1942 unsigned char buf[READBUFSIZ]; 1996 unsigned char buf[READBUFSIZ];
1943 1997
1998 DBG("svr=%p", svr);
1999
1944 /* only possible with non-ssl connections */ 2000 /* only possible with non-ssl connections */
1945 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED)) 2001 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1946 return; 2002 return;
@@ -1971,7 +2027,12 @@ _ecore_con_cl_read(Ecore_Con_Server *svr)
1971 } 2027 }
1972 2028
1973 if ((!svr->delete_me) && (num > 0)) 2029 if ((!svr->delete_me) && (num > 0))
1974 ecore_con_event_server_data(svr, buf, num, EINA_TRUE); 2030 {
2031 if (svr->ecs_state)
2032 ecore_con_socks_read(svr, buf, num);
2033 else
2034 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2035 }
1975 2036
1976 if (lost_server) 2037 if (lost_server)
1977 _ecore_con_server_kill(svr); 2038 _ecore_con_server_kill(svr);
@@ -1994,7 +2055,7 @@ _ecore_con_cl_handler(void *data,
1994 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ); 2055 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
1995 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE); 2056 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
1996 2057
1997 if (svr->handshaking && (want_read || want_write)) 2058 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
1998 { 2059 {
1999 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write"); 2060 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
2000#ifdef ISCOMFITOR 2061#ifdef ISCOMFITOR
@@ -2013,17 +2074,23 @@ _ecore_con_cl_handler(void *data,
2013 2074
2014 } 2075 }
2015 else if (!svr->ssl_state) 2076 else if (!svr->ssl_state)
2077 ecore_con_event_server_add(svr);
2078 return ECORE_CALLBACK_RENEW;
2079 }
2080 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_SOCKS_STATE_READ) && (!svr->ecs_buf))
2081 {
2082 if (svr->ecs_state < ECORE_CON_SOCKS_STATE_INIT)
2016 { 2083 {
2017 svr->connecting = EINA_FALSE; 2084 INF("PROXY STATE++");
2018 svr->start_time = ecore_time_get(); 2085 svr->ecs_state++;
2019 ecore_con_event_server_add(svr);
2020 } 2086 }
2087 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
2021 } 2088 }
2022 else if (want_read) 2089 if (want_read)
2023 _ecore_con_cl_read(svr); 2090 _ecore_con_cl_read(svr);
2024 else if (want_write) /* only possible with non-ssl connections */ 2091 else if (want_write) /* only possible with non-ssl connections */
2025 { 2092 {
2026 if (svr->connecting && (!svr_try_connect_plain(svr))) 2093 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
2027 return ECORE_CALLBACK_RENEW; 2094 return ECORE_CALLBACK_RENEW;
2028 2095
2029 _ecore_con_server_flush(svr); 2096 _ecore_con_server_flush(svr);
@@ -2238,19 +2305,24 @@ static void
2238_ecore_con_server_flush(Ecore_Con_Server *svr) 2305_ecore_con_server_flush(Ecore_Con_Server *svr)
2239{ 2306{
2240 int count, num; 2307 int count, num;
2308 size_t buf_len, buf_offset;
2309 const void *buf;
2241 2310
2242#ifdef _WIN32 2311#ifdef _WIN32
2243 if (ecore_con_local_win32_server_flush(svr)) 2312 if (ecore_con_local_win32_server_flush(svr))
2244 return; 2313 return;
2245#endif 2314#endif
2246 2315
2247 if ((!svr->buf) && svr->fd_handler) 2316 if ((!svr->buf) && (!svr->ecs_buf) && svr->fd_handler)
2248 { 2317 {
2249 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); 2318 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2250 return; 2319 return;
2251 } 2320 }
2252 2321
2253 num = eina_binbuf_length_get(svr->buf) - svr->write_buf_offset; 2322 buf = svr->buf ? eina_binbuf_string_get(svr->buf) : eina_binbuf_string_get(svr->ecs_buf);
2323 buf_len = svr->buf ? eina_binbuf_length_get(svr->buf) : eina_binbuf_length_get(svr->ecs_buf);
2324 buf_offset = svr->buf ? svr->write_buf_offset : svr->ecs_buf_offset;
2325 num = buf_len - buf_offset;
2254 2326
2255 /* check whether we need to write anything at all. 2327 /* check whether we need to write anything at all.
2256 * we must not write zero bytes with SSL_write() since it 2328 * we must not write zero bytes with SSL_write() since it
@@ -2271,9 +2343,9 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
2271 } 2343 }
2272 2344
2273 if (!(svr->type & ECORE_CON_SSL)) 2345 if (!(svr->type & ECORE_CON_SSL))
2274 count = write(svr->fd, eina_binbuf_string_get(svr->buf) + svr->write_buf_offset, num); 2346 count = write(svr->fd, buf + buf_offset, num);
2275 else 2347 else
2276 count = ecore_con_ssl_server_write(svr, eina_binbuf_string_get(svr->buf) + svr->write_buf_offset, num); 2348 count = ecore_con_ssl_server_write(svr, buf + buf_offset, num);
2277 2349
2278 if (count < 0) 2350 if (count < 0)
2279 { 2351 {
@@ -2285,13 +2357,28 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
2285 return; 2357 return;
2286 } 2358 }
2287 2359
2288 if (count) ecore_con_event_server_write(svr, count); 2360 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2289 svr->write_buf_offset += count; 2361 if (svr->ecs_buf)
2290 if (svr->write_buf_offset >= eina_binbuf_length_get(svr->buf)) 2362 buf_offset = svr->ecs_buf_offset += count;
2363 else
2364 buf_offset = svr->write_buf_offset += count;
2365 if (buf_offset >= buf_len)
2291 { 2366 {
2292 svr->write_buf_offset = 0; 2367 if (svr->ecs_buf)
2293 eina_binbuf_free(svr->buf); 2368 {
2294 svr->buf = NULL; 2369 svr->ecs_buf_offset = 0;
2370 eina_binbuf_free(svr->ecs_buf);
2371 svr->ecs_buf = NULL;
2372 INF("PROXY STATE++");
2373 svr->ecs_state++;
2374 }
2375 else
2376 {
2377 svr->write_buf_offset = 0;
2378 eina_binbuf_free(svr->buf);
2379 svr->buf = NULL;
2380 }
2381
2295 if (svr->fd_handler) 2382 if (svr->fd_handler)
2296 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); 2383 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2297 } 2384 }
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c b/legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c
index 206948b77d..d922f204d1 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c
@@ -40,6 +40,7 @@ GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Add, ecore_con_event_server_add);
40GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Del, ecore_con_event_server_del); 40GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Del, ecore_con_event_server_del);
41GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Write, ecore_con_event_server_write); 41GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Write, ecore_con_event_server_write);
42GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Data, ecore_con_event_server_data); 42GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Data, ecore_con_event_server_data);
43GENERIC_ALLOC_FREE(Ecore_Con_Event_Proxy_Bind, ecore_con_event_proxy_bind);
43 44
44static Ecore_Con_Mempool *mempool_array[] = { 45static Ecore_Con_Mempool *mempool_array[] = {
45 &ecore_con_event_client_add_mp, 46 &ecore_con_event_client_add_mp,
@@ -51,7 +52,8 @@ static Ecore_Con_Mempool *mempool_array[] = {
51 &ecore_con_event_server_add_mp, 52 &ecore_con_event_server_add_mp,
52 &ecore_con_event_server_del_mp, 53 &ecore_con_event_server_del_mp,
53 &ecore_con_event_server_write_mp, 54 &ecore_con_event_server_write_mp,
54 &ecore_con_event_server_data_mp 55 &ecore_con_event_server_data_mp,
56 &ecore_con_event_proxy_bind_mp
55}; 57};
56 58
57void 59void
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c b/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c
index dd5a212546..3738e852ab 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_ares.c
@@ -309,7 +309,7 @@ ecore_con_info_get(Ecore_Con_Server *svr,
309 memcpy(&cares->hints, hints, sizeof(struct addrinfo)); 309 memcpy(&cares->hints, hints, sizeof(struct addrinfo));
310 } 310 }
311 311
312 if (inet_pton(AF_INET, svr->name, &cares->addr.v4) == 1) 312 if (inet_pton(AF_INET, svr->ecs : svr->ecs->ip : svr->name, &cares->addr.v4) == 1)
313 { 313 {
314 cares->byaddr = EINA_TRUE; 314 cares->byaddr = EINA_TRUE;
315 cares->isv6 = EINA_FALSE; 315 cares->isv6 = EINA_FALSE;
@@ -320,7 +320,7 @@ ecore_con_info_get(Ecore_Con_Server *svr,
320 cares); 320 cares);
321 } 321 }
322#ifdef HAVE_IPV6 322#ifdef HAVE_IPV6
323 else if (inet_pton(AF_INET6, svr->name, &cares->addr.v6) == 1) 323 else if (inet_pton(AF_INET6, svr->ecs : svr->ecs->ip : svr->name, &cares->addr.v6) == 1)
324 { 324 {
325 cares->byaddr = EINA_TRUE; 325 cares->byaddr = EINA_TRUE;
326 cares->isv6 = EINA_TRUE; 326 cares->isv6 = EINA_TRUE;
@@ -334,7 +334,7 @@ ecore_con_info_get(Ecore_Con_Server *svr,
334 else 334 else
335 { 335 {
336 cares->byaddr = EINA_FALSE; 336 cares->byaddr = EINA_FALSE;
337 ares_gethostbyname(info_channel, svr->name, ai_family, 337 ares_gethostbyname(info_channel, svr->ecs : svr->ecs->ip : svr->name, ai_family,
338 (ares_host_callback)_ecore_con_info_ares_host_cb, 338 (ares_host_callback)_ecore_con_info_ares_host_cb,
339 cares); 339 cares);
340 } 340 }
@@ -457,7 +457,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
457 goto on_mem_error; 457 goto on_mem_error;
458 458
459 addri->sin_family = AF_INET; 459 addri->sin_family = AF_INET;
460 addri->sin_port = htons(arg->svr->port); 460 addri->sin_port = htons(arg->svr->ecs : svr->ecs->port : svr->port);
461 461
462 memcpy(&addri->sin_addr.s_addr, 462 memcpy(&addri->sin_addr.s_addr,
463 hostent->h_addr_list[0], sizeof(struct in_addr)); 463 hostent->h_addr_list[0], sizeof(struct in_addr));
@@ -477,7 +477,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
477 goto on_mem_error; 477 goto on_mem_error;
478 478
479 addri6->sin6_family = AF_INET6; 479 addri6->sin6_family = AF_INET6;
480 addri6->sin6_port = htons(arg->svr->port); 480 addri6->sin6_port = htons(arg->svr->ecs : svr->ecs->port : svr->port);
481 addri6->sin6_flowinfo = 0; 481 addri6->sin6_flowinfo = 0;
482 addri6->sin6_scope_id = 0; 482 addri6->sin6_scope_id = 0;
483 483
@@ -516,7 +516,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
516 goto on_mem_error; 516 goto on_mem_error;
517 517
518 addri6->sin6_family = AF_INET6; 518 addri6->sin6_family = AF_INET6;
519 addri6->sin6_port = htons(arg->svr->port); 519 addri6->sin6_port = htons(arg->svr->ecs : svr->ecs->port : svr->port);
520 addri6->sin6_flowinfo = 0; 520 addri6->sin6_flowinfo = 0;
521 addri6->sin6_scope_id = 0; 521 addri6->sin6_scope_id = 0;
522 522
@@ -537,7 +537,7 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
537 goto on_mem_error; 537 goto on_mem_error;
538 538
539 addri->sin_family = AF_INET; 539 addri->sin_family = AF_INET;
540 addri->sin_port = htons(arg->svr->port); 540 addri->sin_port = htons(arg->svr->ecs : svr->ecs->port : svr->port);
541 541
542 memcpy(&addri->sin_addr.s_addr, 542 memcpy(&addri->sin_addr.s_addr,
543 &arg->addr.v4, sizeof(struct in_addr)); 543 &arg->addr.v4, sizeof(struct in_addr));
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_info.c b/legacy/ecore/src/lib/ecore_con/ecore_con_info.c
index 4ece6b00c1..f451f6ab26 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_info.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_info.c
@@ -246,9 +246,9 @@ ecore_con_info_get(Ecore_Con_Server *svr,
246 int canonname_len = 0; 246 int canonname_len = 0;
247 int err; 247 int err;
248 248
249 eina_convert_itoa(svr->port, service); 249 eina_convert_itoa(svr->ecs ? svr->ecs->port : svr->port, service);
250 /* CHILD */ 250 /* CHILD */
251 if (!getaddrinfo(svr->name, service, hints, &result) && result) 251 if (!getaddrinfo(svr->ecs ? svr->ecs->ip : svr->name, service, hints, &result) && result)
252 { 252 {
253 if (result->ai_canonname) 253 if (result->ai_canonname)
254 canonname_len = strlen(result->ai_canonname) + 1; 254 canonname_len = strlen(result->ai_canonname) + 1;
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_private.h b/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
index af7ffbd0e8..532c1a837c 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
@@ -56,7 +56,8 @@ extern int _ecore_con_log_dom;
56 56
57typedef struct _Ecore_Con_Lookup Ecore_Con_Lookup; 57typedef struct _Ecore_Con_Lookup Ecore_Con_Lookup;
58typedef struct _Ecore_Con_Info Ecore_Con_Info; 58typedef struct _Ecore_Con_Info Ecore_Con_Info;
59 59typedef struct Ecore_Con_Socks_v4 Ecore_Con_Socks_v4;
60typedef struct Ecore_Con_Socks_v5 Ecore_Con_Socks_v5;
60typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos); 61typedef void (*Ecore_Con_Info_Cb)(void *data, Ecore_Con_Info *infos);
61 62
62typedef enum _Ecore_Con_State 63typedef enum _Ecore_Con_State
@@ -82,6 +83,14 @@ typedef enum _Ecore_Con_Ssl_Handshake
82 ECORE_CON_SSL_STATE_INIT 83 ECORE_CON_SSL_STATE_INIT
83} Ecore_Con_Ssl_State; 84} Ecore_Con_Ssl_State;
84 85
86typedef enum Ecore_Con_Socks_State
87{
88 ECORE_CON_SOCKS_STATE_DONE = 0,
89 ECORE_CON_SOCKS_STATE_RESOLVED,
90 ECORE_CON_SOCKS_STATE_INIT,
91 ECORE_CON_SOCKS_STATE_READ
92} Ecore_Con_Socks_State;
93
85struct _Ecore_Con_Client 94struct _Ecore_Con_Client
86{ 95{
87 ECORE_MAGIC; 96 ECORE_MAGIC;
@@ -130,6 +139,17 @@ struct _Ecore_Con_Server
130 Eina_List *event_count; 139 Eina_List *event_count;
131 int client_limit; 140 int client_limit;
132 pid_t ppid; 141 pid_t ppid;
142 /* socks */
143 Ecore_Con_Socks *ecs;
144 Ecore_Con_Socks_State ecs_state;
145 int ecs_addrlen;
146 unsigned char ecs_addr[16];
147 unsigned int ecs_buf_offset;
148 Eina_Binbuf *ecs_buf;
149 Eina_Binbuf *ecs_recvbuf;
150 const char *proxyip;
151 int proxyport;
152 /* endsocks */
133#if USE_GNUTLS 153#if USE_GNUTLS
134 gnutls_session_t session; 154 gnutls_session_t session;
135 gnutls_anon_client_credentials_t anoncred_c; 155 gnutls_anon_client_credentials_t anoncred_c;
@@ -206,8 +226,58 @@ struct _Ecore_Con_Lookup
206 const void *data; 226 const void *data;
207}; 227};
208 228
229#define ECORE_CON_SOCKS_CAST_ELSE(X) \
230 Ecore_Con_Socks_v4 *v4 = NULL; \
231 Ecore_Con_Socks_v5 *v5 = NULL; \
232 if ((X) && ((X)->version == 4)) \
233 v4 = (Ecore_Con_Socks_v4*)(X); \
234 else if ((X) && ((X)->version == 5)) \
235 v5 = (Ecore_Con_Socks_v5*)(X); \
236 else
237
238struct Ecore_Con_Socks
239{
240 unsigned char version;
241
242 const char *ip;
243 int port;
244 const char *username;
245 Eina_Bool lookup : 1;
246 Eina_Bool bind : 1;
247};
248
249struct Ecore_Con_Socks_v4
250{
251 unsigned char version;
252
253 const char *ip;
254 int port;
255 const char *username;
256 Eina_Bool lookup : 1;
257 Eina_Bool bind : 1;
258};
259
260struct Ecore_Con_Socks_v5
261{
262 unsigned char version;
263
264 const char *ip;
265 int port;
266 const char *username;
267 Eina_Bool lookup : 1;
268 Eina_Bool bind : 1;
269};
270
271extern Ecore_Con_Socks *_ecore_con_proxy_once;
272extern Ecore_Con_Socks *_ecore_con_proxy_global;
273void ecore_con_socks_init(void);
274void ecore_con_socks_shutdown(void);
275Eina_Bool ecore_con_socks_svr_init(Ecore_Con_Server *svr);
276void ecore_con_socks_read(Ecore_Con_Server *svr, unsigned char *buf, int num);
277void ecore_con_socks_dns_cb(const char *canonname, const char *ip, struct sockaddr *addr, int addrlen, Ecore_Con_Server *svr);
209/* from ecore_con.c */ 278/* from ecore_con.c */
210void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info); 279void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info);
280void ecore_con_event_proxy_bind(Ecore_Con_Server *svr);
211void ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate); 281void ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate);
212void ecore_con_event_server_del(Ecore_Con_Server *svr); 282void ecore_con_event_server_del(Ecore_Con_Server *svr);
213void ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error); 283void ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error);
@@ -215,7 +285,7 @@ void ecore_con_event_client_add(Ecore_Con_Client *cl);
215void ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate); 285void ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate);
216void ecore_con_event_client_del(Ecore_Con_Client *cl); 286void ecore_con_event_client_del(Ecore_Con_Client *cl);
217void ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error); 287void ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error);
218 288void _ecore_con_server_kill(Ecore_Con_Server *svr);
219/* from ecore_local_win32.c */ 289/* from ecore_local_win32.c */
220#ifdef _WIN32 290#ifdef _WIN32
221Eina_Bool ecore_con_local_listen(Ecore_Con_Server *svr); 291Eina_Bool ecore_con_local_listen(Ecore_Con_Server *svr);
@@ -306,6 +376,7 @@ GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Add, ecore_con_event_server_add
306GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Del, ecore_con_event_server_del); 376GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Del, ecore_con_event_server_del);
307GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Write, ecore_con_event_server_write); 377GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Write, ecore_con_event_server_write);
308GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Data, ecore_con_event_server_data); 378GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Data, ecore_con_event_server_data);
379GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Proxy_Bind, ecore_con_event_proxy_bind);
309 380
310void ecore_con_mempool_init(void); 381void ecore_con_mempool_init(void);
311void ecore_con_mempool_shutdown(void); 382void ecore_con_mempool_shutdown(void);