Module: sip-router Branch: master Commit: 27e1d6f41a7b2545af39ad040b6cf2d824a28f25 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=27e1d6f4...
Author: Ovidiu Sas osas@voipembedded.com Committer: Ovidiu Sas osas@voipembedded.com Date: Thu Dec 2 13:49:34 2010 -0500
sdp parser: detect on hold media during sdp parsing
---
parser/sdp/sdp.c | 20 +++++++++++++++++++- parser/sdp/sdp.h | 3 ++- parser/sdp/sdp_helpr_funcs.c | 12 ++++++++---- parser/sdp/sdp_helpr_funcs.h | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/parser/sdp/sdp.c b/parser/sdp/sdp.c index b35447e..2f8831d 100644 --- a/parser/sdp/sdp.c +++ b/parser/sdp/sdp.c @@ -29,6 +29,7 @@ */
+#include "../../ut.h" #include "../../mem/mem.h" #include "../../mem/shm_mem.h" #include "../parser_f.h" @@ -39,6 +40,9 @@ #define USE_PKG_MEM 0 #define USE_SHM_MEM 1
+#define HOLD_IP_STR "0.0.0.0" +#define HOLD_IP_LEN 7 + /** * Creates and initialize a new sdp_info structure */ @@ -524,7 +528,8 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
if (parse_payload_attr && extract_ptime(&tmpstr1, &stream->ptime) == 0) { a1p = stream->ptime.s + stream->ptime.len; - } else if (parse_payload_attr && extract_sendrecv_mode(&tmpstr1, &stream->sendrecv_mode) == 0) { + } else if (parse_payload_attr && extract_sendrecv_mode(&tmpstr1, + &stream->sendrecv_mode, &stream->is_on_hold) == 0) { a1p = stream->sendrecv_mode.s + stream->sendrecv_mode.len; } else if (parse_payload_attr && extract_rtpmap(&tmpstr1, &rtp_payload, &rtp_enc, &rtp_clock, &rtp_params) == 0) { if (rtp_params.len != 0 && rtp_params.s != NULL) { @@ -554,6 +559,19 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
a2p = find_next_sdp_line(a1p, m2p, 'a', m2p); } + /* Let's detect if the media is on hold by checking + * the good old "0.0.0.0" connection address */ + if (!stream->is_on_hold) { + if (stream->ip_addr.s && stream->ip_addr.len) { + if (stream->ip_addr.len == HOLD_IP_LEN && + strncmp(stream->ip_addr.s, HOLD_IP_STR, HOLD_IP_LEN)==0) + stream->is_on_hold = 1; + } else if (session->ip_addr.s && session->ip_addr.len) { + if (session->ip_addr.len == HOLD_IP_LEN && + strncmp(session->ip_addr.s, HOLD_IP_STR, HOLD_IP_LEN)==0) + stream->is_on_hold = 1; + } + } ++stream_num; } /* Iterate medias/streams in session */ return 0; diff --git a/parser/sdp/sdp.h b/parser/sdp/sdp.h index bdbf593..353580c 100644 --- a/parser/sdp/sdp.h +++ b/parser/sdp/sdp.h @@ -50,7 +50,8 @@ typedef struct sdp_stream_cell { int pf; /**< connection address family: AF_INET/AF_INET6 */ str ip_addr; /**< connection address */ int stream_num; /**< stream index inside a session */ - int is_rtp; /**< flag indicating is this is an RTP stream */ + int is_rtp; /**< flag indicating if this is an RTP stream */ + int is_on_hold; /**< flag indicating if this stream is on hold */ /* m=<media> <port> <transport> <payloads> */ str media; str port; diff --git a/parser/sdp/sdp_helpr_funcs.c b/parser/sdp/sdp_helpr_funcs.c index 8b521f9..e432fd2 100644 --- a/parser/sdp/sdp_helpr_funcs.c +++ b/parser/sdp/sdp_helpr_funcs.c @@ -321,15 +321,19 @@ int extract_rtcp(str *body, str *rtcp) return extract_field(body, rtcp, field); }
-int extract_sendrecv_mode(str *body, str *sendrecv_mode) +int extract_sendrecv_mode(str *body, str *sendrecv_mode, int *is_on_hold) { char *cp1;
cp1 = body->s; if ( !( (strncasecmp(cp1, "a=sendrecv", 10) == 0) || - (strncasecmp(cp1, "a=inactive", 10) == 0) || - (strncasecmp(cp1, "a=recvonly", 10) == 0) || - (strncasecmp(cp1, "a=sendonly", 10) == 0) )) { + (strncasecmp(cp1, "a=recvonly", 10) == 0))) { + if ( !( (strncasecmp(cp1, "a=inactive", 10) == 0) || + (strncasecmp(cp1, "a=sendonly", 10) == 0) )) { + return -1; + } else { + *is_on_hold = 1; + } return -1; }
diff --git a/parser/sdp/sdp_helpr_funcs.h b/parser/sdp/sdp_helpr_funcs.h index 21512e6..c815845 100644 --- a/parser/sdp/sdp_helpr_funcs.h +++ b/parser/sdp/sdp_helpr_funcs.h @@ -47,7 +47,7 @@ int get_mixed_part_delimiter(str * body, str * mp_delimiter); int extract_rtpmap(str *body, str *rtpmap_payload, str *rtpmap_encoding, str *rtpmap_clockrate, str *rtpmap_parmas); int extract_fmtp( str *body, str *fmtp_payload, str *fmtp_string ); int extract_ptime(str *body, str *ptime); -int extract_sendrecv_mode(str *body, str *sendrecv_mode); +int extract_sendrecv_mode(str *body, str *sendrecv_mode, int *is_on_hold); int extract_mediaip(str *body, str *mediaip, int *pf, char *line); int extract_media_attr(str *body, str *mediamedia, str *mediaport, str *mediatransport, str *mediapayload, int *is_rtp); int extract_bwidth(str *body, str *bwtype, str *bwwitdth);