From 38538726635f1b483bdb255a6fdf1631dcee6bde Mon Sep 17 00:00:00 2001 From: Soroush mohammadi Date: Thu, 12 Dec 2024 12:57:02 +0000 Subject: [PATCH] refactor code --- pjsip/include/pjsip-ua/sip_siprec.h | 9 ++++++--- pjsip/src/pjsip-ua/sip_siprec.c | 17 +++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pjsip/include/pjsip-ua/sip_siprec.h b/pjsip/include/pjsip-ua/sip_siprec.h index aeb81b626c..7ece0f8ec5 100644 --- a/pjsip/include/pjsip-ua/sip_siprec.h +++ b/pjsip/include/pjsip-ua/sip_siprec.h @@ -96,10 +96,13 @@ PJ_DECL(pj_status_t) pjsip_siprec_verify_request(pjsip_rx_data *rdata, * @param pool Pool to allocate memory. * @param body The message body. * @param metadata The siprec metadata + * + * @return Return PJ_SUCCESS if metadata exists. */ -PJ_DECL(void) pjsip_siprec_find_metadata(pj_pool_t *pool, - pjsip_msg_body *body, - pj_str_t* metadata); + +PJ_DECL(pj_status_t) pjsip_siprec_get_metadata(pj_pool_t *pool, + pjsip_msg_body *body, + pj_str_t* metadata); PJ_END_DECL diff --git a/pjsip/src/pjsip-ua/sip_siprec.c b/pjsip/src/pjsip-ua/sip_siprec.c index cb4c22acf8..ce6d478297 100644 --- a/pjsip/src/pjsip-ua/sip_siprec.c +++ b/pjsip/src/pjsip-ua/sip_siprec.c @@ -152,11 +152,11 @@ PJ_DEF(pj_status_t) pjsip_siprec_verify_request(pjsip_rx_data *rdata, goto on_return; } - pjsip_siprec_find_metadata(rdata->tp_info.pool, - rdata->msg_info.msg->body, - metadata); + status = pjsip_siprec_get_metadata(rdata->tp_info.pool, + rdata->msg_info.msg->body, + metadata); - if(metadata->ptr == NULL || metadata->slen == 0) { + if(status != PJ_SUCCESS) { code = PJSIP_SC_BAD_REQUEST; warn_text = "SIPREC INVITE must have a 'rs-metadata+xml' Content-Type"; goto on_return; @@ -225,7 +225,7 @@ PJ_DEF(pj_status_t) pjsip_siprec_verify_request(pjsip_rx_data *rdata, /** * Find siprec metadata from the message body */ -PJ_DEF(void) pjsip_siprec_find_metadata(pj_pool_t *pool, +PJ_DEF(pj_status_t) pjsip_siprec_get_metadata(pj_pool_t *pool, pjsip_msg_body *body, pj_str_t* metadata) { @@ -236,10 +236,11 @@ PJ_DEF(void) pjsip_siprec_find_metadata(pj_pool_t *pool, pjsip_multipart_part *metadata_part; metadata_part = pjsip_multipart_find_part(body, &application_metadata, NULL); - if(!metadata_part) { - return; - } + if(!metadata_part) + return PJ_ENOTFOUND; metadata->ptr = (char*)metadata_part->body->data; metadata->slen = metadata_part->body->len; + + return PJ_SUCCESS; }