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