Module: kamailio
Branch: master
Commit: 0d14ce8bf45ada579f7ec85793d358a5fa32e4b7
URL:
https://github.com/kamailio/kamailio/commit/0d14ce8bf45ada579f7ec85793d358a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-09-19T09:03:10+02:00
nathelper: exported fix_nated_sdp() variants to KEMI framework
---
Modified: src/modules/nathelper/nathelper.c
---
Diff:
https://github.com/kamailio/kamailio/commit/0d14ce8bf45ada579f7ec85793d358a…
Patch:
https://github.com/kamailio/kamailio/commit/0d14ce8bf45ada579f7ec85793d358a…
---
diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c
index b9d9d622b3..44badb90fb 100644
--- a/src/modules/nathelper/nathelper.c
+++ b/src/modules/nathelper/nathelper.c
@@ -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;
@@ -1631,7 +1621,7 @@ 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;
@@ -1639,7 +1629,7 @@ static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char
*str2)
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;
@@ -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;
@@ -2432,6 +2444,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 } }
};