Fix feature check logic 69/315569/5
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 2 Aug 2024 11:32:53 +0000 (13:32 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 5 Aug 2024 13:35:35 +0000 (15:35 +0200)
The check_network_features() was unused when feature check was disabled which
led to a build break it this configuration.

Keep the NO_FEATURE_CHECK ifdef in a single place for clarity.

Return either WAUTHN_ERROR_NOT_SUPPORTED or WAUTHN_ERROR_NONE.

Switch to bool return values to simplify the code.

Change-Id: I0e514a1b6e43970907734fcb0eaf0344cb5f509e

srcs/client/client.cpp

index 980f7cd2cd5b9be716e60cb36935ec451242b6e1..a22c2ec10c0c68eafab05619b59ad9d935eecda5 100644 (file)
@@ -33,50 +33,34 @@ constexpr char TELEPHONY[] = "http://tizen.org/feature/network.telephony";
 constexpr char WIFI[] = "http://tizen.org/feature/network.wifi";
 constexpr char ETHERNET[] = "http://tizen.org/feature/network.ethernet";
 
-int has_feature(const char *feature) {
+bool has_feature(const char *feature) {
 #ifdef NO_FEATURE_CHECK
+    LogWarning("Skipping feature check for " << feature);
     (void)feature;
-    return WAUTHN_ERROR_NONE;
+    return true;
 #else
     bool is_supported;
 
     if (SYSTEM_INFO_ERROR_NONE
             != system_info_get_platform_bool(feature, &is_supported)) {
-        LogWarning("Failed to check feature " << feature);
-        return WAUTHN_ERROR_UNKNOWN;
+        LogError("Failed to check feature " << feature);
+        return false;
     }
 
     if (!is_supported) {
         LogWarning("Unsupported feature " << feature);
-        return WAUTHN_ERROR_NOT_SUPPORTED;
+        return false;
     }
-    return WAUTHN_ERROR_NONE;
+    return true;
 #endif
 }
 
-int check_network_features() {
-    if ((has_feature(TELEPHONY) != WAUTHN_ERROR_NONE) &&
-        has_feature(WIFI) != WAUTHN_ERROR_NONE &&
-        has_feature(ETHERNET) != WAUTHN_ERROR_NONE)
-        return WAUTHN_ERROR_NOT_SUPPORTED;
-    return WAUTHN_ERROR_NONE;
+bool check_network_features() {
+    return has_feature(TELEPHONY) || has_feature(WIFI) || has_feature(ETHERNET);
 }
 
-int check_features() {
-#ifdef NO_FEATURE_CHECK
-    LogWarning("Skip to check features");
-    return WAUTHN_ERROR_NONE;
-#else
-    int ret = WAUTHN_ERROR_NONE;
-    if (((ret = has_feature(WEBAUTHN)) != WAUTHN_ERROR_NONE) ||
-        ((ret = has_feature(BLUETOOTH)) != WAUTHN_ERROR_NONE) ||
-        ((ret = check_network_features()) != WAUTHN_ERROR_NONE))
-        {
-            LogError("Features are not supported");
-            return ret;
-        }
-    return WAUTHN_ERROR_NONE;
-#endif
+bool check_features() {
+    return has_feature(WEBAUTHN) && has_feature(BLUETOOTH) && check_network_features();
 }
 } // namespace
 
@@ -84,11 +68,9 @@ int check_features() {
 
 WEBAUTHN_API
 int wauthn_set_api_version(int api_version_number) {
-    int ret = has_feature(WEBAUTHN);
-    if (ret != WAUTHN_ERROR_NONE)
-    {
-        LogError(get_error_message(ret));
-        return ret;
+    if (!has_feature(WEBAUTHN)) {
+        LogError("Required feature is missing");
+        return WAUTHN_ERROR_NOT_SUPPORTED;
     }
 
     if (api_version_number != WAUTHN_API_VERSION_NUMBER)
@@ -99,11 +81,9 @@ int wauthn_set_api_version(int api_version_number) {
 
 WEBAUTHN_API
 int wauthn_supported_authenticators(unsigned int *supported) {
-    int ret = has_feature(WEBAUTHN);
-    if (ret != WAUTHN_ERROR_NONE)
-    {
-        LogError(get_error_message(ret));
-        return ret;
+    if (!has_feature(WEBAUTHN)) {
+        LogError("Required feature is missing");
+        return WAUTHN_ERROR_NOT_SUPPORTED;
     }
 
     if (supported == nullptr)
@@ -117,9 +97,10 @@ WEBAUTHN_API
 int wauthn_make_credential(const wauthn_client_data_s *client_data,
         const wauthn_pubkey_cred_creation_options_s *options,
         wauthn_mc_callbacks_s *callbacks) {
-    int ret = check_features();
-    if (ret != WAUTHN_ERROR_NONE)
-        return ret;
+    if (!check_features()) {
+        LogError("Required feature is missing");
+        return WAUTHN_ERROR_NOT_SUPPORTED;
+    }
 
     return try_catch([&]() -> int {
         CheckParameters(client_data, options, callbacks);
@@ -132,9 +113,10 @@ WEBAUTHN_API
 int wauthn_get_assertion(const wauthn_client_data_s *client_data,
         const wauthn_pubkey_cred_request_options_s *options,
         wauthn_ga_callbacks_s *callbacks) {
-    int ret = check_features();
-    if (ret != WAUTHN_ERROR_NONE)
-        return ret;
+    if (!check_features()) {
+        LogError("Required feature is missing");
+        return WAUTHN_ERROR_NOT_SUPPORTED;
+    }
 
     return try_catch([&]() -> int {
         CheckParameters(client_data, options, callbacks);