diff mbox series

[10/17] wispr: Add and leverage an OS error parameter to '__connman_wispr_cb_t'.

Message ID 20231116010259.628527-11-gerickson@nuovations.com (mailing list archive)
State Superseded
Headers show
Series Address Redundant IPv4 Reachability Checks | expand

Commit Message

Grant Erickson Nov. 16, 2023, 1:02 a.m. UTC
This adds and leverages an operating system error parameter to
'__connman_wispr_cb_t' such that such callbacks can leverage the
error status when 'success' is false to either log the status or
take conditional action.
---
 src/connman.h |  3 ++-
 src/service.c | 15 +++++++++++----
 src/wispr.c   | 37 ++++++++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/src/connman.h b/src/connman.h
index 143a087701d8..d5aa6f5599e7 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -525,7 +525,8 @@  void __connman_wpad_stop(struct connman_service *service);
 
 typedef void (*__connman_wispr_cb_t) (struct connman_service *service,
 				enum connman_ipconfig_type type,
-				bool success);
+				bool success,
+				int err);
 
 int __connman_wispr_init(void);
 void __connman_wispr_cleanup(void);
diff --git a/src/service.c b/src/service.c
index 5fb53c2084f9..0882cd167699 100644
--- a/src/service.c
+++ b/src/service.c
@@ -163,7 +163,8 @@  static void vpn_auto_connect(void);
 static void trigger_autoconnect(struct connman_service *service);
 static void complete_online_check(struct connman_service *service,
 					enum connman_ipconfig_type type,
-					bool success);
+					bool success,
+					int err);
 static bool service_downgrade_online_state(struct connman_service *service);
 
 struct find_data {
@@ -1902,6 +1903,11 @@  static void reschedule_online_check(struct connman_service *service,
  *                           check.
  *  @param[in]      success  A Boolean indicating whether the previously-
  *                           requested online check was successful.
+ *  @param[in]      err      The error status associated with previously-
+ *                           requested online check. This is expected
+ *                           to be zero ('0') if @a success is @a true
+ *                           and less than zero ('< 0') if @a success
+ *                           is @a false.
  *
  *  @sa cancel_online_check
  *  @sa start_online_check
@@ -1911,16 +1917,17 @@  static void reschedule_online_check(struct connman_service *service,
  */
 static void complete_online_check(struct connman_service *service,
 					enum connman_ipconfig_type type,
-					bool success)
+					bool success,
+					int err)
 {
 	unsigned int *interval;
 	guint *timeout;
 
-	DBG("service %p (%s) type %d (%s) success %d\n",
+	DBG("service %p (%s) type %d (%s) success %d err %d (%s)\n",
 		service,
 		connman_service_get_identifier(service),
 		type, __connman_ipconfig_type2string(type),
-		success);
+		success, err, strerror(-err));
 
 	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		interval = &service->online_check_interval_ipv4;
diff --git a/src/wispr.c b/src/wispr.c
index 4b4c9c1e59ec..9d471628e705 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -564,7 +564,7 @@  static void portal_manage_success_status(GWebResult *result,
 				&str))
 		connman_info("Client-Timezone: %s", str);
 
-	wp_context->cb(service, type, true);
+	wp_context->cb(service, type, true, 0);
 }
 
 static bool wispr_route_request(const char *address, int ai_family,
@@ -618,6 +618,8 @@  static bool wispr_route_request(const char *address, int ai_family,
 static void wispr_portal_request_portal(
 		struct connman_wispr_portal_context *wp_context)
 {
+	int err = 0;
+
 	DBG("wispr/portal context %p service %p (%s) type %d (%s)",
 		wp_context,
 		wp_context->service,
@@ -634,10 +636,13 @@  static void wispr_portal_request_portal(
 					wp_context->status_url,
 					wispr_portal_web_result,
 					wispr_route_request,
-					wp_context, NULL);
+					wp_context, &err);
 
 	if (wp_context->request_id == 0) {
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+						wp_context->type,
+						false,
+						err);
 		wispr_portal_error(wp_context);
 		wispr_portal_context_unref(wp_context);
 	}
@@ -910,11 +915,26 @@  static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 
 		goto done;
 	case GWEB_HTTP_STATUS_CODE_BAD_REQUEST:
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-EINVAL);
+		break;
+
 	case GWEB_HTTP_STATUS_CODE_NOT_FOUND:
-	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-ENOENT);
+		break;
 
+	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-ETIMEDOUT);
 		break;
+
 	case GWEB_HTTP_STATUS_CODE_HTTP_VERSION_NOT_SUPPORTED:
 		wispr_portal_context_ref(wp_context);
 		__connman_agent_request_browser(wp_context->service,
@@ -977,7 +997,10 @@  static void proxy_callback(const char *proxy, void *user_data)
 	if (!proxy) {
 		DBG("no valid proxy");
 
-		wp_context->cb(wp_context->service, wp_context->type, false);
+		wp_context->cb(wp_context->service,
+				wp_context->type,
+				false,
+				-EINVAL);
 
 		return;
 	}
@@ -1311,7 +1334,7 @@  int __connman_wispr_start(struct connman_service *service,
 	return 0;
 
 free_wp:
-	wp_context->cb(wp_context->service, wp_context->type, false);
+	wp_context->cb(wp_context->service, wp_context->type, false, err);
 
 	g_hash_table_remove(wispr_portal_hash, GINT_TO_POINTER(index));
 	return err;