forked from osmocom/wireshark
epan: Use proto_*_ret_display_string() in a couple of places
Use a better pattern than formatting the string for display multiple times. Code is cleaner avoids wasteful calls to format_text() that can be slightly expensive. In some cases it might not have exactly the same whitespace semantics for the column info (escape vs replace) but that's OK.
This commit is contained in:
parent
15634c0b46
commit
b982023107
|
@ -140,6 +140,7 @@ dissect_adb_service(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
|
|||
wmem_tree_key_t key[5];
|
||||
wmem_tree_t *subtree;
|
||||
guint32 i_key;
|
||||
char *display_str;
|
||||
|
||||
main_item = proto_tree_add_item(tree, proto_adb_service, tvb, offset, -1, ENC_NA);
|
||||
main_tree = proto_item_add_subtree(main_item, ett_adb_service);
|
||||
|
@ -518,12 +519,12 @@ dissect_adb_service(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
|
|||
offset = tvb_captured_length(tvb);
|
||||
} else if (g_str_has_prefix(service, "shell:")) {
|
||||
if (adb_service_data->direction == P2P_DIR_SENT) {
|
||||
proto_tree_add_item(main_tree, hf_stdin, tvb, offset, -1, ENC_NA | ENC_ASCII);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Stdin=<%s>", tvb_format_text_wsp(pinfo->pool, tvb, offset, tvb_captured_length_remaining(tvb, offset)));
|
||||
proto_tree_add_item_ret_display_string(main_tree, hf_stdin, tvb, offset, -1, ENC_ASCII, pinfo->pool, &display_str);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Stdin=<%s>", display_str);
|
||||
|
||||
} else {
|
||||
proto_tree_add_item(main_tree, hf_stdout, tvb, offset, -1, ENC_NA | ENC_ASCII);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Stdout=<%s>", tvb_format_text_wsp(pinfo->pool, tvb, offset, tvb_captured_length_remaining(tvb, offset)));
|
||||
proto_tree_add_item_ret_display_string(main_tree, hf_stdout, tvb, offset, -1, ENC_ASCII, pinfo->pool, &display_str);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Stdout=<%s>", display_str);
|
||||
}
|
||||
offset = tvb_captured_length(tvb);
|
||||
} else if (g_str_has_prefix(service, "jdwp:")) {
|
||||
|
@ -540,8 +541,8 @@ dissect_adb_service(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
|
|||
g_str_has_prefix(service, "tcpip:") ||
|
||||
g_str_has_prefix(service, "usb:")) {
|
||||
if (tvb_reported_length_remaining(tvb, offset)) {
|
||||
proto_tree_add_item(main_tree, hf_result, tvb, offset, -1, ENC_NA | ENC_ASCII);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Result=<%s>", tvb_format_text_wsp(pinfo->pool, tvb, offset, tvb_captured_length_remaining(tvb, offset)));
|
||||
proto_tree_add_item_ret_display_string(main_tree, hf_result, tvb, offset, -1, ENC_ASCII, pinfo->pool, &display_str);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, " Result=<%s>", display_str);
|
||||
|
||||
offset = tvb_captured_length(tvb);
|
||||
}
|
||||
|
|
|
@ -2438,12 +2438,11 @@ dissect_bthfp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s",
|
||||
tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
|
||||
pitem = proto_tree_add_item(main_tree, hf_fragmented, tvb, 0, 0, ENC_NA);
|
||||
proto_item_set_generated(pitem);
|
||||
proto_tree_add_item(main_tree, hf_fragment, tvb, offset,
|
||||
tvb_captured_length_remaining(tvb, offset), ENC_ASCII | ENC_NA);
|
||||
char *display_str;
|
||||
proto_tree_add_item_ret_display_string(main_tree, hf_fragment, tvb, offset, -1, ENC_ASCII, pinfo->pool, &display_str);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s", display_str);
|
||||
offset = tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
|
|
|
@ -986,12 +986,11 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s",
|
||||
tvb_format_text_wsp(wmem_packet_scope(), tvb, offset, tvb_captured_length_remaining(tvb, offset)));
|
||||
pitem = proto_tree_add_item(main_tree, hf_fragmented, tvb, 0, 0, ENC_NA);
|
||||
proto_item_set_generated(pitem);
|
||||
proto_tree_add_item(main_tree, hf_fragment, tvb, offset,
|
||||
tvb_captured_length_remaining(tvb, offset), ENC_ASCII | ENC_NA);
|
||||
char *display_str;
|
||||
proto_tree_add_item_ret_display_string(main_tree, hf_fragment, tvb, offset, -1, ENC_ASCII, pinfo->pool, &display_str);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, "Fragment: %s", display_str);
|
||||
offset = tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ static int
|
|||
dissect_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
||||
{
|
||||
gint bytes;
|
||||
char *display_str;
|
||||
|
||||
if (tree) {
|
||||
bytes = tvb_captured_length(tvb);
|
||||
|
@ -82,13 +83,17 @@ dissect_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
|||
}
|
||||
|
||||
if (show_as_text) {
|
||||
tvbuff_t *text_tvb;
|
||||
int text_length;
|
||||
if (uncompr_tvb && uncompr_len > 0) {
|
||||
proto_tree_add_item(data_tree, hf_data_text, uncompr_tvb, 0, uncompr_len, ENC_ASCII);
|
||||
col_add_fstr(pinfo->cinfo, COL_INFO, "%s", tvb_format_text_wsp(pinfo->pool, uncompr_tvb, 0, uncompr_len));
|
||||
text_tvb = uncompr_tvb;
|
||||
text_length = uncompr_len;
|
||||
} else {
|
||||
proto_tree_add_item(data_tree, hf_data_text, data_tvb, 0, bytes, ENC_ASCII);
|
||||
col_add_fstr(pinfo->cinfo, COL_INFO, "%s", tvb_format_text_wsp(pinfo->pool, data_tvb, 0, bytes));
|
||||
text_tvb = data_tvb;
|
||||
text_length = bytes;
|
||||
}
|
||||
proto_tree_add_item_ret_display_string(data_tree, hf_data_text, text_tvb, 0, text_length, ENC_ASCII, pinfo->pool, &display_str);
|
||||
col_add_str(pinfo->cinfo, COL_INFO, display_str);
|
||||
}
|
||||
|
||||
if(generate_md5_hash) {
|
||||
|
|
|
@ -363,17 +363,15 @@ dissect_rpcap_error (tvbuff_t *tvb, packet_info *pinfo,
|
|||
{
|
||||
proto_item *ti;
|
||||
gint len;
|
||||
char *str;
|
||||
|
||||
len = tvb_reported_length_remaining (tvb, offset);
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
col_append_fstr (pinfo->cinfo, COL_INFO, ": %s",
|
||||
tvb_format_text_wsp (pinfo->pool, tvb, offset, len));
|
||||
|
||||
ti = proto_tree_add_item (parent_tree, hf_error, tvb, offset, len, ENC_ASCII);
|
||||
expert_add_info_format(pinfo, ti, &ei_error,
|
||||
"Error: %s", tvb_format_text_wsp (pinfo->pool, tvb, offset, len));
|
||||
ti = proto_tree_add_item_ret_display_string(parent_tree, hf_error, tvb, offset, len, ENC_ASCII, pinfo->pool, &str);
|
||||
expert_add_info_format(pinfo, ti, &ei_error, "Error: %s", str);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, ": %s", str);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1321,7 +1319,7 @@ proto_register_rpcap (void)
|
|||
|
||||
/* Error */
|
||||
{ &hf_error,
|
||||
{ "Error", "rpcap.error", FT_STRING, BASE_NONE,
|
||||
{ "Error", "rpcap.error", FT_STRING, BASE_STR_WSP,
|
||||
NULL, 0x0, "Error text", HFILL } },
|
||||
{ &hf_error_value,
|
||||
{ "Error value", "rpcap.error_value", FT_UINT16, BASE_DEC,
|
||||
|
|
Loading…
Reference in New Issue