aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--legacy/ecore/ChangeLog4
-rw-r--r--legacy/ecore/NEWS2
-rw-r--r--legacy/ecore/src/lib/ecore_con/Ecore_Con.h35
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_private.h1
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_url.c116
5 files changed, 154 insertions, 4 deletions
diff --git a/legacy/ecore/ChangeLog b/legacy/ecore/ChangeLog
index 4d770059f7..18d697c6ca 100644
--- a/legacy/ecore/ChangeLog
+++ b/legacy/ecore/ChangeLog
@@ -433,3 +433,7 @@
2011-12-21 Tae-Hwan Kim (Bluezery)
* Add proxy set and timeout set functions in ecore_con.
+
+2011-12-26 Tae-Hwan Kim (Bluezery)
+
+ * Add proxy username/password set functions in ecore_con.
diff --git a/legacy/ecore/NEWS b/legacy/ecore/NEWS
index ae24d72dfe..668dc2fbe9 100644
--- a/legacy/ecore/NEWS
+++ b/legacy/ecore/NEWS
@@ -13,6 +13,8 @@ Additions:
- ECORE_CON_REMOTE_CORK
- ecore_con_url_proxy_set()
- ecore_con_url_timeout_set()
+ - ecore_con_url_proxy_username_set
+ - ecore_con_url_proxy_password_set()
* ecore_x:
- ecore_x_randr_output_backlight_available()
diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
index cd39f085b0..bf58f86d16 100644
--- a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
+++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
@@ -1864,6 +1864,38 @@ EAPI int ecore_con_url_ssl_ca_set(Ecore_Con_Url *url_con,
EAPI Eina_Bool ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy);
/**
+ * Set zero terminated username to use for proxy.
+ *
+ * if socks protocol is used for proxy, protocol should be socks5 and above.
+ *
+ * @param url_con Connection object that will use the proxy.
+ * @param username Username string.
+ *
+ * @return #EINA_TRUE on success, #EINA_FALSE on error.
+ *
+ * @see ecore_con_url_proxy_set()
+ *
+ * @since 1.2
+ */
+EAPI Eina_Bool ecore_con_url_proxy_username_set(Ecore_Con_Url *url_con, const char *username);
+
+/**
+ * Set zero terminated password to use for proxy.
+ *
+ * if socks protocol is used for proxy, protocol should be socks5 and above.
+ *
+ * @param url_con Connection object that will use the proxy.
+ * @param password Password string.
+ *
+ * @return #EINA_TRUE on success, #EINA_FALSE on error.
+ *
+ * @see ecore_con_url_proxy_set()
+ *
+ * @since 1.2
+ */
+EAPI Eina_Bool ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password);
+
+/**
* Set timeout in seconds.
*
* the maximum time in seconds that you allow the ecore con url transfer
@@ -1873,6 +1905,9 @@ EAPI Eina_Bool ecore_con_url_proxy_set(Ecore_Con_Url *url_con, const char *proxy
*
* @param url_con Connection object that will use the timeout.
* @param timeout time in seconds.
+ *
+ * @see ecore_con_url_cookies_jar_file_set()
+ *
* @since 1.2
*/
EAPI void ecore_con_url_timeout_set(Ecore_Con_Url *url_con, double timeout);
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 21669e48ac..33ee052bd4 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
@@ -201,6 +201,7 @@ struct _Ecore_Con_Url
Eina_List *additional_headers;
Eina_List *response_headers;
const char *url;
+ long proxy_type;
Ecore_Timer *timer;
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c
index b16d5c2c30..8ccc48ef37 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c
+++ b/legacy/ecore/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 *url_con, const char *proxy)
{
#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 *url_con, const char *proxy)
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_timeout_set(Ecore_Con_Url *url_con, double timeout)
#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;
+ if (url_con->proxy_type == CURLPROXY_SOCKS4 || url_con->proxy_type == CURLPROXY_SOCKS4A)
+ {
+ ERR("Proxy type should be socks5 and above");
+ 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;
+ (void)url_con;
+ (void)username;
+#endif
+}
+
+EAPI Eina_Bool
+ecore_con_url_proxy_password_set(Ecore_Con_Url *url_con, const char *password)
+{
+#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_password_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 (!password) return EINA_FALSE;
+ if (url_con->proxy_type == CURLPROXY_SOCKS4 || url_con->proxy_type == CURLPROXY_SOCKS4A)
+ {
+ ERR("Proxy type should be socks5 and above");
+ return EINA_FALSE;
+ }
+
+ res = curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password);
+ if (res != CURLE_OK)
+ {
+ ERR("curl_easy_setopt() failed: %s", curl_easy_strerror(res));
+ return EINA_FALSE;
+ }
+ return EINA_TRUE;
+#else
+ return EINA_FALSE;
+ (void)url_con;
+ (void)password;
+#endif
+}
+
/**
* @}
*/