Try to fix Windows compilation
[metze/wireshark/wip.git] / epan / conversation.h
1 /* conversation.h
2  * Routines for building lists of packets that are part of a "conversation"
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __CONVERSATION_H__
26 #define __CONVERSATION_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 /**
33  *@file
34  */
35 /*
36  * Flags to pass to "conversation_new()" to indicate that the address 2
37  * and/or port 2 values for the conversation should be wildcards.
38  * The CONVERSATION_TEMPLATE option tells that any of the other supplied
39  * port and / or address wildcards will be used to match an infinite number
40  * of new connections to the conversation(s) that have the CONVERSATION_-
41  * TEMPLATE flag set. Any conversation created without the CONVERSATION_-
42  * TEMPLATE flag will be altered once the first connections (connection
43  * oriented protocols only) to include the newly found information which
44  * matched the wildcard options.
45  */
46 #define NO_ADDR2 0x01
47 #define NO_PORT2 0x02
48 #define NO_PORT2_FORCE 0x04
49 #define CONVERSATION_TEMPLATE 0x08
50
51 /*
52  * Flags to pass to "find_conversation()" to indicate that the address B
53  * and/or port B search arguments are wildcards.
54  */
55 #define NO_ADDR_B 0x01
56 #define NO_PORT_B 0x02
57
58 #include "packet.h"             /* for conversation dissector type */
59
60 /**
61  * Data structure representing a conversation.
62  */
63 typedef struct conversation_key {
64         struct conversation_key *next;
65         address addr1;
66         address addr2;
67         port_type ptype;
68         guint32 port1;
69         guint32 port2;
70 } conversation_key;
71
72 typedef struct conversation {
73         struct conversation *next;      /** pointer to next conversation on hash chain */
74         struct conversation *last;      /** pointer to the last conversation on hash chain */
75         struct conversation *latest_found;
76                                                                 /** pointer to the last conversation on hash chain */
77         guint32 index;                          /** unique ID for conversation */
78         guint32 setup_frame;            /** frame number that setup this conversation */
79         GSList *data_list;                      /** list of data associated with conversation */
80         dissector_handle_t dissector_handle;
81                                                                 /** handle for protocol dissector client associated with conversation */
82         guint   options;                        /** wildcard flags */
83         conversation_key *key_ptr;      /** pointer to the key for this conversation */
84 } conversation_t;
85
86 /**
87  * Destroy all existing conversations
88  */
89 extern void conversation_cleanup(void);
90
91 /**
92  * Initialize some variables every time a file is loaded or re-loaded.
93  * Create a new hash table for the conversations in the new file.
94  */
95 extern void conversation_init(void);
96
97 /*
98  * Given two address/port pairs for a packet, create a new conversation
99  * to contain packets between those address/port pairs.
100  *
101  * The options field is used to specify whether the address 2 value
102  * and/or port 2 value are not given and any value is acceptable
103  * when searching for this conversation.
104  */
105 extern conversation_t *conversation_new(const guint32 setup_frame, const address *addr1, const address *addr2,
106     const port_type ptype, const guint32 port1, const guint32 port2, const guint options);
107
108 /**
109  * Given two address/port pairs for a packet, search for a conversation
110  * containing packets between those address/port pairs.  Returns NULL if
111  * not found.
112  *
113  * We try to find the most exact match that we can, and then proceed to
114  * try wildcard matches on the "addr_b" and/or "port_b" argument if a more
115  * exact match failed.
116  *
117  * Either or both of the "addr_b" and "port_b" arguments may be specified as
118  * a wildcard by setting the NO_ADDR_B or NO_PORT_B flags in the "options"
119  * argument.  We do only wildcard matches on addresses and ports specified
120  * as wildcards.
121  *
122  * I.e.:
123  *
124  *      if neither "addr_b" nor "port_b" were specified as wildcards, we
125  *      do an exact match (addr_a/port_a and addr_b/port_b) and, if that
126  *      succeeds, we return a pointer to the matched conversation;
127  *
128  *      otherwise, if "port_b" wasn't specified as a wildcard, we try to
129  *      match any address 2 with the specified port 2 (addr_a/port_a and
130  *      {any}/addr_b) and, if that succeeds, we return a pointer to the
131  *      matched conversation;
132  *
133  *      otherwise, if "addr_b" wasn't specified as a wildcard, we try to
134  *      match any port 2 with the specified address 2 (addr_a/port_a and
135  *      addr_b/{any}) and, if that succeeds, we return a pointer to the
136  *      matched conversation;
137  *
138  *      otherwise, we try to match any address 2 and any port 2
139  *      (addr_a/port_a and {any}/{any}) and, if that succeeds, we return
140  *      a pointer to the matched conversation;
141  *
142  *      otherwise, we found no matching conversation, and return NULL.
143  */
144 extern conversation_t *find_conversation(const guint32 frame_num, const address *addr_a, const address *addr_b,
145     const port_type ptype, const guint32 port_a, const guint32 port_b, const guint options);
146
147 /**  A helper function that calls find_conversation() and, if a conversation is
148  *  not found, calls conversation_new().
149  *  The frame number and addresses are taken from pinfo.
150  *  No options are used, though we could extend this API to include an options
151  *  parameter.
152  */
153 extern conversation_t *find_or_create_conversation(packet_info *pinfo);
154
155 extern void conversation_add_proto_data(conversation_t *conv, const int proto,
156     void *proto_data);
157 extern void *conversation_get_proto_data(const conversation_t *conv, const int proto);
158 extern void conversation_delete_proto_data(conversation_t *conv, const int proto);
159
160 extern void conversation_set_dissector(conversation_t *conversation,
161     const dissector_handle_t handle);
162 /**
163  * Given two address/port pairs for a packet, search for a matching
164  * conversation and, if found and it has a conversation dissector,
165  * call that dissector and return TRUE, otherwise return FALSE.
166  *
167  * This helper uses call_dissector_only which will NOT call the default
168  * "data" dissector if the packet was rejected.
169  * Our caller is responsible to call the data dissector explicitely in case
170  * this function returns FALSE.
171  */
172 extern gboolean
173 try_conversation_dissector(const address *addr_a, const address *addr_b, const port_type ptype,
174     const guint32 port_a, const guint32 port_b, tvbuff_t *tvb, packet_info *pinfo,
175     proto_tree *tree);
176
177 /* These routines are used to set undefined values for a conversation */
178
179 extern void conversation_set_port2(conversation_t *conv, const guint32 port);
180 extern void conversation_set_addr2(conversation_t *conv, const address *addr);
181
182 #ifdef __cplusplus
183 }
184 #endif /* __cplusplus */
185
186 #endif /* conversation.h */