Re-apply r40728 and fix Coverity CID 1371 UNINIT again.
[obnox/wireshark/wip.git] / epan / stream.h
1 /* stream.h
2  *
3  * Definititions for handling circuit-switched protocols
4  * which are handled as streams, and don't have lengths
5  * and IDs such as are required for reassemble.h
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifndef STREAM_H
29 #define STREAM_H
30
31 #include <epan/tvbuff.h>
32
33 struct _fragment_items;
34
35 /* A stream represents the concept of an arbitrary stream of data,
36    divided up into frames for transmission, where the frames have
37    little or no correspondence to the PDUs of the protocol being
38    streamed, and those PDUs are just delineated by a magic number.
39
40    For example, we stream H.223 over IAX2. IAX2 has no concept of
41    H.223 PDUs and just divides the H.223 stream into 160-byte
42    frames. H.223 PDUs are delineated by two-byte magic numbers (which
43    may, of course, straddle an IAX2 frame boundary).
44
45    Essentially we act as a wrapper to reassemble.h, by making up
46    PDU ids and keeping some additional data on fragments to allow the
47    PDUs to be defragmented again.
48 */
49
50
51 /* A stream_t represents a stream. There might be one or two streams
52    in a circuit, depending on whether that circuit is mono- or bi-directional.
53 */
54 typedef struct stream stream_t;
55
56 /* Fragments in a PDU are represented using a stream_pdu_fragment_t,
57    and placed in a linked-list with other fragments in the PDU.
58
59    (They're also placed in a hash so we can find them again later)
60 */
61 typedef struct stream_pdu_fragment stream_pdu_fragment_t;
62
63
64
65 struct circuit;
66 struct conversation;
67
68 /* initialise a new stream. Call this when you first identify a distinct
69  * stream. The circit pointer is just used as a key to look up the stream. */
70 extern stream_t *stream_new_circ ( const struct circuit *circuit, int p2p_dir );
71 extern stream_t *stream_new_conv ( const struct conversation *conv, int p2p_dir );
72
73 /* retrieve a previously-created stream.
74  *
75  * Returns null if no matching stream was found.
76  */
77 extern stream_t *find_stream_circ ( const struct circuit *circuit, int p2p_dir );
78 extern stream_t *find_stream_conv ( const struct conversation *conv, int p2p_dir );
79
80
81
82 /* see if we've seen this fragment before.
83
84    The framenum and offset are just hash keys, so can be any values unique
85    to this frame, but the idea is that you use the number of the frame being
86    disassembled, and the byte-offset within that frame.
87 */
88 extern stream_pdu_fragment_t *stream_find_frag( stream_t *stream, guint32 framenum, guint32 offset );
89
90 /* add a new fragment to the fragment tables for the stream. The framenum and
91  * offset are keys allowing future access with stream_find_frag(), tvb is the
92  * fragment to be added, and pinfo is the information for the frame containing
93  * this fragment. more_frags should be set if this is the final fragment in the
94  * PDU.
95  *
96  * * the fragment must be later in the stream than any previous fragment
97  *   (ie, framenum.offset must be greater than those passed on the previous
98  *   call)
99  *
100  * This essentially means that you can only add fragments on the first pass
101  * through the stream.
102  */
103 extern stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guint32 offset,
104                                         tvbuff_t *tvb, packet_info *pinfo, gboolean more_frags );
105
106 /* Get the length of a fragment previously found by stream_find_frag().
107  */
108 extern guint32 stream_get_frag_length( const stream_pdu_fragment_t *frag);
109
110 /* Get a handle on the top of the chain of fragment_datas underlying this PDU
111  * frag can be any fragment within a PDU, and it will always return the head of
112  * the chain
113  *
114  * Returns NULL until the last fragment is added.
115  */
116 extern struct _fragment_data *stream_get_frag_data( const stream_pdu_fragment_t *frag);
117
118 /*
119  * Process reassembled data; if this is the last fragment, put the fragment
120  * information into the protocol tree, and construct a tvbuff with the
121  * reassembled data, otherwise just put a "reassembled in" item into the
122  * protocol tree.
123  */
124 extern tvbuff_t *stream_process_reassembled(
125     tvbuff_t *tvb, int offset, packet_info *pinfo,
126     const char *name, const stream_pdu_fragment_t *frag,
127     const struct _fragment_items *fit,
128     gboolean *update_col_infop, proto_tree *tree);
129
130 /* Get the PDU number. PDUs are numbered from zero within a stream.
131  * frag can be any fragment within a PDU.
132  */
133 extern guint32 stream_get_pdu_no( const stream_pdu_fragment_t *frag);
134
135 /* initialise the stream routines */
136 void stream_init( void );
137 void stream_cleanup( void );
138
139 #endif /* STREAM_H */