add WERR_INVALID_STATE
[wireshark-wip.git] / plugins / mate / mate.h
blob74cae5258b027b90845620afa3a8623d9ab7824e
1 /* mate.h
2 * MATE -- Meta Analysis and Tracing Engine
4 * Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #ifndef __MATE_H_
29 #define __MATE_H_
31 #include "config.h"
33 #ifndef ENABLE_STATIC
34 #include "moduleinfo.h"
35 #include <gmodule.h>
36 #else
37 #include <glib.h>
38 #endif
40 #include <stdio.h>
41 #include <string.h>
42 #include <errno.h>
44 #include <wsutil/report_err.h>
46 #include <epan/packet.h>
47 #include <epan/exceptions.h>
48 #include <epan/strutil.h>
49 #include <epan/prefs.h>
50 #include <epan/proto.h>
51 #include <epan/epan_dissect.h>
52 #include <epan/tap.h>
53 #include <epan/filesystem.h>
55 #include "mate_util.h"
57 /* defaults */
59 #define DEFAULT_GOG_EXPIRATION 2.0
61 #ifdef _WIN32
62 #define DIR_SEP '\\'
63 #else
64 #define DIR_SEP '/'
65 #endif
67 #define DEFAULT_MATE_LIB_PATH "matelib"
69 #define MATE_ITEM_ID_SIZE 24
71 #define VALUE_TOO ((void*)1)
73 #define MateConfigError 65535
75 typedef enum _gop_tree_mode_t {
76 GOP_NULL_TREE,
77 GOP_BASIC_TREE,
78 GOP_FULL_TREE
79 } gop_tree_mode_t;
81 typedef enum _gop_pdu_tree {
82 GOP_NO_TREE,
83 GOP_PDU_TREE,
84 GOP_FRAME_TREE,
85 GOP_BASIC_PDU_TREE
86 } gop_pdu_tree_t;
88 typedef enum _accept_mode_t {
89 ACCEPT_MODE,
90 REJECT_MODE
91 } accept_mode_t;
94 typedef struct _mate_cfg_pdu {
95 gchar* name;
96 guint last_id; /* keeps the last id given to an item of this kind */
98 GHashTable* items; /* all the items of this type */
99 GPtrArray* transforms; /* transformations to be applied */
101 int hfid;
103 int hfid_proto;
104 int hfid_pdu_rel_time;
105 int hfid_pdu_time_in_gop;
107 GHashTable* my_hfids; /* for creating register info */
109 gint ett;
110 gint ett_attr;
112 GHashTable* hfids_attr; /* k=hfid v=avp_name */
114 gboolean discard;
115 gboolean last_extracted;
116 gboolean drop_unassigned;
118 GPtrArray* transport_ranges; /* hfids of candidate transport ranges from which to extract attributes */
119 GPtrArray* payload_ranges; /* hfids of candidate payload ranges from which to extract attributes */
121 avpl_match_mode criterium_match_mode;
122 accept_mode_t criterium_accept_mode;
123 AVPL* criterium;
124 } mate_cfg_pdu;
127 typedef struct _mate_cfg_gop {
128 gchar* name;
129 guint last_id; /* keeps the last id given to an item of this kind */
130 GHashTable* items; /* all the items of this type */
132 GPtrArray* transforms; /* transformations to be applied */
133 gchar* on_pdu;
135 AVPL* key; /* key candidate avpl */
136 AVPL* start; /* start candidate avpl */
137 AVPL* stop; /* stop candidate avpl */
138 AVPL* extra; /* attributes to be added */
140 float expiration;
141 float idle_timeout;
142 float lifetime;
144 gboolean drop_unassigned;
145 gop_pdu_tree_t pdu_tree_mode;
146 gboolean show_times;
148 GHashTable* my_hfids; /* for creating register info */
149 int hfid;
150 int hfid_start_time;
151 int hfid_stop_time;
152 int hfid_last_time;
153 int hfid_gop_pdu;
154 int hfid_gop_num_pdus;
156 gint ett;
157 gint ett_attr;
158 gint ett_times;
159 gint ett_children;
161 GHashTable* gop_index;
162 GHashTable* gog_index;
163 } mate_cfg_gop;
166 typedef struct _mate_cfg_gog {
167 gchar* name;
169 GHashTable* items; /* all the items of this type */
170 guint last_id; /* keeps the last id given to an item of this kind */
172 GPtrArray* transforms; /* transformations to be applied */
174 LoAL* keys;
175 AVPL* extra; /* attributes to be added */
177 float expiration;
178 gop_tree_mode_t gop_tree_mode;
179 gboolean show_times;
181 GHashTable* my_hfids; /* for creating register info */
182 int hfid;
183 int hfid_gog_num_of_gops;
184 int hfid_gog_gop;
185 int hfid_gog_gopstart;
186 int hfid_gog_gopstop;
187 int hfid_start_time;
188 int hfid_stop_time;
189 int hfid_last_time;
190 gint ett;
191 gint ett_attr;
192 gint ett_times;
193 gint ett_children;
194 gint ett_gog_gop;
195 } mate_cfg_gog;
197 typedef struct _mate_config {
198 gchar* mate_config_file; /* name of the config file */
200 int hfid_mate;
202 GString* fields_filter; /* "ip.addr || dns.id || ... " for the tap */
203 GString* protos_filter; /* "dns || ftp || ..." for the tap */
204 gchar* tap_filter;
206 FILE* dbg_facility; /* where to dump dbgprint output g_message if null */
208 gchar* mate_lib_path; /* where to look for "Include" files first */
210 GHashTable* pducfgs; /* k=pducfg->name v=pducfg */
211 GHashTable* gopcfgs; /* k=gopcfg->name v=gopcfg */
212 GHashTable* gogcfgs; /* k=gogcfg->name v=gogcfg */
213 GHashTable* transfs; /* k=transform->name v=transform */
215 GPtrArray* pducfglist; /* pducfgs in order of "execution" */
216 GHashTable* gops_by_pduname; /* k=pducfg->name v=gopcfg */
217 GHashTable* gogs_by_gopname; /* k=gopname v=loal where avpl->name == matchedgop->name */
219 GArray* hfrs;
220 gint ett_root;
221 GArray* ett;
223 /* defaults */
224 struct _mate_cfg_defaults {
225 struct _pdu_defaults {
226 avpl_match_mode match_mode;
227 avpl_replace_mode replace_mode;
228 gboolean last_extracted;
230 gboolean drop_unassigned;
231 gboolean discard;
232 } pdu;
234 struct _gop_defaults {
235 float expiration;
236 float idle_timeout;
237 float lifetime;
239 gop_pdu_tree_t pdu_tree_mode;
240 gboolean show_times;
241 gboolean drop_unassigned;
243 } gop;
245 struct _gog_defaults {
246 float expiration;
247 gboolean show_times;
248 gop_tree_mode_t gop_tree_mode;
249 } gog;
250 } defaults;
252 /* what to dbgprint */
253 int dbg_lvl;
254 int dbg_pdu_lvl;
255 int dbg_gop_lvl;
256 int dbg_gog_lvl;
258 GPtrArray* config_stack;
259 GString* config_error;
261 } mate_config;
264 typedef struct _mate_config_frame {
265 gchar* filename;
266 guint linenum;
267 } mate_config_frame;
270 typedef struct _mate_runtime_data {
271 guint current_items; /* a count of items */
272 float now;
273 guint highest_analyzed_frame;
275 GHashTable* frames; /* k=frame.num v=pdus */
277 } mate_runtime_data;
279 typedef struct _mate_pdu mate_pdu;
280 typedef struct _mate_gop mate_gop;
281 typedef struct _mate_gog mate_gog;
283 /* these are used to contain information regarding pdus, gops and gogs */
284 struct _mate_pdu {
285 guint32 id; /* 1:1 -> saving a g_malloc */
286 mate_cfg_pdu* cfg; /* the type of this item */
288 AVPL* avpl;
290 guint32 frame; /* wich frame I belog to? */
291 mate_pdu* next_in_frame; /* points to the next pdu in this frame */
292 float rel_time; /* time since start of capture */
294 mate_gop* gop; /* the gop the pdu belongs to (if any) */
295 mate_pdu* next; /* next in gop */
296 float time_in_gop; /* time since gop start */
298 gboolean first; /* is this the first pdu in this frame? */
299 gboolean is_start; /* this is the start pdu for this gop */
300 gboolean is_stop; /* this is the stop pdu for this gop */
301 gboolean after_release; /* this pdu comes after the stop */
306 struct _mate_gop {
307 guint32 id;
308 mate_cfg_gop* cfg;
310 gchar* gop_key;
311 AVPL* avpl; /* the attributes of the pdu/gop/gog */
312 guint last_n;
314 mate_gog* gog; /* the gog of a gop */
315 mate_gop* next; /* next in gog; */
317 float expiration; /* when will it expire after release (all gops releases if gog)? */
318 float idle_expiration; /* when will it expire if no new pdus are assigned to it */
319 float time_to_die;
320 float time_to_timeout;
322 float start_time; /* time of start */
323 float release_time; /* when this gop/gog was released */
324 float last_time; /* the rel_time at which the last pdu has been added (to gop or gog's gop) */
327 int num_of_pdus; /* how many gops a gog has? */
328 int num_of_after_release_pdus; /* how many pdus have arrived since it's been released */
329 mate_pdu* pdus; /* pdus that belong to a gop (NULL in gog) */
330 mate_pdu* last_pdu; /* last pdu in pdu's list */
332 gboolean released; /* has this gop been released? */
336 struct _mate_gog {
337 guint32 id;
338 mate_cfg_gog* cfg;
340 AVPL* avpl; /* the attributes of the pdu/gop/gog */
341 guint last_n; /* the number of attributes the avpl had the last time we checked */
343 gboolean released; /* has this gop been released? */
345 float expiration; /* when will it expire after release (all gops releases if gog)? */
346 float idle_expiration; /* when will it expire if no new pdus are assigned to it */
348 /* on gop and gog: */
349 float start_time; /* time of start */
350 float release_time; /* when this gog was released */
351 float last_time; /* the rel_time at which the last pdu has been added */
353 mate_gop* gops; /* gops that belong to a gog (NULL in gop) */
354 mate_gop* last_gop; /* last gop in gop's list */
356 int num_of_gops; /* how many gops a gog has? */
357 int num_of_counting_gops; /* how many of them count for gog release */
358 int num_of_released_gops; /* how many of them have already been released */
359 GPtrArray* gog_keys; /* the keys under which this gog is stored in the gogs hash */
362 typedef union _mate_max_size {
363 mate_pdu pdu;
364 mate_gop gop;
365 mate_gog gog;
366 } mate_max_size;
368 /* from mate_runtime.c */
369 extern void initialize_mate_runtime(void);
370 extern mate_pdu* mate_get_pdus(guint32 framenum);
371 extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree);
373 /* from mate_setup.c */
374 extern mate_config* mate_make_config(const gchar* filename, int mate_hfid);
376 extern mate_config* mate_cfg(void);
377 extern mate_cfg_pdu* new_pducfg(gchar* name);
378 extern mate_cfg_gop* new_gopcfg(gchar* name);
379 extern mate_cfg_gog* new_gogcfg(gchar* name);
381 extern gboolean add_hfid(header_field_info* hfi, gchar* as, GHashTable* where);
382 extern gchar* add_ranges(gchar* range, GPtrArray* range_ptr_arr);
385 /* from mate_parser.l */
386 extern gboolean mate_load_config(const gchar* filename, mate_config* mc);
388 #endif