alljoyn: Use a FT_CHAR and value_string for the type id
The type id is a natural FT_CHAR, which is much easier than using a custom formatting function. This also avoids creating bogus UTF-8 Fix #18582.
This commit is contained in:
parent
3e0ee841b1
commit
df4a0f289c
|
@ -639,6 +639,28 @@ handle_message_header_expected_byte(tvbuff_t *tvb,
|
||||||
#define ARG_STRUCT '(' /* AllJoyn struct container type */
|
#define ARG_STRUCT '(' /* AllJoyn struct container type */
|
||||||
#define ARG_DICT_ENTRY '{' /* AllJoyn dictionary or map container type - an array of key-value pairs */
|
#define ARG_DICT_ENTRY '{' /* AllJoyn dictionary or map container type - an array of key-value pairs */
|
||||||
|
|
||||||
|
static const value_string header_type_vals[] = {
|
||||||
|
{ ARG_INVALID, "invalid" },
|
||||||
|
{ ARG_ARRAY, "array" },
|
||||||
|
{ ARG_BOOLEAN, "boolean" },
|
||||||
|
{ ARG_DOUBLE, "IEEE 754 double" },
|
||||||
|
{ ARG_SIGNATURE, "signature" },
|
||||||
|
{ ARG_HANDLE, "socket handle" },
|
||||||
|
{ ARG_INT32, "int32" },
|
||||||
|
{ ARG_INT16, "int16" },
|
||||||
|
{ ARG_OBJ_PATH, "object path" },
|
||||||
|
{ ARG_UINT16, "uint16" },
|
||||||
|
{ ARG_STRING, "string" },
|
||||||
|
{ ARG_UINT64, "uint64" },
|
||||||
|
{ ARG_UINT32, "uint32" },
|
||||||
|
{ ARG_VARIANT, "variant" },
|
||||||
|
{ ARG_INT64, "int64" },
|
||||||
|
{ ARG_BYTE, "byte" },
|
||||||
|
{ ARG_STRUCT, "structure" },
|
||||||
|
{ ARG_DICT_ENTRY, "dictionary" },
|
||||||
|
{ 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
pad_according_to_type(gint offset, gint field_starting_offset, gint max_offset, guint8 type)
|
pad_according_to_type(gint offset, gint field_starting_offset, gint max_offset, guint8 type)
|
||||||
{
|
{
|
||||||
|
@ -865,12 +887,10 @@ parse_arg(tvbuff_t *tvb,
|
||||||
gint length;
|
gint length;
|
||||||
gint padding_start;
|
gint padding_start;
|
||||||
gint saved_offset = offset;
|
gint saved_offset = offset;
|
||||||
const gchar *header_type_name = NULL;
|
|
||||||
|
|
||||||
switch(type_id)
|
switch(type_id)
|
||||||
{
|
{
|
||||||
case ARG_INVALID:
|
case ARG_INVALID:
|
||||||
header_type_name = "invalid";
|
|
||||||
offset = round_to_8byte(offset + 1, field_starting_offset);
|
offset = round_to_8byte(offset + 1, field_starting_offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -884,10 +904,8 @@ parse_arg(tvbuff_t *tvb,
|
||||||
gint number_of_items = 0;
|
gint number_of_items = 0;
|
||||||
gint packet_length = (gint)tvb_reported_length(tvb);
|
gint packet_length = (gint)tvb_reported_length(tvb);
|
||||||
|
|
||||||
header_type_name = "array";
|
|
||||||
|
|
||||||
if(*signature == NULL || *signature_length < 1) {
|
if(*signature == NULL || *signature_length < 1) {
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "BAD DATA: A %s argument needs a signature.", header_type_name);
|
col_add_fstr(pinfo->cinfo, COL_INFO, "BAD DATA: An array argument needs a signature.");
|
||||||
return tvb_reported_length(tvb);
|
return tvb_reported_length(tvb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -955,7 +973,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_BOOLEAN: /* AllJoyn boolean basic type */
|
case ARG_BOOLEAN: /* AllJoyn boolean basic type */
|
||||||
header_type_name = "boolean";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_4byte(offset, field_starting_offset);
|
offset = round_to_4byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -965,7 +982,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_DOUBLE: /* AllJoyn IEEE 754 double basic type */
|
case ARG_DOUBLE: /* AllJoyn IEEE 754 double basic type */
|
||||||
header_type_name = "IEEE 754 double";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_8byte(offset, field_starting_offset);
|
offset = round_to_8byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -975,7 +991,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_SIGNATURE: /* AllJoyn signature basic type */
|
case ARG_SIGNATURE: /* AllJoyn signature basic type */
|
||||||
header_type_name = "signature";
|
|
||||||
length = tvb_get_guint8(tvb, offset);
|
length = tvb_get_guint8(tvb, offset);
|
||||||
|
|
||||||
if (length + 2 > tvb_reported_length_remaining(tvb, offset)) {
|
if (length + 2 > tvb_reported_length_remaining(tvb, offset)) {
|
||||||
|
@ -1005,7 +1020,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_HANDLE: /* AllJoyn socket handle basic type. */
|
case ARG_HANDLE: /* AllJoyn socket handle basic type. */
|
||||||
header_type_name = "socket handle";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_4byte(offset, field_starting_offset);
|
offset = round_to_4byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1015,7 +1029,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_INT32: /* AllJoyn 32-bit signed integer basic type. */
|
case ARG_INT32: /* AllJoyn 32-bit signed integer basic type. */
|
||||||
header_type_name = "int32";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_4byte(offset, field_starting_offset);
|
offset = round_to_4byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1025,7 +1038,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_INT16: /* AllJoyn 16-bit signed integer basic type. */
|
case ARG_INT16: /* AllJoyn 16-bit signed integer basic type. */
|
||||||
header_type_name = "int16";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_2byte(offset, field_starting_offset);
|
offset = round_to_2byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1035,7 +1047,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_OBJ_PATH: /* AllJoyn Name of an AllJoyn object instance basic type */
|
case ARG_OBJ_PATH: /* AllJoyn Name of an AllJoyn object instance basic type */
|
||||||
header_type_name = "object path";
|
|
||||||
length = get_uint32(tvb, offset, encoding) + 1;
|
length = get_uint32(tvb, offset, encoding) + 1;
|
||||||
|
|
||||||
/* The + 4 is for the length specifier. Object paths may be of "any length"
|
/* The + 4 is for the length specifier. Object paths may be of "any length"
|
||||||
|
@ -1054,7 +1065,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_UINT16: /* AllJoyn 16-bit unsigned integer basic type */
|
case ARG_UINT16: /* AllJoyn 16-bit unsigned integer basic type */
|
||||||
header_type_name = "uint16";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_2byte(offset, field_starting_offset);
|
offset = round_to_2byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1067,7 +1077,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
{
|
{
|
||||||
const guint8 *member_name;
|
const guint8 *member_name;
|
||||||
|
|
||||||
header_type_name = "string";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_4byte(offset, field_starting_offset);
|
offset = round_to_4byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1097,7 +1106,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_UINT64: /* AllJoyn 64-bit unsigned integer basic type */
|
case ARG_UINT64: /* AllJoyn 64-bit unsigned integer basic type */
|
||||||
header_type_name = "uint64";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_8byte(offset, field_starting_offset);
|
offset = round_to_8byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1107,7 +1115,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_UINT32: /* AllJoyn 32-bit unsigned integer basic type */
|
case ARG_UINT32: /* AllJoyn 32-bit unsigned integer basic type */
|
||||||
header_type_name = "uint32";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_4byte(offset, field_starting_offset);
|
offset = round_to_4byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1140,8 +1147,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
const guint8 *sig_pointer;
|
const guint8 *sig_pointer;
|
||||||
guint8 variant_sig_length;
|
guint8 variant_sig_length;
|
||||||
|
|
||||||
header_type_name = "variant";
|
|
||||||
|
|
||||||
variant_sig_length = tvb_get_guint8(tvb, offset);
|
variant_sig_length = tvb_get_guint8(tvb, offset);
|
||||||
length = variant_sig_length;
|
length = variant_sig_length;
|
||||||
|
|
||||||
|
@ -1183,7 +1188,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_INT64: /* AllJoyn 64-bit signed integer basic type */
|
case ARG_INT64: /* AllJoyn 64-bit signed integer basic type */
|
||||||
header_type_name = "int64";
|
|
||||||
padding_start = offset;
|
padding_start = offset;
|
||||||
offset = round_to_8byte(offset, field_starting_offset);
|
offset = round_to_8byte(offset, field_starting_offset);
|
||||||
add_padding_item(padding_start, offset, tvb, field_tree);
|
add_padding_item(padding_start, offset, tvb, field_tree);
|
||||||
|
@ -1193,7 +1197,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_BYTE: /* AllJoyn 8-bit unsigned integer basic type */
|
case ARG_BYTE: /* AllJoyn 8-bit unsigned integer basic type */
|
||||||
header_type_name = "byte";
|
|
||||||
|
|
||||||
proto_tree_add_item(field_tree, hf_alljoyn_uint8, tvb, offset, 1, encoding);
|
proto_tree_add_item(field_tree, hf_alljoyn_uint8, tvb, offset, 1, encoding);
|
||||||
offset += 1;
|
offset += 1;
|
||||||
|
@ -1208,17 +1211,15 @@ parse_arg(tvbuff_t *tvb,
|
||||||
guint8 type_stop;
|
guint8 type_stop;
|
||||||
|
|
||||||
if(type_id == ARG_STRUCT) {
|
if(type_id == ARG_STRUCT) {
|
||||||
header_type_name = "structure";
|
|
||||||
hf = hf_alljoyn_mess_body_structure;
|
hf = hf_alljoyn_mess_body_structure;
|
||||||
type_stop = ')';
|
type_stop = ')';
|
||||||
} else {
|
} else {
|
||||||
header_type_name = "dictionary";
|
|
||||||
hf = hf_alljoyn_mess_body_dictionary_entry;
|
hf = hf_alljoyn_mess_body_dictionary_entry;
|
||||||
type_stop = '}';
|
type_stop = '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*signature == NULL || *signature_length < 1) {
|
if(*signature == NULL || *signature_length < 1) {
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "BAD DATA: A %s argument needs a signature.", header_type_name);
|
col_add_fstr(pinfo->cinfo, COL_INFO, "BAD DATA: A %s argument needs a signature.", val_to_str_const(type_id, header_type_vals, "Unexpected type"));
|
||||||
return tvb_reported_length(tvb);
|
return tvb_reported_length(tvb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1256,7 +1257,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
header_type_name = "unexpected";
|
|
||||||
/* Just say we are done with this packet. */
|
/* Just say we are done with this packet. */
|
||||||
offset = tvb_reported_length(tvb);
|
offset = tvb_reported_length(tvb);
|
||||||
break;
|
break;
|
||||||
|
@ -1267,12 +1267,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
(*signature_length)--;
|
(*signature_length)--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL != header_item && NULL != header_type_name) {
|
|
||||||
/* Using "%s" and the argument "header_type_name" because some compilers don't like
|
|
||||||
"header_type_name" by itself. */
|
|
||||||
proto_item_append_text(header_item, "%s", header_type_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure we never return something longer than the buffer for an offset. */
|
/* Make sure we never return something longer than the buffer for an offset. */
|
||||||
if(offset > (gint)tvb_reported_length(tvb)) {
|
if(offset > (gint)tvb_reported_length(tvb)) {
|
||||||
offset = (gint)tvb_reported_length(tvb);
|
offset = (gint)tvb_reported_length(tvb);
|
||||||
|
@ -1286,12 +1280,6 @@ parse_arg(tvbuff_t *tvb,
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
alljoyn_typeid( gchar *result, guint32 type )
|
|
||||||
{
|
|
||||||
snprintf( result, ITEM_LABEL_LENGTH, "'%c' => ", type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is called by handle_message_header_fields() to handle a single
|
/* This is called by handle_message_header_fields() to handle a single
|
||||||
* message header field.
|
* message header field.
|
||||||
* @param tvb is the incoming network data buffer.
|
* @param tvb is the incoming network data buffer.
|
||||||
|
@ -2757,7 +2745,7 @@ proto_register_AllJoyn(void)
|
||||||
},
|
},
|
||||||
{&hf_alljoyn_mess_body_header_typeid,
|
{&hf_alljoyn_mess_body_header_typeid,
|
||||||
{"Type ID", "alljoyn.message.typeid",
|
{"Type ID", "alljoyn.message.typeid",
|
||||||
FT_UINT8, BASE_CUSTOM, CF_FUNC(alljoyn_typeid), 0,
|
FT_CHAR, BASE_HEX, VALS(header_type_vals), 0,
|
||||||
NULL, HFILL}
|
NULL, HFILL}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue