Qt+epan: Print better-looking values in the packet diagram.

Pull the value-formatting code in proto_custom_set into
proto_item_fill_display_label. Use that in FieldInformation::toString
instead of fvalue_to_string_repr. Fixes #16911.
This commit is contained in:
Gerald Combs 2020-10-15 18:10:33 -07:00 committed by Wireshark GitLab Utility
parent 440d8ceff9
commit 3a7966c716
4 changed files with 333 additions and 231 deletions

View File

@ -1153,6 +1153,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
proto_item_add_subtree@Base 1.9.1
proto_item_append_text@Base 1.9.1
proto_item_fill_label@Base 1.9.1
proto_item_fill_display_label@Base 3.5.0
proto_item_get_display_repr@Base 3.3.0
proto_item_get_len@Base 1.9.1
proto_item_get_parent@Base 1.9.1

View File

@ -6330,6 +6330,293 @@ hfinfo_remove_from_gpa_name_map(const header_field_info *hfinfo)
}
}
int
proto_item_fill_display_label(field_info *finfo, gchar *display_label_str, const int label_str_size)
{
header_field_info *hfinfo = finfo->hfinfo;
int label_len = 0;
char *tmp_str;
guint8 *bytes;
guint32 number;
guint64 number64;
const true_false_string *tfstring;
const char *hf_str_val;
char number_buf[48];
const char *number_out;
address addr;
ws_in4_addr ipv4;
ws_in6_addr *ipv6;
switch (hfinfo->type) {
case FT_NONE:
case FT_PROTOCOL:
/* prevent multiple check marks by setting result directly */
return protoo_strlcpy(display_label_str, UTF8_CHECK_MARK, label_str_size);
break;
case FT_UINT_BYTES:
case FT_BYTES:
tmp_str = hfinfo_format_bytes(NULL,
hfinfo,
(guint8 *)fvalue_get(&finfo->value),
fvalue_length(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_ABSOLUTE_TIME:
tmp_str = abs_time_to_str(NULL, (const nstime_t *)fvalue_get(&finfo->value), (absolute_time_display_e)hfinfo->display, TRUE);
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_RELATIVE_TIME:
tmp_str = rel_time_to_secs_str(NULL, (const nstime_t *)fvalue_get(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_BOOLEAN:
number64 = fvalue_get_uinteger64(&finfo->value);
tfstring = &tfs_true_false;
if (hfinfo->strings) {
tfstring = (const struct true_false_string*) hfinfo->strings;
}
label_len = protoo_strlcpy(display_label_str,
tfs_get_string(!!number64, tfstring), label_str_size);
break;
case FT_CHAR:
number = fvalue_get_uinteger(&finfo->value);
if (FIELD_DISPLAY(hfinfo->display) == BASE_CUSTOM) {
gchar tmp[ITEM_LABEL_LENGTH];
custom_fmt_func_t fmtfunc = (custom_fmt_func_t)hfinfo->strings;
DISSECTOR_ASSERT(fmtfunc);
fmtfunc(tmp, number);
label_len = protoo_strlcpy(display_label_str, tmp, label_str_size);
} else if (hfinfo->strings) {
number_out = hf_try_val_to_str(number, hfinfo);
if (!number_out) {
number_out = hfinfo_char_value_format_display(BASE_HEX, number_buf, number);
}
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
} else {
number_out = hfinfo_char_value_format(hfinfo, number_buf, number);
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
}
break;
/* XXX - make these just FT_NUMBER? */
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
case FT_FRAMENUM:
hf_str_val = NULL;
number = IS_FT_INT(hfinfo->type) ?
(guint32) fvalue_get_sinteger(&finfo->value) :
fvalue_get_uinteger(&finfo->value);
if (FIELD_DISPLAY(hfinfo->display) == BASE_CUSTOM) {
gchar tmp[ITEM_LABEL_LENGTH];
custom_fmt_func_t fmtfunc = (custom_fmt_func_t)hfinfo->strings;
DISSECTOR_ASSERT(fmtfunc);
fmtfunc(tmp, number);
label_len = protoo_strlcpy(display_label_str, tmp, label_str_size);
} else if (hfinfo->strings && hfinfo->type != FT_FRAMENUM) {
if (hfinfo->display & BASE_UNIT_STRING) {
number_out = hfinfo_numeric_value_format(hfinfo, number_buf, number);
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
hf_str_val = hf_try_val_to_str(number, hfinfo);
label_len += protoo_strlcpy(display_label_str+label_len, hf_str_val, label_str_size-label_len);
} else {
number_out = hf_str_val = hf_try_val_to_str(number, hfinfo);
if (!number_out) {
number_out = hfinfo_number_value_format_display(hfinfo, hfinfo->display, number_buf, number);
}
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
}
} else {
number_out = hfinfo_number_value_format(hfinfo, number_buf, number);
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
}
break;
case FT_INT40:
case FT_INT48:
case FT_INT56:
case FT_INT64:
case FT_UINT40:
case FT_UINT48:
case FT_UINT56:
case FT_UINT64:
hf_str_val = NULL;
number64 = IS_FT_INT(hfinfo->type) ?
(guint64) fvalue_get_sinteger64(&finfo->value) :
fvalue_get_uinteger64(&finfo->value);
if (FIELD_DISPLAY(hfinfo->display) == BASE_CUSTOM) {
gchar tmp[ITEM_LABEL_LENGTH];
custom_fmt_func_64_t fmtfunc64 = (custom_fmt_func_64_t)hfinfo->strings;
DISSECTOR_ASSERT(fmtfunc64);
fmtfunc64(tmp, number64);
label_len = protoo_strlcpy(display_label_str, tmp, label_str_size);
} else if (hfinfo->strings) {
if (hfinfo->display & BASE_UNIT_STRING) {
number_out = hfinfo_numeric_value_format64(hfinfo, number_buf, number64);
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
hf_str_val = hf_try_val64_to_str(number64, hfinfo);
label_len += protoo_strlcpy(display_label_str+label_len, hf_str_val, label_str_size-label_len);
} else {
number_out = hf_str_val = hf_try_val64_to_str(number64, hfinfo);
if (!number_out)
number_out = hfinfo_number_value_format_display64(hfinfo, hfinfo->display, number_buf, number64);
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
}
} else {
number_out = hfinfo_number_value_format64(hfinfo, number_buf, number64);
label_len = protoo_strlcpy(display_label_str, number_out, label_str_size);
}
break;
case FT_EUI64:
tmp_str = eui64_to_str(NULL, fvalue_get_uinteger64(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_IPv4:
ipv4 = fvalue_get_uinteger(&finfo->value);
set_address (&addr, AT_IPv4, 4, &ipv4);
address_to_str_buf(&addr, display_label_str, label_str_size);
label_len = (int)strlen(display_label_str);
break;
case FT_IPv6:
ipv6 = (ws_in6_addr *)fvalue_get(&finfo->value);
set_address (&addr, AT_IPv6, sizeof(ws_in6_addr), ipv6);
address_to_str_buf(&addr, display_label_str, label_str_size);
label_len = (int)strlen(display_label_str);
break;
case FT_FCWWN:
set_address (&addr, AT_FCWWN, FCWWN_ADDR_LEN, fvalue_get(&finfo->value));
address_to_str_buf(&addr, display_label_str, label_str_size);
label_len = (int)strlen(display_label_str);
break;
case FT_ETHER:
set_address (&addr, AT_ETHER, FT_ETHER_LEN, fvalue_get(&finfo->value));
address_to_str_buf(&addr, display_label_str, label_str_size);
label_len = (int)strlen(display_label_str);
break;
case FT_GUID:
tmp_str = guid_to_str(NULL, (e_guid_t *)fvalue_get(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_REL_OID:
bytes = (guint8 *)fvalue_get(&finfo->value);
tmp_str = rel_oid_resolved_from_encoded(NULL, bytes, fvalue_length(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_OID:
bytes = (guint8 *)fvalue_get(&finfo->value);
tmp_str = oid_resolved_from_encoded(NULL, bytes, fvalue_length(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_SYSTEM_ID:
bytes = (guint8 *)fvalue_get(&finfo->value);
tmp_str = print_system_id(NULL, bytes, fvalue_length(&finfo->value));
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
case FT_FLOAT:
if (hfinfo->display & BASE_UNIT_STRING) {
double d_value = fvalue_get_floating(&finfo->value);
g_snprintf(display_label_str, label_str_size,
"%." G_STRINGIFY(FLT_DIG) "g%s", d_value,
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
} else {
g_snprintf(display_label_str, label_str_size,
"%." G_STRINGIFY(FLT_DIG) "g", fvalue_get_floating(&finfo->value));
}
label_len = (int)strlen(display_label_str);
break;
case FT_DOUBLE:
if (hfinfo->display & BASE_UNIT_STRING) {
double d_value = fvalue_get_floating(&finfo->value);
g_snprintf(display_label_str, label_str_size,
"%." G_STRINGIFY(DBL_DIG) "g%s", d_value,
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
} else {
g_snprintf(display_label_str, label_str_size,
"%." G_STRINGIFY(DBL_DIG) "g", fvalue_get_floating(&finfo->value));
}
label_len = (int)strlen(display_label_str);
break;
case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
case FT_STRINGZPAD:
case FT_STRINGZTRUNC:
bytes = (guint8 *)fvalue_get(&finfo->value);
tmp_str = hfinfo_format_text(NULL, hfinfo, bytes);
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
default:
/* First try ftype string representation */
tmp_str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, hfinfo->display);
if (!tmp_str) {
/* Default to show as bytes */
bytes = (guint8 *)fvalue_get(&finfo->value);
tmp_str = bytes_to_str(NULL, bytes, fvalue_length(&finfo->value));
}
label_len = protoo_strlcpy(display_label_str, tmp_str, label_str_size);
wmem_free(NULL, tmp_str);
break;
}
return label_len;
}
/* -------------------------- */
const gchar *
proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
@ -6338,13 +6625,8 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
guint32 number;
guint64 number64;
guint8 *bytes;
ws_in4_addr ipv4;
ws_in6_addr *ipv6;
address addr;
const true_false_string *tfstring;
int len, prev_len, last, i, offset_r = 0, offset_e = 0;
int len, prev_len, last, i, offset_r = 0, offset_e = 0, label_len;
GPtrArray *finfos;
field_info *finfo = NULL;
header_field_info* hfinfo;
@ -6353,7 +6635,7 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
const char *hf_str_val;
char number_buf[48];
const char *number_out;
char *tmpbuf, *str;
char *str;
int *field_idx;
int field_id;
int ii = 0;
@ -6424,79 +6706,21 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
switch (hfinfo->type) {
case FT_NONE:
case FT_PROTOCOL:
/* prevent multiple check marks by setting result directly */
g_strlcpy(result, UTF8_CHECK_MARK, size);
break;
case FT_UINT_BYTES:
case FT_BYTES:
tmpbuf = hfinfo_format_bytes(NULL,
hfinfo,
(guint8 *)fvalue_get(&finfo->value),
fvalue_length(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, tmpbuf, size-offset_r);
wmem_free(NULL, tmpbuf);
break;
case FT_ABSOLUTE_TIME:
tmpbuf = abs_time_to_str(NULL, (const nstime_t *)fvalue_get(&finfo->value), (absolute_time_display_e)hfinfo->display, TRUE);
offset_r += protoo_strlcpy(result+offset_r,
tmpbuf,
size-offset_r);
wmem_free(NULL, tmpbuf);
break;
case FT_RELATIVE_TIME:
tmpbuf = rel_time_to_secs_str(NULL, (const nstime_t *)fvalue_get(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r,
tmpbuf,
size-offset_r);
wmem_free(NULL, tmpbuf);
break;
case FT_BOOLEAN:
number64 = fvalue_get_uinteger64(&finfo->value);
tfstring = &tfs_true_false;
if (hfinfo->strings) {
tfstring = (const struct true_false_string*) hfinfo->strings;
}
offset_r += protoo_strlcpy(result+offset_r,
tfs_get_string(!!number64, tfstring), size-offset_r);
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
number64 = fvalue_get_uinteger64(&finfo->value);
offset_e += protoo_strlcpy(expr+offset_e,
number64 ? "1" : "0", size-offset_e);
break;
case FT_CHAR:
hf_str_val = NULL;
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
number = fvalue_get_uinteger(&finfo->value);
if (FIELD_DISPLAY(hfinfo->display) == BASE_CUSTOM) {
gchar tmp[ITEM_LABEL_LENGTH];
custom_fmt_func_t fmtfunc = (custom_fmt_func_t)hfinfo->strings;
DISSECTOR_ASSERT(fmtfunc);
fmtfunc(tmp, number);
offset_r += protoo_strlcpy(result+offset_r, tmp, size-offset_r);
} else if (hfinfo->strings) {
number_out = hf_str_val = hf_try_val_to_str(number, hfinfo);
if (!number_out)
number_out = hfinfo_char_value_format_display(BASE_HEX, number_buf, number);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
} else {
number_out = hfinfo_char_value_format(hfinfo, number_buf, number);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
}
if (hf_str_val && FIELD_DISPLAY(hfinfo->display) == BASE_NONE) {
if (hfinfo->strings && FIELD_DISPLAY(hfinfo->display) == BASE_NONE) {
hf_str_val = hf_try_val_to_str(number, hfinfo);
g_snprintf(expr+offset_e, size-offset_e, "\"%s\"", hf_str_val);
} else {
number_out = hfinfo_char_value_format(hfinfo, number_buf, number);
@ -6517,41 +6741,20 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
case FT_UINT24:
case FT_UINT32:
case FT_FRAMENUM:
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
hf_str_val = NULL;
number = IS_FT_INT(hfinfo->type) ?
(guint32) fvalue_get_sinteger(&finfo->value) :
fvalue_get_uinteger(&finfo->value);
if (FIELD_DISPLAY(hfinfo->display) == BASE_CUSTOM) {
gchar tmp[ITEM_LABEL_LENGTH];
custom_fmt_func_t fmtfunc = (custom_fmt_func_t)hfinfo->strings;
DISSECTOR_ASSERT(fmtfunc);
fmtfunc(tmp, number);
offset_r += protoo_strlcpy(result+offset_r, tmp, size-offset_r);
} else if (hfinfo->strings && hfinfo->type != FT_FRAMENUM) {
if (hfinfo->display & BASE_UNIT_STRING) {
number_out = hfinfo_numeric_value_format(hfinfo, number_buf, number);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
hf_str_val = hf_try_val_to_str(number, hfinfo);
offset_r += protoo_strlcpy(result+offset_r, hf_str_val, size-offset_r);
} else {
number_out = hf_str_val = hf_try_val_to_str(number, hfinfo);
if (!number_out)
number_out = hfinfo_number_value_format_display(hfinfo, hfinfo->display, number_buf, number);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
}
} else {
number_out = hfinfo_number_value_format(hfinfo, number_buf, number);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
if (hfinfo->strings && hfinfo->type != FT_FRAMENUM) {
hf_str_val = hf_try_val_to_str(number, hfinfo);
}
if (hf_str_val && FIELD_DISPLAY(hfinfo->display) == BASE_NONE) {
hf_str_val = hf_try_val_to_str(number, hfinfo);
g_snprintf(expr+offset_e, size-offset_e, "\"%s\"", hf_str_val);
} else {
number_out = hfinfo_numeric_value_format(hfinfo, number_buf, number);
@ -6570,36 +6773,15 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
case FT_UINT48:
case FT_UINT56:
case FT_UINT64:
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
hf_str_val = NULL;
number64 = IS_FT_INT(hfinfo->type) ?
(guint64) fvalue_get_sinteger64(&finfo->value) :
fvalue_get_uinteger64(&finfo->value);
if (FIELD_DISPLAY(hfinfo->display) == BASE_CUSTOM) {
gchar tmp[ITEM_LABEL_LENGTH];
custom_fmt_func_64_t fmtfunc64 = (custom_fmt_func_64_t)hfinfo->strings;
DISSECTOR_ASSERT(fmtfunc64);
fmtfunc64(tmp, number64);
offset_r += protoo_strlcpy(result+offset_r, tmp, size-offset_r);
} else if (hfinfo->strings) {
if (hfinfo->display & BASE_UNIT_STRING) {
number_out = hfinfo_numeric_value_format64(hfinfo, number_buf, number64);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
hf_str_val = hf_try_val64_to_str(number64, hfinfo);
offset_r += protoo_strlcpy(result+offset_r, hf_str_val, size-offset_r);
} else {
number_out = hf_str_val = hf_try_val64_to_str(number64, hfinfo);
if (!number_out)
number_out = hfinfo_number_value_format_display64(hfinfo, hfinfo->display, number_buf, number64);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
}
} else {
number_out = hfinfo_number_value_format64(hfinfo, number_buf, number64);
offset_r += protoo_strlcpy(result+offset_r, number_out, size-offset_r);
if (hfinfo->strings && hfinfo->type != FT_FRAMENUM) {
hf_str_val = hf_try_val64_to_str(number64, hfinfo);
}
if (hf_str_val && FIELD_DISPLAY(hfinfo->display) == BASE_NONE) {
@ -6613,122 +6795,34 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
offset_e = (int)strlen(expr);
break;
case FT_EUI64:
str = eui64_to_str(NULL, fvalue_get_uinteger64(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
break;
case FT_IPv4:
ipv4 = fvalue_get_uinteger(&finfo->value);
set_address (&addr, AT_IPv4, 4, &ipv4);
address_to_str_buf(&addr, result+offset_r, size-offset_r);
offset_r = (int)strlen(result);
break;
case FT_IPv6:
ipv6 = (ws_in6_addr *)fvalue_get(&finfo->value);
set_address (&addr, AT_IPv6, sizeof(ws_in6_addr), ipv6);
address_to_str_buf(&addr, result+offset_r, size-offset_r);
offset_r = (int)strlen(result);
break;
case FT_FCWWN:
set_address (&addr, AT_FCWWN, FCWWN_ADDR_LEN, fvalue_get(&finfo->value));
address_to_str_buf(&addr, result+offset_r, size-offset_r);
offset_r = (int)strlen(result);
break;
case FT_ETHER:
set_address (&addr, AT_ETHER, FT_ETHER_LEN, fvalue_get(&finfo->value));
address_to_str_buf(&addr, result+offset_r, size-offset_r);
offset_r = (int)strlen(result);
break;
case FT_GUID:
str = guid_to_str(NULL, (e_guid_t *)fvalue_get(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
break;
case FT_REL_OID:
bytes = (guint8 *)fvalue_get(&finfo->value);
str = rel_oid_resolved_from_encoded(NULL, bytes, fvalue_length(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
bytes = (guint8 *)fvalue_get(&finfo->value);
str = rel_oid_encoded2string(NULL, bytes, fvalue_length(&finfo->value));
offset_e += protoo_strlcpy(expr+offset_e, str, size-offset_e);
wmem_free(NULL, str);
break;
case FT_OID:
bytes = (guint8 *)fvalue_get(&finfo->value);
str = oid_resolved_from_encoded(NULL, bytes, fvalue_length(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
bytes = (guint8 *)fvalue_get(&finfo->value);
str = oid_encoded2string(NULL, bytes, fvalue_length(&finfo->value));
offset_e += protoo_strlcpy(expr+offset_e, str, size-offset_e);
wmem_free(NULL, str);
break;
case FT_SYSTEM_ID:
bytes = (guint8 *)fvalue_get(&finfo->value);
str = print_system_id(NULL, bytes, fvalue_length(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
offset_e += protoo_strlcpy(expr+offset_e, str, size-offset_e);
wmem_free(NULL, str);
break;
label_len = proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
case FT_FLOAT:
if (hfinfo->display & BASE_UNIT_STRING) {
double d_value = fvalue_get_floating(&finfo->value);
g_snprintf(result+offset_r, size-offset_r,
"%." G_STRINGIFY(FLT_DIG) "g%s", d_value,
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
} else {
g_snprintf(result+offset_r, size-offset_r,
"%." G_STRINGIFY(FLT_DIG) "g", fvalue_get_floating(&finfo->value));
}
offset_r = (int)strlen(result);
break;
offset_e += protoo_strlcpy(expr+offset_e, result+offset_r, size-offset_e);
case FT_DOUBLE:
if (hfinfo->display & BASE_UNIT_STRING) {
double d_value = fvalue_get_floating(&finfo->value);
g_snprintf(result+offset_r, size-offset_r,
"%." G_STRINGIFY(DBL_DIG) "g%s", d_value,
unit_name_string_get_double(d_value, (const unit_name_string*)hfinfo->strings));
} else {
g_snprintf(result+offset_r, size-offset_r,
"%." G_STRINGIFY(DBL_DIG) "g", fvalue_get_floating(&finfo->value));
}
offset_r = (int)strlen(result);
break;
case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
case FT_STRINGZPAD:
case FT_STRINGZTRUNC:
bytes = (guint8 *)fvalue_get(&finfo->value);
str = hfinfo_format_text(NULL, hfinfo, bytes);
offset_r += protoo_strlcpy(result+offset_r,
str, size-offset_r);
wmem_free(NULL, str);
offset_r += label_len;
break;
default:
/* First try ftype string representation */
str = fvalue_to_string_repr(NULL, &finfo->value, FTREPR_DISPLAY, hfinfo->display);
if (!str) {
/* Default to show as bytes */
bytes = (guint8 *)fvalue_get(&finfo->value);
str = bytes_to_str(NULL, bytes, fvalue_length(&finfo->value));
}
offset_r += protoo_strlcpy(result+offset_r, str, size-offset_r);
wmem_free(NULL, str);
offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
break;
}
i++;

View File

@ -1130,7 +1130,7 @@ WS_DLL_PUBLIC int proto_item_get_len(const proto_item *pi);
*/
WS_DLL_PUBLIC void proto_item_set_bits_offset_len(proto_item *ti, int bits_offset, int bits_len);
/** Get display representation of a proto_item.
/** Get the display representation of a proto_item.
* Can be used, for example, to append that to the parent item of
* that item.
@param scope the wmem scope to use to allocate the string
@ -2369,12 +2369,22 @@ WS_DLL_PUBLIC proto_item *
proto_tree_add_debug_text(proto_tree *tree, const char *format,
...) G_GNUC_PRINTF(2,3);
/** Fill given label_str with string representation of field
/** Fill given label_str with a simple string representation of field.
@param fi the item to get the info from
@param label_str the string to fill
@todo think about changing the parameter profile */
WS_DLL_PUBLIC void
proto_item_fill_label(field_info *fi, gchar *label_str);
proto_item_fill_label(field_info *finfo, gchar *label_str);
/** Fill the given display_label_str with the string representation of a field
* formatted according to its type and field display specifier.
* Used to display custom columns and packet diagram values.
@param fi The item to get the info from
@param display_label_str The string to fill
@return The length of the label excluding the terminating '\0'.
*/
WS_DLL_PUBLIC int
proto_item_fill_display_label(field_info *fi, gchar *display_label_str, const int label_str_size);
/** Register a new protocol.
@param name the full name of the new protocol

View File

@ -138,18 +138,15 @@ const QString FieldInformation::moduleName()
QString FieldInformation::toString()
{
QString repr;
gchar *repr_str;
repr_str = fvalue_to_string_repr(NULL, &fi_->value, FTREPR_DISPLAY, fi_->hfinfo->display);
if (repr_str) {
repr = repr_str;
}
wmem_free(NULL, repr_str);
QByteArray display_label;
if (repr.isEmpty()) {
display_label.resize(80); // Arbitrary.
proto_item_fill_display_label(fi_, display_label.data(), display_label.size());
if (display_label.isEmpty()) {
return "[no value for field]";
}
return repr;
return QString(display_label);
}
QString FieldInformation::url()