supplicant: Add a new validation type for UTF-8 strings

This commit is contained in:
Evan Broder 2011-11-17 16:36:14 -08:00 committed by Dan Williams
parent 6346bd60be
commit ef9551bcf3
3 changed files with 27 additions and 0 deletions

View file

@ -293,6 +293,7 @@ get_hash_cb (gpointer key, gpointer value, gpointer user_data)
g_value_set_int (variant, atoi (opt->value));
break;
case TYPE_BYTES:
case TYPE_UTF8:
array = g_byte_array_sized_new (opt->len);
g_byte_array_append (array, (const guint8 *) opt->value, opt->len);
g_value_init (variant, DBUS_TYPE_G_UCHAR_ARRAY);

View file

@ -44,6 +44,10 @@ static gboolean validate_type_bytes (const struct Opt * opt,
const char * value,
const guint32 len);
static gboolean validate_type_utf8 (const struct Opt *opt,
const char * value,
const guint32 len);
static gboolean validate_type_keyword (const struct Opt * opt,
const char * value,
const guint32 len);
@ -58,6 +62,7 @@ struct validate_entry {
static const struct validate_entry validate_table[] = {
{ TYPE_INT, validate_type_int },
{ TYPE_BYTES, validate_type_bytes },
{ TYPE_UTF8, validate_type_utf8 },
{ TYPE_KEYWORD, validate_type_keyword },
};
@ -173,6 +178,26 @@ validate_type_bytes (const struct Opt * opt,
return TRUE;
}
static gboolean
validate_type_utf8 (const struct Opt *opt,
const char * value,
const guint32 len)
{
guint32 check_len;
g_return_val_if_fail (opt != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
check_len = opt->int_high ? opt->int_high : 255;
/* Note that we deliberately don't validate the UTF-8, because
some "UTF-8" fields, such as 8021x.password, do not actually
have to be valid UTF-8 */
if (g_utf8_strlen (value, len) > check_len)
return FALSE;
return TRUE;
}
static gboolean
validate_type_keyword (const struct Opt * opt,
const char * value,

View file

@ -25,6 +25,7 @@ typedef enum OptType {
TYPE_INVALID = 0,
TYPE_INT,
TYPE_BYTES,
TYPE_UTF8,
TYPE_KEYWORD,
TYPE_STRING
} OptType;