Replace deprecated APIs of Glib v2.62.3 with suggested GLib APIs
[platform/core/connectivity/net-config.git] / src / wifi-config.c
index 48b898d..97b9c6d 100755 (executable)
@@ -55,6 +55,8 @@
 
 #define        NET_DNS_ADDR_MAX                2
 
+#define MAX_WIFI_PROFILES              200
+
 struct wifi_eap_config {
        gchar *anonymous_identity;
        gchar *ca_cert;
@@ -301,7 +303,6 @@ static gboolean __remove_configuration(const gchar *pathname)
                ERR("Cannot remove [%s]", pathname);
                return FALSE;
        }
-
        return TRUE;
 }
 
@@ -1300,6 +1301,32 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
        g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_FAVORITE, conf->favorite);
        g_key_file_set_boolean(keyfile, group_name, WIFI_CONFIG_AUTOCONNECT, conf->autoconnect);
 
+#if GLIB_CHECK_VERSION(2,62,0)
+       gint64 real_time = 0;
+       GDateTime *dt_real_time = NULL;
+
+       real_time = g_get_real_time();
+       dt_real_time = g_date_time_new_from_unix_utc(real_time);
+       if (dt_real_time) {
+               gchar *str = g_date_time_format_iso8601(dt_real_time);
+               g_date_time_unref(dt_real_time);
+               if (str) {
+                       g_key_file_set_string(keyfile, group_name,
+                                             WIFI_CONFIG_MODIFIED, str);
+                       g_free(str);
+               }
+       }
+#else /* GLIB_CHECK_VERSION(2,62,0) */
+       GTimeVal modified;
+       g_get_current_time(&modified);
+       gchar *str = g_time_val_to_iso8601(&modified);
+       if (str) {
+               g_key_file_set_string(keyfile, group_name,
+                                     WIFI_CONFIG_MODIFIED, str);
+               g_free(str);
+       }
+#endif /* GLIB_CHECK_VERSION(2,62,0) */
+
        /* Optional field */
        if (conf->proxy_address != NULL) {
                g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_PROXY_METHOD, "manual");
@@ -1355,6 +1382,21 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
        if (ret == TRUE) {
                INFO("Success to save configuration [%s]", config_id);
                wifi_complete_save_configuration(wifi, context);
+               char *file;
+               if (get_files_count(CONNMAN_STORAGE) > MAX_WIFI_PROFILES) {
+                       file = get_least_recently_profile(CONNMAN_STORAGE);
+                       if (file) {
+                               gchar *profileName = g_strdup_printf(CONNMAN_STORAGE "/%s", file);
+                               INFO("least modified file:  %s", profileName);
+                               if (profileName) {
+                                       if (__remove_configuration(profileName) != TRUE)
+                                               DBG("Failed to remove profile: [%s]", profileName);
+                               } else
+                                       ERR("Profile: [%s] does not exist", file);
+
+                               g_free(profileName);
+                       }
+               }
        } else {
                INFO("Fail to save configuration [%s]", config_id);
                netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");