[asterisk-commits] twilson: branch group/srtp r166096 - in /team/group/srtp: channels/ include/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 19 16:48:52 CST 2008


Author: twilson
Date: Fri Dec 19 16:48:52 2008
New Revision: 166096

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166096
Log:
More cleanup work

Modified:
    team/group/srtp/channels/sdp_crypto.h
    team/group/srtp/channels/sdp_mikey.h
    team/group/srtp/include/asterisk/rtp.h
    team/group/srtp/main/rtp.c
    team/group/srtp/res/mikey.h
    team/group/srtp/res/res_mikey.c

Modified: team/group/srtp/channels/sdp_crypto.h
URL: http://svn.digium.com/view/asterisk/team/group/srtp/channels/sdp_crypto.h?view=diff&rev=166096&r1=166095&r2=166096
==============================================================================
--- team/group/srtp/channels/sdp_crypto.h (original)
+++ team/group/srtp/channels/sdp_crypto.h Fri Dec 19 16:48:52 2008
@@ -19,9 +19,9 @@
 /*! \file sdp_crypto.h
  *
  * \brief SDP Security descriptions
- * 
+ *
  * Specified in RFC 4568
- * 
+ *
  * \author Mikael Magnusson <mikma at users.sourceforge.net>
  */
 
@@ -35,11 +35,7 @@
 struct sdp_crypto *sdp_crypto_setup(void);
 void sdp_crypto_destroy(struct sdp_crypto *crypto);
 
-/* int sdp_crypto_activate(struct sdp_crypto *p, int suite_val, */
-/* 			       unsigned char *remote_key, */
-/* 			       struct ast_rtp *rtp); */
-int sdp_crypto_process(struct sdp_crypto *p, const char *attr,
-		       struct ast_rtp *rtp);
+int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp *rtp);
 int sdp_crypto_offer(struct sdp_crypto *p);
 const char *sdp_crypto_attrib(struct sdp_crypto *p);
 

Modified: team/group/srtp/channels/sdp_mikey.h
URL: http://svn.digium.com/view/asterisk/team/group/srtp/channels/sdp_mikey.h?view=diff&rev=166096&r1=166095&r2=166096
==============================================================================
--- team/group/srtp/channels/sdp_mikey.h (original)
+++ team/group/srtp/channels/sdp_mikey.h Fri Dec 19 16:48:52 2008
@@ -18,11 +18,11 @@
 
 /*! \file sdp_mikey.h
  *
- * \brief SDP MIKEY key management 
- * 
- * SDP MIKEY key management 
+ * \brief SDP MIKEY key management
+ *
+ * SDP MIKEY key management
  * Specified in RFC 3830 and 4567
- * 
+ *
  * \author Mikael Magnusson <mikma at users.sourceforge.net>
  */
 
@@ -36,13 +36,10 @@
 int sdp_mikey_init(void);
 void sdp_mikey_uninit(void);
 
-struct sdp_mikey *sdp_mikey_setup(const char *peersecret,
-				  struct ast_rtp *rtp);
+struct sdp_mikey *sdp_mikey_setup(const char *peersecret, struct ast_rtp *rtp);
 void sdp_mikey_destroy(struct sdp_mikey *p);
-/* int sdp_mikey_activate(struct sdp_mikey *p, struct ast_rtp *rtp); */
 int sdp_mikey_offer(struct sdp_mikey *p, struct ast_rtp *rtp);
-int sdp_mikey_process(struct sdp_mikey *p, const char *attr,
-		      struct ast_rtp *rtp);
+int sdp_mikey_process(struct sdp_mikey *p, const char *attr, struct ast_rtp *rtp);
 const char *sdp_mikey_attrib(struct sdp_mikey *p);
 
 #endif	/* _SDP_MIKEY_H */

Modified: team/group/srtp/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/team/group/srtp/include/asterisk/rtp.h?view=diff&rev=166096&r1=166095&r2=166096
==============================================================================
--- team/group/srtp/include/asterisk/rtp.h (original)
+++ team/group/srtp/include/asterisk/rtp.h Fri Dec 19 16:48:52 2008
@@ -129,12 +129,10 @@
 };
 
 struct ast_srtp_res {
-	int (*create)(struct ast_srtp **srtp, struct ast_rtp *rtp,
-		      struct ast_srtp_policy *policy);
+	int (*create)(struct ast_srtp **srtp, struct ast_rtp *rtp, struct ast_srtp_policy *policy);
 	void (*destroy)(struct ast_srtp *srtp);
 	int (*add_stream)(struct ast_srtp *srtp, struct ast_srtp_policy *policy);
-	void (*set_cb)(struct ast_srtp *srtp,
-		       const struct ast_srtp_cb *cb, void *data);
+	void (*set_cb)(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
 	int (*unprotect)(struct ast_srtp *srtp, void *buf, int *size);
 	int (*protect)(struct ast_srtp *srtp, void **buf, int *size);
 	int (*get_random)(unsigned char *key, size_t len);
@@ -160,25 +158,18 @@
 struct ast_srtp_policy_res {
 	struct ast_srtp_policy *(*alloc)(void);
 	void (*destroy)(struct ast_srtp_policy *policy);
-	int (*set_suite)(struct ast_srtp_policy *policy,
-			 enum ast_srtp_suite suite);
-	int (*set_master_key)(struct ast_srtp_policy *policy,
-			      const unsigned char *key, size_t key_len,
-			      const unsigned char *salt, size_t salt_len);
-	int (*set_encr_alg)(struct ast_srtp_policy *policy,
-			    enum ast_srtp_ealg  ealg);
-	int (*set_auth_alg)(struct ast_srtp_policy *policy,
-			    enum ast_srtp_aalg aalg);
+	int (*set_suite)(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
+	int (*set_master_key)(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len);
+	int (*set_encr_alg)(struct ast_srtp_policy *policy, enum ast_srtp_ealg  ealg);
+	int (*set_auth_alg)(struct ast_srtp_policy *policy, enum ast_srtp_aalg aalg);
 	void (*set_encr_keylen)(struct ast_srtp_policy *policy, int ekeyl);
 	void (*set_auth_keylen)(struct ast_srtp_policy *policy, int akeyl);
 	void (*set_srtp_auth_taglen)(struct ast_srtp_policy *policy, int autht);
 	void (*set_srtp_encr_enable)(struct ast_srtp_policy *policy, int enable);
 	void (*set_srtcp_encr_enable)(struct ast_srtp_policy *policy, int enable);
 	void (*set_srtp_auth_enable)(struct ast_srtp_policy *policy, int enable);
-	void (*set_ssrc)(struct ast_srtp_policy *policy, unsigned long ssrc,
-			 int inbound);
-};
-
+	void (*set_ssrc)(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
+};
 
 #define FLAG_3389_WARNING		(1 << 0)
 
@@ -377,11 +368,9 @@
 void ast_rtp_new_init(struct ast_rtp *rtp);
 
 int ast_rtp_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res);
- 
 int ast_rtp_unregister_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res);
- 
 int ast_srtp_is_registered(void);
- 
+
 unsigned int ast_rtp_get_ssrc(struct ast_rtp *rtp);
 unsigned int ast_rtp_get_themssrc(struct ast_rtp *rtp);
 void ast_rtp_set_srtp_cb(struct ast_rtp *rtp, const struct ast_srtp_cb *cb, void *data);
@@ -398,7 +387,7 @@
 void ast_srtp_policy_set_srtcp_encr_enable(struct ast_srtp_policy *policy, int enable);
 void ast_srtp_policy_set_srtp_auth_enable(struct ast_srtp_policy *policy, int enable);
 void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
- 
+
 void ast_srtp_policy_destroy(struct ast_srtp_policy *policy);
 int ast_srtp_get_random(unsigned char *key, size_t len);
 

Modified: team/group/srtp/main/rtp.c
URL: http://svn.digium.com/view/asterisk/team/group/srtp/main/rtp.c?view=diff&rev=166096&r1=166095&r2=166096
==============================================================================
--- team/group/srtp/main/rtp.c (original)
+++ team/group/srtp/main/rtp.c Fri Dec 19 16:48:52 2008
@@ -1117,8 +1117,7 @@
 }
 
 /*! \brief Register SRTP module in res_srtp to rtp core */
-int ast_rtp_register_srtp(struct ast_srtp_res *srtp_res,
-			   struct ast_srtp_policy_res *policy_res)
+int ast_rtp_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
 {
 	if (g_srtp_res || g_policy_res) {
 		ast_log(LOG_WARNING, "Unable to register SRTP\n");
@@ -1132,14 +1131,15 @@
 
 	g_srtp_res = srtp_res;
 	g_policy_res = policy_res;
+
 	return 0;
 }
 
-int ast_rtp_unregister_srtp(struct ast_srtp_res *srtp_res,
-			     struct ast_srtp_policy_res *policy_res)
+int ast_rtp_unregister_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
 {
 	g_srtp_res = NULL;
 	g_policy_res = NULL;
+
 	return 0;
 }
 
@@ -1162,16 +1162,18 @@
 void ast_rtp_set_srtp_cb(struct ast_rtp *rtp, const struct ast_srtp_cb *cb,
 			 void *data)
 {
-	if (!g_srtp_res || !rtp->srtp)
+	if (!g_srtp_res || !rtp->srtp) {
 		return;
+	}
 
 	g_srtp_res->set_cb(rtp->srtp, cb, data);
 }
 
 void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound)
 {
-	if (!g_policy_res)
+	if (!g_policy_res) {
 		return;
+	}
 
 	g_policy_res->set_ssrc(policy, ssrc, inbound);
 }
@@ -1179,9 +1181,10 @@
 int ast_rtp_add_srtp_policy(struct ast_rtp *rtp, struct ast_srtp_policy *policy)
 {
 	int res;
-	
-	if (!g_srtp_res)
+
+	if (!g_srtp_res) {
 		return -1;
+	}
 
 	if (!rtp->srtp) {
 		res = g_srtp_res->create(&rtp->srtp, rtp, policy);
@@ -1194,150 +1197,144 @@
 
 struct ast_srtp_policy *ast_srtp_policy_alloc()
 {
-	if (!g_policy_res)
+	if (!g_policy_res) {
 		return NULL;
+	}
 
 	return g_policy_res->alloc();
 }
 
 void ast_srtp_policy_destroy(struct ast_srtp_policy *policy)
 {
-	if (!g_policy_res)
+	if (!g_policy_res) {
 		return;
+	}
 
 	g_policy_res->destroy(policy);
 }
 
-int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy,
-		enum ast_srtp_suite suite)
-{
-	if (!g_policy_res)
+int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
+{
+	if (!g_policy_res) {
 		return -1;
+	}
 
 	return g_policy_res->set_suite(policy, suite);
 }
 
-int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy,
-		const unsigned char *key, size_t key_len,
-		const unsigned char *salt, size_t salt_len)
-{
-	if (!g_policy_res)
+int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len)
+{
+	if (!g_policy_res) {
 		return -1;
+	}
 
 	return g_policy_res->set_master_key(policy, key, key_len, salt, salt_len);
 }
 
-int ast_srtp_policy_set_encr_alg(struct ast_srtp_policy *policy,
-	      enum ast_srtp_ealg ealg)
-{
-	if (!g_policy_res)
+int ast_srtp_policy_set_encr_alg(struct ast_srtp_policy *policy, enum ast_srtp_ealg ealg)
+{
+	if (!g_policy_res) {
 		return -1;
+	}
 
 	return g_policy_res->set_encr_alg(policy, ealg);
 }
 
-int ast_srtp_policy_set_auth_alg(struct ast_srtp_policy *policy,
-			      enum ast_srtp_aalg aalg)
-{
-	if (!g_policy_res)
+int ast_srtp_policy_set_auth_alg(struct ast_srtp_policy *policy, enum ast_srtp_aalg aalg)
+{
+	if (!g_policy_res) {
 		return -1;
+	}
 
 	return g_policy_res->set_auth_alg(policy, aalg);
 }
 
 void ast_srtp_policy_set_encr_keylen(struct ast_srtp_policy *policy, int ekeyl)
 {
-	if (!g_policy_res)
+	if (!g_policy_res) {
 		return;
-
-	return g_policy_res->set_encr_keylen(policy, ekeyl);
-}
-
-void ast_srtp_policy_set_auth_keylen(struct ast_srtp_policy *policy,
-				 int akeyl)
-{
-	if (!g_policy_res)
+	}
+
+	g_policy_res->set_encr_keylen(policy, ekeyl);
+}
+
+void ast_srtp_policy_set_auth_keylen(struct ast_srtp_policy *policy, int akeyl)
+{
+	if (!g_policy_res) {
 		return;
-
-	return g_policy_res->set_auth_keylen(policy, akeyl);
-}
-
-void ast_srtp_policy_set_srtp_auth_taglen(struct ast_srtp_policy *policy,
-				      int autht)
-{
-	if (!g_policy_res)
+	}
+
+	g_policy_res->set_auth_keylen(policy, akeyl);
+}
+
+void ast_srtp_policy_set_srtp_auth_taglen(struct ast_srtp_policy *policy, int autht)
+{
+	if (!g_policy_res) {
 		return;
-
-	return g_policy_res->set_srtp_auth_taglen(policy, autht);
-}
-
-void ast_srtp_policy_set_srtp_encr_enable(struct ast_srtp_policy *policy,
-				      int enable)
-{
-	if (!g_policy_res)
+	}
+
+	g_policy_res->set_srtp_auth_taglen(policy, autht);
+}
+
+void ast_srtp_policy_set_srtp_encr_enable(struct ast_srtp_policy *policy, int enable)
+{
+	if (!g_policy_res) {
 		return;
-
-	return g_policy_res->set_srtp_encr_enable(policy, enable);
-}
-
-void ast_srtp_policy_set_srtcp_encr_enable(struct ast_srtp_policy *policy,
-				       int enable)
-{
-	if (!g_policy_res)
+	}
+
+	g_policy_res->set_srtp_encr_enable(policy, enable);
+}
+
+void ast_srtp_policy_set_srtcp_encr_enable(struct ast_srtp_policy *policy, int enable)
+{
+	if (!g_policy_res) {
 		return;
-
-	return g_policy_res->set_srtcp_encr_enable(policy, enable);
+	}
+
+	g_policy_res->set_srtcp_encr_enable(policy, enable);
 }
 
 void ast_srtp_policy_set_srtp_auth_enable(struct ast_srtp_policy *policy,
 				      int enable)
 {
-	if (!g_policy_res)
+	if (!g_policy_res) {
 		return;
-
-	return g_policy_res->set_srtp_auth_enable(policy, enable);
+	}
+
+	g_policy_res->set_srtp_auth_enable(policy, enable);
 }
 
 int ast_srtp_get_random(unsigned char *key, size_t len)
 {
-	if (!g_srtp_res)
+	if (!g_srtp_res) {
 		return -1;
+	}
 
 	return g_srtp_res->get_random(key, len);
 }
 
-static int rtp_recvfrom(struct ast_rtp *rtp, void *buf, size_t size,
-			int flags, struct sockaddr *sa, socklen_t *salen)
+static int rtp_recvfrom(struct ast_rtp *rtp, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t *salen)
 {
 	int len;
 
-	len = recvfrom(rtp->s, buf, size, flags, sa, salen);
-
-	if (len < 0)
+	if ((len = recvfrom(rtp->s, buf, size, flags, sa, salen)) < 0) {
 		return len;
-
-	if (g_srtp_res && rtp->srtp) {
-		int res;
-		
-		res = g_srtp_res->unprotect(rtp->srtp, buf, &len);
-		if (res < 0)
-			return -1;
+	}
+
+	if (g_srtp_res && rtp->srtp && g_srtp_res->unprotect(rtp->srtp, buf, &len) < 0) {
+		return -1;
 	}
 
 	return len;
 }
 
-static int rtp_sendto(struct ast_rtp *rtp, void *buf, size_t size,
-		      int flags, struct sockaddr *sa, socklen_t salen)
+static int rtp_sendto(struct ast_rtp *rtp, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t salen)
 {
 	int len = size;
 	void *temp = buf;
 
-	if (g_srtp_res && rtp->srtp) {
-		int res = g_srtp_res->protect(rtp->srtp, &temp, &len);
-
-		if (res < 0)
-			return -1;
+	if (g_srtp_res && rtp->srtp && g_srtp_res->protect(rtp->srtp, &temp, &len) < 0) {
+		return -1;
 	}
 
 	return sendto(rtp->s, temp, len, flags, sa, salen);
@@ -1734,7 +1731,6 @@
 	rtpheader[0] = htonl(reconstruct);
 
 	/* Send the packet back out */
-	/* TODO: correct? */
 	res = rtp_sendto(bridged, (void *)rtpheader, len + hdrlen, 0, (struct sockaddr *)&bridged->them, sizeof(bridged->them));
 	if (res < 0) {
 		if (!bridged->nat || (bridged->nat && (ast_test_flag(bridged, FLAG_NAT_ACTIVE) == FLAG_NAT_ACTIVE))) {

Modified: team/group/srtp/res/mikey.h
URL: http://svn.digium.com/view/asterisk/team/group/srtp/res/mikey.h?view=diff&rev=166096&r1=166095&r2=166096
==============================================================================
--- team/group/srtp/res/mikey.h (original)
+++ team/group/srtp/res/mikey.h Fri Dec 19 16:48:52 2008
@@ -14,13 +14,13 @@
  * This program is free software, distributed under the terms of
  * the GNU General Public License Version 2. See the LICENSE file
  * at the top of the source tree.
- * 
+ *
  */
 
 /*! \file mikey.h
  *
  * \brief MIKEY (internal)
- * 
+ *
  * MIKEY is specified in RFC 3830, 4650 and 4738.
  *
  * \author Mikael Magnusson <mikma at users.sourceforge.net>
@@ -41,7 +41,6 @@
 int mikey_add_global_ca_file(const char *ca_file);
 int mikey_add_global_cert_file(const char *cert_file, const char *key_file);
 
-
 struct mikey *mikey_alloc(void);
 void mikey_destroy(struct mikey *mikey);
 void mikey_set_ssrc(struct mikey *mikey, uint32_t ssrc);

Modified: team/group/srtp/res/res_mikey.c
URL: http://svn.digium.com/view/asterisk/team/group/srtp/res/res_mikey.c?view=diff&rev=166096&r1=166095&r2=166096
==============================================================================
--- team/group/srtp/res/res_mikey.c (original)
+++ team/group/srtp/res/res_mikey.c Fri Dec 19 16:48:52 2008
@@ -41,8 +41,6 @@
 #include<asterisk/module.h>
 #include"mikey.h"
 
-
-
 /* extern struct ast_mikey_res g_mikey_res; */
 
 struct ast_mikey_res g_mikey_res = {
@@ -61,14 +59,13 @@
 	.mikey_create_policy = mikey_create_policy,
 };
 
-
 /*
  * Exported functions
  */
-
 static int load_module(void)
 {
 	mikey_init();
+
 	return ast_register_mikey(&g_mikey_res);
 }
 
@@ -76,10 +73,11 @@
 {
 	int res = ast_unregister_mikey(&g_mikey_res);
 	mikey_uninit();
+
 	return res;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Multimedia Internet KEYing (MIKEY)",
-		.load = load_module,
-		.unload = unload_module,
-		);
+	.load = load_module,
+	.unload = unload_module,
+);




More information about the asterisk-commits mailing list