Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed logging callback function sig. #2000

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/reader_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
workflow->prefs = *prefs;
workflow->ndpi_struct = module;

ndpi_set_user_data(module, workflow);

ndpi_set_log_level(module, nDPI_LogLevel);

if(_debug_protocols != NULL && ! _debug_protocols_ok) {
Expand Down
19 changes: 19 additions & 0 deletions src/include/ndpi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,25 @@ extern "C" {
char *out, u_int out_len,
u_int8_t use_json);

/* ******************************* */

/**
* Set user data which can later retrieved with `ndpi_get_user_data()`.
*
* @par ndpi_str = the struct created for the protocol detection
* @par user_data = user data pointer you want to retrieve later with `ndpi_get_user_data()`
*
*/
void ndpi_set_user_data(struct ndpi_detection_module_struct *ndpi_str, void *user_data);

/**
* Get user data which was previously set with `ndpi_set_user_data()`.
*
* @return the user data pointer
*
*/
void *ndpi_get_user_data(struct ndpi_detection_module_struct *ndpi_str);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@ typedef struct ndpi_protocol_bitmask_struct {
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
} ndpi_protocol_bitmask_struct_t;

struct ndpi_detection_module_struct;

/* NDPI_DEBUG_FUNCTION_PTR (cast) */
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, void *module_struct,
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, struct ndpi_detection_module_struct *module_struct,
ndpi_log_level_t log_level, const char *file,
const char *func, unsigned line,
const char *format, ...);
Expand Down Expand Up @@ -1158,9 +1160,7 @@ struct ndpi_detection_module_struct {
u_int8_t skip_tls_blocks_until_change_cipher:1, enable_ja3_plus:1, _notused:6;
u_int8_t tls_certificate_expire_in_x_days;

#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void *user_data;
#endif
char custom_category_labels[NUM_CUSTOM_CATEGORIES][CUSTOM_CATEGORY_LABEL_LEN];

/* callback function buffer */
Expand Down
19 changes: 17 additions & 2 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2860,9 +2860,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
ndpi_str->max_packets_to_process = NDPI_DEFAULT_MAX_NUM_PKTS_PER_FLOW_TO_DISSECT;

NDPI_BITMASK_SET_ALL(ndpi_str->detection_bitmask);
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
ndpi_str->user_data = NULL;
#endif

ndpi_str->tcp_max_retransmission_window_size = NDPI_DEFAULT_MAX_TCP_RETRANSMISSION_WINDOW_SIZE;
ndpi_str->tls_certificate_expire_in_x_days = 30; /* NDPI_TLS_CERTIFICATE_ABOUT_TO_EXPIRE flow risk */
Expand Down Expand Up @@ -9790,3 +9788,20 @@ u_int32_t ndpi_get_protocol_aggressiveness(struct ndpi_detection_module_struct *
return -1;
}
}

/* ******************************************************************** */

void ndpi_set_user_data(struct ndpi_detection_module_struct *ndpi_str, void *user_data)
{
if (ndpi_str->user_data != NULL)
{
NDPI_LOG_ERR(ndpi_str, "%s", "User data is already set. Overwriting.")
}

ndpi_str->user_data = user_data;
}

void *ndpi_get_user_data(struct ndpi_detection_module_struct *ndpi_str)
{
return ndpi_str->user_data;
}