Skip to content

Commit 9be0310

Browse files
authored
Add option to specify contact URI when making call (PJSUA and PJSUA2) (#4647)
1 parent 18595ca commit 9be0310

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

pjsip/include/pjsua-lib/pjsua.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,13 @@ struct pjsua_msg_data
26652665
*/
26662666
pj_str_t local_uri;
26672667

2668+
/**
2669+
* Optional contact URI to be used for this call. If NULL, the contact
2670+
* will be generated automatically based on the account configuration.
2671+
* This field is currently used only by pjsua_call_make_call().
2672+
*/
2673+
pj_str_t contact_uri;
2674+
26682675
/**
26692676
* Additional message headers as linked list. Application can add
26702677
* headers to the list by creating the header, either from the heap/pool

pjsip/include/pjsua2/siptypes.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,14 @@ struct SipTxOption
996996
*/
997997
string localUri;
998998

999+
/**
1000+
* Optional contact URI to be used for this call. If empty (""), the
1001+
* contact will be generated automatically based on the account
1002+
* configuration. At the moment this field is only used when sending
1003+
* initial INVITE requests.
1004+
*/
1005+
string contactUri;
1006+
9991007
/**
10001008
* Additional message headers to be included in the outgoing message.
10011009
*

pjsip/src/pjsua-lib/pjsua_call.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,30 @@ PJ_DEF(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
947947
status = PJSIP_EINVALIDREQURI;
948948
goto on_error;
949949
}
950+
951+
/* Verify contact URI if provided */
952+
if (msg_data && msg_data->contact_uri.slen) {
953+
pj_strdup_with_null(tmp_pool, &dup, &msg_data->contact_uri);
954+
uri = pjsip_parse_uri(tmp_pool, dup.ptr, dup.slen, 0);
955+
if (uri == NULL) {
956+
pjsua_perror(THIS_FILE, "Invalid contact URI",
957+
PJSIP_EINVALIDREQURI);
958+
status = PJSIP_EINVALIDREQURI;
959+
goto on_error;
960+
}
961+
}
962+
963+
/* Verify local URI if provided */
964+
if (msg_data && msg_data->local_uri.slen) {
965+
pj_strdup_with_null(tmp_pool, &dup, &msg_data->local_uri);
966+
uri = pjsip_parse_uri(tmp_pool, dup.ptr, dup.slen, 0);
967+
if (uri == NULL) {
968+
pjsua_perror(THIS_FILE, "Invalid local URI",
969+
PJSIP_EINVALIDREQURI);
970+
status = PJSIP_EINVALIDREQURI;
971+
goto on_error;
972+
}
973+
}
950974
}
951975

952976
/* Mark call start time. */
@@ -956,9 +980,11 @@ PJ_DEF(pj_status_t) pjsua_call_make_call(pjsua_acc_id acc_id,
956980
call->res_time.sec = 0;
957981

958982
/* Create suitable Contact header unless a Contact header has been
959-
* set in the account.
983+
* set in the account or message data.
960984
*/
961-
if (acc->contact.slen) {
985+
if (msg_data && msg_data->contact_uri.slen) {
986+
contact = msg_data->contact_uri;
987+
} else if (acc->contact.slen) {
962988
contact = acc->contact;
963989
} else {
964990
status = pjsua_acc_create_uac_contact(tmp_pool, &contact,

pjsip/src/pjsua-lib/pjsua_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ PJ_DEF(pjsua_msg_data*) pjsua_msg_data_clone(pj_pool_t *pool,
178178

179179
pj_strdup(pool, &msg_data->target_uri, &rhs->target_uri);
180180
pj_strdup(pool, &msg_data->local_uri, &rhs->local_uri);
181+
pj_strdup(pool, &msg_data->contact_uri, &rhs->contact_uri);
181182

182183
pj_list_init(&msg_data->hdr_list);
183184
hdr = rhs->hdr_list.next;

pjsip/src/pjsua2/siptypes.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,9 @@ TsxStateEvent::TsxStateEvent()
742742

743743
bool SipTxOption::isEmpty() const
744744
{
745-
return (targetUri == "" && localUri == "" && headers.size() == 0 &&
746-
contentType == "" && msgBody == "" && multipartContentType.type == "" &&
745+
return (targetUri == "" && localUri == "" && contactUri == "" &&
746+
headers.size() == 0 && contentType == "" && msgBody == "" &&
747+
multipartContentType.type == "" &&
747748
multipartContentType.subType == "" && multipartParts.size() == 0);
748749
}
749750

@@ -753,6 +754,8 @@ void SipTxOption::fromPj(const pjsua_msg_data &prm) PJSUA2_THROW(Error)
753754

754755
localUri = pj2Str(prm.local_uri);
755756

757+
contactUri = pj2Str(prm.contact_uri);
758+
756759
headers.clear();
757760
pjsip_hdr* pj_hdr = prm.hdr_list.next;
758761
while (pj_hdr != &prm.hdr_list) {
@@ -786,6 +789,8 @@ void SipTxOption::toPj(pjsua_msg_data &msg_data) const
786789

787790
msg_data.local_uri = str2Pj(localUri);
788791

792+
msg_data.contact_uri = str2Pj(contactUri);
793+
789794
pj_list_init(&msg_data.hdr_list);
790795
for (i = 0; i < headers.size(); i++) {
791796
pjsip_generic_string_hdr& pj_hdr = headers[i].toPj();

0 commit comments

Comments
 (0)