diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-04-12 15:26:34 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-04-12 22:27:22 +0000 |
commit | cb16dff992c3844936bf5829f19e5a5247458503 (patch) | |
tree | 901b7be3379f5b94f150de71d1c0f3e2fa2d12e4 /epan/tvbuff.h | |
parent | ef8a0a2ce172810d48371eb65c73b1bd4a6303ca (diff) |
Get rid of more tvb_get_nstringz* calls.
Add an FT_STRINGZPAD type, for null-padded strings (typically
fixed-length fields, where the string can be up to the length of the
field, and is null-padded if it's shorter than that), and use it. Use
IS_FT_STRING() in more cases, so that less code needs to know what types
are string types.
Add a tvb_get_stringzpad() routine, which gets null-padded strings.
Currently, it does the same thing that tvb_get_string_enc() does, but
that might change if we don't store string values as null-terminated
strings.
Change-Id: I46f56e130de8f419a19b56ded914e24cc7518a66
Reviewed-on: https://code.wireshark.org/review/1082
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/tvbuff.h')
-rw-r--r-- | epan/tvbuff.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 7d51a6ac0c..896a13587f 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -557,6 +557,29 @@ WS_DLL_PUBLIC gchar *tvb_get_ts_23_038_7bits_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint bit_offset, gint no_of_chars); /** + * Given an allocator scope, a tvbuff, a byte offset, a byte length, and + * a string encoding, with the specified offset and length referring to + * a null-padded string in the specified encoding: + * + * allocate a buffer using the specified scope; + * + * convert the string from the specified encoding to UTF-8, possibly + * mapping some characters or invalid octet sequences to the Unicode + * REPLACEMENT CHARACTER, and put the resulting UTF-8 string, plus a + * trailing '\0', into that buffer; + * + * and return a pointer to the buffer. + * + * Throws an exception if the tvbuff ends before the string does. + * + * If scope is set to NULL it is the user's responsibility to wmem_free() + * the memory allocated. Otherwise memory is automatically freed when the + * scope lifetime is reached. + */ +WS_DLL_PUBLIC guint8 *tvb_get_stringzpad(wmem_allocator_t *scope, + tvbuff_t *tvb, const gint offset, const gint length, const guint encoding); + +/** * Given an allocator scope, a tvbuff, a byte offset, a pointer to a * gint, and a string encoding, with the specified offset referring to * a null-terminated string in the specified encoding: |