aboutsummaryrefslogtreecommitdiff
path: root/example/reader_util.c
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2022-08-02 17:54:44 +0200
committerGitHub <noreply@github.com>2022-08-02 17:54:44 +0200
commitb3e722e5a8164900a0bfb510ebaafaf5080c4511 (patch)
tree4a2ba4485dce14e70f302638949912e0bc158c3b /example/reader_util.c
parent26aafd931c1a25a631a564ab8f468466344bc731 (diff)
Improved nDPI JSON serialization. (#1689)
* fixed autoconf CFLAGS/LDFLAGS MSAN issue which could lead to build errors * introduced portable version of gmtime_r aka ndpi_gmtime_r * do as most as possible of the serialization work in ndpi_utils.c * use flow2json in ndpiReader Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'example/reader_util.c')
-rw-r--r--example/reader_util.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/example/reader_util.c b/example/reader_util.c
index 48f522cbf..7ccaba1fc 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -434,13 +434,7 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
if(do_init_flows_root)
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
- if (serialization_format != ndpi_serialization_format_unknown &&
- ndpi_init_serializer(&workflow->ndpi_serializer,
- serialization_format) != 0)
- {
- LOG(NDPI_LOG_ERROR, "serializer initialization failed\n");
- exit(-1);
- }
+ workflow->ndpi_serialization_format = serialization_format;
return workflow;
}
@@ -532,6 +526,7 @@ static void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow) {
void ndpi_flow_info_free_data(struct ndpi_flow_info *flow) {
ndpi_free_flow_info_half(flow);
+ ndpi_term_serializer(&flow->ndpi_flow_serializer);
ndpi_free_flow_data_analysis(flow);
ndpi_free_flow_tls_data(flow);
@@ -550,8 +545,6 @@ void ndpi_flow_info_free_data(struct ndpi_flow_info *flow) {
void ndpi_workflow_free(struct ndpi_workflow * workflow) {
u_int i;
- ndpi_term_serializer(&workflow->ndpi_serializer);
-
for(i=0; i<workflow->prefs.num_roots; i++)
ndpi_tdestroy(workflow->ndpi_flows_root[i], ndpi_flow_info_freer);
@@ -1282,6 +1275,26 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
workflow->__flow_detected_callback(workflow, flow, workflow->__flow_detected_udata);
}
+ if (workflow->ndpi_serialization_format != ndpi_serialization_format_unknown)
+ {
+ if (ndpi_init_serializer(&flow->ndpi_flow_serializer,
+ workflow->ndpi_serialization_format) != 0)
+ {
+ LOG(NDPI_LOG_ERROR, "ndpi serializer init failed\n");
+ exit(-1);
+ }
+ if (ndpi_flow2json(workflow->ndpi_struct, flow->ndpi_flow,
+ flow->ip_version, flow->protocol,
+ flow->src_ip, flow->dst_ip,
+ &flow->src_ip6, &flow->dst_ip6,
+ flow->src_port, flow->dst_port,
+ flow->detected_protocol,
+ &flow->ndpi_flow_serializer) != 0)
+ {
+ LOG(NDPI_LOG_ERROR, "flow2json failed\n");
+ exit(-1);
+ }
+ }
ndpi_free_flow_info_half(flow);
}
}