213d9ccba61e8af299337f515aeaaf23e36bab7f
[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.7 1999/10/11 03:03:11 guy 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 dfilter_lex(void);
41 void dfilter_error(char *s);
42
43 /* Report an error during compilation of a filter; this is called by code
44  * other than parser code, so all it does is record that an error occurred,
45  * so that even if the filter is nominally syntactically valid, we still
46  * fail.
47  */
48 #if __GNUC__ == 2
49 void dfilter_fail(char *fmt, ...)
50     __attribute__((format (printf, 1, 2)));
51 #else
52 void dfilter_fail(char *fmt, ...);
53 #endif
54
55 /* functions that dfilter-grammar.y needs during parsing*/
56 gboolean check_relation_numeric(gint operand, GArray *a, GArray *b);
57 gboolean check_relation_ether(gint operand, GArray *a, GArray *b);
58 gboolean check_relation_bytes(gint operand, GArray *a, GArray *b);
59
60 gboolean fill_array_numeric_value(GNode *gnode, gpointer data);
61 gboolean fill_array_numeric_variable(GNode *gnode, gpointer data);
62 gboolean fill_array_ether_value(GNode *gnode, gpointer data);
63 gboolean fill_array_ether_variable(GNode *gnode, gpointer data);
64 gboolean fill_array_bytes_value(GNode *gnode, gpointer data);
65 gboolean fill_array_bytes_variable(GNode *gnode, gpointer data);
66
67 #ifdef WIN32
68 #define boolean truth_value
69 #endif
70
71 enum node_type {
72         relation,       /* eq, ne, gt, ge, lt, le */
73         logical,        /* and, or, not, xor */
74         variable,       /* protocol or header field id */
75         existence,      /* existence of a variable (protocol or hf) */
76         alternation,    /* &, | */
77         boolean,        /* true, false */
78         numeric,        /* uint8, uint16, or uint32 value */
79         abs_time,
80         string,
81         ether,
82         bytes,
83         ipv4,
84         ipxnet
85 };
86
87 typedef gboolean(*CheckRelationFunc) (gint operand, GArray *a, GArray *b);
88
89 /* This struct is the parse tree node created by this grammary and used
90  * directly in the display filter routines to filter packets.
91  */
92 typedef struct dfilter_node {
93         enum node_type                  ntype; /* from dfilter-grammar.h */
94         int                             elem_size; /* computed at dfilter parse time rather than
95                                                 when finding elements for each packet. Saves time
96                                                 in get_values_from_ptree() */
97         CheckRelationFunc               check_relation_func;
98         GNodeTraverseFunc               fill_array_func;
99
100         /* copied from proto.h */
101         union {
102                 gint            relation; /* if type == relation (eq, ne, gt, ge, lt, le) */
103                 gint            logical;  /* if type == logical (and, or, not, xor) */
104                 gint            variable; /* if type == variable (protocol or header field abbrev) */
105                 gint            alternation; /* if type == alternation (& or |) */
106
107                 guint32         numeric;
108                 struct timeval  abs_time; /* the whole struct, not a pointer */
109                 gchar           *string;
110                 guint8          ether[6];
111                 GByteArray      *bytes;
112         }                               value;
113
114         /* used for byte-ranges */
115         gint                            offset;
116         guint                           length;
117 } dfilter_node;
118
119 /* lookup an abbreviation in our token hash, returing the ID # */
120 int dfilter_lookup_token(char *abbrev);
121
122 #endif /* ! __DFILTER_INT_H__ */