From Olivier Biot
authorgram <gram@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 6 Dec 2003 16:35:20 +0000 (16:35 +0000)
committergram <gram@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 6 Dec 2003 16:35:20 +0000 (16:35 +0000)
New "matches" operater in display filter language. Uses PCRE.

If a "matches" operator is found in a dfilter
while libpcre has not been used to build the binary, then an
exception is thrown after using dfilter_fail() to set an apporporiate
error message.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@9182 f5534014-38df-0310-8fa8-9805f1628bb7

24 files changed:
Makefile.am
acinclude.m4
configure.in
epan/acinclude.m4
epan/configure.in
epan/dfilter/dfvm.c
epan/dfilter/dfvm.h
epan/dfilter/gencode.c
epan/dfilter/grammar.lemon
epan/dfilter/scanner.l
epan/dfilter/semcheck.c
epan/dfilter/sttype-test.c
epan/dfilter/sttype-test.h
epan/ftypes/ftype-bytes.c
epan/ftypes/ftype-double.c
epan/ftypes/ftype-integer.c
epan/ftypes/ftype-ipv4.c
epan/ftypes/ftype-none.c
epan/ftypes/ftype-string.c
epan/ftypes/ftype-time.c
epan/ftypes/ftype-tvbuff.c
epan/ftypes/ftypes.c
epan/ftypes/ftypes.h
util.c

index 775871088cfff3155cf153fb7dc36516311c81fa..cb18f1ce0b0844fb52ec597b4b56808ea56e1ffe 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for Ethereal
 #
-# $Id: Makefile.am,v 1.663 2003/12/06 06:09:10 gram Exp $
+# $Id: Makefile.am,v 1.664 2003/12/06 16:35:17 gram Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@ethereal.com>
@@ -481,7 +481,7 @@ if HAVE_PLUGINS
 plugin_libs = \
        plugins/acn/acn.la \
        plugins/artnet/artnet.la \
-        plugins/asn1/asn1.la \
+       plugins/asn1/asn1.la \
        plugins/docsis/docsis.la \
        plugins/enttec/enttec.la \
        plugins/giop/cosnaming.la \
@@ -498,7 +498,7 @@ if ENABLE_STATIC
 plugin_ldadd = \
        plugins/acn/packet-acn.o \
        plugins/artnet/packet-artnet.o \
-        plugins/asn1/packet-asn1.o \
+       plugins/asn1/packet-asn1.o \
        plugins/docsis/packet-bpkmattr.o \
        plugins/docsis/packet-bpkmreq.o \
        plugins/docsis/packet-bpkmrsp.o \
@@ -536,7 +536,7 @@ plugin_ldadd = \
 plugin_src = \
        plugins/acn/packet-acn.c \
        plugins/artnet/packet-artnet.c \
-        plugins/asn1/packet-asn1.c \
+       plugins/asn1/packet-asn1.c \
        plugins/docsis/packet-bpkmattr.c \
        plugins/docsis/packet-bpkmreq.c \
        plugins/docsis/packet-bpkmrsp.c \
@@ -576,7 +576,7 @@ plugin_ldadd = \
        "-dlopen" self  \
        "-dlopen" plugins/acn/acn.la \
        "-dlopen" plugins/artnet/artnet.la \
-        "-dlopen" plugins/asn1/asn1.la \
+       "-dlopen" plugins/asn1/asn1.la \
        "-dlopen" plugins/docsis/docsis.la \
        "-dlopen" plugins/enttec/enttec.la \
        "-dlopen" plugins/giop/cosnaming.la \
@@ -930,6 +930,7 @@ ethereal_LDADD = \
        $(ethereal_additional_libs)     \
        @SNMP_LIBS@ @SSL_LIBS@          \
        $(plugin_ldadd)                 \
+       @PCRE_LIBS@ \
        @PCAP_LIBS@ @GTK_LIBS@ @ADNS_LIBS@
 
 TETHEREAL_TAP_SRC = \
@@ -978,6 +979,7 @@ tethereal_LDADD = \
        $(tethereal_additional_libs)    \
        @SNMP_LIBS@ @SSL_LIBS@          \
        $(plugin_ldadd)                 \
+       @PCRE_LIBS@ \
        @GLIB_LIBS@ -lm                 \
        @PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@ @ADNS_LIBS@
 
@@ -1119,6 +1121,7 @@ dftest_LDADD = \
        $(dftest_additional_libs)       \
        @SNMP_LIBS@ @SSL_LIBS@          \
        $(plugin_ldadd)                 \
+       @PCRE_LIBS@ \
        @GLIB_LIBS@ -lm \
        @PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@ @ADNS_LIBS@
 
index 76109ff08f9030e2aeb04d1706aa56820fb0beba..36f4eecc858fa326c014a815e00a1d016b44d334 100644 (file)
@@ -2,7 +2,7 @@ dnl Macros that test for specific features.
 dnl This file is part of the Autoconf packaging for Ethereal.
 dnl Copyright (C) 1998-2000 by Gerald Combs.
 dnl
-dnl $Id: acinclude.m4,v 1.62 2003/11/01 02:30:14 guy Exp $
+dnl $Id: acinclude.m4,v 1.63 2003/12/06 16:35:18 gram Exp $
 dnl
 dnl This program is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -512,6 +512,108 @@ AC_DEFUN(AC_ETHEREAL_ZLIB_CHECK,
        fi
 ])
 
+#
+# AC_ETHEREAL_LIBPCRE_CHECK
+#
+AC_DEFUN(AC_ETHEREAL_LIBPCRE_CHECK,
+[
+       if test "x$pcre_dir" != "x"
+       then
+         #
+         # The user specified a directory in which libpcre resides,
+         # so add the "include" subdirectory of that directory to
+         # the include file search path and the "lib" subdirectory
+         # of that directory to the library search path.
+         #
+         # XXX - if there's also a libpcre in a directory that's
+         # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
+         # make us find the version in the specified directory,
+         # as the compiler and/or linker will search that other
+         # directory before it searches the specified directory.
+         #
+         ethereal_save_CFLAGS="$CFLAGS"
+         CFLAGS="$CFLAGS -I$pcre_dir/include"
+         ethereal_save_CPPLAGS="$CPPLAGS"
+         CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
+         ethereal_save_LIBS="$LIBS"
+         PCRE_LIBS="-L$pcre_dir/lib -lpcre"
+       fi
+
+       #
+       # Make sure we have "pcre.h".  If we don't, it means we probably
+       # don't have libpcre, so don't use it.
+       #
+       AC_CHECK_HEADER(pcre.h,,
+         [
+           if test "x$pcre_dir" != "x"
+           then
+             #
+             # The user used "--with-pcre=" to specify a directory
+             # containing libpcre, but we didn't find the header file
+             # there; that either means they didn't specify the
+             # right directory or are confused about whether libpcre
+             # is, in fact, installed.  Report the error and give up.
+             #
+             AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
+           else
+             if test "x$want_pcre" = "xyes"
+             then
+               #
+               # The user tried to force us to use the library, but we
+               # couldn't find the header file; report an error.
+               #
+               AC_MSG_ERROR(Header file pcre.h not found.)
+             else
+               #
+               # We couldn't find the header file; don't use the
+               # library, as it's probably not present.
+               #
+               want_pcre=no
+             fi
+           fi
+         ])
+
+       if test "x$want_pcre" != "xno"
+       then
+               #
+               # Well, we at least have the pcre header file.
+               #
+               # We're only using standard functions from libpcre,
+               # so we don't need to perform extra checks.
+               #
+               AC_CHECK_LIB(pcre, pcre_compile,
+               [
+                       if test "x$pcre_dir" != "x"
+                       then
+                               #
+                               # Put the "-I" and "-L" flags for pcre at
+                               # the beginning of CFLAGS, CPPFLAGS, and
+                               # LIBS.
+                               #
+                               PCRE_LIBS="-L$pcre_dir/lib -lpcre $ethereal_save_LIBS"
+                       else
+                               PCRE_LIBS="-lpcre"
+                       fi
+                       AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
+               ],[
+                       if test "x$pcre_dir" != "x"
+                       then
+                               #
+                               # Restore the versions of CFLAGS, CPPFLAGS,
+                               # and LIBS before we added the "-with-pcre="
+                               # directory, as we didn't actually find
+                               # pcre there.
+                               #
+                               CFLAGS="$ethereal_save_CFLAGS"
+                               CPPFLAGS="$ethereal_save_CPPLAGS"
+                               PCRE_LIBS=""
+                       fi
+                       want_pcre=no
+               ])
+               AC_SUBST(PCRE_LIBS)
+       fi
+])
+
 #
 # AC_ETHEREAL_UCDSNMP_CHECK
 #
index 31e7b15f5aedfc55ffee8d44490622384db4ab47..aa3633dd6bca637b38f22c0964f7e70607cf9388 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: configure.in,v 1.233 2003/11/18 08:13:05 guy Exp $
+# $Id: configure.in,v 1.234 2003/12/06 16:35:18 gram Exp $
 dnl
 dnl Process this file with autoconf 2.13 or later to produce a
 dnl configure script; 2.12 doesn't generate a "configure" script that
@@ -520,6 +520,42 @@ else
 fi
 
 
+dnl pcre check
+AC_MSG_CHECKING(whether to use libpcre for regular expressions in dfilters)
+
+AC_ARG_WITH(pcre,
+changequote(<<, >>)dnl
+<<  --with-pcre[=DIR]       use libpcre (located in directory DIR, if supplied) to use in dfilter regular expressions.  [default=yes, if present]>>,
+changequote([, ])dnl
+[
+       if test $withval = no
+       then
+               want_pcre=no
+       elif test $withval = yes
+       then
+               want_pcre=yes
+       else
+               want_pcre=yes
+               pcre_dir=$withval
+       fi
+],[
+       #
+       # Use libpcre if it's present, otherwise don't.
+       #
+       want_pcre=ifpresent
+       pcre_dir=
+])
+if test "x$want_pcre" = "xno" ; then
+        AC_MSG_RESULT(no)
+else
+        AC_MSG_RESULT(yes)
+        AC_ETHEREAL_LIBPCRE_CHECK
+       if test "x$want_pcre" = "xno" ; then
+               AC_MSG_RESULT(libpcre not found - disabling support for perl compatible regular expressions in dfilters)
+       fi
+fi
+
+
 dnl ipv6 check
 AC_ARG_ENABLE(ipv6,
 [  --enable-ipv6           use ipv6 name resolution, if available.  [default=yes]],enable_ipv6=$enableval,enable_ipv6=yes)
@@ -860,6 +896,12 @@ else
        zlib_message="yes"
 fi
 
+if test "x$want_pcre" = "xno" ; then
+       pcre_message="no"
+else
+       pcre_message="yes"
+fi
+
 if test "x$have_good_adns" = "xyes" ; then
        adns_message="yes"
 else
@@ -894,6 +936,7 @@ echo "            Build profile binaries : $enable_profile_build"
 fi
 echo "                  Use pcap library : $want_pcap"
 echo "                  Use zlib library : $zlib_message"
+echo "                  Use pcre library : $pcre_message"
 echo "              Use GNU ADNS library : $adns_message"
 echo "          Use IPv6 name resolution : $enable_ipv6"
 echo "     Use UCD SNMP/NET-SNMP library : $snmp_libs_message"
index 77b339e1064cdc2c67f1ffe6dafe4067474bbb35..a747c8b362e755743dfe6160f622d70a154c9043 100644 (file)
@@ -2,7 +2,7 @@ dnl Macros that test for specific features.
 dnl This file is part of the Autoconf packaging for Ethereal.
 dnl Copyright (C) 1998-2000 by Gerald Combs.
 dnl
-dnl $Id: acinclude.m4,v 1.3 2003/08/21 07:17:09 guy Exp $
+dnl $Id: acinclude.m4,v 1.4 2003/12/06 16:35:18 gram Exp $
 dnl
 dnl This program is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -182,3 +182,105 @@ changequote([, ])dnl
                AC_MSG_RESULT(not required)
        fi
 ])
+
+#
+# AC_ETHEREAL_LIBPCRE_CHECK
+#
+AC_DEFUN(AC_ETHEREAL_LIBPCRE_CHECK,
+[
+       if test "x$pcre_dir" != "x"
+       then
+         #
+         # The user specified a directory in which libpcre resides,
+         # so add the "include" subdirectory of that directory to
+         # the include file search path and the "lib" subdirectory
+         # of that directory to the library search path.
+         #
+         # XXX - if there's also a libpcre in a directory that's
+         # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
+         # make us find the version in the specified directory,
+         # as the compiler and/or linker will search that other
+         # directory before it searches the specified directory.
+         #
+         ethereal_save_CFLAGS="$CFLAGS"
+         CFLAGS="$CFLAGS -I$pcre_dir/include"
+         ethereal_save_CPPLAGS="$CPPLAGS"
+         CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
+         ethereal_save_LIBS="$LIBS"
+         PCRE_LIBS="-L$pcre_dir/lib -lpcre"
+       fi
+
+       #
+       # Make sure we have "pcre.h".  If we don't, it means we probably
+       # don't have libpcre, so don't use it.
+       #
+       AC_CHECK_HEADER(pcre.h,,
+         [
+           if test "x$pcre_dir" != "x"
+           then
+             #
+             # The user used "--with-pcre=" to specify a directory
+             # containing libpcre, but we didn't find the header file
+             # there; that either means they didn't specify the
+             # right directory or are confused about whether libpcre
+             # is, in fact, installed.  Report the error and give up.
+             #
+             AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
+           else
+             if test "x$want_pcre" = "xyes"
+             then
+               #
+               # The user tried to force us to use the library, but we
+               # couldn't find the header file; report an error.
+               #
+               AC_MSG_ERROR(Header file pcre.h not found.)
+             else
+               #
+               # We couldn't find the header file; don't use the
+               # library, as it's probably not present.
+               #
+               want_pcre=no
+             fi
+           fi
+         ])
+
+       if test "x$want_pcre" != "xno"
+       then
+               #
+               # Well, we at least have the pcre header file.
+               #
+               # We're only using standard functions from libpcre,
+               # so we don't need to perform extra checks.
+               #
+               AC_CHECK_LIB(pcre, pcre_compile,
+               [
+                       if test "x$pcre_dir" != "x"
+                       then
+                               #
+                               # Put the "-I" and "-L" flags for pcre at
+                               # the beginning of CFLAGS, CPPFLAGS, and
+                               # LIBS.
+                               #
+                               PCRE_LIBS="-L$pcre_dir/lib -lpcre $ethereal_save_LIBS"
+                       else
+                               PCRE_LIBS="-lpcre"
+                       fi
+                       AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
+               ],[
+                       if test "x$pcre_dir" != "x"
+                       then
+                               #
+                               # Restore the versions of CFLAGS, CPPFLAGS,
+                               # and LIBS before we added the "-with-pcre="
+                               # directory, as we didn't actually find
+                               # pcre there.
+                               #
+                               CFLAGS="$ethereal_save_CFLAGS"
+                               CPPFLAGS="$ethereal_save_CPPLAGS"
+                               PCRE_LIBS=""
+                       fi
+                       want_pcre=no
+               ])
+               AC_SUBST(PCRE_LIBS)
+       fi
+])
index f540653059ded3d7c42cbc3a615ce318099c13e9..a6501d3c51b952db756b8f2a8d1aafd1228d2b13 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: configure.in,v 1.49 2003/11/18 08:13:09 guy Exp $
+# $Id: configure.in,v 1.50 2003/12/06 16:35:18 gram Exp $
 dnl
 dnl Process this file with autoconf 2.13 or later to produce a
 dnl configure script; 2.12 doesn't generate a "configure" script that
@@ -235,6 +235,40 @@ AC_CHECK_FUNC(strptime, ,
   [AC_DEFINE(NEED_STRPTIME_H, 1, [Define if strptime.h needs to be included])
 ])
 
+dnl pcre check
+AC_MSG_CHECKING(whether to use libpcre for regular expressions in dfilters)
+AC_ARG_WITH(pcre,
+changequote(<<, >>)dnl
+<<  --with-pcre[=DIR]       use libpcre (located in directory DIR, if supplied) to use in dfilter regular expressions.  [default=yes, if present]>>,
+changequote([, ])dnl
+[
+       if test $withval = no
+       then
+               want_pcre=no
+       elif test $withval = yes
+       then
+               want_pcre=yes
+       else
+               want_pcre=yes
+               pcre_dir=$withval
+       fi
+],[
+       #
+       # Use libpcre if it's present, otherwise don't.
+       #
+       want_pcre=ifpresent
+       pcre_dir=
+])
+if test "x$want_pcre" = "xno" ; then
+        AC_MSG_RESULT(no)
+else
+        AC_MSG_RESULT(yes)
+        AC_ETHEREAL_LIBPCRE_CHECK
+       if test "x$want_pcre" = "xno" ; then
+               AC_MSG_RESULT(libpcre not found - disabling support for perl compatible regular expressions in dfilters)
+       fi
+fi
+
 dnl ADNS Check
 AC_MSG_CHECKING(whether to use the GNU ADNS library if available)
 if test "x$enable_adns" = "xno" ; then
index be409ed35b38d85ff859c51fac8d1db91d7fd687..3843d4609ba348ff9b3ef59bdb52f891331e0c7a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dfvm.c,v 1.12 2003/12/02 21:15:48 guy Exp $
+ * $Id: dfvm.c,v 1.13 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -408,6 +408,11 @@ dfvm_apply(dfilter_t *df, proto_tree *tree)
                                                arg1->value.numeric, arg2->value.numeric);
                                break;
 
+                       case ANY_MATCHES:
+                               accum = any_test(df, fvalue_matches,
+                                               arg1->value.numeric, arg2->value.numeric);
+                               break;
+
                        case NOT:
                                accum = !accum;
                                break;
index efeb478962498b5dd9c0f922dff5e75629f5ca7e..2f450436995ef57a56f59ab2c9af0c219ad16b25 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dfvm.h,v 1.9 2003/08/27 15:23:04 gram Exp $
+ * $Id: dfvm.h,v 1.10 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -68,6 +68,7 @@ typedef enum {
        ANY_LT,
        ANY_LE,
        ANY_CONTAINS,
+       ANY_MATCHES,
        MK_RANGE
 
 } dfvm_opcode_t;
index 333fdacf381cc738d25aa24fdd27871e6487d38f..992e3afe5b0eb8c7b9b841fe1a0d3d3e90062556 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: gencode.c,v 1.11 2003/08/27 15:23:04 gram Exp $
+ * $Id: gencode.c,v 1.12 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -323,6 +323,10 @@ gen_test(dfwork_t *dfw, stnode_t *st_node)
                case TEST_OP_CONTAINS:
                        gen_relation(dfw, ANY_CONTAINS, st_arg1, st_arg2);
                        break;
+
+               case TEST_OP_MATCHES:
+                       gen_relation(dfw, ANY_MATCHES, st_arg1, st_arg2);
+                       break;
        }
 }
 
index c1148920349e4266232c0f8ec7be6fc104c234c1..8a7e280796109b4000020ff146e38be765d5df90 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: grammar.lemon,v 1.6 2003/08/27 15:23:04 gram Exp $ */
+/* $Id: grammar.lemon,v 1.7 2003/12/06 16:35:19 gram Exp $ */
 
 %include {
 #ifdef HAVE_CONFIG_H
@@ -108,7 +108,7 @@ shifting 3 more symbols. */
 /* Associativity */
 %left TEST_AND.
 %left TEST_OR.
-%nonassoc TEST_EQ TEST_NE TEST_LT TEST_LE TEST_GT TEST_GE TEST_CONTAINS.
+%nonassoc TEST_EQ TEST_NE TEST_LT TEST_LE TEST_GT TEST_GE TEST_CONTAINS TEST_MATCHES.
 %right TEST_NOT.
 
 /* Top-level targets */
@@ -248,6 +248,7 @@ rel_op2(O) ::= TEST_GE.  { O = TEST_OP_GE; }
 rel_op2(O) ::= TEST_LT.  { O = TEST_OP_LT; }
 rel_op2(O) ::= TEST_LE.  { O = TEST_OP_LE; }
 rel_op2(O) ::= TEST_CONTAINS.  { O = TEST_OP_CONTAINS; }
+rel_op2(O) ::= TEST_MATCHES.  { O = TEST_OP_MATCHES; }
 
 
 
index 7d0aa95126e1377ec15b5003f3e87c4d04a3281c..e37df4063d8b4c062e15ecc615dd2ae969fe1b94 100644 (file)
@@ -1,6 +1,6 @@
 %{
 /*
- * $Id: scanner.l,v 1.10 2003/10/27 22:45:47 guy Exp $
+ * $Id: scanner.l,v 1.11 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -65,26 +65,26 @@ GString* quoted_string = NULL;
 "("                            return simple(TOKEN_LPAREN);
 ")"                            return simple(TOKEN_RPAREN);
 
-"=="                           return simple(TOKEN_TEST_EQ);
-"eq"                           return simple(TOKEN_TEST_EQ);
-"!="                           return simple(TOKEN_TEST_NE);
-"ne"                           return simple(TOKEN_TEST_NE);
+"=="                   return simple(TOKEN_TEST_EQ);
+"eq"                   return simple(TOKEN_TEST_EQ);
+"!="                   return simple(TOKEN_TEST_NE);
+"ne"                   return simple(TOKEN_TEST_NE);
 ">"                            return simple(TOKEN_TEST_GT);
-"gt"                           return simple(TOKEN_TEST_GT);
-">="                           return simple(TOKEN_TEST_GE);
-"ge"                           return simple(TOKEN_TEST_GE);
+"gt"                   return simple(TOKEN_TEST_GT);
+">="                   return simple(TOKEN_TEST_GE);
+"ge"                   return simple(TOKEN_TEST_GE);
 "<"                            return simple(TOKEN_TEST_LT);
-"lt"                           return simple(TOKEN_TEST_LT);
-"<="                           return simple(TOKEN_TEST_LE);
-"le"                           return simple(TOKEN_TEST_LE);
-"contains"                     return simple(TOKEN_TEST_CONTAINS);
-
+"lt"                   return simple(TOKEN_TEST_LT);
+"<="                   return simple(TOKEN_TEST_LE);
+"le"                   return simple(TOKEN_TEST_LE);
+"contains"             return simple(TOKEN_TEST_CONTAINS);
+"matches"              return simple(TOKEN_TEST_MATCHES);
 "!"                            return simple(TOKEN_TEST_NOT);
-"not"                          return simple(TOKEN_TEST_NOT);
-"&&"                           return simple(TOKEN_TEST_AND);
-"and"                          return simple(TOKEN_TEST_AND);
-"||"                           return simple(TOKEN_TEST_OR);
-"or"                           return simple(TOKEN_TEST_OR);
+"not"                  return simple(TOKEN_TEST_NOT);
+"&&"                   return simple(TOKEN_TEST_AND);
+"and"                  return simple(TOKEN_TEST_AND);
+"||"                   return simple(TOKEN_TEST_OR);
+"or"                   return simple(TOKEN_TEST_OR);
 
 
 
@@ -223,6 +223,7 @@ simple(int token)
                case TOKEN_TEST_LT:
                case TOKEN_TEST_LE:
                case TOKEN_TEST_CONTAINS:
+               case TOKEN_TEST_MATCHES:
                case TOKEN_TEST_NOT:
                case TOKEN_TEST_AND:
                case TOKEN_TEST_OR:
index 8bcf967d59ab82b33411d2edf4ca64b8610bd2a0..865d74deb285ac63aecaeb61baa753487088a2db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: semcheck.c,v 1.19 2003/08/27 15:23:04 gram Exp $
+ * $Id: semcheck.c,v 1.20 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -694,6 +694,14 @@ check_test(stnode_t *st_node)
                case TEST_OP_CONTAINS:
                        check_relation("contains", TRUE, ftype_can_contains, st_node, st_arg1, st_arg2);
                        break;
+               case TEST_OP_MATCHES:
+#ifdef HAVE_LIBPCRE
+                       check_relation("matches", TRUE, ftype_can_matches, st_node, st_arg1, st_arg2);
+#else
+                       dfilter_fail("This Ethereal version does not support the \"matches\" operation.");
+                       THROW(TypeError);
+#endif
+                       break;
 
                default:
                        g_assert_not_reached();
index f6f917f1fce5e73de385a5fed36226a92c25256d..d01bf1472b1c3676e1e62deee0022397db71fc8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: sttype-test.c,v 1.4 2003/08/27 15:23:05 gram Exp $
+ * $Id: sttype-test.c,v 1.5 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -92,6 +92,8 @@ num_operands(test_op_t op)
                        return 2;
                case TEST_OP_CONTAINS:
                        return 2;
+               case TEST_OP_MATCHES:
+                       return 2;
        }
        g_assert_not_reached();
        return -1;
index f662a5b097383e9caf71e169edf8356bb5fce544..cdbf48b0ba05af69c774c2230707248faed2e1d1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: sttype-test.h,v 1.4 2003/08/27 15:23:05 gram Exp $
+ * $Id: sttype-test.h,v 1.5 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -36,7 +36,8 @@ typedef enum {
        TEST_OP_GE,
        TEST_OP_LT,
        TEST_OP_LE,
-       TEST_OP_CONTAINS
+       TEST_OP_CONTAINS,
+       TEST_OP_MATCHES
 } test_op_t;
 
 void
index 84c9f58a64dc462a2856294673217453c3be28bf..ddb3138769881af256d96f3a5ed862d1cf87fdd5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-bytes.c,v 1.18 2003/10/29 23:48:14 guy Exp $
+ * $Id: ftype-bytes.c,v 1.19 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -642,6 +642,7 @@ ftype_register_bytes(void)
                cmp_lt,
                cmp_le,
                cmp_contains,
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
@@ -673,6 +674,7 @@ ftype_register_bytes(void)
                cmp_lt,
                cmp_le,
                cmp_contains,
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
@@ -704,6 +706,7 @@ ftype_register_bytes(void)
                cmp_lt,
                cmp_le,
                cmp_contains,
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
@@ -735,6 +738,7 @@ ftype_register_bytes(void)
                cmp_lt,
                cmp_le,
                cmp_contains,
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
@@ -766,6 +770,7 @@ ftype_register_bytes(void)
                cmp_lt,
                cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
@@ -797,6 +802,7 @@ ftype_register_bytes(void)
                cmp_lt_i64,
                cmp_le_i64,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
index 27fba9aaf4117261b51132062a63f3998f158df7..0038591d11cc01d9530f901db6507033ed08e173 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-double.c,v 1.11 2003/08/27 15:23:06 gram Exp $
+ * $Id: ftype-double.c,v 1.12 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -182,6 +182,7 @@ ftype_register_double(void)
                cmp_lt,
                cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,
                NULL,
@@ -213,6 +214,7 @@ ftype_register_double(void)
                cmp_lt,
                cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,
                NULL,
index 0bba4d218bc8cf8d33e490d68b829b6691f713b0..b6e32f83dfdc717178011fa59bb8ef0af9b65a30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-integer.c,v 1.15 2003/08/27 15:23:06 gram Exp $
+ * $Id: ftype-integer.c,v 1.16 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -243,6 +243,7 @@ ftype_register_integers(void)
                u_cmp_lt,
                u_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -273,6 +274,7 @@ ftype_register_integers(void)
                u_cmp_lt,
                u_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -303,6 +305,7 @@ ftype_register_integers(void)
                u_cmp_lt,
                u_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -333,6 +336,7 @@ ftype_register_integers(void)
                u_cmp_lt,
                u_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -363,6 +367,7 @@ ftype_register_integers(void)
                s_cmp_lt,
                s_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -393,6 +398,7 @@ ftype_register_integers(void)
                s_cmp_lt,
                s_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -423,6 +429,7 @@ ftype_register_integers(void)
                s_cmp_lt,
                s_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -453,6 +460,7 @@ ftype_register_integers(void)
                s_cmp_lt,
                s_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -483,6 +491,7 @@ ftype_register_integers(void)
                NULL,                           /* cmp_lt */
                NULL,                           /* cmp_le */
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -514,6 +523,7 @@ ftype_register_integers(void)
                u_cmp_lt,
                u_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
@@ -545,6 +555,7 @@ ftype_register_integers(void)
                u_cmp_lt,
                u_cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,                           /* len */
                NULL,                           /* slice */
index 107b5c25258d6919aa5014c005c2ddc3f4454fb7..abdbd7bad5b1e8b9e9aebe90702db0910d998c70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-ipv4.c,v 1.14 2003/11/25 13:20:35 sahlberg Exp $
+ * $Id: ftype-ipv4.c,v 1.15 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -203,6 +203,7 @@ ftype_register_ipv4(void)
                cmp_lt,
                cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,
                NULL,
index 46c1822a80307c6fa6acee3534513d8ac07c4d56..0dcb2f6e834ce79efaa7d29ae14866007c2d17d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-none.c,v 1.7 2003/08/27 15:23:07 gram Exp $
+ * $Id: ftype-none.c,v 1.8 2003/12/06 16:35:19 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -51,13 +51,14 @@ ftype_register_none(void)
                NULL,
                NULL,
 
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
+               NULL,                           /* cmp_eq */
+               NULL,                           /* cmp_ne */
+               NULL,                           /* cmp_gt */
+               NULL,                           /* cmp_ge */
+               NULL,                           /* cmp_lt */
+               NULL,                           /* cmp_le */
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,
                NULL,
index 4abdeca986dde39a1916cd252036d4b415096572..a70425a733ec2f0c3cbace43043fc33170230670 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-string.c,v 1.15 2003/11/25 13:20:36 sahlberg Exp $
+ * $Id: ftype-string.c,v 1.16 2003/12/06 16:35:20 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #include <ftypes-int.h>
 #include <string.h>
 
+#ifdef HAVE_LIBPCRE
+#include <pcre.h>
+#define CMP_MATCHES cmp_matches
+#else
+#define CMP_MATCHES NULL
+#endif
+
 static void
 string_fvalue_new(fvalue_t *fv)
 {
@@ -226,6 +233,54 @@ 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)
+{
+       pcre *re;
+       const char *pcre_error_text;
+       int pcre_error_offset;
+       int options = 0;
+       int rc;
+       pcre_extra *pe = NULL; /* TODO - pcre_study() */
+
+       re = pcre_compile(
+                       fv_b->value.string,     /* pattern */
+                       options,                        /* PCRE options */
+                       &pcre_error_text,       /* PCRE constant error string */
+                       &pcre_error_offset,     /* Start offset of error in pattern */
+                       NULL                            /* Default char tables (C locale) */
+                       );
+       if (re == NULL) {
+               /* TODO - Do something with pcre_error and pcre_error_offset */
+               return FALSE;
+       }
+       /* TODO - Study the RE *if* the compile & study only happens once * /
+       pe = pcre_study(re, 0, &pcre_error_text);
+       if (pcre_error != NULL) {
+               / * TODO - Do something with pcre_error and pcre_error_offset * /
+               return FALSE;
+       }
+       */
+       rc = pcre_exec(
+                       re,                                     /* Compiled PCRE */
+                       pe,                                     /* 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 */
+                       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. */
+                       );
+       /* if (pe != NULL)
+               g_free(pe); */
+       g_free(re);
+       if (rc == 0)
+               return TRUE;
+       return FALSE;
+}
+#endif
+
 void
 ftype_register_string(void)
 {
@@ -255,7 +310,8 @@ ftype_register_string(void)
                cmp_ge,
                cmp_lt,
                cmp_le,
-               cmp_contains,                   /* cmp_contains */
+               cmp_contains,
+               CMP_MATCHES,
 
                len,
                slice,
@@ -286,6 +342,7 @@ ftype_register_string(void)
                cmp_lt,
                cmp_le,
                cmp_contains,                   /* cmp_contains */
+               CMP_MATCHES,
 
                len,
                slice,
@@ -316,6 +373,7 @@ ftype_register_string(void)
                cmp_lt,
                cmp_le,
                cmp_contains,                   /* cmp_contains */
+               CMP_MATCHES,
 
                len,
                slice,
index d926d3036596ec48f6dc171c1425955bf7428a6a..8456bf6a31894bc20cf6a17f7c39ae76c44d4282 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-time.c,v 1.21 2003/08/27 15:23:07 gram Exp $
+ * $Id: ftype-time.c,v 1.22 2003/12/06 16:35:20 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -363,6 +363,7 @@ ftype_register_time(void)
                cmp_lt,
                cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,
                NULL
@@ -393,6 +394,7 @@ ftype_register_time(void)
                cmp_lt,
                cmp_le,
                NULL,                           /* cmp_contains */
+               NULL,                           /* cmp_matches */
 
                NULL,
                NULL
index ee0ef58ead406e240912465c1c0bb2cc7c0f462c..fc4cae972e191d73e343d2c9ba0ae0214676a99f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftype-tvbuff.c,v 1.12 2003/10/29 23:48:14 guy Exp $
+ * $Id: ftype-tvbuff.c,v 1.13 2003/12/06 16:35:20 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -190,13 +190,14 @@ ftype_register_tvbuff(void)
                NULL,
                NULL,
 
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               cmp_contains,                   /* cmp_contains */
+               NULL,                           /* cmp_eq */
+               NULL,                           /* cmp_ne */
+               NULL,                           /* cmp_gt */
+               NULL,                           /* cmp_ge */
+               NULL,                           /* cmp_lt */
+               NULL,                           /* cmp_le */
+               cmp_contains,
+               NULL,                           /* cmp_matches */
 
                len,
                slice,
index 43b437a49d74a27e7aa379319a2460cea92baa43..c294ed75bbe78528ed37f0f44262c32cf25aa10f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ftypes.c,v 1.18 2003/12/03 09:28:23 guy Exp $
+ * $Id: ftypes.c,v 1.19 2003/12/06 16:35:20 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -183,6 +183,15 @@ ftype_can_contains(enum ftenum ftype)
        return ft->cmp_contains ? TRUE : FALSE;
 }
 
+gboolean
+ftype_can_matches(enum ftenum ftype)
+{
+       ftype_t *ft;
+
+       FTYPE_LOOKUP(ftype, ft);
+       return ft->cmp_matches ? TRUE : FALSE;
+}
+
 /* ---------------------------------------------------------- */
 
 /* Allocate and initialize an fvalue_t, given an ftype */
@@ -501,3 +510,11 @@ fvalue_contains(fvalue_t *a, fvalue_t *b)
        g_assert(a->ftype->cmp_contains);
        return a->ftype->cmp_contains(a, b);
 }
+
+gboolean
+fvalue_matches(fvalue_t *a, fvalue_t *b)
+{
+       /* XXX - check compatibility of a and b */
+       g_assert(a->ftype->cmp_matches);
+       return a->ftype->cmp_matches(a, b);
+}
index 00b10c8c04cf5f7255adb02a7589131a8da3d4de..1ffbef7bff45f892415a1262a5fc696e81677268 100644 (file)
@@ -1,7 +1,7 @@
 /* ftypes.h
  * Definitions for field types
  *
- * $Id: ftypes.h,v 1.25 2003/12/03 09:28:23 guy Exp $
+ * $Id: ftypes.h,v 1.26 2003/12/06 16:35:20 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -118,6 +118,9 @@ ftype_can_le(enum ftenum ftype);
 gboolean
 ftype_can_contains(enum ftenum ftype);
 
+gboolean
+ftype_can_matches(enum ftenum ftype);
+
 /* ---------------- FVALUE ----------------- */
 
 #include <epan/ipv4.h>
@@ -196,6 +199,7 @@ struct _ftype_t {
        FvalueCmp               cmp_lt;
        FvalueCmp               cmp_le;
        FvalueCmp               cmp_contains;
+       FvalueCmp               cmp_matches;
 
        FvalueLen               len;
        FvalueSlice             slice;
@@ -292,6 +296,9 @@ fvalue_le(fvalue_t *a, fvalue_t *b);
 gboolean
 fvalue_contains(fvalue_t *a, fvalue_t *b);
 
+gboolean
+fvalue_matches(fvalue_t *a, fvalue_t *b);
+
 guint
 fvalue_length(fvalue_t *fv);
 
diff --git a/util.c b/util.c
index 1b245c3e3cddb7f3cdc7241eb15c6606d056f4d9..26ee78395fed2c21a0ed8b4d5eedfd0e40a596b4 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
 /* util.c
  * Utility routines
  *
- * $Id: util.c,v 1.73 2003/12/01 20:27:09 gerald Exp $
+ * $Id: util.c,v 1.74 2003/12/06 16:35:18 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -60,6 +60,10 @@ typedef int mode_t;  /* for win32 */
 #include <zlib.h>      /* to get the libz version number */
 #endif
 
+#ifdef HAVE_LIBPCRE
+#include <pcre.h>      /* to get the libpcre version number */
+#endif /* HAVE_LIBPCRE */
+
 #ifdef HAVE_LIBPCAP
 #include <pcap.h>
 #endif /* HAVE_LIBPCAP */
@@ -152,6 +156,26 @@ get_compiled_version_info(GString *str)
        g_string_append(str, ",");
        do_word_wrap(str, break_point);
 
+       g_string_append(str, " ");
+       break_point = str->len - 1;
+#ifdef HAVE_LIBPCRE
+       g_string_append(str, "with libpcre ");
+#ifdef PCRE_MAJOR
+#ifdef PCRE_MINOR
+       g_string_sprintfa(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
+#else                  /* PCRE_MINOR */
+       g_string_sprintfa(str, "%u", PCRE_MAJOR);
+#endif                 /* PCRE_MINOR */
+#else          /* PCRE_MAJOR */
+       g_string_append(str, "(version unknown)");
+#endif         /* PCRE_MAJOR */
+#else  /* HAVE_LIBPCRE */
+       g_string_append(str, "without libpcre");
+#endif /* HAVE_LIBPCRE */
+
+       g_string_append(str, ",");
+       do_word_wrap(str, break_point);
+
 /* Oh, this is pretty. */
 /* Oh, ha.  you think that was pretty.  Try this:! --Wes */
        g_string_append(str, " ");
@@ -181,7 +205,17 @@ get_compiled_version_info(GString *str)
 #else
        g_string_append(str, "without ADNS");
 #endif /* HAVE_GNU_ADNS */
+
+       g_string_append(str, ".");
+       do_word_wrap(str, break_point);
+
+#ifndef HAVE_LIBPCRE
+       break_point = str->len - 1;
+       g_string_append(str,
+                       "\nNOTE: this build does not support the \"matches\" operator"
+                       "\nfor Ethereal filter syntax.\n");
        do_word_wrap(str, break_point);
+#endif /* HAVE_LIBPCRE */
 }
 
 /*