Skip to content

Commit

Permalink
dialog: Refactor dlg_leg.sdp and dlg_leg.th_sent_contact
Browse files Browse the repository at this point in the history
These fields are only relevant for dialog pinging and they behave
similarly, so their naming should reflect this.

(cherry picked from commit 287ce6f)
  • Loading branch information
liviuchircu committed Jun 22, 2018
1 parent cfc9efe commit 816cf6e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
16 changes: 8 additions & 8 deletions modules/dialog/dlg_db_handler.c
Expand Up @@ -1253,25 +1253,25 @@ static int persist_reinvite_pinging(struct dlg_cell *dlg)
}

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

if (store_dlg_value_unsafe(dlg, &caller_adv_ct,
&dlg->legs[DLG_CALLER_LEG].th_sent_contact) != 0) {
&dlg->legs[DLG_CALLER_LEG].adv_contact) != 0) {
LM_ERR("failed to persist caller advertised Contact\n");
return -1;
}

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

if (store_dlg_value_unsafe(dlg, &callee_adv_ct,
&dlg->legs[dlg->legs_no[DLG_LEG_200OK]].th_sent_contact) != 0) {
&dlg->legs[dlg->legs_no[DLG_LEG_200OK]].adv_contact) != 0) {
LM_ERR("failed to persist callee advertised Contact\n");
return -1;
}
Expand All @@ -1291,7 +1291,7 @@ static int restore_reinvite_pinging(struct dlg_cell *dlg)
LM_ERR("failed to fetch caller advertised SDP\n");
ret = -1;
} else {
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].sdp, &out_buf) != 0) {
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].adv_sdp, &out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
}
Expand All @@ -1301,7 +1301,7 @@ static int restore_reinvite_pinging(struct dlg_cell *dlg)
LM_ERR("failed to fetch caller advertised Contact\n");
ret = -1;
} else {
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].th_sent_contact,
if (shm_str_dup(&dlg->legs[DLG_CALLER_LEG].adv_contact,
&out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
Expand All @@ -1312,7 +1312,7 @@ static int restore_reinvite_pinging(struct dlg_cell *dlg)
LM_ERR("failed to fetch callee advertised SDP\n");
ret = -1;
} else {
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].sdp, &out_buf) != 0) {
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].adv_sdp, &out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
}
Expand All @@ -1322,7 +1322,7 @@ static int restore_reinvite_pinging(struct dlg_cell *dlg)
LM_ERR("failed to fetch callee advertised Contact\n");
ret = -1;
} else {
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].th_sent_contact,
if (shm_str_dup(&dlg->legs[DLG_FIRST_CALLEE_LEG].adv_contact,
&out_buf) != 0) {
LM_ERR("oom\n");
ret = -1;
Expand Down
18 changes: 9 additions & 9 deletions modules/dialog/dlg_handlers.c
Expand Up @@ -660,16 +660,16 @@ static void dlg_update_sdp(struct dlg_leg *leg,struct sip_msg *msg)
sdp.len = 0;
}

if (leg->sdp.len < sdp.len) {
leg->sdp.s = shm_realloc(leg->sdp.s,sdp.len);
if (!leg->sdp.s) {
if (leg->adv_sdp.len < sdp.len) {
leg->adv_sdp.s = shm_realloc(leg->adv_sdp.s,sdp.len);
if (!leg->adv_sdp.s) {
LM_ERR("Failed to reallocate sdp \n");
return;
}
}

leg->sdp.len = sdp.len;
memcpy(leg->sdp.s,sdp.s,sdp.len);
leg->adv_sdp.len = sdp.len;
memcpy(leg->adv_sdp.s,sdp.s,sdp.len);
}

static void dlg_update_callee_sdp(struct cell* t, int type,
Expand Down Expand Up @@ -959,7 +959,7 @@ static void dlg_onreply_out(struct cell* t, int type, struct tmcb_params *ps)
sdp.len = 0;
}

if (shm_str_sync(&dlg->legs[DLG_CALLER_LEG].sdp, &sdp) != 0) {
if (shm_str_sync(&dlg->legs[DLG_CALLER_LEG].adv_sdp, &sdp) != 0) {
LM_ERR("No more shm \n");
free_sip_msg(msg);
pkg_free(msg);
Expand All @@ -973,7 +973,7 @@ static void dlg_onreply_out(struct cell* t, int type, struct tmcb_params *ps)
contact.s = msg->contact->name.s;
contact.len = msg->contact->len;

if (shm_str_sync(&dlg->legs[DLG_CALLER_LEG].th_sent_contact,
if (shm_str_sync(&dlg->legs[DLG_CALLER_LEG].adv_contact,
&contact) != 0) {
LM_ERR("No more shm mem for outgoing contact hdr\n");
free_sip_msg(msg);
Expand Down Expand Up @@ -1138,7 +1138,7 @@ static void dlg_onreq_out(struct cell* t, int type, struct tmcb_params *ps)

/* TODO: fix for late negotiation ... */

if (shm_str_dup(&leg->sdp, &sdp) != 0) {
if (shm_str_dup(&leg->adv_sdp, &sdp) != 0) {
LM_ERR("No more shm\n");
goto out_free;
}
Expand All @@ -1150,7 +1150,7 @@ static void dlg_onreq_out(struct cell* t, int type, struct tmcb_params *ps)
contact.s = msg->contact->name.s;
contact.len = msg->contact->len;

if (shm_str_dup(&leg->th_sent_contact, &contact) != 0) {
if (shm_str_dup(&leg->adv_contact, &contact) != 0) {
LM_ERR("No more shm for INVITE outgoing contact \n");
goto out_free;
}
Expand Down
24 changes: 12 additions & 12 deletions modules/dialog/dlg_hash.c
Expand Up @@ -198,14 +198,14 @@ static inline void free_dlg_dlg(struct dlg_cell *dlg)
shm_free(dlg->legs[i].contact.s);
if (dlg->legs[i].route_set.s)
shm_free(dlg->legs[i].route_set.s);
if (dlg->legs[i].th_sent_contact.s)
shm_free(dlg->legs[i].th_sent_contact.s);
if (dlg->legs[i].adv_contact.s)
shm_free(dlg->legs[i].adv_contact.s);
if (dlg->legs[i].from_uri.s)
shm_free(dlg->legs[i].from_uri.s);
if (dlg->legs[i].to_uri.s)
shm_free(dlg->legs[i].to_uri.s);
if (dlg->legs[i].sdp.s)
shm_free(dlg->legs[i].sdp.s);
if (dlg->legs[i].adv_sdp.s)
shm_free(dlg->legs[i].adv_sdp.s);
}
shm_free(dlg->legs);
}
Expand Down Expand Up @@ -424,14 +424,14 @@ int dlg_update_leg_info(int leg_idx, struct dlg_cell *dlg, str* tag, str *rr,
}

if (sdp && sdp->s && sdp->len) {
leg->sdp.s = shm_malloc(sdp->len);
if (!leg->sdp.s) {
leg->adv_sdp.s = shm_malloc(sdp->len);
if (!leg->adv_sdp.s) {
LM_ERR("no more shm\n");
goto error_all;
}

leg->sdp.len = sdp->len;
memcpy(leg->sdp.s,sdp->s,sdp->len);
leg->adv_sdp.len = sdp->len;
memcpy(leg->adv_sdp.s,sdp->s,sdp->len);
}

/* tag */
Expand Down Expand Up @@ -1239,8 +1239,8 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
goto error;

node1 = add_mi_node_child(node, MI_DUP_VALUE,"caller_sdp",10,
dlg->legs[DLG_CALLER_LEG].sdp.s,
dlg->legs[DLG_CALLER_LEG].sdp.len);
dlg->legs[DLG_CALLER_LEG].adv_sdp.s,
dlg->legs[DLG_CALLER_LEG].adv_sdp.len);
if(node1 == 0)
goto error;
}
Expand Down Expand Up @@ -1288,8 +1288,8 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
goto error;

node3 = add_mi_node_child(node2, MI_DUP_VALUE,"callee_sdp",10,
dlg->legs[i].sdp.s,
dlg->legs[i].sdp.len);
dlg->legs[i].adv_sdp.s,
dlg->legs[i].adv_sdp.len);
if(node3 == 0)
goto error;
}
Expand Down
6 changes: 3 additions & 3 deletions modules/dialog/dlg_hash.h
Expand Up @@ -95,10 +95,10 @@ struct dlg_leg {
str from_uri; /* FROM URI for this leg, in case of FROM URI mangling*/
str to_uri; /* TO URI for this leg, in case of TO URI mangling */
str route_set;
str contact;
str th_sent_contact; /* topology hiding advertised contact towards this leg - full header */
str contact; /* this leg's Contact URI (most recent version) */
str adv_contact; /* topology hiding advertised contact towards this leg - full header */
str adv_sdp; /* latest SDP advertised towards this leg ( full body ), after all OpenSIPS changes */
str route_uris[64];
str sdp; /* latest SDP advertised towards this leg ( full body ), after all OpenSIPS changes */
int nr_uris;
unsigned int last_gen_cseq; /* FIXME - think this can be atomic_t to avoid locking */
unsigned int last_inv_gen_cseq; /* used when translating ACKs */
Expand Down
28 changes: 14 additions & 14 deletions modules/dialog/dlg_timer.c
Expand Up @@ -1058,9 +1058,9 @@ void dlg_reinvite_routine(unsigned int ticks , void * attr)
if (dlg->state != DLG_STATE_DELETED && it->timeout <= current_ticks) {
if (dlg->flags & DLG_FLAG_REINVITE_PING_CALLER) {

if (dlg->legs[DLG_CALLER_LEG].th_sent_contact.len)
if (dlg->legs[DLG_CALLER_LEG].adv_contact.len)
extra_headers.len =
dlg->legs[DLG_CALLER_LEG].th_sent_contact.len +
dlg->legs[DLG_CALLER_LEG].adv_contact.len +
HEADERS_STR_END_NOCRLF_LEN;
else
extra_headers.len = CONTACT_STR_START_LEN +
Expand All @@ -1073,12 +1073,12 @@ void dlg_reinvite_routine(unsigned int ticks , void * attr)
return;
}

if (dlg->legs[DLG_CALLER_LEG].th_sent_contact.len) {
if (dlg->legs[DLG_CALLER_LEG].adv_contact.len) {
p = extra_headers.s;
memcpy(p,dlg->legs[DLG_CALLER_LEG].th_sent_contact.s,
dlg->legs[DLG_CALLER_LEG].th_sent_contact.len);
memcpy(p,dlg->legs[DLG_CALLER_LEG].adv_contact.s,
dlg->legs[DLG_CALLER_LEG].adv_contact.len);

p+= dlg->legs[DLG_CALLER_LEG].th_sent_contact.len;
p+= dlg->legs[DLG_CALLER_LEG].adv_contact.len;
memcpy(p,HEADERS_STR_END_NOCRLF,HEADERS_STR_END_NOCRLF_LEN);
} else {
p = extra_headers.s;
Expand All @@ -1093,7 +1093,7 @@ void dlg_reinvite_routine(unsigned int ticks , void * attr)

ref_dlg(dlg,1);
if (send_leg_msg(dlg,&invite_str,callee_idx(dlg),
DLG_CALLER_LEG,&extra_headers,&dlg->legs[DLG_CALLER_LEG].sdp,
DLG_CALLER_LEG,&extra_headers,&dlg->legs[DLG_CALLER_LEG].adv_sdp,
reinvite_reply_from_caller,dlg,unref_dlg_cb,
&dlg->legs[DLG_CALLER_LEG].reinvite_confirmed) < 0) {
LM_ERR("failed to ping caller\n");
Expand All @@ -1105,9 +1105,9 @@ void dlg_reinvite_routine(unsigned int ticks , void * attr)


if (dlg->flags & DLG_FLAG_REINVITE_PING_CALLEE) {
if (dlg->legs[callee_idx(dlg)].th_sent_contact.len)
if (dlg->legs[callee_idx(dlg)].adv_contact.len)
extra_headers.len =
dlg->legs[callee_idx(dlg)].th_sent_contact.len +
dlg->legs[callee_idx(dlg)].adv_contact.len +
HEADERS_STR_END_NOCRLF_LEN;
else
extra_headers.len = CONTACT_STR_START_LEN +
Expand All @@ -1120,13 +1120,13 @@ void dlg_reinvite_routine(unsigned int ticks , void * attr)
return ;
}

if (dlg->legs[callee_idx(dlg)].th_sent_contact.len) {
if (dlg->legs[callee_idx(dlg)].adv_contact.len) {
p = extra_headers.s;
memcpy(extra_headers.s,
dlg->legs[callee_idx(dlg)].th_sent_contact.s,
dlg->legs[callee_idx(dlg)].th_sent_contact.len);
dlg->legs[callee_idx(dlg)].adv_contact.s,
dlg->legs[callee_idx(dlg)].adv_contact.len);

p+= dlg->legs[callee_idx(dlg)].th_sent_contact.len;
p+= dlg->legs[callee_idx(dlg)].adv_contact.len;
memcpy(p,HEADERS_STR_END_NOCRLF,HEADERS_STR_END_NOCRLF_LEN);
} else {
p = extra_headers.s;
Expand All @@ -1141,7 +1141,7 @@ void dlg_reinvite_routine(unsigned int ticks , void * attr)

ref_dlg(dlg,1);
if (send_leg_msg(dlg,&invite_str,DLG_CALLER_LEG,
callee_idx(dlg),&extra_headers,&dlg->legs[callee_idx(dlg)].sdp,reinvite_reply_from_callee,
callee_idx(dlg),&extra_headers,&dlg->legs[callee_idx(dlg)].adv_sdp,reinvite_reply_from_callee,
dlg,unref_dlg_cb,&dlg->legs[callee_idx(dlg)].reinvite_confirmed) < 0) {
LM_ERR("failed to ping callee\n");
unref_dlg(dlg,1);
Expand Down

0 comments on commit 816cf6e

Please sign in to comment.