Canonicalize the line endings, and set svn:eol-style to native to keep
[obnox/wireshark/wip.git] / gtk / sip_stat.c
index ade0c71acfc54349f80e7923cbfc90272728c749..a50e57a56690fb9b3c54d3a494c115597c07bb25 100644 (file)
@@ -1,7 +1,7 @@
 /* sip_stat.c
  * sip_stat   2004 Martin Mathieson
  *
- * $Id: sip_stat.c,v 1.3 2004/03/30 18:55:47 guy Exp $
+ * $Id$
  * Copied from http_stat.c
  *
  * Ethereal - Network traffic analyzer
@@ -40,7 +40,7 @@
 #include "dlg_utils.h"
 #include "tap.h"
 #include "../register.h"
-#include "../packet-sip.h"
+#include <epan/dissectors/packet-sip.h>
 #include "../globals.h"
 #include "compat_macros.h"
 #include "../tap_dfilter_dlg.h"
@@ -55,7 +55,9 @@ typedef struct _sip_stats_t {
     GHashTable  *hash_responses;
     GHashTable  *hash_requests;
     guint32        packets;        /* number of sip packets, including continuations */
+    guint32     resent_packets;
     GtkWidget   *packets_label;
+    GtkWidget   *resent_label;
 
     GtkWidget   *request_box;          /* container for INVITE, ... */
 
@@ -328,6 +330,7 @@ sipstat_reset(void *psp)
     if (sp)
     {
        sp->packets = 0;
+        sp->resent_packets = 0;
         g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_reset_hash_responses, NULL);
         g_hash_table_foreach(sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
     }
@@ -343,6 +346,13 @@ sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void
     /* Total number of packets, including continuation packets */
     sp->packets++;
 
+    /* Update resent count if flag set */
+    if (value->resend)
+    {
+        sp->resent_packets++;
+    }
+
+
     /* Looking at both requests and responses */
     if (value->response_code != 0)
     {
@@ -445,6 +455,11 @@ sipstat_draw(void *psp)
                 "SIP stats (%d packets)", sp->packets);
     gtk_label_set(GTK_LABEL(sp->packets_label), string_buff);
 
+    /* Set resend count label */
+    g_snprintf(string_buff, sizeof(string_buff),
+                "(%d resent packets)", sp->resent_packets);
+    gtk_label_set(GTK_LABEL(sp->resent_label), string_buff);
+
     /* Draw responses and requests from their tables */
     g_hash_table_foreach(sp->hash_responses, (GHFunc)sip_draw_hash_responses, NULL);
     g_hash_table_foreach(sp->hash_requests,  (GHFunc)sip_draw_hash_requests, NULL);
@@ -480,6 +495,7 @@ win_destroy_cb(GtkWindow *win _U_, gpointer data)
     g_free(sp);
 }
 
+
 /* Create a new instance of gtk_sipstat. */
 static void
 gtk_sipstat_init(char *optarg)
@@ -492,6 +508,8 @@ gtk_sipstat_init(char *optarg)
                *informational_fr, *success_fr, *redirection_fr,
                *client_errors_fr, *server_errors_fr, *global_failures_fr,
                *request_fr;
+    GtkWidget  *bt_close;
+    GtkWidget  *bbox;
 
 
     if (strncmp (optarg, "sip,stat,", 9) == 0)
@@ -507,6 +525,7 @@ gtk_sipstat_init(char *optarg)
 
     /* Create sip stats window structure */
     sp = g_malloc(sizeof(sipstat_t));
+    sp->win = window_new(GTK_WINDOW_TOPLEVEL, "sip-stat");
 
     /* Set title to include any filter given */
     if (filter)
@@ -520,102 +539,81 @@ gtk_sipstat_init(char *optarg)
         title = g_strdup("SIP statistics");
     }
 
-    /* Create underlying window */
-    sp->win = window_new(GTK_WINDOW_TOPLEVEL, title);
+    gtk_window_set_title(GTK_WINDOW(sp->win), title);
     g_free(title);
 
-    /* Set destroy callback for underlying window */
-    SIGNAL_CONNECT(sp->win, "destroy", win_destroy_cb, sp);
-
 
     /* Create container for all widgets */
-    main_vb = gtk_vbox_new(FALSE, 10);
-    gtk_container_border_width(GTK_CONTAINER(main_vb), 10);
+    main_vb = gtk_vbox_new(FALSE, 12);
+    gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
     gtk_container_add(GTK_CONTAINER(sp->win), main_vb);
-    gtk_widget_show(main_vb);
 
     /* Initialise & show number of packets */
     sp->packets = 0;
     sp->packets_label = gtk_label_new("SIP stats (0 SIP packets)");
     gtk_container_add(GTK_CONTAINER(main_vb), sp->packets_label);
-    gtk_widget_show(sp->packets_label);
+
+    sp->resent_packets = 0;
+    sp->resent_label = gtk_label_new("(0 resent packets)");
+    gtk_container_add(GTK_CONTAINER(main_vb), sp->resent_label);
+    gtk_widget_show(sp->resent_label);
 
 
     /* Informational response frame */
     informational_fr = gtk_frame_new("Informational  SIP 1xx");
     gtk_container_add(GTK_CONTAINER(main_vb), informational_fr);
-    gtk_widget_show(informational_fr);
 
     /* Information table (within that frame) */
     sp->informational_table = gtk_table_new(0, 2, FALSE);
     gtk_container_add(GTK_CONTAINER(informational_fr), sp->informational_table);
-    gtk_widget_show(sp->informational_table);
-
 
     /* Success table and frame */
     success_fr = gtk_frame_new ("Success         SIP 2xx");
     gtk_container_add(GTK_CONTAINER(main_vb), success_fr);
-    gtk_widget_show(success_fr);
 
     sp->success_table = gtk_table_new(0, 2, FALSE);
     gtk_container_add(GTK_CONTAINER(success_fr), sp->success_table);
-    gtk_widget_show(sp->success_table);
-
 
     /* Redirection table and frame */
     redirection_fr = gtk_frame_new     ("Redirection     SIP 3xx");
     gtk_container_add(GTK_CONTAINER(main_vb), redirection_fr);
-    gtk_widget_show(redirection_fr);
 
     sp->redirection_table = gtk_table_new(0, 2, FALSE);
     gtk_container_add(GTK_CONTAINER(redirection_fr), sp->redirection_table);
-    gtk_widget_show(sp->redirection_table);
-
 
     /* Client Errors table and frame */
     client_errors_fr = gtk_frame_new("Client errors  SIP 4xx");
     gtk_container_add(GTK_CONTAINER(main_vb), client_errors_fr);
-    gtk_widget_show(client_errors_fr);
 
     sp->client_error_table = gtk_table_new(0, 2, FALSE);
     gtk_container_add(GTK_CONTAINER(client_errors_fr), sp->client_error_table);
-    gtk_widget_show(sp->client_error_table);
-
 
     /* Server Errors table and frame */
     server_errors_fr = gtk_frame_new("Server errors  SIP 5xx");
     gtk_container_add(GTK_CONTAINER(main_vb), server_errors_fr);
-    gtk_widget_show(server_errors_fr);
 
     sp->server_errors_table = gtk_table_new(0, 2, FALSE);
     gtk_container_add(GTK_CONTAINER(server_errors_fr), sp->server_errors_table);
-    gtk_widget_show(sp->server_errors_table);
-
 
     /* Global Failures table and frame */
     global_failures_fr = gtk_frame_new("Global failures  SIP 6xx");
     gtk_container_add(GTK_CONTAINER(main_vb), global_failures_fr);
-    gtk_widget_show(global_failures_fr);
 
     sp->global_failures_table = gtk_table_new(0, 2, FALSE);
     gtk_container_add(GTK_CONTAINER(global_failures_fr), sp->global_failures_table);
-    gtk_widget_show(sp->global_failures_table);
 
 
     /* Separator between requests and responses */
     separator = gtk_hseparator_new();
     gtk_container_add(GTK_CONTAINER(main_vb), separator);
 
-
     /* Request table and frame */
     request_fr = gtk_frame_new("List of request methods");
     gtk_container_add(GTK_CONTAINER(main_vb), request_fr);
     gtk_container_border_width(GTK_CONTAINER(request_fr), 0);
-    gtk_widget_show(request_fr);
 
     sp->request_box = gtk_vbox_new(FALSE, 10);
     gtk_container_add(GTK_CONTAINER(request_fr), sp->request_box);
-    gtk_widget_show(sp->request_box);
 
 
     /* Register this tap listener now */
@@ -635,8 +633,20 @@ gtk_sipstat_init(char *optarg)
         return;
     }
 
+       /* Button row. */
+    bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
+    gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
+
+    bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
+    window_set_cancel_button(sp->win, bt_close, window_cancel_button_cb);
+
+    SIGNAL_CONNECT(sp->win, "delete_event", window_delete_event_cb, NULL);
+    SIGNAL_CONNECT(sp->win, "destroy", win_destroy_cb, sp);
+
     /* Display up-to-date contents */
     gtk_widget_show_all(sp->win);
+    window_present(sp->win);
+
     sip_init_hash(sp);
     retap_packets(&cfile);
 }