Add casts to fix mac buildbots.
[metze/wireshark/wip.git] / epan / tvbuff-int.h
1 /* tvbuff-int.h
2  *
3  * Structures that most TVB users should not be accessing directly.
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifndef __TVBUFF_INT_H__
27 #define __TVBUFF_INT_H__
28
29 struct tvbuff;
30
31 struct tvb_ops {
32         gsize tvb_size;
33         void (*tvb_free)(struct tvbuff *tvb);
34         guint (*tvb_offset)(const struct tvbuff *tvb, guint counter);
35         const guint8 *(*tvb_get_ptr)(struct tvbuff *tvb, guint abs_offset, guint abs_length);
36         void *(*tvb_memcpy)(struct tvbuff *tvb, void *target, guint offset, guint length);
37
38         gint (*tvb_find_guint8)(tvbuff_t *tvb, guint abs_offset, guint limit, guint8 needle);
39         gint (*tvb_pbrk_guint8)(tvbuff_t *tvb, guint abs_offset, guint limit, const guint8 *needles, guchar *found_needle);
40
41         tvbuff_t *(*tvb_clone)(tvbuff_t *tvb, guint abs_offset, guint abs_length);
42 };
43
44 /*
45  * Tvbuff flags.
46  */
47 #define TVBUFF_FRAGMENT         0x00000001      /* this is a fragment */
48
49 struct tvbuff {
50         /* Doubly linked list pointers */
51         tvbuff_t                *next;
52
53         /* Record-keeping */
54         const struct tvb_ops   *ops;
55         gboolean                initialized;
56         guint                   flags;
57         struct tvbuff           *ds_tvb;  /**< data source top-level tvbuff */
58
59         /** We're either a TVBUFF_REAL_DATA or a
60          * TVBUFF_SUBSET that has a backing buffer that
61          * has real_data != NULL, or a TVBUFF_COMPOSITE
62          * which has flattened its data due to a call
63          * to tvb_get_ptr().
64          */
65         const guint8            *real_data;
66
67         /** Length of virtual buffer (and/or real_data). */
68         guint                   length;
69
70         /** Reported length. */
71         guint                   reported_length;
72
73         /* Offset from beginning of first TVBUFF_REAL. */
74         gint                    raw_offset;
75 };
76
77 WS_DLL_PUBLIC tvbuff_t *tvb_new(const struct tvb_ops *ops);
78
79 tvbuff_t *tvb_new_proxy(tvbuff_t *backing);
80
81 void tvb_add_to_chain(tvbuff_t *parent, tvbuff_t *child);
82
83 guint tvb_offset_from_real_beginning_counter(const tvbuff_t *tvb, const guint counter);
84
85 void tvb_check_offset_length(const tvbuff_t *tvb, const gint offset, gint const length_val, guint *offset_ptr, guint *length_ptr);
86 #endif