diff mbox series

[v2,14/17] wispr: Add '__connman_wispr_cancel' interface.

Message ID 20231119170714.775270-15-gerickson@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Address Redundant IPv4 Reachability Checks | expand

Commit Message

Grant Erickson Nov. 19, 2023, 5:07 p.m. UTC
This adds a heretofore-missing '__connman_wispr_cancel' interface. It
attempts to cancel a HTTP-based Internet reachability check for the
specified network service IP configuration type.

If a matching WISPr portal detect request or HTTP-based Internet
reachability check is found, the original callback specified with
'__connman_wispr_start' will be invoked with a success value of zero
('0') or false and an error value of -ECANCELED.
---
 src/connman.h |  2 ++
 src/wispr.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
diff mbox series

Patch

diff --git a/src/connman.h b/src/connman.h
index d5aa6f5599e7..ae04cd9a26c6 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -534,6 +534,8 @@  int __connman_wispr_start(struct connman_service *service,
 					enum connman_ipconfig_type type,
 					guint connect_timeout_ms,
 					__connman_wispr_cb_t callback);
+int __connman_wispr_cancel(struct connman_service *service,
+					enum connman_ipconfig_type type);
 void __connman_wispr_stop(struct connman_service *service);
 
 #include <connman/technology.h>
diff --git a/src/wispr.c b/src/wispr.c
index 396891c98153..9f995060a6c0 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -1341,6 +1341,61 @@  free_wp:
 	return err;
 }
 
+int __connman_wispr_cancel(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	struct connman_wispr_portal_context *wp_context = NULL;
+	struct connman_wispr_portal *wispr_portal = NULL;
+	int index;
+
+	DBG("service %p (%s) type %d (%s)",
+		service, connman_service_get_identifier(service),
+		type, __connman_ipconfig_type2string(type));
+
+	if (!is_wispr_supported(service))
+		return -EOPNOTSUPP;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -EINVAL;
+
+	DBG("index %d", index);
+
+	if (!wispr_portal_hash)
+		return -ENOENT;
+
+	wispr_portal = g_hash_table_lookup(wispr_portal_hash,
+					GINT_TO_POINTER(index));
+
+	DBG("wispr_portal %p", wispr_portal);
+
+	if (!wispr_portal)
+		return -ENOENT;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		wp_context = wispr_portal->ipv4_context;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		wp_context = wispr_portal->ipv6_context;
+	else
+		return -EINVAL;
+
+	DBG("wp_context %p", wp_context);
+
+	if (!wp_context)
+		return -ENOENT;
+
+	cancel_connman_wispr_portal_context(wp_context);
+
+	wp_context->cb(wp_context->service,
+			wp_context->type,
+			false,
+			-ECANCELED);
+
+	wispr_portal_context_unref(wp_context);
+
+	return 0;
+}
+
 /**
  *  @brief
  *    Stop all HTTP-based Internet reachability checks for the specified