Index: rtp.c =================================================================== RCS file: /var/lib/cvs/asterisk/rtp.c,v retrieving revision 1.5 diff -u -r1.5 rtp.c --- rtp.c 4 Aug 2005 10:18:52 -0000 1.5 +++ rtp.c 21 Sep 2005 14:27:59 -0000 @@ -113,11 +113,23 @@ int ast_rtp_fd(struct ast_rtp *rtp) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_fd called with NULL rtp struct\n"); + return -1; + } + return rtp->s; } int ast_rtcp_fd(struct ast_rtp *rtp) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtcp_fd called with NULL rtp struct\n"); + return -1; + } + if (rtp->rtcp) return rtp->rtcp->s; return -1; @@ -161,16 +173,34 @@ void ast_rtp_set_data(struct ast_rtp *rtp, void *data) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_set_data called with NULL rtp struct\n"); + return; + } + rtp->data = data; } void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_set_callback called with NULL rtp struct\n"); + return; + } + rtp->callback = callback; } void ast_rtp_setnat(struct ast_rtp *rtp, int nat) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_setnat called with NULL rtp struct\n"); + return; + } + rtp->nat = nat; } @@ -179,6 +209,13 @@ struct timeval tv; static struct ast_frame null_frame = { AST_FRAME_NULL, }; char iabuf[INET_ADDRSTRLEN]; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "send_dtmf called with NULL rtp struct\n"); + return NULL; + } + gettimeofday(&tv, NULL); if ((tv.tv_sec < rtp->dtmfmute.tv_sec) || ((tv.tv_sec == rtp->dtmfmute.tv_sec) && (tv.tv_usec < rtp->dtmfmute.tv_usec))) { @@ -210,6 +247,13 @@ unsigned int event; char resp = 0; struct ast_frame *f = NULL; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "process_cisco_dtmf called with NULL rtp struct\n"); + return NULL; + } + event = ntohl(*((unsigned int *)(data))); event &= 0x001F; #if 0 @@ -241,6 +285,13 @@ unsigned int duration; char resp = 0; struct ast_frame *f = NULL; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "process_rfc2833 called with NULL rtp struct\n"); + return NULL; + } + event = ntohl(*((unsigned int *)(data))); event >>= 24; event_end = ntohl(*((unsigned int *)(data))); @@ -288,6 +339,13 @@ static struct ast_frame *process_rfc3389(struct ast_rtp *rtp, unsigned char *data, int len) { struct ast_frame *f = NULL; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "process_rfc3389 called with NULL rtp struct\n"); + return NULL; + } + /* Convert comfort noise into audio with various codecs. Unfortunately this doesn't totally help us out becuase we don't have an engine to keep it going and we are not guaranteed to have it every 20ms or anything */ @@ -342,6 +400,12 @@ unsigned int rtcpdata[1024]; char iabuf[INET_ADDRSTRLEN]; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtcp_read called with NULL rtp struct\n"); + return NULL; + } + if (!rtp->rtcp) return &null_frame; @@ -380,6 +444,12 @@ static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "recalc_rxstamp called with NULL rtp struct\n"); + return; + } + if ((!rtp->rxcore.tv_sec && !rtp->rxcore.tv_usec) || mark) { gettimeofday(&rtp->rxcore, NULL); rtp->rxcore.tv_sec -= timestamp / 8000; @@ -417,6 +487,12 @@ static struct ast_frame *f, null_frame = { AST_FRAME_NULL, }; struct rtpPayloadType rtpPT; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_read called with NULL rtp struct\n"); + return NULL; + } + len = sizeof(sin); /* Cache where the header will go */ @@ -651,6 +727,12 @@ void ast_rtp_pt_clear(struct ast_rtp* rtp) { int i; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_tp_clear called with NULL rtp struct\n"); + return; + } for (i = 0; i < MAX_RTP_PT; ++i) { rtp->current_RTP_PT[i].isAstFormat = 0; @@ -665,6 +747,13 @@ void ast_rtp_pt_default(struct ast_rtp* rtp) { int i; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_tp_default called with NULL rtp struct\n"); + return; + } + /* Initialize to default payload types */ for (i = 0; i < MAX_RTP_PT; ++i) { rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat; @@ -680,6 +769,13 @@ /* 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) { + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_set_m_type called with NULL rtp struct\n"); + return; + } + if (pt < 0 || pt > MAX_RTP_PT) return; /* bogus payload type */ if (static_RTP_PT[pt].code != 0) { @@ -693,6 +789,12 @@ char* mimeType, char* mimeSubtype) { int i; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_set_rtpmap_type called with NULL rtp struct\n"); + return; + } + if (pt < 0 || pt > MAX_RTP_PT) return; /* bogus payload type */ for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) { @@ -710,6 +812,12 @@ int* astFormats, int* nonAstFormats) { int pt; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_get_current_formats called with NULL rtp struct\n"); + return; + } + *astFormats = *nonAstFormats = 0; for (pt = 0; pt < MAX_RTP_PT; ++pt) { if (rtp->current_RTP_PT[pt].isAstFormat) { @@ -727,10 +835,16 @@ ast_log(LOG_WARNING, "rtp structure is null\n"); } -struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) -{ +struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) { struct rtpPayloadType result; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_lookup_pt called with NULL rtp struct\n"); + // XXX return what?? + return result; + } + result.isAstFormat = result.code = 0; if (pt < 0 || pt > MAX_RTP_PT) { return result; /* bogus payload type */ @@ -748,6 +862,11 @@ int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) { int pt; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_lookup_code called with NULL rtp struct\n"); + return -1; + } if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && code == rtp->rtp_lookup_code_cache_code) { @@ -917,6 +1036,13 @@ int ast_rtp_settos(struct ast_rtp *rtp, int tos) { int res; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_settos called with NULL rtp struct\n"); + return -1; + } + if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); return res; @@ -924,6 +1050,12 @@ void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_set_peer called with NULL rtp struct\n"); + return; + } + rtp->them.sin_port = them->sin_port; rtp->them.sin_addr = them->sin_addr; if (rtp->rtcp) { @@ -934,6 +1066,12 @@ void ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_get_peer called with NULL rtp struct\n"); + return; + } + them->sin_family = AF_INET; them->sin_port = rtp->them.sin_port; them->sin_addr = rtp->them.sin_addr; @@ -941,11 +1079,23 @@ void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_get_us called with NULL rtp struct\n"); + return; + } + memcpy(us, &rtp->us, sizeof(rtp->us)); } void ast_rtp_stop(struct ast_rtp *rtp) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_stop called with NULL rtp struct\n"); + return; + } + memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr)); memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port)); if (rtp->rtcp) { @@ -956,6 +1106,12 @@ void ast_rtp_destroy(struct ast_rtp *rtp) { + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_destroy called with NULL rtp struct\n"); + return; + } + if (rtp->smoother) ast_smoother_free(rtp->smoother); if (rtp->ioid) @@ -977,6 +1133,14 @@ { struct timeval now; unsigned int ms; + + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "calc_txstamp called with NULL rtp struct\n"); + // XXX is this ok? + return 0; + } + if (!rtp->txcore.tv_sec && !rtp->txcore.tv_usec) { gettimeofday(&rtp->txcore, NULL); /* Round to 20ms for nice, pretty timestamps */ @@ -1009,6 +1173,12 @@ char data[256]; char iabuf[INET_ADDRSTRLEN]; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_senddigit called with NULL rtp struct\n"); + return -1; + } + if ((digit <= '9') && (digit >= '0')) digit -= '0'; else if (digit == '*') @@ -1075,6 +1245,12 @@ int pred; int mark = 0; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_raw_write called with NULL rtp struct\n"); + return -1; + } + ms = calc_txstamp(rtp, &f->delivery); /* Default prediction */ if (f->subclass < AST_FORMAT_MAX_AUDIO) { @@ -1168,6 +1344,11 @@ int hdrlen = 12; int subclass; + /* sanity check */ + if (rtp == NULL) { + ast_log(LOG_WARNING, "ast_rtp_write called with NULL rtp struct\n"); + return -1; + } /* If we have no peer, return immediately */ if (!rtp->them.sin_addr.s_addr)