From 0ebc01dc03e38726e3d6fdffb30171eda3f8f80e Mon Sep 17 00:00:00 2001 From: Stephen Fisher Date: Tue, 13 Feb 2007 20:57:22 +0000 Subject: [PATCH] From Sebastien Tandel: Create two new files (ws_strsplit.[ch]) that use GTK2 code to override the buggy g_strsplit() function when compiling for GTK1. Include this work-around function (ws_strsplit) in libwireshark.def. Add notes on usage to README.developer. Include epan/ws_strsplit.h in all files that use g_strsplit(). svn path=/trunk/; revision=20804 --- doc/README.developer | 6 +++ epan/Makefile.common | 2 + epan/crypt/airpdcap.c | 1 + epan/dissectors/packet-http.c | 1 + epan/dissectors/packet-jxta.c | 1 + epan/dissectors/packet-k12.c | 1 + epan/ex-opt.c | 1 + epan/libwireshark.def | 1 + epan/stats_tree.c | 71 +++++++++++++--------------- epan/ws_strsplit.c | 82 +++++++++++++++++++++++++++++++++ epan/ws_strsplit.h | 41 +++++++++++++++++ gtk/font_utils.c | 1 + gtk/voip_calls.c | 1 + gtk/webbrowser.c | 1 + plugins/mate/mate_grammar.lemon | 1 + plugins/mate/mate_setup.c | 1 + plugins/mate/mate_util.c | 1 + tap-funnel.c | 1 + util.c | 1 + 19 files changed, 178 insertions(+), 38 deletions(-) create mode 100644 epan/ws_strsplit.c create mode 100644 epan/ws_strsplit.h diff --git a/doc/README.developer b/doc/README.developer index a27c8f3174..3032263502 100644 --- a/doc/README.developer +++ b/doc/README.developer @@ -433,6 +433,12 @@ automatically free()d when the dissection of the current packet ends so you don't have to worry about free()ing them explicitly in order to not leak memory. Please read README.malloc. +When using g_strsplit() from glib, place an #include at +the top of your file. This file will leave in place g_strsplit() when using +GTK/GLib v2 and replace it with GLib v2 code when compiling for GTK/GLib 1. +This is necessary because the GLib v1 version of g_strsplit is known to be +buggy. In either case, you will still use the g_strsplit() function name +as usual in your code. 1.1.3 Robustness. diff --git a/epan/Makefile.common b/epan/Makefile.common index febc2a8319..108fe0cbfb 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -91,6 +91,7 @@ LIBWIRESHARK_SRC = \ uat_load.c \ unicode-utils.c \ value_string.c \ + ws_strsplit.c \ xdlc.c \ xmlstub.c @@ -190,6 +191,7 @@ LIBWIRESHARK_INCLUDES = \ uat-int.h \ unicode-utils.h \ value_string.h \ + ws_strsplit.h \ x264_prt_id.h \ xdlc.h \ xmlstub.h diff --git a/epan/crypt/airpdcap.c b/epan/crypt/airpdcap.c index aa7f6e5069..08754033bf 100644 --- a/epan/crypt/airpdcap.c +++ b/epan/crypt/airpdcap.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "airpdcap_system.h" #include "airpdcap_int.h" diff --git a/epan/dissectors/packet-http.c b/epan/dissectors/packet-http.c index ddacf2de9f..71df1e16fc 100644 --- a/epan/dissectors/packet-http.c +++ b/epan/dissectors/packet-http.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include "packet-http.h" diff --git a/epan/dissectors/packet-jxta.c b/epan/dissectors/packet-jxta.c index 25d30cf58a..97c58da391 100644 --- a/epan/dissectors/packet-jxta.c +++ b/epan/dissectors/packet-jxta.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "packet-jxta.h" diff --git a/epan/dissectors/packet-k12.c b/epan/dissectors/packet-k12.c index c62959b11c..ef98bf6613 100644 --- a/epan/dissectors/packet-k12.c +++ b/epan/dissectors/packet-k12.c @@ -41,6 +41,7 @@ #include #include "packet-sscop.h" #include "packet-umts_fp.h" +#include typedef struct _k12_hdls_t { char* match; diff --git a/epan/ex-opt.c b/epan/ex-opt.c index f584324c8e..3731572d52 100644 --- a/epan/ex-opt.c +++ b/epan/ex-opt.c @@ -32,6 +32,7 @@ #include #include "ex-opt.h" +#include static GHashTable* ex_opts = NULL; diff --git a/epan/libwireshark.def b/epan/libwireshark.def index ce9ec2e9cf..206fd6ffcc 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -802,4 +802,5 @@ vals_status DATA val_to_str value_is_in_range write_prefs +ws_strsplit xml_escape diff --git a/epan/stats_tree.c b/epan/stats_tree.c index dd4e8f0161..02ca8a90bd 100644 --- a/epan/stats_tree.c +++ b/epan/stats_tree.c @@ -29,6 +29,7 @@ #include #include +#include #include #include "stats_tree.h" @@ -541,48 +542,42 @@ extern guint8* stats_tree_get_abbr(const guint8* optarg) { * */ static range_pair_t* get_range(guint8* rngstr) { - gchar** split; - range_pair_t* rng; - - split = g_strsplit((gchar*)rngstr,"-",2); + gchar** split; + range_pair_t* rng; - /* empty string */ - if (split[0] == NULL) { - g_strfreev(split); - return NULL; - } + split = g_strsplit((gchar*)rngstr,"-",2); -#if GLIB_MAJOR_VERSION >= 2 - /* means we have a non empty string - * which does not contain a delimiter */ - if (split[1] == NULL) { - g_strfreev(split); - return NULL; - } -#endif + /* empty string */ + if (split[0] == NULL) { + g_strfreev(split); + return NULL; + } - rng = g_malloc(sizeof(range_pair_t)); + /* means we have a non empty string + * which does not contain a delimiter */ + if (split[1] == NULL) { + g_strfreev(split); + return NULL; + } - /* string == "X-?" */ - if (*(split[0]) != '\0') { - rng->floor = strtol(split[0],NULL,10); - } else - /* string == "-?" */ - rng->floor = G_MININT; + rng = g_malloc(sizeof(range_pair_t)); + + /* string == "X-?" */ + if (*(split[0]) != '\0') { + rng->floor = strtol(split[0],NULL,10); + } else + /* string == "-?" */ + rng->floor = G_MININT; + + /* string != "?-" */ + if (*(split[1]) != '\0') { + rng->ceil = strtol(split[1],NULL,10); + } else + /* string == "?-" */ + rng->ceil = G_MAXINT; + + g_strfreev(split); - /* string != "?-" */ -#if GLIB_MAJOR_VERSION >= 2 - if (*(split[1]) != '\0') { -#else - if (split[1] != NULL) { -#endif - rng->ceil = strtol(split[1],NULL,10); - } else - /* string == "?-" */ - rng->ceil = G_MAXINT; - - g_strfreev(split); - return rng; } @@ -595,7 +590,7 @@ extern int stats_tree_create_range_node(stats_tree* st, guint8* curr_range; stat_node* rng_root = new_stat_node(st, name, parent_id, FALSE, TRUE); stat_node* range_node = NULL; - + va_start( list, parent_id ); while (( curr_range = va_arg(list, guint8*) )) { range_node = new_stat_node(st, curr_range, rng_root->id, FALSE, FALSE); diff --git a/epan/ws_strsplit.c b/epan/ws_strsplit.c new file mode 100644 index 0000000000..b0f02e7122 --- /dev/null +++ b/epan/ws_strsplit.c @@ -0,0 +1,82 @@ +/* ws_strsplit.c + * String Split utility function + * Code borrowed from GTK2 to override the GTK1 version of g_strsplit, which is + * known to be buggy. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + +#if GLIB_MAJOR_VERSION < 2 +#include +#include + +gchar** ws_strsplit ( const gchar *string, + const gchar *delimiter, + gint max_tokens) +{ + GSList *string_list = NULL, *slist; + gchar **str_array, *s; + guint n = 0; + const gchar *remainder; + + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (delimiter != NULL, NULL); + g_return_val_if_fail (delimiter[0] != '\0', NULL); + + if (max_tokens < 1) + max_tokens = G_MAXINT; + + remainder = string; + s = strstr (remainder, delimiter); + if (s) { + gsize delimiter_len = strlen (delimiter); + + while (--max_tokens && s) { + gsize len; + gchar *new_string; + + len = s - remainder; + new_string = g_new (gchar, len + 1); + strncpy (new_string, remainder, len); + new_string[len] = 0; + string_list = g_slist_prepend (string_list, new_string); + n++; + remainder = s + delimiter_len; + s = strstr (remainder, delimiter); + } + } + if (*string) { + n++; + string_list = g_slist_prepend (string_list, g_strdup (remainder)); + } + + str_array = g_new (gchar*, n + 1); + + str_array[n--] = NULL; + for (slist = string_list; slist; slist = slist->next) + str_array[n--] = slist->data; + + g_slist_free (string_list); + + return str_array; +} + +#endif /* GLIB_MAJOR_VERSION */ diff --git a/epan/ws_strsplit.h b/epan/ws_strsplit.h new file mode 100644 index 0000000000..3f5280a0b1 --- /dev/null +++ b/epan/ws_strsplit.h @@ -0,0 +1,41 @@ +/* ws_strsplit.h + * String Split utility function + * Code borrowed from GTK2 to override the GTK1 version of g_strsplit, which is + * known to be buggy. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + +#ifndef __WS_STRSPLIT_H__ +#define __WS_STRSPLIT_H__ + +#if GLIB_MAJOR_VERSION < 2 + +#define g_strsplit(s, d, t) ws_strsplit(s, d, t) + +gchar ** ws_strsplit (const gchar *string, + const gchar *delimiter, + gint max_tokens); + +#endif /* GLIB_MAJOR_VERSION */ + +#endif /* __WS_STRSPLIT_H__ */ + diff --git a/gtk/font_utils.c b/gtk/font_utils.c index fb5da32635..11875fc09f 100644 --- a/gtk/font_utils.c +++ b/gtk/font_utils.c @@ -32,6 +32,7 @@ #include #include +#include #ifdef _WIN32 #include diff --git a/gtk/voip_calls.c b/gtk/voip_calls.c index daadca553c..18a763bd30 100644 --- a/gtk/voip_calls.c +++ b/gtk/voip_calls.c @@ -61,6 +61,7 @@ #include #include #include +#include #include "alert_box.h" #include "simple_dialog.h" diff --git a/gtk/webbrowser.c b/gtk/webbrowser.c index 4520704f67..ff069c98da 100644 --- a/gtk/webbrowser.c +++ b/gtk/webbrowser.c @@ -35,6 +35,7 @@ #include #include +#include #include #include "webbrowser.h" diff --git a/plugins/mate/mate_grammar.lemon b/plugins/mate/mate_grammar.lemon index b575b49634..d57e109aac 100644 --- a/plugins/mate/mate_grammar.lemon +++ b/plugins/mate/mate_grammar.lemon @@ -28,6 +28,7 @@ #include "mate.h" #include "mate_grammar.h" +#include #define DUMMY void* diff --git a/plugins/mate/mate_setup.c b/plugins/mate/mate_setup.c index f0fa63145c..c9146eee50 100644 --- a/plugins/mate/mate_setup.c +++ b/plugins/mate/mate_setup.c @@ -25,6 +25,7 @@ */ #include "mate.h" +#include /* the current mate_config */ static mate_config* matecfg = NULL; diff --git a/plugins/mate/mate_util.c b/plugins/mate/mate_util.c index 7108c215e4..c93512dd31 100644 --- a/plugins/mate/mate_util.c +++ b/plugins/mate/mate_util.c @@ -28,6 +28,7 @@ #include "mate.h" #include "mate_util.h" #include +#include /*************************************************************************** * dbg_print diff --git a/tap-funnel.c b/tap-funnel.c index 7fed0d2f9d..f15b4d77b5 100644 --- a/tap-funnel.c +++ b/tap-funnel.c @@ -30,6 +30,7 @@ #include #include #include +#include struct _funnel_text_window_t { diff --git a/util.c b/util.c index d5e2308811..80fe8d8f1e 100644 --- a/util.c +++ b/util.c @@ -39,6 +39,7 @@ #include #include +#include #include "util.h"