diff options
author | Stephen Fisher <steve@stephen-fisher.com> | 2007-02-13 20:57:22 +0000 |
---|---|---|
committer | Stephen Fisher <steve@stephen-fisher.com> | 2007-02-13 20:57:22 +0000 |
commit | 0ebc01dc03e38726e3d6fdffb30171eda3f8f80e (patch) | |
tree | 9b8f6907fd7e6bd7e99afd8632d22b61eed1452c /epan | |
parent | 1ebd7feda946b60b3a1c9841d282bfb7bd6b3b86 (diff) |
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
Diffstat (limited to 'epan')
-rw-r--r-- | epan/Makefile.common | 2 | ||||
-rw-r--r-- | epan/crypt/airpdcap.c | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-http.c | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-jxta.c | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-k12.c | 1 | ||||
-rw-r--r-- | epan/ex-opt.c | 1 | ||||
-rw-r--r-- | epan/libwireshark.def | 1 | ||||
-rw-r--r-- | epan/stats_tree.c | 71 | ||||
-rw-r--r-- | epan/ws_strsplit.c | 82 | ||||
-rw-r--r-- | epan/ws_strsplit.h | 41 |
10 files changed, 164 insertions, 38 deletions
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 <epan/tvbuff.h> #include <epan/crc32.h> #include <epan/strutil.h> +#include <epan/ws_strsplit.h> #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 <epan/base64.h> #include <epan/emem.h> #include <epan/stats_tree.h> +#include <epan/ws_strsplit.h> #include <epan/req_resp_hdrs.h> #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 <epan/prefs.h> #include <epan/tap.h> #include <epan/emem.h> +#include <epan/ws_strsplit.h> #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 <epan/strutil.h> #include "packet-sscop.h" #include "packet-umts_fp.h" +#include <epan/ws_strsplit.h> 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 <glib.h> #include "ex-opt.h" +#include <epan/ws_strsplit.h> 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 <glib.h> #include <epan/stats_tree_priv.h> +#include <epan/ws_strsplit.h> #include <string.h> #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 <gerald@wireshark.org> + * 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 <glib.h> +#include <string.h> + +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 <gerald@wireshark.org> + * 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__ */ + |