Fix "Modified" is missing when saving wifi config 45/302045/1 accepted/tizen/7.0/unified/20231204.175246
authorJaehyun Kim <jeik01.kim@samsung.com>
Thu, 30 Nov 2023 04:14:48 +0000 (13:14 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Thu, 30 Nov 2023 04:17:49 +0000 (13:17 +0900)
Change-Id: I9c9daeb653a756d564d2d471760cd31a6283a1e5
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
src/wifi-config.c

index 737a177..1719b90 100755 (executable)
@@ -28,6 +28,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <sys/time.h>
 
 #include <vconf.h>
 
@@ -1221,6 +1222,8 @@ gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
        gchar *field;
        gchar *group_name = NULL;
        int order = 0;
+       int rv;
+       struct timeval modified_time;
 
        if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
                ERR("Invalid parameter");
@@ -1372,31 +1375,22 @@ 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);
+       rv = gettimeofday(&modified_time, NULL);
+       if (!rv) {
+               struct tm modified_tm;
+               char time_buf[255];
+               time_t modified_t = modified_time.tv_sec;
+
+               if (localtime_r(&modified_t, &modified_tm)) {
+                       if (strftime(time_buf, sizeof(time_buf), "%FT%TZ", &modified_tm)) {
+                               field = g_strdup(time_buf);
+                               if (field) {
+                                       g_key_file_set_string(keyfile, group_name, WIFI_CONFIG_MODIFIED, field);
+                                       g_free(field);
+                               }
+                       }
                }
        }
-#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) {