[sr-dev] git:master:2d68418a: msrp: use formated string instead of complex sequence of concatenation

Daniel-Constantin Mierla miconda at gmail.com
Thu Jul 27 13:14:32 CEST 2017


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-27T13:09:02+02:00

msrp: use formated string instead of complex sequence of concatenation

---

Modified: src/modules/msrp/msrp_cmap.c

---

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

---

diff --git a/src/modules/msrp/msrp_cmap.c b/src/modules/msrp/msrp_cmap.c
index 3648df41b9..bdcccbd6fe 100644
--- a/src/modules/msrp/msrp_cmap.c
+++ b/src/modules/msrp/msrp_cmap.c
@@ -210,20 +210,16 @@ int msrp_cmap_save(msrp_frame_t *mf)
 	hid = msrp_get_hashid(&_msrp_sruid.uid);	
 	idx = msrp_get_slot(hid, _msrp_cmap_head->mapsize);
 
-	srcaddr.s = sbuf;
-	if (msrp_tls_module_loaded)
-	{
-		memcpy(srcaddr.s, "msrps://", 8);
-		srcaddr.s+=8;
-	} else {
-		memcpy(srcaddr.s, "msrp://", 7);
-		srcaddr.s+=7;
+	srcaddr.len = snprintf(sbuf, MSRP_SBUF_SIZE, "msrp%s://%s:%d",
+						(msrp_tls_module_loaded)?"s":"",
+						ip_addr2a(&mf->tcpinfo->rcv->src_ip),
+						(int)mf->tcpinfo->rcv->src_port);
+	if(srcaddr.len<0 || srcaddr.len>=MSRP_SBUF_SIZE) {
+		LM_ERR("failure or address lenght too big (%d)\n", srcaddr.len);
+		return -1;
 	}
-	strcpy(srcaddr.s, ip_addr2a(&mf->tcpinfo->rcv->src_ip));
-	strcat(srcaddr.s, ":");
-	strcat(srcaddr.s, int2str(mf->tcpinfo->rcv->src_port, NULL));
 	srcaddr.s = sbuf;
-	srcaddr.len = strlen(srcaddr.s);
+
 	srcsock = mf->tcpinfo->rcv->bind_address->sock_str;
 	LM_DBG("saving connection info for [%.*s] [%.*s] (%u/%u)\n",
 			fpeer.len, fpeer.s, _msrp_sruid.uid.len, _msrp_sruid.uid.s,




More information about the sr-dev mailing list