/src/ndpi/src/lib/protocols/hl7.c
Line | Count | Source |
1 | | /* |
2 | | * hl7.c |
3 | | * |
4 | | * Health Level Seven (HL7) |
5 | | * |
6 | | * Copyright (C) 2023 - ntop.org |
7 | | * Copyright (C) 2023 - V.G <v.gavrilov@securitycode.ru> |
8 | | * |
9 | | * This file is part of nDPI, an open source deep packet inspection |
10 | | * library based on the OpenDPI and PACE technology by ipoque GmbH |
11 | | * |
12 | | * nDPI is free software: you can redistribute it and/or modify |
13 | | * it under the terms of the GNU Lesser General Public License as published by |
14 | | * the Free Software Foundation, either version 3 of the License, or |
15 | | * (at your option) any later version. |
16 | | * |
17 | | * nDPI is distributed in the hope that it will be useful, |
18 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | | * GNU Lesser General Public License for more details. |
21 | | * |
22 | | * You should have received a copy of the GNU Lesser General Public License |
23 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
24 | | * |
25 | | */ |
26 | | |
27 | | #include "ndpi_protocol_ids.h" |
28 | | |
29 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HL7 |
30 | | |
31 | | #include "ndpi_api.h" |
32 | | #include "ndpi_private.h" |
33 | | |
34 | | static void ndpi_search_hl7(struct ndpi_detection_module_struct *ndpi_struct, |
35 | | struct ndpi_flow_struct *flow) |
36 | 4.69M | { |
37 | 4.69M | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
38 | | |
39 | 4.69M | NDPI_LOG_DBG(ndpi_struct, "search HL7\n"); |
40 | | |
41 | 4.69M | if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP || |
42 | 3.91M | flow->detected_protocol_stack[1] == NDPI_PROTOCOL_HTTP) |
43 | 852k | { |
44 | 852k | if (packet->content_line.ptr != NULL) { |
45 | 96.4k | if ((LINE_ENDS(packet->content_line, "x-application/hl7-v2+er7") != 0) || |
46 | 96.1k | (LINE_ENDS(packet->content_line, "x-application/hl7-v2+xml") != 0) || |
47 | 95.8k | (LINE_ENDS(packet->content_line, "x-application/hl7-v3+xml") != 0) || |
48 | 95.5k | (LINE_ENDS(packet->content_line, "x-application/fhir+xml") != 0) || |
49 | 95.2k | (LINE_ENDS(packet->content_line, "x-application/fhir+json") != 0) || |
50 | 94.6k | (LINE_ENDS(packet->content_line, "x-application/xml+cda") != 0)) |
51 | 2.18k | { |
52 | 2.18k | NDPI_LOG_INFO(ndpi_struct, "found HL7 over HTTP\n"); |
53 | 2.18k | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HL7, NDPI_PROTOCOL_HTTP, |
54 | 2.18k | NDPI_CONFIDENCE_DPI); |
55 | 2.18k | } |
56 | 96.4k | } |
57 | 852k | return; |
58 | 852k | } |
59 | | |
60 | 3.84M | if (packet->payload_packet_len > 100 && |
61 | 1.18M | memcmp(&packet->payload[1], "MSH|^~\\&|", NDPI_STATICSTRING_LEN("MSH|^~\\&|")) == 0) |
62 | 184 | { |
63 | 184 | NDPI_LOG_INFO(ndpi_struct, "found HL7\n"); |
64 | 184 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HL7, NDPI_PROTOCOL_UNKNOWN, |
65 | 184 | NDPI_CONFIDENCE_DPI); |
66 | 184 | return; |
67 | 184 | } |
68 | | |
69 | 3.84M | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
70 | 3.84M | } |
71 | | |
72 | | void init_hl7_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
73 | 15.7k | { |
74 | 15.7k | ndpi_register_dissector("HL7", ndpi_struct, |
75 | 15.7k | ndpi_search_hl7, |
76 | 15.7k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
77 | 15.7k | 1, NDPI_PROTOCOL_HL7); |
78 | 15.7k | } |