diff options
Diffstat (limited to 'epan/ftypes')
-rw-r--r-- | epan/ftypes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 15 | ||||
-rw-r--r-- | epan/ftypes/ftype-pcre.c | 164 | ||||
-rw-r--r-- | epan/ftypes/ftype-protocol.c | 12 | ||||
-rw-r--r-- | epan/ftypes/ftype-string.c | 14 | ||||
-rw-r--r-- | epan/ftypes/ftypes-int.h | 3 | ||||
-rw-r--r-- | epan/ftypes/ftypes.c | 7 | ||||
-rw-r--r-- | epan/ftypes/ftypes.h | 3 |
8 files changed, 12 insertions, 207 deletions
diff --git a/epan/ftypes/CMakeLists.txt b/epan/ftypes/CMakeLists.txt index 31a4607889..0346c1ccf2 100644 --- a/epan/ftypes/CMakeLists.txt +++ b/epan/ftypes/CMakeLists.txt @@ -26,7 +26,6 @@ set(FTYPE_FILES ftype-ipv6.c ftype-guid.c ftype-none.c - ftype-pcre.c ftype-protocol.c ftype-string.c ftype-time.c diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index ee15aa508e..dc414e3e62 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -650,21 +650,10 @@ cmp_contains(const fvalue_t *fv_a, const fvalue_t *fv_b) } static gboolean -cmp_matches(const fvalue_t *fv_a, const fvalue_t *fv_b) +cmp_matches(const fvalue_t *fv, const GRegex *regex) { - GByteArray *a = fv_a->value.bytes; - GRegex *regex = fv_b->value.re; + GByteArray *a = fv->value.bytes; - /* fv_b is always a FT_PCRE, otherwise the dfilter semcheck() would have - * warned us. For the same reason (and because we're using g_malloc()), - * fv_b->value.re is not NULL. - */ - if (strcmp(fv_b->ftype->name, "FT_PCRE") != 0) { - return FALSE; - } - if (! regex) { - return FALSE; - } return g_regex_match_full( regex, /* Compiled PCRE */ (char *)a->data, /* The data to check for the pattern... */ diff --git a/epan/ftypes/ftype-pcre.c b/epan/ftypes/ftype-pcre.c deleted file mode 100644 index 854d957ee4..0000000000 --- a/epan/ftypes/ftype-pcre.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * Copyright 2001 Gerald Combs - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -/* Perl-Compatible Regular Expression (PCRE) internal field type. - * Used with the "matches" dfilter operator, allowing efficient - * compilation and studying of a PCRE pattern in dfilters. - */ - -#include "config.h" - -#include <ftypes-int.h> - -#include <glib.h> -#include <string.h> - -static void -gregex_fvalue_new(fvalue_t *fv) -{ - fv->value.re = NULL; -} - -static void -gregex_fvalue_free(fvalue_t *fv) -{ - if (fv->value.re) { - g_regex_unref(fv->value.re); - fv->value.re = NULL; - } -} - -/* Generate a FT_PCRE from a parsed string pattern. - * On failure, if err_msg is non-null, set *err_msg to point to a - * g_malloc()ed error message. */ -static gboolean -val_from_string(fvalue_t *fv, const char *pattern, gchar **err_msg) -{ - GError *regex_error = NULL; - GRegexCompileFlags cflags = (GRegexCompileFlags)(G_REGEX_CASELESS | G_REGEX_OPTIMIZE); - - /* - * As FT_BYTES and FT_PROTOCOL contain arbitrary binary data and FT_STRING - * is not guaranteed to contain valid UTF-8, we have to disable support for - * UTF-8 patterns and treat every pattern and subject as raw bytes. - * - * Should support for UTF-8 patterns be necessary, then we should compile a - * pattern without G_REGEX_RAW. Additionally, we MUST use g_utf8_validate() - * before calling g_regex_match_full() or risk crashes. - */ - cflags = (GRegexCompileFlags)(cflags | G_REGEX_RAW); - - /* Free up the old value, if we have one */ - gregex_fvalue_free(fv); - - fv->value.re = g_regex_new( - pattern, /* pattern */ - cflags, /* Compile options */ - (GRegexMatchFlags)0, /* Match options */ - ®ex_error /* Compile / study errors */ - ); - - if (regex_error) { - if (err_msg) { - *err_msg = g_strdup(regex_error->message); - } - g_error_free(regex_error); - if (fv->value.re) { - g_regex_unref(fv->value.re); - } - return FALSE; - } - return TRUE; -} - -/* Generate a FT_PCRE from an unparsed string pattern. - * On failure, if err_msg is non-null, set *err_msg to point to a - * g_malloc()ed error message. */ -static gboolean -val_from_unparsed(fvalue_t *fv, const char *pattern, gboolean allow_partial_value, gchar **err_msg) -{ - g_assert(! allow_partial_value); - - return val_from_string(fv, pattern, err_msg); -} - -static int -gregex_repr_len(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_) -{ - return (int)strlen(g_regex_get_pattern(fv->value.re)); -} - -static void -gregex_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) -{ - g_strlcpy(buf, g_regex_get_pattern(fv->value.re), size); -} - -/* BEHOLD - value contains the string representation of the regular expression, - * and we want to store the compiled PCRE RE object into the value. */ -static void -gregex_fvalue_set(fvalue_t *fv, const char *value) -{ - g_assert(value != NULL); - /* Free up the old value, if we have one */ - gregex_fvalue_free(fv); - val_from_unparsed(fv, value, FALSE, NULL); -} - -static gpointer -gregex_fvalue_get(fvalue_t *fv) -{ - return fv->value.re; -} - -void -ftype_register_pcre(void) -{ - static ftype_t pcre_type = { - FT_PCRE, /* ftype */ - "FT_PCRE", /* name */ - "Compiled Perl-Compatible Regular Expression (GRegex) object", /* pretty_name */ - 0, /* wire_size */ - gregex_fvalue_new, /* new_value */ - gregex_fvalue_free, /* free_value */ - val_from_unparsed, /* val_from_unparsed */ - val_from_string, /* val_from_string */ - gregex_to_repr, /* val_to_string_repr */ - gregex_repr_len, /* len_string_repr */ - - { .set_value_string = gregex_fvalue_set }, /* union set_value */ - { .get_value_ptr = gregex_fvalue_get }, /* union get_value */ - - NULL, /* cmp_eq */ - NULL, /* cmp_ne */ - NULL, /* cmp_gt */ - NULL, /* cmp_ge */ - NULL, /* cmp_lt */ - NULL, /* cmp_le */ - NULL, /* cmp_bitwise_and */ - NULL, /* cmp_contains */ - NULL, /* cmp_matches */ - - NULL, /* len */ - NULL, /* slice */ - }; - ftype_register(FT_PCRE, &pcre_type); -} - -/* - * Editor modelines - https://www.wireshark.org/tools/modelines.html - * - * Local variables: - * c-basic-offset: 4 - * tab-width: 8 - * indent-tabs-mode: nil - * End: - * - * vi: set shiftwidth=4 tabstop=8 expandtab: - * :indentSize=4:tabSize=8:noTabs=true: - */ diff --git a/epan/ftypes/ftype-protocol.c b/epan/ftypes/ftype-protocol.c index 71ffae00c0..b3dc5328a5 100644 --- a/epan/ftypes/ftype-protocol.c +++ b/epan/ftypes/ftype-protocol.c @@ -383,21 +383,13 @@ cmp_contains(const fvalue_t *fv_a, const fvalue_t *fv_b) } static gboolean -cmp_matches(const fvalue_t *fv_a, const fvalue_t *fv_b) +cmp_matches(const fvalue_t *fv, const GRegex *regex) { - const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol; - GRegex *regex = fv_b->value.re; + const protocol_value_t *a = (const protocol_value_t *)&fv->value.protocol; volatile gboolean rc = FALSE; const char *data = NULL; /* tvb data */ guint32 tvb_len; /* tvb length */ - /* fv_b is always a FT_PCRE, otherwise the dfilter semcheck() would have - * warned us. For the same reason (and because we're using g_malloc()), - * fv_b->value.re is not NULL. - */ - if (strcmp(fv_b->ftype->name, "FT_PCRE") != 0) { - return FALSE; - } if (! regex) { return FALSE; } diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index f6813d3b30..c42f08d928 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -186,18 +186,10 @@ cmp_contains(const fvalue_t *fv_a, const fvalue_t *fv_b) } static gboolean -cmp_matches(const fvalue_t *fv_a, const fvalue_t *fv_b) +cmp_matches(const fvalue_t *fv, const GRegex *regex) { - char *str = fv_a->value.string; - GRegex *regex = fv_b->value.re; - - /* fv_b is always a FT_PCRE, otherwise the dfilter semcheck() would have - * warned us. For the same reason (and because we're using g_malloc()), - * fv_b->value.re is not NULL. - */ - if (strcmp(fv_b->ftype->name, "FT_PCRE") != 0) { - return FALSE; - } + char *str = fv->value.string; + if (! regex) { return FALSE; } diff --git a/epan/ftypes/ftypes-int.h b/epan/ftypes/ftypes-int.h index 30051acd41..98af5997c2 100644 --- a/epan/ftypes/ftypes-int.h +++ b/epan/ftypes/ftypes-int.h @@ -62,6 +62,7 @@ typedef gint64 (*FvalueGetSignedInteger64Func)(fvalue_t*); typedef double (*FvalueGetFloatingFunc)(fvalue_t*); typedef gboolean (*FvalueCmp)(const fvalue_t*, const fvalue_t*); +typedef gboolean (*FvalueMatches)(const fvalue_t*, const GRegex*); typedef guint (*FvalueLen)(fvalue_t*); typedef void (*FvalueSlice)(fvalue_t*, GByteArray *, guint offset, guint length); @@ -109,7 +110,7 @@ struct _ftype_t { FvalueCmp cmp_le; FvalueCmp cmp_bitwise_and; FvalueCmp cmp_contains; - FvalueCmp cmp_matches; + FvalueMatches cmp_matches; FvalueLen len; FvalueSlice slice; diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index e62582ab79..a8a4838ffa 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -31,7 +31,6 @@ ftypes_initialize(void) ftype_register_string(); ftype_register_time(); ftype_register_tvbuff(); - ftype_register_pcre(); } /* Each ftype_t is registered via this function */ @@ -528,8 +527,7 @@ void fvalue_set_string(fvalue_t *fv, const gchar *value) { g_assert(IS_FT_STRING(fv->ftype->ftype) || - fv->ftype->ftype == FT_UINT_STRING || - fv->ftype->ftype == FT_PCRE); + fv->ftype->ftype == FT_UINT_STRING); g_assert(fv->ftype->set_value.set_value_string); fv->ftype->set_value.set_value_string(fv, value); } @@ -618,7 +616,6 @@ fvalue_get(fvalue_t *fv) fv->ftype->ftype == FT_FCWWN || fv->ftype->ftype == FT_GUID || fv->ftype->ftype == FT_IPv6 || - fv->ftype->ftype == FT_PCRE || fv->ftype->ftype == FT_PROTOCOL || IS_FT_STRING(fv->ftype->ftype) || fv->ftype->ftype == FT_UINT_STRING || @@ -753,7 +750,7 @@ fvalue_contains(const fvalue_t *a, const fvalue_t *b) } gboolean -fvalue_matches(const fvalue_t *a, const fvalue_t *b) +fvalue_matches(const fvalue_t *a, const GRegex *b) { /* XXX - check compatibility of a and b */ g_assert(a->ftype->cmp_matches); diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index 197c1d58a2..740b0e0280 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -58,7 +58,6 @@ enum ftenum { FT_IPv6, FT_IPXNET, FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that number */ - FT_PCRE, /* a compiled Perl-Compatible Regular Expression object */ FT_GUID, /* GUID, UUID */ FT_OID, /* OBJECT IDENTIFIER */ FT_EUI64, @@ -370,7 +369,7 @@ gboolean fvalue_contains(const fvalue_t *a, const fvalue_t *b); gboolean -fvalue_matches(const fvalue_t *a, const fvalue_t *b); +fvalue_matches(const fvalue_t *a, const GRegex *b); guint fvalue_length(fvalue_t *fv); |