ndpi_load_categories_file() now returns the number of loaded hosts or -1 in case of error

This commit is contained in:
Luca Deri
2020-01-20 23:37:09 +01:00
parent 283588a37b
commit 931f51bd77
+8 -4
View File
@@ -2846,7 +2846,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_str,
int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str, const char* path) { int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str, const char* path) {
char buffer[512], *line, *name, *category, *saveptr; char buffer[512], *line, *name, *category, *saveptr;
FILE *fd; FILE *fd;
int len; int len, num = 0;
fd = fopen(path, "r"); fd = fopen(path, "r");
@@ -2872,15 +2872,19 @@ int ndpi_load_categories_file(struct ndpi_detection_module_struct *ndpi_str, con
if(name) { if(name) {
category = strtok_r(NULL, "\t", &saveptr); category = strtok_r(NULL, "\t", &saveptr);
if(category) if(category) {
ndpi_load_category(ndpi_str, name, (ndpi_protocol_category_t) atoi(category)); int rc = ndpi_load_category(ndpi_str, name, (ndpi_protocol_category_t) atoi(category));
if(rc >= 0)
num++;
}
} }
} }
fclose(fd); fclose(fd);
ndpi_enable_loaded_categories(ndpi_str); ndpi_enable_loaded_categories(ndpi_str);
return(0); return(num);
} }
/* ******************************************************************** */ /* ******************************************************************** */