aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2021-10-11 11:45:45 +0200
committerLuca Deri <deri@ntop.org>2021-10-11 11:45:45 +0200
commit246d115d7bf126c284df739c35cd9b790bf140cf (patch)
treebae84ecf322e62ce1aaee5fa4ce467528421acfc /src/lib
parent60eca79fdf552aa98e6a3505f7b690a5b9c3c87c (diff)
Cleaned up code moving specific includes in files their are using it. Thi prevents ndpi_config.h to be included everywhere in apps using nDPI that might leade to #define redefinitions after the latest changes
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ndpi_geoip.c29
-rw-r--r--src/lib/ndpi_utils.c9
2 files changed, 28 insertions, 10 deletions
diff --git a/src/lib/ndpi_geoip.c b/src/lib/ndpi_geoip.c
index 23fb0b752..c3308b48b 100644
--- a/src/lib/ndpi_geoip.c
+++ b/src/lib/ndpi_geoip.c
@@ -21,10 +21,6 @@
*
*/
-#ifdef HAVE_CONFIG_H
-#include "ndpi_config.h"
-#endif
-
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
@@ -33,6 +29,10 @@
#include "ndpi_api.h"
#include "ndpi_config.h"
+#ifdef HAVE_MAXMINDDB
+#include <maxminddb.h>
+#endif
+
/* ********************************************************************************* */
int ndpi_load_geoip(struct ndpi_detection_module_struct *ndpi_str,
@@ -40,13 +40,19 @@ int ndpi_load_geoip(struct ndpi_detection_module_struct *ndpi_str,
#ifdef HAVE_MAXMINDDB
int status;
+ ndpi_str->mmdb_city = (void*)ndpi_malloc(sizeof(MMDB_s));
+ ndpi_str->mmdb_as = (void*)ndpi_malloc(sizeof(MMDB_s));
+
+ if((ndpi_str->mmdb_city == NULL) || (ndpi_str->mmdb_as == NULL))
+ return(-1);
+
/* Open the MMDB files */
- if((status = MMDB_open(ip_city_data, MMDB_MODE_MMAP, &ndpi_str->mmdb_city)) != MMDB_SUCCESS)
+ if((status = MMDB_open(ip_city_data, MMDB_MODE_MMAP, (MMDB_s*)ndpi_str->mmdb_city)) != MMDB_SUCCESS)
return(-1);
else
ndpi_str->mmdb_city_loaded = 1;
- if((status = MMDB_open(ip_as_data, MMDB_MODE_MMAP, &ndpi_str->mmdb_as)) != MMDB_SUCCESS)
+ if((status = MMDB_open(ip_as_data, MMDB_MODE_MMAP, (MMDB_s*)ndpi_str->mmdb_as)) != MMDB_SUCCESS)
return(-2);
else
ndpi_str->mmdb_as_loaded = 1;
@@ -61,8 +67,11 @@ int ndpi_load_geoip(struct ndpi_detection_module_struct *ndpi_str,
void ndpi_free_geoip(struct ndpi_detection_module_struct *ndpi_str) {
#ifdef HAVE_MAXMINDDB
- if(ndpi_str->mmdb_city_loaded) MMDB_close(&ndpi_str->mmdb_city);
- if(ndpi_str->mmdb_as_loaded) MMDB_close(&ndpi_str->mmdb_as);
+ if(ndpi_str->mmdb_city_loaded) MMDB_close((MMDB_s*)ndpi_str->mmdb_city);
+ if(ndpi_str->mmdb_as_loaded) MMDB_close((MMDB_s*)ndpi_str->mmdb_as);
+
+ ndpi_free(ndpi_str->mmdb_city);
+ ndpi_free(ndpi_str->mmdb_as);
#endif
}
@@ -75,7 +84,7 @@ int ndpi_get_geoip_asn(struct ndpi_detection_module_struct *ndpi_str, char *ip,
MMDB_entry_data_s entry_data;
if(ndpi_str->mmdb_as_loaded) {
- result = MMDB_lookup_string(&ndpi_str->mmdb_as, ip, &gai_error, &mmdb_error);
+ result = MMDB_lookup_string((MMDB_s*)ndpi_str->mmdb_as, ip, &gai_error, &mmdb_error);
if((gai_error != 0)
|| (mmdb_error != MMDB_SUCCESS)
@@ -112,7 +121,7 @@ int ndpi_get_geoip_country_continent(struct ndpi_detection_module_struct *ndpi_s
if(ndpi_str->mmdb_city_loaded) {
int status;
- result = MMDB_lookup_string(&ndpi_str->mmdb_city, ip, &gai_error, &mmdb_error);
+ result = MMDB_lookup_string((MMDB_s*)ndpi_str->mmdb_city, ip, &gai_error, &mmdb_error);
if((gai_error != 0)
|| (mmdb_error != MMDB_SUCCESS)
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index 9839d8863..18e9f424a 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -59,6 +59,15 @@
// #define DEBUG_REASSEMBLY
+#ifdef HAVE_PCRE
+#include <pcre.h>
+
+struct pcre_struct {
+ pcre *compiled;
+ pcre_extra *optimized;
+};
+#endif
+
/* ****************************************** */
/* implementation of the punycode check function */