Browse Source

nathelper: exported fix_nated_sdp() variants to KEMI framework

Daniel-Constantin Mierla 7 years ago
parent
commit
0d14ce8bf4
1 changed files with 36 additions and 14 deletions
  1. 36 14
      src/modules/nathelper/nathelper.c

+ 36 - 14
src/modules/nathelper/nathelper.c

@@ -1548,25 +1548,15 @@ static inline int replace_sdp_ip(
 	return count;
 	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 body;
-	str ip;
-	int level, rest_len;
+	int rest_len;
 	char *buf, *m_start, *m_end;
 	char *buf, *m_start, *m_end;
 	struct lump *anchor;
 	struct lump *anchor;
 	int ret;
 	int ret;
 	int count = 0;
 	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) {
 	if(extract_body(msg, &body) == -1) {
 		LM_ERR("cannot extract body from msg!\n");
 		LM_ERR("cannot extract body from msg!\n");
 		return -1;
 		return -1;
@@ -1631,7 +1621,7 @@ static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)
 
 
 	if(level & FIX_MEDIP) {
 	if(level & FIX_MEDIP) {
 		/* Iterate all c= and replace ips in them. */
 		/* 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)
 		if(ret == -1)
 			return -1;
 			return -1;
 		count += ret;
 		count += ret;
@@ -1639,7 +1629,7 @@ static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)
 
 
 	if(level & FIX_ORGIP) {
 	if(level & FIX_ORGIP) {
 		/* Iterate all o= and replace ips in them. */
 		/* 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)
 		if(ret == -1)
 			return -1;
 			return -1;
 		count += ret;
 		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;
 	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)
 static int extract_mediaip(str *body, str *mediaip, int *pf, char *line)
 {
 {
 	char *cp, *cp1;
 	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_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, 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 } }
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };
 };