Skip to content

Commit

Permalink
Fix db backend init for trace_id's
Browse files Browse the repository at this point in the history
Do not perform DB queries during cfg parsing, but only at mod_init stage, as some DB backends (like db_text) may not be initialized before mod_init.

Closes #1947

(cherry picked from commit b4fce7b)
  • Loading branch information
bogdan-iancu committed Jan 28, 2020
1 parent ae90fca commit 291d3e5
Showing 1 changed file with 55 additions and 34 deletions.
89 changes: 55 additions & 34 deletions modules/siptrace/siptrace.c
Expand Up @@ -294,24 +294,12 @@ get_db_struct(str *url, str *tb_name, st_db_struct_t **st_db)
}

if (!DB_CAPABILITY(dbs->funcs, DB_CAP_INSERT)) {
LM_ERR("database modules does not provide all functions needed by module\n");
return -1;
}

if ((dbs->con=dbs->funcs.init(url)) == 0) {
LM_CRIT("Cannot connect to DB\n");
return -1;
}

if (db_check_table_version(&dbs->funcs, dbs->con,
&dbs->table, SIPTRACE_TABLE_VERSION) < 0) {
LM_ERR("error during table version check.\n");
LM_ERR("database modules does not provide all functions "
"needed by module\n");
return -1;
}

dbs->url = *url;
dbs->funcs.close(dbs->con);
dbs->con = 0;

*st_db = dbs;

Expand Down Expand Up @@ -763,30 +751,63 @@ static int mod_init(void)

*trace_on_flag = trace_on;

/* initialize hep api */
/* initialize the trace IDs */
for (it=trace_list;it;it=it->next) {
if (it->type!=TYPE_HEP)
continue;

if (tprot.get_trace_dest_by_name == NULL) {
LM_DBG("Loading tracing protocol!\n");
/*
* if more tracing protocols shall implement the api then
* this should be a modparam
*/
if (trace_prot_bind(TRACE_PROTO, &tprot)) {
LM_ERR("Failed to bind tracing protocol!\n");
return -1;
}
}
switch (it->type) {

it->el.hep.hep_id = tprot.get_trace_dest_by_name(&it->el.hep.name);
if (it->el.hep.hep_id == NULL) {
LM_ERR("hep id not found!\n");
return -1;
}
LM_DBG("hep id {%.*s} loaded successfully!\n",
case TYPE_HEP:

if (tprot.get_trace_dest_by_name == NULL) {
LM_DBG("Loading tracing protocol!\n");
/*
* if more tracing protocols shall implement the api then
* this should be a modparam
*/
if (trace_prot_bind(TRACE_PROTO, &tprot)) {
LM_ERR("Failed to bind tracing protocol!\n");
return -1;
}
}

it->el.hep.hep_id = tprot.get_trace_dest_by_name
(&it->el.hep.name);
if (it->el.hep.hep_id == NULL) {
LM_ERR("hep id not found!\n");
return -1;
}
LM_DBG("hep id {%.*s} loaded successfully!\n",
it->el.hep.name.len, it->el.hep.name.s);

break;

case TYPE_DB:

if((it->el.db->con=it->el.db->funcs.init(&it->el.db->url))==0){
LM_CRIT("Cannot connect to DB <%.*s>\n",
it->el.db->url.len, it->el.db->url.s );
return -1;
}

if (db_check_table_version(&it->el.db->funcs, it->el.db->con,
&it->el.db->table, SIPTRACE_TABLE_VERSION) < 0) {
LM_ERR("failed to check table version for <%.*s>\n",
it->el.db->url.len, it->el.db->url.s );
return -1;
}
it->el.db->funcs.close(it->el.db->con);
it->el.db->con = 0;

break;

case TYPE_SIP:
case TYPE_END:

/* nothing to do here*/

break;
}

}

/* set db_keys/vals info */
Expand Down

0 comments on commit 291d3e5

Please sign in to comment.