[asterisk-commits] kmoore: branch kmoore/pimp_sip_srtp r386337 - in /team/kmoore/pimp_sip_srtp: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 23 09:46:55 CDT 2013


Author: kmoore
Date: Tue Apr 23 09:46:51 2013
New Revision: 386337

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386337
Log:
Do some cleanup to reduce unnecessary string manipulation

Modified:
    team/kmoore/pimp_sip_srtp/channels/chan_sip.c
    team/kmoore/pimp_sip_srtp/include/asterisk/sdp_srtp.h
    team/kmoore/pimp_sip_srtp/main/sdp_srtp.c
    team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c

Modified: team/kmoore/pimp_sip_srtp/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/channels/chan_sip.c?view=diff&rev=386337&r1=386336&r2=386337
==============================================================================
--- team/kmoore/pimp_sip_srtp/channels/chan_sip.c (original)
+++ team/kmoore/pimp_sip_srtp/channels/chan_sip.c Tue Apr 23 09:46:51 2013
@@ -12990,6 +12990,15 @@
 	}
 }
 
+static char *crypto_get_attrib(struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32)
+{
+	char *a_crypto;
+	if (ast_asprintf(&a_crypto, "a=crypto:%s\r\n", ast_sdp_srtp_get_attrib(srtp, dtls_enabled, default_taglen_32)) == -1) {
+		return NULL;
+	}
+	return a_crypto;
+}
+
 /*! \brief Add Session Description Protocol message
 
     If oldsdp is TRUE, then the SDP version number is not incremented. This mechanism
@@ -13028,9 +13037,9 @@
 	struct ast_str *a_video = ast_str_create(256); /* Attributes for video */
 	struct ast_str *a_text = ast_str_create(256);  /* Attributes for text */
 	struct ast_str *a_modem = ast_str_alloca(1024); /* Attributes for modem */
-	const char *a_crypto = NULL;
-	const char *v_a_crypto = NULL;
-	const char *t_a_crypto = NULL;
+	RAII_VAR(const char *, a_crypto, NULL, ast_free);
+	RAII_VAR(const char *, v_a_crypto, NULL, ast_free);
+	RAII_VAR(const char *, t_a_crypto, NULL, ast_free);
 
 	int x;
 	struct ast_format tmp_fmt;
@@ -13148,7 +13157,7 @@
 		/* Ok, we need video. Let's add what we need for video and set codecs.
 		   Video is handled differently than audio since we can not transcode. */
 		if (needvideo) {
-			v_a_crypto = ast_sdp_srtp_get_attrib(p->vsrtp, p->dtls_cfg.enabled,
+			v_a_crypto = crypto_get_attrib(p->vsrtp, p->dtls_cfg.enabled,
 				ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_TAG_32));
 			ast_str_append(&m_video, 0, "m=video %d %s", ast_sockaddr_port(&vdest),
 				ast_sdp_get_rtp_profile(v_a_crypto ? 1 : 0, p->vrtp,
@@ -13175,7 +13184,7 @@
 		if (needtext) {
 			if (sipdebug_text)
 				ast_verbose("Lets set up the text sdp\n");
-			t_a_crypto = ast_sdp_srtp_get_attrib(p->tsrtp, p->dtls_cfg.enabled,
+			t_a_crypto = crypto_get_attrib(p->tsrtp, p->dtls_cfg.enabled,
 				ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_TAG_32));
 			ast_str_append(&m_text, 0, "m=text %d %s", ast_sockaddr_port(&tdest),
 				ast_sdp_get_rtp_profile(t_a_crypto ? 1 : 0, p->trtp,
@@ -13198,7 +13207,7 @@
 		/* We break with the "recommendation" and send our IP, in order that our
 		   peer doesn't have to ast_gethostbyname() us */
 
-		a_crypto = ast_sdp_srtp_get_attrib(p->srtp, p->dtls_cfg.enabled,
+		a_crypto = crypto_get_attrib(p->srtp, p->dtls_cfg.enabled,
 			ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_TAG_32));
 		ast_str_append(&m_audio, 0, "m=audio %d %s", ast_sockaddr_port(&dest),
 			ast_sdp_get_rtp_profile(a_crypto ? 1 : 0, p->rtp,

Modified: team/kmoore/pimp_sip_srtp/include/asterisk/sdp_srtp.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/include/asterisk/sdp_srtp.h?view=diff&rev=386337&r1=386336&r2=386337
==============================================================================
--- team/kmoore/pimp_sip_srtp/include/asterisk/sdp_srtp.h (original)
+++ team/kmoore/pimp_sip_srtp/include/asterisk/sdp_srtp.h Tue Apr 23 09:46:51 2013
@@ -73,6 +73,8 @@
 /*! \brief Parse the a=crypto line from SDP and set appropriate values on the
  * ast_sdp_crypto struct.
  *
+ * The attribute line should already have "a=crypto:" removed.
+ *
  * \param p A valid ast_sdp_crypto struct
  * \param attr the a:crypto line from SDP
  * \param rtp The rtp instance associated with the SDP being parsed
@@ -99,6 +101,9 @@
 
 /*! \brief Get the crypto attribute line for the srtp structure
  *
+ * The attribute line does not contain the initial "a=crypto:" and does
+ * not terminate with "\r\n".
+ *
  * \param srtp The ast_sdp_srtp structure for which to get an attribute line
  * \param dtls_enabled Whether this connection is encrypted with datagram TLS
  * \param default_taglen_32 Whether to default to a tag length of 32 instead of 80

Modified: team/kmoore/pimp_sip_srtp/main/sdp_srtp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/main/sdp_srtp.c?view=diff&rev=386337&r1=386336&r2=386337
==============================================================================
--- team/kmoore/pimp_sip_srtp/main/sdp_srtp.c (original)
+++ team/kmoore/pimp_sip_srtp/main/sdp_srtp.c Tue Apr 23 09:46:51 2013
@@ -326,7 +326,7 @@
 		ast_free(p->a_crypto);
 	}
 
-	if (ast_asprintf(&p->a_crypto, "a=crypto:%s AES_CM_128_HMAC_SHA1_%i inline:%s\r\n",
+	if (ast_asprintf(&p->a_crypto, "%s AES_CM_128_HMAC_SHA1_%i inline:%s",
 			 p->tag ? p->tag : "1", taglen, p->local_key64) == -1) {
 			ast_log(LOG_ERROR, "Could not allocate memory for crypto line\n");
 		return -1;

Modified: team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c?view=diff&rev=386337&r1=386336&r2=386337
==============================================================================
--- team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c (original)
+++ team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c Tue Apr 23 09:46:51 2013
@@ -594,25 +594,17 @@
 {
 	pj_str_t stmp;
 	pjmedia_sdp_attr *attr;
-	int crypto_len;
-	char *crypto_attribute = ast_strdupa(ast_sdp_srtp_get_attrib(&session_media->srtp,
+	const char *crypto_attribute = ast_sdp_srtp_get_attrib(&session_media->srtp,
 		0 /* DTLS can not be enabled for res_sip */,
-		0 /* don't prefer 32byte tag length */));
+		0 /* don't prefer 32byte tag length */);
 	
 	if (!crypto_attribute) {
 		/* No crypto attribute to add */
 		return -1;
 	}
-	/* skip over a=crypto: since it will be added by pjsip */
-	crypto_attribute += strlen("a=crypto:");
-
-	/* remove the trailing \r\n */
-	crypto_len = strlen(crypto_attribute);
-	crypto_attribute[crypto_len - 2] = '\0';
 
 	attr = pjmedia_sdp_attr_create(pool, "crypto", pj_cstr(&stmp, crypto_attribute));
 	media->attr[media->attr_count++] = attr;
-
 	return 0;
 }
 




More information about the asterisk-commits mailing list