Skip to content

Commit

Permalink
add enable/disable siprec option
Browse files Browse the repository at this point in the history
  • Loading branch information
sorooshm78 committed Dec 22, 2024
1 parent 19239c3 commit 1bede37
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 28 deletions.
13 changes: 9 additions & 4 deletions pjsip/include/pjsip-ua/sip_inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,19 @@ enum pjsip_inv_option
PJSIP_INV_REQUIRE_TRICKLE_ICE = 512,

/**
* Indicate support for siprec
* Require siprec support.
*/
PJSIP_INV_SUPPORT_SIPREC = 1024,
PJSIP_INV_REQUIRE_SIPREC = 1024,

/**
* Require siprec support.
* Indicate support for siprec
*/
PJSIP_INV_SUPPORT_SIPREC = 2048,

/**
* Indicate not support for siprec
*/
PJSIP_INV_REQUIRE_SIPREC = 2048,
PJSIP_INV_NOT_SUPPORT_SIPREC = 4096,
};

/* Forward declaration of Session Timers */
Expand Down
11 changes: 11 additions & 0 deletions pjsip/include/pjsip-ua/sip_siprec.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ PJ_DECL(pj_status_t)
pjsip_siprec_verify_require_hdr(pjsip_require_hdr *req_hdr);


/**
* Checks if the INVITE request is SIPREC.
*
* @param rdata The incoming request to be verified.
*
* @return If the request is SIPREC, return PJ_TRUE;
* otherwise, return PJ_FALSE.
*/
PJ_DECL(pj_status_t) pjsip_siprec_check_request(pjsip_rx_data *rdata);


/**
* Verifies that the incoming request has the siprec value
* in the Require header and "+sip.src" parameter exist in the Contact header.
Expand Down
31 changes: 31 additions & 0 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,32 @@ typedef enum pjsua_sip_timer_use
} pjsua_sip_timer_use;


/**
* This enumeration specifies the usage of SIPREC extension.
*/
typedef enum pjsua_sip_siprec_use
{
/**
* When this flag is specified, when a SIPREC request is received, it
* returns bad extension error. and SIPREC calls will not be established.
*/
PJSUA_SIP_SIPREC_INACTIVE,

/**
* When this flag is specified, when you want both regular calls and
* SIPREC calls to be established.
*/
PJSUA_SIP_SIPREC_OPTIONAL,

/**
* When this flag is specified, when you want only SIPREC calls to
* be established, and regular calls are rejected.
*/
PJSUA_SIP_SIPREC_MANDATORY,

} pjsua_sip_siprec_use;


/**
* This constants controls the use of 100rel extension.
*/
Expand Down Expand Up @@ -2343,6 +2369,9 @@ typedef struct pjsua_config
*/
pjsua_sip_timer_use use_timer;


pjsua_sip_siprec_use use_siprec;

/**
* Handle unsolicited NOTIFY requests containing message waiting
* indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests
Expand Down Expand Up @@ -4065,6 +4094,8 @@ typedef struct pjsua_acc_config
*/
pjsua_sip_timer_use use_timer;

pjsua_sip_siprec_use use_siprec;

/**
* Specify Session Timer settings, see #pjsip_timer_setting.
*/
Expand Down
8 changes: 8 additions & 0 deletions pjsip/include/pjsua2/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ struct AccountCallConfig : public PersistentObject
*/
pjsua_sip_timer_use timerUse;

/**
* Specify the usage of SIPREC INVITE request. See the
* pjsua_sip_siprec_use for possible values.
*
* Default: PJSUA_SIP_SIPREC_INACTIVE
*/
pjsua_sip_siprec_use siprecUse;

/**
* Specify minimum Session Timer expiration period, in seconds.
* Must not be lower than 90. Default is 90.
Expand Down
6 changes: 3 additions & 3 deletions pjsip/src/pjsip-ua/sip_inv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1543,11 +1543,11 @@ PJ_DEF(pj_status_t) pjsip_inv_verify_request3(pjsip_rx_data *rdata,
{
rem_option |= PJSIP_INV_REQUIRE_100REL;

} else if ((*options & PJSIP_INV_SUPPORT_SIPREC) &&
} else if ((*options & PJSIP_INV_NOT_SUPPORT_SIPREC) &&
pj_stricmp(&req_hdr->values[i], &STR_SIPREC)==0)
{
rem_option |= PJSIP_INV_REQUIRE_SIPREC;

unsupp_tags[unsupp_cnt++] = req_hdr->values[i];
} else if ((*options & PJSIP_INV_SUPPORT_TIMER) &&
pj_stricmp(&req_hdr->values[i], &STR_TIMER)==0)
{
Expand Down
67 changes: 47 additions & 20 deletions pjsip/src/pjsip-ua/sip_siprec.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,40 @@ PJ_DEF(pj_status_t) pjsip_siprec_verify_require_hdr(pjsip_require_hdr *req_hdr)
}


/**
* Checks if the INVITE request is SIPREC.
*/
PJ_DEF(pj_status_t) pjsip_siprec_check_request(pjsip_rx_data *rdata)
{
const pj_str_t str_require = {"Require", 7};
const pj_str_t str_src = {"+sip.src", 8};
pjsip_require_hdr *req_hdr;
pjsip_contact_hdr *contact_hdr;

/* Find Require header */
req_hdr = (pjsip_require_hdr*)
pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_require, NULL);

if(!req_hdr || (pjsip_siprec_verify_require_hdr(req_hdr) == PJ_FALSE)){
return PJ_FALSE;
}

/* Find Contact header */
contact_hdr = (pjsip_contact_hdr*)
pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);

if(!contact_hdr || !contact_hdr->uri){
return PJ_FALSE;
}

/* Check "+sip.src" parameter exist in the Contact header */
if(!pjsip_param_find(&contact_hdr->other_param, &str_src)){
return PJ_FALSE;
}
return PJ_TRUE;
}


/**
* Verifies that the incoming request is a siprec request or not.
*/
Expand All @@ -102,10 +136,6 @@ PJ_DEF(pj_status_t) pjsip_siprec_verify_request(pjsip_rx_data *rdata,
pjsip_endpoint *endpt,
pjsip_tx_data **p_tdata)
{
pjsip_require_hdr *req_hdr;
pjsip_contact_hdr *contact_hdr;
const pj_str_t str_require = {"Require", 7};
const pj_str_t str_src = {"+sip.src", 8};
int code = 200;
pj_status_t status = PJ_SUCCESS;
const char *warn_text = NULL;
Expand All @@ -118,25 +148,22 @@ PJ_DEF(pj_status_t) pjsip_siprec_verify_request(pjsip_rx_data *rdata,
/* Init response header list */
pj_list_init(&res_hdr_list);

/* Find Require header */
req_hdr = (pjsip_require_hdr*)
pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_require, NULL);

if(!req_hdr || (pjsip_siprec_verify_require_hdr(req_hdr) == PJ_FALSE)){
return PJ_SUCCESS;
}

/* Find Contact header */
contact_hdr = (pjsip_contact_hdr*)
pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);

if(!contact_hdr || !contact_hdr->uri){
/* Checks if The SIPREC request option is inactive */
if (*options & PJSIP_INV_NOT_SUPPORT_SIPREC){
return PJ_SUCCESS;
}

/* Check "+sip.src" parameter exist in the Contact header */
if(!pjsip_param_find(&contact_hdr->other_param, &str_src)){
return PJ_SUCCESS;
/* Checks if the INVITE request is SIPREC */
if (pjsip_siprec_check_request(rdata) == PJ_FALSE){
/* The SIPREC request option is mandatory */
if (*options & PJSIP_INV_REQUIRE_SIPREC){
code = PJSIP_SC_BAD_REQUEST;
warn_text = "The INVITE request must be SIPREC";
goto on_return;
}else {
/* The SIPREC request option is optional */
return PJ_SUCCESS;
}
}

/* Checks if the body exists */
Expand Down
3 changes: 3 additions & 0 deletions pjsip/src/pjsua-lib/pjsua_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,9 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id,
acc->cfg.use_timer = cfg->use_timer;
acc->cfg.timer_setting = cfg->timer_setting;

/* SIPREC */
acc->cfg.use_siprec = cfg->use_siprec;

/* Transport */
if (acc->cfg.transport_id != cfg->transport_id) {
pjsua_acc_set_transport(acc_id, cfg->transport_id);
Expand Down
10 changes: 9 additions & 1 deletion pjsip/src/pjsua-lib/pjsua_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,15 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata)
/* Verify that we can handle the request. */
options |= PJSIP_INV_SUPPORT_100REL;
options |= PJSIP_INV_SUPPORT_TIMER;
options |= PJSIP_INV_SUPPORT_SIPREC;

if(pjsua_var.acc[acc_id].cfg.use_siprec == PJSUA_SIP_SIPREC_INACTIVE){
options |= PJSIP_INV_NOT_SUPPORT_SIPREC;
}else{
options |= PJSIP_INV_SUPPORT_SIPREC;
if(pjsua_var.acc[acc_id].cfg.use_siprec == PJSUA_SIP_SIPREC_MANDATORY){
options |= PJSIP_INV_REQUIRE_SIPREC;
}
}

/* Check if the INVITE request is a siprec
* this function add PJSIP_INV_REQUIRE_SIPREC to options
Expand Down
2 changes: 2 additions & 0 deletions pjsip/src/pjsua-lib/pjsua_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ PJ_DEF(void) pjsua_config_default(pjsua_config *cfg)
cfg->hangup_forked_call = PJ_TRUE;

cfg->use_timer = PJSUA_SIP_TIMER_OPTIONAL;
cfg->use_siprec = PJSUA_SIP_SIPREC_INACTIVE;
pjsip_timer_setting_default(&cfg->timer_setting);
pjsua_srtp_opt_default(&cfg->srtp_opt);
}
Expand Down Expand Up @@ -335,6 +336,7 @@ PJ_DEF(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
cfg->require_100rel = pjsua_var.ua_cfg.require_100rel;
cfg->use_timer = pjsua_var.ua_cfg.use_timer;
cfg->timer_setting = pjsua_var.ua_cfg.timer_setting;
cfg->use_siprec = pjsua_var.ua_cfg.use_siprec;
cfg->lock_codec = 1;
cfg->ka_interval = 15;
cfg->ka_data = pj_str("\r\n");
Expand Down
2 changes: 2 additions & 0 deletions pjsip/src/pjsua2/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ void AccountConfig::toPj(pjsua_acc_config &ret) const
ret.call_hold_type = callConfig.holdType;
ret.require_100rel = callConfig.prackUse;
ret.use_timer = callConfig.timerUse;
ret.use_siprec = callConfig.siprecUse;
ret.timer_setting.min_se = callConfig.timerMinSESec;
ret.timer_setting.sess_expires = callConfig.timerSessExpiresSec;

Expand Down Expand Up @@ -797,6 +798,7 @@ void AccountConfig::fromPj(const pjsua_acc_config &prm,
callConfig.holdType = prm.call_hold_type;
callConfig.prackUse = prm.require_100rel;
callConfig.timerUse = prm.use_timer;
callConfig.siprecUse = prm.use_siprec;
callConfig.timerMinSESec = prm.timer_setting.min_se;
callConfig.timerSessExpiresSec = prm.timer_setting.sess_expires;

Expand Down

0 comments on commit 1bede37

Please sign in to comment.