aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Cardigliano <cardigliano@ntop.org>2024-10-31 17:36:44 +0100
committerAlfredo Cardigliano <cardigliano@ntop.org>2024-10-31 17:36:44 +0100
commit8ad34b381ca5d352dc4f877f93bc0f7625d8b28c (patch)
treef4ffa751adedd52d40996866644c0f3ffb3644ea
parenta97a130e59d635c5acfccf6049499d201dc90ba3 (diff)
Add new json serialization type ndpi_serialization_format_inner_json
-rw-r--r--src/include/ndpi_typedefs.h4
-rw-r--r--src/lib/ndpi_serializer.c12
2 files changed, 12 insertions, 4 deletions
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index d2931ece5..b09c6bc21 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -1653,7 +1653,8 @@ typedef enum {
ndpi_serialization_format_tlv,
ndpi_serialization_format_json,
ndpi_serialization_format_csv,
- ndpi_serialization_format_multiline_json
+ ndpi_serialization_format_multiline_json, /* new-line separated records */
+ ndpi_serialization_format_inner_json /* no outer braces */
} ndpi_serialization_format;
/* Note:
@@ -1719,6 +1720,7 @@ typedef struct {
char csv_separator[2];
u_int8_t has_snapshot;
u_int8_t multiline_json_array;
+ u_int8_t inner_json;
ndpi_private_serializer_status snapshot;
} ndpi_private_serializer;
diff --git a/src/lib/ndpi_serializer.c b/src/lib/ndpi_serializer.c
index 63877cd69..ec8bfad51 100644
--- a/src/lib/ndpi_serializer.c
+++ b/src/lib/ndpi_serializer.c
@@ -196,6 +196,9 @@ int ndpi_init_serializer_ll(ndpi_serializer *_serializer,
if (fmt == ndpi_serialization_format_multiline_json) {
fmt = ndpi_serialization_format_json;
serializer->multiline_json_array = 1;
+ } else if (fmt == ndpi_serialization_format_inner_json) {
+ fmt = ndpi_serialization_format_json;
+ serializer->inner_json = 1;
}
serializer->fmt = fmt;
@@ -719,7 +722,8 @@ static inline void ndpi_serialize_json_pre(ndpi_serializer *_serializer) {
serializer->status.buffer.size_used--; /* Remove ']' */
serializer->buffer.data[serializer->status.buffer.size_used++] = ',';
}
- serializer->buffer.data[serializer->status.buffer.size_used++] = '{';
+ if (!serializer->inner_json)
+ serializer->buffer.data[serializer->status.buffer.size_used++] = '{';
} else {
if(!serializer->multiline_json_array) {
@@ -727,7 +731,8 @@ static inline void ndpi_serialize_json_pre(ndpi_serializer *_serializer) {
serializer->status.buffer.size_used--; /* Remove ']' */
}
- serializer->status.buffer.size_used--; /* Remove '}' */
+ if (!serializer->inner_json)
+ serializer->status.buffer.size_used--; /* Remove '}' */
if(serializer->status.flags & NDPI_SERIALIZER_STATUS_LIST) {
if(!serializer->multiline_json_array)
@@ -760,7 +765,8 @@ static inline int ndpi_serialize_json_post(ndpi_serializer *_serializer) {
if(serializer->status.buffer.size_used >= serializer->buffer.size)
return -1;
- serializer->buffer.data[serializer->status.buffer.size_used++] = '}';
+ if (!serializer->inner_json)
+ serializer->buffer.data[serializer->status.buffer.size_used++] = '}';
if (!serializer->multiline_json_array) {
if(serializer->status.flags & NDPI_SERIALIZER_STATUS_ARRAY) {