Skip to content

Commit

Permalink
dialog: always persist SDP for both in and out
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Apr 15, 2019
1 parent d05a726 commit 58dc435
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 124 deletions.
4 changes: 2 additions & 2 deletions modules/dialog/dialog.c
Expand Up @@ -2107,7 +2107,7 @@ static char *dlg_get_json_out(struct dlg_cell *dlg,int ctx,int *out_len)
dlg->legs[DLG_CALLER_LEG].r_cseq.len,dlg->legs[DLG_CALLER_LEG].r_cseq.s,
dlg->legs[DLG_CALLER_LEG].route_set.len,dlg->legs[DLG_CALLER_LEG].route_set.s,
dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str.len,dlg->legs[DLG_CALLER_LEG].bind_addr->sock_str.s,
dlg->legs[DLG_CALLER_LEG].adv_sdp.len,dlg->legs[DLG_CALLER_LEG].adv_sdp.s);
dlg->legs[DLG_CALLER_LEG].out_sdp.len,dlg->legs[DLG_CALLER_LEG].out_sdp.s);

if (i<0) {
LM_ERR("Failed to print dlg json \n");
Expand All @@ -2134,7 +2134,7 @@ static char *dlg_get_json_out(struct dlg_cell *dlg,int ctx,int *out_len)
dlg->legs[j].r_cseq.len,dlg->legs[j].r_cseq.s,
dlg->legs[j].route_set.len,dlg->legs[j].route_set.s,
dlg->legs[j].bind_addr->sock_str.len,dlg->legs[j].bind_addr->sock_str.s,
dlg->legs[j].adv_sdp.len,dlg->legs[j].adv_sdp.s);
dlg->legs[j].out_sdp.len,dlg->legs[j].out_sdp.s);

if (i<0) {
LM_ERR("Failed to print dlg json \n");
Expand Down
89 changes: 63 additions & 26 deletions modules/dialog/dlg_db_handler.c
Expand Up @@ -615,9 +615,9 @@ static int load_dialog_info_from_db(int dlg_hash_size)

/* add the 2 legs */
if ( (dlg_update_leg_info(0, dlg, &from_tag, &rroute1, &contact1,
&cseq1, caller_sock,0,0,0)!=0) ||
&cseq1, caller_sock,0,0,0,0)!=0) ||
(dlg_update_leg_info(1, dlg, &to_tag, &rroute2, &contact2,
&cseq2, callee_sock,&mangled_fu,&mangled_tu,0)!=0) ) {
&cseq2, callee_sock,&mangled_fu,&mangled_tu,0,0)!=0) ) {
LM_ERR("dlg_set_leg_info failed\n");
/* destroy the dialog */
unref_dlg(dlg,1);
Expand Down Expand Up @@ -1259,16 +1259,25 @@ str* write_dialog_profiles( struct dlg_profile_link *links)
/* duplicate the SDPs/Contacts of caller/callee(s) into dlg val storage */
static int persist_reinvite_pinging(struct dlg_cell *dlg)
{
str caller_adv_sdp = str_init("CSDP"), callee_adv_sdp = str_init("cSDP");
str caller_in_sdp = str_init("uCSDP"), callee_in_sdp = str_init("ucSDP");
str caller_out_sdp = str_init("aCSDP"), callee_out_sdp = str_init("acSDP");
str caller_adv_ct = str_init("Cct"), callee_adv_ct = str_init("cct");

if (dlg->legs_no[DLG_LEG_200OK] == 0) {
LM_DBG("non-confirmed dialogs are not DB persistent!\n");
return 0;
}

if (store_dlg_value_unsafe(dlg, &caller_adv_sdp,
&dlg->legs[DLG_CALLER_LEG].adv_sdp) != 0) {
if (dlg->legs[DLG_CALLER_LEG].in_sdp.len &&
store_dlg_value_unsafe(dlg, &caller_in_sdp,
&dlg->legs[DLG_CALLER_LEG].in_sdp) != 0) {
LM_ERR("failed to persist caller UAC SDP\n");
return -1;
}

if (dlg->legs[DLG_CALLER_LEG].out_sdp.len &&
store_dlg_value_unsafe(dlg, &caller_out_sdp,
&dlg->legs[DLG_CALLER_LEG].out_sdp) != 0) {
LM_ERR("failed to persist caller advertised SDP\n");
return -1;
}
Expand All @@ -1279,8 +1288,16 @@ static int persist_reinvite_pinging(struct dlg_cell *dlg)
return -1;
}

if (store_dlg_value_unsafe(dlg, &callee_adv_sdp,
&dlg->legs[dlg->legs_no[DLG_LEG_200OK]].adv_sdp) != 0) {
if (dlg->legs[dlg->legs_no[DLG_LEG_200OK]].in_sdp.len &&
store_dlg_value_unsafe(dlg, &callee_in_sdp,
&dlg->legs[dlg->legs_no[DLG_LEG_200OK]].in_sdp) != 0) {
LM_ERR("failed to persist callee UAC SDP\n");
return -1;
}

if (dlg->legs[dlg->legs_no[DLG_LEG_200OK]].out_sdp.len &&
store_dlg_value_unsafe(dlg, &callee_out_sdp,
&dlg->legs[dlg->legs_no[DLG_LEG_200OK]].out_sdp) != 0) {
LM_ERR("failed to persist callee advertised SDP\n");
return -1;
}
Expand All @@ -1297,16 +1314,27 @@ static int persist_reinvite_pinging(struct dlg_cell *dlg)
/* re-populate the SDPs/Contacts of caller/callee(s) from dlg val storage */
static int restore_reinvite_pinging(struct dlg_cell *dlg)
{
str caller_adv_sdp = str_init("CSDP"), callee_adv_sdp = str_init("cSDP");
str caller_in_sdp = str_init("uCSDP"), callee_in_sdp = str_init("ucSDP");
str caller_out_sdp = str_init("aCSDP"), callee_out_sdp = str_init("acSDP");
str caller_adv_ct = str_init("Cct"), callee_adv_ct = str_init("cct");
str out_buf;
int ret = 0;

if (fetch_dlg_value(dlg, &caller_adv_sdp, &out_buf, 0) != 0) {
LM_ERR("failed to fetch caller advertised SDP\n");
ret = -1;
if (fetch_dlg_value(dlg, &caller_in_sdp, &out_buf, 0) != 0) {
dlg->legs[DLG_CALLER_LEG].in_sdp.len = 0;
dlg->legs[DLG_CALLER_LEG].in_sdp.s = 0;
} else {
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].in_sdp, &out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
}
}

if (fetch_dlg_value(dlg, &caller_out_sdp, &out_buf, 0) != 0) {
dlg->legs[DLG_CALLER_LEG].out_sdp.len = 0;
dlg->legs[DLG_CALLER_LEG].out_sdp.s = 0;
} else {
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].adv_sdp, &out_buf) != 0) {
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].out_sdp, &out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
}
Expand All @@ -1323,11 +1351,22 @@ static int restore_reinvite_pinging(struct dlg_cell *dlg)
}
}

if (fetch_dlg_value(dlg, &callee_adv_sdp, &out_buf, 0) != 0) {
LM_ERR("failed to fetch callee advertised SDP\n");
ret = -1;
if (fetch_dlg_value(dlg, &callee_in_sdp, &out_buf, 0) != 0) {
dlg->legs[DLG_FIRST_CALLEE_LEG].in_sdp.len = 0;
dlg->legs[DLG_FIRST_CALLEE_LEG].in_sdp.s = 0;
} else {
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].in_sdp, &out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
}
}


if (fetch_dlg_value(dlg, &callee_out_sdp, &out_buf, 0) != 0) {
dlg->legs[DLG_FIRST_CALLEE_LEG].out_sdp.len = 0;
dlg->legs[DLG_FIRST_CALLEE_LEG].out_sdp.s = 0;
} else {
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].adv_sdp, &out_buf) != 0) {
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].out_sdp, &out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
}
Expand Down Expand Up @@ -1363,10 +1402,8 @@ static inline void set_final_update_cols(db_val_t *vals, struct dlg_cell *cell,
run_dlg_callbacks(DLGCB_WRITE_VP, cell, 0, DLG_DIR_NONE, NULL, 1, 1);
}

if (dlg_has_reinvite_pinging(cell)) {
if (persist_reinvite_pinging(cell) != 0)
LM_ERR("failed to persist some Re-INVITE pinging info\n");
}
if (persist_reinvite_pinging(cell) != 0)
LM_ERR("failed to persist some Re-INVITE pinging info\n");

/* save sharing tag name as dlg val */
if (cell->shtag.s && store_dlg_value_unsafe(cell, &shtag_dlg_val,
Expand Down Expand Up @@ -1778,9 +1815,9 @@ static int sync_dlg_db_mem(void)

/* add the 2 legs */
if ((dlg_update_leg_info(0, dlg, &from_tag, &rroute1, &contact1,
&cseq1, caller_sock,0,0,0)!=0) ||
&cseq1, caller_sock,0,0,0,0)!=0) ||
(dlg_update_leg_info(1, dlg, &to_tag, &rroute2, &contact2,
&cseq2, callee_sock,&mangled_fu,&mangled_tu,0)!=0) ) {
&cseq2, callee_sock,&mangled_fu,&mangled_tu,0,0)!=0) ) {
LM_ERR("dlg_set_leg_info failed\n");
/* destroy the dialog */
unref_dlg(dlg,1);
Expand Down Expand Up @@ -1861,11 +1898,11 @@ static int sync_dlg_db_mem(void)
}
}

if (dlg_has_reinvite_pinging(dlg)) {
if (restore_reinvite_pinging(dlg) != 0)
LM_ERR("failed to fetch some Re-INVITE pinging data\n");
else if (dlg_has_reinvite_pinging(dlg)) {
/* re-populate Re-INVITE pinging fields */
if (restore_reinvite_pinging(dlg) != 0)
LM_ERR("failed to fetch some Re-INVITE pinging data\n");
else if (0 != insert_reinvite_ping_timer(dlg))
if (0 != insert_reinvite_ping_timer(dlg))
LM_CRIT("Unable to insert dlg %p into reinvite"
"ping timer\n", dlg);
else {
Expand Down

0 comments on commit 58dc435

Please sign in to comment.