Commit 5739ba9f authored by Pekka Pessi's avatar Pekka Pessi

sdp_parse: the syntax is updated to RFC 4566

"The changes to the memo are intended to be backward-compatible
clarifications."

darcs-hash:20080812165616-db55f-7a7133e83dbfd84d00c661d18c78764f0d0c4193.gz
parent 050cfdd0
......@@ -11,7 +11,7 @@ tests="${2:-${sdp_path}/tests}"
if test -r $tests/message-1.sdp ; then
for n in 1 2 3 4 5 6 7 8 9 10;
for n in 1 2 3 4 5 6 7 8 9 10 11;
do
echo -n "$n: "
"$test_sdp" < "$tests/message-$n.sdp" && echo OK
......
......@@ -250,6 +250,7 @@ void sdp_parser_free(sdp_parser_t *p)
#define CRLF "\015\012"
#define ALPHA "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define DIGIT "0123456789"
#define TOKEN ALPHA DIGIT "-!#$%&'*+.^_`{|}~"
/* ========================================================================= */
/* Parsing functions */
......@@ -891,9 +892,7 @@ static void parse_bandwidth(sdp_parser_t *p, char *r, sdp_bandwidth_t **result)
{
/*
bandwidth-fields = *("b=" bwtype ":" bandwidth CRLF)
bwtype = 1*(alpha-numeric)
; CT or AS
bwtype = token
bandwidth = 1*(DIGIT)
*/
/* NOTE: bwtype can also be like X-barf */
......@@ -901,7 +900,7 @@ static void parse_bandwidth(sdp_parser_t *p, char *r, sdp_bandwidth_t **result)
char *name;
unsigned long value;
name = token(&r, ":", ALPHA DIGIT "-", SPACE TAB);
name = token(&r, ":", TOKEN, SPACE TAB);
if (name == NULL || parse_ul(p, &r, &value, 0)) {
parsing_error(p, "invalid bandwidth");
......@@ -941,16 +940,21 @@ static void parse_bandwidth(sdp_parser_t *p, char *r, sdp_bandwidth_t **result)
static void parse_time(sdp_parser_t *p, char *r, sdp_time_t **result)
{
/*
time-fields = 1*( "t=" start-time space stop-time
time-fields = 1*( "t=" start-time SP stop-time
*(CRLF repeat-fields) CRLF)
[zone-adjustments CRLF]
start-time = time | "0"
start-time = time / "0"
stop-time = time | "0"
stop-time = time / "0"
time = POS-DIGIT 9*(DIGIT)
;sufficient for 2 more centuries
time = POS-DIGIT 9*DIGIT
; Decimal representation of NTP time in
; seconds since 1900. The representation
; of NTP time is an unbounded length field
; containing at least 10 digits. Unlike the
; 64-bit representation used elsewhere, time
; in SDP does not wrap in the year 2036.
*/
PARSE_ALLOC(p, sdp_time_t, t);
*result = t;
......@@ -975,14 +979,13 @@ static void parse_time(sdp_parser_t *p, char *r, sdp_time_t **result)
static void parse_repeat(sdp_parser_t *p, char *d, sdp_repeat_t **result)
{
/*
repeat-fields = "r=" repeat-interval space typed-time
1*(space typed-time)
repeat-fields = %x72 "=" repeat-interval 2*(SP typed-time)
repeat-interval = typed-time
repeat-interval = POS-DIGIT *DIGIT [fixed-len-time-unit]
typed-time = 1*(DIGIT) [fixed-len-time-unit]
typed-time = 1*DIGIT [fixed-len-time-unit]
fixed-len-time-unit = "d" | "h" | "m" | "s"
fixed-len-time-unit = %x64 / %x68 / %x6d / %x73 ; "d" | "h" | "m" | "s"
*/
unsigned long tt, *interval;
......@@ -1129,17 +1132,15 @@ static void parse_key(sdp_parser_t *p, char *r, sdp_key_t **result)
/*
key-field = ["k=" key-type CRLF]
key-type = "prompt" |
"clear:" key-data |
"base64:" key-data |
"uri:" uri
key-data = email-safe | "~" | "
*/
s = token(&r, ":", ALPHA DIGIT "-", SPACE TAB);
s = token(&r, ":", TOKEN, SPACE TAB);
if (!s) {
parsing_error(p, "invalid key method");
return;
......@@ -1149,16 +1150,24 @@ static void parse_key(sdp_parser_t *p, char *r, sdp_key_t **result)
PARSE_ALLOC(p, sdp_key_t, k);
*result = k;
if (strcasecmp(s, "clear") == 0)
/* These are defined as key-sensitive in RFC 4566 */
#define MATCH(s, tok) \
(STRICT(p) ? strcmp((s), (tok)) == 0 : strcasecmp((s), (tok)) == 0)
if (MATCH(s, "clear"))
k->k_method = sdp_key_clear, k->k_method_name = "clear";
else if (strcasecmp(s, "base64") == 0)
else if (MATCH(s, "base64"))
k->k_method = sdp_key_base64, k->k_method_name = "base64";
else if (strcasecmp(s, "uri") == 0)
else if (MATCH(s, "uri"))
k->k_method = sdp_key_uri, k->k_method_name = "uri";
else if (strcasecmp(s, "prompt") == 0)
else if (MATCH(s, "prompt"))
k->k_method = sdp_key_prompt, k->k_method_name = "prompt";
else
else if (!STRICT(p))
k->k_method = sdp_key_x, k->k_method_name = s;
else {
parsing_error(p, "invalid key method");
return;
}
k->k_material = r;
}
......@@ -1180,16 +1189,16 @@ static void parse_session_attr(sdp_parser_t *p, char *r, sdp_attribute_t **resul
/*
attribute-fields = *("a=" attribute CRLF)
attribute = (att-field ":" att-value) | att-field
attribute = (att-field ":" att-value) / att-field
att-field = 1*(alpha-numeric)
att-field = token
att-value = byte-string
*/
char *name = NULL, *value = NULL;
if (!(name = token(&r, ":", ALPHA DIGIT "-", SPACE TAB))) {
if (!(name = token(&r, ":", TOKEN, SPACE TAB))) {
parsing_error(p,"invalid attribute name");
return;
}
......@@ -1248,15 +1257,15 @@ static void parse_media(sdp_parser_t *p, char *r, sdp_media_t **result)
media-field = "m=" media space port ["/" integer]
space proto 1*(space fmt) CRLF
media = 1*(alpha-numeric)
media = token
;typically "audio", "video", "application"
;or "data"
fmt = 1*(alpha-numeric)
fmt = token
;typically an RTP payload type for audio
;and video media
proto = 1*(alpha-numeric)
proto = token *("/" token)
;typically "RTP/AVP" or "udp" for IP4
port = 1*(DIGIT)
......@@ -1270,9 +1279,7 @@ static void parse_media(sdp_parser_t *p, char *r, sdp_media_t **result)
m->m_mode = sdp_sendrecv;
s = token(&r, SPACE, ALPHA DIGIT, NULL);
if (s == NULL && p->pr_config)
s = token(&r, SPACE, "*", NULL);
s = token(&r, SPACE, TOKEN, NULL);
if (!s) {
parsing_error(p, "m= invalid media field");
return;
......@@ -1304,10 +1311,7 @@ static void parse_media(sdp_parser_t *p, char *r, sdp_media_t **result)
m->m_number_of_ports = value;
}
/* alpha-numeric and "/" */
s = token(&r, SPACE, ALPHA DIGIT "/", SPACE);
if (s == NULL && p->pr_config)
s = token(&r, SPACE, "*", SPACE);
s = token(&r, SPACE, "/" TOKEN, SPACE);
if (s == NULL) {
parsing_error(p, "m= missing protocol");
return;
......@@ -1331,7 +1335,7 @@ static void parse_media(sdp_parser_t *p, char *r, sdp_media_t **result)
while (r && *r) {
PARSE_ALLOC(p, sdp_list_t, l);
*fmt = l;
l->l_text = next(&r, SPACE TAB, SPACE TAB);
l->l_text = token(&r, SPACE TAB, TOKEN, SPACE TAB);
fmt = &l->l_next;
}
}
......@@ -1536,9 +1540,9 @@ static void parse_media_attr(sdp_parser_t *p, char *r, sdp_media_t *m,
/*
attribute-fields = *("a=" attribute CRLF)
attribute = (att-field ":" att-value) | att-field
attribute = (att-field ":" att-value) / att-field
att-field = 1*(alpha-numeric)
att-field = token
att-value = byte-string
......@@ -1549,7 +1553,7 @@ static void parse_media_attr(sdp_parser_t *p, char *r, sdp_media_t *m,
char *name = NULL, *value = NULL;
int n;
if (!(name = token(&r, ":", ALPHA DIGIT "-", SPACE TAB))) {
if (!(name = token(&r, ":", TOKEN, SPACE TAB))) {
parsing_error(p,"invalid attribute name");
return;
}
......@@ -1623,7 +1627,7 @@ static int parse_rtpmap(sdp_parser_t *p, char *r, sdp_media_t *m)
return -1;
}
encoding = token(&r, "/", ALPHA DIGIT "-", NULL);
encoding = token(&r, "/", TOKEN, NULL);
if (!r) {
parsing_error(p, "a=rtpmap:%lu: missing <clock rate>", pt);
return -2;
......
v=0
o=- 3250588766 0 IN IP4 77.75.1.10
s=-
c=IN IP4 77.75.1.10
t=0 0
m=audio 54424 RTP/AVP 18 99 101 102 103 15 104 4 105 106 107 108 125 109 100 8 0
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:99 G.729a/8000
a=rtpmap:101 G.726-16/8000
a=rtpmap:102 G.726-24/8000
a=rtpmap:103 G.726-32/8000
a=rtpmap:15 G728/8000
a=rtpmap:104 G.723.1-H/8000
a=rtpmap:4 G723/8000
a=rtpmap:105 G.723.1-L/8000
a=rtpmap:106 G.729b/8000
a=rtpmap:107 G.723.1a-H/8000
a=rtpmap:108 G.723.1a-L/8000
a=rtpmap:125 G.nX64/8000
a=rtpmap:109 AMR/8000
a=rtpmap:100 X-NSE/8000
a=fmtp:100 192-194,200-202
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=maxptime:20
a=maxptime:30
a=ptime:20
a=ptime:30
a=X-cap: 1 audio RTP/AVP 100
a=X-cap: 2 image udptl t38
a=X-sqn:0
a=X-cpar: a=rtpmap:100 X-NSE/8000
a=X-cpar: a=fmtp:100 192-194,200-202
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment