3 * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "tvbuff-int.h"
28 #include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
29 #include "exceptions.h"
34 /** Func to call when actually freed */
35 tvbuff_free_cb_t free_cb;
39 real_free(tvbuff_t *tvb)
41 struct tvb_real *real_tvb = (struct tvb_real *) tvb;
43 if (real_tvb->free_cb) {
45 * XXX - do this with a union?
47 real_tvb->free_cb((gpointer)tvb->real_data);
52 real_offset(const tvbuff_t *tvb _U_, const guint counter)
57 static const struct tvb_ops tvb_real_ops = {
58 sizeof(struct tvb_real), /* size */
61 real_offset, /* offset */
64 NULL, /* find_guint8 */
65 NULL, /* pbrk_guint8 */
70 tvb_new_real_data(const guint8* data, const guint length, const gint reported_length)
73 struct tvb_real *real_tvb;
75 THROW_ON(reported_length < -1, ReportedBoundsError);
77 tvb = tvb_new(&tvb_real_ops);
79 tvb->real_data = data;
81 tvb->reported_length = reported_length;
82 tvb->initialized = TRUE;
85 * This is the top-level real tvbuff for this data source,
86 * so its data source tvbuff is itself.
90 real_tvb = (struct tvb_real *) tvb;
91 real_tvb->free_cb = NULL;
97 tvb_set_free_cb(tvbuff_t *tvb, const tvbuff_free_cb_t func)
99 struct tvb_real *real_tvb = (struct tvb_real *) tvb;
101 DISSECTOR_ASSERT(tvb);
102 DISSECTOR_ASSERT(tvb->ops == &tvb_real_ops);
103 real_tvb->free_cb = func;
107 tvb_set_child_real_data_tvbuff(tvbuff_t *parent, tvbuff_t *child)
109 DISSECTOR_ASSERT(parent && child);
110 DISSECTOR_ASSERT(parent->initialized);
111 DISSECTOR_ASSERT(child->initialized);
112 DISSECTOR_ASSERT(child->ops == &tvb_real_ops);
113 tvb_add_to_chain(parent, child);
117 tvb_new_child_real_data(tvbuff_t *parent, const guint8* data, const guint length, const gint reported_length)
119 tvbuff_t *tvb = tvb_new_real_data(data, length, reported_length);
121 tvb_set_child_real_data_tvbuff(parent, tvb);
127 * Editor modelines - http://www.wireshark.org/tools/modelines.html
132 * indent-tabs-mode: t
135 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
136 * :indentSize=8:tabSize=8:noTabs=false: