aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2017-09-16 16:52:23 +0200
committerMichael Mann <mmann78@netscape.net>2017-09-18 21:24:16 +0000
commitc41bab1f667cfe51b09b80869497a2db68abecce (patch)
treef61fbf402e9cfe58b9a694eabf4dd389bed94796 /ui
parenta593fce94cb7fd0fa3f5eef7fae9c0128cb6f7e3 (diff)
Move most of sequence analysis code from ui/ to epan/
Create registration system to allow creation of analysis items to be localized to the dissector. For now only frame (all) and TCP are supported. VOIP functionality will be covered in a separate patch. Change-Id: I5b05ef6d5afff8d0b162b03a0f451ab810602e81 Reviewed-on: https://code.wireshark.org/review/23571 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk/flow_graph.c88
-rw-r--r--ui/gtk/lbm_uimflow_dlg.c2
-rw-r--r--ui/qt/sequence_diagram.cpp2
-rw-r--r--ui/qt/sequence_dialog.cpp52
-rw-r--r--ui/qt/sequence_dialog.h2
-rw-r--r--ui/qt/voip_calls_dialog.cpp2
-rw-r--r--ui/tap-sequence-analysis.c374
-rw-r--r--ui/tap-sequence-analysis.h84
8 files changed, 103 insertions, 503 deletions
diff --git a/ui/gtk/flow_graph.c b/ui/gtk/flow_graph.c
index 75680c0009..5475be457b 100644
--- a/ui/gtk/flow_graph.c
+++ b/ui/gtk/flow_graph.c
@@ -47,17 +47,16 @@ static GtkWidget *flow_graph_dlg = NULL;
static GtkWidget *select_all_rb;
static GtkWidget *select_displayed_rb;
-static GtkWidget *select_general_rb;
-static GtkWidget *select_tcp_rb;
static GtkWidget *src_dst_rb;
static GtkWidget *net_src_dst_rb;
+static GtkWidget *select_analysis_combo;
/****************************************************************************/
static void
flow_graph_data_init(void) {
graph_analysis = sequence_analysis_info_new();
- graph_analysis->type = SEQ_ANALYSIS_ANY;
+ graph_analysis->name = "any";
graph_analysis->all_packets = TRUE;
}
@@ -82,44 +81,47 @@ flow_graph_on_destroy(GObject *object _U_, gpointer user_data _U_)
flow_graph_dlg = NULL;
}
-
-/****************************************************************************/
-static void
-toggle_select_all(GtkWidget *widget _U_, gpointer user_data _U_)
+static gboolean
+find_seq_name(const void *key, void *value, void *userdata)
{
- /* is the button now active? */
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_all_rb))) {
- graph_analysis->all_packets = TRUE;
+ const char* name = (const char*)key;
+ register_analysis_t* analysis = (register_analysis_t*)value;
+ const char* ui_name = (const char*)userdata;
+
+ if (strcmp(ui_name, sequence_analysis_get_ui_name(analysis)) == 0)
+ {
+ graph_analysis->name = name;
+ return TRUE;
}
+
+ return FALSE;
}
-/****************************************************************************/
static void
-toggle_select_displayed(GtkWidget *widget _U_, gpointer user_data _U_)
+sequence_combo_box_changed_cb(GtkComboBox *combo_box, gpointer user_data _U_)
{
- /* is the button now active? */
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_displayed_rb))) {
- graph_analysis->all_packets = FALSE;
- }
+ gchar* ui_name = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box));
+
+ sequence_analysis_table_iterate_tables(find_seq_name, ui_name);
}
/****************************************************************************/
static void
-toggle_select_general(GtkWidget *widget _U_, gpointer user_data _U_)
+toggle_select_all(GtkWidget *widget _U_, gpointer user_data _U_)
{
/* is the button now active? */
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_general_rb))) {
- graph_analysis->type = SEQ_ANALYSIS_ANY;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_all_rb))) {
+ graph_analysis->all_packets = TRUE;
}
}
/****************************************************************************/
static void
-toggle_select_tcp(GtkWidget *widget _U_, gpointer user_data _U_)
+toggle_select_displayed(GtkWidget *widget _U_, gpointer user_data _U_)
{
/* is the button now active? */
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_tcp_rb))) {
- graph_analysis->type = SEQ_ANALYSIS_TCP;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_displayed_rb))) {
+ graph_analysis->all_packets = FALSE;
}
}
@@ -184,6 +186,16 @@ flow_graph_on_delete(GtkButton *button _U_,
/****************************************************************************/
/* INTERFACE */
/****************************************************************************/
+static gboolean
+add_flow_sequence_item(const void *key _U_, void *value, void *userdata)
+{
+ register_analysis_t* analysis = (register_analysis_t*)value;
+ GtkWidget* combo_box = (GtkWidget*)userdata;
+
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), sequence_analysis_get_ui_name(analysis));
+ return FALSE;
+}
+
static void
flow_graph_dlg_create(void)
@@ -230,7 +242,7 @@ flow_graph_dlg_create(void)
if (graph_analysis->all_packets) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_all_rb),TRUE);
}
- gtk_widget_show(select_all_rb);
+ gtk_widget_show(select_all_rb);
/* Process displayed packets */
select_displayed_rb = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(select_all_rb),
@@ -255,28 +267,14 @@ flow_graph_dlg_create(void)
gtk_container_set_border_width(GTK_CONTAINER(flow_type_grid), 5);
gtk_container_add(GTK_CONTAINER(flow_type_fr), flow_type_grid);
- /* General information */
- select_general_rb = gtk_radio_button_new_with_mnemonic_from_widget(NULL, "_General flow");
- gtk_widget_set_tooltip_text (select_general_rb, ("Show all packets, with general information"));
- g_signal_connect(select_general_rb, "toggled", G_CALLBACK(toggle_select_general), NULL);
- ws_gtk_grid_attach_extended(GTK_GRID(flow_type_grid), select_general_rb, 0, 0, 1, 1,
- (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0);
- if (graph_analysis->type == SEQ_ANALYSIS_ANY) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_general_rb),TRUE);
- }
- gtk_widget_show(select_general_rb);
-
- /* TCP specific information */
- select_tcp_rb = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(select_general_rb),
- "_TCP flow");
- gtk_widget_set_tooltip_text (select_tcp_rb, ("Show only TCP packets, with TCP specific information"));
- g_signal_connect(select_tcp_rb, "toggled", G_CALLBACK(toggle_select_tcp), NULL);
- ws_gtk_grid_attach_extended(GTK_GRID(flow_type_grid), select_tcp_rb, 0, 1, 1, 1,
- (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0);
- if (graph_analysis->type == SEQ_ANALYSIS_TCP) {
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_tcp_rb),TRUE);
- }
- gtk_widget_show(select_tcp_rb);
+ select_analysis_combo = gtk_combo_box_text_new();
+ g_signal_connect(select_analysis_combo, "changed", G_CALLBACK(sequence_combo_box_changed_cb), NULL);
+ sequence_analysis_table_iterate_tables(add_flow_sequence_item, select_analysis_combo);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(select_analysis_combo), 0);
+
+ ws_gtk_grid_attach_extended(GTK_GRID(flow_type_grid), select_analysis_combo, 0, 0, 1, 1,
+ (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0);
+ gtk_widget_show(select_analysis_combo);
gtk_widget_show(flow_type_grid);
gtk_widget_show(flow_type_fr);
diff --git a/ui/gtk/lbm_uimflow_dlg.c b/ui/gtk/lbm_uimflow_dlg.c
index 61ea3eb5ea..0a5f1fbd4c 100644
--- a/ui/gtk/lbm_uimflow_dlg.c
+++ b/ui/gtk/lbm_uimflow_dlg.c
@@ -58,7 +58,7 @@ static lbm_uimflow_dialog_t dialog_data = { FALSE, -1, NULL, NULL, NULL, select_
static void lbmc_uim_flow_graph_data_init(void)
{
dialog_data.graph_analysis = sequence_analysis_info_new();
- dialog_data.graph_analysis->type = SEQ_ANALYSIS_ANY;
+ dialog_data.graph_analysis->name = "any";
dialog_data.graph_analysis->all_packets = TRUE;
dialog_data.graph_analysis->any_addr = TRUE;
}
diff --git a/ui/qt/sequence_diagram.cpp b/ui/qt/sequence_diagram.cpp
index 0dd52c59b1..98071b18a6 100644
--- a/ui/qt/sequence_diagram.cpp
+++ b/ui/qt/sequence_diagram.cpp
@@ -263,7 +263,7 @@ void SequenceDiagram::draw(QCPPainter *painter)
fg_pen.setColor(sel_pal.color(QPalette::HighlightedText));
bg_color = sel_pal.color(QPalette::Highlight);
selected_key_ = cur_key;
- } else if (sainfo_->type == SEQ_ANALYSIS_ANY) {
+ } else if (strcmp(sainfo_->name, "any") == 0) {
if (sai->has_color_filter) {
fg_pen.setColor(QColor().fromRgb(sai->fg_color));
bg_color = QColor().fromRgb(sai->bg_color);
diff --git a/ui/qt/sequence_dialog.cpp b/ui/qt/sequence_dialog.cpp
index 0d058fe556..786a73076d 100644
--- a/ui/qt/sequence_dialog.cpp
+++ b/ui/qt/sequence_dialog.cpp
@@ -33,6 +33,7 @@
#include <ui/qt/utils/qt_ui_utils.h>
#include "sequence_diagram.h"
#include "wireshark_application.h"
+#include <ui/qt/utils/variant_pointer.h>
#include <QDir>
#include <QFileDialog>
@@ -65,6 +66,12 @@
static const double min_top_ = -1.0;
static const double min_left_ = -0.5;
+typedef struct {
+ int curr_index;
+ QComboBox *flow;
+ SequenceInfo *info;
+} sequence_items_t;
+
SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, SequenceInfo *info) :
WiresharkDialog(parent, cf),
ui(new Ui::SequenceDialog),
@@ -80,7 +87,7 @@ SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, SequenceInfo *i
if (!info_) {
info_ = new SequenceInfo(sequence_analysis_info_new());
- info_->sainfo()->type = SEQ_ANALYSIS_ANY;
+ info_->sainfo()->name = "any";
info_->sainfo()->all_packets = TRUE;
} else {
info_->ref();
@@ -153,13 +160,16 @@ SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, SequenceInfo *i
ui->showComboBox->setCurrentIndex(0);
ui->addressComboBox->setCurrentIndex(0);
- QComboBox *fcb = ui->flowComboBox;
- fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY);
- fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP);
+ sequence_items_t item_data;
+
+ item_data.curr_index = 0;
+ item_data.flow = ui->flowComboBox;
+ item_data.info = info_;
- ui->flowComboBox->setCurrentIndex(info_->sainfo()->type);
+ //Add all registered analysis to combo box
+ sequence_analysis_table_iterate_tables(addFlowSequenceItem, &item_data);
- if (info_->sainfo()->type == SEQ_ANALYSIS_VOIP) {
+ if (strcmp(info_->sainfo()->name, "voip") == 0) {
ui->flowComboBox->blockSignals(true);
ui->controlFrame->hide();
}
@@ -405,7 +415,7 @@ void SequenceDialog::fillDiagram()
QCustomPlot *sp = ui->sequencePlot;
- if (info_->sainfo()->type == SEQ_ANALYSIS_VOIP) {
+ if (strcmp(info_->sainfo()->name, "voip") == 0) {
seq_diagram_->setData(info_->sainfo());
} else {
seq_diagram_->clearData();
@@ -587,9 +597,12 @@ void SequenceDialog::on_showComboBox_activated(int index)
void SequenceDialog::on_flowComboBox_activated(int index)
{
- if (!info_->sainfo() || info_->sainfo()->type == SEQ_ANALYSIS_VOIP || index < 0) return;
+ if (!info_->sainfo() || (strcmp(info_->sainfo()->name, "voip") == 0) || index < 0)
+ return;
+
+ register_analysis_t* analysis = VariantPointer<register_analysis_t>::asPtr(ui->flowComboBox->itemData(index));
+ info_->sainfo()->name = sequence_analysis_get_name(analysis);
- info_->sainfo()->type = static_cast<seq_analysis_type>(ui->flowComboBox->itemData(index).toInt());
fillDiagram();
}
@@ -673,6 +686,27 @@ void SequenceDialog::zoomXAxis(bool in)
sp->replot();
}
+gboolean SequenceDialog::addFlowSequenceItem(const void* key, void *value, void *userdata)
+{
+ const char* name = (const char*)key;
+ register_analysis_t* analysis = (register_analysis_t*)value;
+ sequence_items_t* item_data = (sequence_items_t*)userdata;
+
+ /* XXX - Although "voip" isn't a registered name yet, it appears to have special
+ handling that will be done outside of registered data */
+ if (strcmp(name, "voip") == 0)
+ return FALSE;
+
+ item_data->flow->addItem(sequence_analysis_get_ui_name(analysis), VariantPointer<register_analysis_t>::asQVariant(analysis));
+
+ if (item_data->flow->itemData(item_data->curr_index).toString().compare(item_data->info->sainfo()->name) == 0)
+ item_data->flow->setCurrentIndex(item_data->curr_index);
+
+ item_data->curr_index++;
+
+ return FALSE;
+}
+
SequenceInfo::SequenceInfo(seq_analysis_info_t *sainfo) :
sainfo_(sainfo),
count_(1)
diff --git a/ui/qt/sequence_dialog.h b/ui/qt/sequence_dialog.h
index e6f0afef11..110e1f948e 100644
--- a/ui/qt/sequence_dialog.h
+++ b/ui/qt/sequence_dialog.h
@@ -117,6 +117,8 @@ private:
void panAxes(int x_pixels, int y_pixels);
void resetAxes(bool keep_lower = false);
void goToAdjacentPacket(bool next);
+
+ static gboolean addFlowSequenceItem(const void *key, void *value, void *userdata);
};
#endif // SEQUENCE_DIALOG_H
diff --git a/ui/qt/voip_calls_dialog.cpp b/ui/qt/voip_calls_dialog.cpp
index ef7ce35760..2016c01eaa 100644
--- a/ui/qt/voip_calls_dialog.cpp
+++ b/ui/qt/voip_calls_dialog.cpp
@@ -103,7 +103,7 @@ VoipCallsDialog::VoipCallsDialog(QWidget &parent, CaptureFile &cf, bool all_flow
tapinfo_.h225_cstype = H225_OTHER;
tapinfo_.fs_option = all_flows ? FLOW_ALL : FLOW_ONLY_INVITES; /* flow show option */
tapinfo_.graph_analysis = sequence_analysis_info_new();
- tapinfo_.graph_analysis->type = SEQ_ANALYSIS_VOIP;
+ tapinfo_.graph_analysis->name = "voip";
sequence_info_ = new SequenceInfo(tapinfo_.graph_analysis);
voip_calls_init_all_taps(&tapinfo_);
diff --git a/ui/tap-sequence-analysis.c b/ui/tap-sequence-analysis.c
index eda3b049f8..2ec1fc8333 100644
--- a/ui/tap-sequence-analysis.c
+++ b/ui/tap-sequence-analysis.c
@@ -29,19 +29,13 @@
#include "tap-sequence-analysis.h"
#include "epan/addr_resolv.h"
-#include "epan/color_filters.h"
#include "epan/packet.h"
#include "epan/tap.h"
-#include "epan/proto_data.h"
-#include "epan/dissectors/packet-tcp.h"
-#include "epan/dissectors/packet-icmp.h"
#include "ui/alert_box.h"
#include <wsutil/file_util.h>
-#define NODE_OVERFLOW MAX_NUM_NODES+1
-
#define NODE_CHARS_WIDTH 20
#define CONV_TIME_HEADER "Conv.| Time "
#define TIME_HEADER "|Time "
@@ -50,210 +44,6 @@
#define CONV_TIME_HEADER_LENGTH 16
#define TIME_HEADER_LENGTH 10
-seq_analysis_info_t *
-sequence_analysis_info_new(void)
-{
- seq_analysis_info_t *sainfo = g_new0(seq_analysis_info_t, 1);
-
- /* SEQ_ANALYSIS_DEBUG("adding new item"); */
- sainfo->items = g_queue_new();
- sainfo->ht= g_hash_table_new(g_int_hash, g_int_equal);
- return sainfo;
-}
-
-void sequence_analysis_info_free(seq_analysis_info_t *sainfo)
-{
- if (!sainfo) return;
-
- /* SEQ_ANALYSIS_DEBUG("%d items", g_queue_get_length(sainfo->items)); */
- sequence_analysis_list_free(sainfo);
-
- g_queue_free(sainfo->items);
- g_hash_table_destroy(sainfo->ht);
-
- g_free(sainfo);
-}
-
-/****************************************************************************/
-/* whenever a frame packet is seen by the tap listener */
-/* Add a new frame into the graph */
-static gboolean
-seq_analysis_frame_packet( void *ptr, packet_info *pinfo, epan_dissect_t *edt _U_, const void *dummy _U_)
-{
- seq_analysis_info_t *sainfo = (seq_analysis_info_t *) ptr;
- col_item_t* col_item;
-
- if ((sainfo->all_packets)||(pinfo->fd->flags.passed_dfilter==1)){
- int i;
- gchar *protocol = NULL;
- gchar *colinfo = NULL;
- seq_analysis_item_t *sai = NULL;
- icmp_info_t *p_icmp_info;
-
- if (sainfo->any_addr) {
- if (pinfo->net_src.type!=AT_NONE && pinfo->net_dst.type!=AT_NONE) {
- sai = (seq_analysis_item_t *)g_malloc0(sizeof(seq_analysis_item_t));
- copy_address(&(sai->src_addr),&(pinfo->net_src));
- copy_address(&(sai->dst_addr),&(pinfo->net_dst));
- }
-
- } else {
- if (pinfo->src.type!=AT_NONE && pinfo->dst.type!=AT_NONE) {
- sai = (seq_analysis_item_t *)g_malloc0(sizeof(seq_analysis_item_t));
- copy_address(&(sai->src_addr),&(pinfo->src));
- copy_address(&(sai->dst_addr),&(pinfo->dst));
- }
- }
-
- if (!sai) return FALSE;
-
- sai->frame_number = pinfo->num;
-
- if (pinfo->fd->color_filter) {
- sai->bg_color = color_t_to_rgb(&pinfo->fd->color_filter->bg_color);
- sai->fg_color = color_t_to_rgb(&pinfo->fd->color_filter->fg_color);
- sai->has_color_filter = TRUE;
- }
-
- sai->port_src=pinfo->srcport;
- sai->port_dst=pinfo->destport;
- sai->protocol = g_strdup(port_type_to_str(pinfo->ptype));
-
- if(pinfo->cinfo) {
- if (pinfo->cinfo->col_first[COL_INFO]>=0){
-
- for (i = pinfo->cinfo->col_first[COL_INFO]; i <= pinfo->cinfo->col_last[COL_INFO]; i++) {
- col_item = &pinfo->cinfo->columns[i];
- if (col_item->fmt_matx[COL_INFO]) {
- colinfo = g_strdup(col_item->col_data);
- /* break; ? or g_free(colinfo); before g_strdup() */
- }
- }
- }
-
- if (pinfo->cinfo->col_first[COL_PROTOCOL]>=0){
-
- for (i = pinfo->cinfo->col_first[COL_PROTOCOL]; i <= pinfo->cinfo->col_last[COL_PROTOCOL]; i++) {
- col_item = &pinfo->cinfo->columns[i];
- if (col_item->fmt_matx[COL_PROTOCOL]) {
- protocol = g_strdup(col_item->col_data);
- /* break; ? or g_free(protocol); before g_strdup() */
- }
- }
- }
- }
-
- if (colinfo != NULL) {
- sai->frame_label = g_strdup(colinfo);
- if (protocol != NULL) {
- sai->comment = g_strdup_printf("%s: %s", protocol, colinfo);
- } else {
- sai->comment = g_strdup(colinfo);
- }
- } else {
- /* This will probably never happen...*/
- if (protocol != NULL) {
- sai->frame_label = g_strdup(protocol);
- sai->comment = g_strdup(protocol);
- }
- }
-
- if (pinfo->ptype == PT_NONE) {
- if ((p_icmp_info = (icmp_info_t *)p_get_proto_data(wmem_file_scope(),
- pinfo, proto_get_id_by_short_name("ICMP"), 0)) != NULL) {
- g_free(sai->protocol);
- sai->protocol = g_strdup("ICMP");
- sai->port_src = 0;
- sai->port_dst = p_icmp_info->type * 256 + p_icmp_info->code;
- } else if ((p_icmp_info = (icmp_info_t *)p_get_proto_data(wmem_file_scope(),
- pinfo, proto_get_id_by_short_name("ICMPv6"), 0)) != NULL) {
- g_free(sai->protocol);
- sai->protocol = g_strdup("ICMPv6");
- sai->port_src = 0;
- sai->port_dst = p_icmp_info->type * 256 + p_icmp_info->code;
- }
- }
-
- g_free(protocol);
- g_free(colinfo);
-
- sai->line_style=1;
- sai->conv_num=0;
- sai->display=TRUE;
-
- g_queue_push_tail(sainfo->items, sai);
- }
-
- return TRUE;
-}
-
-/****************************************************************************/
-/* whenever a TCP packet is seen by the tap listener */
-/* Add a new tcp frame into the graph */
-static gboolean
-seq_analysis_tcp_packet( void *ptr, packet_info *pinfo, epan_dissect_t *edt _U_, const void *tcp_info)
-{
- seq_analysis_info_t *sainfo = (seq_analysis_info_t *) ptr;
- const struct tcpheader *tcph = (const struct tcpheader *)tcp_info;
-
- if ((sainfo->all_packets)||(pinfo->fd->flags.passed_dfilter==1)){
- /* copied from packet-tcp */
- static const gchar *fstr[] = {"FIN", "SYN", "RST", "PSH", "ACK", "URG", "ECN", "CWR" };
- guint i, bpos;
- gboolean flags_found = FALSE;
- gchar flags[64];
- seq_analysis_item_t *sai;
-
- sai = (seq_analysis_item_t *)g_malloc0(sizeof(seq_analysis_item_t));
- sai->frame_number = pinfo->num;
- if (sainfo->any_addr) {
- copy_address(&(sai->src_addr),&(pinfo->net_src));
- copy_address(&(sai->dst_addr),&(pinfo->net_dst));
- } else {
- copy_address(&(sai->src_addr),&(pinfo->src));
- copy_address(&(sai->dst_addr),&(pinfo->dst));
- }
- sai->port_src=pinfo->srcport;
- sai->port_dst=pinfo->destport;
- sai->protocol=g_strdup(port_type_to_str(pinfo->ptype));
-
- flags[0] = '\0';
- for (i = 0; i < 8; i++) {
- bpos = 1 << i;
- if (tcph->th_flags & bpos) {
- if (flags_found) {
- g_strlcat(flags, ", ", sizeof(flags));
- }
- g_strlcat(flags, fstr[i], sizeof(flags));
- flags_found = TRUE;
- }
- }
- if (flags[0] == '\0') {
- g_snprintf (flags, sizeof(flags), "<None>");
- }
-
- if ((tcph->th_have_seglen)&&(tcph->th_seglen!=0)){
- sai->frame_label = g_strdup_printf("%s - Len: %u",flags, tcph->th_seglen);
- }
- else{
- sai->frame_label = g_strdup(flags);
- }
-
- if (tcph->th_flags & TH_ACK)
- sai->comment = g_strdup_printf("Seq = %u Ack = %u",tcph->th_seq, tcph->th_ack);
- else
- sai->comment = g_strdup_printf("Seq = %u",tcph->th_seq);
-
- sai->line_style = 1;
- sai->conv_num = (guint16) tcph->th_stream;
- sai->display = TRUE;
-
- g_queue_push_tail(sainfo->items, sai);
- }
-
- return TRUE;
-}
-
static void sequence_analysis_item_set_timestamp(gpointer data, gpointer user_data)
{
gchar time_str[COL_MAX_LEN];
@@ -267,29 +57,17 @@ static void sequence_analysis_item_set_timestamp(gpointer data, gpointer user_da
void
sequence_analysis_list_get(capture_file *cf, seq_analysis_info_t *sainfo)
{
- if (!cf || !sainfo) return;
-
- switch (sainfo->type) {
- case SEQ_ANALYSIS_ANY:
- register_tap_listener("frame", sainfo, NULL,
- TL_REQUIRES_COLUMNS,
- NULL,
- seq_analysis_frame_packet,
- NULL
- );
- break;
- case SEQ_ANALYSIS_TCP:
- register_tap_listener("tcp", sainfo, NULL,
- 0,
- NULL,
- seq_analysis_tcp_packet,
- NULL
- );
- break;
- case SEQ_ANALYSIS_VOIP:
- default:
+ register_analysis_t* analysis = NULL;
+
+ if (!cf || !sainfo)
return;
- }
+
+ analysis = sequence_analysis_find_by_name(sainfo->name);
+ if (analysis == NULL)
+ return;
+
+ register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), sainfo, NULL, sequence_analysis_get_tap_flags(analysis),
+ NULL, sequence_analysis_get_packet_func(analysis), NULL);
cf_retap_packets(cf);
remove_tap_listener(sainfo);
@@ -299,74 +77,6 @@ sequence_analysis_list_get(capture_file *cf, seq_analysis_info_t *sainfo)
g_queue_foreach(sainfo->items, sequence_analysis_item_set_timestamp, cf);
}
-static void sequence_analysis_item_free(gpointer data)
-{
- seq_analysis_item_t *seq_item = (seq_analysis_item_t *)data;
- g_free(seq_item->frame_label);
- g_free(seq_item->time_str);
- g_free(seq_item->comment);
- g_free(seq_item->protocol);
- free_address(&seq_item->src_addr);
- free_address(&seq_item->dst_addr);
- g_free(data);
-}
-
-
-/* compare two list entries by packet no */
-static gint
-sequence_analysis_sort_compare(gconstpointer a, gconstpointer b, gpointer user_data _U_)
-{
- const seq_analysis_item_t *entry_a = (const seq_analysis_item_t *)a;
- const seq_analysis_item_t *entry_b = (const seq_analysis_item_t *)b;
-
- if(entry_a->frame_number < entry_b->frame_number)
- return -1;
-
- if(entry_a->frame_number > entry_b->frame_number)
- return 1;
-
- return 0;
-}
-
-
-void
-sequence_analysis_list_sort(seq_analysis_info_t *sainfo)
-{
- if (!sainfo) return;
- g_queue_sort(sainfo->items, sequence_analysis_sort_compare, NULL);
-}
-
-void
-sequence_analysis_list_free(seq_analysis_info_t *sainfo)
-{
- if (!sainfo) return;
- /* SEQ_ANALYSIS_DEBUG("%d items", g_queue_get_length(sainfo->items)); */
-
- /* free the graph data items */
-
-#if GLIB_CHECK_VERSION (2, 32, 0)
- g_queue_free_full(sainfo->items, sequence_analysis_item_free);
- sainfo->items = g_queue_new();
-#else
- {
- GList *list = g_queue_peek_nth_link(sainfo->items, 0);
- while (list)
- {
- sequence_analysis_item_free(list->data);
- list = g_list_next(list);
- }
- g_queue_clear(sainfo->items);
- }
-#endif
-
- if (NULL != sainfo->ht) {
- g_hash_table_remove_all(sainfo->ht);
- }
- sainfo->nconv = 0;
-
- sequence_analysis_free_nodes(sainfo);
-}
-
/****************************************************************************/
/* Adds trailing characters to complete the requested length. */
/****************************************************************************/
@@ -427,70 +137,6 @@ static void overwrite (GString *gstr, char *text_to_insert, guint32 p1, guint32
g_free(ins_str);
}
-/* Return the index array if the node is in the array. Return -1 if there is room in the array
- * and Return -2 if the array is full
- */
-/****************************************************************************/
-static guint add_or_get_node(seq_analysis_info_t *sainfo, address *node) {
- guint i;
-
- if (node->type == AT_NONE) return NODE_OVERFLOW;
-
- for (i=0; i<MAX_NUM_NODES && i < sainfo->num_nodes ; i++) {
- if ( cmp_address(&(sainfo->nodes[i]), node) == 0 ) return i; /* it is in the array */
- }
-
- if (i >= MAX_NUM_NODES) {
- return NODE_OVERFLOW;
- } else {
- sainfo->num_nodes++;
- copy_address(&(sainfo->nodes[i]), node);
- return i;
- }
-}
-
-struct sainfo_counter {
- seq_analysis_info_t *sainfo;
- int num_items;
-};
-
-static void sequence_analysis_get_nodes_item_proc(gpointer data, gpointer user_data)
-{
- seq_analysis_item_t *gai = (seq_analysis_item_t *)data;
- struct sainfo_counter *sc = (struct sainfo_counter *)user_data;
- if (gai->display) {
- (sc->num_items)++;
- gai->src_node = add_or_get_node(sc->sainfo, &(gai->src_addr));
- gai->dst_node = add_or_get_node(sc->sainfo, &(gai->dst_addr));
- }
-}
-
-/* Get the nodes from the list */
-/****************************************************************************/
-int
-sequence_analysis_get_nodes(seq_analysis_info_t *sainfo)
-{
- struct sainfo_counter sc = {sainfo, 0};
-
- /* Fill the node array */
- g_queue_foreach(sainfo->items, sequence_analysis_get_nodes_item_proc, &sc);
-
- return sc.num_items;
-}
-
-/* Free the node address list */
-/****************************************************************************/
-void
-sequence_analysis_free_nodes(seq_analysis_info_t *sainfo)
-{
- int i;
-
- for (i=0; i<MAX_NUM_NODES; i++) {
- free_address(&sainfo->nodes[i]);
- }
- sainfo->num_nodes = 0;
-}
-
/****************************************************************************/
gboolean
sequence_analysis_dump_to_file(const char *pathname, seq_analysis_info_t *sainfo, capture_file *cf, unsigned int first_node)
diff --git a/ui/tap-sequence-analysis.h b/ui/tap-sequence-analysis.h
index 39b09839f2..f6d6d3267a 100644
--- a/ui/tap-sequence-analysis.h
+++ b/ui/tap-sequence-analysis.h
@@ -36,71 +36,12 @@
#include "cfile.h"
#include "epan/address.h"
+#include <epan/sequence_analysis.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
-#define MAX_NUM_NODES 40
-
-typedef enum seq_analysis_type_ {
- SEQ_ANALYSIS_ANY,
- SEQ_ANALYSIS_TCP,
- SEQ_ANALYSIS_VOIP
-} seq_analysis_type;
-
-/** defines an entry for the graph analysis */
-typedef struct _seq_analysis_item {
- guint32 frame_number;
- address src_addr;
- guint16 port_src;
- address dst_addr;
- guint16 port_dst;
- gchar *frame_label; /**< the label on top of the arrow */
- gchar *time_str; /**< timestamp */
- gchar *comment; /**< a comment that appears at the right of the graph */
- guint16 conv_num; /**< The conversation number. Used for coloring VoIP calls. */
- unsigned fg_color; /**< Foreground color, 0xRRGGBB. Qt only. */
- unsigned bg_color; /**< Background color, 0xRRGGBB. Qt only. */
- gboolean has_color_filter; /**< Set if packet has color filter. Qt only. */
- gboolean display; /**< indicate if the packet is displayed or not in the graph */
- guint src_node; /**< this is used by graph_analysis.c to identify the node */
- guint dst_node; /**< a node is an IP address that will be displayed in columns */
- guint16 line_style; /**< the arrow line width in pixels*/
- gchar *protocol; /**< the label of the protocol defined in the IP packet */
-} seq_analysis_item_t;
-
-/** defines the graph analysis structure */
-typedef struct _seq_analysis_info {
- seq_analysis_type type; /**< sequence type */
- gboolean all_packets; /**< all packets vs only displayed */
- gboolean any_addr; /**< any addr (DL+net) vs net-only */
- int nconv; /**< number of conversations in the list */
- GQueue* items; /**< list of seq_analysis_info_t */
- GHashTable *ht; /**< hash table of seq_analysis_info_t */
- address nodes[MAX_NUM_NODES]; /**< horizontal node list */
- guint32 num_nodes; /**< actual number of nodes */
-} seq_analysis_info_t;
-
-#if 0
-#define SEQ_ANALYSIS_DEBUG(...) { \
- char *SEQ_ANALYSIS_DEBUG_MSG = g_strdup_printf(__VA_ARGS__); \
- g_warning("sequence analysis: %s:%d %s", G_STRFUNC, __LINE__, SEQ_ANALYSIS_DEBUG_MSG); \
- g_free(SEQ_ANALYSIS_DEBUG_MSG); \
-}
-#else
-#define SEQ_ANALYSIS_DEBUG()
-#endif
-
-/** Create and initialize a seq_analysis_info_t struct
- * @return A pointer to a newly allocated seq_analysis_info_t struct.
- */
-seq_analysis_info_t *sequence_analysis_info_new(void);
-
-/** Free a seq_analysis_info_t struct.
- * @param sainfo A pointer to the seq_analysis_info_t struct to be freed.
- */
-void sequence_analysis_info_free(seq_analysis_info_t * sainfo);
-
/** Fill in the segment list for sequence analysis
*
* @param cf Capture file to scan
@@ -108,27 +49,6 @@ void sequence_analysis_info_free(seq_analysis_info_t * sainfo);
*/
void sequence_analysis_list_get(capture_file *cf, seq_analysis_info_t *sainfo);
-void sequence_analysis_list_sort(seq_analysis_info_t *sainfo);
-
-/** Free the segment list
- *
- * @param sainfo Sequence analysis information.
- */
-void sequence_analysis_list_free(seq_analysis_info_t *sainfo);
-
-/** Fill in the node address list
- *
- * @param sainfo Sequence analysis information.
- * @return The number of transaction items (not nodes) processed.
- */
-int sequence_analysis_get_nodes(seq_analysis_info_t *sainfo);
-
-/** Free the node address list
- *
- * @param sainfo Sequence analysis information.
- */
-void sequence_analysis_free_nodes(seq_analysis_info_t *sainfo);
-
/** Write an ASCII version of the sequence diagram to a file.
*
* @param pathname Pathname of the file to write.