summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2023-02-07 08:23:06 +0100
committerJan-Michael Brummer <jan.brummer@tabos.org>2023-03-27 16:31:58 +0200
commit9376b17ba95e0e592719e23bf6a350c8205c0172 (patch)
treeb90d9df453c0e43d910a5f0278ca91b027968455
parentde336fbccf6a1b617cbfae20f66ed85a3dcf8a45 (diff)
downloadlibproxy-git-9376b17ba95e0e592719e23bf6a350c8205c0172.tar.gz
Cleanup config plugins (#50)
-rw-r--r--src/backend/plugins/config-env/config-env.c10
-rw-r--r--src/backend/plugins/config-env/config-env.h3
-rw-r--r--src/backend/plugins/config-env/config-env.plugin6
-rw-r--r--src/backend/plugins/config-env/meson.build1
-rw-r--r--src/backend/plugins/config-gnome/config-gnome.c20
-rw-r--r--src/backend/plugins/config-gnome/config-gnome.h2
-rw-r--r--src/backend/plugins/config-gnome/config-gnome.plugin3
-rw-r--r--src/backend/plugins/config-gnome/meson.build1
-rw-r--r--src/backend/plugins/config-kde/config-kde.c7
-rw-r--r--src/backend/plugins/config-kde/config-kde.h3
-rw-r--r--src/backend/plugins/config-kde/config-kde.plugin3
-rw-r--r--src/backend/plugins/config-kde/meson.build1
-rw-r--r--src/backend/plugins/config-osx/config-osx.c141
-rw-r--r--src/backend/plugins/config-osx/config-osx.h2
-rw-r--r--src/backend/plugins/config-osx/config-osx.plugin3
-rw-r--r--src/backend/plugins/config-osx/meson.build3
-rw-r--r--src/backend/plugins/config-sysconfig/config-sysconfig.c4
-rw-r--r--src/backend/plugins/config-sysconfig/config-sysconfig.h3
-rw-r--r--src/backend/plugins/config-sysconfig/config-sysconfig.plugin3
-rw-r--r--src/backend/plugins/config-sysconfig/meson.build1
-rw-r--r--src/backend/plugins/config-windows/config-windows.c60
-rw-r--r--src/backend/plugins/config-windows/config-windows.h2
-rw-r--r--src/backend/plugins/config-windows/config-windows.plugin3
-rw-r--r--src/backend/plugins/config-windows/meson.build1
-rw-r--r--src/backend/px-manager.c2
-rw-r--r--src/tests/config-env-test.c21
-rw-r--r--src/tests/config-gnome-test.c99
-rw-r--r--src/tests/config-kde-test.c38
-rw-r--r--src/tests/config-sysconfig-test.c12
-rw-r--r--src/tests/data/sample-sysconfig-proxy1
30 files changed, 366 insertions, 93 deletions
diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c
index e98ad52..bec1d72 100644
--- a/src/backend/plugins/config-env/config-env.c
+++ b/src/backend/plugins/config-env/config-env.c
@@ -1,6 +1,6 @@
/* config-env.c
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,8 +23,8 @@
#include "config-env.h"
-#include "px-plugin-config.h"
#include "px-manager.h"
+#include "px-plugin-config.h"
static void px_config_iface_init (PxConfigInterface *iface);
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
@@ -102,10 +102,6 @@ px_config_env_get_config (PxConfig *config,
const char *proxy = NULL;
const char *scheme = g_uri_get_scheme (uri);
- /* TODO:
- * - Are host names resolved to IPs??
- * - case insensitive check?
- */
if (self->no_proxy && (g_strv_contains ((const char * const *)self->no_proxy, g_uri_get_host (uri)) || g_strv_contains ((const char * const *)self->no_proxy, "*"))) {
return;
}
@@ -115,11 +111,9 @@ px_config_env_get_config (PxConfig *config,
else if (g_strcmp0 (scheme, "https") == 0)
proxy = self->https_proxy;
- /* TODO: Is this what we want as a fallback? What about ALL_PROXY? */
if (!proxy)
proxy = self->http_proxy;
- /* TODO: Where should we add proxy url validation ? */
if (proxy)
g_strv_builder_add (builder, proxy);
}
diff --git a/src/backend/plugins/config-env/config-env.h b/src/backend/plugins/config-env/config-env.h
index 7d31d4e..6b654bd 100644
--- a/src/backend/plugins/config-env/config-env.h
+++ b/src/backend/plugins/config-env/config-env.h
@@ -1,6 +1,6 @@
/* config-env.h
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,6 @@
#pragma once
#include <glib.h>
-#include <libpeas/peas.h>
G_BEGIN_DECLS
diff --git a/src/backend/plugins/config-env/config-env.plugin b/src/backend/plugins/config-env/config-env.plugin
index 34b3049..2dfbdf3 100644
--- a/src/backend/plugins/config-env/config-env.plugin
+++ b/src/backend/plugins/config-env/config-env.plugin
@@ -1,7 +1,3 @@
[Plugin]
-Authors=Jan-Michael Brummer <jan.brummer@tabos.org>
-Copyright=Copyright © 2023 Jan-Michael Brummer
-Description=Read proxy configuration from environment variables
Module=config-env
-Name=Environment Variables
-Builtin=True \ No newline at end of file
+Name=Environment Variables \ No newline at end of file
diff --git a/src/backend/plugins/config-env/meson.build b/src/backend/plugins/config-env/meson.build
index 9496775..471ecc0 100644
--- a/src/backend/plugins/config-env/meson.build
+++ b/src/backend/plugins/config-env/meson.build
@@ -14,6 +14,7 @@ plugin_lib = shared_module(
plugin_name,
sources: plugin_src,
include_directories: px_backend_inc,
+ c_args: px_backend_c_args,
dependencies: [px_backend_dep],
install_dir: join_paths(px_plugins_dir, plugin_name),
install: true,
diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c
index 053544d..f5c8008 100644
--- a/src/backend/plugins/config-gnome/config-gnome.c
+++ b/src/backend/plugins/config-gnome/config-gnome.c
@@ -1,6 +1,6 @@
/* config-gnome.c
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*/
#include <libpeas/peas.h>
-#include <glib.h>
#include "config-gnome.h"
+
#include "px-plugin-config.h"
struct _PxConfigGnome {
@@ -35,11 +35,11 @@ struct _PxConfigGnome {
gboolean settings_found;
};
-enum {
+typedef enum {
GNOME_PROXY_MODE_NONE,
GNOME_PROXY_MODE_MANUAL,
GNOME_PROXY_MODE_AUTO
-};
+} GnomeProxyMode;
static void px_config_iface_init (PxConfigInterface *iface);
void peas_register_types (PeasObjectModule *module);
@@ -104,8 +104,8 @@ store_response (GStrvBuilder *builder,
char *username,
char *password)
{
- if (host && port != 0) {
- GString *tmp = g_string_new (type);
+ if (type && host && port != 0) {
+ g_autoptr (GString) tmp = g_string_new (type);
g_string_append (tmp, "://");
if (auth)
@@ -113,7 +113,7 @@ store_response (GStrvBuilder *builder,
g_string_append_printf (tmp, "%s:%d", host, port);
- g_strv_builder_add (builder, g_string_free (tmp, FALSE));
+ g_strv_builder_add (builder, tmp->str);
}
}
@@ -124,7 +124,7 @@ px_config_gnome_get_config (PxConfig *config,
{
PxConfigGnome *self = PX_CONFIG_GNOME (config);
g_autofree char *proxy = NULL;
- int mode;
+ GnomeProxyMode mode;
mode = g_settings_get_enum (self->proxy_settings, "mode");
if (mode == GNOME_PROXY_MODE_AUTO) {
@@ -137,10 +137,10 @@ px_config_gnome_get_config (PxConfig *config,
g_strv_builder_add (builder, proxy);
} else if (mode == GNOME_PROXY_MODE_MANUAL) {
- gboolean auth = g_settings_get_boolean (self->http_proxy_settings, "use-authentication");
g_autofree char *username = g_settings_get_string (self->http_proxy_settings, "authentication-user");
g_autofree char *password = g_settings_get_string (self->http_proxy_settings, "authentication-password");
const char *scheme = g_uri_get_scheme (uri);
+ gboolean auth = g_settings_get_boolean (self->http_proxy_settings, "use-authentication");
if (g_strcmp0 (scheme, "http") == 0) {
g_autofree char *host = g_settings_get_string (self->http_proxy_settings, "host");
@@ -174,7 +174,7 @@ px_config_gnome_get_config (PxConfig *config,
store_response (builder,
"socks",
host,
- g_settings_get_int (self->ftp_proxy_settings, "port"),
+ g_settings_get_int (self->socks_proxy_settings, "port"),
auth,
username,
password);
diff --git a/src/backend/plugins/config-gnome/config-gnome.h b/src/backend/plugins/config-gnome/config-gnome.h
index 53402e9..c5e8c6e 100644
--- a/src/backend/plugins/config-gnome/config-gnome.h
+++ b/src/backend/plugins/config-gnome/config-gnome.h
@@ -1,6 +1,6 @@
/* config-gnome.h
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/src/backend/plugins/config-gnome/config-gnome.plugin b/src/backend/plugins/config-gnome/config-gnome.plugin
index 2b3f442..5121ceb 100644
--- a/src/backend/plugins/config-gnome/config-gnome.plugin
+++ b/src/backend/plugins/config-gnome/config-gnome.plugin
@@ -1,6 +1,3 @@
[Plugin]
-Authors=Jan-Michael Brummer <jan.brummer@tabos.org>
-Copyright=Copyright © 2023 Jan-Michael Brummer
-Description=Read proxy configuration from GNOME settings
Module=config-gnome
Name=GNOME Settings \ No newline at end of file
diff --git a/src/backend/plugins/config-gnome/meson.build b/src/backend/plugins/config-gnome/meson.build
index ba99418..08acc1c 100644
--- a/src/backend/plugins/config-gnome/meson.build
+++ b/src/backend/plugins/config-gnome/meson.build
@@ -14,6 +14,7 @@ plugin_lib = shared_module(
plugin_name,
plugin_src,
include_directories: px_backend_inc,
+ c_args: px_backend_c_args,
dependencies: [peas_dep, px_backend_dep],
install_dir: join_paths(px_plugins_dir, plugin_name),
install: true,
diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c
index 917ccd2..3fb6d1c 100644
--- a/src/backend/plugins/config-kde/config-kde.c
+++ b/src/backend/plugins/config-kde/config-kde.c
@@ -1,6 +1,6 @@
/* config-kde.c
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -66,16 +66,15 @@ px_config_kde_read_config (PxConfigKde *self,
g_autoptr (GFileInputStream) istr = NULL;
g_autoptr (GDataInputStream) dstr = NULL;
-
file = g_file_new_for_path (proxy_file);
if (!file) {
- g_print ("Could not create file\n");
+ g_debug ("%s: Could not create file", __FUNCTION__);
return;
}
istr = g_file_read (file, NULL, NULL);
if (!istr) {
- g_print ("Could not read file\n");
+ g_debug ("%s: Could not read file", __FUNCTION__);
return;
}
diff --git a/src/backend/plugins/config-kde/config-kde.h b/src/backend/plugins/config-kde/config-kde.h
index 408b28a..892c45a 100644
--- a/src/backend/plugins/config-kde/config-kde.h
+++ b/src/backend/plugins/config-kde/config-kde.h
@@ -1,6 +1,6 @@
/* config-kde.h
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,6 @@
#pragma once
#include <glib.h>
-#include <libpeas/peas.h>
G_BEGIN_DECLS
diff --git a/src/backend/plugins/config-kde/config-kde.plugin b/src/backend/plugins/config-kde/config-kde.plugin
index b8aabab..d03d2a8 100644
--- a/src/backend/plugins/config-kde/config-kde.plugin
+++ b/src/backend/plugins/config-kde/config-kde.plugin
@@ -1,6 +1,3 @@
[Plugin]
-Authors=Jan-Michael Brummer <jan.brummer@tabos.org>
-Copyright=Copyright © 2023 Jan-Michael Brummer
-Description=Read proxy configuration from KDE System Settings
Module=config-kde
Name=KDE \ No newline at end of file
diff --git a/src/backend/plugins/config-kde/meson.build b/src/backend/plugins/config-kde/meson.build
index 109e5db..ef4adfe 100644
--- a/src/backend/plugins/config-kde/meson.build
+++ b/src/backend/plugins/config-kde/meson.build
@@ -14,6 +14,7 @@ plugin_lib = shared_module(
plugin_name,
sources: plugin_src,
include_directories: px_backend_inc,
+ c_args: px_backend_c_args,
dependencies: [px_backend_dep],
install_dir: join_paths(px_plugins_dir, plugin_name),
install: true,
diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c
index e6192e9..08b87c3 100644
--- a/src/backend/plugins/config-osx/config-osx.c
+++ b/src/backend/plugins/config-osx/config-osx.c
@@ -1,6 +1,6 @@
/* config-osx.c
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -91,6 +91,37 @@ getobj_str (CFDictionaryRef settings,
return retval;
}
+static CFArrayRef
+getobj_array (CFDictionaryRef settings,
+ char *key)
+{
+ CFStringRef k;
+ CFArrayRef retval;
+
+ if (!settings)
+ return NULL;
+
+ k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman);
+ if (!k)
+ return NULL;
+
+ retval = (CFArrayRef)CFDictionaryGetValue (settings, k);
+
+ CFRelease (k);
+ return retval;
+}
+
+static char *
+str (CFStringRef ref)
+{
+ CFIndex size = CFStringGetLength (ref) + 1;
+ char *ret = g_malloc0 (size);
+
+ CFStringGetCString (ref, ret, size, kCFStringEncodingUTF8);
+
+ return ret;
+}
+
static gboolean
getint (CFDictionaryRef settings,
char *key,
@@ -119,6 +150,94 @@ getbool (CFDictionaryRef settings,
return i != 0;
}
+static char *
+str_to_upper (const char *str)
+{
+ char *ret = NULL;
+ int idx;
+
+ if (!str)
+ return NULL;
+
+ ret = g_malloc0 (strlen (str) + 1);
+
+ for (idx = 0; idx < strlen (str); idx++)
+ ret[idx] = g_ascii_toupper (str[idx]);
+
+ return ret;
+}
+
+static char *
+protocol_url (CFDictionaryRef settings,
+ char *protocol)
+{
+ g_autofree char *tmp = NULL;
+ g_autoptr (GString) ret = NULL;
+ g_autofree char *host = NULL;
+ int64_t port;
+ CFStringRef ref;
+
+ /* Check ProtocolEnabled */
+ tmp = g_strconcat (protocol, "Enable", NULL);
+ if (!getbool (settings, tmp)) {
+ g_debug ("%s: %s not set", __FUNCTION__, tmp);
+ return NULL;
+ }
+ g_clear_pointer (&tmp, g_free);
+
+ /* Get ProtocolPort */
+ tmp = g_strconcat (protocol, "Port", NULL);
+ getint (settings, tmp, &port);
+ if (!port) {
+ g_debug ("%s: %s not set", __FUNCTION__, tmp);
+ return NULL;
+ }
+ g_clear_pointer (&tmp, g_free);
+
+ /* Get ProtocolProxy */
+ tmp = g_strconcat (protocol, "Proxy", NULL);
+ ref = getobj_str (settings, tmp);
+ g_clear_pointer (&tmp, g_free);
+
+ host = str (ref);
+ if (!host || strlen (host) == 0)
+ return NULL;
+
+ if (strcmp (protocol, "HTTP") == 0 || strcmp (protocol, "HTTPS") == 0 || strcmp (protocol, "FTP") == 0 || strcmp (protocol, "Gopher") == 0)
+ ret = g_string_new ("http://");
+ else if (strcmp (protocol, "RTSP") == 0)
+ ret = g_string_new ("rtsp://");
+ else if (strcmp (protocol, "SOCKS") == 0)
+ ret = g_string_new ("socks://");
+ else
+ return NULL;
+
+ g_string_append_printf (ret, "%s:%lld", host, port);
+
+ return g_strdup (ret->str);
+}
+
+static GStrv
+get_ignore_list (CFDictionaryRef proxies)
+{
+ CFArrayRef ref = getobj_array (proxies, "ExceptionsList");
+ g_autoptr (GStrvBuilder) ret = g_strv_builder_new ();
+
+ if (!ref)
+ return g_strv_builder_end (ret);
+
+ for (int idx = 0; idx < CFArrayGetCount (ref); idx++) {
+ CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex (ref, idx);
+
+ g_strv_builder_add (ret, str (s));
+ }
+
+ if (getbool (proxies, "ExcludeSimpleHostnames"))
+ g_strv_builder_add (ret, "127.0.0.1");
+
+ return g_strv_builder_end (ret);
+}
+
static void
px_config_osx_get_config (PxConfig *self,
GUri *uri,
@@ -126,12 +245,18 @@ px_config_osx_get_config (PxConfig *self,
{
const char *proxy = NULL;
CFDictionaryRef proxies = SCDynamicStoreCopyProxies (NULL);
+ g_auto (GStrv) ignore_list = NULL;
if (!proxies) {
g_warning ("Unable to fetch proxy configuration");
return;
}
+ ignore_list = get_ignore_list (proxies);
+
+ if (ignore_list && g_strv_contains ((const char * const *)ignore_list, g_uri_get_host (uri)))
+ return;
+
if (getbool (proxies, "ProxyAutoDiscoveryEnable")) {
CFRelease (proxies);
g_strv_builder_add (builder, "wpad://");
@@ -140,7 +265,7 @@ px_config_osx_get_config (PxConfig *self,
if (getbool (proxies, "ProxyAutoConfigEnable")) {
CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString");
- const char *tmp = CFStringGetCStringPtr (ref, CFStringGetFastestEncoding (ref));
+ g_autofree char *tmp = str (ref);
GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL);
if (tmp_uri) {
@@ -149,9 +274,19 @@ px_config_osx_get_config (PxConfig *self,
g_strv_builder_add (builder, ret);
return;
}
+ } else {
+ const char *scheme = g_uri_get_scheme (uri);
+ g_autofree char *capital_scheme = str_to_upper (scheme);
+
+ proxy = protocol_url (proxies, capital_scheme);
+
+ if (!proxy)
+ proxy = protocol_url (proxies, "HTTP");
+
+ if (!proxy)
+ proxy = protocol_url (proxies, "SOCKS");
}
- g_print ("%s: Whatever", __FUNCTION__);
if (proxy)
g_strv_builder_add (builder, proxy);
}
diff --git a/src/backend/plugins/config-osx/config-osx.h b/src/backend/plugins/config-osx/config-osx.h
index 62e71ca..544329f 100644
--- a/src/backend/plugins/config-osx/config-osx.h
+++ b/src/backend/plugins/config-osx/config-osx.h
@@ -1,6 +1,6 @@
/* config-osx.h
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/src/backend/plugins/config-osx/config-osx.plugin b/src/backend/plugins/config-osx/config-osx.plugin
index 25e4bdd..61c4a2a 100644
--- a/src/backend/plugins/config-osx/config-osx.plugin
+++ b/src/backend/plugins/config-osx/config-osx.plugin
@@ -1,6 +1,3 @@
[Plugin]
-Authors=Jan-Michael Brummer <jan.brummer@tabos.org>
-Copyright=Copyright © 2023 Jan-Michael Brummer
-Description=Read proxy configuration from OS X
Module=config-osx
Name=OS X \ No newline at end of file
diff --git a/src/backend/plugins/config-osx/meson.build b/src/backend/plugins/config-osx/meson.build
index 4435bbf..eac98e8 100644
--- a/src/backend/plugins/config-osx/meson.build
+++ b/src/backend/plugins/config-osx/meson.build
@@ -16,6 +16,7 @@ plugin_lib = shared_module(
plugin_name,
plugin_src,
include_directories: px_backend_inc,
+ c_args: px_backend_c_args,
dependencies: [px_backend_dep],
install_dir: join_paths(px_plugins_dir, plugin_name),
install: true,
@@ -35,4 +36,4 @@ custom_target(
endif
-endif \ No newline at end of file
+endif
diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c
index d05eb39..77c7fe1 100644
--- a/src/backend/plugins/config-sysconfig/config-sysconfig.c
+++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c
@@ -1,6 +1,6 @@
/* config-sysconfig.c
*
- * Copyright 2023 Jan-Michael Brummer
+ * Copyright 2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,8 +23,8 @@
#include "config-sysconfig.h"
-#include "px-plugin-config.h"
#include "px-manager.h"
+#include "px-plugin-config.h"
struct _PxConfigSysConfig {
GObject parent_instance;
diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.h b/src/backend/plugins/config-sysconfig/config-sysconfig.h
index 176da94..daa4672 100644
--- a/src/backend/plugins/config-sysconfig/config-sysconfig.h
+++ b/src/backend/plugins/config-sysconfig/config-sysconfig.h
@@ -1,6 +1,6 @@
/* config-sysconfig.h
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,6 @@
#pragma once
#include <glib.h>
-#include <libpeas/peas.h>
G_BEGIN_DECLS
diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.plugin b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin
index d164295..0697fa2 100644
--- a/src/backend/plugins/config-sysconfig/config-sysconfig.plugin
+++ b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin
@@ -1,6 +1,3 @@
[Plugin]
-Authors=Jan-Michael Brummer <jan.brummer@tabos.org>
-Copyright=Copyright © 2023 Jan-Michael Brummer
-Description=Read proxy configuration from /etc/sysconfig/proxy
Module=config-sysconfig
Name=sysconfig \ No newline at end of file
diff --git a/src/backend/plugins/config-sysconfig/meson.build b/src/backend/plugins/config-sysconfig/meson.build
index d5b3613..2ac17fb 100644
--- a/src/backend/plugins/config-sysconfig/meson.build
+++ b/src/backend/plugins/config-sysconfig/meson.build
@@ -14,6 +14,7 @@ plugin_lib = shared_module(
plugin_name,
plugin_src,
include_directories: px_backend_inc,
+ c_args: px_backend_c_args,
dependencies: [px_backend_dep],
install_dir: join_paths(px_plugins_dir, plugin_name),
install: true,
diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c
index 903c332..c8bc94d 100644
--- a/src/backend/plugins/config-windows/config-windows.c
+++ b/src/backend/plugins/config-windows/config-windows.c
@@ -1,6 +1,6 @@
/* config-windows.c
*
- * Copyright 2022-2023 Jan-Michael Brummer
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -107,6 +107,33 @@ get_registry (const char *key,
return FALSE;
}
+static GHashTable *
+parse_manual (char *manual)
+{
+ g_auto (GStrv) split = NULL;
+ GHashTable *ret = g_hash_table_new (g_str_hash, g_str_equal);
+
+ /* We have to check for two formats:
+ * - 1.2.3.4:8080
+ * - ftp=1.2.4.5:8080;https=1.2.3.4:8080
+ */
+
+ split = g_strsplit (manual, ";", -1);
+ for (int idx = 0; idx < g_strv_length (split); idx++) {
+ if (!strchr (split[idx], '=')) {
+ g_hash_table_insert (ret, (char *)"http", g_strdup_printf ("http://%s", split[idx]));
+ } else {
+ g_auto (GStrv) split_kv = g_strsplit (split[idx], "=", -1);
+
+ if (g_strv_length (split_kv) == 2) {
+ g_hash_table_insert (ret, g_strdup (split_kv[0]), g_strdup_printf ("%s://%s", split_kv[0], split_kv[1]));
+ }
+ }
+ }
+
+ return ret;
+}
+
static gboolean
is_enabled (char type)
{
@@ -132,7 +159,10 @@ px_config_windows_get_config (PxConfig *self,
guint32 enabled = 0;
if (get_registry (W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) {
- g_print ("Override: %s\n", tmp);
+ const char *host = g_uri_get_host (uri);
+
+ if (g_strcmp0 (tmp, "<local>") == 0 && g_strcmp0 (host, "127.0.0.1") == 0)
+ return;
}
/* WPAD */
@@ -154,10 +184,28 @@ px_config_windows_get_config (PxConfig *self,
/* Manual proxy */
if (get_registry (W32REG_BASEKEY, "ProxyEnable", NULL, NULL, &enabled) && enabled && get_registry (W32REG_BASEKEY, "ProxyServer", &tmp, NULL, NULL)) {
- g_autofree char *http_proxy = g_strconcat ("http://", tmp, NULL);
- /* TODO */
- g_strv_builder_add (builder, http_proxy);
- return;
+ g_autoptr (GHashTable) table = parse_manual (tmp);
+ const char *scheme = g_uri_get_scheme (uri);
+
+ if (table) {
+ char *ret = g_hash_table_lookup (table, scheme);
+ if (ret) {
+ g_strv_builder_add (builder, ret);
+ return;
+ }
+
+ ret = g_hash_table_lookup (table, "http");
+ if (ret) {
+ g_strv_builder_add (builder, ret);
+ return;
+ }
+
+ ret = g_hash_table_lookup (table, "socks");
+ if (ret) {
+ g_strv_builder_add (builder, ret);
+ return;
+ }
+ }
}
}
diff --git a/src/backend/plugins/config-windows/config-windows.h b/src/backend/plugins/config-windows/config-windows.h
index e7706e5..7c2afcf 100644
--- a/src/backend/plugins/config-windows/config-windows.h
+++ b/src/backend/plugins/config-windows/config-windows.h
@@ -1,6 +1,6 @@
/* config-windows.h
*
- * Copyright 2023 Jan-Michael Brummer
+ * Copyright 2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/src/backend/plugins/config-windows/config-windows.plugin b/src/backend/plugins/config-windows/config-windows.plugin
index e8af810..04a589b 100644
--- a/src/backend/plugins/config-windows/config-windows.plugin
+++ b/src/backend/plugins/config-windows/config-windows.plugin
@@ -1,6 +1,3 @@
[Plugin]
-Authors=Jan-Michael Brummer <jan.brummer@tabos.org>
-Copyright=Copyright © 2023 Jan-Michael Brummer
-Description=Read proxy configuration from Windows registry
Module=config-windows
Name=Windows \ No newline at end of file
diff --git a/src/backend/plugins/config-windows/meson.build b/src/backend/plugins/config-windows/meson.build
index 9416e34..2e592b5 100644
--- a/src/backend/plugins/config-windows/meson.build
+++ b/src/backend/plugins/config-windows/meson.build
@@ -16,6 +16,7 @@ plugin_lib = shared_module(
plugin_name,
plugin_src,
include_directories: px_backend_inc,
+ c_args: px_backend_c_args,
dependencies: [px_backend_dep],
install_dir: join_paths(px_plugins_dir, plugin_name),
install: true,
diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c
index f54791c..be6b5f5 100644
--- a/src/backend/px-manager.c
+++ b/src/backend/px-manager.c
@@ -263,7 +263,7 @@ download_pac (PeasExtensionSet *set,
PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension);
struct DownloadData *download_data = data;
- g_debug ("%s: Download PAC using plugin '%s'", __FUNCTION__, peas_plugin_info_get_module_name (info));
+ g_debug ("%s: Download PAC '%s' using plugin '%s'", __FUNCTION__, download_data->uri, peas_plugin_info_get_module_name (info));
if (!download_data->bytes)
download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri);
}
diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c
index 2c780d2..34d3218 100644
--- a/src/tests/config-env-test.c
+++ b/src/tests/config-env-test.c
@@ -1,6 +1,6 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2022-2023 Jan-Michael Brummer <jan.brummer@tabos.org>
+/* config-env-test.c
+ *
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,8 +14,10 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- ******************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
#include "px-manager.h"
@@ -67,8 +69,12 @@ test_config_env (void)
continue;
}
- if (test.no_proxy)
- g_setenv ("NO_PROXY", test.no_proxy, TRUE);
+ if (test.no_proxy) {
+ if (test.config_is_proxy)
+ g_setenv ("NO_PROXY", test.no_proxy, TRUE);
+ else
+ g_setenv ("no_proxy", test.no_proxy, TRUE);
+ }
manager = px_test_manager_new ("config-env");
g_clear_error (&error);
@@ -82,6 +88,7 @@ test_config_env (void)
g_unsetenv (test.env);
g_unsetenv ("NO_PROXY");
+ g_unsetenv ("no_proxy");
g_clear_object (&manager);
}
diff --git a/src/tests/config-gnome-test.c b/src/tests/config-gnome-test.c
index 2f4bb8c..7d8223d 100644
--- a/src/tests/config-gnome-test.c
+++ b/src/tests/config-gnome-test.c
@@ -1,6 +1,6 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2022-2023 Jan-Michael Brummer <jan.brummer@tabos.org>
+/* config-gnome-test.c
+ *
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,8 +14,10 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- ******************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
#include "px-manager.h"
@@ -29,6 +31,7 @@ typedef struct {
GSettings *http_proxy_settings;
GSettings *https_proxy_settings;
GSettings *ftp_proxy_settings;
+ GSettings *socks_proxy_settings;
} Fixture;
enum {
@@ -51,6 +54,7 @@ static const ConfigGnomeTest config_gnome_test_set[] = {
{ GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://www.example.com", "http://127.0.0.1:8080", TRUE},
{ GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "ftp://www.example.com", "http://127.0.0.1:8080", TRUE},
{ GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://localhost:1234", "http://127.0.0.1:8080", TRUE},
+ { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "socks://localhost:1234", "socks://127.0.0.1:8080", TRUE},
};
static void
@@ -61,6 +65,7 @@ fixture_setup (Fixture *self,
self->http_proxy_settings = g_settings_new ("org.gnome.system.proxy.http");
self->https_proxy_settings = g_settings_new ("org.gnome.system.proxy.https");
self->ftp_proxy_settings = g_settings_new ("org.gnome.system.proxy.ftp");
+ self->socks_proxy_settings = g_settings_new ("org.gnome.system.proxy.socks");
}
static void
@@ -70,8 +75,8 @@ fixture_teardown (Fixture *fixture,
}
static void
-test_config_gnome (Fixture *self,
- const void *user_data)
+test_config_gnome_manual (Fixture *self,
+ const void *user_data)
{
int idx;
@@ -89,6 +94,8 @@ test_config_gnome (Fixture *self,
g_settings_set_int (self->https_proxy_settings, "port", test.proxy_port);
g_settings_set_string (self->ftp_proxy_settings, "host", test.proxy);
g_settings_set_int (self->ftp_proxy_settings, "port", test.proxy_port);
+ g_settings_set_string (self->socks_proxy_settings, "host", test.proxy);
+ g_settings_set_int (self->socks_proxy_settings, "port", test.proxy_port);
manager = px_test_manager_new ("config-gnome");
g_clear_error (&error);
@@ -100,22 +107,90 @@ test_config_gnome (Fixture *self,
}
config = px_manager_get_configuration (manager, uri, &error);
- if (test.success)
- g_assert_cmpstr (config[0], ==, test.expected_return);
- else
- g_assert_cmpstr (config[0], !=, test.expected_return);
+ g_assert_cmpstr (config[0], ==, test.expected_return);
g_clear_object (&manager);
}
}
+static void
+test_config_gnome_manual_auth (Fixture *self,
+ const void *user_data)
+{
+ g_autoptr (PxManager) manager = NULL;
+ g_autoptr (GError) error = NULL;
+ g_autoptr (GUri) uri = NULL;
+ g_auto (GStrv) config = NULL;
+
+ g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_MANUAL);
+ g_settings_set_string (self->http_proxy_settings, "host", "127.0.0.1");
+ g_settings_set_int (self->http_proxy_settings, "port", 9876);
+ g_settings_set_boolean (self->http_proxy_settings, "use-authentication", TRUE);
+ g_settings_set_string (self->http_proxy_settings, "authentication-user", "test");
+ g_settings_set_string (self->http_proxy_settings, "authentication-password", "pwd");
+
+ manager = px_test_manager_new ("config-gnome");
+ g_clear_error (&error);
+
+ uri = g_uri_parse ("http://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
+
+ config = px_manager_get_configuration (manager, uri, &error);
+ g_assert_cmpstr (config[0], ==, "http://test:pwd@127.0.0.1:9876");
+}
+
+static void
+test_config_gnome_auto (Fixture *self,
+ const void *user_data)
+{
+ g_autoptr (PxManager) manager = NULL;
+ g_autoptr (GError) error = NULL;
+ g_auto (GStrv) config = NULL;
+ g_autoptr (GUri) uri = NULL;
+
+ manager = px_test_manager_new ("config-gnome");
+ g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO);
+ g_settings_set_string (self->proxy_settings, "autoconfig-url", "");
+
+ uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
+ config = px_manager_get_configuration (manager, uri, &error);
+ g_assert_cmpstr (config[0], ==, "wpad://");
+
+ g_settings_set_string (self->proxy_settings, "autoconfig-url", "http://127.0.0.1:3435");
+ config = px_manager_get_configuration (manager, uri, &error);
+ g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1:3435");
+}
+
+static void
+test_config_gnome_fail (Fixture *self,
+ const void *user_data)
+{
+ g_autoptr (PxManager) manager = NULL;
+ g_autoptr (GError) error = NULL;
+ g_auto (GStrv) config = NULL;
+ g_autoptr (GUri) uri = NULL;
+
+ /* Disable GNOME support */
+ g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE);
+
+ manager = px_test_manager_new ("config-gnome");
+ g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO);
+ g_settings_set_string (self->proxy_settings, "autoconfig-url", "");
+
+ uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
+ config = px_manager_get_configuration (manager, uri, &error);
+ g_assert_null (config[0]);
+}
+
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
- g_test_add ("/config/gnome", Fixture, NULL, fixture_setup, test_config_gnome, fixture_teardown);
+ g_test_add ("/config/gnome/manual", Fixture, NULL, fixture_setup, test_config_gnome_manual, fixture_teardown);
+ g_test_add ("/config/gnome/manual_auth", Fixture, NULL, fixture_setup, test_config_gnome_manual_auth, fixture_teardown);
+ g_test_add ("/config/gnome/auto", Fixture, NULL, fixture_setup, test_config_gnome_auto, fixture_teardown);
+ g_test_add ("/config/gnome/fail", Fixture, NULL, fixture_setup, test_config_gnome_fail, fixture_teardown);
return g_test_run ();
}
diff --git a/src/tests/config-kde-test.c b/src/tests/config-kde-test.c
index 08b950b..9aba2d5 100644
--- a/src/tests/config-kde-test.c
+++ b/src/tests/config-kde-test.c
@@ -1,6 +1,6 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2022-2023 Jan-Michael Brummer <jan.brummer@tabos.org>
+/* config-kde-test.c
+ *
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,8 +14,10 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- ******************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
#include "px-manager.h"
@@ -33,6 +35,7 @@ static const ConfigKdeTest config_kde_manual_test_set[] = {
{ "https://www.example.com", "http://127.0.0.1:8080", TRUE},
{ "http://www.example.com", "http://127.0.0.1:8080", TRUE},
{ "ftp://www.example.com", "ftp://127.0.0.1:8080", TRUE},
+ { "socks://www.example.com", "socks://127.0.0.1:8080", TRUE},
{ "http://localhost:1234", "http://127.0.0.1:8080", FALSE},
{ "socks://localhost:1234", "http://127.0.0.1:8080", FALSE},
{ "socks://localhost:1234", "socks://127.0.0.1:8080", FALSE},
@@ -194,6 +197,30 @@ test_config_kde_pac (void)
}
}
+static void
+test_config_kde_fail (void)
+{
+ g_autoptr (PxManager) manager = NULL;
+ g_autoptr (GError) error = NULL;
+ g_autoptr (GUri) uri = NULL;
+ g_auto (GStrv) config = NULL;
+ g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL);
+
+ if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) {
+ g_warning ("Failed to set kde environment");
+ }
+
+ /* Disable KDE support */
+ g_unsetenv ("KDE_FULL_SESSION");
+
+ manager = px_test_manager_new ("config-kde");
+
+ uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
+
+ config = px_manager_get_configuration (manager, uri, &error);
+ g_assert_null (config[0]);
+}
+
int
main (int argc,
char **argv)
@@ -204,6 +231,7 @@ main (int argc,
g_test_add_func ("/config/kde/manual", test_config_kde_manual);
g_test_add_func ("/config/kde/wpad", test_config_kde_wpad);
g_test_add_func ("/config/kde/pac", test_config_kde_pac);
+ g_test_add_func ("/config/kde/fail", test_config_kde_fail);
return g_test_run ();
}
diff --git a/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c
index 1a2d3ec..4cc0989 100644
--- a/src/tests/config-sysconfig-test.c
+++ b/src/tests/config-sysconfig-test.c
@@ -1,6 +1,6 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2022-2023 Jan-Michael Brummer <jan.brummer@tabos.org>
+/* config-sysconfig-test.c
+ *
+ * Copyright 2022-2023 The Libproxy Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,8 +14,10 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- ******************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
#include "px-manager.h"
diff --git a/src/tests/data/sample-sysconfig-proxy b/src/tests/data/sample-sysconfig-proxy
index 08aba65..1318f21 100644
--- a/src/tests/data/sample-sysconfig-proxy
+++ b/src/tests/data/sample-sysconfig-proxy
@@ -3,3 +3,4 @@ HTTP_PROXY="http://127.0.0.1:8080"
HTTPS_PROXY="http://127.0.0.1:8080"
FTP_PROXY="http://127.0.0.1:8080"
NO_PROXY="localhost, 127.0.0.1"
+USELESS_OPTION="" \ No newline at end of file