aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-string.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2009-12-18 01:15:08 +0000
committerGerald Combs <gerald@wireshark.org>2009-12-18 01:15:08 +0000
commit7c0dc5d7e7a479d497f0e991158a60ae89a35f74 (patch)
tree1d7a312d77cd21c4d65f74e46f8214079c3f610b /epan/ftypes/ftype-string.c
parent7524c0b96314b87ca6a2c8f4dbf14770277ef31a (diff)
If we don't have PCRE and we do have GLib >= 2.14, use GRegexes for the
"matches" operator. svn path=/trunk/; revision=31302
Diffstat (limited to 'epan/ftypes/ftype-string.c')
-rw-r--r--epan/ftypes/ftype-string.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c
index 18754d7cc0..a3571bab23 100644
--- a/epan/ftypes/ftype-string.c
+++ b/epan/ftypes/ftype-string.c
@@ -28,8 +28,10 @@
#include <ftypes-int.h>
#include <string.h>
-#ifdef HAVE_LIBPCRE
-#include <pcre.h>
+#if defined(HAVE_LIBPCRE) || GLIB_CHECK_VERSION(2,14,0)
+# ifdef HAVE_LIBPCRE
+# include <pcre.h>
+# endif
#define CMP_MATCHES cmp_matches
#else
#define CMP_MATCHES NULL
@@ -286,7 +288,34 @@ cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b)
}
return FALSE;
}
-#endif
+#elif GLIB_CHECK_VERSION(2,14,0) /* GRegex */
+static gboolean
+cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b)
+{
+ 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;
+ }
+ if (! regex) {
+ return FALSE;
+ }
+ return g_regex_match_full(
+ regex, /* Compiled PCRE */
+ str, /* The data to check for the pattern... */
+ (int)strlen(str), /* ... and its length */
+ 0, /* Start offset within data */
+ 0, /* GRegexMatchFlags */
+ NULL, /* We are not interested in the match information */
+ NULL /* We don't want error information */
+ );
+}
+#endif /* HAVE_LIBPCRE / GRegex */
void
ftype_register_string(void)