Simplified nDPI initialization function
This commit is contained in:
+3
-11
@@ -115,22 +115,14 @@ extern "C" {
|
||||
*
|
||||
*/
|
||||
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol_match *match);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new initialized detection module
|
||||
*
|
||||
* @par ticks_per_second = the timestamp resolution per second (like 1000 for millisecond resolution)
|
||||
* @par __ndpi_malloc = function pointer to a nDPI memory allocator
|
||||
* @par ndpi_debug_printf = function pointer to a nDPI debug output function (use NULL in productive envionments)
|
||||
* @return the initialized detection module
|
||||
*
|
||||
*/
|
||||
struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_per_second,
|
||||
void* (*__ndpi_malloc)(size_t size),
|
||||
void (*__ndpi_free)(void *ptr),
|
||||
ndpi_debug_function_ptr ndpi_debug_printf);
|
||||
|
||||
struct ndpi_detection_module_struct *ndpi_init_detection_module();
|
||||
|
||||
/**
|
||||
* Frees the memory allocated in the specified flow
|
||||
@@ -595,10 +587,10 @@ extern "C" {
|
||||
int ndpi_match_string(void *_automa, char *string_to_match);
|
||||
|
||||
|
||||
|
||||
/* Utility functions to set ndpi malloc/free wrappers */
|
||||
/* Utility functions to set ndpi malloc/free/print wrappers */
|
||||
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
|
||||
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
|
||||
void set_ndpi_debug_function(ndpi_debug_function_ptr ndpi_debug_printf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+26
-27
@@ -308,7 +308,7 @@ static int removeDefaultPort(ndpi_port_range *range,
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
void* ndpi_malloc(size_t size) { return(_ndpi_malloc(size)); }
|
||||
void* ndpi_malloc(size_t size) { return(_ndpi_malloc ? _ndpi_malloc(size) : malloc(size)); }
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
@@ -324,7 +324,7 @@ void* ndpi_calloc(unsigned long count, size_t size) {
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
void ndpi_free(void *ptr) { _ndpi_free(ptr); }
|
||||
void ndpi_free(void *ptr) { if(_ndpi_free) _ndpi_free(ptr); else free(ptr); }
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
@@ -1682,24 +1682,24 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
||||
#endif
|
||||
|
||||
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size)) { _ndpi_malloc = __ndpi_malloc; }
|
||||
|
||||
void set_ndpi_free(void (*__ndpi_free)(void *ptr)) { _ndpi_free = __ndpi_free; }
|
||||
|
||||
void set_ndpi_debug_function(ndpi_debug_function_ptr ndpi_debug_printf) {
|
||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
ndpi_str->ndpi_debug_printf = ndpi_debug_printf;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ******************************************************************** */
|
||||
|
||||
struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_per_second,
|
||||
void* (*__ndpi_malloc)(size_t size),
|
||||
void (*__ndpi_free)(void *ptr),
|
||||
ndpi_debug_function_ptr ndpi_debug_printf)
|
||||
{
|
||||
struct ndpi_detection_module_struct *ndpi_str;
|
||||
|
||||
/* TODO global malloc wrappers should not be set here: ndpi_init_detection_module can be called many times */
|
||||
set_ndpi_malloc(__ndpi_malloc), set_ndpi_free(__ndpi_free);
|
||||
|
||||
ndpi_str = ndpi_malloc(sizeof(struct ndpi_detection_module_struct));
|
||||
struct ndpi_detection_module_struct *ndpi_init_detection_module() {
|
||||
struct ndpi_detection_module_struct *ndpi_str = ndpi_malloc(sizeof(struct ndpi_detection_module_struct));
|
||||
|
||||
if(ndpi_str == NULL) {
|
||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
ndpi_debug_printf(0, NULL, NDPI_LOG_DEBUG, "ndpi_init_detection_module initial malloc failed\n");
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
memset(ndpi_str, 0, sizeof(struct ndpi_detection_module_struct));
|
||||
@@ -1709,30 +1709,29 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_
|
||||
|
||||
NDPI_BITMASK_RESET(ndpi_str->detection_bitmask);
|
||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
ndpi_str->ndpi_debug_printf = ndpi_debug_printf;
|
||||
ndpi_str->user_data = NULL;
|
||||
#endif
|
||||
|
||||
ndpi_str->ticks_per_second = ticks_per_second;
|
||||
ndpi_str->ticks_per_second = 1000; /* ndpi_str->ticks_per_second */
|
||||
ndpi_str->tcp_max_retransmission_window_size = NDPI_DEFAULT_MAX_TCP_RETRANSMISSION_WINDOW_SIZE;
|
||||
ndpi_str->directconnect_connection_ip_tick_timeout =
|
||||
NDPI_DIRECTCONNECT_CONNECTION_IP_TICK_TIMEOUT * ticks_per_second;
|
||||
NDPI_DIRECTCONNECT_CONNECTION_IP_TICK_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
|
||||
ndpi_str->rtsp_connection_timeout = NDPI_RTSP_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->tvants_connection_timeout = NDPI_TVANTS_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->irc_timeout = NDPI_IRC_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->gnutella_timeout = NDPI_GNUTELLA_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->rtsp_connection_timeout = NDPI_RTSP_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->tvants_connection_timeout = NDPI_TVANTS_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->irc_timeout = NDPI_IRC_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->gnutella_timeout = NDPI_GNUTELLA_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
|
||||
ndpi_str->battlefield_timeout = NDPI_BATTLEFIELD_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->battlefield_timeout = NDPI_BATTLEFIELD_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
|
||||
ndpi_str->thunder_timeout = NDPI_THUNDER_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->thunder_timeout = NDPI_THUNDER_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->yahoo_detect_http_connections = NDPI_YAHOO_DETECT_HTTP_CONNECTIONS;
|
||||
|
||||
ndpi_str->yahoo_lan_video_timeout = NDPI_YAHOO_LAN_VIDEO_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->zattoo_connection_timeout = NDPI_ZATTOO_CONNECTION_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->jabber_stun_timeout = NDPI_JABBER_STUN_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->jabber_file_transfer_timeout = NDPI_JABBER_FT_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->soulseek_connection_ip_tick_timeout = NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT * ticks_per_second;
|
||||
ndpi_str->yahoo_lan_video_timeout = NDPI_YAHOO_LAN_VIDEO_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->zattoo_connection_timeout = NDPI_ZATTOO_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->jabber_stun_timeout = NDPI_JABBER_STUN_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->jabber_file_transfer_timeout = NDPI_JABBER_FT_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
ndpi_str->soulseek_connection_ip_tick_timeout = NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT * ndpi_str->ticks_per_second;
|
||||
|
||||
ndpi_str->ndpi_num_supported_protocols = NDPI_MAX_SUPPORTED_PROTOCOLS;
|
||||
ndpi_str->ndpi_num_custom_protocols = 0;
|
||||
|
||||
Reference in New Issue
Block a user