Skip to content

Commit

Permalink
nathelper: exported fix_nated_sdp() variants to KEMI framework
Browse files Browse the repository at this point in the history
(cherry picked from commit 0d14ce8)
  • Loading branch information
miconda committed Oct 1, 2018
1 parent 592438a commit 514b2eb
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions src/modules/nathelper/nathelper.c
Expand Up @@ -1548,25 +1548,15 @@ static inline int replace_sdp_ip(
return count;
}

static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)
static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip)
{
str body;
str ip;
int level, rest_len;
int rest_len;
char *buf, *m_start, *m_end;
struct lump *anchor;
int ret;
int count = 0;

if(fixup_get_ivalue(msg, (gparam_t *)str1, &level) != 0) {
LM_ERR("failed to get value for first parameter\n");
return -1;
}
if(str2 && fixup_get_svalue(msg, (gparam_t *)str2, &ip) != 0) {
LM_ERR("failed to get value for second parameter\n");
return -1;
}

if(extract_body(msg, &body) == -1) {
LM_ERR("cannot extract body from msg!\n");
return -1;
Expand Down Expand Up @@ -1631,15 +1621,15 @@ static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)

if(level & FIX_MEDIP) {
/* Iterate all c= and replace ips in them. */
ret = replace_sdp_ip(msg, &body, "c=", str2 ? &ip : 0);
ret = replace_sdp_ip(msg, &body, "c=", (ip && ip->len>0) ? ip : 0);
if(ret == -1)
return -1;
count += ret;
}

if(level & FIX_ORGIP) {
/* Iterate all o= and replace ips in them. */
ret = replace_sdp_ip(msg, &body, "o=", str2 ? &ip : 0);
ret = replace_sdp_ip(msg, &body, "o=", (ip && ip->len>0) ? ip : 0);
if(ret == -1)
return -1;
count += ret;
Expand All @@ -1648,6 +1638,28 @@ static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)
return count > 0 ? 1 : 2;
}

static int ki_fix_nated_sdp(sip_msg_t *msg, int level)
{
return ki_fix_nated_sdp_ip(msg, level, NULL);
}

static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)
{
int level;
str ip;

if(fixup_get_ivalue(msg, (gparam_t *)str1, &level) != 0) {
LM_ERR("failed to get value for first parameter\n");
return -1;
}
if(str2 && fixup_get_svalue(msg, (gparam_t *)str2, &ip) != 0) {
LM_ERR("failed to get value for second parameter\n");
return -1;
}

return ki_fix_nated_sdp_ip(msg, level, &ip);
}

static int extract_mediaip(str *body, str *mediaip, int *pf, char *line)
{
char *cp, *cp1;
Expand Down Expand Up @@ -2425,6 +2437,16 @@ static sr_kemi_t sr_kemi_nathelper_exports[] = {
{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("nathelper"), str_init("fix_nated_sdp"),
SR_KEMIP_INT, ki_fix_nated_sdp,
{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("nathelper"), str_init("fix_nated_sdp_ip"),
SR_KEMIP_INT, ki_fix_nated_sdp_ip,
{ SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},

{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};
Expand Down

0 comments on commit 514b2eb

Please sign in to comment.