Now that FT_BOOLEAN display filter fields are treated differently (only
[obnox/wireshark/wip.git] / dfilter-int.h
1 /* dfilter-int.h
2  * Definitions for routines common to multiple modules in the display
3  * filter code, but not used outside that code.
4  *
5  * $Id: dfilter-int.h,v 1.4 1999/08/30 16:01:42 gram Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifndef __DFILTER_INT_H__
28 #define __DFILTER_INT_H__
29
30 /* in dfilter-scanner.l */
31 GByteArray *byte_str_to_guint8_array(const char *s);
32 void dfilter_scanner_text(char*);
33 void dfilter_scanner_cleanup(void);
34
35 /* in dfilter-grammar.y */
36 extern dfilter *global_df;
37 extern GSList *gnode_slist;
38
39 /* Here we provide interfaces to make our scanner act and look like lex */
40 int yylex(void);
41 void yyerror(char *s);
42 void dfilter_yyerror(char *fmt, ...);
43
44 /* functions that dfilter-grammar.y needs during parsing*/
45 gboolean check_relation_numeric(gint operand, GArray *a, GArray *b);
46 gboolean check_relation_ether(gint operand, GArray *a, GArray *b);
47 gboolean check_relation_bytes(gint operand, GArray *a, GArray *b);
48
49 gboolean fill_array_numeric_value(GNode *gnode, gpointer data);
50 gboolean fill_array_numeric_variable(GNode *gnode, gpointer data);
51 gboolean fill_array_ether_value(GNode *gnode, gpointer data);
52 gboolean fill_array_ether_variable(GNode *gnode, gpointer data);
53 gboolean fill_array_bytes_value(GNode *gnode, gpointer data);
54 gboolean fill_array_bytes_variable(GNode *gnode, gpointer data);
55
56 #ifdef WIN32
57 #define boolean truth_value
58 #endif
59
60 enum node_type {
61         relation,       /* eq, ne, gt, ge, lt, le */
62         logical,        /* and, or, not, xor */
63         variable,       /* protocol or header field id */
64         existence,      /* existence of a variable (protocol or hf) */
65         alternation,    /* &, | */
66         boolean,        /* true, false */
67         numeric,        /* uint8, uint16, or uint32 value */
68         abs_time,
69         string,
70         ether,
71         bytes,
72         ipv4,
73         ipxnet
74 };
75
76 typedef gboolean(*CheckRelationFunc) (gint operand, GArray *a, GArray *b);
77
78 /* This struct is the parse tree node created by this grammary and used
79  * directly in the display filter routines to filter packets.
80  */
81 typedef struct dfilter_node {
82         enum node_type                  ntype; /* from dfilter-grammar.h */
83         int                             elem_size; /* computed at dfilter parse time rather than
84                                                 when finding elements for each packet. Saves time
85                                                 in get_values_from_ptree() */
86         CheckRelationFunc               check_relation_func;
87         GNodeTraverseFunc               fill_array_func;
88
89         /* copied from proto.h */
90         union {
91                 gint            relation; /* if type == relation (eq, ne, gt, ge, lt, le) */
92                 gint            logical;  /* if type == logical (and, or, not, xor) */
93                 gint            variable; /* if type == variable (protocol or header field abbrev) */
94                 gint            alternation; /* if type == alternation (& or |) */
95
96                 guint32         numeric;
97                 struct timeval  abs_time; /* the whole struct, not a pointer */
98                 gchar           *string;
99                 guint8          ether[6];
100                 GByteArray      *bytes;
101         }                               value;
102
103         /* used for byte-ranges */
104         gint                            offset;
105         guint                           length;
106 } dfilter_node;
107
108 /* lookup an abbreviation in our token hash, returing the ID # */
109 int dfilter_lookup_token(char *abbrev);
110
111 #endif /* ! __DFILTER_INT_H__ */