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.
This commit is contained in:
Andrew Zaborowski 2018-08-01 03:56:41 +02:00 committed by Denis Kenzior
parent ac527d88c6
commit e1634baae4
5 changed files with 31 additions and 33 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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);
/*