Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH 1/2] manual: support for non browser scheme in
'manual' mode (Atul Anand)
2. [PATCH 2/2] proxy: support for non browser schemes in 'auto'
mode (Atul Anand)
----------------------------------------------------------------------
Message: 1
Date: Sun, 7 Aug 2016 13:41:27 +0530
From: Atul Anand <[email protected]>
To: [email protected]
Subject: [PATCH 1/2] manual: support for non browser scheme in
'manual' mode
Message-ID: <[email protected]>
when a client request proxy for a url with non browser scheme (eg:
smtp://mail.client.com from a mail client) it is an unknown scheme
for PacRunner i.e PACRUNNER_PROTOCOL_UNKNOWN. So, PacRunner replies with
a proxy string iterating from the start (http/https/ftp proxies at head).
Though these proxies are not for the non browser protocols.
Instead, we should reply with only SOCKs proxies (if stored) otherwise
"DIRECT".
---
src/manual.c | 18 ++++++++++++++++++
unit/suite/manual_basic.test | 2 ++
unit/suite/manual_exclude.test | 2 ++
3 files changed, 22 insertions(+)
diff --git a/src/manual.c b/src/manual.c
index f6077bc..d69a089 100644
--- a/src/manual.c
+++ b/src/manual.c
@@ -593,6 +593,24 @@ static char *generate_proxy_string(GList **servers,
enum pacrunner_manual_protocol i;
char *result = NULL;
+ /* if the protocol is unknown (e.g: request from a mail client
+ * for a smtp:// connection), we will prefer SOCKs proxies (if
+ * available) otherwise simply return "DIRECT".
+ */
+ if (proto == PACRUNNER_PROTOCOL_UNKNOWN) {
+ if (servers[PACRUNNER_PROTOCOL_SOCKS])
+ result = append_servers_to_proxy_string(result,
+ servers[PACRUNNER_PROTOCOL_SOCKS]);
+ if (servers[PACRUNNER_PROTOCOL_SOCKS4])
+ result = append_servers_to_proxy_string(result,
+ servers[PACRUNNER_PROTOCOL_SOCKS4]);
+ if (servers[PACRUNNER_PROTOCOL_SOCKS5])
+ result = append_servers_to_proxy_string(result,
+ servers[PACRUNNER_PROTOCOL_SOCKS5]);
+
+ return result;
+ }
+
/* if the protocol is known, we will prefer to set same
* protocol-based proxies first, if any... */
if (proto >= PACRUNNER_PROTOCOL_HTTP &&
diff --git a/unit/suite/manual_basic.test b/unit/suite/manual_basic.test
index 4406d9c..eeb9373 100644
--- a/unit/suite/manual_basic.test
+++ b/unit/suite/manual_basic.test
@@ -24,3 +24,5 @@ https://bar.net/?property=true bar.net
PROXY secproxy.internal.com; PROXY proxy.internal.com; SOCKS4
sockproxy.internal.com
socks4://sockaccess.external.net:8888/sock_script sockaccess.external.net
SOCKS4 sockproxy.internal.com; PROXY proxy.internal.com; PROXY
secproxy.internal.com
+smtp://mail.client.com/drafts mail.client.com
+SOCKS4 sockproxy.internal.com
diff --git a/unit/suite/manual_exclude.test b/unit/suite/manual_exclude.test
index 211ae16..95b2599 100644
--- a/unit/suite/manual_exclude.test
+++ b/unit/suite/manual_exclude.test
@@ -33,3 +33,5 @@ trivial.co.uk:2984 trivial.co.uk
DIRECT
http://failed.com:99999/ failed.com
DIRECT
+imap://imap.session.com/id=inbox imap.session.com
+SOCKS4 sockproxy.internal.com
--
2.5.5
------------------------------
Message: 2
Date: Sun, 7 Aug 2016 13:41:28 +0530
From: Atul Anand <[email protected]>
To: [email protected]
Subject: [PATCH 2/2] proxy: support for non browser schemes in 'auto'
mode
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
PacRunner is obtaining PAC file from the network for the use of all
clients. Though PAC files are usually written for browser protocols
and browsers have already support for. To be fair towards all clients
add a new key "NonBrowser" on DBus interface as an string array and
should be provided when there is a request for proxy from URL with non
browser scheme.
---
doc/manager-api.txt | 8 +++
doc/manual-configuration.txt | 4 ++
src/manager.c | 8 ++-
src/pacrunner.h | 4 +-
src/proxy.c | 125 +++++++++++++++++++++++++++++++++++++----
unit/suite/manual_basic.test | 2 +
unit/suite/manual_exclude.test | 2 +
unit/suite/pac_basic.test | 5 ++
unit/suite/pac_direct.test | 2 +
unit/suite/proxy_domain.test | 2 +
unit/suite/stub.test | 3 +
unit/test-mozjs.c | 8 +--
unit/test-pacrunner.c | 40 ++++++++++---
13 files changed, 185 insertions(+), 28 deletions(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index 9e6209d..a83bd0a 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -74,6 +74,14 @@ Methods object CreateProxyConfiguration(dict
settings)
This value is needed for dnsResolve function
in PAC files.
+ array{string} NonBrowser [optional]
+
+ List of Proxy servers for Non Browser Sessions
+ (eg: smtp, imap connection requests). This value
+ is valid in method 'auto' where you want proxies
+ for non browser clients (Which a PAC Script
can't
+ fulfill).
+
On successful configuration of this method returns
an object path that uniquely identifies this specific
configuration.
diff --git a/doc/manual-configuration.txt b/doc/manual-configuration.txt
index 8584ad6..6d6b653 100644
--- a/doc/manual-configuration.txt
+++ b/doc/manual-configuration.txt
@@ -57,6 +57,10 @@ the other.
So when a proxy server is given without a protocol, it will set a generic
proxy server and this will be the only way.
+If requested URL has an unknown scheme (e.g: imap://) only socks proxy is ret-
+urned (if stored) otherwise DIRECT in manual mode. In auto mode there is a key
+NonBrowser which Network Managers can fill to be replied for the unknown
scheme.
+
How Excludes list apply:
-----------------------
diff --git a/src/manager.c b/src/manager.c
index 5a8b4fd..d293409 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -142,6 +142,7 @@ static DBusMessage *create_proxy_config(DBusConnection
*conn,
const char *url = NULL, *script = NULL;
char **servers = NULL, **excludes = NULL;
char **domains = NULL, **nameservers = NULL;
+ char **nonbrowser = NULL;
sender = dbus_message_get_sender(msg);
@@ -197,6 +198,9 @@ static DBusMessage *create_proxy_config(DBusConnection
*conn,
} else if (g_str_equal(key, "Nameservers")) {
g_strfreev(nameservers);
nameservers = extract_string_array(&list);
+ } else if (g_str_equal(key, "NonBrowser")) {
+ g_strfreev(nonbrowser);
+ nonbrowser = extract_string_array(&list);
}
break;
}
@@ -237,7 +241,8 @@ static DBusMessage *create_proxy_config(DBusConnection
*conn,
servers, excludes) < 0)
pacrunner_error("Failed to set proxy servers");
} else if (g_str_equal(method, "auto")) {
- if (pacrunner_proxy_set_auto(config->proxy, url, script) < 0)
+ if (pacrunner_proxy_set_auto(config->proxy, url,
+ script, nonbrowser) < 0)
pacrunner_error("Failed to set auto proxy");
} else {
destroy_config(config);
@@ -256,6 +261,7 @@ static DBusMessage *create_proxy_config(DBusConnection
*conn,
done:
g_strfreev(servers);
g_strfreev(excludes);
+ g_strfreev(nonbrowser);
g_strfreev(domains);
g_strfreev(nameservers);
diff --git a/src/pacrunner.h b/src/pacrunner.h
index 87c51da..7740097 100644
--- a/src/pacrunner.h
+++ b/src/pacrunner.h
@@ -68,8 +68,8 @@ int pacrunner_proxy_set_domains(struct pacrunner_proxy *proxy,
int pacrunner_proxy_set_direct(struct pacrunner_proxy *proxy);
int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy,
char **servers, char **excludes);
-int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
- const char *url, const char *script);
+int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy, const char *url,
+ const char *script, char **nonbrowser);
int pacrunner_proxy_enable(struct pacrunner_proxy *proxy);
int pacrunner_proxy_disable(struct pacrunner_proxy *proxy);
diff --git a/src/proxy.c b/src/proxy.c
index db49c58..ac51f7d 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -41,6 +41,7 @@ struct pacrunner_proxy {
GList **servers;
GList **excludes;
GList *domains;
+ GList *nonbrowser;
void *jsctx;
};
@@ -135,6 +136,9 @@ void pacrunner_proxy_unref(struct pacrunner_proxy *proxy)
g_list_free_full(proxy->domains, proxy_domain_destroy);
proxy->domains = NULL;
+ g_list_free_full(proxy->nonbrowser, g_free);
+ proxy->nonbrowser = NULL;
+
g_free(proxy->interface);
g_free(proxy);
}
@@ -234,6 +238,91 @@ int pacrunner_proxy_set_domains(struct pacrunner_proxy
*proxy, char **domains)
return 0;
}
+static int pacrunner_proxy_set_non_browser_servers(struct pacrunner_proxy
+ *proxy, char **nonbrowser)
+{
+ char **iter;
+
+ DBG("proxy %p nonbrowser %p", proxy, nonbrowser);
+
+ if (!proxy)
+ return -EINVAL;
+
+ g_list_free_full(proxy->nonbrowser, g_free);
+ proxy->nonbrowser = NULL;
+
+ if (!nonbrowser)
+ return 0;
+
+ for (iter = nonbrowser; *iter; iter++) {
+ char *tmp = NULL, *server = NULL, *slash = NULL;
+
+ DBG("proxy %p nonbrowser %s", proxy, *iter);
+
+ /* Extract Proxy host & port */
+ tmp = strstr(*iter, "://");
+ if (tmp)
+ tmp = tmp + 3;
+ else
+ tmp = *iter;
+
+ slash = strchr(tmp, '/');
+ if (slash)
+ server = g_strndup(tmp, slash - tmp);
+
+ proxy->nonbrowser = g_list_append(proxy->nonbrowser,
+ g_strdup_printf("PROXY %s", server ? server : tmp));
+
+ g_free(server);
+ }
+
+ return 0;
+}
+
+static gboolean check_browser_protocol(const char *url)
+{
+ static const char *browser_schemes[] = {
+ "http://",
+ "https://",
+ "ftp://",
+ "nntp://",
+ "nntps://",
+ };
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS(browser_schemes); i++) {
+ if (strncmp(browser_schemes[i], url,
+ strlen(browser_schemes[i])) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static char *non_browser_proxies(struct pacrunner_proxy *proxy,
+ const char *url)
+{
+ GList *iter = NULL;
+ char *proxy_string = NULL;
+
+ for (iter = g_list_first(proxy->nonbrowser); iter;
+ iter = g_list_next(iter)) {
+ char *tmp = proxy_string;
+
+ if (tmp) {
+ proxy_string = g_strdup_printf("%s; %s", tmp,
+ (char *) iter->data);
+ } else {
+ proxy_string = g_strdup_printf("%s",
+ (char *) iter->data);
+ }
+
+ g_free(tmp);
+ }
+
+ return proxy_string;
+}
+
static int set_method(struct pacrunner_proxy *proxy,
enum pacrunner_proxy_method method)
{
@@ -303,30 +392,30 @@ static void download_callback(char *content, void
*user_data)
DBG("url %s content %p", proxy->url, content);
- if (!content) {
+ if (content) {
+ g_free(proxy->script);
+ proxy->script = content;
+ } else
pacrunner_error("Failed to retrieve PAC script");
- goto done;
- }
- g_free(proxy->script);
- proxy->script = content;
-
- pacrunner_proxy_enable(proxy);
+ if (proxy->script || proxy->nonbrowser)
+ pacrunner_proxy_enable(proxy);
+ else
+ pacrunner_proxy_unref(proxy);
-done:
pthread_mutex_lock(&proxy_mutex);
proxy_updating--;
pthread_cond_broadcast(&proxy_cond);
pthread_mutex_unlock(&proxy_mutex);
- pacrunner_proxy_unref(proxy);
}
int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
- const char *url, const char *script)
+ const char *url, const char *script, char **nonbrowser)
{
int err;
- DBG("proxy %p url %s script %p", proxy, url, script);
+ DBG("proxy %p url %s script %p nonbrowser %p", proxy, url,
+ script, nonbrowser);
if (!proxy)
return -EINVAL;
@@ -335,6 +424,15 @@ int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
if (err < 0)
return err;
+ g_list_free_full(proxy->nonbrowser, g_free);
+ proxy->nonbrowser = NULL;
+
+ if (nonbrowser) {
+ if (pacrunner_proxy_set_non_browser_servers(proxy,
+ nonbrowser) < 0)
+ pacrunner_error("Failed to Set Non Browser Servers");
+ }
+
g_free(proxy->url);
proxy->url = g_strdup(url);
@@ -357,7 +455,6 @@ int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
err = __pacrunner_download_update(proxy->interface, proxy->url,
download_callback, proxy);
if (err < 0) {
- pacrunner_proxy_unref(proxy);
if (proxy_updating == -1) {
proxy_updating = 0;
pthread_cond_broadcast(&proxy_cond);
@@ -577,7 +674,11 @@ found:
return __pacrunner_manual_execute(url, host,
selected_proxy->servers,
selected_proxy->excludes);
+ break;
case PACRUNNER_PROXY_METHOD_AUTO:
+ if (!check_browser_protocol(url))
+ return non_browser_proxies(selected_proxy, url);
+
return __pacrunner_js_execute(selected_proxy, url, host);
}
diff --git a/unit/suite/manual_basic.test b/unit/suite/manual_basic.test
index eeb9373..6e6d65d 100644
--- a/unit/suite/manual_basic.test
+++ b/unit/suite/manual_basic.test
@@ -12,6 +12,8 @@ socks4://sockproxy.internal.com
[domains]
+[nonbrowser]
+
[config]
VALID
diff --git a/unit/suite/manual_exclude.test b/unit/suite/manual_exclude.test
index 95b2599..71b8b67 100644
--- a/unit/suite/manual_exclude.test
+++ b/unit/suite/manual_exclude.test
@@ -17,6 +17,8 @@ tri*
[domains]
+[nonbrowser]
+
[config]
VALID
diff --git a/unit/suite/pac_basic.test b/unit/suite/pac_basic.test
index c63757e..97a8c4f 100644
--- a/unit/suite/pac_basic.test
+++ b/unit/suite/pac_basic.test
@@ -19,9 +19,14 @@ function FindProxyForURL(url, host)
[domains]
+[nonbrowser]
+imap://imap.proxy.internal.com
+
[config]
VALID
[tests]
http://www.example.com/site/test.html www.example.com
PROXY proxy.example.com
+imap://mail.google.com/inbox mail.google.com
+PROXY imap.proxy.internal.com
diff --git a/unit/suite/pac_direct.test b/unit/suite/pac_direct.test
index b820abc..fc2b880 100644
--- a/unit/suite/pac_direct.test
+++ b/unit/suite/pac_direct.test
@@ -13,6 +13,8 @@ function FindProxyForURL(url, host)
[domains]
+[nonbrowser]
+
[config]
VALID
diff --git a/unit/suite/proxy_domain.test b/unit/suite/proxy_domain.test
index 8c2c5e4..c808f69 100644
--- a/unit/suite/proxy_domain.test
+++ b/unit/suite/proxy_domain.test
@@ -13,6 +13,8 @@ suite.com
test.suite.com
172.132.231.6/24
+[nonbrowser]
+
[config]
VALID
diff --git a/unit/suite/stub.test b/unit/suite/stub.test
index cde0aeb..4ebbd73 100644
--- a/unit/suite/stub.test
+++ b/unit/suite/stub.test
@@ -14,6 +14,9 @@ Stub suite file
[domains]
# List of domains are here
+[nonbrowser]
+# List of proxy servers for non browser clients
+
[config]
#?Result of the configuration: VALID or INVALID
diff --git a/unit/test-mozjs.c b/unit/test-mozjs.c
index 7ccdee9..dbaabe2 100644
--- a/unit/test-mozjs.c
+++ b/unit/test-mozjs.c
@@ -125,7 +125,7 @@ static void test_single_execute_with_direct_pac(void)
g_assert(mozjs_init() == 0);
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC) == 0);
+ g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC, NULL) == 0);
result = __pacrunner_js_execute(proxy, EXAMPLE_URL, EXAMPLE_HOST);
g_test_message("result: %s", result);
@@ -142,7 +142,7 @@ static void test_multiple_execute_with_direct_pac(void)
mozjs_init();
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC) == 0);
+ g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC, NULL) == 0);
for (i = 0; i < MULTIPLE_COUNT; i++) {
result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
@@ -162,7 +162,7 @@ static void test_massive_execute_with_direct_pac(void)
mozjs_init();
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC) == 0);
+ g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC, NULL) == 0);
for (i = 0; i < MASSIVE_COUNT; i++) {
result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
@@ -182,7 +182,7 @@ static void test_multiple_execute_with_example_pac(void)
mozjs_init();
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, EXAMPLE_PAC) == 0);
+ g_assert(pacrunner_proxy_set_auto(proxy, NULL, EXAMPLE_PAC, NULL) == 0);
for (i = 0; i < MULTIPLE_COUNT; i++) {
result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
diff --git a/unit/test-pacrunner.c b/unit/test-pacrunner.c
index 0c4ac69..5ddac38 100644
--- a/unit/test-pacrunner.c
+++ b/unit/test-pacrunner.c
@@ -38,14 +38,15 @@
#include "pacrunner.h"
enum test_suite_part {
- SUITE_TITLE = 0,
- SUITE_PAC = 1,
- SUITE_SERVERS = 2,
- SUITE_EXCLUDES = 3,
- SUITE_DOMAINS = 4,
- SUITE_CONFIG = 5,
- SUITE_TESTS = 6,
- SUITE_NOTHING = 7,
+ SUITE_TITLE = 0,
+ SUITE_PAC = 1,
+ SUITE_SERVERS = 2,
+ SUITE_EXCLUDES = 3,
+ SUITE_DOMAINS = 4,
+ SUITE_NON_BROWSER = 5,
+ SUITE_CONFIG = 6,
+ SUITE_TESTS = 7,
+ SUITE_NOTHING = 8,
};
enum cu_test_mode {
@@ -60,6 +61,7 @@ struct pacrunner_test_suite {
gchar **servers;
gchar **excludes;
gchar **domains;
+ gchar **nonbrowser;
bool config_result;
@@ -82,6 +84,7 @@ static void free_pacrunner_test_suite(struct
pacrunner_test_suite *suite)
g_strfreev(suite->servers);
g_strfreev(suite->excludes);
g_strfreev(suite->domains);
+ g_strfreev(suite->nonbrowser);
g_strfreev(suite->tests);
g_free(suite);
@@ -152,6 +155,13 @@ static void print_test_suite(struct pacrunner_test_suite
*suite)
} else
printf("(none)\n");
+ printf("\nNonBrowser:\n");
+ if (suite->nonbrowser) {
+ for (line = suite->nonbrowser; *line; line++)
+ printf("%s\n", *line);
+ } else
+ printf("(none)\n");
+
printf("\nConfig result: %s\n",
suite->config_result ? "Valid" : "Invalid");
@@ -259,6 +269,15 @@ static struct pacrunner_test_suite *read_test_suite(const
char *path)
suite->domains = array;
break;
+ case SUITE_NON_BROWSER:
+ array = _g_strappendv(suite->nonbrowser, *line);
+ if (!array)
+ goto error;
+
+ g_free(suite->nonbrowser);
+ suite->nonbrowser = array;
+
+ break;
case SUITE_CONFIG:
if (strncmp(*line, "VALID", 5) == 0)
suite->config_result = true;
@@ -293,6 +312,8 @@ static struct pacrunner_test_suite *read_test_suite(const
char *path)
part = SUITE_EXCLUDES;
else if (strncmp(*line, "[domains]", 9) == 0)
part = SUITE_DOMAINS;
+ else if (strncmp(*line, "[nonbrowser]", 12) == 0)
+ part = SUITE_NON_BROWSER;
else if (strncmp(*line, "[config]", 8) == 0)
part = SUITE_CONFIG;
else if (strncmp(*line, "[tests]", 7) == 0)
@@ -344,7 +365,8 @@ static int test_suite_cleanup(void)
static void test_pac_config(void)
{
- if (pacrunner_proxy_set_auto(proxy, NULL, test_suite->pac) == 0)
+ if (pacrunner_proxy_set_auto(proxy, NULL, test_suite->pac,
+ test_suite->nonbrowser) == 0)
test_config = true;
CU_ASSERT_TRUE(test_suite->config_result == test_config);
--
2.5.5
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 10, Issue 2
**************************************