Bug #6109: Fix unprotected list in RTP, implement AST_LIST macros, update doxygen docs

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7730 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Olle Johansson
2006-01-03 09:30:19 +00:00
parent 9b315771d4
commit 715a220850
2 changed files with 120 additions and 124 deletions

View File

@@ -26,12 +26,13 @@
#ifndef _ASTERISK_RTP_H
#define _ASTERISK_RTP_H
#include <netinet/in.h>
#include "asterisk/frame.h"
#include "asterisk/io.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include <netinet/in.h>
#include "asterisk/linkedlists.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
@@ -48,15 +49,15 @@ extern "C" {
#define AST_RTP_MAX AST_RTP_CISCO_DTMF
struct ast_rtp_protocol {
/* Get RTP struct, or NULL if unwilling to transfer */
/*! Get RTP struct, or NULL if unwilling to transfer */
struct ast_rtp *(* const get_rtp_info)(struct ast_channel *chan);
/* Get RTP struct, or NULL if unwilling to transfer */
/*! Get RTP struct, or NULL if unwilling to transfer */
struct ast_rtp *(* const get_vrtp_info)(struct ast_channel *chan);
/* Set RTP peer */
/*! Set RTP peer */
int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs, int nat_active);
int (* const get_codec)(struct ast_channel *chan);
const char * const type;
struct ast_rtp_protocol *next;
AST_LIST_ENTRY(ast_rtp_protocol) list;
};
/*!
@@ -124,25 +125,25 @@ int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
int ast_rtp_settos(struct ast_rtp *rtp, int tos);
/* Setting RTP payload types from lines in a SDP description: */
/*! \brief Setting RTP payload types from lines in a SDP description: */
void ast_rtp_pt_clear(struct ast_rtp* rtp);
/* Set payload types to defaults */
/*! \brief Set payload types to defaults */
void ast_rtp_pt_default(struct ast_rtp* rtp);
void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
char* mimeType, char* mimeSubtype);
/* Mapping between RTP payload format codes and Asterisk codes: */
/*! \brief Mapping between RTP payload format codes and Asterisk codes: */
struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
void ast_rtp_get_current_formats(struct ast_rtp* rtp,
int* astFormats, int* nonAstFormats);
/* Mapping an Asterisk code into a MIME subtype (string): */
/*! \brief Mapping an Asterisk code into a MIME subtype (string): */
char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
/* Build a string of MIME subtype names from a capability list */
/*! \brief Build a string of MIME subtype names from a capability list */
char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat);
void ast_rtp_setnat(struct ast_rtp *rtp, int nat);

123
rtp.c
View File

@@ -61,21 +61,21 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define RTP_MTU 1200
#define DEFAULT_DTMF_TIMEOUT 3000 /* samples */
#define DEFAULT_DTMF_TIMEOUT 3000 /*!< samples */
static int dtmftimeout = DEFAULT_DTMF_TIMEOUT;
static int rtpstart = 0;
static int rtpend = 0;
static int rtpdebug = 0; /* Are we debugging? */
static struct sockaddr_in rtpdebugaddr; /* Debug packets to/from this host */
static int rtpstart = 0; /*!< First port for RTP sessions (set in rtp.conf) */
static int rtpend = 0; /*!< Last port for RTP sessions (set in rtp.conf) */
static int rtpdebug = 0; /*!< Are we debugging? */
static struct sockaddr_in rtpdebugaddr; /*!< Debug packets to/from this host */
#ifdef SO_NO_CHECK
static int nochecksums = 0;
#endif
/* The value of each payload format mapping: */
/*! \brief The value of each payload format mapping: */
struct rtpPayloadType {
int isAstFormat; /* whether the following code is an AST_FORMAT */
int isAstFormat; /*!< whether the following code is an AST_FORMAT */
int code;
};
@@ -86,13 +86,13 @@ struct rtpPayloadType {
#define FLAG_NAT_INACTIVE (0 << 1)
#define FLAG_NAT_INACTIVE_NOWARN (1 << 1)
/*! \brief RTP session description */
struct ast_rtp {
int s;
char resp;
struct ast_frame f;
unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
/*! Synchronization source, RFC 3550, page 10. */
unsigned int ssrc;
unsigned int ssrc; /*!< Synchronization source, RFC 3550, page 10. */
unsigned int lastts;
unsigned int lastdigitts;
unsigned int lastrxts;
@@ -106,25 +106,21 @@ struct ast_rtp {
unsigned int dtmfduration;
int nat;
unsigned int flags;
/*! Socket representation of the local endpoint. */
struct sockaddr_in us;
/*! Socket representation of the remote endpoint. */
struct sockaddr_in them;
struct sockaddr_in us; /*!< Socket representation of the local endpoint. */
struct sockaddr_in them; /*!< Socket representation of the remote endpoint. */
struct timeval rxcore;
struct timeval txcore;
struct timeval dtmfmute;
struct ast_smoother *smoother;
int *ioid;
/*! Sequence number, RFC 3550, page 13. */
unsigned short seqno;
unsigned short seqno; /*!< Sequence number, RFC 3550, page 13. */
unsigned short rxseqno;
struct sched_context *sched;
struct io_context *io;
void *data;
ast_rtp_callback callback;
struct rtpPayloadType current_RTP_PT[MAX_RTP_PT];
/*! a cache for the result of rtp_lookup_code(): */
int rtp_lookup_code_cache_isAstFormat;
int rtp_lookup_code_cache_isAstFormat; /*!< a cache for the result of rtp_lookup_code(): */
int rtp_lookup_code_cache_code;
int rtp_lookup_code_cache_result;
struct ast_rtcp *rtcp;
@@ -141,15 +137,13 @@ struct ast_rtp {
*
*/
struct ast_rtcp {
/*! Socket */
int s;
/*! Socket representation of the local endpoint. */
struct sockaddr_in us;
/*! Socket representation of the remote endpoint. */
struct sockaddr_in them;
int s; /*!< Socket */
struct sockaddr_in us; /*!< Socket representation of the local endpoint. */
struct sockaddr_in them; /*!< Socket representation of the remote endpoint. */
};
static struct ast_rtp_protocol *protos = NULL;
/*! \brief List of current sessions */
static AST_LIST_HEAD_STATIC(protos, ast_rtp_protocol);
int ast_rtp_fd(struct ast_rtp *rtp)
{
@@ -229,9 +223,8 @@ static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *
struct ast_frame *f = NULL;
event = ntohl(*((unsigned int *)(data)));
event &= 0x001F;
#if 0
printf("Cisco Digit: %08x (len = %d)\n", event, len);
#endif
if (option_debug > 2 || rtpdebug)
ast_log(LOG_DEBUG, "Cisco DTMF Digit: %08x (len = %d)\n", event, len);
if (event < 10) {
resp = '0' + event;
} else if (event < 11) {
@@ -269,6 +262,7 @@ static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *dat
unsigned int duration;
char resp = 0;
struct ast_frame *f = NULL;
event = ntohl(*((unsigned int *)(data)));
event >>= 24;
event_end = ntohl(*((unsigned int *)(data)));
@@ -276,7 +270,7 @@ static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *dat
event_end >>= 24;
duration = ntohl(*((unsigned int *)(data)));
duration &= 0xFFFF;
if (rtpdebug)
if (rtpdebug || option_debug > 2)
ast_log(LOG_DEBUG, "- RTP 2833 Event: %08x (len = %d)\n", event, len);
if (event < 10) {
resp = '0' + event;
@@ -741,18 +735,18 @@ static void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src)
dest->rtp_lookup_code_cache_result = 0;
}
/*--- get_proto: Get channel driver interface structure */
/*! \brief Get channel driver interface structure */
static struct ast_rtp_protocol *get_proto(struct ast_channel *chan)
{
struct ast_rtp_protocol *cur;
cur = protos;
while(cur) {
if (cur->type == chan->type) {
AST_LIST_LOCK(&protos);
AST_LIST_TRAVERSE(&protos, cur, list) {
if (cur->type == chan->type)
return cur;
}
cur = cur->next;
}
AST_LIST_UNLOCK(&protos);
return NULL;
}
@@ -773,13 +767,15 @@ int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src)
destpr = get_proto(dest);
srcpr = get_proto(src);
if (!destpr) {
if (option_debug)
ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name);
ast_mutex_unlock(&dest->lock);
ast_mutex_unlock(&src->lock);
return 0;
}
if (!srcpr) {
ast_log(LOG_WARNING, "Channel '%s' has no RTP, not doing anything\n", src->name);
if (option_debug)
ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src->name);
ast_mutex_unlock(&dest->lock);
ast_mutex_unlock(&src->lock);
return 0;
@@ -809,13 +805,15 @@ int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src)
ast_rtp_pt_copy(vdestp, vsrcp);
ast_mutex_unlock(&dest->lock);
ast_mutex_unlock(&src->lock);
if (option_debug)
ast_log(LOG_DEBUG, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name);
return 1;
}
/* Make a note of a RTP paymoad type that was seen in a SDP "m=" line. */
/* By default, use the well-known value for this type (although it may */
/* still be set to a different value by a subsequent "a=rtpmap:" line): */
/*! \brief Make a note of a RTP paymoad type that was seen in a SDP "m=" line.
* By default, use the well-known value for this type (although it may
* still be set to a different value by a subsequent "a=rtpmap:" line)
*/
void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt)
{
if (pt < 0 || pt > MAX_RTP_PT)
@@ -826,11 +824,10 @@ void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt)
}
}
/* Make a note of a RTP payload type (with MIME type) that was seen in */
/* a SDP "a=rtpmap:" line. */
/*! \brief Make a note of a RTP payload type (with MIME type) that was seen in
a SDP "a=rtpmap:" line. */
void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
char* mimeType, char* mimeSubtype)
{
int i;
@@ -846,8 +843,8 @@ void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
}
}
/* Return the union of all of the codecs that were set by rtp_set...() calls */
/* They're returned as two distinct sets: AST_FORMATs, and AST_RTPs */
/*! \brief Return the union of all of the codecs that were set by rtp_set...() calls
* They're returned as two distinct sets: AST_FORMATs, and AST_RTPs */
void ast_rtp_get_current_formats(struct ast_rtp* rtp,
int* astFormats, int* nonAstFormats) {
int pt;
@@ -879,7 +876,7 @@ struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt)
return result;
}
/* Looks up an RTP code out of our *static* outbound list */
/*! \brief Looks up an RTP code out of our *static* outbound list */
int ast_rtp_lookup_code(struct ast_rtp* rtp, const int isAstFormat, const int code) {
int pt;
@@ -1533,44 +1530,42 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
return 0;
}
/*--- ast_rtp_proto_unregister: Unregister interface to channel driver */
/*! \brief Unregister interface to channel driver */
void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto)
{
struct ast_rtp_protocol *cur, *prev;
struct ast_rtp_protocol *cur;
cur = protos;
prev = NULL;
while(cur) {
AST_LIST_LOCK(&protos);
AST_LIST_TRAVERSE_SAFE_BEGIN(&protos, cur, list) {
if (cur == proto) {
if (prev)
prev->next = proto->next;
else
protos = proto->next;
return;
AST_LIST_REMOVE_CURRENT(&protos, list);
break;
}
prev = cur;
cur = cur->next;
}
AST_LIST_TRAVERSE_SAFE_END
AST_LIST_UNLOCK(&protos);
}
/*--- ast_rtp_proto_register: Register interface to channel driver */
/*! \brief Register interface to channel driver */
int ast_rtp_proto_register(struct ast_rtp_protocol *proto)
{
struct ast_rtp_protocol *cur;
cur = protos;
while(cur) {
AST_LIST_LOCK(&protos);
AST_LIST_TRAVERSE(&protos, cur, list) {
if (cur->type == proto->type) {
ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
AST_LIST_UNLOCK(&protos);
return -1;
}
cur = cur->next;
}
proto->next = protos;
protos = proto;
AST_LIST_INSERT_HEAD(&protos, proto, list);
AST_LIST_UNLOCK(&protos);
return 0;
}
/* ast_rtp_bridge: Bridge calls. If possible and allowed, initiate
/*! \brief Bridge calls. If possible and allowed, initiate
re-invite so the peers exchange media directly outside
of Asterisk. */
enum ast_bridge_result ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
@@ -1935,7 +1930,7 @@ void ast_rtp_reload(void)
}
/*--- ast_rtp_init: Initialize the RTP system in Asterisk */
/*! \brief Initialize the RTP system in Asterisk */
void ast_rtp_init(void)
{
ast_cli_register(&cli_debug);