static void add_connections_for_aps (NmtConnectDevice *nmtdev, const GPtrArray *connections) { NmtConnectConnection *nmtconn; NMConnection *conn; NMAccessPoint *ap; const GPtrArray *aps; GHashTable *seen_ssids; GBytes *ssid; char *ap_hash; int i, c; aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nmtdev->device)); if (!aps->len) return; seen_ssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; i < aps->len; i++) { ap = aps->pdata[i]; if (!nm_access_point_get_ssid (ap)) continue; ap_hash = hash_ap (ap); if (g_hash_table_contains (seen_ssids, ap_hash)) { g_free (ap_hash); continue; } g_hash_table_add (seen_ssids, ap_hash); nmtconn = g_slice_new0 (NmtConnectConnection); nmtconn->device = nmtdev->device; nmtconn->ap = g_object_ref (ap); ssid = nm_access_point_get_ssid (ap); if (ssid) nmtconn->ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); for (c = 0; c < connections->len; c++) { conn = connections->pdata[c]; if ( nm_device_connection_valid (nmtdev->device, conn) && nm_access_point_connection_valid (ap, conn)) { nmtconn->name = nm_connection_get_id (conn); nmtconn->conn = g_object_ref (conn); break; } } if (!nmtconn->name) nmtconn->name = nmtconn->ssid ? nmtconn->ssid : "<unknown>"; nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn); } g_hash_table_unref (seen_ssids); }
/** * @brief Inserts a given value into the bloom filter. * * @param key_begin A pointer to the value being inserted. * @param length Size of the value being inserted in bytes. */ inline void insert(const std::uint8_t *key_begin, const std::size_t &length) { std::size_t bit_index = 0; std::size_t bit = 0; for (std::size_t i = 0; i < hash_fn_count_; ++i) { compute_indices(hash_ap(key_begin, length, hash_fn_[i]), &bit_index, &bit); bit_array_[bit_index / kNumBitsPerByte] |= (1 << bit); } ++inserted_element_count_; }
static void add_connections_for_aps (NmtConnectDevice *nmtdev, GSList *connections) { NmtConnectConnection *nmtconn; NMConnection *conn; NMAccessPoint *ap; const GPtrArray *aps; GHashTable *seen_ssids; char *ap_hash; GSList *iter; int i; aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nmtdev->device)); if (!aps) return; seen_ssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; i < aps->len; i++) { ap = aps->pdata[i]; if (!nm_access_point_get_ssid (ap)) continue; ap_hash = hash_ap (ap); if (g_hash_table_contains (seen_ssids, ap_hash)) { g_free (ap_hash); continue; } g_hash_table_add (seen_ssids, ap_hash); nmtconn = g_slice_new0 (NmtConnectConnection); nmtconn->device = nmtdev->device; nmtconn->ap = g_object_ref (ap); nmtconn->ssid = nm_utils_ssid_to_utf8 (nm_access_point_get_ssid (ap)); for (iter = connections; iter; iter = iter->next) { conn = iter->data; if ( nm_device_connection_valid (nmtdev->device, conn) && nm_access_point_connection_valid (ap, conn)) { nmtconn->name = nm_connection_get_id (conn); nmtconn->conn = g_object_ref (conn); break; } } if (!iter) nmtconn->name = nmtconn->ssid; nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn); } g_hash_table_unref (seen_ssids); }
/** * @brief Test membership of a given value in the bloom filter. * If true is returned, then a value may or may not be present in the bloom filter. * If false is returned, a value is certainly not present in the bloom filter. * * @param key_begin A pointer to the value being tested for membership. * @param length Size of the value being inserted in bytes. */ inline bool contains(const std::uint8_t *key_begin, const std::size_t length) const { std::size_t bit_index = 0; std::size_t bit = 0; for (std::size_t i = 0; i < hash_fn_count_; ++i) { compute_indices(hash_ap(key_begin, length, hash_fn_[i]), &bit_index, &bit); if ((bit_array_[bit_index / kNumBitsPerByte] & (1 << bit)) != (1 << bit)) { return false; } } return true; }