summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Wicki <gandro@gmx.net>2013-07-21 17:01:09 +0200
committerSebastian Wicki <gandro@gmx.net>2013-07-21 17:01:09 +0200
commite75d8b1791009712ceda58762489f8a7df9c8140 (patch)
tree9ef0b6489a48756511c4084403a10dd80787c506
parent30ea4c009e9ba095eb6ac94655715cc9531d4594 (diff)
downloadnetctl-e75d8b1791009712ceda58762489f8a7df9c8140.tar.gz
netctl-e75d8b1791009712ceda58762489f8a7df9c8140.tar.xz
Add wpa_unquote function
This function can be used to unquote WPA supplicant config file strings returned from wpa_cli calls.
-rw-r--r--src/lib/wpa18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/wpa b/src/lib/wpa
index 65ef8f9..ca9b83e 100644
--- a/src/lib/wpa
+++ b/src/lib/wpa
@@ -167,6 +167,24 @@ wpa_quote() {
fi
}
+## Unquotes a string, i.e. returned from wpa_cli
+## Quoted: "string" -> string
+## Non-Quoted: string -> string
+## Hex: 737472696e67 -> string
+wpa_unquote() {
+ local string="$1"
+ if [[ ${string:0:1} == '"' && ${string:(-1)} == '"' ]]; then
+ printf "%s" "${string:1:-1}"
+ elif [[ "$string" =~ ^([[:xdigit:]]{2})+$ ]]; then
+ while [[ -n "$string" ]]; do
+ printf "\x"${string:0:2}
+ string=${string:2}
+ done
+ else
+ printf "%s" "${string}"
+ fi
+}
+
## Create a configuration file for wpa_supplicant without any network blocks
# $1: interface name
wpa_make_config_file() {