diff mbox series

[4/7] service: Refactor '__connman_service_set_proxy_autoconfig'.

Message ID e8c2b846c7065de631592721bc38d15f6a9a6575.1741121901.git.gerickson@nuovations.com (mailing list archive)
State Accepted
Commit 5488cd6dcaa8d99739f1812f207a2f50943c3760
Headers show
Series Improve PAC URL Mutation and PAC URL Logging | expand

Commit Message

Grant Erickson March 4, 2025, 9:03 p.m. UTC
There are currently two places where the network service proxy method
is set:

  1. connman_service_set_proxy_method
  2. __connman_service_set_proxy_autoconfig

Prior to this change, each did a similar, but bespoke set of
operations to set the network service proxy method.

Leverage 'service_set_proxy_method', which embodies the
previously-similar, bespoke operations, for
'__connman_service_set_proxy_autoconfig', the second of the above two
call sites.
---
 src/service.c | 48 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/src/service.c b/src/service.c
index 6fff20d4de96..cb168b03c790 100644
--- a/src/service.c
+++ b/src/service.c
@@ -5662,32 +5662,46 @@  const char *connman_service_get_proxy_url(const struct connman_service *service)
 	return service->pac;
 }
 
-void __connman_service_set_proxy_autoconfig(struct connman_service *service,
-							const char *url)
+static bool service_set_proxy_method_auto_handler(
+				struct connman_service *service,
+				enum connman_service_proxy_method method,
+				const void *context)
 {
-	const bool dochanged = true;
-
-	if (!service || service->hidden)
-		return;
-
-	service_set_pac(service, url, !dochanged);
-
-	service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
+	const char * const url = context;
 
 	if (service->ipconfig_ipv4) {
 		if (__connman_ipconfig_set_proxy_autoconfig(
-			    service->ipconfig_ipv4, url) < 0)
-			return;
+				service->ipconfig_ipv4, url) < 0)
+			return false;
 	} else if (service->ipconfig_ipv6) {
 		if (__connman_ipconfig_set_proxy_autoconfig(
-			    service->ipconfig_ipv6, url) < 0)
-			return;
+				service->ipconfig_ipv6, url) < 0)
+			return false;
 	} else
-		return;
+		return false;
 
-	proxy_changed(service);
+	return true;
+}
+
+void __connman_service_set_proxy_autoconfig(struct connman_service *service,
+							const char *url)
+{
+	const bool dochanged = true;
+	const bool donotifier = true;
 
-	__connman_notifier_proxy_changed(service);
+	DBG("service %p (%s) url %p (%s)",
+		service,
+		connman_service_get_identifier(service),
+		url,
+		url ? url : "<null>");
+
+	service_set_pac(service, url, !dochanged);
+
+	service_set_proxy_method(service,
+		CONNMAN_SERVICE_PROXY_METHOD_AUTO,
+		donotifier,
+		service_set_proxy_method_auto_handler,
+		url);
 }
 
 const char *connman_service_get_proxy_autoconfig(struct connman_service *service)