summaryrefslogtreecommitdiff
path: root/epan/tvbuff_real.c
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2013-07-14 07:42:19 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2013-07-14 07:42:19 +0000
commit0d85b75305677a1298b76718112c4e440f84b94c (patch)
tree70ddebed4e192eb88700d2dd208d58b6d4c32477 /epan/tvbuff_real.c
parentc089afca5c353aec09a7bd7d918f58b21bcc9437 (diff)
downloadwireshark-0d85b75305677a1298b76718112c4e440f84b94c.tar.gz
Move tvb real and subset implementations to seperate files.
svn path=/trunk/; revision=50569
Diffstat (limited to 'epan/tvbuff_real.c')
-rw-r--r--epan/tvbuff_real.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/epan/tvbuff_real.c b/epan/tvbuff_real.c
new file mode 100644
index 0000000000..c1014eddbf
--- /dev/null
+++ b/epan/tvbuff_real.c
@@ -0,0 +1,120 @@
+/* tvbuff_real.c
+ *
+ * $Id$
+ *
+ * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include "tvbuff.h"
+#include "tvbuff-int.h"
+#include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
+
+struct tvb_real {
+ struct tvbuff tvb;
+
+ /** Func to call when actually freed */
+ tvbuff_free_cb_t free_cb;
+};
+
+static gsize
+real_sizeof(void)
+{
+ return sizeof(struct tvb_real);
+}
+
+static void
+real_free(tvbuff_t *tvb)
+{
+ struct tvb_real *real_tvb = (struct tvb_real *) tvb;
+
+ if (real_tvb->free_cb) {
+ /*
+ * XXX - do this with a union?
+ */
+ real_tvb->free_cb((gpointer)tvb->real_data);
+ }
+}
+
+static guint
+real_offset(const tvbuff_t *tvb _U_, const guint counter)
+{
+ return counter;
+}
+
+static const struct tvb_ops tvb_real_ops = {
+ real_sizeof, /* size */
+ real_free, /* free */
+ real_offset, /* offset */
+ NULL, /* get_ptr */
+ NULL, /* memcpy */
+ NULL, /* find_guint8 */
+ NULL, /* pbrk_guint8 */
+ NULL, /* clone */
+};
+
+tvbuff_t *
+tvb_new_real_data(const guint8* data, const guint length, const gint reported_length)
+{
+ tvbuff_t *tvb;
+ struct tvb_real *real_tvb;
+
+ THROW_ON(reported_length < -1, ReportedBoundsError);
+
+ tvb = tvb_new(&tvb_real_ops);
+
+ tvb->real_data = data;
+ tvb->length = length;
+ tvb->reported_length = reported_length;
+ tvb->initialized = TRUE;
+
+ /*
+ * This is the top-level real tvbuff for this data source,
+ * so its data source tvbuff is itself.
+ */
+ tvb->ds_tvb = tvb;
+
+ real_tvb = (struct tvb_real *) tvb;
+ real_tvb->free_cb = NULL;
+
+ return tvb;
+}
+
+void
+tvb_set_free_cb(tvbuff_t *tvb, const tvbuff_free_cb_t func)
+{
+ struct tvb_real *real_tvb = (struct tvb_real *) tvb;
+
+ DISSECTOR_ASSERT(tvb);
+ DISSECTOR_ASSERT(tvb->ops == &tvb_real_ops);
+ real_tvb->free_cb = func;
+}
+
+void
+tvb_set_child_real_data_tvbuff(tvbuff_t *parent, tvbuff_t *child)
+{
+ DISSECTOR_ASSERT(parent && child);
+ DISSECTOR_ASSERT(parent->initialized);
+ DISSECTOR_ASSERT(child->initialized);
+ DISSECTOR_ASSERT(child->ops == &tvb_real_ops);
+ tvb_add_to_chain(parent, child);
+}