Commit 2365af8b authored by jehan's avatar jehan

check malformed sdp origin field

parent 1d1d287c
......@@ -66,21 +66,36 @@ scope { belle_sdp_session_description_t* current; }
(attribute {belle_sdp_session_description_add_attribute($session_description::current,$attribute.ret);} CR LF)*
(media_description {belle_sdp_session_description_add_media_description($session_description::current,$media_description.ret);}) *;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] on [\%s] reason [\%s]",(const char*)EXCEPTION->name, (const char*)EXCEPTION->ruleName, (const char*)EXCEPTION->message);
belle_sip_object_unref($session_description::current);
$ret=NULL;
}
version: {IS_TOKEN(v)}?alpha_num EQUAL v=DIGIT+ {belle_sdp_version_t* version =belle_sdp_version_new();
belle_sdp_version_set_version(version,atoi((const char*)$v.text->chars));
belle_sdp_session_description_set_version($session_description::current,version);};
// ;this memo describes version 0
origin returns [belle_sdp_origin_t* ret]
scope { belle_sdp_origin_t* current; }
@init {$origin::current = belle_sdp_origin_new(); $ret=$origin::current; }
: {IS_TOKEN(o)}?alpha_num EQUAL username {belle_sdp_origin_set_username($origin::current,(const char*)$username.text->chars);}
SPACE sess_id {belle_sdp_origin_set_session_id($origin::current,atoi((const char*)$sess_id.text->chars));}
SPACE sess_version {belle_sdp_origin_set_session_version($origin::current,atoi((const char*)$sess_version.text->chars));}
SPACE sess_id {if ($sess_id.text->chars) belle_sdp_origin_set_session_id($origin::current,atoi((const char*)$sess_id.text->chars));}
SPACE sess_version {if ($sess_version.text->chars) belle_sdp_origin_set_session_version($origin::current,atoi((const char*)$sess_version.text->chars));}
SPACE nettype {belle_sdp_origin_set_network_type($origin::current,(const char*)$nettype.text->chars);}
SPACE addrtype {belle_sdp_origin_set_address_type($origin::current,(const char*)$addrtype.text->chars);}
SPACE addr {belle_sdp_origin_set_address($origin::current,(const char*)$addr.text->chars);} ;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] on [\%s] reason [\%s]",(const char*)EXCEPTION->name, (const char*)EXCEPTION->ruleName, (const char*)EXCEPTION->message);
belle_sip_object_unref($origin::current);
$ret=NULL;
}
session_name: {IS_TOKEN(s)}? alpha_num EQUAL text {belle_sdp_session_name_t* session_name =belle_sdp_session_name_new();
belle_sdp_session_name_set_value(session_name,(const char*)$text.text->chars);
belle_sdp_session_description_set_session_name($session_description::current,session_name);};
......@@ -194,7 +209,7 @@ att_field: token+;
att_value options { greedy = false; }: ~(CR|LF)*;
sess_id: DIGIT*;
sess_id: DIGIT+;
// ;should be unique for this originating username/host
sess_version: DIGIT+;
......
......@@ -86,6 +86,27 @@ static void test_bandwidth(void) {
belle_sip_free(l_raw_bandwidth);
}
static void test_origin(void) {
belle_sdp_origin_t* lTmp;
belle_sdp_origin_t* lOrigin = belle_sdp_origin_parse("o=jehan-mac 3800 2558 IN IP4 192.168.0.165");
char* l_raw_origin = belle_sip_object_to_string(BELLE_SIP_OBJECT(lOrigin));
belle_sip_object_unref(BELLE_SIP_OBJECT(lOrigin));
lTmp = belle_sdp_origin_parse(l_raw_origin);
lOrigin = BELLE_SDP_ORIGIN(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address(lOrigin), "192.168.0.165");
CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address_type(lOrigin), "IP4");
CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_network_type(lOrigin), "IN");
belle_sip_object_unref(BELLE_SIP_OBJECT(lOrigin));
belle_sip_free(l_raw_origin);
}
static void test_malformed_origin(void) {
belle_sdp_origin_t* lOrigin = belle_sdp_origin_parse("o=Jehan Monnier 3800 2558 IN IP4 192.168.0.165");
CU_ASSERT_PTR_NOT_NULL(lOrigin);
}
static void test_connection(void) {
belle_sdp_connection_t* lTmp;
belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP4 192.168.0.18");
......@@ -454,7 +475,9 @@ test_t sdp_tests[] = {
{ "a= (attribute)", test_attribute },
{ "a= (attribute) 2", test_attribute_2 },
{ "b= (bandwidth)", test_bandwidth },
{ "c= (IPv4 connection)", test_connection },
{ "o= (IPv4 origin)", test_connection },
{ "o= (malformed origin)", test_malformed_origin },
{ "c= (IPv4 connection)", test_origin },
{ "c= (IPv6 connection)", test_connection_6 },
{ "e= (email)", test_email },
{ "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