Commit 8827e51c authored by jehan's avatar jehan

fix keep alive parsing

parent 70be244d
......@@ -135,7 +135,7 @@ zone_adjustments: sdp_time SPACE '-'? typed_time
(SPACE sdp_time SPACE '-'? typed_time)*;
key_field: {IS_TOKEN(k)}?alpha_num EQUAL key_value ;
key_value options { greedy = false; }: ~(CR|LF)*;
key_value options { greedy = false; }: (~(CR|LF))*;
//key_type: {IS_TOKEN(prompt)}? alpha_num* /*'prompt'*/ |
// {IS_TOKEN(clear)}? alpha_num* /*'clear'*/ COLON key_data |
// {IS_TOKEN(base64)}? alpha_num* /*'base64*/ COLON key_data |
......@@ -155,7 +155,7 @@ scope { belle_sdp_media_description_t* current; }
(info {belle_sdp_media_description_set_info($media_description::current,$info.ret);} CR LF)?
(connection { belle_sdp_media_description_set_connection($media_description::current,$connection.ret);} CR LF)?
(bandwidth {belle_sdp_media_description_add_bandwidth($media_description::current,$bandwidth.ret);} CR LF)*
key_field ?
(key_field CR LF)?
(attribute {belle_sdp_media_description_add_attribute($media_description::current,$attribute.ret);} CR LF)*;
......@@ -189,7 +189,7 @@ attribute_value: (att_field {belle_sdp_attribute_set_name($attribute::
COLON att_value {belle_sdp_attribute_set_value($attribute::current,(const char*)$att_value.text->chars);})
| att_field {belle_sdp_attribute_set_name($attribute::current,(const char*)$att_field.text->chars);};
att_field: alpha_num+;
att_field: token+;
att_value options { greedy = false; }: ~(CR|LF)*;
......@@ -266,7 +266,7 @@ b4: decimal_uchar;
//ip6_address : ;//to be defined
text : byte_string;
text : ~(CR|LF)*;
//default is to interpret this as IS0-10646 UTF8
//ISO 8859-1 requires a "a=charset:ISO-8859-1"
//session-level attribute to be used
......@@ -280,6 +280,7 @@ integer: POS_DIGIT DIGIT*;
email_safe : byte_string;
token : alpha_num | '!' | '#' | '$' |'&'| '%'| '\'' | '*' |'+' | '-' | '.' ;
alpha_num: ALPHA | DIGIT;
......
......@@ -128,7 +128,10 @@ GET_SET_STRING(belle_sip_header_address,displayname);
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value) {
if (address->displayname != NULL) belle_sip_free((void*)(address->displayname));
address->displayname=_belle_sip_str_dup_and_unquote_string(value);
if (strlen(value)>2)
address->displayname=_belle_sip_str_dup_and_unquote_string(value);
else
address->displayname=NULL;
}
belle_sip_uri_t* belle_sip_header_address_get_uri(const belle_sip_header_address_t* address) {
return address->uri;
......
......@@ -91,6 +91,7 @@ static int get_message_start_pos(char *buff, size_t bufflen) {
int status_code;
char method[16];
char saved_char1;
char sip_version[9];
int saved_char1_index;
for(i=0; i<bufflen-12;i++) { /*9=strlen( SIP/2.0\r\n)*/
......@@ -99,7 +100,8 @@ static int get_message_start_pos(char *buff, size_t bufflen) {
buff[saved_char1_index]='\0';
res=sscanf(buff+i,"SIP/2.0 %d ",&status_code);
if (res!=1) {
res=sscanf(buff+i,"%16s %*s SIP/2.0 ",method);
res= sscanf(buff+i,"%16s %*s %s\r\n",method,sip_version)==2
&& strcmp("SIP/2.0",sip_version)==0 ;
}
buff[saved_char1_index]=saved_char1;
if (res==1) return i;
......@@ -158,7 +160,7 @@ void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revent
}
obj->input_stream.state=MESSAGE_AQUISITION;
} else {
belle_sip_warning("Unexpected [%s] received on channel [%p], trashing",obj->input_stream.write_ptr,obj);
belle_sip_warning("Unexpected [%s] received on channel [%p], trashing",obj->input_stream.read_ptr,obj);
belle_sip_channel_input_stream_reset(&obj->input_stream,0);
}
}
......
......@@ -266,7 +266,7 @@ int belle_sip_dialog_update(belle_sip_dialog_t *obj,belle_sip_request_t *req, be
}
obj->needs_ack=TRUE;
}else if (strcmp(belle_sip_request_get_method(req),"BYE")==0 && code>=200 && code<300){
if (obj->terminate_on_bye) belle_sip_dialog_delete(obj);
if (obj->terminate_on_bye && as_uas /*only when receive 200ok from BYE*/) belle_sip_dialog_delete(obj);
}
break;
case BELLE_SIP_DIALOG_TERMINATED:
......@@ -345,7 +345,7 @@ belle_sip_request_t *belle_sip_dialog_create_ack(belle_sip_dialog_t *obj, unsign
belle_sip_request_t *belle_sip_dialog_create_request(belle_sip_dialog_t *obj, const char *method){
if (obj->state != BELLE_SIP_DIALOG_CONFIRMED && obj->state != BELLE_SIP_DIALOG_EARLY) {
belle_sip_error("Cannot create method [%s] from dialog [%p] in state [%s]",method,obj,belle_sip_dialog_state_to_string(obj->dialog));
belle_sip_error("Cannot create method [%s] from dialog [%p] in state [%s]",method,obj,belle_sip_dialog_state_to_string(obj->state));
return NULL;
}
if (obj->local_cseq==0) obj->local_cseq=110;
......
......@@ -40,7 +40,11 @@ static int udp_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
int err;
err=sendto(chan->sock,buf,buflen,0,obj->peer->ai_addr,obj->peer->ai_addrlen);
if (err==-1){
belle_sip_fatal("Could not send UDP packet: %s",strerror(errno));
belle_sip_error("Could not send UDP packet: from [%s:%i] to [%s:%i] because [%s]",obj->local_ip
,obj->local_port
,obj->peer_name
,obj->peer_port
,strerror(errno));
return -errno;
}
return err;
......
......@@ -125,7 +125,10 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
}
if (chan){
/*notify the channel*/
belle_sip_message("Notifying channel.");
belle_sip_message("Notifying udp channel, local [%s:%i] remote [%s:%i], [%i]",chan->local_ip
,chan->local_port
,chan->peer_name
,chan->peer_port);
belle_sip_channel_process_data(chan,events);
}
}
......
......@@ -46,6 +46,7 @@ static int clean_suite_sdp(void) {
//a=rtpmap:98 H263-1998/90000
//a=fmtp:98 CIF=1;QCIF=1
static void test_attribute(void) {
belle_sdp_attribute_t* lTmp;
belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse("a=rtpmap:101 telephone-event/8000");
......@@ -60,6 +61,20 @@ static void test_attribute(void) {
CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
}
static void test_attribute_2(void) {
belle_sdp_attribute_t* lTmp;
belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse("a=ice-pwd:31ec21eb38b2ec6d36e8dc7b\r\n");
char* l_raw_attribute = belle_sip_object_to_string(BELLE_SIP_OBJECT(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
lTmp = belle_sdp_attribute_parse(l_raw_attribute);
belle_sip_free(l_raw_attribute);
lAttribute = BELLE_SDP_ATTRIBUTE(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(lAttribute), "ice-pwd");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value(lAttribute), "31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
}
static void test_bandwidth(void) {
belle_sdp_bandwidth_t* lTmp;
belle_sdp_bandwidth_t* l_bandwidth = belle_sdp_bandwidth_parse("b=AS:380");
......@@ -198,7 +213,7 @@ static void test_media_description(void) {
belle_sip_free(l_raw_media_description);
return;
}
static void test_session_description(void) {
static void simple_session_description(void) {
const char* l_src = "v=0\r\n"\
"o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\
"s=Talk\r\n"\
......@@ -258,6 +273,68 @@ static void test_session_description(void) {
return;
}
static void test_session_description(void) {
const char* l_src = "v=0\r\n"\
"o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\
"s=SIP Talk\r\n"\
"c=IN IP4 192.168.0.18\r\n"\
"b=AS:380\r\n"\
"t=0 0\r\n"\
"a=ice-pwd:31ec21eb38b2ec6d36e8dc7b\r\n"\
"m=audio 7078 RTP/AVP 111 110 3 0 8 101\r\n"\
"a=rtpmap:111 speex/16000\r\n"\
"a=fmtp:111 vbr=on\r\n"\
"a=rtpmap:110 speex/8000\r\n"\
"a=fmtp:110 vbr=on\r\n"\
"a=rtpmap:101 telephone-event/8000\r\n"\
"a=fmtp:101 0-11\r\n"\
"m=video 8078 RTP/AVP 99 97 98\r\n"\
"c=IN IP4 192.168.0.18\r\n"\
"b=AS:380\r\n"\
"a=rtpmap:99 MP4V-ES/90000\r\n"\
"a=fmtp:99 profile-level-id=3\r\n"\
"a=rtpmap:97 theora/90000\r\n"\
"a=rtpmap:98 H263-1998/90000\r\n"\
"a=fmtp:98 CIF=1;QCIF=1\r\n";
belle_sdp_session_description_t* lTmp;
belle_sdp_session_description_t* l_session_description = belle_sdp_session_description_parse(l_src);
char* l_raw_session_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_session_description));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_session_description));
lTmp = belle_sdp_session_description_parse(l_raw_session_description);
belle_sip_free(l_raw_session_description);
l_session_description = BELLE_SDP_SESSION_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_version(l_session_description));
CU_ASSERT_EQUAL(belle_sdp_version_get_version(belle_sdp_session_description_get_version(l_session_description)),0);
belle_sdp_origin_t* l_origin = belle_sdp_session_description_get_origin(l_session_description);
CU_ASSERT_PTR_NOT_NULL(l_origin);
CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address(l_origin),"192.168.0.18")
CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address_type(l_origin),"IP4")
CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_network_type(l_origin),"IN")
CU_ASSERT_EQUAL(belle_sdp_origin_get_session_id(l_origin),1239)
CU_ASSERT_EQUAL(belle_sdp_origin_get_session_version(l_origin),1239)
CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_session_name(l_session_description));
CU_ASSERT_STRING_EQUAL(belle_sdp_session_name_get_value(belle_sdp_session_description_get_session_name(l_session_description)),"SIP Talk");
CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_connection(l_session_description));
CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_time_descriptions(l_session_description));
CU_ASSERT_EQUAL(belle_sdp_time_get_start(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0);
CU_ASSERT_EQUAL(belle_sdp_time_get_stop(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0);
belle_sip_list_t* media_descriptions = belle_sdp_session_description_get_media_descriptions(l_session_description);
CU_ASSERT_PTR_NOT_NULL(media_descriptions);
CU_ASSERT_STRING_EQUAL (belle_sdp_media_get_media_type(belle_sdp_media_description_get_media((belle_sdp_media_description_t*)(media_descriptions->data))),"audio");
media_descriptions=media_descriptions->next;
CU_ASSERT_PTR_NOT_NULL(media_descriptions);
test_media_description_base((belle_sdp_media_description_t*)(media_descriptions->data));
belle_sip_object_unref(l_session_description);
return;
}
static belle_sdp_mime_parameter_t* find_mime_parameter(belle_sip_list_t* list,const int format) {
for(;list!=NULL;list=list->next){
if (belle_sdp_mime_parameter_get_media_format((belle_sdp_mime_parameter_t*)list->data) == format) {
......@@ -352,7 +429,7 @@ int belle_sdp_test_suite () {
CU_pSuite pSuite = NULL;
/* add a suite to the registry */
pSuite = CU_add_suite("sdp_suite", init_suite_sdp, clean_suite_sdp);
pSuite = CU_add_suite("SDP", init_suite_sdp, clean_suite_sdp);
/* add the tests to the suite */
/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
......@@ -362,6 +439,9 @@ int belle_sdp_test_suite () {
if (NULL == CU_add_test(pSuite, "attribute", test_attribute)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_attribute_2", test_attribute_2)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "bandwidth", test_bandwidth)) {
return CU_get_error();
}
......@@ -380,7 +460,11 @@ int belle_sdp_test_suite () {
if (NULL == CU_add_test(pSuite, "mime_parameter", test_mime_parameter)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_session_description", simple_session_description)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "session_description", test_session_description)) {
return CU_get_error();
} return 0;
}
return 0;
}
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