diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-04-14 08:52:41 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-04-14 08:52:41 +0000 |
commit | 9f81887ff049bf44f210114fa5976941d148b142 (patch) | |
tree | 3c31a8f2ab66e3746a8b5f1e9b7f053e35e260aa /src | |
parent | ef104456a379052fbfdd181cb7855c06861931d9 (diff) | |
download | gnunet-9f81887ff049bf44f210114fa5976941d148b142.tar.gz gnunet-9f81887ff049bf44f210114fa5976941d148b142.zip |
adding extended proxy support for http(s) client
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 143 | ||||
-rw-r--r-- | src/transport/transport.conf.in | 34 |
2 files changed, 176 insertions, 1 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index ed6d84471..e0c88b004 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -275,6 +275,39 @@ struct HTTP_Client_Plugin | |||
275 | char *protocol; | 275 | char *protocol; |
276 | 276 | ||
277 | /** | 277 | /** |
278 | * Proxy configuration: hostname or ip of the proxy server | ||
279 | */ | ||
280 | char *proxy_hostname; | ||
281 | |||
282 | /** | ||
283 | * Username for the proxy server | ||
284 | */ | ||
285 | char *proxy_username; | ||
286 | |||
287 | /** | ||
288 | * Password for the proxy server | ||
289 | */ | ||
290 | char *proxy_password; | ||
291 | |||
292 | /** | ||
293 | * Type of proxy server: | ||
294 | * | ||
295 | * Valid values as supported by curl: | ||
296 | * CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, | ||
297 | * CURLPROXY_SOCKS4A, CURLPROXY_SOCKS5_HOSTNAME | ||
298 | */ | ||
299 | curl_proxytype proxytype; | ||
300 | |||
301 | /** | ||
302 | * Use proxy tunneling: | ||
303 | * Tunnel all operations through a given HTTP instead of have the proxy | ||
304 | * evaluate the HTTP request | ||
305 | * | ||
306 | * Default: GNUNET_NO, GNUNET_yes experimental | ||
307 | */ | ||
308 | int proxy_use_httpproxytunnel; | ||
309 | |||
310 | /** | ||
278 | * My options to be included in the address | 311 | * My options to be included in the address |
279 | */ | 312 | */ |
280 | uint32_t options; | 313 | uint32_t options; |
@@ -1269,6 +1302,21 @@ client_connect_get (struct Session *s) | |||
1269 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP); | 1302 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP); |
1270 | #endif | 1303 | #endif |
1271 | 1304 | ||
1305 | if (s->plugin->proxy_hostname != NULL) | ||
1306 | { | ||
1307 | curl_easy_setopt (s->client_get, CURLOPT_PROXY, s->plugin->proxy_hostname); | ||
1308 | curl_easy_setopt (s->client_get, CURLOPT_PROXYTYPE, s->plugin->proxytype); | ||
1309 | if (NULL != s->plugin->proxy_username) | ||
1310 | curl_easy_setopt (s->client_get, CURLOPT_PROXYUSERNAME, | ||
1311 | s->plugin->proxy_username); | ||
1312 | if (NULL != s->plugin->proxy_password) | ||
1313 | curl_easy_setopt (s->client_get, CURLOPT_PROXYPASSWORD, | ||
1314 | s->plugin->proxy_password); | ||
1315 | if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) | ||
1316 | curl_easy_setopt (s->client_get, CURLOPT_HTTPPROXYTUNNEL, | ||
1317 | s->plugin->proxy_use_httpproxytunnel); | ||
1318 | } | ||
1319 | |||
1272 | curl_easy_setopt (s->client_get, CURLOPT_URL, s->url); | 1320 | curl_easy_setopt (s->client_get, CURLOPT_URL, s->url); |
1273 | //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); | 1321 | //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); |
1274 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps); | 1322 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps); |
@@ -1353,6 +1401,21 @@ client_connect_put (struct Session *s) | |||
1353 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTP); | 1401 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTP); |
1354 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP); | 1402 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP); |
1355 | #endif | 1403 | #endif |
1404 | if (s->plugin->proxy_hostname != NULL) | ||
1405 | { | ||
1406 | curl_easy_setopt (s->client_put, CURLOPT_PROXY, s->plugin->proxy_hostname); | ||
1407 | curl_easy_setopt (s->client_put, CURLOPT_PROXYTYPE, s->plugin->proxytype); | ||
1408 | if (NULL != s->plugin->proxy_username) | ||
1409 | curl_easy_setopt (s->client_put, CURLOPT_PROXYUSERNAME, | ||
1410 | s->plugin->proxy_username); | ||
1411 | if (NULL != s->plugin->proxy_password) | ||
1412 | curl_easy_setopt (s->client_put, CURLOPT_PROXYPASSWORD, | ||
1413 | s->plugin->proxy_password); | ||
1414 | if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) | ||
1415 | curl_easy_setopt (s->client_put, CURLOPT_HTTPPROXYTUNNEL, | ||
1416 | s->plugin->proxy_use_httpproxytunnel); | ||
1417 | } | ||
1418 | |||
1356 | curl_easy_setopt (s->client_put, CURLOPT_URL, s->url); | 1419 | curl_easy_setopt (s->client_put, CURLOPT_URL, s->url); |
1357 | curl_easy_setopt (s->client_put, CURLOPT_UPLOAD, 1L); | 1420 | curl_easy_setopt (s->client_put, CURLOPT_UPLOAD, 1L); |
1358 | //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &client_curl_header); | 1421 | //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &client_curl_header); |
@@ -1722,6 +1785,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1722 | _("Shutdown for plugin `%s' complete\n"), | 1785 | _("Shutdown for plugin `%s' complete\n"), |
1723 | plugin->name); | 1786 | plugin->name); |
1724 | 1787 | ||
1788 | GNUNET_free_non_null (plugin->proxy_hostname); | ||
1789 | GNUNET_free_non_null (plugin->proxy_username); | ||
1790 | GNUNET_free_non_null (plugin->proxy_password); | ||
1791 | |||
1725 | GNUNET_free (plugin); | 1792 | GNUNET_free (plugin); |
1726 | GNUNET_free (api); | 1793 | GNUNET_free (api); |
1727 | return NULL; | 1794 | return NULL; |
@@ -1738,6 +1805,8 @@ static int | |||
1738 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) | 1805 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) |
1739 | { | 1806 | { |
1740 | unsigned long long max_connections; | 1807 | unsigned long long max_connections; |
1808 | char *proxy_type; | ||
1809 | |||
1741 | 1810 | ||
1742 | /* Optional parameters */ | 1811 | /* Optional parameters */ |
1743 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 1812 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, |
@@ -1746,9 +1815,81 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1746 | max_connections = 128; | 1815 | max_connections = 128; |
1747 | plugin->max_connections = max_connections; | 1816 | plugin->max_connections = max_connections; |
1748 | 1817 | ||
1749 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1818 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
1750 | _("Maximum number of connections is %u\n"), | 1819 | _("Maximum number of connections is %u\n"), |
1751 | plugin->max_connections); | 1820 | plugin->max_connections); |
1821 | |||
1822 | /* Read proxy configuration */ | ||
1823 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | ||
1824 | plugin->name, "PROXY", &plugin->proxy_hostname)) | ||
1825 | { | ||
1826 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
1827 | "Found proxy host: `%s'\n", | ||
1828 | plugin->proxy_hostname); | ||
1829 | /* proxy username */ | ||
1830 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | ||
1831 | plugin->name, "PROXY_USERNAME", &plugin->proxy_username)) | ||
1832 | { | ||
1833 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
1834 | "Found proxy username name: `%s'\n", | ||
1835 | plugin->proxy_username); | ||
1836 | } | ||
1837 | |||
1838 | /* proxy password */ | ||
1839 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | ||
1840 | plugin->name, "PROXY_PASSWORD", &plugin->proxy_password)) | ||
1841 | { | ||
1842 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
1843 | "Found proxy password name: `%s'\n", | ||
1844 | plugin->proxy_password); | ||
1845 | } | ||
1846 | |||
1847 | /* proxy type */ | ||
1848 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | ||
1849 | plugin->name, "PROXY_TYPE", &proxy_type)) | ||
1850 | { | ||
1851 | GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type); | ||
1852 | |||
1853 | if (0 == strcmp(proxy_type, "HTTP")) | ||
1854 | plugin->proxytype = CURLPROXY_HTTP; | ||
1855 | else if (0 == strcmp(proxy_type, "SOCKS4")) | ||
1856 | plugin->proxytype = CURLPROXY_SOCKS4; | ||
1857 | else if (0 == strcmp(proxy_type, "SOCKS5")) | ||
1858 | plugin->proxytype = CURLPROXY_SOCKS5; | ||
1859 | else if (0 == strcmp(proxy_type, "SOCKS4A")) | ||
1860 | plugin->proxytype = CURLPROXY_SOCKS4A; | ||
1861 | else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME ")) | ||
1862 | plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME ; | ||
1863 | else | ||
1864 | { | ||
1865 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
1866 | _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), | ||
1867 | proxy_type); | ||
1868 | |||
1869 | GNUNET_free (proxy_type); | ||
1870 | GNUNET_free (plugin->proxy_hostname); | ||
1871 | plugin->proxy_hostname = NULL; | ||
1872 | GNUNET_free_non_null (plugin->proxy_username); | ||
1873 | plugin->proxy_username = NULL; | ||
1874 | GNUNET_free_non_null (plugin->proxy_password); | ||
1875 | plugin->proxy_password = NULL; | ||
1876 | |||
1877 | return GNUNET_SYSERR; | ||
1878 | } | ||
1879 | |||
1880 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | ||
1881 | "Found proxy type: `%s'\n", proxy_type); | ||
1882 | } | ||
1883 | |||
1884 | /* proxy http tunneling */ | ||
1885 | if (GNUNET_SYSERR == (plugin->proxy_use_httpproxytunnel == GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | ||
1886 | plugin->name, "PROXY_HTTP_TUNNELING"))) | ||
1887 | plugin->proxy_use_httpproxytunnel = GNUNET_NO; | ||
1888 | |||
1889 | GNUNET_free_non_null (proxy_type); | ||
1890 | } | ||
1891 | |||
1892 | |||
1752 | return GNUNET_OK; | 1893 | return GNUNET_OK; |
1753 | } | 1894 | } |
1754 | 1895 | ||
diff --git a/src/transport/transport.conf.in b/src/transport/transport.conf.in index 00807c701..20a878c2e 100644 --- a/src/transport/transport.conf.in +++ b/src/transport/transport.conf.in | |||
@@ -64,6 +64,22 @@ TESTING_IGNORE_KEYS = ACCEPT_FROM; | |||
64 | [transport-http_client] | 64 | [transport-http_client] |
65 | MAX_CONNECTIONS = 128 | 65 | MAX_CONNECTIONS = 128 |
66 | TESTING_IGNORE_KEYS = ACCEPT_FROM; | 66 | TESTING_IGNORE_KEYS = ACCEPT_FROM; |
67 | # Hostname or IP of proxy server | ||
68 | # PROXY = | ||
69 | |||
70 | # User name for proxy server | ||
71 | # PROXY_USERNAME = | ||
72 | # User password for proxy server | ||
73 | # PROXY_PASSWORD = | ||
74 | |||
75 | # Type of proxy server, | ||
76 | # Valid values: HTTP, SOCKS4, SOCKS5, SOCKS4A, SOCKS5_HOSTNAME | ||
77 | # Default: HTTP | ||
78 | # PROXY_TYPE = HTTP | ||
79 | |||
80 | # Enable tunneling proxy request instead of having proxy server evaluate it | ||
81 | # Experimental, default: NO | ||
82 | # PROXY_HTTP_TUNNELING = NO | ||
67 | 83 | ||
68 | [transport-http_server] | 84 | [transport-http_server] |
69 | #EXTERNAL_HOSTNAME = <your hostname/path> | 85 | #EXTERNAL_HOSTNAME = <your hostname/path> |
@@ -75,6 +91,24 @@ TESTING_IGNORE_KEYS = ACCEPT_FROM; | |||
75 | [transport-https_client] | 91 | [transport-https_client] |
76 | MAX_CONNECTIONS = 128 | 92 | MAX_CONNECTIONS = 128 |
77 | TESTING_IGNORE_KEYS = ACCEPT_FROM; | 93 | TESTING_IGNORE_KEYS = ACCEPT_FROM; |
94 | # Hostname or IP of proxy server | ||
95 | # PROXY = | ||
96 | |||
97 | # User name for proxy server | ||
98 | # PROXY_USERNAME = | ||
99 | # User password for proxy server | ||
100 | # PROXY_PASSWORD = | ||
101 | |||
102 | # Type of proxy server, | ||
103 | # Valid values: HTTP, SOCKS4, SOCKS5, SOCKS4A, SOCKS5_HOSTNAME | ||
104 | # Default: HTTP | ||
105 | # PROXY_TYPE = HTTP | ||
106 | |||
107 | # Enable tunneling proxy request instead of having proxy server evaluate it | ||
108 | # Experimental, default: NO | ||
109 | # PROXY_HTTP_TUNNELING = NO | ||
110 | |||
111 | |||
78 | 112 | ||
79 | [transport-https_server] | 113 | [transport-https_server] |
80 | # EXTERNAL_HOSTNAME = <your hostname/path> | 114 | # EXTERNAL_HOSTNAME = <your hostname/path> |