diff options
author | Havoc Pennington <hp@redhat.com> | 2005-01-17 03:53:40 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2005-01-17 03:53:40 +0000 |
commit | 7bf62e31a3c820852271768fafc04ba95c31a19f (patch) | |
tree | 660d6e210d04143773da2e86d3b3e8dae8be5cc0 /dbus/dbus-message-builder.c | |
parent | 4c1a2a760b67b4600db3e5b9c2ad0056b5cf32b6 (diff) |
2005-01-16 Havoc Pennington <hp@redhat.com>
This is about it on what can be disabled/deleted from libdbus
easily, back below 150K anyhow. Deeper cuts are more work than
just turning the code off as I've done here.
* dbus/dbus-marshal-basic.c (_dbus_pack_int32): we don't need the
signed int convenience funcs
* dbus/dbus-internals.c (_dbus_verbose_real): omit when not in
verbose mode
* dbus/dbus-string-util.c, dbus/dbus-string.c: more breaking
things out of libdbus
* dbus/dbus-sysdeps.c, dbus/dbus-sysdeps-util.c: same
* dbus/dbus-hash.c: purge the TWO_STRINGS crap (well, make it
tests-enabled-only, though it should probably be deleted)
* dbus/dbus-message-util.c: same stuff
* dbus/dbus-auth-util.c: same stuff
Diffstat (limited to 'dbus/dbus-message-builder.c')
-rw-r--r-- | dbus/dbus-message-builder.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/dbus/dbus-message-builder.c b/dbus/dbus-message-builder.c index b5b7564e..58718f6d 100644 --- a/dbus/dbus-message-builder.c +++ b/dbus/dbus-message-builder.c @@ -335,6 +335,115 @@ append_string_field (DBusString *dest, return TRUE; } +#ifdef DBUS_BUILD_TESTS +/** + * Parses a basic type defined by type contained in a DBusString. The + * end_return parameter may be #NULL if you aren't interested in it. The + * type is parsed and stored in value_return. Return parameters are not + * initialized if the function returns #FALSE. + * + * @param str the string + * @param type the type of the basic type + * @param start the byte index of the start of the type + * @param value_return return location of the value or #NULL + * @param end_return return location of the end of the type, or #NULL + * @returns #TRUE on success + */ +static dbus_bool_t +_dbus_string_parse_basic_type (const DBusString *str, + char type, + int start, + void *value, + int *end_return) +{ + int end = start; + + switch (type) + { + case DBUS_TYPE_BOOLEAN: + { + int len = _dbus_string_get_length (str) - start; + if (len >= 5 && _dbus_string_find_to (str, start, start + 5, "false", NULL)) + { + end += 5; + *(unsigned char *) value = TRUE; + } + else if (len >= 4 && _dbus_string_find_to (str, start, start + 4, "true", NULL)) + { + end += 4; + *(unsigned char *) value = FALSE; + } + else + _dbus_warn ("could not parse BOOLEAN\n"); + break; + } + case DBUS_TYPE_BYTE: + { + long val = 0; + + if (_dbus_string_get_byte (str, start) == '\'' && + _dbus_string_get_length (str) >= start + 4 && + _dbus_string_get_byte (str, start + 1) == '\\' && + _dbus_string_get_byte (str, start + 2) == '\'' && + _dbus_string_get_byte (str, start + 3) == '\'') + { + val = '\''; + end += 4; + } + else if (_dbus_string_get_byte (str, start) == '\'' && + _dbus_string_get_length (str) >= start + 3 && + _dbus_string_get_byte (str, start + 2) == '\'') + { + val = _dbus_string_get_byte (str, start + 1); + end += 3; + } + else + { + if (!_dbus_string_parse_int (str, start, &val, &end)) + _dbus_warn ("Failed to parse integer for BYTE\n"); + } + + if (val > 255) + _dbus_warn ("A byte must be in range 0-255 not %ld\n", val); + + *(unsigned char *) value = val; + break; + } + case DBUS_TYPE_INT32: + { + long val; + if (_dbus_string_parse_int (str, start, &val, &end)) + *(dbus_int32_t *)value = val; + break; + } + case DBUS_TYPE_UINT32: + { + unsigned long val; + if (_dbus_string_parse_uint (str, start, &val, &end)) + *(dbus_uint32_t *)value = val; + break; + } +#ifdef DBUS_HAVE_INT64 + case DBUS_TYPE_INT64: + case DBUS_TYPE_UINT64: + /* use stroll oull */ + _dbus_assert_not_reached ("string -> [u]int64 not supported yet"); + break; +#endif /* DBUS_HAVE_INT64 */ + case DBUS_TYPE_DOUBLE: + _dbus_string_parse_double (str, start, value, &end); + break; + default: + _dbus_assert_not_reached ("not a basic type"); + break; + } + if (end_return) + *end_return = end; + + return end != start; +} +#endif /* DBUS_BUILD_TESTS */ + static dbus_bool_t parse_basic_type (DBusString *src, char type, DBusString *dest, dbus_bool_t *unalign, |