Merge lp:~ted/indicator-network/blank-items into lp:indicator-network/13.10

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 304
Merged at revision: 294
Proposed branch: lp:~ted/indicator-network/blank-items
Merge into: lp:indicator-network/13.10
Diff against target: 226 lines (+107/-14)
5 files modified
network/CMakeLists.txt (+3/-0)
network/device-wifi.vala (+49/-14)
network/util-wrapper.c (+30/-0)
network/util-wrapper.h (+20/-0)
network/util-wrapper.vapi (+5/-0)
To merge this branch: bzr merge lp:~ted/indicator-network/blank-items
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Sebastien Bacher Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+189754@code.launchpad.net

Commit message

Ensure APs with SSIDs we don't want to show aren't shown

Description of the change

This change reshuffles the AP handling a little bit in that we're looking at each item that we're creating, and possibily rejecting the menu item getting created at all. But, because there is some amount of uncertainty here, we need to track each and ensure that if the SSID updates to something valid, we can then show it. So this branch makes sure to set up notification of that change, and then rejects anything we might see as suspect.

To use the NM Utils library we required a small wrapper there as the NM VAPI isn't quite clear on what it wants and I didn't want to force it. Making our own wrapper function made things a lot cleaner, even though it makes the diff much larger.

To post a comment you must log in.
303. By Ted Gould

Make sure to grab the header for prototypes

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Jenkins hickup.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, that seems to fix the issue, it just hit a segfaults though:

#0 util_wrapper_is_empty_ssid (bytes=0x0)
    at /home/seb128/boulot/package/download/ted/build-area/indicator-network-0.5.1+13.10.20131005/network/util-wrapper.c:26
#1 0x08053bbb in network_device_wifi_menu_insert_ap_item (
    self=self@entry=0x8bbe370, ap=ap@entry=0x8bd72c8)
    at /home/seb128/boulot/package/download/ted/build-area/indicator-network-0.5.1+13.10.20131005/obj-i686-linux-gnu/network/device-wifi.c:774
#2 0x080542b7 in network_device_wifi_menu_access_point_added_cb (
    self=0x8bbe370, device=<optimized out>, user_data=<optimized out>)
    at /home/seb128/boulot/package/download/ted/build-area/indicator-network-0.5.1+13.10.20131005/obj-i686-linux-gnu/network/device-wifi.c:599
#3 0xb75c558e in g_cclosure_marshal_VOID__OBJECT (closure=0x8c0bd58,
    return_value=0x0, n_param_values=2, param_values=0xbf887d50,
    invocation_hint=0xbf887cfc, marshal_data=0x0)
    at /build/buildd/glib2.0-2.38.0/./gobject/gmarshal.c:1272
#4 0xb75c28ae in g_closure_invoke (closure=0x8c0bd58,
    return_value=return_value@entry=0x0, n_param_values=2,
    param_values=param_values@entry=0xbf887d50,
    invocation_hint=invocation_hint@entry=0xbf887cfc)
    at /build/buildd/glib2.0-2.38.0/./gobject/gclosure.c:777

review: Needs Fixing
304. By Ted Gould

Check for the byte array being NULL

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

The new revision works fine on my system which used to have the issue, thanks! The code looks fine as well, but I just had easy look at it so it would be good to get another code review but getting that in still

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

(but getting that in -> before getting that in)

Revision history for this message
Charles Kerr (charlesk) wrote :

Code level looks OK.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'network/CMakeLists.txt'
2--- network/CMakeLists.txt 2013-09-06 16:19:21 +0000
3+++ network/CMakeLists.txt 2013-10-08 15:00:14 +0000
4@@ -16,6 +16,7 @@
5 CUSTOM_VAPIS
6 "${CMAKE_CURRENT_SOURCE_DIR}/action-muxer.vapi"
7 "${CMAKE_CURRENT_SOURCE_DIR}/url-dispatcher.vapi"
8+ "${CMAKE_CURRENT_SOURCE_DIR}/util-wrapper.vapi"
9 )
10
11 vala_add(libnetwork
12@@ -103,6 +104,7 @@
13 ${LIBNETWORK_VALA_SOURCES}
14 ${LIBNETWORK_VALA_C}
15 action-muxer.c
16+ util-wrapper.c
17 )
18
19 add_library(
20@@ -130,6 +132,7 @@
21 CUSTOM_VAPIS
22 "${CMAKE_CURRENT_SOURCE_DIR}/config.vapi"
23 "${CMAKE_CURRENT_SOURCE_DIR}/action-muxer.vapi"
24+ "${CMAKE_CURRENT_SOURCE_DIR}/util-wrapper.vapi"
25 OPTIONS
26 --vapidir=.
27 )
28
29=== modified file 'network/device-wifi.vala'
30--- network/device-wifi.vala 2013-09-30 18:49:50 +0000
31+++ network/device-wifi.vala 2013-10-08 15:00:14 +0000
32@@ -32,6 +32,7 @@
33 private NM.Client client;
34 private string action_prefix;
35 private bool show_settings;
36+ private HashTable<string, NM.AccessPoint> aps = new HashTable<string, NM.AccessPoint>(str_hash, str_equal);
37
38 public WifiMenu (NM.Client client, DeviceWifi device, Menu global_menu, SimpleActionGroup actions, string action_prefix, bool show_settings)
39 {
40@@ -61,12 +62,17 @@
41
42 for (uint i = 0; i<aps.length; i++)
43 {
44- insert_ap (aps.get (i));
45+ access_point_added_cb (device, aps.get (i));
46 }
47 }
48
49 ~WifiMenu ()
50 {
51+ /* Make sure to clean up! */
52+ foreach (var ap in aps.get_values()) {
53+ access_point_removed_cb(this.device, ap);
54+ }
55+
56 device.access_point_added.disconnect (access_point_added_cb);
57 device.access_point_removed.disconnect (access_point_removed_cb);
58 device.notify.disconnect (active_access_point_changed);
59@@ -89,14 +95,36 @@
60 item.set_attribute ("action", "s", activate_action_id);
61 }
62
63- private void access_point_added_cb (NM.DeviceWifi device, GLib.Object ap)
64- {
65- insert_ap ((AccessPoint)ap);
66- }
67-
68- private void access_point_removed_cb (NM.DeviceWifi device, GLib.Object ap)
69- {
70- remove_ap ((AccessPoint)ap);
71+ private void access_point_ssid_cb (GLib.Object obj, GLib.ParamSpec pspec)
72+ {
73+ AccessPoint ap = (AccessPoint)obj;
74+ remove_ap_item(ap);
75+ insert_ap_item(ap);
76+ }
77+
78+ private void access_point_added_cb (NM.DeviceWifi device, GLib.Object user_data)
79+ {
80+ AccessPoint ap = (AccessPoint)user_data;
81+ string ap_path = ap.get_path();
82+
83+ if (aps.lookup(ap_path) == null) {
84+ aps.insert(ap_path, ap);
85+ insert_ap_item (ap);
86+
87+ ap.notify["ssid"].connect(access_point_ssid_cb);
88+ }
89+ }
90+
91+ private void access_point_removed_cb (NM.DeviceWifi device, GLib.Object user_data)
92+ {
93+ AccessPoint ap = (AccessPoint)user_data;
94+ string ap_path = ap.get_path();
95+
96+ if (aps.lookup(ap_path) == null) {
97+ ap.notify["ssid"].disconnect(access_point_ssid_cb);
98+ aps.remove(ap_path);
99+ remove_ap_item (ap);
100+ }
101 }
102
103 private void active_access_point_changed (GLib.Object obj, ParamSpec pspec)
104@@ -126,15 +154,23 @@
105 * - Previously used APs are ordered by signal strength
106 * - Unused APs are ordered by signal strength
107 */
108- private void insert_ap (AccessPoint ap)
109+ private void insert_ap_item (AccessPoint ap)
110 {
111 var rs = new NM.RemoteSettings (null);
112 SList <NM.Connection>? dev_conns = null;
113 bool has_connection = false;
114+ string label;
115
116 if (ap == null)
117 return;
118
119+ if (UtilWrapper.is_empty_ssid(ap.get_ssid ()))
120+ return;
121+
122+ label = Utils.ssid_to_utf8(ap.get_ssid ());
123+ if (label == null || label[0] == '\0')
124+ return;
125+
126 //If it is the active access point it always goes first
127 if (ap == device.active_access_point)
128 {
129@@ -155,7 +191,7 @@
130
131
132 //Remove duplicate SSID
133- for (int i = 1; i < apsmenu.get_n_items(); i++)
134+ for (int i = 0; i < apsmenu.get_n_items(); i++)
135 {
136 string path;
137
138@@ -182,8 +218,7 @@
139 //Find the right spot for the AP
140 var item = new MenuItem (null, null);
141 bind_ap_item (ap, item);
142- /* We need to start at 1 and end at -1 to avoid the toggle and the settings */
143- for (int i = 1; i < apsmenu.get_n_items() - 1; i++)
144+ for (int i = 0; i < apsmenu.get_n_items(); i++)
145 {
146 string path;
147
148@@ -245,7 +280,7 @@
149 return ap_conns.length () > 0;
150 }
151
152- private void remove_ap (AccessPoint ap)
153+ private void remove_ap_item (AccessPoint ap)
154 {
155 for (int i = 1; i < apsmenu.get_n_items(); i++)
156 {
157
158=== added file 'network/util-wrapper.c'
159--- network/util-wrapper.c 1970-01-01 00:00:00 +0000
160+++ network/util-wrapper.c 2013-10-08 15:00:14 +0000
161@@ -0,0 +1,30 @@
162+/*
163+ * Copyright 2013 Canonical Ltd.
164+ *
165+ * This program is free software: you can redistribute it and/or modify it
166+ * under the terms of the GNU General Public License version 3, as published
167+ * by the Free Software Foundation.
168+ *
169+ * This program is distributed in the hope that it will be useful, but
170+ * WITHOUT ANY WARRANTY; without even the implied warranties of
171+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
172+ * PURPOSE. See the GNU General Public License for more details.
173+ *
174+ * You should have received a copy of the GNU General Public License along
175+ * with this program. If not, see <http://www.gnu.org/licenses/>.
176+ *
177+ * Authors:
178+ * Ted Gould <ted@canonical.com>
179+ */
180+
181+#include <glib.h>
182+#include <NetworkManager/nm-utils.h>
183+
184+gboolean
185+util_wrapper_is_empty_ssid (GByteArray * bytes)
186+{
187+ if (bytes == NULL)
188+ return TRUE;
189+
190+ return nm_utils_is_empty_ssid(bytes->data, bytes->len);
191+}
192
193=== added file 'network/util-wrapper.h'
194--- network/util-wrapper.h 1970-01-01 00:00:00 +0000
195+++ network/util-wrapper.h 2013-10-08 15:00:14 +0000
196@@ -0,0 +1,20 @@
197+/*
198+ * Copyright 2013 Canonical Ltd.
199+ *
200+ * This program is free software: you can redistribute it and/or modify it
201+ * under the terms of the GNU General Public License version 3, as published
202+ * by the Free Software Foundation.
203+ *
204+ * This program is distributed in the hope that it will be useful, but
205+ * WITHOUT ANY WARRANTY; without even the implied warranties of
206+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
207+ * PURPOSE. See the GNU General Public License for more details.
208+ *
209+ * You should have received a copy of the GNU General Public License along
210+ * with this program. If not, see <http://www.gnu.org/licenses/>.
211+ *
212+ * Authors:
213+ * Ted Gould <ted@canonical.com>
214+ */
215+
216+gboolean util_wrapper_is_empty_ssid (GByteArray * bytes);
217
218=== added file 'network/util-wrapper.vapi'
219--- network/util-wrapper.vapi 1970-01-01 00:00:00 +0000
220+++ network/util-wrapper.vapi 2013-10-08 15:00:14 +0000
221@@ -0,0 +1,5 @@
222+[CCode (cprefix = "UtilWrapper", lower_case_cprefix = "util_wrapper_")]
223+namespace UtilWrapper {
224+ [CCode (cheader_filename = "util-wrapper.h")]
225+ public bool is_empty_ssid (GLib.ByteArray ssid);
226+}

Subscribers

People subscribed via source and target branches