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