[asterisk-commits] twilson: branch group/srtp r165953 - in /team/group/srtp: channels/ include/a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Dec 19 10:35:34 CST 2008
Author: twilson
Date: Fri Dec 19 10:35:33 2008
New Revision: 165953
URL: http://svn.digium.com/view/asterisk?view=rev&rev=165953
Log:
Add ast_rtp_get_themssrc() to get around having to #include <srtp/srtp_priv.h> since the author made it private for a reason. Also, when a hold INVITE came in it would print a WARNING because libsrtp would return err_status_bad_param when srtp_add_stream was called when a stream had already been set up. Currently I'm ignoring that particular error, but I'll probably add a field in ast_srtp to be able to track whether or not we already have a stream set up (so I don't have to resort to including srtp_priv.h)
There are also some formatting fixes I found along the way thrown in.
Modified:
team/group/srtp/channels/chan_sip.c
team/group/srtp/include/asterisk/rtp.h
team/group/srtp/main/rtp.c
team/group/srtp/res/res_srtp.c
Modified: team/group/srtp/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/srtp/channels/chan_sip.c?view=diff&rev=165953&r1=165952&r2=165953
==============================================================================
--- team/group/srtp/channels/chan_sip.c (original)
+++ team/group/srtp/channels/chan_sip.c Fri Dec 19 10:35:33 2008
@@ -4897,6 +4897,10 @@
/* We're replacing a call. */
p->options->replaces = ast_var_value(current);
} else if (!strcasecmp(ast_var_name(current), "SIPSRTP")) {
+ if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {
+ ast_debug(1, "Reinviting not possible when using SRTP, ignoring canreinvite setting\n");
+ }
+
if (!p->srtp) {
if (setup_srtp(p) < 0) {
ast_log(LOG_WARNING, "SRTP setup failed\n");
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=165953&r1=165952&r2=165953
==============================================================================
--- team/group/srtp/include/asterisk/rtp.h (original)
+++ team/group/srtp/include/asterisk/rtp.h Fri Dec 19 10:35:33 2008
@@ -383,6 +383,7 @@
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);
int ast_rtp_add_srtp_policy(struct ast_rtp *rtp, struct ast_srtp_policy *policy);
struct ast_srtp_policy *ast_srtp_policy_alloc(void);
Modified: team/group/srtp/main/rtp.c
URL: http://svn.digium.com/view/asterisk/team/group/srtp/main/rtp.c?view=diff&rev=165953&r1=165952&r2=165953
==============================================================================
--- team/group/srtp/main/rtp.c (original)
+++ team/group/srtp/main/rtp.c Fri Dec 19 10:35:33 2008
@@ -1152,6 +1152,11 @@
unsigned int ast_rtp_get_ssrc(struct ast_rtp *rtp)
{
return rtp->ssrc;
+}
+
+unsigned int ast_rtp_get_themssrc(struct ast_rtp *rtp)
+{
+ return rtp->themssrc;
}
void ast_rtp_set_srtp_cb(struct ast_rtp *rtp, const struct ast_srtp_cb *cb,
@@ -4526,7 +4531,7 @@
}
if (p0->srtp || p1->srtp) {
- ast_log(LOG_NOTICE, "Cannot native bridge in SRTP.\n");
+ /* We can't do native briding if someone is using SRTP! */
ast_channel_unlock(c0);
ast_channel_unlock(c1);
return AST_BRIDGE_FAILED_NOWARN;
Modified: team/group/srtp/res/res_srtp.c
URL: http://svn.digium.com/view/asterisk/team/group/srtp/res/res_srtp.c?view=diff&rev=165953&r1=165952&r2=165953
==============================================================================
--- team/group/srtp/res/res_srtp.c (original)
+++ team/group/srtp/res/res_srtp.c Fri Dec 19 10:35:33 2008
@@ -52,7 +52,6 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-#include <srtp/srtp_priv.h>
#include <srtp/srtp.h>
#include "asterisk/lock.h"
@@ -72,7 +71,6 @@
srtp_policy_t sp;
};
-static int srtpdebug = 1;
static int g_initialized = 0;
/* Exported functions */
@@ -198,32 +196,18 @@
static void srtp_event_cb(srtp_event_data_t *data)
{
switch (data->event) {
- case event_ssrc_collision: {
- if (option_debug || srtpdebug) {
- ast_log(LOG_DEBUG, "SSRC collision ssrc:%u dir:%d\n",
- ntohl(data->stream->ssrc),
- data->stream->direction);
- }
- break;
- }
- case event_key_soft_limit: {
- if (option_debug || srtpdebug) {
- ast_log(LOG_DEBUG, "event_key_soft_limit\n");
- }
- break;
- }
- case event_key_hard_limit: {
- if (option_debug || srtpdebug) {
- ast_log(LOG_DEBUG, "event_key_hard_limit\n");
- }
- break;
- }
- case event_packet_index_limit: {
- if (option_debug || srtpdebug) {
- ast_log(LOG_DEBUG, "event_packet_index_limit\n");
- }
- break;
- }
+ case event_ssrc_collision:
+ ast_debug(1, "SSRC collision\n");
+ break;
+ case event_key_soft_limit:
+ ast_debug(1, "event_key_soft_limit\n");
+ break;
+ case event_key_hard_limit:
+ ast_debug(1, "event_key_hard_limit\n");
+ break;
+ case event_packet_index_limit:
+ ast_debug(1, "event_packet_index_limit\n");
+ break;
}
}
@@ -427,42 +411,34 @@
/* Vtable functions */
-static int
-res_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len)
+static int res_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len)
{
int res = 0;
int i;
for (i = 0; i < 2; i++) {
- srtp_hdr_t *header = buf;
-
res = srtp_unprotect(srtp->session, buf, len);
if (res != err_status_no_ctx)
break;
-
+
if (srtp->cb && srtp->cb->no_ctx) {
- if (srtp->cb->no_ctx(srtp->rtp, ntohl(header->ssrc), srtp->data) < 0) {
+ if (srtp->cb->no_ctx(srtp->rtp, ast_rtp_get_themssrc(srtp->rtp), srtp->data) < 0) {
break;
}
-
} else {
break;
}
}
-
+
if (res != err_status_ok) {
- if (option_debug || srtpdebug) {
- ast_log(LOG_DEBUG, "SRTP unprotect: %s\n",
- srtp_errstr(res));
- }
+ ast_debug(1, "SRTP unprotect: %s\n", srtp_errstr(res));
return -1;
}
return *len;
}
-static int
-res_srtp_protect(struct ast_srtp *srtp, void **buf, int *len)
+static int res_srtp_protect(struct ast_srtp *srtp, void **buf, int *len)
{
int res = 0;
@@ -474,10 +450,7 @@
res = srtp_protect(srtp->session, srtp->buf, len);
if (res != err_status_ok) {
- if (option_debug || srtpdebug) {
- ast_log(LOG_DEBUG, "SRTP protect: %s\n",
- srtp_errstr(res));
- }
+ ast_debug(1, "SRTP protect: %s\n", srtp_errstr(res));
return -1;
}
@@ -485,9 +458,7 @@
return *len;
}
-static int
-res_srtp_create(struct ast_srtp **srtp, struct ast_rtp *rtp,
- struct ast_srtp_policy *policy)
+static int res_srtp_create(struct ast_srtp **srtp, struct ast_rtp *rtp, struct ast_srtp_policy *policy)
{
int res;
struct ast_srtp *temp = res_srtp_new();
@@ -503,8 +474,7 @@
return 0;
}
-static void
-res_srtp_destroy(struct ast_srtp *srtp)
+static void res_srtp_destroy(struct ast_srtp *srtp)
{
if (srtp->session) {
srtp_dealloc(srtp->session);
@@ -513,13 +483,15 @@
free(srtp);
}
-static int
-res_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
+static int res_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
{
int res;
res = srtp_add_stream(srtp->session, &policy->sp);
- if (res != err_status_ok)
+ /* If a stream has already been set up, libsrtp will return a bad_param error
+ * and then we'll flash a warning on CLI. Might be better to add a flag to the
+ * ast_srtp struct.*/
+ if (!(res == err_status_ok || res == err_status_bad_param))
return -1;
return 0;
More information about the asterisk-commits
mailing list