Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
sorooshm78 committed Dec 24, 2024
1 parent 7cc2ab1 commit add6352
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 45 deletions.
11 changes: 0 additions & 11 deletions pjsip/include/pjsip-ua/sip_siprec.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ 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
68 changes: 34 additions & 34 deletions pjsip/src/pjsip-ua/sip_siprec.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ static void pjsip_siprec_deinit_module(pjsip_endpoint *endpt)
}


/**
* Checks if the INVITE request is SIPREC.
*/
static 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;
}


/**
* Initialize siprec support in PJSIP.
*/
Expand Down Expand Up @@ -91,40 +125,6 @@ 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 Down

0 comments on commit add6352

Please sign in to comment.