From 69772dc644e1ccc12b6394267f010100470f3c95 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Sun, 10 May 2009 09:27:07 -0700 Subject: nexus: Move to a line based protocol (similar to FTP) + fix bugs Signed-off-by: San Mehat --- nexus/ScanResult.cpp | 58 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'nexus/ScanResult.cpp') diff --git a/nexus/ScanResult.cpp b/nexus/ScanResult.cpp index b7237b57..dc7599af 100644 --- a/nexus/ScanResult.cpp +++ b/nexus/ScanResult.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ #include +#include #define LOG_TAG "ScanResult" #include @@ -24,30 +25,53 @@ ScanResult::ScanResult() { } ScanResult::ScanResult(char *rawResult) { - char *tok, *next = NULL; + char *p = rawResult, *q = rawResult; + char tmp[255]; - if (!(tok = strtok_r(rawResult, "\t", &next))) - goto out_bad; - mBssid = strdup(tok); + // BSSID + for (q = p; *q != '\t'; ++q); + strncpy(tmp, p, (q - p)); + tmp[q-p] = '\0'; + mBssid = strdup(tmp); + ++q; - if (!(tok = strtok_r(NULL, "\t", &next))) - goto out_bad; - mFreq = atoi(tok); + // FREQ + for (p = q; *q != '\t'; ++q); + strncpy(tmp, p, (q - p)); + tmp[q-p] = '\0'; + mFreq = atoi(tmp); + ++q; - if (!(tok = strtok_r(NULL, "\t", &next))) - goto out_bad; - mLevel = atoi(tok); + // LEVEL + for (p = q; *q != '\t'; ++q); + strncpy(tmp, p, (q - p)); + tmp[q-p] = '\0'; + mLevel = atoi(tmp); + ++q; - if (!(tok = strtok_r(rawResult, "\t", &next))) - goto out_bad; - mFlags = strdup(tok); + // FLAGS + for (p = q; *q != '\t'; ++q); + strncpy(tmp, p, (q - p)); + tmp[q-p] = '\0'; + mFlags = strdup(tmp); + ++q; - if (!(tok = strtok_r(rawResult, "\t", &next))) - goto out_bad; - mSsid = strdup(tok); + // XXX: For some reason Supplicant sometimes sends a double-tab here. + // haven't had time to dig into it ... + if (*q == '\t') + q++; + + for (p = q; *q != '\t'; ++q) { + if (*q == '\0') + break; + } - return; + strncpy(tmp, p, (q - p)); + tmp[q-p] = '\0'; + mSsid = strdup(tmp); + ++q; + return; out_bad: LOGW("Malformatted scan result (%s)", rawResult); } -- cgit v1.2.3