commit e1634baae4d1de4fe260a59d4f94be88c3989783
parent ac527d88c667b47f75e02eb67c9263d21df9e5d7
Author: Andrew Zaborowski <andrew.zaborowski@intel.com>
Date: Wed, 1 Aug 2018 03:56:41 +0200
storage: Take enum security instead of string as parameter
Make the network_storage_* functions uniformly accept an enum value
instead of a string so that he conversion to string doesn't need to
happen in all callers.
Diffstat:
5 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/src/knownnetworks.c b/src/knownnetworks.c
@@ -107,14 +107,14 @@ static bool known_networks_add(const char *ssid, enum security security)
strcpy(network->ssid, ssid);
network->type = security;
- err = storage_network_get_mtime(security_to_str(security), ssid,
+ err = storage_network_get_mtime(security, ssid,
&network->connected_time);
if (err < 0) {
l_free(network);
return false;
}
- settings = storage_network_open(security_to_str(security), ssid);
+ settings = storage_network_open(security, ssid);
if (l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden))
network->is_hidden = is_hidden;
diff --git a/src/network.c b/src/network.c
@@ -64,16 +64,11 @@ static struct l_queue *networks;
static bool network_settings_load(struct network *network)
{
- const char *strtype;
-
if (network->settings)
return true;
- strtype = security_to_str(network_get_security(network));
- if (!strtype)
- return false;
-
- network->settings = storage_network_open(strtype, network->info->ssid);
+ network->settings = storage_network_open(network_get_security(network),
+ network->info->ssid);
return network->settings != NULL;
}
@@ -112,11 +107,9 @@ static bool network_info_ptr_match(const void *a, const void *b)
void network_connected(struct network *network)
{
int err;
- const char *strtype;
-
- strtype = security_to_str(network_get_security(network));
- err = storage_network_touch(strtype, network->info->ssid);
+ err = storage_network_touch(network_get_security(network),
+ network->info->ssid);
switch (err) {
case 0:
break;
@@ -130,7 +123,8 @@ void network_connected(struct network *network)
*/
network->settings = l_settings_new();
- storage_network_sync(strtype, network->info->ssid,
+ storage_network_sync(network_get_security(network),
+ network->info->ssid,
network->settings);
break;
default:
@@ -138,7 +132,8 @@ void network_connected(struct network *network)
break;
}
- err = storage_network_get_mtime(strtype, network->info->ssid,
+ err = storage_network_get_mtime(network_get_security(network),
+ network->info->ssid,
&network->info->connected_time);
if (err < 0)
l_error("Error %i reading network timestamp", err);
@@ -434,7 +429,8 @@ void network_sync_psk(struct network *network)
l_settings_set_value(network->settings, "Security",
"PreSharedKey", hex);
l_free(hex);
- storage_network_sync("psk", network->info->ssid, network->settings);
+ storage_network_sync(SECURITY_PSK, network->info->ssid,
+ network->settings);
}
int network_autoconnect(struct network *network, struct scan_bss *bss)
diff --git a/src/storage.c b/src/storage.c
@@ -169,7 +169,7 @@ error_create_dirs:
return r;
}
-static char *get_network_file_path(const char *type, const char *ssid)
+static char *get_network_file_path(enum security type, const char *ssid)
{
char *path;
const char *c;
@@ -183,11 +183,13 @@ static char *get_network_file_path(const char *type, const char *ssid)
hex = l_util_hexstring((const unsigned char *) ssid,
strlen(ssid));
- path = l_strdup_printf(STORAGEDIR "/=%s.%s", hex, type);
+ path = l_strdup_printf(STORAGEDIR "/=%s.%s", hex,
+ security_to_str(type));
l_free(hex);
} else
- path = l_strdup_printf(STORAGEDIR "/%s.%s", ssid, type);
+ path = l_strdup_printf(STORAGEDIR "/%s.%s", ssid,
+ security_to_str(type));
return path;
}
@@ -250,12 +252,12 @@ const char *storage_network_ssid_from_path(const char *path,
return buf;
}
-struct l_settings *storage_network_open(const char *type, const char *ssid)
+struct l_settings *storage_network_open(enum security type, const char *ssid)
{
struct l_settings *settings;
char *path;
- if (ssid == NULL || type == NULL)
+ if (ssid == NULL)
return NULL;
path = get_network_file_path(type, ssid);
@@ -270,12 +272,12 @@ struct l_settings *storage_network_open(const char *type, const char *ssid)
return settings;
}
-int storage_network_touch(const char *type, const char *ssid)
+int storage_network_touch(enum security type, const char *ssid)
{
char *path;
int ret;
- if (ssid == NULL || type == NULL)
+ if (ssid == NULL)
return -EINVAL;
path = get_network_file_path(type, ssid);
@@ -288,14 +290,14 @@ int storage_network_touch(const char *type, const char *ssid)
return -errno;
}
-int storage_network_get_mtime(const char *type, const char *ssid,
+int storage_network_get_mtime(enum security type, const char *ssid,
struct timespec *mtim)
{
char *path;
int ret;
struct stat sb;
- if (ssid == NULL || type == NULL)
+ if (ssid == NULL)
return -EINVAL;
path = get_network_file_path(type, ssid);
@@ -314,7 +316,7 @@ int storage_network_get_mtime(const char *type, const char *ssid,
return 0;
}
-void storage_network_sync(const char *type, const char *ssid,
+void storage_network_sync(enum security type, const char *ssid,
struct l_settings *settings)
{
char *data;
@@ -328,7 +330,7 @@ void storage_network_sync(const char *type, const char *ssid,
l_free(path);
}
-int storage_network_remove(const char *type, const char *ssid)
+int storage_network_remove(enum security type, const char *ssid)
{
char *path;
int ret;
diff --git a/src/storage.h b/src/storage.h
@@ -34,10 +34,10 @@ ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...)
const char *storage_network_ssid_from_path(const char *path,
enum security *type);
-struct l_settings *storage_network_open(const char *type, const char *ssid);
-int storage_network_touch(const char *type, const char *ssid);
-int storage_network_get_mtime(const char *type, const char *ssid,
+struct l_settings *storage_network_open(enum security type, const char *ssid);
+int storage_network_touch(enum security type, const char *ssid);
+int storage_network_get_mtime(enum security type, const char *ssid,
struct timespec *mtim);
-void storage_network_sync(const char *type, const char *ssid,
+void storage_network_sync(enum security type, const char *ssid,
struct l_settings *settings);
-int storage_network_remove(const char *type, const char *ssid);
+int storage_network_remove(enum security type, const char *ssid);
diff --git a/src/wsc.c b/src/wsc.c
@@ -170,7 +170,7 @@ static void wsc_store_credentials(struct wsc *wsc)
l_free(hex);
}
- storage_network_sync(security_to_str(security), ssid, settings);
+ storage_network_sync(security, ssid, settings);
l_settings_free(settings);
/*