Skip to content

Commit

Permalink
Make ndpi_finalize_initialization() returns an error code
Browse files Browse the repository at this point in the history
We should check if the initialization was fine or not
  • Loading branch information
IvanNardi committed Jan 9, 2024
1 parent 1a801c4 commit b9fca3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions example/ndpiReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ static void on_protocol_discovered(struct ndpi_workflow * workflow,
static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
NDPI_PROTOCOL_BITMASK enabled_bitmask;
struct ndpi_workflow_prefs prefs;
int i;
int i, ret;
ndpi_cfg_error rc;

memset(&prefs, 0, sizeof(prefs));
Expand Down Expand Up @@ -2917,8 +2917,11 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
cfgs[i].proto, cfgs[i].param, cfgs[i].value, rc);
}


ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct);
ret = ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct);
if(ret != 0) {
fprintf(stderr, "Error ndpi_finalize_initialization: %d\n", ret);
exit(-1);
}

if(enable_doh_dot_detection)
ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_pref_enable_tls_block_dissection, 1);
Expand Down
4 changes: 3 additions & 1 deletion src/include/ndpi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ extern "C" {
*
* @par ndpi_str = the struct created for the protocol detection
*
* @return 0 on success
*
*/
void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str);
int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str);

/**
* Frees the dynamic memory allocated members in the specified flow
Expand Down
10 changes: 5 additions & 5 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,13 +3510,13 @@ static void ndpi_add_domain_risk_exceptions(struct ndpi_detection_module_struct

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

void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) {
int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) {
u_int i;

if(!ndpi_str)
return;
return -1;
if(ndpi_str->finalized) /* Already finalized */
return;
return 0;

ndpi_add_domain_risk_exceptions(ndpi_str);

Expand Down Expand Up @@ -3585,7 +3585,7 @@ void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)
}
}

if(ndpi_str->ac_automa_finalized) return;
if(ndpi_str->ac_automa_finalized) return -1;

ndpi_automa * const automa[] = { &ndpi_str->host_automa,
&ndpi_str->tls_cert_subject_automa,
Expand All @@ -3603,7 +3603,7 @@ void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)

ndpi_str->finalized = 1;

return;
return 0;
}

/* *********************************************** */
Expand Down

0 comments on commit b9fca3e

Please sign in to comment.