From cbca34c67bec1ba8581a6f7d2de83a71f1fefcd3 Mon Sep 17 00:00:00 2001 From: Henning Westerholt Date: Tue, 14 Sep 2021 15:39:57 +0000 Subject: [PATCH] sipt: use helper function to check for valid ISUP/ACM/CPG --- src/modules/sipt/sipt.c | 55 +++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/modules/sipt/sipt.c b/src/modules/sipt/sipt.c index e0324e3f8ad..b5e596d077d 100644 --- a/src/modules/sipt/sipt.c +++ b/src/modules/sipt/sipt.c @@ -264,6 +264,25 @@ static inline int sipt_check_IAM(struct sip_msg *msg, str *body) return 1; } +static inline int sipt_check_ACM_CPG(struct sip_msg *msg, str *body) +{ + body->s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP, &body->len); + + if(body->s == NULL) + { + LM_INFO("No ISUP Message Found"); + return -1; + } + + if((body->s[0] != ISUP_ACM) && (body->s[0] != ISUP_CPG)) + { + LM_DBG("message not an ACM or CPG\n"); + return -1; + } + return 1; +} + + static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str body; @@ -353,17 +372,9 @@ static int sipt_get_calling_party(struct sip_msg *msg, pv_param_t *param, pv_val static int sipt_get_redirection_info(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str body; - body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len); - - if(body.s == NULL) - { - LM_INFO("No ISUP Message Found"); - return -1; - } - - if((body.s[0] != ISUP_ACM) && (body.s[0] != ISUP_CPG)) + if(sipt_check_ACM_CPG(msg, &body) != 1) { - LM_DBG("message not an ACM or CPG\n"); + LM_INFO("could not check ACM or CPG\n"); return -1; } @@ -374,17 +385,9 @@ static int sipt_get_redirection_info(struct sip_msg *msg, pv_param_t *param, pv_ static int sipt_get_redirection_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { str body; - body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len); - - if(body.s == NULL) - { - LM_INFO("No ISUP Message Found"); - return -1; - } - - if((body.s[0] != ISUP_ACM) && (body.s[0] != ISUP_CPG)) + if(sipt_check_ACM_CPG(msg, &body) != 1) { - LM_DBG("message not an ACM or CPG\n"); + LM_INFO("could not check ACM or CPG\n"); return -1; } @@ -396,18 +399,10 @@ static int sipt_get_redirection_number(struct sip_msg *msg, pv_param_t *param, p { static char sb_s_buf[26]; str body; - body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len); - memset(sb_s_buf, 0, 26); - if(body.s == NULL) + if(sipt_check_ACM_CPG(msg, &body) != 1) { - LM_INFO("No ISUP Message Found"); - return -1; - } - - if((body.s[0] != ISUP_ACM) && (body.s[0] != ISUP_CPG)) - { - LM_DBG("message not an ACM or CPG\n"); + LM_INFO("could not check ACM or CPG\n"); return -1; }