Re: [E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-22 Thread Michael Blumenkrantz
On Thu, 22 Dec 2011 14:09:36 +0900
Bluezery  wrote:

> 2011/12/22 Michael Blumenkrantz :
> > On Thu, 22 Dec 2011 12:32:36 +0900
> > Bluezery  wrote:
> >
> >> 2011/12/21 Michael Blumenkrantz :
> >> > On Wed, 21 Dec 2011 17:42:22 +0900
> >> > Bluezery  wrote:
> >> >
> >> >> Hi,
> >> >>
> >> >> I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
> >> >> So, I add to read this value when econ_con_url is used.
> >> >> But I can not test this. because I cannot access socks proxy server.
> >> >> @discomfitor can help to review this patch.
> >> >>
> >> > also, you can easily test this by doing something like:
> >> >
> >> > Create the ssh tunnel to localhost:
> >> > ssh -D  127.0.0.1
> >> >
> >> > Start an app with the proxy variable which uses the localhost tunnel:
> >> > ECORE_CON_SOCKS_V4=127.0.0.1::1 ./app
> >>
> >> Oops.. I have forgotten a patch file :(
> >> And sorry for later response
> >> I have tested as you suggested.  It works well :)
> >> Also I have realized that proxy username/password set APIs are needed
> >> and added them.
> >> Please review attached patch.
> >>
> > a few issues with this:
> >
> > * you don't actually need to do the env variable parsing, there's a global
> > (to ecore-con) variable which gets set any time a proxy should always be
> > used, and you can simply check for this and then pull the data from it just
> > before a curl request begins
> > * you can only set a username/password with socks5+, so you'll have to add
> >  checks for that
> > * for now I would stick with just socks4/4a stuff to keep the patch
> > smaller; I have a few things which need to be done before socks5 goes in,
> > and it may require changes to whatever you do now
> 
> Ok, I found a global variable and use it.
> And I added check for username/password set APIs. if proxy type is
> socks4 and socks4a (not socks5 and above and not http), it fails.
> 
in

--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel


Re: [E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-21 Thread Bluezery
2011/12/22 Michael Blumenkrantz :
> On Thu, 22 Dec 2011 12:32:36 +0900
> Bluezery  wrote:
>
>> 2011/12/21 Michael Blumenkrantz :
>> > On Wed, 21 Dec 2011 17:42:22 +0900
>> > Bluezery  wrote:
>> >
>> >> Hi,
>> >>
>> >> I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
>> >> So, I add to read this value when econ_con_url is used.
>> >> But I can not test this. because I cannot access socks proxy server.
>> >> @discomfitor can help to review this patch.
>> >>
>> > also, you can easily test this by doing something like:
>> >
>> > Create the ssh tunnel to localhost:
>> > ssh -D  127.0.0.1
>> >
>> > Start an app with the proxy variable which uses the localhost tunnel:
>> > ECORE_CON_SOCKS_V4=127.0.0.1::1 ./app
>>
>> Oops.. I have forgotten a patch file :(
>> And sorry for later response
>> I have tested as you suggested.  It works well :)
>> Also I have realized that proxy username/password set APIs are needed
>> and added them.
>> Please review attached patch.
>>
> a few issues with this:
>
> * you don't actually need to do the env variable parsing, there's a global (to
>  ecore-con) variable which gets set any time a proxy should always be used,
>  and you can simply check for this and then pull the data from it just before
>  a curl request begins
> * you can only set a username/password with socks5+, so you'll have to add
>  checks for that
> * for now I would stick with just socks4/4a stuff to keep the patch smaller; I
>  have a few things which need to be done before socks5 goes in, and it may
>  require changes to whatever you do now

Ok, I found a global variable and use it.
And I added check for username/password set APIs. if proxy type is
socks4 and socks4a (not socks5 and above and not http), it fails.

-- 
BRs,
Kim.
Index: src/lib/ecore_con/ecore_con_url.c
===
--- src/lib/ecore_con/ecore_con_url.c	(리비전 66447)
+++ src/lib/ecore_con/ecore_con_url.c	(작업 사본)
@@ -196,6 +196,24 @@ ecore_con_url_new(const char *url)
 return NULL;
  }
 
+   url_con->proxy_type = -1;
+   if (_ecore_con_proxy_global)
+ {
+if (_ecore_con_proxy_global->ip)
+  {
+ char host[128];
+ if (_ecore_con_proxy_global->port > 0 &&
+ _ecore_con_proxy_global->port <= 65535)
+snprintf(host, sizeof(host), "socks4://%s:%d",
+ _ecore_con_proxy_global->ip,
+ _ecore_con_proxy_global->port);
+ else
+snprintf(host, sizeof(host), "socks4://%s",
+ _ecore_con_proxy_global->ip);
+ecore_con_url_proxy_set(url_con, host);
+  }
+ }
+
ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_ENCODING, "gzip,deflate");
if (ret != CURLE_OK)
  {
@@ -1074,6 +1092,8 @@ ecore_con_url_proxy_set(Ecore_Con_Url *u
 {
 #ifdef HAVE_CURL
int res = -1;
+   curl_version_info_data *vers = NULL;
+
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
  {
 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_proxy_set");
@@ -1083,12 +1103,33 @@ ecore_con_url_proxy_set(Ecore_Con_Url *u
if (eina_list_data_find(_url_con_list, url_con)) return EINA_FALSE;
if (!url_con->url) return EINA_FALSE;
 
-   if (proxy == NULL) res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, "");
-   else   res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, proxy);
-
+   if (!proxy) res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, "");
+   else
+ {
+// before curl version 7.21.7, socks protocol:// prefix is not supported
+// (e.g. socks4://, socks4a://, socks5:// or socks5h://, etc.)
+vers = curl_version_info(CURLVERSION_NOW);
+if (vers->age >=0 && vers->version_num < 0x71507)
+  {
+ url_con->proxy_type = CURLPROXY_HTTP;
+ if (strstr(proxy, "socks4"))   url_con->proxy_type = CURLPROXY_SOCKS4;
+ else if (strstr(proxy, "socks4a")) url_con->proxy_type = CURLPROXY_SOCKS4A;
+ else if (strstr(proxy, "socks5"))  url_con->proxy_type = CURLPROXY_SOCKS5;
+ else if (strstr(proxy, "socks5h")) url_con->proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
+ res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXYTYPE, url_con->proxy_type);
+ if (res != CURLE_OK)
+   {
+  ERR("curl proxy type setting failed: %s", curl_easy_strerror(res));
+  url_con->proxy_type = -1;
+  return EINA_FALSE;
+   }
+  }
+res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, proxy);
+ }
if (res != CURLE_OK)
  {
-ERR("curl_easy_setopt() failed");
+ERR("curl proxy setting failed: %s", curl_easy_strerror(res));
+url_con->proxy_type = -1;
 return EINA_FALSE;
  }
return EINA_TRUE;
@@ -1120,6 +1161,73 @@ ecore_con_url

Re: [E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-21 Thread Michael Blumenkrantz
On Thu, 22 Dec 2011 12:32:36 +0900
Bluezery  wrote:

> 2011/12/21 Michael Blumenkrantz :
> > On Wed, 21 Dec 2011 17:42:22 +0900
> > Bluezery  wrote:
> >
> >> Hi,
> >>
> >> I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
> >> So, I add to read this value when econ_con_url is used.
> >> But I can not test this. because I cannot access socks proxy server.
> >> @discomfitor can help to review this patch.
> >>
> > also, you can easily test this by doing something like:
> >
> > Create the ssh tunnel to localhost:
> > ssh -D  127.0.0.1
> >
> > Start an app with the proxy variable which uses the localhost tunnel:
> > ECORE_CON_SOCKS_V4=127.0.0.1::1 ./app
> 
> Oops.. I have forgotten a patch file :(
> And sorry for later response
> I have tested as you suggested.  It works well :)
> Also I have realized that proxy username/password set APIs are needed
> and added them.
> Please review attached patch.
> 
a few issues with this:

* you don't actually need to do the env variable parsing, there's a global (to
  ecore-con) variable which gets set any time a proxy should always be used,
  and you can simply check for this and then pull the data from it just before
  a curl request begins
* you can only set a username/password with socks5+, so you'll have to add
  checks for that
* for now I would stick with just socks4/4a stuff to keep the patch smaller; I
  have a few things which need to be done before socks5 goes in, and it may
  require changes to whatever you do now

--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel


Re: [E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-21 Thread Bluezery
2011/12/21 Michael Blumenkrantz :
> On Wed, 21 Dec 2011 17:42:22 +0900
> Bluezery  wrote:
>
>> Hi,
>>
>> I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
>> So, I add to read this value when econ_con_url is used.
>> But I can not test this. because I cannot access socks proxy server.
>> @discomfitor can help to review this patch.
>>
> also, you can easily test this by doing something like:
>
> Create the ssh tunnel to localhost:
> ssh -D  127.0.0.1
>
> Start an app with the proxy variable which uses the localhost tunnel:
> ECORE_CON_SOCKS_V4=127.0.0.1::1 ./app

Oops.. I have forgotten a patch file :(
And sorry for later response
I have tested as you suggested.  It works well :)
Also I have realized that proxy username/password set APIs are needed
and added them.
Please review attached patch.

-- 
BRs,
Kim.
Index: src/lib/ecore_con/ecore_con_url.c
===
--- src/lib/ecore_con/ecore_con_url.c	(리비전 66443)
+++ src/lib/ecore_con/ecore_con_url.c	(작업 사본)
@@ -171,6 +171,7 @@ ecore_con_url_new(const char *url)
 #ifdef HAVE_CURL
Ecore_Con_Url *url_con;
CURLcode ret;
+   const char *socks;
 
if (!_init_count)
  return NULL;
@@ -196,6 +197,33 @@ ecore_con_url_new(const char *url)
 return NULL;
  }
 
+   /* Copied & modified somewhat from ecore_con_socks_init() */
+   /* ECORE_CON_SOCKS_V4=user@host:port:[1|0] */
+   socks = getenv("ECORE_CON_SOCKS_V4");
+   if ((socks) && (socks[0]) && (strlen(socks) <= 64))
+ {
+char *u = NULL;
+char *h, *p;
+char buf[128];
+
+strncpy(buf, socks, sizeof(buf));
+h = strchr(buf, '@');
+u = NULL;
+if (h && (h - buf > 0)) *h++ = 0, u = buf;
+else h = buf;
+
+if (u) ecore_con_url_proxy_username_set(url_con, u);
+
+p = strrchr(h, ':');
+if (p) *p++ = 0;
+if (h)
+  {
+ char host[64];
+ snprintf(host, sizeof(host), "socks4://%s", h);
+ ecore_con_url_proxy_set(url_con, host);
+  }
+ }
+
ret = curl_easy_setopt(url_con->curl_easy, CURLOPT_ENCODING, "gzip,deflate");
if (ret != CURLE_OK)
  {
@@ -1074,6 +1102,8 @@ ecore_con_url_proxy_set(Ecore_Con_Url *u
 {
 #ifdef HAVE_CURL
int res = -1;
+   curl_version_info_data *vers = NULL;
+
if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
  {
 ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_proxy_set");
@@ -1083,12 +1113,31 @@ ecore_con_url_proxy_set(Ecore_Con_Url *u
if (eina_list_data_find(_url_con_list, url_con)) return EINA_FALSE;
if (!url_con->url) return EINA_FALSE;
 
-   if (proxy == NULL) res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, "");
-   else   res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, proxy);
-
+   if (!proxy) res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, "");
+   else
+ {
+// before curl version 7.21.7, socks protocol:// prefix is not supported
+// (e.g. socks4://, socks4a://, socks5:// or socks5h://, etc.)
+vers = curl_version_info(CURLVERSION_NOW);
+if (vers->age >=0 && vers->version_num < 0x71507)
+  {
+ long type = CURLPROXY_HTTP;
+ if (strstr(proxy, "socks4"))   type = CURLPROXY_SOCKS4;
+ else if (strstr(proxy, "socks4a")) type = CURLPROXY_SOCKS4A;
+ else if (strstr(proxy, "socks5"))  type = CURLPROXY_SOCKS5;
+ else if (strstr(proxy, "socks5h")) type = CURLPROXY_SOCKS5_HOSTNAME;
+ res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXYTYPE, type);
+ if (res != CURLE_OK)
+   {
+  ERR("curl proxy type setting failed: %s", curl_easy_strerror(res));
+  return EINA_FALSE;
+   }
+  }
+res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PROXY, proxy);
+ }
if (res != CURLE_OK)
  {
-ERR("curl_easy_setopt() failed");
+ERR("curl proxy setting failed: %s", curl_easy_strerror(res));
 return EINA_FALSE;
  }
return EINA_TRUE;
@@ -1120,6 +1169,63 @@ ecore_con_url_timeout_set(Ecore_Con_Url
 #endif
 }
 
+EAPI Eina_Bool
+ecore_con_url_proxy_username_set(Ecore_Con_Url *url_con, const char *username)
+{
+#ifdef HAVE_CURL
+   int res = -1;
+   if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
+ {
+ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_proxy_username_set");
+return EINA_FALSE;
+ }
+
+   if (eina_list_data_find(_url_con_list, url_con)) return EINA_FALSE;
+   if (!url_con->url) return EINA_FALSE;
+   if (!username) return EINA_FALSE;
+
+   res = curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, username);
+   if (res != CURLE_OK)
+ {
+ERR("curl_easy_setopt() failed: %s", curl_easy_strerror(res));
+return EINA_FALSE;
+ }
+   return EINA_TRUE;
+#else
+   return EINA_FALSE;

Re: [E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-21 Thread Michael Blumenkrantz
On Wed, 21 Dec 2011 17:42:22 +0900
Bluezery  wrote:

> Hi,
> 
> I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
> So, I add to read this value when econ_con_url is used.
> But I can not test this. because I cannot access socks proxy server.
> @discomfitor can help to review this patch.
> 
also, you can easily test this by doing something like:

Create the ssh tunnel to localhost:
ssh -D  127.0.0.1

Start an app with the proxy variable which uses the localhost tunnel:
ECORE_CON_SOCKS_V4=127.0.0.1::1 ./app

--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel


Re: [E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-21 Thread Michael Blumenkrantz
On Wed, 21 Dec 2011 17:42:22 +0900
Bluezery  wrote:

> Hi,
> 
> I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
> So, I add to read this value when econ_con_url is used.
> But I can not test this. because I cannot access socks proxy server.
> @discomfitor can help to review this patch.
> 
you forgot the patch

--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel


[E-devel] [Patch][ecore_con] Read ECORE_CON_SOCKS_V4 for ecore_con_url

2011-12-21 Thread Bluezery
Hi,

I have heard that ECORE_CON_SOCKS_V4 is used for socks proxy.
So, I add to read this value when econ_con_url is used.
But I can not test this. because I cannot access socks proxy server.
@discomfitor can help to review this patch.

-- 
BRs,
Kim.

--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel