aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_main.h1
-rw-r--r--src/lib/ndpi_main.c19
-rw-r--r--src/lib/protocols/http.c13
-rw-r--r--src/lib/protocols/ssdp.c10
-rw-r--r--src/lib/protocols/xiaomi.c7
5 files changed, 31 insertions, 19 deletions
diff --git a/src/include/ndpi_main.h b/src/include/ndpi_main.h
index 790fa4c33..ab9170fbf 100644
--- a/src/include/ndpi_main.h
+++ b/src/include/ndpi_main.h
@@ -161,6 +161,7 @@ extern "C" {
const char *alpn_to_check, u_int alpn_to_check_len);
char *ndpi_hostname_sni_set(struct ndpi_flow_struct *flow, const u_int8_t *value, size_t value_len);
+ char *ndpi_user_agent_set(struct ndpi_flow_struct *flow, const u_int8_t *value, size_t value_len);
#ifdef __cplusplus
}
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 5a6376c6f..a9e34f30b 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -8421,3 +8421,22 @@ char *ndpi_hostname_sni_set(struct ndpi_flow_struct *flow, const u_int8_t *value
return dst;
}
+
+/* ******************************************************************** */
+
+char *ndpi_user_agent_set(struct ndpi_flow_struct *flow, const u_int8_t *value, size_t value_len)
+{
+ if (flow->http.user_agent != NULL)
+ {
+ return NULL;
+ }
+
+ flow->http.user_agent = ndpi_malloc(value_len + 1);
+ if (flow->http.user_agent != NULL)
+ {
+ memcpy(flow->http.user_agent, value, value_len);
+ flow->http.user_agent[value_len] = '\0';
+ }
+
+ return flow->http.user_agent;
+}
diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c
index 8b65ece50..8ecadb303 100644
--- a/src/lib/protocols/http.c
+++ b/src/lib/protocols/http.c
@@ -535,14 +535,11 @@ int http_process_user_agent(struct ndpi_detection_module_struct *ndpi_struct,
}
}
- if(flow->http.user_agent == NULL) {
- flow->http.user_agent = ndpi_malloc(ua_ptr_len + 1);
- if(flow->http.user_agent) {
- memcpy(flow->http.user_agent, (char*)ua_ptr, ua_ptr_len);
- flow->http.user_agent[ua_ptr_len] = '\0';
-
- ndpi_check_user_agent(ndpi_struct, flow, flow->http.user_agent);
- }
+ if (ndpi_user_agent_set(flow, ua_ptr, ua_ptr_len) != NULL)
+ {
+ ndpi_check_user_agent(ndpi_struct, flow, flow->http.user_agent);
+ } else {
+ NDPI_LOG_DBG2(ndpi_struct, "Could not set HTTP user agent\n");
}
NDPI_LOG_DBG2(ndpi_struct, "User Agent Type line found %.*s\n",
diff --git a/src/lib/protocols/ssdp.c b/src/lib/protocols/ssdp.c
index cc2eb2f71..9fb1d0eae 100644
--- a/src/lib/protocols/ssdp.c
+++ b/src/lib/protocols/ssdp.c
@@ -38,13 +38,9 @@ static void ssdp_parse_lines(struct ndpi_detection_module_struct
/* Save user-agent for device discovery if available */
if(packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) {
- if(flow->http.user_agent == NULL) {
- flow->http.user_agent = ndpi_malloc(packet->user_agent_line.len + 1);
- if(flow->http.user_agent) {
- memcpy(flow->http.user_agent,
- (char*)packet->user_agent_line.ptr, packet->user_agent_line.len);
- flow->http.user_agent[packet->user_agent_line.len] = '\0';
- }
+ if (ndpi_user_agent_set(flow, packet->user_agent_line.ptr, packet->user_agent_line.len) == NULL)
+ {
+ NDPI_LOG_DBG2(ndpi_struct, "Could not set SSDP user agent\n");
}
}
}
diff --git a/src/lib/protocols/xiaomi.c b/src/lib/protocols/xiaomi.c
index 831478e9e..f18c6202b 100644
--- a/src/lib/protocols/xiaomi.c
+++ b/src/lib/protocols/xiaomi.c
@@ -52,10 +52,9 @@ static void xiaomi_dissect_metadata(struct ndpi_detection_module_struct *ndpi_st
switch(op) {
case 0x12:
- flow->http.user_agent = ndpi_malloc(len + 1);
- if(flow->http.user_agent != NULL) {
- memcpy(flow->http.user_agent, &payload[offset], len);
- flow->http.user_agent[len] = '\0';
+ if (ndpi_user_agent_set(flow, &payload[offset], len) == NULL)
+ {
+ NDPI_LOG_DBG2(ndpi_struct, "Could not set Xiaomi user agent\n");
}
break;