void netconfig_convert_bytes_to_hexstr(const char* bin, int blen, gchar* hexstr);
+int get_files_count(const char* path);
+char *get_least_recently_profile(const char* path);
+
#ifdef __cplusplus
}
#endif
#define WIFI_CONFIG_SECURITY_TYPE "Security"
#define WIFI_CONFIG_FAVORITE "Favorite"
#define WIFI_CONFIG_AUTOCONNECT "AutoConnect"
+#define WIFI_CONFIG_MODIFIED "Modified"
#define WIFI_CONFIG_HIDDEN "Hidden"
#define WIFI_CONFIG_CREATED "Created"
#define WIFI_CONFIG_IPV4_METHOD "IPv4.method"
#include <vconf-keys.h>
#include <tzplatform_config.h>
#include <system_info.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <time.h>
#include "log.h"
#include "util.h"
*hexstr = '\0';
}
+
+bool __is_hidden_file(const char *file)
+{
+ /* exclude "." , "..", "settings" and hidden files */
+ if( g_strcmp0( file, "." ) == 0 ||
+ g_strcmp0( file, ".." ) == 0 || file[0]=='.' || g_strcmp0(file, "settings")==0 )
+ {
+ return true;
+ }
+
+ return false;
+}
+
+int get_files_count(const char *path)
+{
+ DIR *dfd = NULL;
+ struct dirent *dir = NULL;
+ int file_count = 0;
+ dfd = opendir(path);
+ if (dfd) {
+ while ((dir = readdir(dfd)) != NULL) {
+ if (__is_hidden_file(dir->d_name))
+ continue;
+
+ if (strncmp(dir->d_name, "wifi_", 5) != 0)
+ continue;
+
+ ++file_count;
+ }
+ closedir(dfd);
+ }
+
+ return file_count;
+}
+
+char * get_least_recently_profile(const char *path)
+{
+ DIR *dfd = NULL;
+ struct dirent *dir = NULL;
+ unsigned long lastModified = (unsigned long)~0;
+ char *file = NULL;
+ dfd = opendir(path);
+ if (dfd) {
+ while ((dir = readdir(dfd)) != NULL) {
+ if (__is_hidden_file(dir->d_name))
+ continue;
+
+ if (strncmp(dir->d_name, "wifi_", 5) != 0)
+ continue;
+
+ struct stat attr;
+ gchar *full_path = g_strdup_printf("%s/%s", path, dir->d_name);
+ if (stat(full_path, &attr)== 0) {
+ if(lastModified > attr.st_mtime)
+ {
+ lastModified = attr.st_mtime;
+ file = dir->d_name;
+ }
+ } else {
+ ERR("stat failed");
+ }
+ g_free(full_path);
+ }
+ closedir(dfd);
+ }
+
+ DBG("least recently path: [%s]", file);
+
+ return file;
+}
#define NET_DNS_ADDR_MAX 2
+#define MAX_WIFI_PROFILES 200
+
struct wifi_eap_config {
gchar *anonymous_identity;
gchar *ca_cert;
gchar *security_type;
gboolean favorite;
gboolean autoconnect;
+ GTimeVal modified;
gchar *is_hidden;
gboolean is_created;
gchar *proxy_address;
ERR("Cannot remove [%s]", pathname);
return FALSE;
}
-
return TRUE;
}
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);
+ g_get_current_time(&conf->modified);
+ gchar *str = g_time_val_to_iso8601(&conf->modified);
+ if (str) {
+ g_key_file_set_string(keyfile, group_name,
+ WIFI_CONFIG_MODIFIED, str);
+ g_free(str);
+ }
/* Optional field */
if (conf->proxy_address != NULL) {
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", profileName);
+
+ g_free(profileName);
+ }
+ }
} else {
INFO("Fail to save configuration [%s]", config_id);
netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSaveConfiguration");