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 station *station = network->station;
struct scan_bss *bss; struct scan_bss *bss;
struct l_dbus_message *error;
l_debug(""); l_debug("");
if (network->agent_request) { if (network->agent_request)
error = dbus_error_busy(*message); return dbus_error_busy(message);
goto reply_error;
}
/* /*
* This is not a Known Network. If connection succeeds, either * 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); bss = network_bss_select(network, true);
if (!bss) { /* This should never happened for the hidden networks. */
/* This should never happened for the hidden networks. */ if (!bss)
error = dbus_error_not_supported(*message); return dbus_error_not_supported(message);
goto reply_error;
}
network->settings = l_settings_new(); network->settings = l_settings_new();
l_settings_set_bool(network->settings, "Settings", "Hidden", true); l_settings_set_bool(network->settings, "Settings", "Hidden", true);
switch (network_get_security(network)) { switch (network_get_security(network)) {
case SECURITY_PSK: case SECURITY_PSK:
error = network_connect_psk(network, bss, *message); return network_connect_psk(network, bss, message);
break;
case SECURITY_NONE: case SECURITY_NONE:
station_connect_network(station, network, bss, *message); station_connect_network(station, network, bss, message);
return; return NULL;
default: default:
error = dbus_error_not_supported(*message);
break; break;
} }
if (error) return dbus_error_not_supported(message);
goto reply_error;
return;
reply_error:
dbus_pending_reply(message, error);
} }
void network_blacklist_add(struct network *network, struct scan_bss *bss) 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); int network_rank_compare(const void *a, const void *b, void *user);
void network_rank_update(struct network *network, bool connected); void network_rank_update(struct network *network, bool connected);
void network_connect_new_hidden_network(struct network *network, struct l_dbus_message *network_connect_new_hidden_network(
struct l_dbus_message **message); struct network *network,
struct l_dbus_message *message);
void network_blacklist_add(struct network *network, struct scan_bss *bss); 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 station *station = userdata;
struct network *network_psk; struct network *network_psk;
struct network *network_open; struct network *network_open;
struct network *network;
const char *ssid; const char *ssid;
uint8_t ssid_len; uint8_t ssid_len;
struct l_dbus_message *msg; struct l_dbus_message *msg;
struct l_dbus_message *error;
struct scan_bss *bss; struct scan_bss *bss;
l_debug(""); l_debug("");
@ -2644,10 +2644,13 @@ next:
return true; 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)
l_dbus_message_unref(msg); dbus_pending_reply(&msg, error);
else
l_dbus_message_unref(msg);
return true; return true;
} }