wpa_gui-qt4: Fix network selection

Use regular expression matches to see if input is not the (now translated?)
string "Select any network" and is a "<network id>: <ssid>" string or the
"all" keyword where that is applicable.

Signed-off-by: Kel Modderman <kel@otaku42.de>
This commit is contained in:
Kel Modderman 2010-05-02 11:17:13 +03:00 committed by Jouni Malinen
parent adc8d4a791
commit 1491f8a785

View file

@ -971,17 +971,10 @@ void WpaGui::selectNetwork( const QString &sel )
char reply[10]; char reply[10];
size_t reply_len = sizeof(reply); size_t reply_len = sizeof(reply);
if (cmd.compare(tr("Select any network"))) { if (cmd.contains(QRegExp("^\\d+:")))
cmd.truncate(cmd.indexOf(':'));
else
cmd = "any"; cmd = "any";
} else {
int pos = cmd.indexOf(':');
if (pos < 0) {
printf("Invalid selectNetwork '%s'\n",
cmd.toAscii().constData());
return;
}
cmd.truncate(pos);
}
cmd.prepend("SELECT_NETWORK "); cmd.prepend("SELECT_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len); ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
triggerUpdate(); triggerUpdate();
@ -995,14 +988,12 @@ void WpaGui::enableNetwork(const QString &sel)
char reply[10]; char reply[10];
size_t reply_len = sizeof(reply); size_t reply_len = sizeof(reply);
if (!cmd.startsWith("all")) { if (cmd.contains(QRegExp("^\\d+:")))
int pos = cmd.indexOf(':'); cmd.truncate(cmd.indexOf(':'));
if (pos < 0) { else if (!cmd.startsWith("all")) {
printf("Invalid enableNetwork '%s'\n", printf("Invalid editNetwork '%s'\n",
cmd.toAscii().constData()); cmd.toAscii().constData());
return; return;
}
cmd.truncate(pos);
} }
cmd.prepend("ENABLE_NETWORK "); cmd.prepend("ENABLE_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len); ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
@ -1016,14 +1007,12 @@ void WpaGui::disableNetwork(const QString &sel)
char reply[10]; char reply[10];
size_t reply_len = sizeof(reply); size_t reply_len = sizeof(reply);
if (!cmd.startsWith("all")) { if (cmd.contains(QRegExp("^\\d+:")))
int pos = cmd.indexOf(':'); cmd.truncate(cmd.indexOf(':'));
if (pos < 0) { else if (!cmd.startsWith("all")) {
printf("Invalid disableNetwork '%s'\n", printf("Invalid editNetwork '%s'\n",
cmd.toAscii().constData()); cmd.toAscii().constData());
return; return;
}
cmd.truncate(pos);
} }
cmd.prepend("DISABLE_NETWORK "); cmd.prepend("DISABLE_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len); ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
@ -1036,14 +1025,8 @@ void WpaGui::editNetwork(const QString &sel)
QString cmd(sel); QString cmd(sel);
int id = -1; int id = -1;
if (!cmd.compare(tr("Select any network"))) { if (cmd.contains(QRegExp("^\\d+:"))) {
int pos = sel.indexOf(':'); cmd.truncate(cmd.indexOf(':'));
if (pos < 0) {
printf("Invalid editNetwork '%s'\n",
cmd.toAscii().constData());
return;
}
cmd.truncate(pos);
id = cmd.toInt(); id = cmd.toInt();
} }
@ -1114,17 +1097,12 @@ void WpaGui::removeNetwork(const QString &sel)
char reply[10]; char reply[10];
size_t reply_len = sizeof(reply); size_t reply_len = sizeof(reply);
if (cmd.compare(tr("Select any network"))) if (cmd.contains(QRegExp("^\\d+:")))
cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) {
printf("Invalid editNetwork '%s'\n",
cmd.toAscii().constData());
return; return;
if (!cmd.startsWith("all")) {
int pos = cmd.indexOf(':');
if (pos < 0) {
printf("Invalid removeNetwork '%s'\n",
cmd.toAscii().constData());
return;
}
cmd.truncate(pos);
} }
cmd.prepend("REMOVE_NETWORK "); cmd.prepend("REMOVE_NETWORK ");
ctrlRequest(cmd.toAscii().constData(), reply, &reply_len); ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);