From d884e9757624383cabe42b40b62f21c275b59552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=2E=20=C4=B0brahim=20G=C3=BCng=C3=B6r?= Date: Tue, 22 Nov 2016 16:04:53 +0300 Subject: [PATCH] wifi: fix parsing of connmanctl output Also follow the coding style. --- wifi/drivers/connmanctl.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/wifi/drivers/connmanctl.c b/wifi/drivers/connmanctl.c index b8cfbf9cba..773b3ba26b 100644 --- a/wifi/drivers/connmanctl.c +++ b/wifi/drivers/connmanctl.c @@ -102,7 +102,20 @@ static bool connmanctl_ssid_is_online(unsigned i) if (connman_counter == 60) { connman_counter = 0; - strlcpy(service, line+25, sizeof(service)); + + static struct string_list* list = NULL; + list = string_split(line, " "); + if (!list) + return false; + + if (list->size == 0) + { + string_list_free(list); + return false; + } + + strlcpy(service, list->elems[list->size-1].data, sizeof(service)); + string_list_free(list); strlcat(command, "connmanctl services ", sizeof(command)); strlcat(command, service, sizeof(command)); @@ -146,17 +159,19 @@ static bool connmanctl_connect_ssid(unsigned i, const char* passphrase) // '*A0 SSID some_unique_id' // ' SSID some_another_unique_id' list = string_split(line+4, " "); - if(!list) - return false; + if (!list) + return false; - if (list->size == 0) { - string_list_free(list); - return false; + if (list->size == 0) + { + string_list_free(list); + return false; } - for (int i = 0; i < list->size-1; i++) { - strlcat(name, list->elems[i].data, sizeof(name)); - strlcat(name, " ", sizeof(name)); + for (int i = 0; i < list->size-1; i++) + { + strlcat(name, list->elems[i].data, sizeof(name)); + strlcat(name, " ", sizeof(name)); } strlcpy(service, list->elems[list->size-1].data, sizeof(service));