Add PTREE_FINFO and use PITEM_FINFO when possible.
[obnox/wireshark/wip.git] / gtk / expert_comp_table.c
1 /* expert_comp_table.c
2  * expert_comp_table   2005 Greg Morris
3  * Portions copied from service_response_time_table.c by Ronnie Sahlberg
4  * Helper routines common to all composite expert statistics
5  * tap.
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <string.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <math.h>
36
37 #include <gtk/gtk.h>
38
39 #include "epan/packet_info.h"
40 #include <epan/expert.h>
41
42 #include "../simple_dialog.h"
43 #include "../globals.h"
44 #include "../color.h"
45
46 #include "gtk/expert_comp_table.h"
47 #include "gtk/filter_utils.h"
48 #include "gtk/find_dlg.h"
49 #include "gtk/color_dlg.h"
50 #include "gtk/main.h"
51 #include "gtk/gui_utils.h"
52 #include "gtk/gtkglobals.h"
53 #include "gtk/webbrowser.h"
54
55
56 #define SORT_ALPHABETICAL 0
57
58 static gint
59 sort_iter_compare_func (GtkTreeModel *model,
60                         GtkTreeIter *a,
61                         GtkTreeIter *b,
62                         gpointer userdata)
63 {
64     gint sortcol = GPOINTER_TO_INT(userdata);
65     gint ret = 0;
66     switch (sortcol)
67     {
68         case SORT_ALPHABETICAL:
69         {
70             gchar *name1, *name2;
71             gtk_tree_model_get(model, a, 0, &name1, -1);
72             gtk_tree_model_get(model, b, 0, &name2, -1);
73             if (name1 == NULL || name2 == NULL)
74             {
75                 if (name1 == NULL && name2 == NULL)
76                     break; /* both equal => ret = 0 */
77                 ret = (name1 == NULL) ? -1 : 1;
78             }
79             else
80             {
81                 ret = g_ascii_strcasecmp(name1,name2);
82             }
83             g_free(name1);
84             g_free(name2);
85         }
86         break;
87         default:
88             g_return_val_if_reached(0);
89     }
90     return ret;
91 }
92
93 enum
94 {
95    GROUP_COLUMN,
96    PROTOCOL_COLUMN,
97    SUMMARY_COLUMN,
98    COUNT_COLUMN,
99    N_COLUMNS
100 };
101
102 static gint find_summary_data(error_equiv_table *err, const expert_info_t *expert_data)
103 {
104     gint i;
105     
106     /* First time thru values will be 0 */
107     if (err->num_procs==0) {
108         return -1;
109     }
110     for (i=0;i<err->num_procs;i++) {
111         if (strcmp(err->procedures[i].entries[1], expert_data->protocol) == 0 &&
112             strcmp(err->procedures[i].entries[2], expert_data->summary) == 0) {
113             return i;
114         }
115     }
116     return -1;
117 }
118
119 static void
120 error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
121 {
122     int action, type, selection;
123     error_equiv_table *err = (error_equiv_table *)callback_data;
124     char str[256];
125     const char *current_filter;
126
127     GtkTreeIter iter;
128     GtkTreeModel *model;
129     expert_info_t expert_data;
130     gchar *grp;
131
132     action=FILTER_ACTION(callback_action);
133     type=FILTER_ACTYPE(callback_action);
134
135
136     gtk_tree_selection_get_selected(err->select, &model, &iter);
137
138     gtk_tree_model_get (model, &iter, 
139                         GROUP_COLUMN,    &grp,
140                         PROTOCOL_COLUMN, &expert_data.protocol,
141                         SUMMARY_COLUMN,  &expert_data.summary,
142                         -1);
143     
144     if (strcmp(grp, "Packet:")==0) {
145         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "You cannot filter or search for packet number. Click on a valid item header.");
146         g_free(grp);
147         g_free(expert_data.protocol);
148         g_free(expert_data.summary);
149         return;
150     }
151
152     g_free(grp);
153
154     /* XXX: find_summary_data doesn't (currently) reference expert_data.group.   */
155     /*      If "group" is required, then the message from GROUP_COLUMN will need */
156     /*       to be translated to the group number (or the actual group number    */
157     /*       will also need to be stored in the TreeModel).                      */
158     selection = find_summary_data(err, &expert_data);
159
160     g_free(expert_data.protocol);
161     g_free(expert_data.summary);
162
163     if(selection>=(int)err->num_procs){
164         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No items are selected");
165         return;
166     }
167     current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
168
169     /* Some expert data doesn't pass an expert item. Without this we cannot create a filter */
170     /* But allow for searching of internet for error string */
171     if (action != 6 && action != 7) {
172         if (err->procedures[selection].fvalue_value==NULL) {
173             if (action != 2 && action != 3 && action != 4) {
174                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Wireshark cannot create a filter on this item - %s, try using find instead.", err->procedures[selection].entries[2]);
175                 return;
176             }
177         }
178         switch(type){
179         case ACTYPE_SELECTED:
180             /* if no expert item was passed */
181             if (err->procedures[selection].fvalue_value==NULL) {
182                 g_strlcpy(str, err->procedures[selection].entries[2], sizeof(str));
183             }
184             else
185             {
186                 /* expert item exists. Use it. */
187                 g_strlcpy(str, err->procedures[selection].fvalue_value, sizeof(str));
188             }
189             break;
190         case ACTYPE_NOT_SELECTED:
191             /* if no expert item was passed */
192             if (err->procedures[selection].fvalue_value==NULL) {
193                 g_snprintf(str, sizeof(str), "!%s", err->procedures[selection].entries[2]);
194             }
195             else
196             {
197                 /* expert item exists. Use it. */
198                 g_snprintf(str, sizeof(str), "!(%s)", err->procedures[selection].fvalue_value);
199             }
200             break;
201             /* the remaining cases will only exist if the expert item exists so no need to check */
202         case ACTYPE_AND_SELECTED:
203             if ((!current_filter) || (0 == strlen(current_filter)))
204                 g_strlcpy(str, err->procedures[selection].fvalue_value, sizeof(str));
205             else
206                 g_snprintf(str, sizeof(str), "(%s) && (%s)", current_filter, err->procedures[selection].fvalue_value);
207             break;
208         case ACTYPE_OR_SELECTED:
209             if ((!current_filter) || (0 == strlen(current_filter)))
210                 g_strlcpy(str, err->procedures[selection].fvalue_value, sizeof(str));
211             else
212                 g_snprintf(str, sizeof(str), "(%s) || (%s)", current_filter, err->procedures[selection].fvalue_value);
213             break;
214         case ACTYPE_AND_NOT_SELECTED:
215             if ((!current_filter) || (0 == strlen(current_filter)))
216                 g_snprintf(str, sizeof(str), "!(%s)", err->procedures[selection].fvalue_value);
217             else
218                 g_snprintf(str, sizeof(str), "(%s) && !(%s)", current_filter, err->procedures[selection].fvalue_value);
219             break;
220         case ACTYPE_OR_NOT_SELECTED:
221             if ((!current_filter) || (0 == strlen(current_filter)))
222                 g_snprintf(str, sizeof(str), "!(%s)", err->procedures[selection].fvalue_value);
223             else
224                 g_snprintf(str, sizeof(str), "(%s) || !(%s)", current_filter, err->procedures[selection].fvalue_value);
225             break;
226         default:
227             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't find menu type - %u", type);
228         }
229     }
230
231     switch(action){
232     case ACTION_MATCH:
233         main_filter_packets(&cfile, str, FALSE);
234         break;
235     case ACTION_PREPARE:
236         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
237         break;
238     case ACTION_FIND_FRAME:
239         /* When trying to perform a find without expert item, we must pass
240          * the expert string to the find window. The user might need to modify
241          * the string and click on the text search to locate the packet in question.
242          * So regardless of the type we will just bring up the find window and allow
243          * the user to modify the search criteria and options.
244          */
245         find_frame_with_filter(str);
246         break;
247     case ACTION_FIND_NEXT:
248         /* In the case of find next, if there was no expert item, then most likely the expert
249          * string was modified to locate the text inside the message. So we can't just perform
250          * a find with the expert string or we will not really be performing a find next.
251          * In an effort to allow the user to modify the string and/or continue searching, we
252          * will just present the user with the find window again with the default expert string.
253          * A better aproach would be to attempt in capturing the last find string and utilize this 
254          * with a find next/previous. Also a better approach might be to just send a <Ctl-N> keystroke.
255          */
256         if (err->procedures[selection].fvalue_value==NULL) {
257             find_frame_with_filter(str);
258         }
259         else
260         { 
261             /* We have an expert item so just continue search without find dialog. */
262             find_previous_next_frame_with_filter(str, FALSE);
263         }
264         break;
265     case ACTION_FIND_PREVIOUS:
266         /* In the case of find previous, if there was no expert item, then most likely the expert
267          * string was modified to locate the text inside the message. So we can't just perform
268          * a find with the expert string or we will not really be performing a find previous.
269          * In an effort to allow the user to modify the string and/or continue searching, we
270          * will just present the user with the find window again with the default expert string.
271          * A better aproach would be to attempt in capturing the last find string and utilize this 
272          * with a find next/previous. Also a better approach might be to just send a <Ctl-B> keystroke.
273          */
274         if (err->procedures[selection].fvalue_value==NULL) {
275             find_frame_with_filter(str);
276         }
277         else
278         { 
279             /* We have an expert item so just continue search without find dialog. */
280             find_previous_next_frame_with_filter(str, TRUE);
281         }
282         break;
283     case ACTION_COLORIZE:
284         color_display_with_filter(str);
285         break;
286     case ACTION_WEB_LOOKUP:
287         /* Lookup expert string on internet. Default search via www.google.com */
288         g_snprintf(str, sizeof(str), "http://www.google.com/search?hl=en&q=%s+'%s'", err->procedures[selection].entries[1], err->procedures[selection].entries[2]);
289         browser_open_url(str);
290         break;
291     default:
292         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't find menu action - %u", action);
293     }
294 }
295
296 static gint
297 error_show_popup_menu_cb(void *widg _U_, GdkEvent *event, error_equiv_table *err)
298 {
299         GdkEventButton *bevent = (GdkEventButton *)event;
300
301         if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
302                 gtk_menu_popup(GTK_MENU(err->menu), NULL, NULL, NULL, NULL, 
303                         bevent->button, bevent->time);
304         }
305
306         return FALSE;
307 }
308
309 static GtkItemFactoryEntry error_list_menu_items[] =
310 {
311         /* Match */
312         {"/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL,},
313         {"/Apply as Filter/Selected", NULL,
314                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_SELECTED, 0),
315                 NULL, NULL,},
316         {"/Apply as Filter/... not Selected", NULL,
317                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0),
318                 NULL, NULL,},
319         {"/Apply as Filter/.. and Selected", NULL,
320                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0),
321                 NULL, NULL,},
322         {"/Apply as Filter/... or Selected", NULL,
323                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0),
324                 NULL, NULL,},
325         {"/Apply as Filter/... and not Selected", NULL,
326                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0),
327                 NULL, NULL,},
328         {"/Apply as Filter/... or not Selected", NULL,
329                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0),
330                 NULL, NULL,},
331
332         /* Prepare */
333         {"/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL,},
334         {"/Prepare a Filter/Selected", NULL,
335                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_SELECTED, 0),
336                 NULL, NULL,},
337         {"/Prepare a Filter/Not Selected", NULL,
338                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0),
339                 NULL, NULL,},
340         {"/Prepare a Filter/... and Selected", NULL,
341                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0),
342                 NULL, NULL,},
343         {"/Prepare a Filter/... or Selected", NULL,
344                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0),
345                 NULL, NULL,},
346         {"/Prepare a Filter/... and not Selected", NULL,
347                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0),
348                 NULL, NULL,},
349         {"/Prepare a Filter/... or not Selected", NULL,
350                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0),
351                 NULL, NULL,},
352
353         /* Find Frame */
354         {"/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
355         {"/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
356         {"/Find Frame/Find Frame/Selected", NULL,
357                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0),
358                 NULL, NULL,},
359         {"/Find Frame/Find Frame/Not Selected", NULL,
360                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0),
361                 NULL, NULL,},
362         /* Find Next */
363         {"/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL,},
364         {"/Find Frame/Find Next/Selected", NULL,
365                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0),
366                 NULL, NULL,},
367         {"/Find Frame/Find Next/Not Selected", NULL,
368                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0),
369                 NULL, NULL,},
370
371         /* Find Previous */
372         {"/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL,},
373         {"/Find Frame/Find Previous/Selected", NULL,
374                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0),
375                 NULL, NULL,},
376         {"/Find Frame/Find Previous/Not Selected", NULL,
377                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0),
378                 NULL, NULL,},
379
380         /* Colorize Procedure */
381         {"/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL,},
382         {"/Colorize Procedure/Selected", NULL,
383                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_SELECTED, 0),
384                 NULL, NULL,},
385         {"/Colorize Procedure/Not Selected", NULL,
386                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_NOT_SELECTED, 0),
387                 NULL, NULL,},
388
389         /* Search Internet */
390         {"/Internet Search for Info Text", NULL,
391                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_WEB_LOOKUP, NULL, NULL,}
392 };
393
394 static void
395 expert_goto_pkt_cb (GtkTreeSelection *selection, gpointer data _U_)
396 {
397         GtkTreeIter iter;
398         GtkTreeModel *model;
399         gchar *pkt;
400         gchar *grp;
401
402         if (gtk_tree_selection_get_selected (selection, &model, &iter))
403         {
404                 gtk_tree_model_get (model, &iter, 
405                                     PROTOCOL_COLUMN, &pkt,
406                                     GROUP_COLUMN,    &grp,
407                                     -1);
408
409                 if (strcmp(grp, "Packet:")==0) {
410                     cf_goto_frame(&cfile, atoi(pkt));
411                 }
412                 g_free (pkt);
413                 g_free (grp);
414         }
415 }
416
417 static void
418 error_create_popup_menu(error_equiv_table *err)
419 {
420     GtkItemFactory *item_factory;
421
422
423     err->select = gtk_tree_view_get_selection (GTK_TREE_VIEW (err->tree_view));
424     gtk_tree_selection_set_mode (err->select, GTK_SELECTION_SINGLE);
425     g_signal_connect (G_OBJECT (err->select), "changed",
426                   G_CALLBACK (expert_goto_pkt_cb),
427                   err);
428     item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
429
430     gtk_item_factory_create_items_ac(item_factory, sizeof(error_list_menu_items)/sizeof(error_list_menu_items[0]), error_list_menu_items, err, 2);
431
432     err->menu = gtk_item_factory_get_widget(item_factory, "<main>");
433     g_signal_connect(err->tree_view, "button_press_event", G_CALLBACK(error_show_popup_menu_cb), err);
434 }
435
436 void
437 init_error_table(error_equiv_table *err, guint16 num_procs, GtkWidget *vbox)
438 {
439     guint16 i, j;
440     GtkTreeStore *store;
441     GtkWidget *tree;
442     GtkTreeViewColumn *column;
443     GtkCellRenderer *renderer;
444     GtkTreeSortable *sortable;
445
446     /* Create the store */
447     store = gtk_tree_store_new (4,       /* Total number of columns */
448                                G_TYPE_STRING,   /* Group              */
449                                G_TYPE_STRING,   /* Protocol           */
450                                G_TYPE_STRING,   /* Summary            */
451                                G_TYPE_INT);     /* Count              */
452
453     /* Create a view */
454     tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
455     err->tree_view = GTK_TREE_VIEW(tree);
456     sortable = GTK_TREE_SORTABLE(store);
457
458     /* Setup the sortable columns */
459     gtk_tree_sortable_set_sort_func(sortable, SORT_ALPHABETICAL, sort_iter_compare_func, GINT_TO_POINTER(SORT_ALPHABETICAL), NULL);
460     gtk_tree_sortable_set_sort_column_id(sortable, SORT_ALPHABETICAL, GTK_SORT_ASCENDING);
461     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW (tree), FALSE);
462
463     /* The view now holds a reference.  We can get rid of our own reference */
464     g_object_unref (G_OBJECT (store));
465
466     /* Create a cell renderer */
467     renderer = gtk_cell_renderer_text_new ();
468
469     /* Create the first column, associating the "text" attribute of the
470      * cell_renderer to the first column of the model */
471     column = gtk_tree_view_column_new_with_attributes ("Group", renderer, "text", GROUP_COLUMN, NULL);
472     gtk_tree_view_column_set_sort_column_id(column, 0);
473     gtk_tree_view_column_set_resizable(column, TRUE);
474     /* Add the column to the view. */
475     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
476  
477     /* Second column.. Protocol. */
478     renderer = gtk_cell_renderer_text_new ();
479     column = gtk_tree_view_column_new_with_attributes ("Protocol", renderer, "text", PROTOCOL_COLUMN, NULL);
480     gtk_tree_view_column_set_sort_column_id(column, 1);
481     gtk_tree_view_column_set_resizable(column, TRUE);
482     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
483  
484     /* Third column.. Summary. */
485     renderer = gtk_cell_renderer_text_new ();
486     column = gtk_tree_view_column_new_with_attributes ("Summary", renderer, "text", SUMMARY_COLUMN, NULL);
487     gtk_tree_view_column_set_sort_column_id(column, 2);
488     gtk_tree_view_column_set_resizable(column, TRUE);
489     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
490  
491     /* Last column.. Count. */
492     column = gtk_tree_view_column_new_with_attributes ("Count", renderer, "text", COUNT_COLUMN, NULL);
493     gtk_tree_view_column_set_sort_column_id(column, 3);
494     gtk_tree_view_column_set_resizable(column, TRUE);
495     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
496  
497     err->scrolled_window=scrolled_window_new(NULL, NULL);
498
499     gtk_container_add(GTK_CONTAINER(err->scrolled_window), GTK_WIDGET (err->tree_view));
500
501     gtk_box_pack_start(GTK_BOX(vbox), err->scrolled_window, TRUE, TRUE, 0);
502
503     gtk_tree_view_set_search_column (err->tree_view, SUMMARY_COLUMN); /* Allow searching the summary */
504     gtk_tree_view_set_reorderable (err->tree_view, TRUE);   /* Allow user to reorder data with drag n drop */
505     
506     /* Now enable the sorting of each column */
507     gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(err->tree_view), TRUE);
508     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(err->tree_view), TRUE);
509
510     gtk_widget_show(err->scrolled_window);
511
512     err->num_procs=num_procs;
513     err->procedures=g_malloc(sizeof(error_procedure_t)*(num_procs+1));
514     for(i=0;i<num_procs;i++){
515         for(j=0;j<3;j++){
516             err->procedures[i].entries[j]=NULL; /* reset all values */
517         }
518     }
519
520     /* create popup menu for this table */
521     error_create_popup_menu(err);
522 }
523
524 void
525 init_error_table_row(error_equiv_table *err, const expert_info_t *expert_data)
526 {
527     guint16 old_num_procs=err->num_procs;
528     guint16 j;
529     gint row=0;
530
531     GtkTreeStore *store;
532
533     /* we have discovered a new procedure. Extend the table accordingly */
534     row = find_summary_data(err, expert_data);
535     if(row==-1){
536         /* First time we have seen this event so initialize memory table */
537         row = old_num_procs; /* Number of expert events since this is a new event */
538         err->procedures=g_realloc(err->procedures, (sizeof(error_procedure_t)*(old_num_procs+1)));
539         err->procedures[row].count=0; /* count of events for this item */
540         err->procedures[row].fvalue_value = NULL; /* Filter string value */
541         for(j=0;j<4;j++){
542             err->procedures[row].entries[j]=NULL;
543         }
544         
545         /* Create the item in our memory table */
546         err->procedures[row].entries[0]=(char *)g_strdup(val_to_str(expert_data->group, expert_group_vals,"Unknown group (%u)"));  /* Group */
547         err->procedures[row].entries[1]=(char *)g_strdup(expert_data->protocol);    /* Protocol */
548         err->procedures[row].entries[2]=(char *)g_strdup(expert_data->summary);     /* Summary */
549
550         /* Create a new item in our tree view */
551         store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view)); /* Get store */
552         gtk_tree_store_append (store, &err->procedures[row].iter, NULL);  /* Acquire an iterator */
553         
554         /* (Note: gtk_tree_store_set *copies* the input strings) */
555         gtk_tree_store_set (store, &err->procedures[row].iter,
556                             GROUP_COLUMN,    val_to_str(expert_data->group, expert_group_vals,"Unknown group (%u)"),
557                             PROTOCOL_COLUMN, expert_data->protocol,
558                             SUMMARY_COLUMN,  expert_data->summary,
559                             -1);
560
561         /* If an expert item was passed then build the filter string */
562         if (expert_data->pitem) {
563             char *filter;
564
565             filter = proto_construct_match_selected_string(PITEM_FINFO(expert_data->pitem), NULL);
566             if (filter != NULL)
567                 err->procedures[row].fvalue_value = g_strdup(filter);
568         }
569         /* Store the updated count of events */
570         err->num_procs = ++old_num_procs;
571     }
572
573     /* Update our memory table with event data */
574     err->procedures[row].count++; /* increment the count of events for this item */
575
576     /* Store the updated count for this event item */
577     err->procedures[row].entries[3]=(char *)g_strdup_printf("%d", err->procedures[row].count);     /* Count */
578
579     /* Update the tree with new count for this event */
580     store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
581     gtk_tree_store_set(store, &err->procedures[row].iter, COUNT_COLUMN, err->procedures[row].count, -1);
582 }
583
584 void
585 add_error_table_data(error_equiv_table *err, const expert_info_t *expert_data)
586 {
587     error_procedure_t *errp;
588     gint index;
589     GtkTreeStore    *store;
590     GtkTreeIter      new_iter;
591     gchar            str[16];
592
593     index = find_summary_data(err, expert_data);
594
595     /* We should never encounter a condition where we cannot find the expert data. If
596      * we do then we will just abort.
597      */
598     if (index == -1) {
599         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not find expert data. Aborting");
600         return;
601     }
602     errp=&err->procedures[index];
603
604     store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
605
606     g_snprintf(str, sizeof(str), "%d", expert_data->packet_num);
607     gtk_tree_store_append(store, &new_iter, &errp->iter);
608     gtk_tree_store_set(store, &new_iter,
609                        GROUP_COLUMN,    "Packet:",
610                        PROTOCOL_COLUMN, str,
611                        COUNT_COLUMN,    1,
612                        -1);
613 }
614
615 void
616 reset_error_table_data(error_equiv_table *err)
617 {
618     guint16 i;
619     GtkTreeStore    *store;
620
621     for(i=0;i<err->num_procs;i++){
622         err->procedures[i].entries[0] = NULL;
623         err->procedures[i].entries[1] = NULL;
624         err->procedures[i].entries[2] = NULL;
625         err->procedures[i].entries[3] = NULL;
626         err->procedures[i].count=0;
627     }
628
629     store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
630     gtk_tree_store_clear(store);
631     err->num_procs = 0;
632 }
633
634 void
635 free_error_table_data(error_equiv_table *err)
636 {
637     guint16 i,j;
638
639     for(i=0;i<err->num_procs;i++){
640         for(j=0;j<4;j++){
641             if(err->procedures[i].entries[j]){
642                 err->procedures[i].entries[j]=NULL;
643             }
644             err->procedures[i].fvalue_value=NULL;
645             err->procedures[i].count=0;
646         }
647     }
648     err->procedures=NULL;
649     err->num_procs=0;
650 }