[sr-dev] git:master:2ffdcf7f: nat_traversal: use core string handling instead of redundant implementation

Henning Westerholt hw at skalatan.de
Sat Nov 23 23:23:34 CET 2019


Module: kamailio
Branch: master
Commit: 2ffdcf7fa13b1450a606d135d479dbf2b8d67bd3
URL: https://github.com/kamailio/kamailio/commit/2ffdcf7fa13b1450a606d135d479dbf2b8d67bd3

Author: Henning Westerholt <hw at skalatan.de>
Committer: Henning Westerholt <hw at skalatan.de>
Date: 2019-11-23T23:01:06+01:00

nat_traversal:  use core string handling instead of redundant implementation

---

Modified: src/modules/nat_traversal/nat_traversal.c

---

Diff:  https://github.com/kamailio/kamailio/commit/2ffdcf7fa13b1450a606d135d479dbf2b8d67bd3.diff
Patch: https://github.com/kamailio/kamailio/commit/2ffdcf7fa13b1450a606d135d479dbf2b8d67bd3.patch

---

diff --git a/src/modules/nat_traversal/nat_traversal.c b/src/modules/nat_traversal/nat_traversal.c
index 4ad12674db..7bf0ae8c02 100644
--- a/src/modules/nat_traversal/nat_traversal.c
+++ b/src/modules/nat_traversal/nat_traversal.c
@@ -51,6 +51,7 @@
 #include "../../core/lock_ops.h"
 #include "../../core/dprint.h"
 #include "../../core/str.h"
+#include "../../core/ut.h"
 #include "../../core/pvar.h"
 #include "../../core/error.h"
 #include "../../core/timer.h"
@@ -213,8 +214,6 @@ static bool test_private_contact(struct sip_msg *msg);
 static bool test_source_address(struct sip_msg *msg);
 static bool test_private_via(struct sip_msg *msg);
 
-static INLINE char *shm_strdup(char *source);
-
 static int mod_init(void);
 static int child_init(int rank);
 static void mod_destroy(void);
@@ -436,7 +435,7 @@ static NAT_Contact *NAT_Contact_new(char *uri, struct socket_info *socket)
 	}
 	memset(contact, 0, sizeof(NAT_Contact));
 
-	contact->uri = shm_strdup(uri);
+	contact->uri = shm_char_dup(uri);
 	if(!contact->uri) {
 		LM_ERR("out of memory while creating new NAT_Contact structure\n");
 		shm_free(contact);
@@ -714,7 +713,7 @@ static bool Dialog_Param_add_candidate(Dialog_Param *param, char *candidate)
 		param->callee_candidates.size = new_size;
 	}
 
-	new_candidate = shm_strdup(candidate);
+	new_candidate = shm_char_dup(candidate);
 	if(!new_candidate) {
 		LM_ERR("cannot allocate shared memory for new candidate uri\n");
 		return false;
@@ -759,23 +758,6 @@ static INLINE void trim(str *string)
 	rtrim(string);
 }
 
-
-static INLINE char *shm_strdup(char *source)
-{
-	char *copy;
-
-	if(!source)
-		return NULL;
-
-	copy = (char *)shm_malloc(strlen(source) + 1);
-	if(!copy)
-		return NULL;
-	strcpy(copy, source);
-
-	return copy;
-}
-
-
 static bool get_contact_uri(
 		struct sip_msg *msg, struct sip_uri *uri, contact_t **_c)
 {
@@ -1142,7 +1124,7 @@ static void __dialog_confirmed(
 		// free old uri in case this callback is called more than once (shouldn't normally happen)
 		if(param->callee_uri)
 			shm_free(param->callee_uri);
-		param->callee_uri = shm_strdup(callee_uri);
+		param->callee_uri = shm_char_dup(callee_uri);
 		if(!param->callee_uri) {
 			LM_ERR("cannot allocate shared memory for callee_uri in dialog "
 				   "param\n");
@@ -1277,7 +1259,7 @@ static void __dialog_created(
 		return;
 
 	uri = get_source_uri(request);
-	param->caller_uri = shm_strdup(uri);
+	param->caller_uri = shm_char_dup(uri);
 	if(!param->caller_uri) {
 		LM_ERR("cannot allocate shared memory for caller_uri in dialog "
 			   "param\n");




More information about the sr-dev mailing list