White space changes.
[obnox/wireshark/wip.git] / color_filters.c
index eee30e172c4d150deee68d146a455ff6e3d42589..bd6abfbd686573320aa7b83fe0fa2dd6b0b4a88f 100644 (file)
 #include "color_filters.h"
 #include "file.h"
 #include <epan/dfilter/dfilter.h>
-#include "simple_dialog.h"
-#include "ui_util.h"
 #include <epan/prefs.h>
 
+#include "ui/simple_dialog.h"
+#include "ui/ui_util.h"
+
 #define RED_COMPONENT(x)   (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
 #define GREEN_COMPONENT(x) (guint16) (((((x) >>  8) & 0xff) * 65535 / 255))
 #define BLUE_COMPONENT(x)  (guint16) ( (((x)        & 0xff) * 65535 / 255))
@@ -62,12 +63,12 @@ static GSList *color_filter_deleted_list = NULL;
 static GSList *color_filter_valid_list = NULL;
 
 /* Color Filters can en-/disabled. */
-gboolean filters_enabled = TRUE;
+static gboolean filters_enabled = TRUE;
 
 /* Remember if there are temporary coloring filters set to
  * add sensitivity to the "Reset Coloring 1-10" menu item
  */
-gboolean tmp_colors_set = FALSE;
+static gboolean tmp_colors_set = FALSE;
 
 /* Create a new filter */
 color_filter_t *
@@ -79,7 +80,7 @@ color_filter_new(const gchar *name,    /* The name of the filter to create */
 {
        color_filter_t *colorf;
 
-       colorf = g_malloc(sizeof (color_filter_t));
+       colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t));
        colorf->filter_name = g_strdup(name);
        colorf->filter_text = g_strdup(filter_string);
        colorf->bg_color = *bg_color;
@@ -88,57 +89,57 @@ color_filter_new(const gchar *name,    /* The name of the filter to create */
        colorf->c_colorfilter = NULL;
        colorf->edit_dialog = NULL;
        colorf->selected = FALSE;
-        return colorf;
+    return colorf;
 }
 
 /* Add ten empty (temporary) colorfilters for easy coloring */
-void
+static void
 color_filters_add_tmp(GSList **cfl)
 {
-       gchar  *name = NULL;
-       guint32 i;
-        gchar** bg_colors;
-        gchar** fg_colors;
-        unsigned long int cval;
-        color_t bg_color, fg_color;
-        color_filter_t *colorf;
+    gchar  *name = NULL;
+    guint32 i;
+    gchar** bg_colors;
+    gchar** fg_colors;
+    unsigned long int cval;
+    color_t bg_color, fg_color;
+    color_filter_t *colorf;
 
-       g_assert(strlen(prefs.gui_colorized_fg)==69);
-       g_assert(strlen(prefs.gui_colorized_bg)==69);
-        fg_colors = g_strsplit(prefs.gui_colorized_fg, ",", -1);
-        bg_colors = g_strsplit(prefs.gui_colorized_bg, ",", -1);
+    g_assert(strlen(prefs.gui_colorized_fg)==69);
+    g_assert(strlen(prefs.gui_colorized_bg)==69);
+    fg_colors = g_strsplit(prefs.gui_colorized_fg, ",", -1);
+    bg_colors = g_strsplit(prefs.gui_colorized_bg, ",", -1);
 
         for ( i=1 ; i<=10 ; i++ ) {
-                name = g_strdup_printf("%s%02d",TEMP_COLOR_PREFIX,i);
-
-               /* retrieve background and foreground colors */
-                cval = strtoul(fg_colors[i-1], NULL, 16);
-                initialize_color(&fg_color, RED_COMPONENT(cval),
-                                            GREEN_COMPONENT(cval),
-                                            BLUE_COMPONENT(cval) );
-                cval = strtoul(bg_colors[i-1], NULL, 16);
-                initialize_color(&bg_color, RED_COMPONENT(cval),
-                                            GREEN_COMPONENT(cval),
-                                            BLUE_COMPONENT(cval) );
-                colorf = color_filter_new(name, NULL, &bg_color, &fg_color, TRUE);
-                colorf->filter_text = g_strdup("frame");
-                colorf->c_colorfilter = NULL;
-                *cfl = g_slist_append(*cfl, colorf);
-
-                g_free(name);
-       }
+            name = g_strdup_printf("%s%02d",CONVERSATION_COLOR_PREFIX,i);
+
+            /* retrieve background and foreground colors */
+            cval = strtoul(fg_colors[i-1], NULL, 16);
+            initialize_color(&fg_color, RED_COMPONENT(cval),
+                                        GREEN_COMPONENT(cval),
+                                        BLUE_COMPONENT(cval) );
+            cval = strtoul(bg_colors[i-1], NULL, 16);
+            initialize_color(&bg_color, RED_COMPONENT(cval),
+                                        GREEN_COMPONENT(cval),
+                                        BLUE_COMPONENT(cval) );
+            colorf = color_filter_new(name, NULL, &bg_color, &fg_color, TRUE);
+            colorf->filter_text = g_strdup("frame");
+            colorf->c_colorfilter = NULL;
+            *cfl = g_slist_append(*cfl, colorf);
+
+            g_free(name);
+    }
 
-        g_strfreev(fg_colors);
-        g_strfreev(bg_colors);
+    g_strfreev(fg_colors);
+    g_strfreev(bg_colors);
 
-       return;
+    return;
 }
 
 static gint
 color_filters_find_by_name_cb(gconstpointer arg1, gconstpointer arg2)
 {
-        color_filter_t *colorf = (color_filter_t *)arg1;
-        gchar          *name   = (gchar *)arg2;
+        const color_filter_t *colorf = (const color_filter_t *)arg1;
+        const gchar          *name   = (const gchar *)arg2;
 
         return (strstr(colorf->filter_name, name)==NULL) ? -1 : 0 ;
 }
@@ -148,12 +149,12 @@ color_filters_find_by_name_cb(gconstpointer arg1, gconstpointer arg2)
 void
 color_filters_set_tmp(guint8 filt_nr, gchar *filter, gboolean disabled)
 {
-       gchar  *name = NULL;
-       gchar  *tmpfilter = NULL;
-        GSList *cfl;
+       gchar          *name = NULL;
+       const gchar    *tmpfilter = NULL;
+        GSList         *cfl;
         color_filter_t *colorf;
         dfilter_t      *compiled_filter;
-       guint8 i;
+       guint8         i;
 
         /* Go through the tomporary filters and look for the same filter string.
          * If found, clear it so that a filter can be "moved" up and down the list
@@ -165,9 +166,9 @@ color_filters_set_tmp(guint8 filt_nr, gchar *filter, gboolean disabled)
                 if( i!=filt_nr && filter==NULL )
                         continue;
 
-                name = g_strdup_printf("%s%02d",TEMP_COLOR_PREFIX,i);
-                cfl = g_slist_find_custom(color_filter_list, (gpointer *) name, color_filters_find_by_name_cb);
-                colorf = cfl->data;
+                name = g_strdup_printf("%s%02d",CONVERSATION_COLOR_PREFIX,i);
+                cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb);
+                colorf = (color_filter_t *)cfl->data;
 
                 /* Only change the filter rule if this is the rule to change or if
                  * a matching filter string has been found
@@ -201,7 +202,7 @@ color_filters_set_tmp(guint8 filt_nr, gchar *filter, gboolean disabled)
 
 /* Reset the temporary colorfilters */
 void
-color_filters_reset_tmp()
+color_filters_reset_tmp(void)
 {
        guint8 i;
 
@@ -230,7 +231,7 @@ color_filter_delete(color_filter_t *colorf)
 static void
 color_filter_delete_cb(gpointer filter_arg, gpointer unused _U_)
 {
-       color_filter_t *colorf = filter_arg;
+       color_filter_t *colorf = (color_filter_t *)filter_arg;
 
        color_filter_delete(colorf);
 }
@@ -250,7 +251,7 @@ color_filter_clone(color_filter_t *colorf)
 {
        color_filter_t *new_colorf;
 
-       new_colorf = g_malloc(sizeof (color_filter_t));
+       new_colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t));
        new_colorf->filter_name = g_strdup(colorf->filter_name);
        new_colorf->filter_text = g_strdup(colorf->filter_text);
        new_colorf->bg_color = colorf->bg_color;
@@ -260,17 +261,17 @@ color_filter_clone(color_filter_t *colorf)
        new_colorf->edit_dialog = NULL;
        new_colorf->selected = FALSE;
 
-        return new_colorf;
+    return new_colorf;
 }
 
 static void
 color_filter_list_clone_cb(gpointer filter_arg, gpointer cfl_arg)
 {
-    gpointer *cfl = cfl_arg;
-    color_filter_t *new_colorf;
+       GSList **cfl = (GSList **)cfl_arg;
+       color_filter_t *new_colorf;
 
-    new_colorf = color_filter_clone(filter_arg);
-    *cfl = g_slist_append(*cfl, new_colorf);
+       new_colorf = color_filter_clone((color_filter_t *)filter_arg);
+       *cfl = g_slist_append(*cfl, new_colorf);
 }
 
 /* clone the specified list */
@@ -291,8 +292,8 @@ color_filters_init(void)
        /* delete all currently existing filters */
        color_filter_list_delete(&color_filter_list);
 
-        /* start the list with the temporary colorizing rules */
-        color_filters_add_tmp(&color_filter_list);
+       /* start the list with the temporary colorizing rules */
+       color_filters_add_tmp(&color_filter_list);
 
        /* try to read the users filters */
        if (!read_users_filters(&color_filter_list))
@@ -303,13 +304,13 @@ color_filters_init(void)
 void
 color_filters_reload(void)
 {
-        /* "move" old entries to the deleted list
-         * we must keep them until the dissection no longer needs them */
-        color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list);
-        color_filter_list = NULL;
+    /* "move" old entries to the deleted list
+     * we must keep them until the dissection no longer needs them */
+    color_filter_deleted_list = g_slist_concat(color_filter_deleted_list, color_filter_list);
+    color_filter_list = NULL;
 
-        /* start the list with the temporary colorizing rules */
-        color_filters_add_tmp(&color_filter_list);
+    /* start the list with the temporary colorizing rules */
+    color_filters_add_tmp(&color_filter_list);
 
        /* try to read the users filters */
        if (!read_users_filters(&color_filter_list))
@@ -320,28 +321,28 @@ color_filters_reload(void)
 void
 color_filters_cleanup(void)
 {
-        /* delete the previously deleted filters */
-        color_filter_list_delete(&color_filter_deleted_list);
+    /* delete the previously deleted filters */
+    color_filter_list_delete(&color_filter_deleted_list);
 }
 
 static void
 color_filters_clone_cb(gpointer filter_arg, gpointer user_data)
 {
-       color_filter_t * new_colorf = color_filter_clone(filter_arg);
-        color_filter_add_cb (new_colorf, user_data);
+       color_filter_t * new_colorf = color_filter_clone((color_filter_t *)filter_arg);
+    color_filter_add_cb (new_colorf, user_data);
 }
 
 void
 color_filters_clone(gpointer user_data)
 {
-    g_slist_foreach(color_filter_list, color_filters_clone_cb, user_data);
+       g_slist_foreach(color_filter_list, color_filters_clone_cb, user_data);
 }
 
 
 static void
 color_filter_compile_cb(gpointer filter_arg, gpointer unused _U_)
 {
-       color_filter_t *colorf = filter_arg;
+       color_filter_t *colorf = (color_filter_t *)filter_arg;
 
        g_assert(colorf->c_colorfilter == NULL);
        if (!dfilter_compile(colorf->filter_text, &colorf->c_colorfilter)) {
@@ -357,7 +358,7 @@ color_filter_compile_cb(gpointer filter_arg, gpointer unused _U_)
 static void
 color_filter_validate_cb(gpointer filter_arg, gpointer unused _U_)
 {
-       color_filter_t *colorf = filter_arg;
+       color_filter_t *colorf = (color_filter_t *)filter_arg;
 
        g_assert(colorf->c_colorfilter == NULL);
        if (!dfilter_compile(colorf->filter_text, &colorf->c_colorfilter)) {
@@ -410,11 +411,7 @@ tmp_color_filters_used(void)
 void
 color_filters_enable(gboolean enable)
 {
-#ifdef NEW_PACKET_LIST
        new_packet_list_enable_color(enable);
-#else
-        filters_enabled = enable;
-#endif
 }
 
 
@@ -422,8 +419,8 @@ color_filters_enable(gboolean enable)
 static void
 prime_edt(gpointer data, gpointer user_data)
 {
-       color_filter_t  *colorf = data;
-       epan_dissect_t   *edt = user_data;
+       color_filter_t  *colorf = (color_filter_t *)data;
+       epan_dissect_t   *edt = (epan_dissect_t *)user_data;
 
        if (colorf->c_colorfilter != NULL)
                epan_dissect_prime_dfilter(edt, colorf->c_colorfilter);
@@ -438,36 +435,29 @@ color_filters_prime_edt(epan_dissect_t *edt)
                g_slist_foreach(color_filter_list, prime_edt, edt);
 }
 
-/* Colorize a single packet of the packet list (old packet list)
- * (row is only _U_ for the NEW_PACKET_LIST case
- * Return the color_t for later use (new packet list) */
-color_filter_t *
-color_filters_colorize_packet(gint row _U_, epan_dissect_t *edt)
+/* * Return the color_t for later use */
+const color_filter_t *
+color_filters_colorize_packet(epan_dissect_t *edt)
 {
-    GSList *curr;
-    color_filter_t *colorf;
+       GSList *curr;
+       color_filter_t *colorf;
 
-    /* If we have color filters, "search" for the matching one. */
-    if (color_filters_used()) {
-        curr = color_filter_list;
-
-        while(curr != NULL) {
-            colorf = curr->data;
-            if ( (!colorf->disabled) &&
-                 (colorf->c_colorfilter != NULL) &&
-                 dfilter_apply_edt(colorf->c_colorfilter, edt)) {
-                    /* this is the filter to use, apply it to the packet list */
-#ifndef NEW_PACKET_LIST
-                   /* We'll do this in the column cell function instead. */
-                    packet_list_set_colors(row, &(colorf->fg_color), &(colorf->bg_color));
-#endif
-                    return colorf;
-            }
-            curr = g_slist_next(curr);
-        }
-    }
+       /* If we have color filters, "search" for the matching one. */
+       if (color_filters_used()) {
+               curr = color_filter_list;
+
+               while(curr != NULL) {
+                       colorf = (color_filter_t *)curr->data;
+                       if ( (!colorf->disabled) &&
+                            (colorf->c_colorfilter != NULL) &&
+                            dfilter_apply_edt(colorf->c_colorfilter, edt)) {
+                               return colorf;
+                       }
+                       curr = g_slist_next(curr);
+               }
+       }
 
-    return NULL;
+       return NULL;
 }
 
 /* read filters from the given file */
@@ -487,8 +477,8 @@ read_filters_file(FILE *f, gpointer user_data)
        gboolean disabled = FALSE;
        gboolean skip_end_of_line = FALSE;
 
-       name = g_malloc(name_len + 1);
-       filter_exp = g_malloc(filter_exp_len + 1);
+       name = (gchar *)g_malloc(name_len + 1);
+       filter_exp = (gchar *)g_malloc(filter_exp_len + 1);
 
        while (1) {
 
@@ -536,7 +526,7 @@ read_filters_file(FILE *f, gpointer user_data)
                        if (i >= name_len) {
                                /* buffer isn't long enough; double its length.*/
                                name_len *= 2;
-                               name = g_realloc(name, name_len + 1);
+                               name = (gchar *)g_realloc(name, name_len + 1);
                        }
                        name[i++] = c;
                }
@@ -558,7 +548,7 @@ read_filters_file(FILE *f, gpointer user_data)
                        if (i >= filter_exp_len) {
                                /* buffer isn't long enough; double its length.*/
                                filter_exp_len *= 2;
-                               filter_exp = g_realloc(filter_exp, filter_exp_len + 1);
+                               filter_exp = (gchar *)g_realloc(filter_exp, filter_exp_len + 1);
                        }
                        filter_exp[i++] = c;
                }
@@ -582,9 +572,8 @@ read_filters_file(FILE *f, gpointer user_data)
                        dfilter_t *temp_dfilter;
 
                        if (!dfilter_compile(filter_exp, &temp_dfilter)) {
-                               simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                               "Could not compile color filter %s from saved filters.\n%s",
-                                             name, dfilter_error_msg);
+                               g_warning("Could not compile color filter \"%s\" from saved filters: %s",
+                                       name, dfilter_error_msg);
                                skip_end_of_line = TRUE;
                                continue;
                        }
@@ -646,7 +635,7 @@ read_users_filters(GSList **cfl)
                if (errno != ENOENT) {
                        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Could not open filter file\n\"%s\": %s.", path,
-                           strerror(errno));
+                           g_strerror(errno));
                }
                g_free(path);
                return FALSE;
@@ -673,7 +662,7 @@ color_filters_read_globals(gpointer user_data)
                if (errno != ENOENT) {
                        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Could not open global filter file\n\"%s\": %s.", path,
-                           strerror(errno));
+                           g_strerror(errno));
                }
                g_free(path);
                return FALSE;
@@ -696,7 +685,7 @@ color_filters_import(gchar *path, gpointer user_data)
        if ((f = ws_fopen(path, "r")) == NULL) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Could not open\n%s\nfor reading: %s.",
-                   path, strerror(errno));
+                   path, g_strerror(errno));
                return FALSE;
        }
 
@@ -707,20 +696,20 @@ color_filters_import(gchar *path, gpointer user_data)
 
 struct write_filter_data
 {
-  FILE * f;
-  gboolean only_selected;
+       FILE * f;
+       gboolean only_selected;
 };
 
 /* save a single filter */
 static void
 write_filter(gpointer filter_arg, gpointer data_arg)
 {
-       struct write_filter_data *data = data_arg;
-       color_filter_t *colorf = filter_arg;
+       struct write_filter_data *data = (struct write_filter_data *)data_arg;
+       color_filter_t *colorf = (color_filter_t *)filter_arg;
        FILE *f = data->f;
 
        if ( (colorf->selected || !data->only_selected) &&
-             (strstr(colorf->filter_name,TEMP_COLOR_PREFIX)==NULL) ) {
+             (strstr(colorf->filter_name,CONVERSATION_COLOR_PREFIX)==NULL) ) {
                fprintf(f,"%s@%s@%s@[%d,%d,%d][%d,%d,%d]\n",
                    colorf->disabled ? "!" : "",
                    colorf->filter_name,
@@ -761,7 +750,7 @@ color_filters_write(GSList *cfl)
        if (create_persconffile_dir(&pf_dir_path) == -1) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Can't create directory\n\"%s\"\nfor color files: %s.",
-                   pf_dir_path, strerror(errno));
+                   pf_dir_path, g_strerror(errno));
                g_free(pf_dir_path);
                return FALSE;
        }
@@ -770,7 +759,7 @@ color_filters_write(GSList *cfl)
        if ((f = ws_fopen(path, "w+")) == NULL) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Could not open\n%s\nfor writing: %s.",
-                   path, strerror(errno));
+                   path, g_strerror(errno));
                g_free(path);
                return FALSE;
        }
@@ -789,7 +778,7 @@ color_filters_export(gchar *path, GSList *cfl, gboolean only_marked)
        if ((f = ws_fopen(path, "w+")) == NULL) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                    "Could not open\n%s\nfor writing: %s.",
-                   path, strerror(errno));
+                   path, g_strerror(errno));
                return FALSE;
        }
        write_filters_file(cfl, f, only_marked);