TODO: packet-smb2: setup decryption keys for kerberos session setups
[metze/wireshark/wip.git] / filters.c
index f73b7141f75c7928f103cbb06aefe450374e3115..68eb9e418f00f6f735821f38ecbc8c04e9c58200 100644 (file)
--- a/filters.c
+++ b/filters.c
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include <stdio.h>
 #include <string.h>
 
 #include <glib.h>
 
-#include <epan/filesystem.h>
+#include <wsutil/file_util.h>
+#include <wsutil/filesystem.h>
 
 #include "filters.h"
-#include <wsutil/file_util.h>
 
 /*
  * Old filter file name.
@@ -145,7 +143,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
   }
 
   /* try to open personal "cfilters"/"dfilters" file */
-  ff_path = get_persconffile_path(ff_name, TRUE, FALSE);
+  ff_path = get_persconffile_path(ff_name, TRUE);
   if ((ff = ws_fopen(ff_path, "r")) == NULL) {
     /*
      * Did that fail because the file didn't exist?
@@ -168,7 +166,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
      * a particular list.
      */
     g_free(ff_path);
-    ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE, FALSE);
+    ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE);
     if ((ff = ws_fopen(ff_path, "r")) == NULL) {
       /*
        * Did that fail because the file didn't exist?
@@ -211,9 +209,9 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
 
   /* Allocate the filter name buffer. */
   filt_name_len = INIT_BUF_SIZE;
-  filt_name = g_malloc(filt_name_len + 1);
+  filt_name = (char *)g_malloc(filt_name_len + 1);
   filt_expr_len = INIT_BUF_SIZE;
-  filt_expr = g_malloc(filt_expr_len + 1);
+  filt_expr = (char *)g_malloc(filt_expr_len + 1);
 
   for (line = 1; ; line++) {
     /* Lines in a filter file are of the form
@@ -257,7 +255,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
        if (filt_name_index >= filt_name_len) {
          /* Filter name buffer isn't long enough; double its length. */
          filt_name_len *= 2;
-         filt_name = g_realloc(filt_name, filt_name_len + 1);
+         filt_name = (char *)g_realloc(filt_name, filt_name_len + 1);
        }
        filt_name[filt_name_index] = '\0';
        break;
@@ -272,7 +270,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
       if (filt_name_index >= filt_name_len) {
        /* Filter name buffer isn't long enough; double its length. */
        filt_name_len *= 2;
-       filt_name = g_realloc(filt_name, filt_name_len + 1);
+       filt_name = (char *)g_realloc(filt_name, filt_name_len + 1);
       }
       filt_name[filt_name_index] = c;
       filt_name_index++;
@@ -324,7 +322,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
       if (filt_expr_index >= filt_expr_len) {
        /* Filter expressioin buffer isn't long enough; double its length. */
        filt_expr_len *= 2;
-       filt_expr = g_realloc(filt_expr, filt_expr_len + 1);
+       filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1);
       }
       filt_expr[filt_expr_index] = c;
       filt_expr_index++;
@@ -348,7 +346,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
     if (filt_expr_index >= filt_expr_len) {
       /* Filter expressioin buffer isn't long enough; double its length. */
       filt_expr_len *= 2;
-      filt_expr = g_realloc(filt_expr, filt_expr_len + 1);
+      filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1);
     }
     filt_expr[filt_expr_index] = '\0';
 
@@ -490,7 +488,7 @@ save_filter_list(filter_list_type_t list_type, char **pref_path_return,
     return;
   }
 
-  ff_path = get_persconffile_path(ff_name, TRUE, TRUE);
+  ff_path = get_persconffile_path(ff_name, TRUE);
 
   /* Write to "XXX.new", and rename if that succeeds.
      That means we don't trash the file if we fail to write it out
@@ -544,7 +542,14 @@ save_filter_list(filter_list_type_t list_type, char **pref_path_return,
   /* ANSI C doesn't say whether "rename()" removes the target if it
      exists; the Win32 call to rename files doesn't do so, which I
      infer is the reason why the MSVC++ "rename()" doesn't do so.
-     We must therefore remove the target file first, on Windows. */
+     We must therefore remove the target file first, on Windows.
+
+     XXX - ws_rename() should be ws_stdio_rename() on Windows,
+     and ws_stdio_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING,
+     so it should remove the target if it exists, so this stuff
+     shouldn't be necessary.  Perhaps it dates back to when we were
+     calling rename(), with that being a wrapper around Microsoft's
+     _rename(), which didn't remove the target. */
   if (ws_remove(ff_path) < 0 && errno != ENOENT) {
     /* It failed for some reason other than "it's not there"; if
        it's not there, we don't need to remove it, so we just
@@ -582,8 +587,6 @@ void copy_filter_list(filter_list_type_t dest_type, filter_list_type_t src_type)
 
     flpp_dest = get_filter_list(dest_type);
     flpp_src = get_filter_list(src_type);
-    flp_src = *flpp_src;
-
     /* throw away the "old" destination list - a NULL list is ok here */
     while(*flpp_dest) {
         *flpp_dest = remove_filter_entry(*flpp_dest, g_list_first(*flpp_dest));
@@ -591,11 +594,10 @@ void copy_filter_list(filter_list_type_t dest_type, filter_list_type_t src_type)
     g_assert(g_list_length(*flpp_dest) == 0);
 
     /* copy the list entries */
-    while(flp_src) {
-        filt = (flp_src)->data;
+    for(flp_src = g_list_first(*flpp_src); flp_src; flp_src = g_list_next(flp_src)) {
+        filt = (filter_def *)(flp_src->data);
 
         *flpp_dest = add_filter_entry(*flpp_dest, filt->name, filt->strval);
-        flp_src = g_list_next(flp_src);
     }
 }