summaryrefslogtreecommitdiff
blob: b5d7a0280d56d968ff62d54fd777dd0826ab65f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
From: Kel Modderman <kel@otaku42.de>
Date: Sun, 2 May 2010 08:17:13 +0000 (+0300)
Subject: wpa_gui-qt4: Fix network selection
X-Git-Url: http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap.git;a=commitdiff_plain;h=1491f8a78516a5c773583125bd9691323249a6dc;hp=adc8d4a791ca7ef5245d2030d7096cf8675a3720

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>
---

diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
index 94220f4..e15d751 100644
--- a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
@@ -971,17 +971,10 @@ void WpaGui::selectNetwork( const QString &sel )
 	char reply[10];
 	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";
-	} else {
-		int pos = cmd.indexOf(':');
-		if (pos < 0) {
-			printf("Invalid selectNetwork '%s'\n",
-			       cmd.toAscii().constData());
-			return;
-		}
-		cmd.truncate(pos);
-	}
 	cmd.prepend("SELECT_NETWORK ");
 	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
 	triggerUpdate();
@@ -995,14 +988,12 @@ void WpaGui::enableNetwork(const QString &sel)
 	char reply[10];
 	size_t reply_len = sizeof(reply);
 
-	if (!cmd.startsWith("all")) {
-		int pos = cmd.indexOf(':');
-		if (pos < 0) {
-			printf("Invalid enableNetwork '%s'\n",
-			       cmd.toAscii().constData());
-			return;
-		}
-		cmd.truncate(pos);
+	if (cmd.contains(QRegExp("^\\d+:")))
+		cmd.truncate(cmd.indexOf(':'));
+	else if (!cmd.startsWith("all")) {
+		printf("Invalid editNetwork '%s'\n",
+		       cmd.toAscii().constData());
+		return;
 	}
 	cmd.prepend("ENABLE_NETWORK ");
 	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
@@ -1016,14 +1007,12 @@ void WpaGui::disableNetwork(const QString &sel)
 	char reply[10];
 	size_t reply_len = sizeof(reply);
 
-	if (!cmd.startsWith("all")) {
-		int pos = cmd.indexOf(':');
-		if (pos < 0) {
-			printf("Invalid disableNetwork '%s'\n",
-			       cmd.toAscii().constData());
-			return;
-		}
-		cmd.truncate(pos);
+	if (cmd.contains(QRegExp("^\\d+:")))
+		cmd.truncate(cmd.indexOf(':'));
+	else if (!cmd.startsWith("all")) {
+		printf("Invalid editNetwork '%s'\n",
+		       cmd.toAscii().constData());
+		return;
 	}
 	cmd.prepend("DISABLE_NETWORK ");
 	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
@@ -1036,14 +1025,8 @@ void WpaGui::editNetwork(const QString &sel)
 	QString cmd(sel);
 	int id = -1;
 
-	if (!cmd.compare(tr("Select any network"))) {
-		int pos = sel.indexOf(':');
-		if (pos < 0) {
-			printf("Invalid editNetwork '%s'\n",
-			       cmd.toAscii().constData());
-			return;
-		}
-		cmd.truncate(pos);
+	if (cmd.contains(QRegExp("^\\d+:"))) {
+		cmd.truncate(cmd.indexOf(':'));
 		id = cmd.toInt();
 	}
 
@@ -1114,17 +1097,12 @@ void WpaGui::removeNetwork(const QString &sel)
 	char reply[10];
 	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;
-
-	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 ");
 	ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);