From e75d8b1791009712ceda58762489f8a7df9c8140 Mon Sep 17 00:00:00 2001 From: Sebastian Wicki Date: Sun, 21 Jul 2013 17:01:09 +0200 Subject: Add wpa_unquote function This function can be used to unquote WPA supplicant config file strings returned from wpa_cli calls. --- src/lib/wpa | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/lib') 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() { -- cgit v1.2.3-24-g4f1b