Commit 24adbe3f authored by Tambet Ingo's avatar Tambet Ingo
Browse files

2007-10-09 Tambet Ingo <tambet@gmail.com>

        * src/NetworkManagerUtils.c
        (nm_utils_is_empty_ssid):
        (nm_utils_escape_ssid):
        (nm_utils_same_ssid): Remove. These functions are copied and
pasted in a 
        lot of places, so they belong to libnm-utils instead.

        Now with 100% less compiler warnings:

        * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove,
        * unused.
        (nm_dbus_unescape_object_path): Ditto.
        (nm_utils_ssid_to_utf8): Ditto.
        (nm_utils_is_empty_ssid): Move here from
src/NetworkManagerUtils.c
        (nm_utils_escape_ssid): Ditto.
        (nm_utils_same_ssid): Ditto.

        * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r.
        (add_one_connection_element): Remove an unused variable.
        (impl_manager_get_active_connections): Ditto.

        * src/NetworkManagerPolicy.c (get_device_connection): Remove an
        * unused
        variable.

        * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove
        * a leftover
        from the previous commit.

        * src/nm-device-802-11-wireless.c (set_current_ap): Remove
        * unused variable.
        (real_act_stage1_prepare): Ditto.
        (activation_success_handler): Ditto.
        (get_property): Ditto.

        * src/nm-device-802-3-ethernet.c (real_get_best_connection):
        * Remove unused
        variable.

        * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check
        * for 'ifname',
        it's always set.

        * src/supplicant-manager/nm-supplicant-config.c 
        (nm_supplicant_config_add_setting_wireless): Cast the
GByteArray's 'guint8 *'
        to expected "char *".
        (nm_supplicant_config_add_setting_wireless): Ditto.
        (nm_supplicant_config_remove_option): Remove, not used.

        * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is
        * a guint32,
        not double.
        (test_wireless_enabled): Ifdef out unused function.
        (device_deactivate): Ditto.
        (device_state_changed): Ditto.
        (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils.
        (nm_utils_escape_ssid): Ditto.

        * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in
        * libnm-utils.
        (nm_utils_is_empty_ssid): Ditto.

        * libnm-glib/nm-client.c
        * (nm_client_free_active_connection_element): Remove
        unused variable.

        * libnm-util/nm-setting.c (setting_wireless_destroy): Remove
        * unused variable.
        (setting_vpn_properties_update_secrets): Ditto.
        (int_to_gvalue): Ifdef out for now, not used.
        (byte_to_gvalue): Ditto.

        * libnm-util/dbus-dict-helpers.c
        * (_nmu_dbus_add_dict_entry_string_array): 
        Unused, remove.




git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 591dc59e
2007-10-09 Tambet Ingo <tambet@gmail.com>
* src/NetworkManagerUtils.c
(nm_utils_is_empty_ssid):
(nm_utils_escape_ssid):
(nm_utils_same_ssid): Remove. These functions are copied and pasted in a
lot of places, so they belong to libnm-utils instead.
Now with 100% less compiler warnings:
* libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, unused.
(nm_dbus_unescape_object_path): Ditto.
(nm_utils_ssid_to_utf8): Ditto.
(nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c
(nm_utils_escape_ssid): Ditto.
(nm_utils_same_ssid): Ditto.
* src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r.
(add_one_connection_element): Remove an unused variable.
(impl_manager_get_active_connections): Ditto.
* src/NetworkManagerPolicy.c (get_device_connection): Remove an unused
variable.
* src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove a leftover
from the previous commit.
* src/nm-device-802-11-wireless.c (set_current_ap): Remove unused variable.
(real_act_stage1_prepare): Ditto.
(activation_success_handler): Ditto.
(get_property): Ditto.
* src/nm-device-802-3-ethernet.c (real_get_best_connection): Remove unused
variable.
* src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check for 'ifname',
it's always set.
* src/supplicant-manager/nm-supplicant-config.c
(nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *'
to expected "char *".
(nm_supplicant_config_add_setting_wireless): Ditto.
(nm_supplicant_config_remove_option): Remove, not used.
* libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is a guint32,
not double.
(test_wireless_enabled): Ifdef out unused function.
(device_deactivate): Ditto.
(device_state_changed): Ditto.
(nm_utils_is_empty_ssid): Remove, it's now in libnm-utils.
(nm_utils_escape_ssid): Ditto.
* test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in libnm-utils.
(nm_utils_is_empty_ssid): Ditto.
* libnm-glib/nm-client.c (nm_client_free_active_connection_element): Remove
unused variable.
* libnm-util/nm-setting.c (setting_wireless_destroy): Remove unused variable.
(setting_vpn_properties_update_secrets): Ditto.
(int_to_gvalue): Ifdef out for now, not used.
(byte_to_gvalue): Ditto.
* libnm-util/dbus-dict-helpers.c (_nmu_dbus_add_dict_entry_string_array):
Unused, remove.
2007-10-08 Tambet Ingo <tambet@gmail.com>
* src/NetworkManager.c (main): When dbus manager doesn't want to start, complain
......
......@@ -10,50 +10,9 @@
#include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "nm-utils.h"
/* Shamelessly ripped from the Linux kernel ieee80211 stack */
static gboolean
nm_utils_is_empty_ssid (const char * ssid, int 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;
}
static const char *
nm_utils_escape_ssid (const char * ssid, guint32 len)
{
static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
const char *s = ssid;
char *d = escaped;
if (nm_utils_is_empty_ssid (ssid, len)) {
memcpy (escaped, "<hidden>", sizeof ("<hidden>"));
return escaped;
}
len = MIN (len, (guint32) IW_ESSID_MAX_SIZE);
while (len--) {
if (*s == '\0') {
*d++ = '\\';
*d++ = '0';
s++;
} else {
*d++ = *s++;
}
}
*d = '\0';
return escaped;
}
#if 0
static gboolean
test_wireless_enabled (NMClient *client)
{
......@@ -71,6 +30,7 @@ test_wireless_enabled (NMClient *client)
return TRUE;
}
#endif
static gboolean
test_get_state (NMClient *client)
......@@ -178,7 +138,7 @@ dump_access_point (NMAccessPoint *ap)
g_print ("\tFlags: 0x%X\n", nm_access_point_get_flags (ap));
g_print ("\tWPA Flags: 0x%X\n", nm_access_point_get_wpa_flags (ap));
g_print ("\tRSN Flags: 0x%X\n", nm_access_point_get_rsn_flags (ap));
g_print ("\tFrequency: %f\n", nm_access_point_get_frequency (ap));
g_print ("\tFrequency: %u\n", nm_access_point_get_frequency (ap));
g_print ("\tMode: %d\n", nm_access_point_get_mode (ap));
g_print ("\tRate: %d\n", nm_access_point_get_rate (ap));
......@@ -291,7 +251,7 @@ device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
dump_device (device);
}
#if 0
static gboolean
device_deactivate (gpointer user_data)
{
......@@ -318,6 +278,7 @@ device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data)
device);
}
}
#endif
static void
manager_running (NMClient *client, gboolean running, gpointer user_data)
......
......@@ -530,8 +530,6 @@ nm_client_get_active_connections (NMClient *client)
void
nm_client_free_active_connection_element (NMClientActiveConnection *elt)
{
GSList *iter;
g_return_if_fail (elt != NULL);
g_free (elt->service_name);
......
......@@ -279,52 +279,6 @@ _nmu_dbus_add_dict_entry_uint32_array (DBusMessageIter *iter_dict,
}
static dbus_bool_t
_nmu_dbus_add_dict_entry_string_array (DBusMessageIter *iter_dict,
const char *key,
const char **items,
const dbus_uint32_t num_items)
{
DBusMessageIter iter_dict_entry, iter_dict_val, iter_array;
dbus_uint32_t i;
if (!_nmu_dbus_add_dict_entry_start (iter_dict,
&iter_dict_entry,
key,
DBUS_TYPE_ARRAY))
return FALSE;
if (!dbus_message_iter_open_container (&iter_dict_entry,
DBUS_TYPE_VARIANT,
DBUS_TYPE_ARRAY_AS_STRING
DBUS_TYPE_STRING_AS_STRING,
&iter_dict_val))
return FALSE;
if (!dbus_message_iter_open_container (&iter_dict_val,
DBUS_TYPE_ARRAY,
DBUS_TYPE_BYTE_AS_STRING,
&iter_array))
return FALSE;
for (i = 0; i < num_items; i++) {
if (!dbus_message_iter_append_basic (&iter_array,
DBUS_TYPE_STRING,
&(items[i])))
return FALSE;
}
if (!dbus_message_iter_close_container (&iter_dict_val, &iter_array))
return FALSE;
if (!_nmu_dbus_add_dict_entry_end (iter_dict,
&iter_dict_entry,
&iter_dict_val))
return FALSE;
return TRUE;
}
/**
* Add a string entry to the dict.
*
......
......@@ -172,6 +172,7 @@ boolean_to_gvalue (gboolean b)
return val;
}
#if 0
static GValue *
int_to_gvalue (int i)
{
......@@ -183,6 +184,7 @@ int_to_gvalue (int i)
return val;
}
#endif
static GValue *
uint_to_gvalue (guint32 i)
......@@ -208,6 +210,7 @@ uint64_to_gvalue (guint64 i)
return val;
}
#if 0
static GValue *
byte_to_gvalue (guchar c)
{
......@@ -219,6 +222,7 @@ byte_to_gvalue (guchar c)
return val;
}
#endif
static GValue *
byte_array_to_gvalue (GByteArray *array)
......@@ -763,7 +767,6 @@ static void
setting_wireless_destroy (NMSetting *setting)
{
NMSettingWireless *self = (NMSettingWireless *) setting;
GSList *iter;
g_free (self->mode);
g_free (self->band);
......@@ -1380,7 +1383,6 @@ setting_vpn_properties_update_secrets (NMSetting *setting,
GHashTable *secrets)
{
NMSettingVPNProperties *self = (NMSettingVPNProperties *) setting;
SettingMember *m;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (secrets != NULL, FALSE);
......
......@@ -31,324 +31,73 @@
#include <dbus/dbus.h>
#include "nm-utils.h"
gchar *nm_dbus_escape_object_path (const gchar *utf8_string)
/* Shamelessly ripped from the Linux kernel ieee80211 stack */
gboolean
nm_utils_is_empty_ssid (const char * ssid, int len)
{
const gchar *p;
gchar *object_path;
GString *string;
g_return_val_if_fail (utf8_string != NULL, NULL);
g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL);
string = g_string_sized_new ((strlen (utf8_string) + 1) * 6);
for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p))
{
gunichar character;
character = g_utf8_get_char (p);
if (((character >= ((gunichar) 'a')) &&
(character <= ((gunichar) 'z'))) ||
((character >= ((gunichar) 'A')) &&
(character <= ((gunichar) 'Z'))) ||
((character >= ((gunichar) '0')) &&
(character <= ((gunichar) '9'))) ||
(character == ((gunichar) '/')))
{
g_string_append_c (string, (gchar) character);
continue;
}
g_string_append_printf (string, "_%x_", character);
}
object_path = string->str;
g_string_free (string, FALSE);
return object_path;
/* 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;
}
gchar *nm_dbus_unescape_object_path (const gchar *object_path)
const char *
nm_utils_escape_ssid (const guint8 * ssid, guint32 len)
{
const gchar *p;
gchar *utf8_string;
GString *string;
g_return_val_if_fail (object_path != NULL, NULL);
string = g_string_sized_new (strlen (object_path) + 1);
for (p = object_path; *p != '\0'; p++)
{
const gchar *q;
gchar *hex_digits, *end, utf8_character[6] = { '\0' };
gint utf8_character_size;
gunichar character;
gulong hex_value;
if (*p != '_')
{
g_string_append_c (string, *p);
continue;
}
q = strchr (p + 1, '_');
if ((q == NULL) || (q == p + 1))
{
g_string_free (string, TRUE);
return NULL;
}
hex_digits = g_strndup (p + 1, (q - 1) - p);
hex_value = strtoul (hex_digits, &end, 16);
static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
const guint8 *s = ssid;
char *d = escaped;
character = (gunichar) hex_value;
if (((hex_value == G_MAXLONG) && (errno == ERANGE)) ||
(hex_value > G_MAXUINT32) ||
(*end != '\0') ||
(!g_unichar_validate (character)))
{
g_free (hex_digits);
g_string_free (string, TRUE);
return NULL;
}
utf8_character_size =
g_unichar_to_utf8 (character, utf8_character);
g_assert (utf8_character_size > 0);
g_string_append_len (string, utf8_character,
utf8_character_size);
p = q;
if (nm_utils_is_empty_ssid ((const char *) ssid, len)) {
memcpy (escaped, "<hidden>", sizeof ("<hidden>"));
return escaped;
}
utf8_string = string->str;
g_string_free (string, FALSE);
return utf8_string;
}
struct EncodingTriplet
{
const char *encoding1;
const char *encoding2;
const char *encoding3;
};
struct IsoLangToEncodings
{
const char * lang;
struct EncodingTriplet encodings;
};
/* 5-letter language codes */
static const struct IsoLangToEncodings isoLangEntries5[] =
{
/* Simplified Chinese */
{ "zh_cn", {"euc-cn", "gb2312", "gb18030"} }, /* PRC */
{ "zh_sg", {"euc-cn", "gb2312", "gb18030"} }, /* Singapore */
/* Traditional Chinese */
{ "zh_tw", {"big5", "euc-tw", NULL} }, /* Taiwan */
{ "zh_hk", {"big5", "euc-tw", "big5-hkcs"} },/* Hong Kong */
{ "zh_mo", {"big5", "euc-tw", NULL} }, /* Macau */
/* Table end */
{ NULL, {NULL, NULL, NULL} }
};
/* 2-letter language codes; we don't care about the other 3 in this table */
static const struct IsoLangToEncodings isoLangEntries2[] =
{
/* Japanese */
{ "ja", {"euc-jp", "shift_jis", "iso-2022-jp"} },
/* Korean */
{ "ko", {"euc-kr", "iso-2022-kr", "johab"} },
/* Thai */
{ "th", {"iso-8859-11","windows-874", NULL} },
/* Central European */
{ "hu", {"iso-8859-2", "windows-1250", NULL} }, /* Hungarian */
{ "cs", {"iso-8859-2", "windows-1250", NULL} }, /* Czech */
{ "hr", {"iso-8859-2", "windows-1250", NULL} }, /* Croatian */
{ "pl", {"iso-8859-2", "windows-1250", NULL} }, /* Polish */
{ "ro", {"iso-8859-2", "windows-1250", NULL} }, /* Romanian */
{ "sk", {"iso-8859-2", "windows-1250", NULL} }, /* Slovakian */
{ "sl", {"iso-8859-2", "windows-1250", NULL} }, /* Slovenian */
{ "sh", {"iso-8859-2", "windows-1250", NULL} }, /* Serbo-Croatian */
/* Cyrillic */
{ "ru", {"koi8-r", "windows-1251", "iso-8859-5"} }, /* Russian */
{ "be", {"koi8-r", "windows-1251", "iso-8859-5"} }, /* Belorussian */
{ "bg", {"windows-1251","koi8-r", "iso-8859-5"} }, /* Bulgarian */
{ "mk", {"koi8-r", "windows-1251", "iso-8859-5"} }, /* Macedonian */
{ "sr", {"koi8-r", "windows-1251", "iso-8859-5"} }, /* Serbian */
{ "uk", {"koi8-u", "koi8-r", "windows-1251"} }, /* Ukranian */
/* Arabic */
{ "ar", {"iso-8859-6", "windows-1256", NULL} },
/* Balitc */
{ "et", {"iso-8859-4", "windows-1257", NULL} }, /* Estonian */
{ "lt", {"iso-8859-4", "windows-1257", NULL} }, /* Lithuanian */
{ "lv", {"iso-8859-4", "windows-1257", NULL} }, /* Latvian */
/* Greek */
{ "el", {"iso-8859-7", "windows-1253", NULL} },
/* Hebrew */
{ "he", {"iso-8859-8", "windows-1255", NULL} },
{ "iw", {"iso-8859-8", "windows-1255", NULL} },
/* Turkish */
{ "tr", {"iso-8859-9", "windows-1254", NULL} },
/* Table end */
{ NULL, {NULL, NULL, NULL} }
};
static GHashTable * langToEncodings5 = NULL;
static GHashTable * langToEncodings2 = NULL;
static void
init_lang_to_encodings_hash (void)
{
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
g_static_mutex_lock (&mutex);
if (G_UNLIKELY (!langToEncodings5 || !langToEncodings2))
{
const struct IsoLangToEncodings * enc = &isoLangEntries5[0];
/* Five-letter codes */
langToEncodings5 = g_hash_table_new (g_str_hash, g_str_equal);
while (enc->lang)
{
g_hash_table_insert (langToEncodings5, (gpointer) enc->lang,
(gpointer) &enc->encodings);
enc++;
}
/* Two-letter codes */
enc = &isoLangEntries2[0];
langToEncodings2 = g_hash_table_new (g_str_hash, g_str_equal);
while (enc->lang)
{
g_hash_table_insert (langToEncodings2, (gpointer) enc->lang,
(gpointer) &enc->encodings);
enc++;
len = MIN (len, (guint32) IW_ESSID_MAX_SIZE);
while (len--) {
if (*s == '\0') {
*d++ = '\\';
*d++ = '0';
s++;
} else {
*d++ = *s++;
}
}
g_static_mutex_unlock (&mutex);
}
static gboolean
get_encodings_for_lang (const char *lang,
char **encoding1,
char **encoding2,
char **encoding3)
{
struct EncodingTriplet * encodings;
gboolean success = FALSE;
char * tmp_lang;
g_return_val_if_fail (lang != NULL, FALSE);
g_return_val_if_fail (encoding1 != NULL, FALSE);
g_return_val_if_fail (encoding2 != NULL, FALSE);
g_return_val_if_fail (encoding3 != NULL, FALSE);
*encoding1 = "iso-8859-1";
*encoding2 = "windows-1251";
*encoding3 = NULL;
init_lang_to_encodings_hash ();
tmp_lang = g_strdup (lang);
if ((encodings = g_hash_table_lookup (langToEncodings5, tmp_lang)))
{
*encoding1 = (char *) encodings->encoding1;
*encoding2 = (char *) encodings->encoding2;
*encoding3 = (char *) encodings->encoding3;
success = TRUE;
}
/* Truncate tmp_lang to length of 2 */
if (strlen (tmp_lang) > 2)
tmp_lang[2] = '\0';
if (!success && (encodings = g_hash_table_lookup (langToEncodings2, tmp_lang)))
{
*encoding1 = (char *) encodings->encoding1;
*encoding2 = (char *) encodings->encoding2;
*encoding3 = (char *) encodings->encoding3;
success = TRUE;
}
g_free (tmp_lang);
return success;
*d = '\0';
return escaped;
}
char *
nm_utils_ssid_to_utf8 (const char *ssid, guint32 len)
gboolean
nm_utils_same_ssid (const GByteArray * ssid1,
const GByteArray * ssid2,
gboolean ignore_trailing_null)
{
char * new_ssid = NULL;
char buf[IW_ESSID_MAX_SIZE + 1];
guint32 buf_len = MIN (sizeof (buf) - 1, len);
char * lang;
char *e1 = NULL, *e2 = NULL, *e3 = NULL;
g_return_val_if_fail (ssid != NULL, NULL);
memset (buf, 0, sizeof (buf));
memcpy (buf, ssid, buf_len);
if (g_utf8_validate (buf, buf_len, NULL)) {
new_ssid = g_strdup (buf);
goto out;
}
/* Even if the local encoding is UTF-8, LANG may give
* us a clue as to what encoding SSIDs are more likely to be in.
*/
g_get_charset ((const char **)(&e1));
if ((lang = getenv ("LANG"))) {
char * dot;
lang = g_ascii_strdown (lang, -1);
if ((dot = strchr (lang, '.')))
*dot = '\0';
get_encodings_for_lang (lang, &e1, &e2, &e3);
g_free (lang);
guint32 ssid1_len, ssid2_len;
if (ssid1 == ssid2)
return TRUE;
if ((ssid1 && !ssid2) || (!ssid1 && ssid2))
return FALSE;
ssid1_len = ssid1->len;