Refactoring how to get profile list 42/203842/5 submit/tizen/20190509.021344
authorhyunuktak <hyunuk.tak@samsung.com>
Thu, 18 Apr 2019 05:49:53 +0000 (14:49 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 8 May 2019 07:39:40 +0000 (16:39 +0900)
Change-Id: I4ca1c236f3ff530cf94ad56a77c008f51179be98
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
packaging/capi-network-connection.spec
src/libnetwork.c

index 636e074..cf6a1c7 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-connection
 Summary:       Network Connection library in TIZEN C API
-Version:       1.0.115
+Version:       1.0.116
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index b8f9c7b..f40966f 100755 (executable)
@@ -35,8 +35,8 @@ struct _profile_cb_s {
 };
 
 struct _profile_list_s {
-       int count;
        int next;
+       int count;
        net_profile_info_t *profiles;
 };
 
@@ -377,7 +377,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
 }
 //LCOV_EXCL_STOP
 
-int __libnet_get_connected_count(struct _profile_list_s *profile_list)
+static int __libnet_get_connected_count(struct _profile_list_s *profile_list)
 {
        int count = 0;
        int i = 0;
@@ -391,7 +391,7 @@ int __libnet_get_connected_count(struct _profile_list_s *profile_list)
        return count;
 }
 
-void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
+static void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
 {
        int i = 0;
 
@@ -405,27 +405,31 @@ void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_
 }
 
 //LCOV_EXCL_START
-int __libnet_get_default_count(struct _profile_list_s *profile_list)
+static int __libnet_get_default_count(struct _profile_list_s *profile_list)
 {
        int count = 0;
        int i = 0;
 
        for (; i < profile_list->count; i++) {
-               if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
-                       count++;
+               if (profile_list->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
+                       if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
+                               count++;
+               }
        }
 
        return count;
 }
 
-void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
+static void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
 {
        int i = 0;
 
        for (; i < source->count; i++) {
-               if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
-                       memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
-                       (*dest)++;
+               if (source->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
+                       if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
+                               memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
+                               (*dest)++;
+                       }
                }
        }
 }
@@ -661,197 +665,78 @@ int _connection_libnet_get_profile_iterator(connection_handle_s *conn_handle,
                        connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
 {
        int count = 0;
-       int rv1, rv2, rv3, rv4, rv5;
+       int rv;
        net_profile_info_t *profiles = NULL;
 
-       struct _profile_list_s wifi_profiles = {0, 0, NULL};
-       struct _profile_list_s cellular_profiles = {0, 0, NULL};
-       struct _profile_list_s ethernet_profiles = {0, 0, NULL};
-       struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
-       struct _profile_list_s mesh_profiles = {0, 0, NULL};
+       struct _profile_list_s profile_list = {0, 0, NULL};
 
        __libnet_clear_profile_list(&profile_iterator);
 
-       rv1 = net_get_profile_list(conn_handle->network_info_handle,
-               NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
-       if (rv1 == NET_ERR_ACCESS_DENIED) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
-               return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
-               return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-
-       CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
-
-       rv2 = net_get_profile_list(conn_handle->network_info_handle,
-               NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
-       if (rv2 == NET_ERR_ACCESS_DENIED) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
-               __libnet_clear_profile_list(&wifi_profiles);
-               return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
-               __libnet_clear_profile_list(&wifi_profiles);
-               return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-       }
-       CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
-
-       rv3 = net_get_profile_list(conn_handle->network_info_handle,
-               NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
-       if (rv3 == NET_ERR_ACCESS_DENIED) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
-               __libnet_clear_profile_list(&wifi_profiles);
-               __libnet_clear_profile_list(&cellular_profiles);
-               return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
-               __libnet_clear_profile_list(&wifi_profiles);
-               __libnet_clear_profile_list(&cellular_profiles);
-               return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-       }
-       CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
-
-       rv4 = net_get_profile_list(conn_handle->network_info_handle,
-               NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
-       if (rv4 == NET_ERR_ACCESS_DENIED) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
-               __libnet_clear_profile_list(&wifi_profiles);
-               __libnet_clear_profile_list(&cellular_profiles);
-               __libnet_clear_profile_list(&ethernet_profiles);
-               return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
-               __libnet_clear_profile_list(&wifi_profiles);
-               __libnet_clear_profile_list(&cellular_profiles);
-               __libnet_clear_profile_list(&ethernet_profiles);
-               return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-       }
-       CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
-
-       rv5 = net_get_profile_list(conn_handle->network_info_handle,
-               NET_DEVICE_MESH, &mesh_profiles.profiles, &mesh_profiles.count);
-       if (rv5 == NET_ERR_ACCESS_DENIED) {
+       rv = net_get_all_profile_list(conn_handle->network_info_handle,
+                       &profile_list.profiles, &profile_list.count);
+       if (rv == NET_ERR_ACCESS_DENIED) {
                CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
-               __libnet_clear_profile_list(&wifi_profiles);
                return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       } else if (rv5 != NET_ERR_NO_SERVICE && rv5 != NET_ERR_NONE) {
-               __libnet_clear_profile_list(&wifi_profiles);
+       } else if (rv != NET_ERR_NO_SERVICE && rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-       }
 
-       CONNECTION_LOG(CONNECTION_INFO, "Mesh profile count: %d", mesh_profiles.count);
        *profile_iter_h = &profile_iterator;
 
        switch (type) {
        case CONNECTION_ITERATOR_TYPE_REGISTERED:
-               count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count + mesh_profiles.count;
+               count = profile_list.count;
                CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
 
                profiles = g_try_new0(net_profile_info_t, count);
                if (profiles == NULL) {
-                       __libnet_clear_profile_list(&wifi_profiles);
-                       __libnet_clear_profile_list(&cellular_profiles);
-                       __libnet_clear_profile_list(&ethernet_profiles);
-                       __libnet_clear_profile_list(&bluetooth_profiles);
-                       __libnet_clear_profile_list(&mesh_profiles);
+                       __libnet_clear_profile_list(&profile_list);
                        return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
                profile_iterator.profiles = profiles;
 
-               if (wifi_profiles.count > 0) {
-                       memcpy(profiles, wifi_profiles.profiles,
-                                       sizeof(net_profile_info_t) * wifi_profiles.count);
-                       profiles += wifi_profiles.count;
-               }
-
-               if (cellular_profiles.count > 0) {
-                       memcpy(profiles, cellular_profiles.profiles,
-                                       sizeof(net_profile_info_t) * cellular_profiles.count);
-                       profiles += cellular_profiles.count;
-               }
-
-               if (ethernet_profiles.count > 0) {
-                       memcpy(profiles, ethernet_profiles.profiles,
-                                       sizeof(net_profile_info_t) * ethernet_profiles.count);
-                       profiles += ethernet_profiles.count;
-               }
-
-               if (mesh_profiles.count > 0) {
-                       memcpy(profiles, mesh_profiles.profiles,
-                                       sizeof(net_profile_info_t) * mesh_profiles.count);
-                       profiles += mesh_profiles.count;
-               }
-
-               if (bluetooth_profiles.count > 0)
-                       memcpy(profiles, bluetooth_profiles.profiles,
-                                       sizeof(net_profile_info_t) * bluetooth_profiles.count);
+               memcpy(profiles, profile_list.profiles, sizeof(net_profile_info_t) * count);
 
                break;
        case CONNECTION_ITERATOR_TYPE_CONNECTED:
-               count = __libnet_get_connected_count(&wifi_profiles);
-               count += __libnet_get_connected_count(&cellular_profiles);
-               count += __libnet_get_connected_count(&ethernet_profiles);
-               count += __libnet_get_connected_count(&bluetooth_profiles);
-               count += __libnet_get_connected_count(&mesh_profiles);
+               count = __libnet_get_connected_count(&profile_list);
                CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
 
                profiles = g_try_new0(net_profile_info_t, count);
                if (profiles == NULL) {
-                       __libnet_clear_profile_list(&wifi_profiles);
-                       __libnet_clear_profile_list(&cellular_profiles);
-                       __libnet_clear_profile_list(&ethernet_profiles);
-                       __libnet_clear_profile_list(&bluetooth_profiles);
-                       __libnet_clear_profile_list(&mesh_profiles);
+                       __libnet_clear_profile_list(&profile_list);
                        return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
                profile_iterator.profiles = profiles;
 
-               if (wifi_profiles.count > 0)
-                       __libnet_copy_connected_profile(&profiles, &wifi_profiles);
-
-               if (cellular_profiles.count > 0)
-                       __libnet_copy_connected_profile(&profiles, &cellular_profiles);
-
-               if (ethernet_profiles.count > 0)
-                       __libnet_copy_connected_profile(&profiles, &ethernet_profiles);
-
-               if (bluetooth_profiles.count > 0)
-                       __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
-
-               if (mesh_profiles.count > 0)
-                       __libnet_copy_connected_profile(&profiles, &mesh_profiles);
+               __libnet_copy_connected_profile(&profiles, &profile_list);
 
                break;
        case CONNECTION_ITERATOR_TYPE_DEFAULT:
-               count = __libnet_get_default_count(&cellular_profiles);
+               count = __libnet_get_default_count(&profile_list);
                CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
 
                profiles = g_try_new0(net_profile_info_t, count);
                if (profiles == NULL) {
-                       __libnet_clear_profile_list(&wifi_profiles);
-                       __libnet_clear_profile_list(&cellular_profiles);
-                       __libnet_clear_profile_list(&ethernet_profiles);
-                       __libnet_clear_profile_list(&bluetooth_profiles);
-                       __libnet_clear_profile_list(&mesh_profiles);
+                       __libnet_clear_profile_list(&profile_list);
                        return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
                profile_iterator.profiles = profiles;
 
-               if (cellular_profiles.count > 0)
-                       __libnet_copy_default_profile(&profiles, &cellular_profiles);
+               __libnet_copy_default_profile(&profiles, &profile_list);
+
                break;
        }
 
-       __libnet_clear_profile_list(&wifi_profiles);
-       __libnet_clear_profile_list(&cellular_profiles);
-       __libnet_clear_profile_list(&ethernet_profiles);
-       __libnet_clear_profile_list(&bluetooth_profiles);
-       __libnet_clear_profile_list(&mesh_profiles);
+       __libnet_clear_profile_list(&profile_list);
 
        profile_iterator.count = count;