commit e04ae506a38f57ee4aae0af879455be8670c2471
parent 56538bf75b0d92c1b7f19d2c3c66e2b394725289
Author: Denis Kenzior <denkenz@gmail.com>
Date: Mon, 1 Feb 2021 11:22:42 -0600
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.
Diffstat:
3 files changed, 27 insertions(+), 30 deletions(-)
diff --git 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
@@ -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
@@ -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;
}