diff options
author | João Valverde <j@v6e.pt> | 2022-09-28 10:02:17 +0100 |
---|---|---|
committer | A Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2022-09-28 22:13:32 +0000 |
commit | b9820231070a113b804ebf0c3b4c3e424c98f2ee (patch) | |
tree | 909c42f7f3c592566937bd6040be575c619eec88 /epan/dissectors | |
parent | 15634c0b4690a27c81cf69d60f9d7016fc62c61f (diff) |
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.
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/packet-adb_service.c | 13 | ||||
-rw-r--r-- | epan/dissectors/packet-bthfp.c | 7 | ||||
-rw-r--r-- | epan/dissectors/packet-bthsp.c | 7 | ||||
-rw-r--r-- | epan/dissectors/packet-data.c | 13 | ||||
-rw-r--r-- | epan/dissectors/packet-rpcap.c | 12 |
5 files changed, 27 insertions, 25 deletions
diff --git a/epan/dissectors/packet-adb_service.c b/epan/dissectors/packet-adb_service.c index 3bcf7c9aba..5aecbc89f9 100644 --- a/epan/dissectors/packet-adb_service.c +++ b/epan/dissectors/packet-adb_service.c @@ -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); } diff --git a/epan/dissectors/packet-bthfp.c b/epan/dissectors/packet-bthfp.c index 09f4b6ef72..f9afb053d5 100644 --- a/epan/dissectors/packet-bthfp.c +++ b/epan/dissectors/packet-bthfp.c @@ -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); } diff --git a/epan/dissectors/packet-bthsp.c b/epan/dissectors/packet-bthsp.c index 564921cc84..2f1234ea9e 100644 --- a/epan/dissectors/packet-bthsp.c +++ b/epan/dissectors/packet-bthsp.c @@ -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); } diff --git a/epan/dissectors/packet-data.c b/epan/dissectors/packet-data.c index ca8f74ba29..389d005333 100644 --- a/epan/dissectors/packet-data.c +++ b/epan/dissectors/packet-data.c @@ -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) { diff --git a/epan/dissectors/packet-rpcap.c b/epan/dissectors/packet-rpcap.c index e265a2661d..e95f87210e 100644 --- a/epan/dissectors/packet-rpcap.c +++ b/epan/dissectors/packet-rpcap.c @@ -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, |