Commit e4d52ca7 authored by jehan's avatar jehan

rework sdp grammar a bit

parent cc49a54f
...@@ -70,7 +70,11 @@ belle_sdp_attribute_t* belle_sdp_attribute_create(const char* name, const char* ...@@ -70,7 +70,11 @@ belle_sdp_attribute_t* belle_sdp_attribute_create(const char* name, const char*
for (i = 0; i < elements; i++) { for (i = 0; i < elements; i++) {
if (strcasecmp(attribute_table[i].name, name) == 0) { if (strcasecmp(attribute_table[i].name, name) == 0) {
char* raw = belle_sip_strdup_printf("a=%s:%s", name, value); char* raw;
if (value)
raw = belle_sip_strdup_printf("a=%s:%s", name, value);
else
raw = belle_sip_strdup_printf("a=%s", name);
ret = attribute_table[i].func(raw); ret = attribute_table[i].func(raw);
belle_sip_free(raw); belle_sip_free(raw);
return ret; return ret;
......
...@@ -232,11 +232,10 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION] ...@@ -232,11 +232,10 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
attribute_content returns [belle_sdp_attribute_t* ret] attribute_content returns [belle_sdp_attribute_t* ret]
//options { greedy = false; } //options { greedy = false; }
@init {$ret=NULL;} @init {$ret=NULL; }
: (attribute_name COLON attribute_value) { : attribute_name (COLON val=attribute_value {$ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,(const char*)$attribute_value.text->chars);})?
$ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,(const char*)$attribute_value.text->chars); {
}| attribute_name { if (!val.tree) $ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,NULL);
$ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,NULL);
}; };
rtcp_xr_attribute returns [belle_sdp_rtcp_xr_attribute_t* ret] rtcp_xr_attribute returns [belle_sdp_rtcp_xr_attribute_t* ret]
...@@ -249,17 +248,26 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION] ...@@ -249,17 +248,26 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
belle_sip_object_unref($ret); belle_sip_object_unref($ret);
$ret=NULL; $ret=NULL;
} }
rtcp_xr_attribute_value rtcp_xr_attribute_value :
: ({IS_TOKEN(rcvr-rtt)}? rtcp_xr_attribute_name /*'rcvr-rtt'*/ EQUAL {IS_TOKEN(all) || IS_TOKEN(sender)}? rtcp_xr_rcvr_rtt_mode { (rcvr_rtt)=> rcvr_rtt
| (stat_summary)=> stat_summary
| (voip_metrics)=>voip_metrics;
rcvr_rtt :
{IS_TOKEN(rcvr-rtt)}? rtcp_xr_attribute_name /*'rcvr-rtt'*/ EQUAL {IS_TOKEN(all) || IS_TOKEN(sender)}? rtcp_xr_rcvr_rtt_mode {
belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_mode($rtcp_xr_attribute::current,(const char*)$rtcp_xr_rcvr_rtt_mode.text->chars); belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_mode($rtcp_xr_attribute::current,(const char*)$rtcp_xr_rcvr_rtt_mode.text->chars);
}) };
| ({IS_TOKEN(stat-summary)}? rtcp_xr_attribute_name /*'stat-summary'*/ {
belle_sdp_rtcp_xr_attribute_set_stat_summary($rtcp_xr_attribute::current,1); stat_summary :
} (EQUAL rtcp_xr_stat_summary_flag (COMMA rtcp_xr_stat_summary_flag)*)?) {IS_TOKEN(stat-summary)}? rtcp_xr_attribute_name /*'stat-summary'*/ {
| ({IS_TOKEN(voip-metrics)}? rtcp_xr_attribute_name /*'voip-metrics'*/ { belle_sdp_rtcp_xr_attribute_set_stat_summary($rtcp_xr_attribute::current,1);
belle_sdp_rtcp_xr_attribute_set_voip_metrics($rtcp_xr_attribute::current,1); } (EQUAL rtcp_xr_stat_summary_flag (COMMA rtcp_xr_stat_summary_flag)*)?;
});
voip_metrics :
{IS_TOKEN(voip-metrics)}? rtcp_xr_attribute_name /*'voip-metrics'*/ {
belle_sdp_rtcp_xr_attribute_set_voip_metrics($rtcp_xr_attribute::current,1);
};
rtcp_xr_stat_summary_flag rtcp_xr_stat_summary_flag
: {IS_TOKEN(loss) || IS_TOKEN(dup) || IS_TOKEN(jitt) || IS_TOKEN(TTL) || IS_TOKEN(HL)}?rtcp_xr_stat_summary_flag_value { : {IS_TOKEN(loss) || IS_TOKEN(dup) || IS_TOKEN(jitt) || IS_TOKEN(TTL) || IS_TOKEN(HL)}?rtcp_xr_stat_summary_flag_value {
belle_sdp_rtcp_xr_attribute_add_stat_summary_flag($rtcp_xr_attribute::current,(const char*)$rtcp_xr_stat_summary_flag_value.text->chars); belle_sdp_rtcp_xr_attribute_add_stat_summary_flag($rtcp_xr_attribute::current,(const char*)$rtcp_xr_stat_summary_flag_value.text->chars);
...@@ -413,21 +421,22 @@ text : ~(CR|LF)* ; ...@@ -413,21 +421,22 @@ text : ~(CR|LF)* ;
//ISO 8859-1 requires a "a=charset:ISO-8859-1" //ISO 8859-1 requires a "a=charset:ISO-8859-1"
//session-level attribute to be used //session-level attribute to be used
byte_string options { greedy = false; }: (.)* ; byte_string options { greedy = false; }: (OCTET)* ;
//any byte except NUL, CR or LF //any byte except NUL, CR or LF
decimal_uchar: integer;// (d+=DIGIT+ {$d !=NULL && $d->count<=3}?) decimal_uchar: integer;// (d+=DIGIT+ {$d !=NULL && $d->count<=3}?)
integer: DIGIT+; integer: DIGIT+;
email_safe : byte_string; email_safe : ~(SPACE)*;
token : (alpha_num | '!' | '#' | '$' |'&'| '%'| '\'' | '*' |'+' | DASH | DOT)+; token : (alpha_num | '!' | '#' | '$' |'&'| '%'| '\'' | '*' |'+' | DASH | DOT)+;
alpha_num: (alpha | DIGIT) ; alpha_num: (alpha | DIGIT) ;
hexdigit: (HEX_CHAR | DIGIT) ; hexdigit: (HEX_CHAR | DIGIT) ;
alpha: (COMMON_CHAR | HEX_CHAR);
word: (alpha | DASH)+; word: (alpha | DASH)+;
alpha: COMMON_CHAR | HEX_CHAR;
DIGIT: ZERO | POS_DIGIT; DIGIT: ZERO | POS_DIGIT;
fragment ZERO: '0'; fragment ZERO: '0';
...@@ -450,4 +459,4 @@ COLON: ':'; ...@@ -450,4 +459,4 @@ COLON: ':';
SLASH: '/'; SLASH: '/';
DASH: '-'; DASH: '-';
COMMA: ','; COMMA: ',';
ANY_EXCEPT_CR_LF: ~(CR|LF); OCTET : .;
...@@ -79,31 +79,31 @@ static void test_rtcp_xr_attribute(void) { ...@@ -79,31 +79,31 @@ static void test_rtcp_xr_attribute(void) {
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == FALSE); CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == FALSE);
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute)); belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:rcvr-rtt=all")); lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:rcvr-rtt=all"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr"); CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_STRING_EQUAL(belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(lAttribute), "all"); CU_ASSERT_STRING_EQUAL(belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(lAttribute), "all");
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/ belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:stat-summary")); lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:stat-summary"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr"); CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_PTR_NULL(belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(lAttribute)); CU_ASSERT_PTR_NULL(belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(lAttribute));
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == TRUE); CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == TRUE);
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == FALSE); CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == FALSE);
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/ belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:stat-summary=loss,jitt")); lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:stat-summary=loss,jitt"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr"); CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == TRUE); CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == TRUE);
CU_ASSERT_PTR_NOT_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "loss")); CU_ASSERT_PTR_NOT_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "loss"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "jitt")); CU_ASSERT_PTR_NOT_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "jitt"));
CU_ASSERT_PTR_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "HL")); CU_ASSERT_PTR_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "HL"));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/ belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:voip-metrics")); lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:voip-metrics"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr"); CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == FALSE); CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == FALSE);
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == TRUE); CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == TRUE);
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/ belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
} }
static void test_bandwidth(void) { static void test_bandwidth(void) {
...@@ -584,9 +584,9 @@ test_t sdp_tests[] = { ...@@ -584,9 +584,9 @@ test_t sdp_tests[] = {
{ "a= (attribute) 2", test_attribute_2 }, { "a= (attribute) 2", test_attribute_2 },
{ "a=rtcp-xr", test_rtcp_xr_attribute }, { "a=rtcp-xr", test_rtcp_xr_attribute },
{ "b= (bandwidth)", test_bandwidth }, { "b= (bandwidth)", test_bandwidth },
{ "o= (IPv4 origin)", test_connection }, { "o= (IPv4 origin)", test_origin },
{ "o= (malformed origin)", test_malformed_origin }, { "o= (malformed origin)", test_malformed_origin },
{ "c= (IPv4 connection)", test_origin }, { "c= (IPv4 connection)", test_connection },
{ "c= (IPv6 connection)", test_connection_6 }, { "c= (IPv6 connection)", test_connection_6 },
{ "e= (email)", test_email }, { "e= (email)", test_email },
{ "i= (info)", test_info }, { "i= (info)", test_info },
......
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