From 8be78588e230778417832072470cb236722f0273 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Tue, 7 Jun 2016 05:29:57 +0200 Subject: [PATCH] common: Add security_from_str The reverse operation of security_to_str. --- src/common.c | 17 +++++++++++++++++ src/common.h | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/common.c b/src/common.c index 71376815..77265994 100644 --- a/src/common.c +++ b/src/common.c @@ -25,6 +25,7 @@ #endif #include +#include #include "src/iwd.h" #include "src/common.h" @@ -44,3 +45,19 @@ const char *security_to_str(enum security security) return NULL; } + +bool security_from_str(const char *str, enum security *security) +{ + if (!strcmp(str, "open")) + *security = SECURITY_NONE; + else if (!strcmp(str, "wep")) + *security = SECURITY_WEP; + else if (!strcmp(str, "psk")) + *security = SECURITY_PSK; + else if (!strcmp(str, "8021x")) + *security = SECURITY_8021X; + else + return false; + + return true; +} diff --git a/src/common.h b/src/common.h index e300524e..766d0bea 100644 --- a/src/common.h +++ b/src/common.h @@ -20,4 +20,9 @@ * */ +#include + +enum security; + const char *security_to_str(enum security security); +bool security_from_str(const char *str, enum security *security);