Skip to content

Commit

Permalink
Fix rollback of transfer in case of using of separate media server url
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Altmann authored and nikbyte committed Oct 24, 2022
1 parent 9f14bb0 commit fdf50bb
Showing 1 changed file with 73 additions and 12 deletions.
85 changes: 73 additions & 12 deletions modules/b2b_logic/logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ str *b2b_scenario_hdrs(struct b2bl_new_entity *entity);
int post_cb_sanity_check(b2bl_tuple_t **tuple, unsigned int hash_index, unsigned int local_index,
b2bl_entity_id_t **entity, int etype, str *ekey);
int udh_to_uri(str user, str host, str port, str* uri);

static b2bl_entity_id_t* b2bl_new_client(str* to_uri, str *proxy, str* from_uri,
b2bl_tuple_t* tuple, str* ssid, str* hdrs, str *adv_ct, struct sip_msg* msg);

static str method_invite= {INVITE, INVITE_LEN};
static str method_ack = {ACK, ACK_LEN};
static str method_bye = {BYE, BYE_LEN};
Expand Down Expand Up @@ -490,6 +494,8 @@ void b2b_mark_todel( b2bl_tuple_t* tuple)
int process_bridge_dialog_end(b2bl_tuple_t* tuple, unsigned int hash_index,
int entity_no, b2bl_entity_id_t* bentity)
{
b2bl_entity_id_t* entity;

if(entity_no == 0) /* if a negative reply received from the server */
{
/* send cancel or bye to the peers */
Expand All @@ -498,20 +504,33 @@ int process_bridge_dialog_end(b2bl_tuple_t* tuple, unsigned int hash_index,
b2b_mark_todel(tuple);
}
else
if(entity_no == 1)
if(entity_no == 1) /* if a negative reply received from client or media server */
{
/* if the media server in 2 stage connecting did not reply */
if(tuple->bridge_entities[2])
{
/* media server did not reply with success */
b2bl_delete_entity(bentity, tuple, hash_index, 1);

tuple->bridge_entities[1] = tuple->bridge_entities[0];
tuple->bridge_entities[0] = tuple->bridge_entities[2];
tuple->bridge_entities[2] = NULL;
/* anyway contact the real destination */
entity = b2bl_new_client(&tuple->bridge_entities[2]->to_uri,
&tuple->bridge_entities[2]->proxy, &tuple->bridge_entities[0]->from_uri, tuple,
&tuple->bridge_entities[2]->scenario_id, &tuple->bridge_entities[2]->hdrs, NULL, NULL);

tuple->bridge_entities[1]->peer = tuple->bridge_entities[0];
tuple->bridge_entities[0]->peer = tuple->bridge_entities[1];
if(entity == NULL)
{
LM_ERR("Failed to generate new client\n");
return -1;
}
entity->no = 1;
b2bl_delete_entity(tuple->bridge_entities[2], tuple, hash_index, 1);
if (0 != b2bl_add_client(tuple, entity))
return -1;

/* original destination connected in the second step */
tuple->bridge_entities[2]= entity;

return 1; // Don't delete tuple
}
else
{
Expand All @@ -531,6 +550,8 @@ int process_bridge_dialog_end(b2bl_tuple_t* tuple, unsigned int hash_index,
/* Disable bridging state */
tuple->state = B2B_NOTDEF_STATE;
tuple->bridge_initiator = 0;

return 1; // Don't delete tuple
} else {
/* the entity to connect replied with negative reply */
b2b_end_dialog(tuple->bridge_entities[0], tuple, hash_index);
Expand All @@ -539,10 +560,42 @@ int process_bridge_dialog_end(b2bl_tuple_t* tuple, unsigned int hash_index,
}
}
else
if(entity_no == 2) /* if a negative reply received from real destination in case of media server used */
{
if(tuple->bridge_flags & B2BL_BR_FLAG_RETURN_AFTER_FAILURE &&
tuple->bridge_initiator != 0 && tuple->bridge_initiator->peer)
{
/* Delete failed entity */
b2bl_delete_entity(bentity, tuple, hash_index, 1);

/* End media entity */
b2b_end_dialog(tuple->bridge_entities[1], tuple, hash_index);

tuple->bridge_entities[2] = NULL;
tuple->bridge_entities[1] = tuple->bridge_entities[0];
tuple->bridge_entities[0] = tuple->bridge_initiator;

tuple->bridge_entities[1]->peer = tuple->bridge_entities[0];
tuple->bridge_entities[0]->peer = tuple->bridge_entities[1];

/* Disable bridging state */
tuple->state = B2B_NOTDEF_STATE;
tuple->bridge_initiator = 0;

return 1; // Don't delete tuple
} else {
/* if the final destination replied with negative reply */
b2b_end_dialog(tuple->bridge_entities[0], tuple, hash_index);
b2b_end_dialog(tuple->bridge_entities[1], tuple, hash_index);
b2b_mark_todel(tuple);
}
}
else /* if a negative reply received from bridge initiator */
{
/* if the final destination replied with negative reply */
/* send cancel or bye to the peers */
b2b_end_dialog(tuple->bridge_entities[0], tuple, hash_index);
b2b_end_dialog(tuple->bridge_entities[1], tuple, hash_index);
b2b_end_dialog(tuple->bridge_entities[2], tuple, hash_index);
b2b_mark_todel(tuple);
}

Expand All @@ -555,11 +608,17 @@ int process_bridge_bye(struct sip_msg* msg, b2bl_tuple_t* tuple,
int entity_no;
b2b_rpl_data_t rpl_data;

entity_no = bridge_get_entityno(tuple, entity);
if(entity_no < 0)
if (tuple->bridge_flags & B2BL_BR_FLAG_RETURN_AFTER_FAILURE &&
entity && tuple->bridge_initiator == entity)
{
LM_ERR("No match found\n");
return -1;
entity_no = 3; // Bridge initiator
} else {
entity_no = bridge_get_entityno(tuple, entity);
if(entity_no < 0)
{
LM_ERR("No match found\n");
return -1;
}
}

memset(&rpl_data, 0, sizeof(b2b_rpl_data_t));
Expand Down Expand Up @@ -638,6 +697,7 @@ int process_bridge_negreply(b2bl_tuple_t* tuple,
tuple->state = B2B_NONE;
break;
case 1: break;
case 2: break;
default:
LM_ERR("unexpected entity_no [%d] for tuple [%p]\n",
entity_no, tuple);
Expand Down Expand Up @@ -1286,7 +1346,8 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple,
}

/* Reply from new bridge entity */
if(statuscode >= 200 && entity == tuple->bridge_entities[1] &&
if(statuscode >= 200 &&
entity == (tuple->bridge_entities[2]?tuple->bridge_entities[2]:tuple->bridge_entities[1]) &&
tuple->bridge_flags & B2BL_BR_FLAG_NOTIFY && tuple->bridge_initiator != 0)
{
process_bridge_notify(tuple->bridge_initiator, cur_route_ctx.hash_index, msg);
Expand Down

0 comments on commit fdf50bb

Please sign in to comment.