From 61d033645d7b146c2535fce8ed1cbb6272dde2d7 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 25 Feb 2018 15:41:02 +0100 Subject: [PATCH] Qt/USB: Allow USB src/dst addresses to be selected for columns Make "Prepare a Filter" from the Source and Destination columns work for USB source and destination address, this value must be quoted as well. Change-Id: Ib7a772050c204e716781cc27f9eddbdb7971e547 Reviewed-on: https://code.wireshark.org/review/26096 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/packet-usb.c | 8 +++++++- ui/qt/packet_list.cpp | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/epan/dissectors/packet-usb.c b/epan/dissectors/packet-usb.c index d7f53b7a10..740c239414 100644 --- a/epan/dissectors/packet-usb.c +++ b/epan/dissectors/packet-usb.c @@ -1746,6 +1746,12 @@ static const char* usb_host_get_filter_type(hostlist_talker_t* host, conv_filter return CONV_FILTER_INVALID; } +static const char* +usb_col_filter_str(const address* addr _U_, gboolean is_src) +{ + return is_src ? "usb.src" : "usb.dst"; +} + static hostlist_dissector_info_t usb_host_dissector_info = {&usb_host_get_filter_type}; static int @@ -6340,7 +6346,7 @@ proto_register_usb(void) register_decode_as(&usb_product_da); register_decode_as(&usb_device_da); - usb_address_type = address_type_dissector_register("AT_USB", "USB Address", usb_addr_to_str, usb_addr_str_len, NULL, NULL, NULL, NULL, NULL); + usb_address_type = address_type_dissector_register("AT_USB", "USB Address", usb_addr_to_str, usb_addr_str_len, NULL, usb_col_filter_str, NULL, NULL, NULL); register_conversation_table(proto_usb, TRUE, usb_conversation_packet, usb_hostlist_packet); } diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 657928a749..dd2582227d 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -1002,6 +1002,7 @@ QString PacketList::getFilterFromRowAndColumn() */ if (strlen(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) != 0 && strlen(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_]) != 0) { + gboolean is_string_value = FALSE; if (cap_file_->cinfo.columns[ctx_column_].col_fmt == COL_CUSTOM) { header_field_info *hfi = proto_registrar_get_byname(cap_file_->cinfo.columns[ctx_column_].col_custom_fields); if (hfi && hfi->parent == -1) { @@ -1009,16 +1010,27 @@ QString PacketList::getFilterFromRowAndColumn() filter.append(cap_file_->cinfo.col_expr.col_expr[ctx_column_]); } else if (hfi && hfi->type == FT_STRING) { /* Custom string, add quotes */ + is_string_value = TRUE; + } + } else { + header_field_info *hfi = proto_registrar_get_byname(cap_file_->cinfo.col_expr.col_expr[ctx_column_]); + if (hfi && hfi->type == FT_STRING) { + /* Could be an address type such as usb.src which must be quoted. */ + is_string_value = TRUE; + } + } + + if (filter.isEmpty()) { + if (is_string_value) { filter.append(QString("%1 == \"%2\"") .arg(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) .arg(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_])); + } else { + filter.append(QString("%1 == %2") + .arg(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) + .arg(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_])); } } - if (filter.isEmpty()) { - filter.append(QString("%1 == %2") - .arg(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) - .arg(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_])); - } } }