mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 12:40:16 +01:00
glib-aux: move ssid utils from "libnm-core-impl" to "libnm-glib-aux"
The purpose is of course to be able to use it outside of the internal API from libnm-core-intern.
This commit is contained in:
parent
b3f5113503
commit
5c790db8b6
6 changed files with 78 additions and 66 deletions
|
|
@ -1822,7 +1822,7 @@ _scan_kickoff(NMDeviceWifi *self)
|
|||
|
||||
strv = g_new(char *, ssids->len + 1u);
|
||||
for (i = 0; i < ssids->len; i++)
|
||||
strv[i] = _nm_utils_ssid_to_string(ssids->pdata[i]);
|
||||
strv[i] = _nm_utils_ssid_to_string_gbytes(ssids->pdata[i]);
|
||||
strv[i] = NULL;
|
||||
|
||||
nm_assert(ssids->len > 0);
|
||||
|
|
@ -1986,19 +1986,19 @@ supplicant_iface_bss_changed_cb(NMSupplicantInterface *iface,
|
|||
|
||||
/* Let the manager try to fill in the SSID from seen-bssids lists */
|
||||
ssid = nm_wifi_ap_get_ssid(ap);
|
||||
if (!ssid || _nm_utils_is_empty_ssid(ssid)) {
|
||||
if (!ssid || _nm_utils_is_empty_ssid_gbytes(ssid)) {
|
||||
/* Try to fill the SSID from the AP database */
|
||||
try_fill_ssid_for_hidden_ap(self, ap);
|
||||
|
||||
ssid = nm_wifi_ap_get_ssid(ap);
|
||||
if (ssid && !_nm_utils_is_empty_ssid(ssid)) {
|
||||
if (ssid && !_nm_utils_is_empty_ssid_gbytes(ssid)) {
|
||||
gs_free char *s = NULL;
|
||||
|
||||
/* Yay, matched it, no longer treat as hidden */
|
||||
_LOGD(LOGD_WIFI,
|
||||
"matched hidden AP %s => %s",
|
||||
nm_wifi_ap_get_address(ap),
|
||||
(s = _nm_utils_ssid_to_string(ssid)));
|
||||
(s = _nm_utils_ssid_to_string_gbytes(ssid)));
|
||||
} else {
|
||||
/* Didn't have an entry for this AP in the database */
|
||||
_LOGD(LOGD_WIFI, "failed to match hidden AP %s", nm_wifi_ap_get_address(ap));
|
||||
|
|
@ -2483,7 +2483,7 @@ supplicant_iface_state(NMDeviceWifi * self,
|
|||
"Activation: (wifi) Stage 2 of 5 (Device Configure) successful. %s %s",
|
||||
priv->mode == NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot"
|
||||
: "Connected to wireless network",
|
||||
(ssid_str = _nm_utils_ssid_to_string(ssid)));
|
||||
(ssid_str = _nm_utils_ssid_to_string_gbytes(ssid)));
|
||||
nm_device_activate_schedule_stage3_ip_config_start(device);
|
||||
} else if (devstate == NM_DEVICE_STATE_ACTIVATED)
|
||||
periodic_update(self);
|
||||
|
|
@ -2599,9 +2599,9 @@ supplicant_iface_notify_current_bss(NMSupplicantInterface *iface,
|
|||
_LOGD(LOGD_WIFI,
|
||||
"roamed from BSSID %s (%s) to %s (%s)",
|
||||
old_bssid ?: "(none)",
|
||||
(old_ssid_s = _nm_utils_ssid_to_string(old_ssid)),
|
||||
(old_ssid_s = _nm_utils_ssid_to_string_gbytes(old_ssid)),
|
||||
new_bssid ?: "(none)",
|
||||
(new_ssid_s = _nm_utils_ssid_to_string(new_ssid)));
|
||||
(new_ssid_s = _nm_utils_ssid_to_string_gbytes(new_ssid)));
|
||||
|
||||
if (new_bssid) {
|
||||
/* The new AP could be in a different layer 3 network
|
||||
|
|
|
|||
|
|
@ -517,7 +517,7 @@ nm_wifi_ap_to_string(const NMWifiAP *self, char *str_buf, gulong buf_len, gint64
|
|||
buf_len,
|
||||
"%17s %-35s [ %c %3u %3u%% %c%c %c%c W:%04X R:%04X ] %s sup:%s [nm:%s]",
|
||||
priv->address ?: "(none)",
|
||||
(ssid_to_free = _nm_utils_ssid_to_string(priv->ssid)),
|
||||
(ssid_to_free = _nm_utils_ssid_to_string_gbytes(priv->ssid)),
|
||||
(priv->mode == NM_802_11_MODE_ADHOC
|
||||
? '*'
|
||||
: (priv->hotspot
|
||||
|
|
|
|||
|
|
@ -630,28 +630,7 @@ _nm_utils_ssid_to_utf8(GBytes *ssid)
|
|||
gboolean
|
||||
nm_utils_is_empty_ssid(const guint8 *ssid, gsize len)
|
||||
{
|
||||
/* Single white space is for Linksys APs */
|
||||
if (len == 1 && ssid[0] == ' ')
|
||||
return TRUE;
|
||||
|
||||
/* Otherwise, if the entire ssid is 0, we assume it is hidden */
|
||||
while (len--) {
|
||||
if (ssid[len] != '\0')
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_utils_is_empty_ssid(GBytes *ssid)
|
||||
{
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
|
||||
g_return_val_if_fail(ssid, FALSE);
|
||||
|
||||
p = g_bytes_get_data(ssid, &l);
|
||||
return nm_utils_is_empty_ssid(p, l);
|
||||
return _nm_utils_is_empty_ssid_arr(ssid, len);
|
||||
}
|
||||
|
||||
#define ESSID_MAX_SIZE 32
|
||||
|
|
@ -695,38 +674,6 @@ nm_utils_escape_ssid(const guint8 *ssid, gsize len)
|
|||
return escaped;
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len)
|
||||
{
|
||||
gs_free char *s_copy = NULL;
|
||||
const char * s_cnst;
|
||||
|
||||
if (len == 0)
|
||||
return g_strdup("(empty)");
|
||||
|
||||
s_cnst =
|
||||
nm_utils_buf_utf8safe_escape(ssid, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &s_copy);
|
||||
nm_assert(s_cnst);
|
||||
|
||||
if (nm_utils_is_empty_ssid(ssid, len))
|
||||
return g_strdup_printf("\"%s\" (hidden)", s_cnst);
|
||||
|
||||
return g_strdup_printf("\"%s\"", s_cnst);
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_string(GBytes *ssid)
|
||||
{
|
||||
gconstpointer p;
|
||||
gsize l;
|
||||
|
||||
if (!ssid)
|
||||
return g_strdup("(none)");
|
||||
|
||||
p = g_bytes_get_data(ssid, &l);
|
||||
return _nm_utils_ssid_to_string_arr(p, l);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_same_ssid:
|
||||
* @ssid1: (array length=len1): the first SSID to compare
|
||||
|
|
|
|||
|
|
@ -484,10 +484,7 @@ gboolean _nm_dbus_error_has_name(GError *error, const char *dbus_error_name);
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
char * _nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len);
|
||||
char * _nm_utils_ssid_to_string(GBytes *ssid);
|
||||
char * _nm_utils_ssid_to_utf8(GBytes *ssid);
|
||||
gboolean _nm_utils_is_empty_ssid(GBytes *ssid);
|
||||
char *_nm_utils_ssid_to_utf8(GBytes *ssid);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -5739,3 +5739,64 @@ nm_utils_exp10(gint16 ex)
|
|||
return _exp10(ex);
|
||||
return 1.0 / _exp10(-((gint32) ex));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean
|
||||
_nm_utils_is_empty_ssid_arr(const guint8 *ssid, gsize len)
|
||||
{
|
||||
/* Single white space is for Linksys APs */
|
||||
if (len == 1 && ssid[0] == ' ')
|
||||
return TRUE;
|
||||
|
||||
/* Otherwise, if the entire ssid is 0, we assume it is hidden */
|
||||
while (len--) {
|
||||
if (ssid[len] != '\0')
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_utils_is_empty_ssid_gbytes(GBytes *ssid)
|
||||
{
|
||||
const guint8 *p;
|
||||
gsize l;
|
||||
|
||||
g_return_val_if_fail(ssid, FALSE);
|
||||
|
||||
p = g_bytes_get_data(ssid, &l);
|
||||
return _nm_utils_is_empty_ssid_arr(p, l);
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len)
|
||||
{
|
||||
gs_free char *s_copy = NULL;
|
||||
const char * s_cnst;
|
||||
|
||||
if (len == 0)
|
||||
return g_strdup("(empty)");
|
||||
|
||||
s_cnst =
|
||||
nm_utils_buf_utf8safe_escape(ssid, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &s_copy);
|
||||
nm_assert(s_cnst);
|
||||
|
||||
if (_nm_utils_is_empty_ssid_arr(ssid, len))
|
||||
return g_strdup_printf("\"%s\" (hidden)", s_cnst);
|
||||
|
||||
return g_strdup_printf("\"%s\"", s_cnst);
|
||||
}
|
||||
|
||||
char *
|
||||
_nm_utils_ssid_to_string_gbytes(GBytes *ssid)
|
||||
{
|
||||
gconstpointer p;
|
||||
gsize l;
|
||||
|
||||
if (!ssid)
|
||||
return g_strdup("(none)");
|
||||
|
||||
p = g_bytes_get_data(ssid, &l);
|
||||
return _nm_utils_ssid_to_string_arr(p, l);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2495,4 +2495,11 @@ gboolean nm_utils_name_to_uid(const char *name, uid_t *out_uid);
|
|||
|
||||
double nm_utils_exp10(gint16 e);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean _nm_utils_is_empty_ssid_arr(const guint8 *ssid, gsize len);
|
||||
gboolean _nm_utils_is_empty_ssid_gbytes(GBytes *ssid);
|
||||
char * _nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len);
|
||||
char * _nm_utils_ssid_to_string_gbytes(GBytes *ssid);
|
||||
|
||||
#endif /* __NM_SHARED_UTILS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue