| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
json-dictionary.h
1/* json-dictionary.h
2 * JSON dictionary parsing for JSON protocol dissector
3 * Copyright 2026, Mark Stout <mark.stout@markstout.com>
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12#ifndef __JSON_DICTIONARY_H__
13#define __JSON_DICTIONARY_H__
14
15#include <glib.h>
16#include <libxml/parser.h>
17#include <epan/wmem_scopes.h>
18#include <epan/packet.h>
19#include <wsutil/value_string.h>
20#include <wsutil/wsjson.h>
21
22// Field type enumeration
23 typedef enum {
24 JSON_FIELD_STRING,
25 JSON_FIELD_INTEGER,
26 JSON_FIELD_UNSIGNED,
27 JSON_FIELD_FLOAT,
28 JSON_FIELD_BOOLEAN,
29 JSON_FIELD_OBJECT,
30 JSON_FIELD_ARRAY,
31 JSON_FIELD_NULL
32} json_field_type_t;
33
34// Display type enumeration for special formatting
35 typedef enum {
36 JSON_DISPLAY_NONE,
37 JSON_DISPLAY_IPV4,
38 JSON_DISPLAY_IPV6,
39 JSON_DISPLAY_ETHER,
40 JSON_DISPLAY_ABSOLUTE_TIME,
41 JSON_DISPLAY_RELATIVE_TIME,
42 JSON_DISPLAY_HEX2DEC
43} json_display_type_t;
44
45 typedef struct _json_field_t json_field_t;
46
47/* Field definition structure */
48 struct _json_field_t {
49 char *name; /* Display name */
50 char *path; /* JSON path (e.g., "user.profile.age") */
51 unsigned path_hash; /* Hash for O(1) lookup */
52 json_field_type_t type; /* Field type */
53 json_display_type_t display_type; /* Special display formatting */
54 int hf_value; /* Wireshark header field index */
55 int *ett; /* Pointer to subtree index (for objects/arrays) */
56 value_string *enum_values; /* For enumerated fields */
57 wmem_tree_t *child_fields; /* Child fields (for objects/arrays) */
58 void *type_data; /* Type-specific data */
59 char *info_label; /* Custom label for Info column (NULL = don't show) */
60 char *parser; /* External parser script path (relative to parsers/ dir) */
61 char *parser_args; /* Additional arguments for parser */
62 wmem_tree_t *parser_child_hf; /* Dynamic header fields from parser (filter → hf_index) */
63 bool case_insensitive; /* Enable case-insensitive path matching */
64};
65
66// Dictionary structure
67 typedef struct _json_dictionary_t {
68 wmem_tree_t *fields; // Field definitions (path hash → json_field_t)
69 wmem_tree_t *protocols; // Protocol definitions (port → json_protocol_t)
70 value_string_ext *types; // Type name → type enum mapping
71 bool has_case_insensitive_fields; // Optimization flag: true if any field is case-insensitive
72} json_dictionary_t;
73
74/* Protocol definition */
75 typedef struct _json_protocol_t {
76 char *name; // Protocol nam
77 char *display_name; // Custom display name for Protocol column
78 unsigned port; // Default port
79 char *transport; // tcp or udp
80 char **content_types; // Array of content-type strings
81} json_protocol_t;
82
83/* Dictionary XML element names */
84#define XML_ELEMENT_DICTIONARY "json-dictionary"
85#define XML_ELEMENT_BASE "base"
86#define XML_ELEMENT_TYPEDEFN "typedefn"
87#define XML_ELEMENT_PROTOCOL "protocol"
88#define XML_ELEMENT_FIELD "field"
89#define XML_ELEMENT_ARRAY_ELEMENT "array-element"
90#define XML_ELEMENT_ENUM "enum"
91#define XML_ELEMENT_CONTENT_TYPE "content-type"
92
93/* XML attribute names */
94#define XML_ATTR_NAME "name"
95#define XML_ATTR_VERSION "version"
96#define XML_ATTR_TYPE_NAME "type-name"
97#define XML_ATTR_BASE_TYPE "base-type"
98#define XML_ATTR_DISPLAY "display"
99#define XML_ATTR_DISPLAY_NAME "displayName"
100#define XML_ATTR_PORT "port"
101#define XML_ATTR_TRANSPORT "transport"
102#define XML_ATTR_PATH "path"
103#define XML_ATTR_TYPE "type"
104#define XML_ATTR_DESCRIPTION "description"
105#define XML_ATTR_VALUE "value"
106#define XML_ATTR_CODE "code"
107#define XML_ATTR_INFO "info"
108#define XML_ATTR_DF "df"
109#define XML_ATTR_PARSER "parser"
110#define XML_ATTR_PARSER_ARGS "parser-args"
111#define XML_ATTR_CASE "case"
112
113// Temporary structures for XML parsing
114 typedef struct _dict_type_def {
115 xmlChar *type_name;
116 xmlChar *base_type;
117 xmlChar *display;
118} dict_type_def_t;
119
120 typedef struct _dict_enum_def {
121 xmlChar *value;
122 unsigned code;
123 xmlChar *description;
124} dict_enum_def_t;
125
126 typedef struct _dict_field_def {
127 xmlChar *name;
128 xmlChar *path;
129 xmlChar *type;
130 xmlChar *description;
131 GSList *child_fields; // List of dict_field_def_t
132 GSList *enum_values; // List of dict_enum_def_t
133 bool is_array_element;
134 xmlChar *info_label; // Custom label for Info column (NULL = don't show)
135 xmlChar *display_filter; // Custom display filter name (NULL = use path-based name)
136 xmlChar *parser; // External parser script path
137 xmlChar *parser_args; // Additional arguments for parser
138 xmlChar *case_attr; // "sensitive" or "insensitive" - case sensitivity for path matching
139} dict_field_def_t;
140
141 typedef struct _dict_protocol_def {
142 xmlChar *name;
143 xmlChar *display_name; // Custom display name for Protocol column
144 GSList *ports; // List of unsigned port numbers - supports comma-separated ports
145 xmlChar *transport;
146 GSList *content_types; // List of xmlChar*
147 GSList *fields; // List of dict_field_def_t
148} dict_protocol_def_t;
149
150/* Load dictionary from XML files
151 * Returns true if successful, false otherwise
152 */
153 bool load_json_dictionary(wmem_array_t *hf_array, GPtrArray *ett_array,
154 json_dictionary_t *dict);
155
156// Cleanup functions for temporary structures
157 void dict_type_def_free(dict_type_def_t *type_def);
158 void dict_enum_def_free(dict_enum_def_t *enum_def);
159 void dict_field_def_free(dict_field_def_t *field_def);
160 void dict_protocol_def_free(dict_protocol_def_t *proto_def);
161
162#endif /* __JSON_DICTIONARY_H__ */
163
164/*
165 * Editor modelines - https://www.wireshark.org/tools/modelines.html
166 *
167 * Local variables:
168 * c-basic-offset: 8
169 * tab-width: 8
170 * indent-tabs-mode: t
171 * End:
172 *
173 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
174 * :indentSize=8:tabSize=8:noTabs=false:
175 */
packet.h
_dict_enum_def
Definition json-dictionary.h:120
_dict_field_def
Definition json-dictionary.h:126
_dict_protocol_def
Definition json-dictionary.h:141
_dict_type_def
Definition json-dictionary.h:114
_json_dictionary_t
Definition json-dictionary.h:67
_json_field_t
Definition json-dictionary.h:48
_json_protocol_t
Definition json-dictionary.h:75
_value_string_ext
Extended metadata for a value_string array.
Definition value_string.h:325
_value_string
Mapping between a 32-bit integer value and its string representation.
Definition value_string.h:33
_wmem_array_t
Definition wmem_array.c:29
_wmem_tree_t
Internal representation of a wmem balanced tree.
Definition wmem_tree-int.h:81
value_string.h
wmem_scopes.h
wsjson.h