summaryrefslogtreecommitdiffstats
path: root/epan/tvbuff_composite.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:53 +0000
commita86c5f7cae7ec9a3398300555a0b644689d946a1 (patch)
tree39fe4b107c71174fd1e8a8ceb9a4d2aa14116248 /epan/tvbuff_composite.c
parentReleasing progress-linux version 4.2.6-1~progress7.99u1. (diff)
downloadwireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.tar.xz
wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.zip
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/tvbuff_composite.c')
-rw-r--r--epan/tvbuff_composite.c89
1 files changed, 43 insertions, 46 deletions
diff --git a/epan/tvbuff_composite.c b/epan/tvbuff_composite.c
index 620b8d27..e483d6ba 100644
--- a/epan/tvbuff_composite.c
+++ b/epan/tvbuff_composite.c
@@ -16,13 +16,13 @@
#include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
typedef struct {
- GSList *tvbs;
+ GQueue *tvbs;
/* Used for quick testing to see if this
* is the tvbuff that a COMPOSITE is
* interested in. */
- guint *start_offsets;
- guint *end_offsets;
+ unsigned *start_offsets;
+ unsigned *end_offsets;
} tvb_comp_t;
@@ -38,40 +38,39 @@ composite_free(tvbuff_t *tvb)
struct tvb_composite *composite_tvb = (struct tvb_composite *) tvb;
tvb_comp_t *composite = &composite_tvb->composite;
- g_slist_free(composite->tvbs);
+ g_queue_free(composite->tvbs);
g_free(composite->start_offsets);
g_free(composite->end_offsets);
- g_free((gpointer)tvb->real_data);
+ g_free((void *)tvb->real_data);
}
-static guint
-composite_offset(const tvbuff_t *tvb _U_, const guint counter)
+static unsigned
+composite_offset(const tvbuff_t *tvb _U_, const unsigned counter)
{
return counter;
}
-static const guint8*
-composite_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length)
+static const uint8_t*
+composite_get_ptr(tvbuff_t *tvb, unsigned abs_offset, unsigned abs_length)
{
struct tvb_composite *composite_tvb = (struct tvb_composite *) tvb;
- guint i, num_members;
+ unsigned i;
tvb_comp_t *composite;
tvbuff_t *member_tvb = NULL;
- guint member_offset;
- GSList *slist;
+ unsigned member_offset;
/* DISSECTOR_ASSERT(tvb->ops == &tvb_composite_ops); */
/* Maybe the range specified by offset/length
* is contiguous inside one of the member tvbuffs */
composite = &composite_tvb->composite;
- num_members = g_slist_length(composite->tvbs);
+ GList *item = (GList*)composite->tvbs->head;
- for (i = 0; i < num_members; i++) {
+
+ for (i = 0; i < g_queue_get_length(composite->tvbs); i++, item=item->next) {
if (abs_offset <= composite->end_offsets[i]) {
- slist = g_slist_nth(composite->tvbs, i);
- member_tvb = (tvbuff_t *)slist->data;
+ member_tvb = (tvbuff_t *)item->data;
break;
}
}
@@ -95,7 +94,7 @@ composite_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length)
/* Use a temporary variable as tvb_memcpy is also checking tvb->real_data pointer */
void *real_data = g_malloc(tvb->length);
tvb_memcpy(tvb, real_data, 0, tvb->length);
- tvb->real_data = (const guint8 *)real_data;
+ tvb->real_data = (const uint8_t *)real_data;
return tvb->real_data + abs_offset;
}
@@ -103,28 +102,26 @@ composite_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length)
}
static void *
-composite_memcpy(tvbuff_t *tvb, void* _target, guint abs_offset, guint abs_length)
+composite_memcpy(tvbuff_t *tvb, void* _target, unsigned abs_offset, unsigned abs_length)
{
struct tvb_composite *composite_tvb = (struct tvb_composite *) tvb;
- guint8 *target = (guint8 *) _target;
+ uint8_t *target = (uint8_t *) _target;
- guint i, num_members;
+ unsigned i;
tvb_comp_t *composite;
tvbuff_t *member_tvb = NULL;
- guint member_offset, member_length;
- GSList *slist;
+ unsigned member_offset, member_length;
/* DISSECTOR_ASSERT(tvb->ops == &tvb_composite_ops); */
/* Maybe the range specified by offset/length
* is contiguous inside one of the member tvbuffs */
composite = &composite_tvb->composite;
- num_members = g_slist_length(composite->tvbs);
- for (i = 0; i < num_members; i++) {
+ GList *item = (GList*)composite->tvbs->head;
+ for (i = 0; i < g_queue_get_length(composite->tvbs); i++, item=item->next) {
if (abs_offset <= composite->end_offsets[i]) {
- slist = g_slist_nth(composite->tvbs, i);
- member_tvb = (tvbuff_t *)slist->data;
+ member_tvb = (tvbuff_t *)item->data;
break;
}
}
@@ -174,8 +171,8 @@ static const struct tvb_ops tvb_composite_ops = {
composite_offset, /* offset */
composite_get_ptr, /* get_ptr */
composite_memcpy, /* memcpy */
- NULL, /* find_guint8 XXX */
- NULL, /* pbrk_guint8 XXX */
+ NULL, /* find_uint8 XXX */
+ NULL, /* pbrk_uint8 XXX */
NULL, /* clone */
};
@@ -198,7 +195,7 @@ tvb_new_composite(void)
struct tvb_composite *composite_tvb = (struct tvb_composite *) tvb;
tvb_comp_t *composite = &composite_tvb->composite;
- composite->tvbs = NULL;
+ composite->tvbs = g_queue_new();
composite->start_offsets = NULL;
composite->end_offsets = NULL;
@@ -219,11 +216,11 @@ tvb_composite_append(tvbuff_t *tvb, tvbuff_t *member)
*/
if (member && member->length) {
composite = &composite_tvb->composite;
- composite->tvbs = g_slist_append(composite->tvbs, member);
+ g_queue_push_tail(composite->tvbs, member);
/* Attach the composite TVB to the first TVB only. */
- if (!composite->tvbs->next) {
- tvb_add_to_chain((tvbuff_t *)composite->tvbs->data, tvb);
+ if (g_queue_get_length(composite->tvbs) == 1) {
+ tvb_add_to_chain((tvbuff_t *)g_queue_peek_head(composite->tvbs), tvb);
}
}
}
@@ -242,11 +239,11 @@ tvb_composite_prepend(tvbuff_t *tvb, tvbuff_t *member)
*/
if (member && member->length) {
composite = &composite_tvb->composite;
- composite->tvbs = g_slist_prepend(composite->tvbs, member);
+ g_queue_push_head(composite->tvbs, member);
/* Attach the composite TVB to the first TVB only. */
- if (!composite->tvbs->next) {
- tvb_add_to_chain((tvbuff_t *)composite->tvbs->data, tvb);
+ if (g_queue_get_length(composite->tvbs) == 1) {
+ tvb_add_to_chain((tvbuff_t *)g_queue_peek_head(composite->tvbs), tvb);
}
}
}
@@ -255,11 +252,11 @@ void
tvb_composite_finalize(tvbuff_t *tvb)
{
struct tvb_composite *composite_tvb = (struct tvb_composite *) tvb;
- GSList *slist;
- guint num_members;
+
+ unsigned num_members;
tvbuff_t *member_tvb;
tvb_comp_t *composite;
- int i = 0;
+ unsigned i;
DISSECTOR_ASSERT(tvb && !tvb->initialized);
DISSECTOR_ASSERT(tvb->ops == &tvb_composite_ops);
@@ -268,7 +265,8 @@ tvb_composite_finalize(tvbuff_t *tvb)
DISSECTOR_ASSERT(tvb->contained_length == 0);
composite = &composite_tvb->composite;
- num_members = g_slist_length(composite->tvbs);
+
+ num_members = g_queue_get_length(composite->tvbs);
/* Dissectors should not create composite TVBs if they're not going to
* put at least one TVB in them.
@@ -276,21 +274,20 @@ tvb_composite_finalize(tvbuff_t *tvb)
*/
DISSECTOR_ASSERT(num_members);
- composite->start_offsets = g_new(guint, num_members);
- composite->end_offsets = g_new(guint, num_members);
+ composite->start_offsets = g_new(unsigned, num_members);
+ composite->end_offsets = g_new(unsigned, num_members);
- for (slist = composite->tvbs; slist != NULL; slist = slist->next) {
- DISSECTOR_ASSERT((guint) i < num_members);
- member_tvb = (tvbuff_t *)slist->data;
+ GList *item = (GList*)composite->tvbs->head;
+ for (i=0; i < num_members; i++, item=item->next) {
+ member_tvb = (tvbuff_t *)item->data;
composite->start_offsets[i] = tvb->length;
tvb->length += member_tvb->length;
tvb->reported_length += member_tvb->reported_length;
tvb->contained_length += member_tvb->contained_length;
composite->end_offsets[i] = tvb->length - 1;
- i++;
}
- tvb->initialized = TRUE;
+ tvb->initialized = true;
tvb->ds_tvb = tvb;
}