diff options
author | Olivier Biot <obiot.ethereal@gmail.com> | 2003-12-18 13:02:19 +0000 |
---|---|---|
committer | Olivier Biot <obiot.ethereal@gmail.com> | 2003-12-18 13:02:19 +0000 |
commit | 7b1c1a94977bf60ef4f5151a5abccc07d8ee08cf (patch) | |
tree | 893c4a99bd4663ff0b95cf7db6d866050732796f /epan | |
parent | a98aa75a5856d1e340413308ad1b0d24276a6a30 (diff) | |
download | wireshark-7b1c1a94977bf60ef4f5151a5abccc07d8ee08cf.tar.gz wireshark-7b1c1a94977bf60ef4f5151a5abccc07d8ee08cf.tar.bz2 wireshark-7b1c1a94977bf60ef4f5151a5abccc07d8ee08cf.zip |
Add support of the "matches" operator to FT_BYTES and FT_ETHER. I don't think
it would make sense to add PCRE support for byte arrays containing an integer
or an IP address.
Avoid lengthy pointer constructs in cmp_matches().
svn path=/trunk/; revision=9343
Diffstat (limited to 'epan')
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 50 | ||||
-rw-r--r-- | epan/ftypes/ftype-string.c | 14 | ||||
-rw-r--r-- | epan/ftypes/ftype-tvbuff.c | 18 |
3 files changed, 65 insertions, 17 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index ddb3138769..e396f64744 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-bytes.c,v 1.19 2003/12/06 16:35:19 gram Exp $ + * $Id: ftype-bytes.c,v 1.20 2003/12/18 13:02:19 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -31,6 +31,13 @@ #include <epan/strutil.h> #include <epan/int-64bit.h> +#ifdef HAVE_LIBPCRE +#include <pcre.h> +#define CMP_MATCHES cmp_matches +#else +#define CMP_MATCHES NULL +#endif + #define ETHER_LEN 6 #define IPv6_LEN 16 #define U64_LEN 8 @@ -612,6 +619,43 @@ cmp_contains(fvalue_t *fv_a, fvalue_t *fv_b) } } +#ifdef HAVE_LIBPCRE +static gboolean +cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b) +{ + GByteArray *a = fv_a->value.bytes; + pcre_tuple_t *pcre = fv_b->value.re; + int options = 0; + int rc; + + /* 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 (! pcre) { + return FALSE; + } + rc = pcre_exec( + pcre->re, /* Compiled PCRE */ + pcre->ex, /* PCRE extra from pcre_study() */ + a->data, /* The data to check for the pattern... */ + a->len, /* ... and its length */ + 0, /* Start offset within data */ + options, /* PCRE options */ + NULL, /* We are not interested in the matched string */ + 0 /* of the pattern; only in success or failure. */ + ); + /* NOTE - DO NOT g_free(data) */ + if (rc == 0) { + return TRUE; + } + return FALSE; +} +#endif + void ftype_register_bytes(void) { @@ -642,7 +686,7 @@ ftype_register_bytes(void) cmp_lt, cmp_le, cmp_contains, - NULL, /* cmp_matches */ + CMP_MATCHES, len, slice, @@ -706,7 +750,7 @@ ftype_register_bytes(void) cmp_lt, cmp_le, cmp_contains, - NULL, /* cmp_matches */ + CMP_MATCHES, len, slice, diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index 1af5c38184..814bb481a7 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-string.c,v 1.17 2003/12/09 23:02:39 obiot Exp $ + * $Id: ftype-string.c,v 1.18 2003/12/18 13:02:19 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -237,6 +237,8 @@ cmp_contains(fvalue_t *fv_a, fvalue_t *fv_b) static gboolean cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b) { + char *str = fv_a->value.string; + pcre_tuple_t *pcre = fv_b->value.re; int options = 0; int rc; @@ -247,14 +249,14 @@ cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b) if (strcmp(fv_b->ftype->name, "FT_PCRE") != 0) { return FALSE; } - if (! fv_b->value.re) { + if (! pcre) { return FALSE; } rc = pcre_exec( - (fv_b->value.re)->re, /* Compiled PCRE */ - (fv_b->value.re)->ex, /* PCRE extra from pcre_study() */ - fv_a->value.string, /* The data to check for the pattern... */ - (int)strlen(fv_a->value.string), /* ... and its length */ + pcre->re, /* Compiled PCRE */ + pcre->ex, /* PCRE extra from pcre_study() */ + str, /* The data to check for the pattern... */ + (int)strlen(str), /* ... and its length */ 0, /* Start offset within data */ options, /* PCRE options */ NULL, /* We are not interested in the matched string */ diff --git a/epan/ftypes/ftype-tvbuff.c b/epan/ftypes/ftype-tvbuff.c index debf358a8b..42eb8ca7e7 100644 --- a/epan/ftypes/ftype-tvbuff.c +++ b/epan/ftypes/ftype-tvbuff.c @@ -1,5 +1,5 @@ /* - * $Id: ftype-tvbuff.c,v 1.14 2003/12/17 22:42:02 obiot Exp $ + * $Id: ftype-tvbuff.c,v 1.15 2003/12/18 13:02:19 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -176,10 +176,12 @@ cmp_contains(fvalue_t *fv_a, fvalue_t *fv_b) static gboolean cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b) { + tvbuff_t *tvb = fv_a->value.tvb; + pcre_tuple_t *pcre = fv_b->value.re; int options = 0; int rc; - const char *data = NULL; - guint32 tvb_len; + 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()), @@ -188,15 +190,15 @@ cmp_matches(fvalue_t *fv_a, fvalue_t *fv_b) if (strcmp(fv_b->ftype->name, "FT_PCRE") != 0) { return FALSE; } - if (! fv_b->value.re) { + if (! pcre) { return FALSE; } TRY { - tvb_len = tvb_length(fv_a->value.tvb); - data = tvb_get_ptr(fv_a->value.tvb, 0, tvb_len); + tvb_len = tvb_length(tvb); + data = tvb_get_ptr(tvb, 0, tvb_len); rc = pcre_exec( - (fv_b->value.re)->re, /* Compiled PCRE */ - (fv_b->value.re)->ex, /* PCRE extra from pcre_study() */ + pcre->re, /* Compiled PCRE */ + pcre->ex, /* PCRE extra from pcre_study() */ data, /* The data to check for the pattern... */ tvb_len, /* ... and its length */ 0, /* Start offset within data */ |