From e04ae506a38f57ee4aae0af879455be8670c2471 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Mon, 1 Feb 2021 11:22:42 -0600 Subject: [PATCH] network: rework network_connect_new_hidden_network Rework the logic slightly so that this function returns an error message on error and NULL on success, just like other D-Bus method implementations. This also simplifies the code slightly. --- src/network.c | 41 +++++++++++++++++------------------------ src/network.h | 5 +++-- src/station.c | 11 +++++++---- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/network.c b/src/network.c index 0d2506e7..15a34d66 100644 --- a/src/network.c +++ b/src/network.c @@ -1192,19 +1192,22 @@ static struct l_dbus_message *network_connect(struct l_dbus *dbus, } } -void network_connect_new_hidden_network(struct network *network, - struct l_dbus_message **message) +/* + * Returns an error message in case an error occurs. Otherwise this function + * returns NULL and takes a reference to message. Callers should unref + * their copy in this case + */ +struct l_dbus_message *network_connect_new_hidden_network( + struct network *network, + struct l_dbus_message *message) { struct station *station = network->station; struct scan_bss *bss; - struct l_dbus_message *error; l_debug(""); - if (network->agent_request) { - error = dbus_error_busy(*message); - goto reply_error; - } + if (network->agent_request) + return dbus_error_busy(message); /* * This is not a Known Network. If connection succeeds, either @@ -1213,34 +1216,24 @@ void network_connect_new_hidden_network(struct network *network, */ bss = network_bss_select(network, true); - if (!bss) { - /* This should never happened for the hidden networks. */ - error = dbus_error_not_supported(*message); - goto reply_error; - } + /* This should never happened for the hidden networks. */ + if (!bss) + return dbus_error_not_supported(message); network->settings = l_settings_new(); l_settings_set_bool(network->settings, "Settings", "Hidden", true); switch (network_get_security(network)) { case SECURITY_PSK: - error = network_connect_psk(network, bss, *message); - break; + return network_connect_psk(network, bss, message); case SECURITY_NONE: - station_connect_network(station, network, bss, *message); - return; + station_connect_network(station, network, bss, message); + return NULL; default: - error = dbus_error_not_supported(*message); break; } - if (error) - goto reply_error; - - return; - -reply_error: - dbus_pending_reply(message, error); + return dbus_error_not_supported(message); } void network_blacklist_add(struct network *network, struct scan_bss *bss) diff --git a/src/network.h b/src/network.h index c008c04c..22561834 100644 --- a/src/network.h +++ b/src/network.h @@ -69,8 +69,9 @@ void network_remove(struct network *network, int reason); int network_rank_compare(const void *a, const void *b, void *user); void network_rank_update(struct network *network, bool connected); -void network_connect_new_hidden_network(struct network *network, - struct l_dbus_message **message); +struct l_dbus_message *network_connect_new_hidden_network( + struct network *network, + struct l_dbus_message *message); void network_blacklist_add(struct network *network, struct scan_bss *bss); diff --git a/src/station.c b/src/station.c index afd01f4d..2abde50c 100644 --- a/src/station.c +++ b/src/station.c @@ -2589,10 +2589,10 @@ static bool station_hidden_network_scan_results(int err, struct station *station = userdata; struct network *network_psk; struct network *network_open; - struct network *network; const char *ssid; uint8_t ssid_len; struct l_dbus_message *msg; + struct l_dbus_message *error; struct scan_bss *bss; l_debug(""); @@ -2644,10 +2644,13 @@ next: return true; } - network = network_psk ? : network_open; + error = network_connect_new_hidden_network(network_psk ?: network_open, + msg); - network_connect_new_hidden_network(network, &msg); - l_dbus_message_unref(msg); + if (error) + dbus_pending_reply(&msg, error); + else + l_dbus_message_unref(msg); return true; }