Commit 28a8e44d authored by jehan's avatar jehan

better error repporting + support for non numerical media fmt

parent 0aa7fdf8
......@@ -111,11 +111,13 @@ BELLESIP_EXPORT belle_sdp_media_t* belle_sdp_media_create(const char* media_type
,const char* protocol
,belle_sip_list_t* static_media_formats);
BELLESIP_EXPORT belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* media);
BELLESIP_EXPORT const char* belle_sdp_media_get_raw_fmt(const belle_sdp_media_t* media);
BELLESIP_EXPORT int belle_sdp_media_get_media_port(const belle_sdp_media_t* media);
BELLESIP_EXPORT const char* belle_sdp_media_get_media_type(const belle_sdp_media_t* media);
BELLESIP_EXPORT int belle_sdp_media_get_port_count(const belle_sdp_media_t* media);
BELLESIP_EXPORT const char* belle_sdp_media_get_protocol(const belle_sdp_media_t* media);
BELLESIP_EXPORT void belle_sdp_media_set_media_formats(belle_sdp_media_t* media, belle_sip_list_t* mediaFormats);
BELLESIP_EXPORT void belle_sdp_media_set_raw_fmt(belle_sdp_media_t* media, const char* fmt);
BELLESIP_EXPORT void belle_sdp_media_set_media_port(belle_sdp_media_t* media, int port);
BELLESIP_EXPORT void belle_sdp_media_set_media_type(belle_sdp_media_t* media, const char* mediaType);
BELLESIP_EXPORT void belle_sdp_media_set_port_count(belle_sdp_media_t* media, int port_count);
......
......@@ -10,7 +10,7 @@ generated_src= \
belle_sdpLexer.c belle_sdpLexer.h
$(builddir)/generated_src_stamp : $(grammar_files)
$(ANTLR) -make -fo $(builddir) $(grammar_files)
$(ANTLR) -fo $(builddir) $(grammar_files)
touch $(builddir)/generated_src_stamp
$(generated_src) : $(builddir)/generated_src_stamp
......
......@@ -42,6 +42,18 @@ options {
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
}
@rulecatch
{
if (HASEXCEPTION())
{
// This is ugly. We set the exception type to ANTLR3_RECOGNITION_EXCEPTION so we can always
// catch them.
//PREPORTERROR();
EXCEPTION->type = ANTLR3_RECOGNITION_EXCEPTION;
}
}
@includes {
#include "belle-sip/belle-sdp.h"
#include "belle_sip_internal.h"
......@@ -60,7 +72,7 @@ scope { belle_sdp_session_description_t* current; }
(connection {belle_sdp_session_description_set_connection($session_description::current,$connection.ret);} CR LF)?
(bandwidth {belle_sdp_session_description_add_bandwidth($session_description::current,$bandwidth.ret);} CR LF)*
time_field CR LF
(repeat_time CR LF)?
(repeat_time CR LF)*
(zone_adjustments CR LF)?
(key_field CR LF)?
(attribute {belle_sdp_session_description_add_attribute($session_description::current,$attribute.ret);} CR LF)*
......@@ -68,7 +80,7 @@ scope { belle_sdp_session_description_t* current; }
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_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($session_description::current);
$ret=NULL;
}
......@@ -91,7 +103,7 @@ scope { belle_sdp_origin_t* current; }
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_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($origin::current);
$ret=NULL;
}
......@@ -126,13 +138,24 @@ scope { belle_sdp_connection_t* current; }
//;a connection field must be present
//;in every media description or at the
//;session-level
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
bandwidth returns [belle_sdp_bandwidth_t* ret]
scope { belle_sdp_bandwidth_t* current; }
@init {$bandwidth::current = belle_sdp_bandwidth_new(); $ret=$bandwidth::current; }
: {IS_TOKEN(b)}?alpha_num EQUAL bwtype {belle_sdp_bandwidth_set_type($bandwidth::current,(const char*)$bwtype.text->chars); }
COLON bandwidth_value {belle_sdp_bandwidth_set_value($bandwidth::current,atoi((const char*)$bandwidth_value.text->chars));};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
time_field: {IS_TOKEN(t)}?alpha_num EQUAL
start_time
SPACE
......@@ -147,7 +170,7 @@ time_field: {IS_TOKEN(t)}?alpha_num EQUAL
repeat_time: {IS_TOKEN(r)}?alpha_num EQUAL repeat_interval (SPACE typed_time)+;
zone_adjustments: sdp_time SPACE '-'? typed_time
zone_adjustments: {IS_TOKEN(z)}? alpha_num EQUAL sdp_time SPACE '-'? typed_time
(SPACE sdp_time SPACE '-'? typed_time)*;
key_field: {IS_TOKEN(k)}?alpha_num EQUAL key_value ;
......@@ -174,7 +197,12 @@ scope { belle_sdp_media_description_t* current; }
(key_field CR LF)?
(attribute {belle_sdp_media_description_add_attribute($media_description::current,$attribute.ret);} CR LF)*;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
media returns [belle_sdp_media_t* ret]
scope { belle_sdp_media_t* current; }
@init {$media::current = belle_sdp_media_new(); $ret=$media::current; }
......@@ -183,15 +211,23 @@ scope { belle_sdp_media_t* current; }
SPACE port {belle_sdp_media_set_media_port($media::current,atoi((const char*)$port.text->chars));}
(SLASH integer{belle_sdp_media_set_port_count($media::current,atoi((const char*)$integer.text->chars));})?
SPACE proto {belle_sdp_media_set_protocol($media::current,(const char*)$proto.text->chars);}
(SPACE fmt)*;
(SPACE fmt)+;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
media_value: alpha_num+;
// ;typically "audio", "video", "application"
// ;or "data"
fmt: DIGIT+ {belle_sdp_media_set_media_formats($media::current
,belle_sip_list_append(belle_sdp_media_get_media_formats($media::current)
,(void*)(long)atoi((const char*)$fmt.text->chars)));};
fmt
scope { int is_number; }
@init { $fmt::is_number=0;}: ((DIGIT+)=>(DIGIT+){$fmt::is_number=1;} | token+ )
{belle_sdp_media_set_media_formats($media::current
,belle_sip_list_append(belle_sdp_media_get_media_formats($media::current)
,(void*)($fmt::is_number?(long)atoi((const char*)$fmt.text->chars):$fmt.text->chars)));};
//;typically an RTP payload type for audio
//;and video media
proto options { greedy = false; }: ~(SPACE|CR|LF)*;
......
......@@ -183,6 +183,7 @@ struct _belle_sdp_media {
belle_sip_list_t* media_formats;
int port_count;
const char* protocol;
const char* raw_fmt;
};
belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* media) {
return media->media_formats;
......
......@@ -104,7 +104,7 @@ static void test_origin(void) {
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);
CU_ASSERT_PTR_NULL(lOrigin);
}
static void test_connection(void) {
......@@ -313,6 +313,24 @@ static void test_simple_session_description(void) {
return;
}
static void test_image_mline() {
const char * sdp = "v=0\r\n"
"o=cp10 138884701697 138884701699 IN IP4 10.7.1.133\r\n"
"s=SIP Call\r\n"
"c=IN IP4 91.121.128.144\r\n"
"t=0 0\r\n"
"m=image 33802 udptl t38\r\n"
"a=sendrecv\r\n"
"a=T38FaxVersion:0\r\n"
"a=T38MaxBitRate:9600\r\n"
"a=T38FaxRateManagement:transferredTCF\r\n"
"a=T38FaxMaxBuffer:1000\r\n"
"a=T38FaxMaxDatagram:200\r\n"
"a=T38FaxUdpEC:t38UDPRedundancy\r\n";
belle_sdp_session_description_t* l_session_description = belle_sdp_session_description_parse(sdp);
belle_sip_object_unref(l_session_description);
}
static const char* big_sdp = "v=0\r\n"\
"o=jehan-mac 1239 1239 IN IP6 2a01:e35:1387:1020:6233:4bff:fe0b:5663\r\n"\
"s=SIP Talk\r\n"\
......@@ -449,6 +467,7 @@ static void test_mime_parameter(void) {
belle_sdp_mime_parameter_t* l_param;
belle_sdp_mime_parameter_t* lTmp;
belle_sdp_media_t* l_media;
belle_sdp_media_description_t* l_media_description_tmp = belle_sdp_media_description_parse(l_src);
belle_sdp_media_description_t* l_media_description = belle_sdp_media_description_parse(belle_sip_object_to_string(l_media_description_tmp));
......@@ -460,7 +479,11 @@ static void test_mime_parameter(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
l_media_description = belle_sdp_media_description_new();
belle_sdp_media_description_set_media(l_media_description,belle_sdp_media_parse("m=audio 7078 RTP/AVP"));
belle_sdp_media_description_set_media(l_media_description,l_media=belle_sdp_media_parse("m=audio 7078 RTP/AVP 0"));
belle_sdp_media_set_media_formats(l_media,belle_sip_list_free(belle_sdp_media_get_media_formats(l_media))); /*to remove 0*/
for (;mime_parameter_list_iterator!=NULL;mime_parameter_list_iterator=mime_parameter_list_iterator->next) {
belle_sdp_media_description_append_values_from_mime_parameter(l_media_description,(belle_sdp_mime_parameter_t*)mime_parameter_list_iterator->data);
}
......@@ -537,6 +560,7 @@ test_t sdp_tests[] = {
{ "Media description", test_media_description },
{ "Simple session description", test_simple_session_description },
{ "Session description", test_session_description },
{ "Session description for fax", test_image_mline },
{ "Marshal buffer overflow", test_overflow }
};
......
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