Skip to content

Commit

Permalink
topos: detect first direction for dlg requests before linking contact
Browse files Browse the repository at this point in the history
- related to GH #1571

(cherry picked from commit a8d4ca2)
  • Loading branch information
miconda committed Aug 17, 2018
1 parent 8540e2b commit adae203
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
20 changes: 11 additions & 9 deletions src/modules/topos/tps_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
memset(&mtsd, 0, sizeof(tps_data_t));
memset(&btsd, 0, sizeof(tps_data_t));
memset(&stsd, 0, sizeof(tps_data_t));
ptsd = &mtsd;
ptsd = NULL;

if(tps_pack_message(msg, &mtsd)<0) {
LM_ERR("failed to extract and pack the headers\n");
Expand All @@ -956,14 +956,6 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)

tps_storage_lock_get(&lkey);

if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)!=0) {
if(tps_storage_record(msg, ptsd, dialog)<0) {
goto error;
}
} else {
ptsd = &btsd;
}

if(dialog!=0) {
if(tps_storage_load_dialog(msg, &mtsd, &stsd)==0) {
ptsd = &stsd;
Expand All @@ -975,6 +967,16 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
mtsd.direction = direction;
}

if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)!=0) {
if(tps_storage_record(msg, &mtsd, dialog, direction)<0) {
goto error;
}
} else {
if(ptsd==NULL) ptsd = &btsd;
}

if(ptsd==NULL) ptsd = &mtsd;

/* local generated requests */
if(local) {
/* ACK and CANCEL go downstream */
Expand Down
6 changes: 3 additions & 3 deletions src/modules/topos/tps_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
}
}

LM_DBG("downstream: %s acontact: [%.*s] bcontact: [%.*s]\n",
LM_DBG("downstream: %s - acontact: [%.*s] - bcontact: [%.*s]\n",
(dir==TPS_DIR_DOWNSTREAM)?"yes":"no",
td->a_contact.len, (td->a_contact.len>0)?td->a_contact.s:"",
td->b_contact.len, (td->b_contact.len>0)?td->b_contact.s:"");
Expand All @@ -374,7 +374,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
/**
*
*/
int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog)
int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir)
{
int ret = -1; /* error if dialog == 0 */
str suid;
Expand All @@ -399,7 +399,7 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog)
ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_UPSTREAM);
if(ret<0) goto error;

ret = tps_storage_link_msg(msg, td, TPS_DIR_DOWNSTREAM);
ret = tps_storage_link_msg(msg, td, dir);
if(ret<0) goto error;
if(dialog==0) {
if(td->as_contact.len <= 0 && td->bs_contact.len <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/topos/tps_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int tps_storage_branch_find(sip_msg_t *msg, tps_data_t *td);
int tps_storage_branch_save(sip_msg_t *msg, tps_data_t *td);
int tps_storage_branch_rm(sip_msg_t *msg, tps_data_t *td);

int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog);
int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir);
int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
uint32_t mode);
int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
Expand Down

0 comments on commit adae203

Please sign in to comment.