Skip to content

Commit

Permalink
SIP plugin: add missing SIP Contact header in re-INVITE request (#3286)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycherniavskyi authored Dec 6, 2023
1 parent dc0b9a3 commit 99a64f2
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/plugins/janus_sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,13 @@ static void janus_sip_session_dereference(janus_sip_session *session) {
janus_refcount_decrease(&session->ref);
}

static char *janus_sip_session_contact_header_retrieve(janus_sip_session *session) {
if(session->helper && session->master)
return session->master->stack->contact_header;
else
return session->stack->contact_header;
}

static void janus_sip_session_free(const janus_refcount *session_ref) {
janus_sip_session *session = janus_refcount_containerof(session_ref, janus_sip_session, ref);
/* Remove the reference to the core plugin session */
Expand Down Expand Up @@ -3428,19 +3435,14 @@ static void *janus_sip_handler(void *data) {
janus_mutex_unlock(&session->stack->smutex);
char custom_headers[2048];
janus_sip_parse_custom_headers(root, (char *)&custom_headers, sizeof(custom_headers));
/* Check if we need to manually add the Contact header */
gboolean add_contact_header = FALSE;
if(session->helper && session->master)
add_contact_header = (session->master->stack->contact_header != NULL);
else
add_contact_header = (session->stack->contact_header != NULL);
/* Retrieve the Contact header for manually adding if not NULL */
char *contact_header = janus_sip_session_contact_header_retrieve(session);
/* Send the SUBSCRIBE */
nua_subscribe(nh,
SIPTAG_TO_STR(to),
SIPTAG_EVENT_STR(event_type),
SIPTAG_CALL_ID_STR(callid),
TAG_IF(add_contact_header, SIPTAG_CONTACT_STR((session->helper && session->master) ?
session->master->stack->contact_header: session->stack->contact_header)),
TAG_IF(contact_header != NULL, SIPTAG_CONTACT_STR(contact_header)),
SIPTAG_ACCEPT_STR(accept),
SIPTAG_EXPIRES_STR(ttl_text),
NUTAG_PROXY(session->helper && session->master ?
Expand Down Expand Up @@ -3822,14 +3824,14 @@ static void *janus_sip_handler(void *data) {
g_atomic_int_set(&session->establishing, 1);
/* Add a reference for this call */
janus_sip_ref_active_call(session);
/* Check if we need to manually add the Contact header */
gboolean add_contact_header = (session->stack->contact_header != NULL);
/* Retrieve the Contact header for manually adding if not NULL */
char *contact_header = janus_sip_session_contact_header_retrieve(session);
/* Send the INVITE */
nua_invite(session->stack->s_nh_i,
SIPTAG_FROM_STR(from_hdr),
SIPTAG_TO_STR(uri_text),
SIPTAG_CALL_ID_STR(callid),
TAG_IF(add_contact_header, SIPTAG_CONTACT_STR(session->stack->contact_header)),
TAG_IF(contact_header != NULL, SIPTAG_CONTACT_STR(contact_header)),
SOATAG_USER_SDP_STR(sdp),
NUTAG_PROXY(session->helper && session->master ?
session->master->account.outbound_proxy : session->account.outbound_proxy),
Expand Down Expand Up @@ -4180,8 +4182,11 @@ static void *janus_sip_handler(void *data) {
session->media.update = offer;
JANUS_LOG(LOG_VERB, "Prepared SDP for update:\n%s", sdp);
if(session->status == janus_sip_call_status_incall) {
/* Retrieve the Contact header for manually adding if not NULL */
char *contact_header = janus_sip_session_contact_header_retrieve(session);
/* We're sending a re-INVITE ourselves */
nua_invite(session->stack->s_nh_i,
TAG_IF(contact_header != NULL, SIPTAG_CONTACT_STR(contact_header)),
SOATAG_USER_SDP_STR(sdp),
TAG_END());
} else {
Expand Down Expand Up @@ -4485,9 +4490,12 @@ static void *janus_sip_handler(void *data) {
char custom_headers[2048];
janus_sip_parse_custom_headers(root, (char *)&custom_headers, sizeof(custom_headers));

/* Retrieve the Contact header for manually adding if not NULL */
char *contact_header = janus_sip_session_contact_header_retrieve(session);
/* Send the re-INVITE */
char *sdp = janus_sdp_write(session->sdp);
nua_invite(session->stack->s_nh_i,
TAG_IF(contact_header != NULL, SIPTAG_CONTACT_STR(contact_header)),
SOATAG_USER_SDP_STR(sdp),
TAG_IF(strlen(custom_headers) > 0, SIPTAG_HEADER_STR(custom_headers)),
TAG_END());
Expand Down

0 comments on commit 99a64f2

Please sign in to comment.