Skip to content

Commit

Permalink
b2b_logic: properly restore b2b sessions from database
Browse files Browse the repository at this point in the history
When continuing a b2b session loaded from database, the dedicated
b2b_logic routes would no longer be run for the received request/replies.
Also, fix the detection of the current entity when using the
$b2b_logic.entity variable.
  • Loading branch information
rvlad-patrascu committed Dec 21, 2021
1 parent 9e2e817 commit 452d01d
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions modules/b2b_logic/b2b_logic.c
Expand Up @@ -354,6 +354,24 @@ static int mod_init(void)
if (server_address.s)
server_address.len = strlen(server_address.s);

if (script_req_route) {
global_req_rtid = get_script_route_ID_by_name(script_req_route,
sroutes->request, RT_NO);
if (global_req_rtid < 1) {
LM_ERR("route <%s> does not exist\n", script_req_route);
return -1;
}
}

if (script_reply_route) {
global_reply_rtid = get_script_route_ID_by_name(script_reply_route,
sroutes->request, RT_NO);
if (global_reply_rtid < 1) {
LM_ERR("route <%s> does not exist\n",script_reply_route);
return -1;
}
}

if(init_b2bl_htable() < 0)
{
LM_ERR("Failed to initialize b2b logic hash table\n");
Expand Down Expand Up @@ -567,24 +585,6 @@ static int mod_init(void)
return -1;
}

if (script_req_route) {
global_req_rtid = get_script_route_ID_by_name(script_req_route,
sroutes->request, RT_NO);
if (global_req_rtid < 1) {
LM_ERR("route <%s> does not exist\n", script_req_route);
return -1;
}
}

if (script_reply_route) {
global_reply_rtid = get_script_route_ID_by_name(script_reply_route,
sroutes->request, RT_NO);
if (global_reply_rtid < 1) {
LM_ERR("route <%s> does not exist\n",script_reply_route);
return -1;
}
}

return 0;
}

Expand Down Expand Up @@ -1667,22 +1667,35 @@ int pv_get_entity(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
}

if (param->pvi.type != PV_IDX_INT) {
/* no index provided, identify the current entity by callid */
if (get_callid(msg, &callid) < 0) {
LM_ERR("Failed to get callid from SIP message\n");
goto ret_null;
}
if (cur_route_ctx.flags & (B2BL_RT_REQ_CTX|B2BL_RT_RPL_CTX)) {
/* identify the current entity by entity key */
entity = curr_entities[0];
if (entity && str_strcmp(&entity->key, &cur_route_ctx.entity_key))
entity = NULL;

entity = curr_entities[0];
if (entity &&
(!entity->dlginfo || str_strcmp(&entity->dlginfo->callid, &callid)))
entity = NULL;
if (!entity) {
entity = curr_entities[1];
if (entity && str_strcmp(&entity->key, &cur_route_ctx.entity_key))
entity = NULL;
}
} else {
/* identify the current entity by callid */
if (get_callid(msg, &callid) < 0) {
LM_ERR("Failed to get callid from SIP message\n");
goto ret_null;
}

if (!entity) {
entity = curr_entities[1];
if (entity && (!entity->dlginfo ||
str_strcmp(&entity->dlginfo->callid, &callid)))
entity = curr_entities[0];
if (entity &&
(!entity->dlginfo || str_strcmp(&entity->dlginfo->callid, &callid)))
entity = NULL;

if (!entity) {
entity = curr_entities[1];
if (entity && (!entity->dlginfo ||
str_strcmp(&entity->dlginfo->callid, &callid)))
entity = NULL;
}
}

if (!entity) {
Expand Down

0 comments on commit 452d01d

Please sign in to comment.