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.
This commit is contained in:
Denis Kenzior 2021-02-01 11:22:42 -06:00
parent 56538bf75b
commit e04ae506a3
3 changed files with 27 additions and 30 deletions

View File

@ -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;
}
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)

View File

@ -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);

View File

@ -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,9 +2644,12 @@ 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);
if (error)
dbus_pending_reply(&msg, error);
else
l_dbus_message_unref(msg);
return true;