Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into async-aud-conf
Browse files Browse the repository at this point in the history
  • Loading branch information
nanangizz committed Sep 10, 2024
2 parents 7072e3c + cbccd49 commit 3d5dfad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
38 changes: 34 additions & 4 deletions pjsip/src/pjsip-ua/sip_inv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,8 @@ PJ_DEF(pj_status_t) pjsip_inv_uac_restart(pjsip_inv_session *inv,
{
PJ_ASSERT_RETURN(inv, PJ_EINVAL);

pjsip_inv_add_ref(inv);

inv->state = PJSIP_INV_STATE_NULL;
inv->invite_tsx = NULL;
if (inv->last_answer) {
Expand All @@ -1942,6 +1944,8 @@ PJ_DEF(pj_status_t) pjsip_inv_uac_restart(pjsip_inv_session *inv,
}
}

pjsip_inv_dec_ref(inv);

return PJ_SUCCESS;
}

Expand Down Expand Up @@ -2814,6 +2818,8 @@ PJ_DEF(pj_status_t) pjsip_inv_set_local_sdp(pjsip_inv_session *inv,

PJ_ASSERT_RETURN(inv && sdp, PJ_EINVAL);

pjsip_inv_add_ref(inv);

/* If we have remote SDP offer, set local answer to respond to the offer,
* otherwise we set/modify our local offer (and create an SDP negotiator
* if we don't have one yet).
Expand All @@ -2830,13 +2836,17 @@ PJ_DEF(pj_status_t) pjsip_inv_set_local_sdp(pjsip_inv_session *inv,
status = pjmedia_sdp_neg_modify_local_offer2(inv->pool, inv->neg,
inv->sdp_neg_flags,
sdp);
} else
} else {
pjsip_inv_dec_ref(inv);
return PJMEDIA_SDPNEG_EINSTATE;
}
} else {
status = pjmedia_sdp_neg_create_w_local_offer(inv->pool,
sdp, &inv->neg);
}

pjsip_inv_dec_ref(inv);

return status;
}

Expand Down Expand Up @@ -2874,6 +2884,7 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL);

pj_log_push_indent();
pjsip_inv_add_ref(inv);

/* Set cause code. */
inv_set_cause(inv, st_code, st_text);
Expand All @@ -2890,7 +2901,8 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
/* For UAC when session has not been confirmed, create CANCEL. */

/* MUST have the original UAC INVITE transaction. */
PJ_ASSERT_RETURN(inv->invite_tsx != NULL, PJ_EBUG);
PJ_ASSERT_ON_FAIL(inv->invite_tsx != NULL,
{ pjsip_inv_dec_ref(inv); return PJ_EBUG; });

/* But CANCEL should only be called when we have received a
* provisional response. If we haven't received any responses,
Expand All @@ -2905,6 +2917,7 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
*p_tdata = NULL;
PJ_LOG(4, (inv->obj_name, "Delaying CANCEL since no "
"provisional response is received yet"));
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJ_SUCCESS;
}
Expand All @@ -2918,6 +2931,7 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
inv->invite_tsx->last_tx,
&tdata);
if (status != PJ_SUCCESS) {
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return status;
}
Expand All @@ -2938,7 +2952,9 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
if (tdata == NULL)
tdata = inv->last_answer;

PJ_ASSERT_RETURN(tdata != NULL, PJ_EINVALIDOP);
PJ_ASSERT_ON_FAIL(tdata != NULL,
{ pjsip_inv_dec_ref(inv);
return PJ_EINVALIDOP; });

//status = pjsip_dlg_modify_response(inv->dlg, tdata, st_code,
// st_text);
Expand All @@ -2960,16 +2976,19 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,

case PJSIP_INV_STATE_DISCONNECTED:
/* No need to do anything. */
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJSIP_ESESSIONTERMINATED;

default:
pj_assert(!"Invalid operation!");
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJ_EINVALIDOP;
}

if (status != PJ_SUCCESS) {
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return status;
}
Expand All @@ -2980,6 +2999,7 @@ PJ_DEF(pj_status_t) pjsip_inv_end_session( pjsip_inv_session *inv,
inv->cancelling = PJ_TRUE;
*p_tdata = tdata;

pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJ_SUCCESS;
}
Expand All @@ -2997,6 +3017,7 @@ PJ_DEF(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv,
PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL);

pj_log_push_indent();
pjsip_inv_add_ref(inv);

/* Create appropriate message. */
switch (inv->state) {
Expand All @@ -3013,6 +3034,7 @@ PJ_DEF(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv,
*p_tdata = NULL;
PJ_LOG(4, (inv->obj_name, "Delaying CANCEL since no "
"provisional response is received yet"));
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJ_SUCCESS;
}
Expand All @@ -3021,6 +3043,7 @@ PJ_DEF(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv,
inv->invite_tsx->last_tx,
&tdata);
if (status != PJ_SUCCESS) {
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return status;
}
Expand All @@ -3030,10 +3053,12 @@ PJ_DEF(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv,
/* We cannot send CANCEL to a re-INVITE if the INVITE session is
* not confirmed.
*/
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJ_EINVALIDOP;
}

pjsip_inv_dec_ref(inv);
pj_log_pop_indent();

*p_tdata = tdata;
Expand Down Expand Up @@ -3732,6 +3757,7 @@ PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv,
PJ_ASSERT_RETURN(inv && tdata, PJ_EINVAL);

pj_log_push_indent();
pjsip_inv_add_ref(inv);

PJ_LOG(5,(inv->obj_name, "Sending %s",
pjsip_tx_data_get_info(tdata)));
Expand Down Expand Up @@ -3819,7 +3845,9 @@ PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv,
cseq = (pjsip_cseq_hdr*)pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL);
PJ_ASSERT_ON_FAIL(cseq != NULL
&& (inv->invite_tsx && cseq->cseq == inv->invite_tsx->cseq),
{ pjsip_tx_data_dec_ref(tdata); return PJ_EINVALIDOP; });
{ pjsip_tx_data_dec_ref(tdata);
pjsip_inv_dec_ref(inv);
return PJ_EINVALIDOP; });

if (inv->options & PJSIP_INV_REQUIRE_100REL) {
status = pjsip_100rel_tx_response(inv, tdata);
Expand All @@ -3835,10 +3863,12 @@ PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv,

/* Done */
on_return:
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return PJ_SUCCESS;

on_error:
pjsip_inv_dec_ref(inv);
pj_log_pop_indent();
return status;
}
Expand Down
8 changes: 8 additions & 0 deletions pjsip/src/pjsip/sip_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,11 @@ PJ_DEF(pj_status_t) pjsip_dlg_inc_session( pjsip_dialog *dlg,
*/
PJ_DEF(void) pjsip_dlg_inc_lock(pjsip_dialog *dlg)
{
/* Add ref temporarily to avoid possible dialog destroy while waiting
* the lock.
*/
pj_grp_lock_add_ref(dlg->grp_lock_);

PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_inc_lock(), sess_count=%d",
dlg->sess_count));

Expand All @@ -956,6 +961,9 @@ PJ_DEF(void) pjsip_dlg_inc_lock(pjsip_dialog *dlg)

PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_inc_lock(), sess_count=%d",
dlg->sess_count));

/* Lock has been acquired, dec ref */
pj_grp_lock_dec_ref(dlg->grp_lock_);
}

/* Try to acquire dialog's group lock, but bail out if group lock can not be
Expand Down

0 comments on commit 3d5dfad

Please sign in to comment.