mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 21:22:37 +01:00
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:
parent
ac527d88c6
commit
e1634baae4
@ -107,14 +107,14 @@ static bool known_networks_add(const char *ssid, enum security security)
|
|||||||
strcpy(network->ssid, ssid);
|
strcpy(network->ssid, ssid);
|
||||||
network->type = security;
|
network->type = security;
|
||||||
|
|
||||||
err = storage_network_get_mtime(security_to_str(security), ssid,
|
err = storage_network_get_mtime(security, ssid,
|
||||||
&network->connected_time);
|
&network->connected_time);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
l_free(network);
|
l_free(network);
|
||||||
return false;
|
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))
|
if (l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden))
|
||||||
network->is_hidden = is_hidden;
|
network->is_hidden = is_hidden;
|
||||||
|
@ -64,16 +64,11 @@ static struct l_queue *networks;
|
|||||||
|
|
||||||
static bool network_settings_load(struct network *network)
|
static bool network_settings_load(struct network *network)
|
||||||
{
|
{
|
||||||
const char *strtype;
|
|
||||||
|
|
||||||
if (network->settings)
|
if (network->settings)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
strtype = security_to_str(network_get_security(network));
|
network->settings = storage_network_open(network_get_security(network),
|
||||||
if (!strtype)
|
network->info->ssid);
|
||||||
return false;
|
|
||||||
|
|
||||||
network->settings = storage_network_open(strtype, network->info->ssid);
|
|
||||||
|
|
||||||
return network->settings != NULL;
|
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)
|
void network_connected(struct network *network)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
const char *strtype;
|
|
||||||
|
|
||||||
strtype = security_to_str(network_get_security(network));
|
err = storage_network_touch(network_get_security(network),
|
||||||
|
network->info->ssid);
|
||||||
err = storage_network_touch(strtype, network->info->ssid);
|
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
@ -130,7 +123,8 @@ void network_connected(struct network *network)
|
|||||||
*/
|
*/
|
||||||
network->settings = l_settings_new();
|
network->settings = l_settings_new();
|
||||||
|
|
||||||
storage_network_sync(strtype, network->info->ssid,
|
storage_network_sync(network_get_security(network),
|
||||||
|
network->info->ssid,
|
||||||
network->settings);
|
network->settings);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -138,7 +132,8 @@ void network_connected(struct network *network)
|
|||||||
break;
|
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);
|
&network->info->connected_time);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
l_error("Error %i reading network timestamp", err);
|
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",
|
l_settings_set_value(network->settings, "Security",
|
||||||
"PreSharedKey", hex);
|
"PreSharedKey", hex);
|
||||||
l_free(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)
|
int network_autoconnect(struct network *network, struct scan_bss *bss)
|
||||||
|
@ -169,7 +169,7 @@ error_create_dirs:
|
|||||||
return r;
|
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;
|
char *path;
|
||||||
const char *c;
|
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,
|
hex = l_util_hexstring((const unsigned char *) ssid,
|
||||||
strlen(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);
|
l_free(hex);
|
||||||
} else
|
} else
|
||||||
path = l_strdup_printf(STORAGEDIR "/%s.%s", ssid, type);
|
path = l_strdup_printf(STORAGEDIR "/%s.%s", ssid,
|
||||||
|
security_to_str(type));
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@ -250,12 +252,12 @@ const char *storage_network_ssid_from_path(const char *path,
|
|||||||
return buf;
|
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;
|
struct l_settings *settings;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if (ssid == NULL || type == NULL)
|
if (ssid == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
path = get_network_file_path(type, ssid);
|
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;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
int storage_network_touch(const char *type, const char *ssid)
|
int storage_network_touch(enum security type, const char *ssid)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (ssid == NULL || type == NULL)
|
if (ssid == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
path = get_network_file_path(type, ssid);
|
path = get_network_file_path(type, ssid);
|
||||||
@ -288,14 +290,14 @@ int storage_network_touch(const char *type, const char *ssid)
|
|||||||
return -errno;
|
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)
|
struct timespec *mtim)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int ret;
|
int ret;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (ssid == NULL || type == NULL)
|
if (ssid == NULL)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
path = get_network_file_path(type, ssid);
|
path = get_network_file_path(type, ssid);
|
||||||
@ -314,7 +316,7 @@ int storage_network_get_mtime(const char *type, const char *ssid,
|
|||||||
return 0;
|
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)
|
struct l_settings *settings)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
@ -328,7 +330,7 @@ void storage_network_sync(const char *type, const char *ssid,
|
|||||||
l_free(path);
|
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;
|
char *path;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -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,
|
const char *storage_network_ssid_from_path(const char *path,
|
||||||
enum security *type);
|
enum security *type);
|
||||||
|
|
||||||
struct l_settings *storage_network_open(const char *type, const char *ssid);
|
struct l_settings *storage_network_open(enum security type, const char *ssid);
|
||||||
int storage_network_touch(const char *type, const char *ssid);
|
int storage_network_touch(enum security type, const char *ssid);
|
||||||
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);
|
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);
|
struct l_settings *settings);
|
||||||
int storage_network_remove(const char *type, const char *ssid);
|
int storage_network_remove(enum security type, const char *ssid);
|
||||||
|
Loading…
Reference in New Issue
Block a user