diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | epan/filesystem.c | 26 | ||||
-rw-r--r-- | epan/filesystem.h | 10 | ||||
-rw-r--r-- | epan/resolv.c | 7 | ||||
-rw-r--r-- | gtk/color_dlg.c | 161 | ||||
-rw-r--r-- | gtk/color_filters.c | 188 | ||||
-rw-r--r-- | gtk/color_filters.h | 5 | ||||
-rw-r--r-- | packet-diameter.c | 10 | ||||
-rw-r--r-- | prefs.c | 10 |
9 files changed, 301 insertions, 117 deletions
@@ -1413,6 +1413,7 @@ Liviu Daia <Liviu.Daia[AT]imar.ro> { Richard Urwin <rurwin[AT]schenck.co.uk> { Developer documentation fixes and updates + Support for a system-wide color filter file } Prabhakar Krishnan <Prabhakar.Krishnan[AT]netapp.com> { diff --git a/epan/filesystem.c b/epan/filesystem.c index 82d412abe3..2a38b09c6d 100644 --- a/epan/filesystem.c +++ b/epan/filesystem.c @@ -1,7 +1,7 @@ /* filesystem.c * Filesystem utility routines * - * $Id: filesystem.c,v 1.22 2003/03/26 00:34:27 guy Exp $ + * $Id: filesystem.c,v 1.23 2003/05/15 07:44:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -601,3 +601,27 @@ get_persconffile_path(const char *filename, gboolean for_writing return path; } + +/* + * Construct the path name of a global configuration file, given the + * file name. + */ +char * +get_datafile_path(const char *filename) +{ + char *path; + + path = (gchar *) g_malloc(strlen(get_datafile_dir()) + + strlen(filename) + 2); + sprintf(path, "%s" G_DIR_SEPARATOR_S "%s", get_datafile_dir(), + filename); + + return path; +} + +/* Delete a file */ +gboolean +deletefile(const char *path) +{ + return unlink(path) == 0; +} diff --git a/epan/filesystem.h b/epan/filesystem.h index ea356b8a56..a23a621684 100644 --- a/epan/filesystem.h +++ b/epan/filesystem.h @@ -1,7 +1,7 @@ /* filesystem.h * Filesystem utility definitions * - * $Id: filesystem.h,v 1.12 2002/08/28 20:40:44 jmayer Exp $ + * $Id: filesystem.h,v 1.13 2003/05/15 07:44:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -77,6 +77,12 @@ int test_for_fifo(const char *); const char *get_datafile_dir(void); /* + * Construct the path name of a global configuration file, given the + * file name. + */ +char *get_datafile_path(const char *filename); + +/* * Get the directory in which files that, at least on UNIX, are * system files (such as "/etc/ethers") are stored; on Windows, * there's no "/etc" directory, so we get them from the Ethereal @@ -105,4 +111,6 @@ int create_persconffile_dir(char **pf_dir_path_return); */ char *get_persconffile_path(const char *filename, gboolean for_writing); +/* Delete a file */ +gboolean deletefile (const char *path); #endif /* FILESYSTEM_H */ diff --git a/epan/resolv.c b/epan/resolv.c index 9b60866ecd..b93cace39e 100644 --- a/epan/resolv.c +++ b/epan/resolv.c @@ -1,7 +1,7 @@ /* resolv.c * Routines for network object lookup * - * $Id: resolv.c,v 1.32 2003/05/05 00:53:06 guy Exp $ + * $Id: resolv.c,v 1.33 2003/05/15 07:44:54 guy Exp $ * * Laurent Deniel <laurent.deniel@free.fr> * @@ -912,10 +912,7 @@ static void initialize_ethers(void) /* manuf hash table initialization */ /* Compute the pathname of the manuf file */ - manuf_path = (gchar *) g_malloc(strlen(get_datafile_dir()) + - strlen(ENAME_MANUF) + 2); - sprintf(manuf_path, "%s" G_DIR_SEPARATOR_S "%s", get_datafile_dir(), - ENAME_MANUF); + manuf_path = get_datafile_path(ENAME_MANUF); /* Read it and initialize the hash table */ set_ethent(manuf_path); diff --git a/gtk/color_dlg.c b/gtk/color_dlg.c index 62ef62fc2c..770a4c9ac8 100644 --- a/gtk/color_dlg.c +++ b/gtk/color_dlg.c @@ -1,7 +1,7 @@ /* color_dlg.c * Definitions for dialog boxes for color filters * - * $Id: color_dlg.c,v 1.23 2003/02/17 21:08:37 oabad Exp $ + * $Id: color_dlg.c,v 1.24 2003/05/15 07:44:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -66,6 +66,8 @@ static void color_save_cb(GtkButton *button, gpointer user_data); static void color_ok_cb(GtkButton *button, gpointer user_data); static void color_cancel_cb(GtkWidget *widget, gpointer user_data); static void color_apply_cb(GtkButton *button, gpointer user_data); +static void color_revert_cb(GtkWidget *button, gpointer user_data); + static void edit_color_filter_dialog_new(GtkWidget *color_filters, GtkWidget **colorize_filter_name, @@ -152,6 +154,7 @@ colorize_dialog_new (void) GtkWidget *color_ok; GtkWidget *color_apply; GtkWidget *color_save; + GtkWidget *color_revert; GtkWidget *color_cancel; #if GTK_MAJOR_VERSION >= 2 @@ -385,6 +388,17 @@ colorize_dialog_new (void) gtk_tooltips_set_tip(tooltips, color_save, ("Save all filters to disk"), NULL); #if GTK_MAJOR_VERSION < 2 + color_revert = gtk_button_new_with_label (("Revert")); +#else + color_revert = gtk_button_new_from_stock(GTK_STOCK_REVERT_TO_SAVED); +#endif + gtk_widget_ref(color_revert); + OBJECT_SET_DATA_FULL(color_win, "color_revert", color_revert, gtk_widget_unref); + gtk_widget_show(color_revert); + gtk_box_pack_start(GTK_BOX (button_ok_hbox), color_revert, FALSE, FALSE, 5); + gtk_tooltips_set_tip(tooltips, color_revert, ("Delete filter file and revert to system-wide default filter set"), NULL); + +#if GTK_MAJOR_VERSION < 2 color_cancel = gtk_button_new_with_label (("Cancel")); #else color_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); @@ -419,6 +433,8 @@ colorize_dialog_new (void) OBJECT_SET_DATA(color_delete, COLOR_FILTERS_CL, color_filters); SIGNAL_CONNECT(color_delete, "clicked", color_delete_cb, NULL); SIGNAL_CONNECT(color_save, "clicked", color_save_cb, NULL); + SIGNAL_CONNECT(color_revert, "clicked", color_revert_cb, NULL); + OBJECT_SET_DATA(color_revert, COLOR_FILTERS_CL, color_filters); SIGNAL_CONNECT(color_ok, "clicked", color_ok_cb, NULL); SIGNAL_CONNECT(color_apply, "clicked", color_apply_cb, NULL); SIGNAL_CONNECT(color_cancel, "clicked", color_cancel_cb, NULL); @@ -770,77 +786,83 @@ color_edit_cb(GtkButton *button, gpointer user_data _U_) /* Delete a color from the list. */ static void -color_delete_cb(GtkWidget *widget, gpointer user_data _U_) +color_delete(gint row, GtkWidget *color_filters) { - GtkWidget *color_filters; - color_filter_t *colorf; + color_filter_t *colorf; + #if GTK_MAJOR_VERSION >= 2 GtkTreeModel *model; GtkTreeIter iter; - gint row; + gint rowsel; GtkTreeSelection *sel; - if(row_selected != -1) { - /* The "selection changed" callback is called when the row is - * removed, so we must remember the selected row. */ - row = row_selected; - color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL); - model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters)); - gtk_tree_model_iter_nth_child(model, &iter, NULL, row); - gtk_tree_model_get(model, &iter, 4, &colorf, -1); - - /* Remove this color filter from the CList displaying the - color filters. */ - gtk_list_store_remove(GTK_LIST_STORE(model), &iter); - num_of_filters--; - - /* Destroy any "Edit color filter" dialog boxes editing it. */ - if (colorf->edit_dialog != NULL) - gtk_widget_destroy(colorf->edit_dialog); - - /* Remove the color filter from the list of color filters. */ - delete_color_filter(colorf); - - /* If we grab the focus after updating the selection, the first - * row is always selected, so we do it before */ - gtk_widget_grab_focus(color_filters); - /* Update the selection */ - if (row <= (num_of_filters-1)) { - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)); - gtk_tree_model_iter_nth_child(model, &iter, NULL, row); - gtk_tree_selection_select_iter(sel, &iter); - } - else if (num_of_filters > 0) { - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)); - gtk_tree_model_iter_nth_child(model, &iter, NULL, num_of_filters-1); - gtk_tree_selection_select_iter(sel, &iter); - } + + /* The "selection changed" callback is called when the row is + * removed, so we must remember the selected row. */ + model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters)); + gtk_tree_model_iter_nth_child(model, &iter, NULL, row); + gtk_tree_model_get(model, &iter, 4, &colorf, -1); + + /* Remove this color filter from the CList displaying the + color filters. */ + gtk_list_store_remove(GTK_LIST_STORE(model), &iter); + num_of_filters--; + + /* Destroy any "Edit color filter" dialog boxes editing it. */ + if (colorf->edit_dialog != NULL) + gtk_widget_destroy(colorf->edit_dialog); + + /* Remove the color filter from the list of color filters. */ + delete_color_filter(colorf); + + /* If we grab the focus after updating the selection, the first + * row is always selected, so we do it before */ + gtk_widget_grab_focus(color_filters); + /* Update the selection */ + if (row_selected <= (num_of_filters-1)) { + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)); + gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected); + gtk_tree_selection_select_iter(sel, &iter); + } + else if (num_of_filters > 0) { + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters)); + gtk_tree_model_iter_nth_child(model, &iter, NULL, num_of_filters-1); + gtk_tree_selection_select_iter(sel, &iter); } #else - if(row_selected != -1){ - color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL); - colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected); + colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row); - /* Remove this color filter from the CList displaying the - color filters. */ - gtk_clist_remove(GTK_CLIST(color_filters), row_selected); - num_of_filters--; + /* Remove this color filter from the CList displaying the + color filters. */ + gtk_clist_remove(GTK_CLIST(color_filters), row); + num_of_filters--; - /* Destroy any "Edit color filter" dialog boxes editing it. */ - if (colorf->edit_dialog != NULL) - gtk_widget_destroy(colorf->edit_dialog); + /* Destroy any "Edit color filter" dialog boxes editing it. */ + if (colorf->edit_dialog != NULL) + gtk_widget_destroy(colorf->edit_dialog); - /* Remove the color filter from the list of color filters. */ - delete_color_filter(colorf); + /* Remove the color filter from the list of color filters. */ + delete_color_filter(colorf); - /* Select the previous row, if there is one. */ - if (row_selected > 0) { - row_selected--; - gtk_clist_select_row(GTK_CLIST(color_filters), row_selected, 0); - } + /* Select the previous row, if there is one. */ + if (row <= row_selected && row_selected > 0) { + row_selected--; + gtk_clist_select_row(GTK_CLIST(color_filters), row_selected, 0); } #endif } +/* Delete the selected color from the list.*/ +static void +color_delete_cb(GtkWidget *widget, gpointer user_data _U_) +{ + GtkWidget *color_filters; + + if(row_selected != -1) + { + color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL); + color_delete (row_selected, color_filters); + } +} /* Save color filters to the color filter file. */ static void @@ -852,6 +874,31 @@ color_save_cb(GtkButton *button _U_, gpointer user_data _U_) } +/* Remove all user defined color filters and revert to the global file. */ +static void +color_revert_cb(GtkWidget *widget, gpointer user_data _U_) +{ + GtkWidget * color_filters; + + color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL); + + while (num_of_filters > 0) + { + color_delete (num_of_filters-1, color_filters); + } + + if (!revert_filters()) + simple_dialog(ESD_TYPE_CRIT, NULL, "Could not delete filter file: %s", + strerror(errno)); + + /* colorize list */ + colorize_packets(&cfile); + + /* Destroy the dialog box. */ + gtk_widget_destroy(colorize_win); + +} + /* Exit dialog and apply new list of color filters to the capture. */ static void color_ok_cb(GtkButton *button _U_, gpointer user_data _U_) diff --git a/gtk/color_filters.c b/gtk/color_filters.c index 89b635f248..25cdc5ebc2 100644 --- a/gtk/color_filters.c +++ b/gtk/color_filters.c @@ -1,7 +1,7 @@ /* color_filters.c * Routines for color filters * - * $Id: color_filters.c,v 1.1 2003/01/08 01:59:42 guy Exp $ + * $Id: color_filters.c,v 1.2 2003/05/15 07:44:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -45,14 +45,48 @@ #include "gtkglobals.h" static gboolean read_filters(void); +static gboolean read_global_filters(void); GSList *filter_list; -/* Initialize the filter structures (reading from file) */ +/* delete the specified filter */ +void +delete_color_filter(color_filter_t *colorf) +{ + if (colorf->filter_name != NULL) + g_free(colorf->filter_name); + if (colorf->filter_text != NULL) + g_free(colorf->filter_text); + if (colorf->c_colorfilter != NULL) + dfilter_free(colorf->c_colorfilter); + filter_list = g_slist_remove(filter_list, colorf); + g_free(colorf); +} + +/* delete the specified filter as an iterator*/ +static void +delete_color_filter_it(gpointer filter_arg, gpointer ignored _U_) +{ + color_filter_t *colorf = filter_arg; + + delete_color_filter(colorf); +} + +/* delete all the filters */ + +static void +delete_all_color_filters (void) +{ + g_slist_foreach(filter_list, delete_color_filter_it, NULL); +} + +/* Initialize the filter structures (reading from file) for general running, including app startup */ void colfilter_init(void) { - read_filters(); + delete_all_color_filters(); + if (!read_filters()) + read_global_filters(); } /* Create a new filter */ @@ -75,19 +109,6 @@ new_color_filter(gchar *name, /* The name of the filter to create */ return colorf; } -/* delete the specified filter */ -void -delete_color_filter(color_filter_t *colorf) -{ - if (colorf->filter_name != NULL) - g_free(colorf->filter_name); - if (colorf->filter_text != NULL) - g_free(colorf->filter_text); - if (colorf->c_colorfilter != NULL) - dfilter_free(colorf->c_colorfilter); - filter_list = g_slist_remove(filter_list, colorf); - g_free(colorf); -} static void prime_edt(gpointer data, gpointer user_data) @@ -108,9 +129,9 @@ filter_list_prime_edt(epan_dissect_t *edt) } -/* read filters from the file */ +/* read filters from the given file */ static gboolean -read_filters(void) +read_filters_file(gpointer file_arg) { /* TODO: Lots more syntax checking on the file */ /* I hate these fixed length names! TODO: make more dynamic */ @@ -121,23 +142,8 @@ read_filters(void) guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; GdkColor fg_color, bg_color; color_filter_t *colorf; - gchar *path; - FILE *f; dfilter_t *temp_dfilter; - - /* decide what file to open (from dfilter code) */ - path = get_persconffile_path("colorfilters", FALSE); - if ((f = fopen(path, "r")) == NULL) { - if (errno != ENOENT) { - simple_dialog(ESD_TYPE_CRIT, NULL, - "Could not open filter file\n\"%s\": %s.", path, - strerror(errno)); - } - g_free((gchar *)path); - return FALSE; - } - g_free((gchar *)path); - path = NULL; + FILE *f = file_arg; do { if (fgets(buf,sizeof buf, f) == NULL) @@ -193,8 +199,61 @@ read_filters(void) gdkcolor_to_color_t(&colorf->fg_color, &fg_color); } /* if sscanf */ } while(!feof(f)); + fclose(f); return TRUE; } +/* read filters from the user's filter file */ +static gboolean +read_filters(void) +{ + /* TODO: Lots more syntax checking on the file */ + /* I hate these fixed length names! TODO: make more dynamic */ + /* XXX - buffer overflow possibility here + * sscanf blocks max size of name and filter_exp; buf is used for + * reading only */ + gchar *path; + FILE *f; + + /* decide what file to open (from dfilter code) */ + path = get_persconffile_path("colorfilters", FALSE); + if ((f = fopen(path, "r")) == NULL) { + if (errno != ENOENT) { + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not open filter file\n\"%s\": %s.", path, + strerror(errno)); + } + g_free((gchar *)path); + return FALSE; + } + g_free((gchar *)path); + path = NULL; + + return read_filters_file(f); +} + +/* read filters from the filter file */ +static gboolean +read_global_filters(void) +{ + gchar *path; + FILE *f; + + /* decide what file to open (from dfilter code) */ + path = get_datafile_path("colorfilters"); + if ((f = fopen(path, "r")) == NULL) { + if (errno != ENOENT) { + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not open global filter file\n\"%s\": %s.", path, + strerror(errno)); + } + g_free((gchar *)path); + return FALSE; + } + g_free((gchar *)path); + path = NULL; + + return read_filters_file(f); +} static void write_filter(gpointer filter_arg, gpointer file_arg) @@ -213,7 +272,17 @@ write_filter(gpointer filter_arg, gpointer file_arg) colorf->fg_color.blue); } -/* save filters in filter file */ +/* save filters in a filter file */ +gboolean +write_filters_file(FILE *f) +{ + fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n"); + g_slist_foreach(filter_list, write_filter, f); + return TRUE; +} + +/* save filters in users filter file */ + gboolean write_filters(void) { @@ -238,8 +307,53 @@ write_filters(void) path, strerror(errno)); return FALSE; } - fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n"); - g_slist_foreach(filter_list, write_filter, f); + write_filters_file(f); + fclose(f); + return TRUE; +} + +/* delete users filter file and reload global filters*/ + +gboolean +revert_filters(void) +{ + gchar *pf_dir_path; + const gchar *path; + + /* Create the directory that holds personal configuration files, + if necessary. */ + if (create_persconffile_dir(&pf_dir_path) == -1) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Can't create directory\n\"%s\"\nfor color files: %s.", + pf_dir_path, strerror(errno)); + g_free(pf_dir_path); + return FALSE; + } + + path = get_persconffile_path("colorfilters", TRUE); + if (!deletefile(path)) + return FALSE; + + /* Reload the (global) filters - Note: this does not update the dialog. */ + colfilter_init(); + return TRUE; +} + + +/* save filters in some other filter file */ + +gboolean +write_other_filters(gchar *path) +{ + FILE *f; + + if ((f = fopen(path, "w+")) == NULL) { + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not open\n%s\nfor writing: %s.", + path, strerror(errno)); + return FALSE; + } + write_filters_file(f); fclose(f); return TRUE; } diff --git a/gtk/color_filters.h b/gtk/color_filters.h index 046a672031..16154b3de4 100644 --- a/gtk/color_filters.h +++ b/gtk/color_filters.h @@ -1,7 +1,7 @@ /* color_filters.h * Definitions for color filters * - * $Id: color_filters.h,v 1.1 2003/01/08 01:59:42 guy Exp $ + * $Id: color_filters.h,v 1.2 2003/05/15 07:44:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -34,8 +34,9 @@ void colfilter_init(void); gboolean write_filters(void); +gboolean revert_filters(void); color_filter_t *new_color_filter(gchar *name, gchar *filter_string); void delete_color_filter(color_filter_t *colorf); - +gboolean write_other_filters(gchar *path); #endif diff --git a/packet-diameter.c b/packet-diameter.c index 091a8654fa..e7ee2172ba 100644 --- a/packet-diameter.c +++ b/packet-diameter.c @@ -1,7 +1,7 @@ /* packet-diameter.c * Routines for Diameter packet disassembly * - * $Id: packet-diameter.c,v 1.53 2003/04/12 05:48:26 guy Exp $ + * $Id: packet-diameter.c,v 1.54 2003/05/15 07:44:53 guy Exp $ * * Copyright (c) 2001 by David Frascone <dave@frascone.com> * @@ -1896,12 +1896,8 @@ proto_register_diameter(void) /* * Build our default dictionary filename */ - if (! gbl_diameterDictionary) { - gbl_diameterDictionary = (gchar *) g_malloc(strlen(get_datafile_dir()) + - 1 + strlen(DICT_FN) + 1); /* slash + fn + null */ - sprintf(gbl_diameterDictionary, "%s" G_DIR_SEPARATOR_S "%s", - get_datafile_dir(), DICT_FN ); - } + if (! gbl_diameterDictionary) + gbl_diameterDictionary = get_datafile_path(DICT_FN); /* Now register its preferences so it can be changed. */ prefs_register_string_preference(diameter_module, "dictionary.name", "Diameter XML Dictionary", @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.100 2003/04/21 21:28:31 guy Exp $ + * $Id: prefs.c,v 1.101 2003/05/15 07:44:53 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -986,12 +986,8 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return, } /* Construct the pathname of the global preferences file. */ - if (! gpf_path) { - gpf_path = (gchar *) g_malloc(strlen(get_datafile_dir()) + - strlen(GPF_NAME) + 2); - sprintf(gpf_path, "%s" G_DIR_SEPARATOR_S "%s", - get_datafile_dir(), GPF_NAME); - } + if (! gpf_path) + gpf_path = get_datafile_path(GPF_NAME); /* Read the global preferences file, if it exists. */ *gpf_path_return = NULL; |