| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
wscbor.h
Go to the documentation of this file.
1
14#pragma once
15#include <ws_symbol_export.h>
16#include <epan/tvbuff.h>
17#include <epan/proto.h>
18#include <epan/expert.h>
19#include <wsutil/wmem/wmem_list.h>
20
21#ifdef __cplusplus
22 extern "C" {
23#endif
24
27WS_DLL_PUBLIC
28 void wscbor_init(void);
29
34WS_DLL_PUBLIC
35 const ei_register_info * wscbor_expert_items(int *size);
36
38 typedef enum cbor_type {
39 CBOR_TYPE_UINT = 0,
40 CBOR_TYPE_NEGINT = 1,
41 CBOR_TYPE_BYTESTRING = 2,
42 CBOR_TYPE_STRING = 3,
43 CBOR_TYPE_ARRAY = 4,
44 CBOR_TYPE_MAP = 5,
45 CBOR_TYPE_TAG = 6,
46 CBOR_TYPE_FLOAT_CTRL = 7,
47} cbor_type;
48
52 typedef enum {
53 CBOR_CTRL_NONE = 0,
54 CBOR_CTRL_FALSE = 20,
55 CBOR_CTRL_TRUE = 21,
56 CBOR_CTRL_NULL = 22,
57 CBOR_CTRL_UNDEF = 23
58} _cbor_ctrl;
59
61 typedef struct {
63 expert_field *ei;
65 const char *msg;
66} wscbor_error_t;
67
75WS_DLL_PUBLIC
76 wscbor_error_t * wscbor_error_new(wmem_allocator_t *alloc, expert_field *ei, const char *format, ...) G_GNUC_PRINTF(3,4);
77
79typedef struct {
81 int start;
83 int length;
85 uint64_t value;
86} wscbor_tag_t;
87
88 struct _wscbor_chunk_priv_t;
89 typedef struct _wscbor_chunk_priv_t wscbor_chunk_priv_t;
91 typedef struct {
93 wscbor_chunk_priv_t *_priv;
94
96 int start;
98 int head_length;
100 int data_length;
102 wmem_list_t *errors;
104 wmem_list_t *tags;
105
108 cbor_type type_major;
110 uint8_t type_minor;
112 uint64_t head_value;
113} wscbor_chunk_t;
114
128WS_DLL_PUBLIC
129 wscbor_chunk_t * wscbor_chunk_read(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset);
130
135WS_DLL_PUBLIC
136 void wscbor_chunk_free(wscbor_chunk_t *chunk);
137
145WS_DLL_PUBLIC
146uint64_t wscbor_chunk_mark_errors(packet_info *pinfo, proto_item *item, const wscbor_chunk_t *chunk);
147
153WS_DLL_PUBLIC
154 unsigned wscbor_has_errors(const wscbor_chunk_t *chunk);
155
161WS_DLL_PUBLIC
162 bool wscbor_is_indefinite_break(const wscbor_chunk_t *chunk);
163
175WS_DLL_PUBLIC
176 bool wscbor_skip_next_item(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset);
177
188WS_DLL_PUBLIC
189 bool wscbor_skip_if_errors(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset, const wscbor_chunk_t *chunk);
190
191
198WS_DLL_PUBLIC
199 bool wscbor_require_major_type(wscbor_chunk_t *chunk, cbor_type major);
200
206WS_DLL_PUBLIC
207 bool wscbor_require_array(wscbor_chunk_t *chunk);
208
216WS_DLL_PUBLIC
217 bool wscbor_require_array_size(wscbor_chunk_t *chunk, uint64_t count_min, uint64_t count_max);
218
224WS_DLL_PUBLIC
225 bool wscbor_require_map(wscbor_chunk_t *chunk);
226
234WS_DLL_PUBLIC
235 bool * wscbor_require_boolean(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
236
245WS_DLL_PUBLIC
246uint64_t * wscbor_require_uint64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
247
256WS_DLL_PUBLIC
257int64_t * wscbor_require_int64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
258
271WS_DLL_PUBLIC
272 char * wscbor_require_tstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
273
282WS_DLL_PUBLIC
283tvbuff_t * wscbor_require_bstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
284
298WS_DLL_PUBLIC
299 proto_item * proto_tree_add_cbor_container(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
300
310WS_DLL_PUBLIC
311 proto_item * proto_tree_add_cbor_ctrl(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
312
324WS_DLL_PUBLIC
325 proto_item * proto_tree_add_cbor_boolean(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const bool *value);
326
338WS_DLL_PUBLIC
339 proto_item * proto_tree_add_cbor_uint64(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const uint64_t *value);
340
352WS_DLL_PUBLIC
353 proto_item * proto_tree_add_cbor_int64(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const int64_t *value);
354
368WS_DLL_PUBLIC
369 proto_item * proto_tree_add_cbor_bitmask(proto_tree *tree, int hfindex, const int ett, int *const *fields, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const uint64_t *value);
370
381WS_DLL_PUBLIC
382 proto_item * proto_tree_add_cbor_tstr(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
383
394WS_DLL_PUBLIC
395 proto_item * proto_tree_add_cbor_bstr(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
396
406WS_DLL_PUBLIC
407 proto_item * proto_tree_add_cbor_strlen(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
408
409#ifdef __cplusplus
410}
411#endif
expert.h
packet_info
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
proto_item
proto_node proto_item
Definition proto.h:927
wmem_list_t
struct _wmem_list_t wmem_list_t
Opaque type representing a scoped, doubly-linked list in the wmem system.
Definition wmem_list.h:42
wmem_allocator_t
struct _wmem_allocator_t wmem_allocator_t
Definition wmem_core.h:44
proto.h
_wscbor_chunk_priv_t
Definition wscbor.c:143
ei_register_info
Bundles an expert_field handle with its expert_field_info for use in bulk registration.
Definition expert.h:77
expert_field
Pairs an expert info index with its associated header field index for registration and display.
Definition expert.h:41
wscbor_chunk_t
A data-containing, optionally-tagged chunk of CBOR.
Definition wscbor.h:91
wscbor_chunk_t::data_length
int data_length
The length of this chunk and its immediate definite data (i.e. strings).
Definition wscbor.h:100
wscbor_chunk_t::type_minor
uint8_t type_minor
Minor type of this item.
Definition wscbor.h:110
wscbor_chunk_t::tags
wmem_list_t * tags
Tags on this chunk, in encoded order (type wscbor_tag_t*).
Definition wscbor.h:104
wscbor_chunk_t::head_value
uint64_t head_value
The header-encoded value.
Definition wscbor.h:112
wscbor_chunk_t::type_major
cbor_type type_major
Definition wscbor.h:108
wscbor_chunk_t::start
int start
The start offset of this chunk.
Definition wscbor.h:96
wscbor_chunk_t::head_length
int head_length
The length of just this header and any preceding tags.
Definition wscbor.h:98
wscbor_chunk_t::errors
wmem_list_t * errors
Errors processing this chunk (type wscbor_error_t*).
Definition wscbor.h:102
wscbor_chunk_t::_priv
wscbor_chunk_priv_t * _priv
Internal private data.
Definition wscbor.h:93
wscbor_error_t
Decoding or require_* error.
Definition wscbor.h:61
wscbor_error_t::ei
expert_field * ei
The associated expert info.
Definition wscbor.h:63
wscbor_error_t::msg
const char * msg
Optional specific text.
Definition wscbor.h:65
wscbor_tag_t
Tag metadata and value.
Definition wscbor.h:79
wscbor_tag_t::value
uint64_t value
The tag value.
Definition wscbor.h:85
wscbor_tag_t::start
int start
The start offset of this tag head.
Definition wscbor.h:81
wscbor_tag_t::length
int length
The length of just this tag head.
Definition wscbor.h:83
tvbuff.h
wmem_list.h
wscbor_require_uint64
WS_DLL_PUBLIC uint64_t * wscbor_require_uint64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:552
wscbor_require_tstr
WS_DLL_PUBLIC char * wscbor_require_tstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:599
proto_tree_add_cbor_bitmask
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_bitmask(proto_tree *tree, int hfindex, const int ett, int *const *fields, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const uint64_t *value)
Add an item representing a bitmask value.
Definition wscbor.c:655
proto_tree_add_cbor_boolean
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_boolean(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const bool *value)
Adds a CBOR boolean item to the protocol tree.
Definition wscbor.c:637
wscbor_expert_items
WS_DLL_PUBLIC const ei_register_info * wscbor_expert_items(int *size)
Definition wscbor.c:486
wscbor_require_map
WS_DLL_PUBLIC bool wscbor_require_map(wscbor_chunk_t *chunk)
Definition wscbor.c:524
proto_tree_add_cbor_int64
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_int64(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const int64_t *value)
Adds a CBOR integer item to the protocol tree.
Definition wscbor.c:649
wscbor_chunk_read
WS_DLL_PUBLIC wscbor_chunk_t * wscbor_chunk_read(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset)
Definition wscbor.c:197
cbor_type
cbor_type
The same enumeration from libcbor-0.5.
Definition wscbor.h:38
CBOR_TYPE_FLOAT_CTRL
@ CBOR_TYPE_FLOAT_CTRL
decimals and special values (true, false, nil, ...)
Definition wscbor.h:46
CBOR_TYPE_TAG
@ CBOR_TYPE_TAG
tags
Definition wscbor.h:45
CBOR_TYPE_UINT
@ CBOR_TYPE_UINT
positive integers
Definition wscbor.h:39
CBOR_TYPE_BYTESTRING
@ CBOR_TYPE_BYTESTRING
byte strings
Definition wscbor.h:41
CBOR_TYPE_STRING
@ CBOR_TYPE_STRING
text strings
Definition wscbor.h:42
CBOR_TYPE_NEGINT
@ CBOR_TYPE_NEGINT
negative integers
Definition wscbor.h:40
wscbor_require_major_type
WS_DLL_PUBLIC bool wscbor_require_major_type(wscbor_chunk_t *chunk, cbor_type major)
Definition wscbor.c:493
proto_tree_add_cbor_uint64
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_uint64(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk, const uint64_t *value)
Adds a CBOR unsigned integer item to the protocol tree.
Definition wscbor.c:643
wscbor_is_indefinite_break
WS_DLL_PUBLIC bool wscbor_is_indefinite_break(const wscbor_chunk_t *chunk)
Determine if an indefinite break is present.
Definition wscbor.c:369
wscbor_require_boolean
WS_DLL_PUBLIC bool * wscbor_require_boolean(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:528
wscbor_skip_next_item
WS_DLL_PUBLIC bool wscbor_skip_next_item(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset)
Recursively skip items from a stream.
Definition wscbor.c:461
wscbor_require_int64
WS_DLL_PUBLIC int64_t * wscbor_require_int64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:562
_cbor_ctrl
_cbor_ctrl
CBOR simple (control) values, mirroring the cbor_ctrl enumeration from libcbor 0.5.
Definition wscbor.h:52
CBOR_CTRL_UNDEF
@ CBOR_CTRL_UNDEF
Definition wscbor.h:57
CBOR_CTRL_NULL
@ CBOR_CTRL_NULL
Definition wscbor.h:56
CBOR_CTRL_FALSE
@ CBOR_CTRL_FALSE
Definition wscbor.h:54
CBOR_CTRL_NONE
@ CBOR_CTRL_NONE
Definition wscbor.h:53
CBOR_CTRL_TRUE
@ CBOR_CTRL_TRUE
Definition wscbor.h:55
wscbor_require_array_size
WS_DLL_PUBLIC bool wscbor_require_array_size(wscbor_chunk_t *chunk, uint64_t count_min, uint64_t count_max)
Definition wscbor.c:509
wscbor_require_array
WS_DLL_PUBLIC bool wscbor_require_array(wscbor_chunk_t *chunk)
Definition wscbor.c:505
wscbor_has_errors
WS_DLL_PUBLIC unsigned wscbor_has_errors(const wscbor_chunk_t *chunk)
Determine if a chunk has errors.
Definition wscbor.c:365
proto_tree_add_cbor_ctrl
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_ctrl(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk)
Add an item representing a non-boolean, non-float control value.
Definition wscbor.c:631
wscbor_init
WS_DLL_PUBLIC void wscbor_init(void)
Definition wscbor.c:475
wscbor_skip_if_errors
WS_DLL_PUBLIC bool wscbor_skip_if_errors(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset, const wscbor_chunk_t *chunk)
Definition wscbor.c:465
proto_tree_add_cbor_tstr
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_tstr(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk)
Add an item representing a CBOR text string (tstr) value.
Definition wscbor.c:675
wscbor_require_bstr
WS_DLL_PUBLIC tvbuff_t * wscbor_require_bstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
wscbor_chunk_mark_errors
WS_DLL_PUBLIC uint64_t wscbor_chunk_mark_errors(packet_info *pinfo, proto_item *item, const wscbor_chunk_t *chunk)
After both reading and decoding a chunk, report on any errors found.
Definition wscbor.c:357
proto_tree_add_cbor_bstr
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_bstr(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk)
Add an item representing a CBOR byte string value.
Definition wscbor.c:688
wscbor_chunk_free
WS_DLL_PUBLIC void wscbor_chunk_free(wscbor_chunk_t *chunk)
Free a chunk and its lists.
Definition wscbor.c:326
proto_tree_add_cbor_container
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_container(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk)
Add an item representing an array or map container.
Definition wscbor.c:615
proto_tree_add_cbor_strlen
WS_DLL_PUBLIC proto_item * proto_tree_add_cbor_strlen(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk)
Add an item representing the length of a bstr or tstr value.
wscbor_error_new
WS_DLL_PUBLIC wscbor_error_t * wscbor_error_new(wmem_allocator_t *alloc, expert_field *ei, const char *format,...)
Definition wscbor.c:181