diff options
author | Gerald Combs <gerald@wireshark.org> | 2013-11-23 01:06:30 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2013-11-23 01:06:30 +0000 |
commit | b3a24c5cc401498535ffdb64aaa212e46e587698 (patch) | |
tree | dc835e50c3dc6745eea9f958a20e0af3f72ea228 | |
parent | 11d8147ab57af71f28b59f8a43f6a9a0618e0c66 (diff) |
Replace similar code with a common routine.
svn path=/trunk/; revision=53519
-rw-r--r-- | epan/proto.c | 29 | ||||
-rw-r--r-- | epan/proto.h | 13 | ||||
-rw-r--r-- | ui/gtk/follow_tcp.c | 18 | ||||
-rw-r--r-- | ui/gtk/follow_udp.c | 18 | ||||
-rw-r--r-- | ui/gtk/main_menubar.c | 22 | ||||
-rw-r--r-- | ui/qt/follow_stream_dialog.cpp | 19 | ||||
-rw-r--r-- | ui/qt/main_window.cpp | 23 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 32 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 17 |
9 files changed, 50 insertions, 141 deletions
diff --git a/epan/proto.c b/epan/proto.c index bb6a6e32fc..dfec1e5cb2 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -4543,6 +4543,35 @@ proto_get_protocol_filter_name(const int proto_id) return protocol->filter_name; } +void +proto_get_frame_protocols(const wmem_list_t *layers, gboolean *is_ip, gboolean *is_tcp, gboolean *is_udp, gboolean *is_sctp) { + wmem_list_frame_t* protos = wmem_list_head(layers); + int proto_id; + const char* proto_name; + + /* Walk the list of a available protocols in the packet and + find "major" ones. */ + /* It might make more sense to assemble and return a bitfield. */ + while (protos != NULL) + { + proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); + proto_name = proto_get_protocol_filter_name(proto_id); + + if (is_ip && ((!strcmp(proto_name, "ip")) || + (!strcmp(proto_name, "ipv6")))) { + *is_ip = TRUE; + } else if (is_tcp && !strcmp(proto_name, "tcp")) { + *is_tcp = TRUE; + } else if (is_udp && !strcmp(proto_name, "udp")) { + *is_udp = TRUE; + } else if (is_sctp && !strcmp(proto_name, "sctp")) { + *is_sctp = TRUE; + } + + protos = wmem_list_frame_next(protos); + } +} + gboolean proto_is_protocol_enabled(const protocol_t *protocol) { diff --git a/epan/proto.h b/epan/proto.h index 1528866438..ad12588f6f 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -1787,6 +1787,19 @@ WS_DLL_PUBLIC gboolean proto_is_protocol_enabled(const protocol_t *protocol); @return its filter name. */ WS_DLL_PUBLIC const char *proto_get_protocol_filter_name(const int proto_id); +/** Find commonly-used protocols in a layer list. + * @param layers Protocol layer list + * @param is_ip Set to TRUE if the layer list contains IPv4 or IPv6, otherwise + * unchanged. May be NULL. + * @param is_tcp Set to TRUE if the layer list contains TCP, otherwise + * unchanged. May be NULL. + * @param is_udp Set to TRUE if the layer list contains UDP, otherwise + * unchanged. May be NULL. + * @param is_sctp Set to TRUE if the layer list contains SCTP, otherwise + * unchanged. May be NULL. + */ +WS_DLL_PUBLIC void proto_get_frame_protocols(const wmem_list_t *layers, gboolean *is_ip, gboolean *is_tcp, gboolean *is_udp, gboolean *is_sctp); + /** Enable / Disable protocol of the given item number. @param proto_id protocol id (0-indexed) @param enabled enable / disable the protocol */ diff --git a/ui/gtk/follow_tcp.c b/ui/gtk/follow_tcp.c index 483b739d0e..1e62085f16 100644 --- a/ui/gtk/follow_tcp.c +++ b/ui/gtk/follow_tcp.c @@ -105,25 +105,9 @@ follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_) size_t nchars; gchar *data_out_filename; char stream_window_title[256]; - wmem_list_frame_t* protos; - int proto_id; - const char* proto_name; gboolean is_tcp = FALSE; - /* we got tcp so we can follow (should really be protected by menu sensitivity) */ - protos = wmem_list_head(cfile.edt->pi.layers); - /* walk the list of a available protocols in the packet to see if we have TCP */ - while (protos != NULL) { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - - if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - break; - } - - protos = wmem_list_frame_next(protos); - } + proto_get_frame_protocols(cfile.edt->pi.layers, NULL, &is_tcp, NULL, NULL); if (!is_tcp) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, diff --git a/ui/gtk/follow_udp.c b/ui/gtk/follow_udp.c index f5232afdea..3ba4348845 100644 --- a/ui/gtk/follow_udp.c +++ b/ui/gtk/follow_udp.c @@ -94,25 +94,9 @@ follow_udp_stream_cb(GtkWidget *w _U_, gpointer data _U_) follow_stats_t stats; follow_info_t *follow_info; GString *msg; - wmem_list_frame_t* protos; - int proto_id; - const char* proto_name; gboolean is_udp = FALSE; - /* we got udp so we can follow (should really be protected by menu sensitivity) */ - protos = wmem_list_head(cfile.edt->pi.layers); - /* walk the list of a available protocols in the packet to see if we have UDP */ - while (protos != NULL) { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - - if (!strcmp(proto_name, "udp")) { - is_udp = TRUE; - break; - } - - protos = wmem_list_frame_next(protos); - } + proto_get_frame_protocols(cfile.edt->pi.layers, NULL, NULL, &is_udp, NULL); if (!is_udp) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c index 4654671fee..e16152c5b3 100644 --- a/ui/gtk/main_menubar.c +++ b/ui/gtk/main_menubar.c @@ -189,30 +189,10 @@ static char * build_conversation_filter(int action, gboolean show_dialog) { packet_info *pi = &cfile.edt->pi; - wmem_list_frame_t * protos = wmem_list_head(pi->layers); - int proto_id; - const char* proto_name; char *buf; gboolean is_ip = FALSE, is_tcp = FALSE, is_udp = FALSE; - /* walk the list of a available protocols in the packet to - figure out if any of them affect conversation filters */ - while (protos != NULL) - { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - - if ((!strcmp(proto_name, "ip")) || - (!strcmp(proto_name, "ipv6"))) { - is_ip = TRUE; - } else if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - } else if (!strcmp(proto_name, "udp")) { - is_udp = TRUE; - } - - protos = wmem_list_frame_next(protos); - } + proto_get_frame_protocols(pi->layers, &is_ip, &is_tcp, &is_udp, NULL); switch(action) { case(CONV_CBA): diff --git a/ui/qt/follow_stream_dialog.cpp b/ui/qt/follow_stream_dialog.cpp index 7adb53b6b9..882c2b8c3c 100644 --- a/ui/qt/follow_stream_dialog.cpp +++ b/ui/qt/follow_stream_dialog.cpp @@ -807,9 +807,6 @@ bool FollowStreamDialog::follow(QString previous_filter, bool use_tcp_index) tcp_stream_chunk sc; size_t nchars; GString * msg; - wmem_list_frame_t* protos; - int proto_id; - const char* proto_name; gboolean is_tcp = FALSE, is_udp = FALSE; resetStream(); @@ -826,21 +823,7 @@ bool FollowStreamDialog::follow(QString previous_filter, bool use_tcp_index) return false; } - /* walk the list of a available protocols in the packet to see what we have - Handles error conditions that should probably just be handled with menu sensitivity */ - protos = wmem_list_head(cap_file_->edt->pi.layers); - while (protos != NULL) { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - - if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - } else if (!strcmp(proto_name, "udp")) { - is_udp = TRUE; - } - - protos = wmem_list_frame_next(protos); - } + proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL); switch (follow_type_) { diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index cbd010aa8e..d3c827406d 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -1366,9 +1366,6 @@ void MainWindow::setTitlebarForCaptureInProgress() void MainWindow::setMenusForFollowStream() { - wmem_list_frame_t* protos; - int proto_id; - const char* proto_name; gboolean is_tcp = FALSE, is_udp = FALSE; if (!cap_file_) @@ -1381,24 +1378,8 @@ void MainWindow::setMenusForFollowStream() main_ui_->actionAnalyzeFollowUDPStream->setEnabled(false); main_ui_->actionAnalyzeFollowSSLStream->setEnabled(false); - protos = wmem_list_head(cap_file_->edt->pi.layers); - - /* walk the list of a available protocols in the packet to - figure out if any of them affect context sensitivity */ - while (protos != NULL) - { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - - if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - } else if (!strcmp(proto_name, "udp")) { - is_udp = TRUE; - } - - protos = wmem_list_frame_next(protos); - } - + proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL); + if (is_tcp) { main_ui_->actionAnalyzeFollowTCPStream->setEnabled(true); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 0ec6cb80fc..551c0499bd 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -726,9 +726,6 @@ void MainWindow::setMenusForSelectedPacket() // gboolean properties = FALSE; // const char *abbrev = NULL; // char *prev_abbrev; - wmem_list_frame_t* protos; - int proto_id; - const char* proto_name; #if 0 gboolean is_ip = FALSE, is_tcp = FALSE, is_udp = FALSE, is_sctp = FALSE; #else @@ -776,34 +773,7 @@ void MainWindow::setMenusForSelectedPacket() if (cap_file_->edt) { - protos = wmem_list_head(cap_file_->edt->pi.layers); - - /* walk the list of a available protocols in the packet to - figure out if any of them affect context sensitivity */ - while (protos != NULL) - { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - -#if 0 - if ((!strcmp(proto_name, "ip")) || - (!strcmp(proto_name, "ipv6"))) { - is_ip = TRUE; - } else if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - } else if (!strcmp(proto_name, "udp")) { - is_udp = TRUE; - } else if (!strcmp(proto_name, "sctp")) { - is_sctp = TRUE; - } -#else - if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - } -#endif - - protos = wmem_list_frame_next(protos); - } + proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, NULL, NULL); } } // if (cfile.edt && cfile.edt->tree) { diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index ad6ffcb324..a70c3e690d 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -460,27 +460,12 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event) { bool fa_enabled = filter_actions_[0]->isEnabled(); QAction *act; - wmem_list_frame_t* protos; - int proto_id; - const char* proto_name; gboolean is_tcp = FALSE, is_udp = FALSE; /* walk the list of a available protocols in the packet to see what we have */ if ((cap_file_ != NULL) && (cap_file_->edt != NULL)) { - protos = wmem_list_head(cap_file_->edt->pi.layers); - while (protos != NULL) { - proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos)); - proto_name = proto_get_protocol_filter_name(proto_id); - - if (!strcmp(proto_name, "tcp")) { - is_tcp = TRUE; - } else if (!strcmp(proto_name, "udp")) { - is_udp = TRUE; - } - - protos = wmem_list_frame_next(protos); - } + proto_get_frame_protocols(cap_file_->edt->pi.layers, NULL, &is_tcp, &is_udp, NULL); } foreach (act, filter_actions_) |