| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
wscbor.h
Go to the documentation of this file.
1
15#ifndef __WSCBOR_H__
16#define __WSCBOR_H__
17
18#include <ws_symbol_export.h>
19#include <epan/tvbuff.h>
20#include <epan/proto.h>
21#include <epan/expert.h>
22#include <wsutil/wmem/wmem_list.h>
23
24#ifdef __cplusplus
25 extern "C" {
26#endif
27
30WS_DLL_PUBLIC
31 void wscbor_init(void);
32
37WS_DLL_PUBLIC
38 const ei_register_info * wscbor_expert_items(int *size);
39
41 typedef enum cbor_type {
42 CBOR_TYPE_UINT = 0,
43 CBOR_TYPE_NEGINT = 1,
44 CBOR_TYPE_BYTESTRING = 2,
45 CBOR_TYPE_STRING = 3,
46 CBOR_TYPE_ARRAY = 4,
47 CBOR_TYPE_MAP = 5,
48 CBOR_TYPE_TAG = 6,
49 CBOR_TYPE_FLOAT_CTRL = 7,
50} cbor_type;
51
53 typedef enum {
54 CBOR_CTRL_NONE = 0,
55 CBOR_CTRL_FALSE = 20,
56 CBOR_CTRL_TRUE = 21,
57 CBOR_CTRL_NULL = 22,
58 CBOR_CTRL_UNDEF = 23
59} _cbor_ctrl;
60
62 typedef struct {
64 expert_field *ei;
66 const char *msg;
67} wscbor_error_t;
68
76WS_DLL_PUBLIC
77 wscbor_error_t * wscbor_error_new(wmem_allocator_t *alloc, expert_field *ei, const char *format, ...) G_GNUC_PRINTF(3,4);
78
80typedef struct {
82 int start;
84 int length;
86 uint64_t value;
87} wscbor_tag_t;
88
89 struct _wscbor_chunk_priv_t;
90 typedef struct _wscbor_chunk_priv_t wscbor_chunk_priv_t;
92 typedef struct {
94 wscbor_chunk_priv_t *_priv;
95
97 int start;
99 int head_length;
101 int data_length;
103 wmem_list_t *errors;
105 wmem_list_t *tags;
106
109 cbor_type type_major;
111 uint8_t type_minor;
113 uint64_t head_value;
114} wscbor_chunk_t;
115
129WS_DLL_PUBLIC
130 wscbor_chunk_t * wscbor_chunk_read(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset);
131
134WS_DLL_PUBLIC
135 void wscbor_chunk_free(wscbor_chunk_t *chunk);
136
143WS_DLL_PUBLIC
144uint64_t wscbor_chunk_mark_errors(packet_info *pinfo, proto_item *item, const wscbor_chunk_t *chunk);
145
150WS_DLL_PUBLIC
151 unsigned wscbor_has_errors(const wscbor_chunk_t *chunk);
152
158WS_DLL_PUBLIC
159 bool wscbor_is_indefinite_break(const wscbor_chunk_t *chunk);
160
171WS_DLL_PUBLIC
172 bool wscbor_skip_next_item(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset);
173
184WS_DLL_PUBLIC
185 bool wscbor_skip_if_errors(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset, const wscbor_chunk_t *chunk);
186
187
194WS_DLL_PUBLIC
195 bool wscbor_require_major_type(wscbor_chunk_t *chunk, cbor_type major);
196
202WS_DLL_PUBLIC
203 bool wscbor_require_array(wscbor_chunk_t *chunk);
204
212WS_DLL_PUBLIC
213 bool wscbor_require_array_size(wscbor_chunk_t *chunk, uint64_t count_min, uint64_t count_max);
214
220WS_DLL_PUBLIC
221 bool wscbor_require_map(wscbor_chunk_t *chunk);
222
230WS_DLL_PUBLIC
231 bool * wscbor_require_boolean(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
232
241WS_DLL_PUBLIC
242uint64_t * wscbor_require_uint64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
243
252WS_DLL_PUBLIC
253int64_t * wscbor_require_int64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
254
267WS_DLL_PUBLIC
268 char * wscbor_require_tstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
269
278WS_DLL_PUBLIC
279 tvbuff_t * wscbor_require_bstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk);
280
285WS_DLL_PUBLIC
286 proto_item * proto_tree_add_cbor_container(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
287
290WS_DLL_PUBLIC
291 proto_item * proto_tree_add_cbor_ctrl(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
292
293WS_DLL_PUBLIC
294 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);
295
296WS_DLL_PUBLIC
297 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);
298
299WS_DLL_PUBLIC
300 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);
301
302WS_DLL_PUBLIC
303 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);
304
305WS_DLL_PUBLIC
306 proto_item * proto_tree_add_cbor_tstr(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
307
308WS_DLL_PUBLIC
309 proto_item * proto_tree_add_cbor_bstr(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
310
313WS_DLL_PUBLIC
314 proto_item * proto_tree_add_cbor_strlen(proto_tree *tree, int hfindex, packet_info *pinfo, tvbuff_t *tvb, const wscbor_chunk_t *chunk);
315
316#ifdef __cplusplus
317}
318#endif
319
320#endif /* __WSCBOR_H__ */
expert.h
proto.h
_packet_info
Definition packet_info.h:43
_proto_node
Definition proto.h:905
_wmem_allocator_t
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
_wmem_list_t
Definition wmem_list.c:23
_wscbor_chunk_priv_t
Definition wscbor.c:143
ei_register_info
Definition expert.h:68
expert_field
Definition expert.h:39
tvbuff
Definition tvbuff-int.h:36
wscbor_chunk_t
A data-containing, optionally-tagged chunk of CBOR.
Definition wscbor.h:92
wscbor_chunk_t::data_length
int data_length
The length of this chunk and its immediate definite data (i.e. strings)
Definition wscbor.h:101
wscbor_chunk_t::type_minor
uint8_t type_minor
Minor type of this item.
Definition wscbor.h:111
wscbor_chunk_t::tags
wmem_list_t * tags
Tags on this chunk, in encoded order (type wscbor_tag_t*)
Definition wscbor.h:105
wscbor_chunk_t::head_value
uint64_t head_value
The header-encoded value.
Definition wscbor.h:113
wscbor_chunk_t::type_major
cbor_type type_major
Definition wscbor.h:109
wscbor_chunk_t::start
int start
The start offset of this chunk.
Definition wscbor.h:97
wscbor_chunk_t::head_length
int head_length
The length of just this header and any preceding tags.
Definition wscbor.h:99
wscbor_chunk_t::errors
wmem_list_t * errors
Errors processing this chunk (type wscbor_error_t*)
Definition wscbor.h:103
wscbor_chunk_t::_priv
wscbor_chunk_priv_t * _priv
Internal private data.
Definition wscbor.h:94
wscbor_error_t
Decoding or require_* error.
Definition wscbor.h:62
wscbor_error_t::ei
expert_field * ei
The associated expert info.
Definition wscbor.h:64
wscbor_error_t::msg
const char * msg
Optional specific text.
Definition wscbor.h:66
wscbor_tag_t
Tag metadata and value.
Definition wscbor.h:80
wscbor_tag_t::value
uint64_t value
The tag value.
Definition wscbor.h:86
wscbor_tag_t::start
int start
The start offset of this tag head.
Definition wscbor.h:82
wscbor_tag_t::length
int length
The length of just this tag head.
Definition wscbor.h:84
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:549
wscbor_require_tstr
WS_DLL_PUBLIC char * wscbor_require_tstr(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:596
wscbor_expert_items
WS_DLL_PUBLIC const ei_register_info * wscbor_expert_items(int *size)
Definition wscbor.c:483
wscbor_require_map
WS_DLL_PUBLIC bool wscbor_require_map(wscbor_chunk_t *chunk)
Definition wscbor.c:521
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:41
CBOR_TYPE_MAP
@ CBOR_TYPE_MAP
maps
Definition wscbor.h:47
CBOR_TYPE_FLOAT_CTRL
@ CBOR_TYPE_FLOAT_CTRL
decimals and special values (true, false, nil, ...)
Definition wscbor.h:49
CBOR_TYPE_TAG
@ CBOR_TYPE_TAG
tags
Definition wscbor.h:48
CBOR_TYPE_UINT
@ CBOR_TYPE_UINT
positive integers
Definition wscbor.h:42
CBOR_TYPE_BYTESTRING
@ CBOR_TYPE_BYTESTRING
byte strings
Definition wscbor.h:44
CBOR_TYPE_STRING
@ CBOR_TYPE_STRING
text strings
Definition wscbor.h:45
CBOR_TYPE_NEGINT
@ CBOR_TYPE_NEGINT
negative integers
Definition wscbor.h:43
CBOR_TYPE_ARRAY
@ CBOR_TYPE_ARRAY
arrays
Definition wscbor.h:46
wscbor_require_major_type
WS_DLL_PUBLIC bool wscbor_require_major_type(wscbor_chunk_t *chunk, cbor_type major)
Definition wscbor.c:490
wscbor_is_indefinite_break
WS_DLL_PUBLIC bool wscbor_is_indefinite_break(const wscbor_chunk_t *chunk)
Definition wscbor.c:366
wscbor_require_boolean
WS_DLL_PUBLIC bool * wscbor_require_boolean(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:525
wscbor_skip_next_item
WS_DLL_PUBLIC bool wscbor_skip_next_item(wmem_allocator_t *alloc, tvbuff_t *tvb, int *offset)
Definition wscbor.c:458
wscbor_require_int64
WS_DLL_PUBLIC int64_t * wscbor_require_int64(wmem_allocator_t *alloc, wscbor_chunk_t *chunk)
Definition wscbor.c:559
_cbor_ctrl
_cbor_ctrl
The same enumeration from libcbor-0.5.
Definition wscbor.h:53
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:506
wscbor_require_array
WS_DLL_PUBLIC bool wscbor_require_array(wscbor_chunk_t *chunk)
Definition wscbor.c:502
wscbor_has_errors
WS_DLL_PUBLIC unsigned wscbor_has_errors(const wscbor_chunk_t *chunk)
Definition wscbor.c:362
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)
Definition wscbor.c:628
wscbor_init
WS_DLL_PUBLIC void wscbor_init(void)
Definition wscbor.c:472
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:462
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)
Definition wscbor.c:354
wscbor_chunk_free
WS_DLL_PUBLIC void wscbor_chunk_free(wscbor_chunk_t *chunk)
Definition wscbor.c:323
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)
Definition wscbor.c:612
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)
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