Allow filtering on strings.
[obnox/wireshark/wip.git] / dfilter-int.h
index 1ad150279509fa14af9b69abbd39cc7bd4237798..cf7a1c71e81d7a9ff4c91674e129459f23c04b77 100644 (file)
@@ -2,7 +2,7 @@
  * Definitions for routines common to multiple modules in the display
  * filter code, but not used outside that code.
  *
- * $Id: dfilter-int.h,v 1.1 1999/08/12 21:16:31 guy Exp $
+ * $Id: dfilter-int.h,v 1.13 2000/08/01 18:10:05 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #ifndef __DFILTER_INT_H__
 #define __DFILTER_INT_H__
 
+#ifndef __IPV4_H__
+#include "ipv4.h"
+#endif
+
 /* in dfilter-scanner.l */
 GByteArray *byte_str_to_guint8_array(const char *s);
+void dfilter_scanner_text(char*);
+void dfilter_scanner_cleanup(void);
 
 /* in dfilter-grammar.y */
-extern GSList *dfilter_list_byte_arrays;
+extern dfilter *global_df;
 
 /* Here we provide interfaces to make our scanner act and look like lex */
-int yylex(void);
-void yyerror(char *s);
-void dfilter_yyerror(char *fmt, ...);
+int dfilter_lex(void);
+void dfilter_error(char *s);
+
+/* Report an error during compilation of a filter; this is called by code
+ * other than parser code, so all it does is record that an error occurred,
+ * so that even if the filter is nominally syntactically valid, we still
+ * fail.
+ */
+#if __GNUC__ == 2
+void dfilter_fail(char *fmt, ...)
+    __attribute__((format (printf, 1, 2)));
+#else
+void dfilter_fail(char *fmt, ...);
+#endif
 
 /* functions that dfilter-grammar.y needs during parsing*/
 gboolean check_relation_numeric(gint operand, GArray *a, GArray *b);
+gboolean check_relation_floating(gint operand, GArray *a, GArray *b);
 gboolean check_relation_ether(gint operand, GArray *a, GArray *b);
+gboolean check_relation_ipv4(gint operand, GArray *a, GArray *b);
+gboolean check_relation_ipv6(gint operand, GArray *a, GArray *b);
 gboolean check_relation_bytes(gint operand, GArray *a, GArray *b);
-gboolean check_relation_boolean(gint operand, GArray *a, GArray *b);
+gboolean check_relation_string(gint operand, GArray *a, GArray *b);
+
+void fill_array_numeric_variable(field_info*, GArray*, const guint8*);
+void fill_array_floating_variable(field_info*, GArray*, const guint8*);
+void fill_array_ether_variable(field_info*, GArray*, const guint8*);
+void fill_array_ipv4_variable(field_info*, GArray*, const guint8*);
+void fill_array_ipv6_variable(field_info*, GArray*, const guint8*);
+void fill_array_bytes_variable(field_info*, GArray*, const guint8*);
+void fill_array_string_variable(field_info*, GArray*, const guint8*);
 
 gboolean fill_array_numeric_value(GNode *gnode, gpointer data);
-gboolean fill_array_numeric_variable(GNode *gnode, gpointer data);
+gboolean fill_array_floating_value(GNode *gnode, gpointer data);
 gboolean fill_array_ether_value(GNode *gnode, gpointer data);
-gboolean fill_array_ether_variable(GNode *gnode, gpointer data);
+gboolean fill_array_ipv4_value(GNode *gnode, gpointer data);
+gboolean fill_array_ipv6_value(GNode *gnode, gpointer data);
 gboolean fill_array_bytes_value(GNode *gnode, gpointer data);
-gboolean fill_array_bytes_variable(GNode *gnode, gpointer data);
-gboolean fill_array_boolean_value(GNode *gnode, gpointer data);
-gboolean fill_array_boolean_variable(GNode *gnode, gpointer data);
+gboolean fill_array_string_value(GNode *gnode, gpointer data);
+
+#ifdef WIN32
+#define boolean truth_value
+#endif
 
 enum node_type {
        relation,       /* eq, ne, gt, ge, lt, le */
@@ -61,15 +92,18 @@ enum node_type {
        alternation,    /* &, | */
        boolean,        /* true, false */
        numeric,        /* uint8, uint16, or uint32 value */
+       floating,       /* double */
        abs_time,
        string,
        ether,
        bytes,
        ipv4,
+       ipv6,
        ipxnet
 };
 
 typedef gboolean(*CheckRelationFunc) (gint operand, GArray *a, GArray *b);
+typedef void(*FillArrayFunc) (field_info*, GArray*, const guint8*);
 
 /* This struct is the parse tree node created by this grammary and used
  * directly in the display filter routines to filter packets.
@@ -80,7 +114,8 @@ typedef struct dfilter_node {
                                                when finding elements for each packet. Saves time
                                                in get_values_from_ptree() */
        CheckRelationFunc               check_relation_func;
-       GNodeTraverseFunc               fill_array_func;
+       FillArrayFunc                   fill_array_variable_func;
+       GNodeTraverseFunc               fill_array_value_func;
 
        /* copied from proto.h */
        union {
@@ -89,11 +124,13 @@ typedef struct dfilter_node {
                gint            variable; /* if type == variable (protocol or header field abbrev) */
                gint            alternation; /* if type == alternation (& or |) */
 
-               gboolean        boolean;
                guint32         numeric;
-               struct timeval  abs_time; /* the whole struct, not a pointer */
+               double          floating;
+               struct timeval  abs_time;       /* the whole struct, not a pointer */
                gchar           *string;
                guint8          ether[6];
+               ipv4_addr       ipv4;           /* the whole struct, not a pointer */
+               guint8          ipv6[16];
                GByteArray      *bytes;
        }                               value;