diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-03-03 17:35:14 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-03-10 19:14:55 +0000 |
commit | 09c9d6406b75f161429e16b2e45dcae3eb60cef9 (patch) | |
tree | 56d0f71974bdf50c14a0e97f0a44879d85e27d7d /dbus/dbus-signature.c | |
parent | 8299a41aa6808f020907b17bf3a66d9f360305be (diff) | |
download | dbus-09c9d6406b75f161429e16b2e45dcae3eb60cef9.tar.gz |
Make dbus_type_is_valid into public API
This is just as useful for bindings as dbus_signature_validate, and I
think it's a good design principle to say that anything checked in a
_dbus_return_if_fail should be something the caller could check
for themselves.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=20496
Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
Diffstat (limited to 'dbus/dbus-signature.c')
-rw-r--r-- | dbus/dbus-signature.c | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/dbus/dbus-signature.c b/dbus/dbus-signature.c index 9c13ff43..c130de5b 100644 --- a/dbus/dbus-signature.c +++ b/dbus/dbus-signature.c @@ -284,7 +284,8 @@ dbus_signature_validate_single (const char *signature, * container types. #DBUS_TYPE_INVALID is not a container type. * * It is an error to pass an invalid type-code, other than DBUS_TYPE_INVALID, - * to this function. The valid type-codes are defined by dbus-protocol.h. + * to this function. The valid type-codes are defined by dbus-protocol.h + * and can be checked with dbus_type_is_valid(). * * @param typecode either a valid type-code or DBUS_TYPE_INVALID * @returns #TRUE if type is a container @@ -293,7 +294,7 @@ dbus_bool_t dbus_type_is_container (int typecode) { /* only reasonable (non-line-noise) typecodes are allowed */ - _dbus_return_val_if_fail (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID, + _dbus_return_val_if_fail (dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID, FALSE); return TYPE_IS_CONTAINER (typecode); } @@ -307,7 +308,8 @@ dbus_type_is_container (int typecode) * type. * * It is an error to pass an invalid type-code, other than DBUS_TYPE_INVALID, - * to this function. The valid type-codes are defined by dbus-protocol.h. + * to this function. The valid type-codes are defined by dbus-protocol.h + * and can be checked with dbus_type_is_valid(). * * @param typecode either a valid type-code or DBUS_TYPE_INVALID * @returns #TRUE if type is basic @@ -316,7 +318,7 @@ dbus_bool_t dbus_type_is_basic (int typecode) { /* only reasonable (non-line-noise) typecodes are allowed */ - _dbus_return_val_if_fail (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID, + _dbus_return_val_if_fail (dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID, FALSE); /* everything that isn't invalid or a container */ @@ -337,7 +339,8 @@ dbus_type_is_basic (int typecode) * function. * * It is an error to pass an invalid type-code, other than DBUS_TYPE_INVALID, - * to this function. The valid type-codes are defined by dbus-protocol.h. + * to this function. The valid type-codes are defined by dbus-protocol.h + * and can be checked with dbus_type_is_valid(). * * @param typecode either a valid type-code or DBUS_TYPE_INVALID * @returns #FALSE if the type can occupy different lengths @@ -346,7 +349,7 @@ dbus_bool_t dbus_type_is_fixed (int typecode) { /* only reasonable (non-line-noise) typecodes are allowed */ - _dbus_return_val_if_fail (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID, + _dbus_return_val_if_fail (dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID, FALSE); switch (typecode) @@ -367,6 +370,44 @@ dbus_type_is_fixed (int typecode) } } +/** + * Return #TRUE if the argument is a valid typecode. + * #DBUS_TYPE_INVALID surprisingly enough is not considered valid, and + * random unknown bytes aren't either. This function is safe with + * untrusted data. + * + * @param typecode a potential type-code + * @returns #TRUE if valid + */ +dbus_bool_t +dbus_type_is_valid (int typecode) +{ + switch (typecode) + { + case DBUS_TYPE_BYTE: + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_INT16: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_INT32: + case DBUS_TYPE_UINT32: + case DBUS_TYPE_INT64: + case DBUS_TYPE_UINT64: + case DBUS_TYPE_DOUBLE: + case DBUS_TYPE_STRING: + case DBUS_TYPE_OBJECT_PATH: + case DBUS_TYPE_SIGNATURE: + case DBUS_TYPE_ARRAY: + case DBUS_TYPE_STRUCT: + case DBUS_TYPE_DICT_ENTRY: + case DBUS_TYPE_VARIANT: + case DBUS_TYPE_UNIX_FD: + return TRUE; + + default: + return FALSE; + } +} + /** @} */ /* end of DBusSignature group */ #ifdef DBUS_BUILD_TESTS |