replace all appearances of BUTTON_NEW_FROM_STOCK with GTK2's gtk_button_new_from_stock
[obnox/wireshark/wip.git] / gtk / flow_graph.c
1 /* flow_graph.c
2  * $Id$
3  * Allows to display a flow graph of the currently displayed packets
4  *
5  * Copyright 2004, Ericsson , Spain
6  * By Francisco Alcoba <francisco.alcoba@ericsson.com>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation,  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include "register.h"
32
33 #include "globals.h"
34 #include "epan/filesystem.h"
35
36 #include "graph_analysis.h"
37 #include <epan/stat_cmd_args.h>
38 #include "../stat_menu.h"
39 #include "gui_stat_menu.h"
40 #include "dlg_utils.h"
41 #include "gui_utils.h"
42 #include "compat_macros.h"
43 #include "gtkglobals.h"
44
45 #include "simple_dialog.h"
46
47 #include <epan/to_str.h>
48 #include <epan/tap.h>
49 #include <epan/emem.h>
50 #include <epan/dissectors/packet-tcp.h>
51
52 #include <string.h>
53 #include <epan/strutil.h>
54
55 #define DISPLAYED 0
56 #define ALL 1
57 #define GENERAL 0
58 #define TCP 1
59 #define SRCDST 0
60 #define NET_SRCDST 1
61
62 static int type_of_packets = DISPLAYED;
63 static int type_of_flow = GENERAL;
64 static int node_addr_type = SRCDST;
65
66 static int tap_identifier;
67 static gboolean have_frame_tap_listener=FALSE;
68 static gboolean have_tcp_tap_listener=FALSE;
69 static graph_analysis_info_t *graph_analysis = NULL;
70 static graph_analysis_data_t *graph_analysis_data;
71
72 static GtkWidget *flow_graph_dlg = NULL;
73
74 static GtkWidget *select_all_rb;
75 static GtkWidget *select_displayed_rb;
76 static GtkWidget *select_general_rb;
77 static GtkWidget *select_tcp_rb;
78 static GtkWidget *src_dst_rb;
79 static GtkWidget *net_src_dst_rb;
80
81 void flow_graph_data_init(void);
82
83
84 /****************************************************************************/
85 /* free up memory and initialize the pointers */
86
87 static void flow_graph_reset(void *ptr _U_)
88 {
89
90         graph_analysis_item_t *graph_item;
91         
92         GList* list;
93
94         if (graph_analysis !=NULL){
95
96                 /* free the graph data items */
97                 list = g_list_first(graph_analysis->list);
98                 while (list)
99                 {
100                         graph_item = list->data;
101                         g_free(graph_item->frame_label);
102                         g_free(graph_item->comment);
103                         g_free(list->data);
104                         list = g_list_next(list);
105                 }
106                 g_list_free(graph_analysis->list);
107                 graph_analysis->nconv = 0;
108                 graph_analysis->list = NULL;
109         }
110         return;
111 }
112
113 /****************************************************************************/
114 void flow_graph_data_init(void) {
115         graph_analysis = g_malloc(sizeof(graph_analysis_info_t));
116         graph_analysis->nconv = 0;
117         graph_analysis->list = NULL;
118         return;
119 }
120
121 /* XXX just copied from gtk/rpc_stat.c */
122 void protect_thread_critical_region(void);
123 void unprotect_thread_critical_region(void);
124
125 /****************************************************************************/
126 static void
127 remove_tap_listener_flow_graph(void)
128 {
129         protect_thread_critical_region();
130         remove_tap_listener(&(tap_identifier));
131         unprotect_thread_critical_region();
132
133         have_frame_tap_listener=FALSE;
134         have_tcp_tap_listener=FALSE;
135 }
136
137
138 /****************************************************************************/
139 /* CALLBACKS                                                                */
140 /****************************************************************************/
141 static void
142 flow_graph_on_destroy(GtkObject *object _U_, gpointer user_data _U_)
143 {
144         /* remove_tap_listeners */
145         remove_tap_listener_flow_graph();
146
147         /* Clean up memory used by tap */
148         flow_graph_reset(NULL);
149
150         /* Note that we no longer have a "Flow Graph" dialog box. */
151         flow_graph_dlg = NULL;
152 }
153
154         
155 /****************************************************************************/
156 static void
157 toggle_select_all(GtkWidget *widget _U_, gpointer user_data _U_)
158 {
159   /* is the button now active? */
160         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_all_rb))) {
161                 type_of_packets = ALL;
162         }
163 }
164
165 /****************************************************************************/
166 static void
167 toggle_select_displayed(GtkWidget *widget _U_, gpointer user_data _U_)
168 {
169   /* is the button now active? */
170         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_displayed_rb))) {
171                 type_of_packets = DISPLAYED;
172         }
173 }
174
175 /****************************************************************************/
176 static void
177 toggle_select_general(GtkWidget *widget _U_, gpointer user_data _U_)
178 {
179   /* is the button now active? */
180         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_general_rb))) {
181                 type_of_flow = GENERAL;
182         }
183 }
184
185 /****************************************************************************/
186 static void
187 toggle_select_tcp(GtkWidget *widget _U_, gpointer user_data _U_)
188 {
189   /* is the button now active? */
190         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(select_tcp_rb))) {
191                 type_of_flow = TCP;
192         }
193 }
194
195 /****************************************************************************/
196 static void
197 toggle_select_srcdst(GtkWidget *widget _U_, gpointer user_data _U_)
198 {
199   /* is the button now active? */
200         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(src_dst_rb))) {
201                 node_addr_type = SRCDST;
202         }
203 }
204
205 /****************************************************************************/
206 static void
207 toggle_select_netsrcdst(GtkWidget *widget _U_, gpointer user_data _U_)
208 {
209   /* is the button now active? */
210         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(net_src_dst_rb))) {
211                 node_addr_type = NET_SRCDST;
212         }
213 }
214
215 /****************************************************************************/
216 /* Add a new frame into the graph */
217 static int flow_graph_frame_add_to_graph(packet_info *pinfo)
218 {
219         graph_analysis_item_t *gai;
220         int i;
221         gchar *protocol;
222         gchar *colinfo;
223         
224         protocol=NULL;
225         colinfo=NULL;
226
227         if (node_addr_type == NET_SRCDST) {
228                 if (pinfo->net_src.type!=AT_NONE && pinfo->net_dst.type!=AT_NONE) {
229                         gai = g_malloc(sizeof(graph_analysis_item_t));
230                         COPY_ADDRESS(&(gai->src_addr),&(pinfo->net_src));
231                         COPY_ADDRESS(&(gai->dst_addr),&(pinfo->net_dst));
232                 }
233                 else return 0;
234                 
235         } else {
236                 if (pinfo->src.type!=AT_NONE && pinfo->dst.type!=AT_NONE) {
237                         gai = g_malloc(sizeof(graph_analysis_item_t));
238                         COPY_ADDRESS(&(gai->src_addr),&(pinfo->src));
239                         COPY_ADDRESS(&(gai->dst_addr),&(pinfo->dst));
240                 }
241                 else return 0;
242         }
243
244         gai->frame_num = pinfo->fd->num;
245         gai->time= nstime_to_sec(&pinfo->fd->rel_ts);
246
247         gai->port_src=pinfo->srcport;
248         gai->port_dst=pinfo->destport;
249         gai->comment=NULL;
250         gai->frame_label=NULL;
251
252         if (gai->comment!=NULL){
253                 g_free(gai->comment);
254         }
255         if (gai->frame_label!=NULL){
256                 g_free(gai->frame_label);
257         }
258
259
260         if(pinfo->cinfo) {
261                 if (pinfo->cinfo->col_first[COL_INFO]>=0){
262                         
263                         for (i = pinfo->cinfo->col_first[COL_INFO]; i <= pinfo->cinfo->col_last[COL_INFO]; i++) {
264                                 if (pinfo->cinfo->fmt_matx[i][COL_INFO]) {
265                                         colinfo = g_strdup(pinfo->cinfo->col_data[i]);
266                                 }
267                         }
268                 }
269                 
270                 if (pinfo->cinfo->col_first[COL_PROTOCOL]>=0){
271                         
272                         for (i = pinfo->cinfo->col_first[COL_PROTOCOL]; i <= pinfo->cinfo->col_last[COL_PROTOCOL]; i++) {
273                                 if (pinfo->cinfo->fmt_matx[i][COL_PROTOCOL]) {
274                                         protocol = g_strdup(pinfo->cinfo->col_data[i]);
275                                         
276                                 }
277                         }
278                 }
279         }
280
281         if (colinfo != NULL) {
282                 if (protocol != NULL) {
283                         gai->frame_label = g_strdup_printf("%.19s", colinfo);
284                         gai->comment = g_strdup_printf("%s: %s", protocol, colinfo);
285                 } else {
286                         gai->frame_label = g_strdup_printf("%.19s", colinfo);
287                         gai->comment = g_strdup_printf("%s", colinfo);
288                 }
289         } else {
290                 /* This will probably never happen...*/
291                 if (protocol != NULL) {
292                         gai->frame_label = g_strdup_printf("%.19s", protocol);
293                         gai->comment = g_strdup_printf("%s", protocol);
294                 } else {
295                         gai->frame_label = NULL;
296                         gai->comment = NULL;
297                 }
298         }
299  
300         if (protocol!=NULL){
301                 g_free(protocol);
302         }
303         if (colinfo!=NULL){
304                 g_free(colinfo);
305         }
306
307         gai->line_style=1;
308         gai->conv_num=0;
309         gai->display=TRUE;
310
311         graph_analysis->list = g_list_append(graph_analysis->list, gai);
312
313         return 1;
314
315 }
316
317 /****************************************************************************/
318 /* Add a new tcp frame into the graph */
319 static int flow_graph_tcp_add_to_graph(packet_info *pinfo, const struct tcpheader *tcph)
320 {
321   graph_analysis_item_t *gai;
322   /* copied from packet-tcp */
323   const gchar *fstr[] = {"FIN", "SYN", "RST", "PSH", "ACK", "URG", "ECN", "CWR" };
324   guint i, bpos;
325   gboolean flags_found = FALSE;
326   gchar flags[64];
327
328   gai = g_malloc(sizeof(graph_analysis_item_t));
329   gai->frame_num = pinfo->fd->num;
330   gai->time= nstime_to_sec(&pinfo->fd->rel_ts);
331   if (node_addr_type == NET_SRCDST) {
332     COPY_ADDRESS(&(gai->src_addr),&(pinfo->net_src));
333     COPY_ADDRESS(&(gai->dst_addr),&(pinfo->net_dst));
334   } else {
335     COPY_ADDRESS(&(gai->src_addr),&(pinfo->src));
336     COPY_ADDRESS(&(gai->dst_addr),&(pinfo->dst));
337   }
338   gai->port_src=pinfo->srcport;
339   gai->port_dst=pinfo->destport;
340
341   flags[0] = '\0';
342   for (i = 0; i < 8; i++) {
343     bpos = 1 << i;
344     if (tcph->th_flags & bpos) {
345       if (flags_found) {
346         g_strlcat(flags, ", ", 64);
347       }
348       g_strlcat(flags, fstr[i], 64);
349       flags_found = TRUE;
350     }
351   }
352   if (flags[0] == '\0') {
353     g_snprintf (flags, 64, "<None>");
354   }
355
356   if ((tcph->th_have_seglen)&&(tcph->th_seglen!=0)){
357     gai->frame_label = g_strdup_printf("%s - Len: %u",flags, tcph->th_seglen);
358   }
359   else{
360     gai->frame_label = g_strdup(flags);
361   }
362
363   gai->comment = g_strdup_printf("Seq = %u Ack = %u",tcph->th_seq, tcph->th_ack);
364
365   gai->line_style=1;
366   gai->conv_num=0;
367   gai->display=TRUE;
368
369   graph_analysis->list = g_list_append(graph_analysis->list, gai);
370
371   return 1;
372
373 }
374
375
376
377 /****************************************************************************/
378 /* whenever a frame packet is seen by the tap listener */
379 static int 
380 flow_graph_frame_packet( void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *dummy _U_)
381 {
382
383         if ((type_of_packets == ALL)||(pinfo->fd->flags.passed_dfilter==1)){
384                 flow_graph_frame_add_to_graph(pinfo);  
385         }
386         
387         return 1;
388 }
389
390 /****************************************************************************/
391 /* whenever a TCP packet is seen by the tap listener */
392 static int 
393 flow_graph_tcp_packet( void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *tcp_info)
394 {
395         const struct tcpheader *tcph = tcp_info;
396
397         if ((type_of_packets == ALL)||(pinfo->fd->flags.passed_dfilter==1)){
398                 flow_graph_tcp_add_to_graph(pinfo,tcph);  
399         }
400         
401         return 1;
402 }
403
404
405 static void flow_graph_packet_draw(void *prs _U_)
406 {
407         return; 
408 }
409
410 /****************************************************************************/
411 static void
412 flow_graph_on_ok                    (GtkButton       *button _U_,
413                                         gpointer         user_data)
414 {
415
416         if ((have_frame_tap_listener==TRUE)
417                 ||(have_tcp_tap_listener==TRUE))
418         { 
419                 /* remove_tap_listeners */
420                 remove_tap_listener_flow_graph();
421         }
422         
423         /* Scan for displayed packets (retap all packets) */
424
425         if (type_of_flow == GENERAL){
426                 /* Register the tap listener */
427
428                 if(have_frame_tap_listener==FALSE)
429                 {
430                         /* don't register tap listener, if we have it already */
431                         register_tap_listener("frame", &tap_identifier, NULL,
432                                 flow_graph_reset, 
433                                 flow_graph_frame_packet, 
434                                 flow_graph_packet_draw
435                                 );
436                         have_frame_tap_listener=TRUE;
437                 }
438
439                 cf_retap_packets(&cfile, TRUE);
440         }
441         else if (type_of_flow == TCP){
442         /* Register the tap listener */
443
444                 if(have_tcp_tap_listener==FALSE)
445                 {
446                         /* don't register tap listener, if we have it already */
447                         register_tap_listener("tcp", &tap_identifier, NULL,
448                                 flow_graph_reset, 
449                                 flow_graph_tcp_packet, 
450                                 flow_graph_packet_draw
451                                 );
452                         have_tcp_tap_listener=TRUE;
453                 }
454
455                 cf_retap_packets(&cfile, FALSE);
456         }
457
458         if (graph_analysis_data->dlg.window != NULL){ /* if we still have a window */
459                 graph_analysis_update(graph_analysis_data);             /* refresh it xxx */
460         }
461         else{
462                 graph_analysis_data->dlg.parent_w = user_data;
463                 graph_analysis_create(graph_analysis_data);
464         }
465
466 }
467
468
469 /****************************************************************************/
470 /* INTERFACE                                                                */
471 /****************************************************************************/
472
473 static void flow_graph_dlg_create (void)
474 {
475         
476         GtkWidget *flow_graph_dlg_w;
477         GtkWidget *main_vb;
478         GtkWidget *hbuttonbox;
479         GtkWidget *bt_close, *bt_ok;
480 #if 0
481         GtkWidget *top_label = NULL;
482 #endif
483         GtkWidget *flow_type_fr, *range_fr, *range_tb, *flow_type_tb, *node_addr_fr, *node_addr_tb;
484
485
486         GtkTooltips *tooltips = gtk_tooltips_new();
487
488         flow_graph_dlg_w=window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Flow Graph");
489
490         gtk_window_set_default_size(GTK_WINDOW(flow_graph_dlg_w), 350, 150);
491
492         main_vb = gtk_vbox_new (FALSE, 0);
493         gtk_container_add(GTK_CONTAINER(flow_graph_dlg_w), main_vb);
494         gtk_container_set_border_width (GTK_CONTAINER (main_vb), 12);
495
496 #if 0
497         top_label = gtk_label_new ("Choose packets to include in the graph");
498         gtk_box_pack_start (GTK_BOX (main_vb), top_label, FALSE, FALSE, 8);
499 #endif
500         
501         gtk_widget_show(flow_graph_dlg_w);
502
503         /*** Packet range frame ***/
504         range_fr = gtk_frame_new("Choose packets");
505         gtk_box_pack_start(GTK_BOX(main_vb), range_fr, FALSE, FALSE, 0);
506
507     range_tb = gtk_table_new(4, 4, FALSE);
508     gtk_container_border_width(GTK_CONTAINER(range_tb), 5);
509         gtk_container_add(GTK_CONTAINER(range_fr), range_tb);
510
511         /* Process all packets */
512         select_all_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(NULL, "_All packets", accel_group);
513         gtk_tooltips_set_tip (tooltips, select_all_rb, 
514                 ("Process all packets"), NULL);
515         SIGNAL_CONNECT(select_all_rb, "toggled", toggle_select_all, NULL);
516         gtk_table_attach_defaults(GTK_TABLE(range_tb), select_all_rb, 0, 1, 0, 1);
517         if (type_of_packets == ALL) {
518                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_all_rb),TRUE);
519         }
520         gtk_widget_show(select_all_rb);
521
522         /* Process displayed packets */
523         select_displayed_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(select_all_rb, "_Displayed packets", accel_group);
524         gtk_tooltips_set_tip (tooltips, select_displayed_rb, 
525                 ("Process displayed packets"), NULL);
526         SIGNAL_CONNECT(select_displayed_rb, "toggled", toggle_select_displayed, NULL);
527         gtk_table_attach_defaults(GTK_TABLE(range_tb), select_displayed_rb, 1, 2, 0, 1);
528         if (type_of_packets == DISPLAYED) {
529                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_displayed_rb),TRUE);
530         }
531         gtk_widget_show(select_displayed_rb);
532
533         gtk_widget_show(range_tb);
534
535         gtk_widget_show(range_fr);
536
537         /*** Flow type frame ***/
538         flow_type_fr = gtk_frame_new("Choose flow type");
539         gtk_box_pack_start(GTK_BOX(main_vb), flow_type_fr, FALSE, FALSE, 0);
540
541     flow_type_tb = gtk_table_new(4, 4, FALSE);
542     gtk_container_border_width(GTK_CONTAINER(flow_type_tb), 5);
543         gtk_container_add(GTK_CONTAINER(flow_type_fr), flow_type_tb);
544
545         /* General information */
546         select_general_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(NULL, "_General flow", accel_group);
547         gtk_tooltips_set_tip (tooltips, select_general_rb, 
548                 ("Show all packets, with general information"), NULL);
549         SIGNAL_CONNECT(select_general_rb, "toggled", toggle_select_general, NULL);
550         gtk_table_attach_defaults(GTK_TABLE(flow_type_tb), select_general_rb, 0, 1, 0, 1);
551         if (type_of_flow == GENERAL) {
552                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_general_rb),TRUE);
553         }
554         gtk_widget_show(select_general_rb);
555
556         /* TCP specific information */
557         select_tcp_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(select_general_rb, "_TCP flow", accel_group);
558         gtk_tooltips_set_tip (tooltips, select_tcp_rb, 
559                 ("Show only TCP packets, with TCP specific information"), NULL);
560         SIGNAL_CONNECT(select_tcp_rb, "toggled", toggle_select_tcp, NULL);
561         gtk_table_attach_defaults(GTK_TABLE(flow_type_tb), select_tcp_rb, 1, 2, 0, 1);
562         if (type_of_flow == TCP) {
563                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(select_tcp_rb),TRUE);
564         }
565
566         gtk_widget_show(select_tcp_rb);
567
568         gtk_widget_show(flow_type_tb);
569         gtk_widget_show(flow_type_fr);
570
571         /*** Node address type frame ***/
572         node_addr_fr = gtk_frame_new("Choose node address type");
573         gtk_box_pack_start(GTK_BOX(main_vb), node_addr_fr, FALSE, FALSE, 0);
574
575     node_addr_tb = gtk_table_new(4, 4, FALSE);
576     gtk_container_border_width(GTK_CONTAINER(node_addr_tb), 5);
577         gtk_container_add(GTK_CONTAINER(node_addr_fr), node_addr_tb);
578
579         /* Source / Dest address */
580         src_dst_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(NULL, "_Standard source/destination addresses", accel_group);
581         gtk_tooltips_set_tip (tooltips, src_dst_rb, 
582                 ("Nodes in the diagram are identified with source and destination addresses"), NULL);
583         SIGNAL_CONNECT(src_dst_rb, "toggled", toggle_select_srcdst, NULL);
584         gtk_table_attach_defaults(GTK_TABLE(node_addr_tb), src_dst_rb, 0, 1, 0, 1);
585         if (node_addr_type == SRCDST) {
586                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(src_dst_rb),TRUE);
587         }
588         gtk_widget_show(src_dst_rb);
589
590         /* Network source / dest address */
591         net_src_dst_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(src_dst_rb, "_Network source/destination addresses", accel_group);
592         gtk_tooltips_set_tip (tooltips, net_src_dst_rb, 
593                 ("Nodes in the diagram are identified with network source and destination addresses"), NULL);
594         SIGNAL_CONNECT(net_src_dst_rb, "toggled", toggle_select_netsrcdst, NULL);
595         gtk_table_attach_defaults(GTK_TABLE(node_addr_tb), net_src_dst_rb, 1, 2, 0, 1);
596         if (node_addr_type == NET_SRCDST) {
597                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(net_src_dst_rb),TRUE);
598         }
599
600         gtk_widget_show(net_src_dst_rb);
601
602         gtk_widget_show(node_addr_tb);
603         gtk_widget_show(node_addr_fr);
604
605         /* button row */
606         hbuttonbox = gtk_hbutton_box_new ();
607         gtk_box_pack_start (GTK_BOX (main_vb), hbuttonbox, FALSE, FALSE, 0);
608         gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_SPREAD);
609         gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 30);
610
611         bt_ok = gtk_button_new_from_stock(GTK_STOCK_OK);
612         gtk_container_add(GTK_CONTAINER(hbuttonbox), bt_ok);
613         gtk_tooltips_set_tip (tooltips, bt_ok, "Show the flow graph", NULL);
614         SIGNAL_CONNECT(bt_ok, "clicked", flow_graph_on_ok, flow_graph_dlg_w);
615         gtk_widget_show(bt_ok);
616
617         bt_close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
618         gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_close);
619         GTK_WIDGET_SET_FLAGS(bt_close, GTK_CAN_DEFAULT);
620         gtk_tooltips_set_tip (tooltips, bt_close, "Close this dialog", NULL);
621         window_set_cancel_button(flow_graph_dlg_w, bt_close, window_cancel_button_cb);
622
623         SIGNAL_CONNECT(flow_graph_dlg_w, "delete_event", window_delete_event_cb, NULL);
624         SIGNAL_CONNECT(flow_graph_dlg_w, "destroy", flow_graph_on_destroy, NULL);
625
626         gtk_widget_show_all(flow_graph_dlg_w);
627         window_present(flow_graph_dlg_w);
628
629         flow_graph_dlg = flow_graph_dlg_w;
630 }       
631
632 /****************************************************************************/
633 /* PUBLIC                                                                   */
634 /****************************************************************************/
635
636 /* init function for tap */
637 static void
638 flow_graph_init_tap(const char *dummy _U_, void* userdata _U_)
639 {
640
641         /* initialize graph items store */
642         flow_graph_data_init();
643         
644         /* init the Graph Analysys */
645         graph_analysis_data = graph_analysis_init();
646         graph_analysis_data->graph_info = graph_analysis;
647
648         /* create dialog box if necessary */
649         if (flow_graph_dlg == NULL) {
650                 flow_graph_dlg_create();
651         } else {
652                 /* There's already a dialog box; reactivate it. */
653                 reactivate_window(flow_graph_dlg);
654         }
655
656 }
657
658
659 /****************************************************************************/
660 /* entry point when called via the GTK menu */
661 static void flow_graph_launch(GtkWidget *w _U_, gpointer data _U_)
662 {
663         flow_graph_init_tap("",NULL);
664 }
665
666 /****************************************************************************/
667 void
668 register_tap_listener_flow_graph(void)
669 {
670         register_stat_cmd_arg("flow_graph",flow_graph_init_tap,NULL);
671         register_stat_menu_item("Flo_w Graph...", REGISTER_STAT_GROUP_NONE,
672             flow_graph_launch, NULL, NULL, NULL);
673             
674 }
675