remove remnants of the old plugin api from dissectors and plugins
[obnox/wireshark/wip.git] / plugins / mate / mate.h
1 /* mate.h
2 * MATE -- Meta Analysis and Tracing Engine 
3 *
4 * Copyright 2004, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
5 *
6 * $Id$
7 *
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
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
28 #ifndef __MATE_H_
29 #define __MATE_H_
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #ifndef ENABLE_STATIC
36 #include "moduleinfo.h"
37 #include <gmodule.h>
38 #else 
39 #include <glib.h>
40 #endif
41
42 #include <stdio.h>
43 #include <string.h>
44 #include <errno.h>
45
46 #include <epan/packet.h>
47 #include <epan/strutil.h>
48 #include <epan/prefs.h>
49 #include <epan/proto.h>
50 #include <epan/epan_dissect.h>
51 #include <epan/tap.h>
52 #include <epan/filesystem.h>
53 #include <epan/report_err.h>
54
55 #include "mate_util.h"
56
57 /* defaults */
58
59 #define DEFAULT_GOG_EXPIRATION 2.0
60
61 #ifdef WIN32
62 #define DIR_SEP '\\'
63 #else
64 #define DIR_SEP '/'
65 #endif
66
67 #define DEFAULT_MATE_LIB_PATH "matelib"
68
69 #define MATE_ITEM_ID_SIZE 24
70
71 /* Config AVP Names */
72 #define KEYWORD_ACTION "Action"
73 #define KEYWORD_SETTINGS "Settings"
74 #define KEYWORD_INCLUDE "Include"
75 #define KEYWORD_TRANSFORM "Transform"
76 #define KEYWORD_PDU "PduDef"
77 #define KEYWORD_PDUCRITERIA "PduCriteria"
78 #define KEYWORD_PDUEXTRA "PduExtra"
79 #define KEYWORD_PDUTRANSFORM "PduTransform"
80 #define KEYWORD_GOP "GopDef"
81 #define KEYWORD_GOPSTART "GopStart"
82 #define KEYWORD_GOPSTOP "GopStop"
83 #define KEYWORD_GOPEXTRA "GopExtra"
84 #define KEYWORD_GOPTRANSFORM "GopTransform"
85 #define KEYWORD_GOGDEF "GogDef"
86 #define KEYWORD_GOGKEY "GogKey"
87 #define KEYWORD_GOGEXTRA "GogExtra"
88 #define KEYWORD_GOGTRANSFORM "GogTransform"
89 #define KEYWORD_NAME "Name"
90 #define KEYWORD_ON "On"
91 #define KEYWORD_FOR "For"
92 #define KEYWORD_FROM "From"
93 #define KEYWORD_TO "To"
94 #define KEYWORD_MATCH "Match"
95 #define KEYWORD_MODE "Mode"
96 #define KEYWORD_FILENAME "Filename"
97 #define KEYWORD_PROTO "Proto"
98 #define KEYWORD_METHOD "Method"
99 #define KEYWORD_TRANSPORT "Transport"
100 #define KEYWORD_PAYLOAD "Payload"
101 #define KEYWORD_STRICT "Strict"
102 #define KEYWORD_LOOSE "Loose"
103 #define KEYWORD_EVERY "Every"
104 #define KEYWORD_REPLACE "Replace"
105 #define KEYWORD_INSERT "Insert"
106 #define KEYWORD_MAP "Map"
107 #define KEYWORD_GOGEXPIRE "GogExpiration"
108 #define KEYWORD_GOPTREE "GopTree"
109 #define KEYWORD_DISCARDPDU "DiscardPduData"
110 #define KEYWORD_LIBPATH "ThingLibPath"
111 #define KEYWORD_SHOWPDUTREE "ShowPduTree"
112 #define KEYWORD_SHOWGOPTIMES "ShowGopTimes"
113 #define KEYWORD_STOP "Stop"
114 #define KEYWORD_DROPGOP "DiscardUnassignedGop"
115 #define KEYWORD_DROPPDU "DiscardUnassignedPdu"
116 #define KEYWORD_LIB "Lib"
117 #define KEYWORD_ACCEPT "Accept"
118 #define KEYWORD_REJECT "Reject"
119 #define KEYWORD_NOTREE "NoTree"
120 #define KEYWORD_BASICTREE "BasicTree"
121 #define KEYWORD_FULLTREE "FullTree"
122 #define KEYWORD_PDUTREE "PduTree"
123 #define KEYWORD_FRAMETREE "FrameTree"
124 #define KEYWORD_GOPEXPIRATION "GopExpiration"
125 #define KEYWORD_GOPIDLETIMEOUT "GopIdleTimeout"
126 #define KEYWORD_GOPLIFETIME "GopLifetime"
127
128 #define KEYWORD_DEBUGFILENAME "Debug_File"
129 #define KEYWORD_DBG_GENERAL "Debug_General"
130 #define KEYWORD_DBG_CFG "Debug_Cfg"
131 #define KEYWORD_DBG_PDU "Debug_Pdu"
132 #define KEYWORD_DBG_GOP "Debug_Gop"
133 #define KEYWORD_DBG_GOG "Debug_Gog"
134 #ifdef _AVP_DEBUGGING
135 #define KEYWORD_DBG_AVPLIB "Debug_AVP_Lib"
136 #define KEYWORD_DBG_AVP "Debug_AVP"
137 #define KEYWORD_DBG_AVP_OP "Debug_AVP_Op"
138 #define KEYWORD_DBG_AVPL "Debug_AVPL"
139 #define KEYWORD_DBG_AVPL_OP "Debug_AVPL_Op"
140 #endif
141
142 #define VALUE_TOO ((void*)1)
143
144 typedef enum _mate_item_type {
145         MATE_UNK_TYPE,
146         MATE_PDU_TYPE,
147         MATE_GOP_TYPE,
148         MATE_GOG_TYPE
149 } mate_item_type;
150
151 typedef struct _mate_cfg_item mate_cfg_pdu;
152 typedef struct _mate_cfg_item mate_cfg_gop;
153 typedef struct _mate_cfg_item mate_cfg_gog;
154
155 typedef struct _mate_item mate_item;
156 typedef struct _mate_item mate_pdu;
157 typedef struct _mate_item mate_gop;
158 typedef struct _mate_item mate_gog;
159
160 typedef struct _mate_cfg_item {
161         guint8* name;
162         mate_item_type type; 
163         GPtrArray* transforms; /* transformations to be applied */
164         AVPL* extra; /* attributes to be added */
165         guint last_id; /* keeps the last id given to an item of this kind */
166         int hfid;
167         GHashTable* my_hfids; /* for creating register info */
168         GHashTable* items; /* all the items of this type */
169         gint ett;
170         gint ett_attr;
171         gint ett_times;
172         gint ett_children;
173                 
174         /* pdu */
175         gboolean discard_pdu_attributes;
176         gboolean last_to_be_created;
177         int hfid_proto;
178         GPtrArray* transport_ranges; /* hfids of candidate transport ranges from which to extract attributes */
179         GPtrArray* payload_ranges; /* hfids of candidate payload ranges from which to extract attributes */
180         GHashTable* hfids_attr; /* k=hfid v=avp_name */
181         gboolean drop_pdu;
182         avpl_match_mode criterium_match_mode;
183         AVPL* criterium; /* must match to be created */
184         int hfid_pdu_rel_time;
185         int hfid_pdu_time_in_gop;
186         
187         
188         /* common to gop and gog */
189         float expiration;
190         int hfid_start_time;
191         int hfid_stop_time;
192         int hfid_last_time;
193         
194         /* gop */
195         AVPL* start; /* start candidate avpl */
196         AVPL* stop;  /* stop candidate avpl */
197         AVPL* key; /* key candidate avpl */
198         guint8* show_pdu_tree;
199         gboolean show_times;
200         gboolean drop_gop; 
201         float idle_timeout;
202         float lifetime; 
203         int hfid_gop_pdu;
204         int hfid_gop_num_pdus;
205         
206         GHashTable* gop_index;
207         GHashTable* gog_index;
208         
209         /* gog */
210         guint8* gop_as_subtree;
211         LoAL* keys;
212         int hfid_gog_num_of_gops;
213         int hfid_gog_gop;
214         int hfid_gog_gopstart;
215         int hfid_gog_gopstop;   
216         gint ett_gog_gop;
217         
218 } mate_cfg_item;
219
220 typedef struct _mate_config {
221         /* current defaults */
222         float gog_expiration; /* default expirations for gogs if undefined in gog */
223         gboolean discard_pdu_attributes; /* destroy the pdu's avpl once analyzed */
224         gboolean drop_pdu; /* destroy the pdu if not assign to a gop */
225         gboolean drop_gop; /* destroy the gop if not assign to a gog */
226         guint8* mate_lib_path; /* where to look for "Include" files first */
227         guint8* show_pdu_tree;
228         gboolean show_times;
229         gboolean last_to_be_created;
230         avpl_match_mode match_mode;
231         avpl_replace_mode replace_mode;
232         guint8* gop_as_subtree;
233         int hfid_mate;
234         
235         float gop_expiration;
236         float gop_idle_timeout;
237         float gop_lifetime;
238         
239         /* text "constants" */
240         guint8* accept;
241         guint8* reject;
242         guint8* no_tree;
243         guint8* frame_tree;
244         guint8* pdu_tree;
245         guint8* full_tree;
246         guint8* basic_tree;
247         
248         /* what to dbgprint */
249         int dbg_lvl;    
250         int dbg_cfg_lvl;
251         int dbg_pdu_lvl;
252         int dbg_gop_lvl;
253         int dbg_gog_lvl;
254         
255         guint8* mate_config_file; /* name of the config file */
256         GString* mate_attrs_filter; /* "ip.addr || dns.id || ... " for the tap */
257         GString* mate_protos_filter; /* "dns || ftp || ..." for the tap */
258         FILE* dbg_facility; /* where to dump dbgprint output g_message if null */
259         guint8* tap_filter;
260                         
261         GHashTable* pducfgs; /* k=pducfg->name v=pducfg */
262         GHashTable* gopcfgs; /* k=gopcfg->name v=gopcfg */
263         GHashTable* gogcfgs; /* k=gogcfg->name v=gogcfg */
264         GHashTable* transfs; /* k=transform->name v=transform */
265         
266         GPtrArray* pducfglist; /* pducfgs in order of "execution" */
267         GHashTable* gops_by_pduname; /* k=pducfg->name v=gopcfg */
268         GHashTable* gogs_by_gopname; /* k=gopname v=loal where avpl->name == matchedgop->name */
269
270         GArray* hfrs;
271         gint ett_root;
272         GArray* ett;
273 } mate_config;
274
275 typedef struct _mate_runtime_data {
276         guint current_items; /* a count of items */
277         GMemChunk* mate_items;
278         float now;
279         guint highest_analyzed_frame;
280         
281         GHashTable* frames; /* k=frame.num v=pdus */
282         
283 } mate_runtime_data;
284
285 /* these are used to contain information regarding pdus, gops and gogs */
286 struct _mate_item {
287         /* all three of them */
288         guint32 id; /* 1:1 -> saving a g_malloc */
289         mate_cfg_item* cfg; /* the type of this item */
290
291         AVPL* avpl; /* the attributes of the pdu/gop/gog */
292                 
293         mate_item* next; /* in pdu: next in gop; in gop: next in gog; in gog this doesn't make any sense yet */
294         
295         float expiration; /* when will it expire after release (all gops releases if gog)? */
296         float idle_expiration; /* when will it expire if no new pdus are assigned to it */
297         
298         /* on gop and gog: */
299         float start_time; /* time of start */
300         float release_time; /* when this gop/gog was released */
301         float last_time; /* the rel_time at which the last pdu has been added (to gop or gog's gop) */
302         
303         /* union _payload { */
304                 /* struct _pdu { */
305                         guint32 frame; /* wich frame I belog to? */
306                         mate_gop* gop; /* the gop the pdu belongs to (if any) */
307                         gboolean first; /* is this the first pdu in this frame? */
308                         gboolean is_start; /* this is the start pdu for this gop */
309                         gboolean is_stop; /* this is the stop pdu for this gop */
310                         gboolean after_release; /* this pdu comes after the stop */
311                         float rel_time; /* time since start of capture  */
312                         float time_in_gop; /* time since gop start */
313                         mate_pdu* next_in_frame; /* points to the next pdu in this frame */
314                 /* } pdu; */
315                 
316                 /* struct _gop { */
317                         /* membership* gogs; */
318                         mate_gog* gog; /* the gog of a gop */
319                         mate_pdu* pdus; /* pdus that belong to a gop (NULL in gog) */
320                         gboolean released; /* has this gop been released? */
321                         int num_of_pdus; /* how many gops a gog has? */
322                         int num_of_after_release_pdus;  /* how many pdus have arrived since it's been released */
323                         guint8* gop_key; /* used by gop */
324                         mate_pdu* last_pdu; /* last pdu in pdu's list */
325                         float time_to_die;
326                         float time_to_timeout;
327                 /* } gop; */
328                 
329                 /* struct _gog { */
330                         /* membership* gops; */
331                         mate_gop* gops; /* gops that belong to a gog (NULL in gop) */
332                         int num_of_gops; /* how many gops a gog has? */
333                         int num_of_counting_gops;  /* how many of them count for gog release */
334                         int num_of_released_gops;  /* how many of them have already been released */
335                         guint last_n; /* the number of attributes the avpl had the last time we checked */
336                         GPtrArray* gog_keys; /* the keys under which this gog is stored in the gogs hash */
337                         mate_gop* last_gop; /* last gop in gop's list */
338                 /* } gog; */
339         /* } o; */
340 };
341
342 /* from mate_runtime.c */
343 extern void initialize_mate_runtime(void);
344 extern mate_pdu* mate_get_pdus(guint32 framenum);
345 extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree);
346
347 /* from mate_setup.c */
348 extern mate_config* mate_make_config(guint8* filename, int mate_hfid);
349 extern mate_config* mate_cfg(void);
350
351 #endif