Commit 6325daf2 authored by jehan's avatar jehan

add sdp attribute, connection, info, email

parent 3f4235f9
......@@ -41,9 +41,9 @@ void belle_sdp_attribute_set_value(belle_sdp_attribute_t* attribute, const char*
typedef struct _belle_sdp_bandwidth belle_sdp_bandwidth_t;
belle_sdp_bandwidth_t* belle_sdp_bandwidth_new();
belle_sdp_bandwidth_t* belle_sdp_bandwidth_parse (const char* bandwidth);
const char* belle_sdp_bandwidth_get_value(const belle_sdp_bandwidth_t* attribute);
int belle_sdp_bandwidth_get_value(const belle_sdp_bandwidth_t* attribute);
const char* belle_sdp_bandwidth_get_type(const belle_sdp_bandwidth_t* attribute);
void belle_sdp_bandwidth_set_value(belle_sdp_bandwidth_t* attribute, const char* value);
void belle_sdp_bandwidth_set_value(belle_sdp_bandwidth_t* attribute, int value);
void belle_sdp_bandwidth_set_type(belle_sdp_bandwidth_t* attribute, const char* type);
#define BELLE_SDP_BANDWITH(t) BELLE_SDP_CAST(t,belle_sdp_bandwidth_t);
/***************************************************************************************
......@@ -84,15 +84,15 @@ void belle_sdp_info_set_value(belle_sdp_info_t* info, const char* value);
* Key
*
**************************************************************************************/
typedef struct _belle_sdp_key belle_sdp_key_t;
belle_sdp_key_t* belle_sdp_key_new();
belle_sdp_key_t* belle_sdp_key_parse (const char* key);
const char* belle_sdp_key_get_key(const belle_sdp_key_t* key);
const char* belle_sdp_key_get_method(const belle_sdp_key_t* key);
unsigned int belle_sdp_key_as_key(const belle_sdp_key_t* key);
void belle_sdp_key_set_key(belle_sdp_key_t* key, const char* keyvalue);
void belle_sdp_key_set_method(belle_sdp_key_t* key, const char* method);
#define BELLE_SDP_KEY(t) BELLE_SDP_CAST(t,belle_sdp_key_t);
//typedef struct _belle_sdp_key belle_sdp_key_t;
//belle_sdp_key_t* belle_sdp_key_new();
//belle_sdp_key_t* belle_sdp_key_parse (const char* key);
//const char* belle_sdp_key_get_key(const belle_sdp_key_t* key);
//const char* belle_sdp_key_get_method(const belle_sdp_key_t* key);
//unsigned int belle_sdp_key_as_key(const belle_sdp_key_t* key);
//void belle_sdp_key_set_key(belle_sdp_key_t* key, const char* keyvalue);
//void belle_sdp_key_set_method(belle_sdp_key_t* key, const char* method);
//#define BELLE_SDP_KEY(t) BELLE_SDP_CAST(t,belle_sdp_key_t);
/***************************************************************************************
* Media
*
......@@ -111,7 +111,7 @@ void belle_sdp_media_set_media_formats(belle_sdp_media_t* media, belle_sip_list_
void belle_sdp_media_set_media_port(belle_sdp_media_t* media, int port);
void belle_sdp_media_set_media_type(belle_sdp_media_t* media, const char* mediaType);
void belle_sdp_media_set_port_count(belle_sdp_media_t* media, int portCount);
void belle_sdp_media_set_media_protocole(belle_sdp_media_t* media, const char* protocole);
void belle_sdp_media_set_media_protocol(belle_sdp_media_t* media, const char* protocole);
#define BELLE_SDP_MEDIA(t) BELLE_SDP_CAST(t,belle_sdp_media_t);
/***************************************************************************************
......@@ -128,7 +128,7 @@ int belle_sdp_media_description_get_bandwidth(const belle_sdp_media_description_
belle_sip_list_t* belle_sdp_media_description_get_bandwidths(const belle_sdp_media_description_t* media_description, unsigned int create);
belle_sdp_connection_t* belle_sdp_media_description_get_connection(const belle_sdp_media_description_t* media_description);
belle_sdp_info_t* belle_sdp_media_description_get_info(const belle_sdp_media_description_t* media_description);
belle_sdp_key_t* belle_sdp_media_description_get_key(const belle_sdp_media_description_t* media_description);
/*belle_sdp_key_t* belle_sdp_media_description_get_key(const belle_sdp_media_description_t* media_description);*/
belle_sdp_media_t* belle_sdp_media_description_get_media(const belle_sdp_media_description_t* media_description);
belle_sip_list_t* belle_sdp_media_description_get_mime_parameters(const belle_sdp_media_description_t* media_description);
belle_sip_list_t* belle_sdp_media_description_get_mime_types(const belle_sdp_media_description_t* media_description);
......@@ -140,7 +140,7 @@ void belle_sdp_media_description_set_bandwidth(belle_sdp_media_description_t* me
void belle_sdp_media_description_set_bandwidths(belle_sdp_media_description_t* media_description, belle_sip_list_t* bandwidths);
void belle_sdp_media_description_set_connection(belle_sdp_media_description_t* media_description, belle_sdp_connection_t* conn);
void belle_sdp_media_description_set_info(belle_sdp_media_description_t* media_description,belle_sdp_info_t* i);
void belle_sdp_media_description_set_key(belle_sdp_media_description_t* media_description,belle_sdp_key_t* key);
/*void belle_sdp_media_description_set_key(belle_sdp_media_description_t* media_description,belle_sdp_key_t* key);*/
void belle_sdp_media_description_set_media(belle_sdp_media_description_t* media_description, belle_sdp_media_t* media);
#define BELLE_SDP_MEDIA_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_media_description_t);
/***************************************************************************************
......@@ -248,7 +248,7 @@ belle_sip_list_t* belle_sdp_session_description_get_bandwidths(const belle_sdp_s
belle_sdp_connection_t* belle_sdp_session_description_get_connection(const belle_sdp_session_description_t* session_description);
belle_sip_list_t* belle_sdp_session_description_get_emails(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sdp_info_t* belle_sdp_session_description_get_info(const belle_sdp_session_description_t* session_description);
belle_sdp_key_t* belle_sdp_session_description_get_key(const belle_sdp_session_description_t* session_description);
/*belle_sdp_key_t* belle_sdp_session_description_get_key(const belle_sdp_session_description_t* session_description);*/
belle_sdp_info_t* belle_sdp_session_description_get_mediaDescriptions(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sdp_origin_t* belle_sdp_session_description_get_origin(const belle_sdp_session_description_t* session_description);
belle_sip_list_t* belle_sdp_session_description_get_phones(const belle_sdp_session_description_t* session_description, unsigned int create);
......@@ -266,7 +266,7 @@ void belle_sdp_session_description_set_bandwidths(belle_sdp_session_description_
void belle_sdp_session_description_set_connection(belle_sdp_session_description_t* session_description, belle_sdp_connection_t* conn);
void belle_sdp_session_description_set_emails(belle_sdp_session_description_t* session_description, belle_sip_list_t* emails);
void belle_sdp_session_description_set_info(belle_sdp_session_description_t* session_description, belle_sdp_info_t* i);
void belle_sdp_session_description_set_key(belle_sdp_session_description_t* session_description, belle_sdp_key_t* key);
/*void belle_sdp_session_description_set_key(belle_sdp_session_description_t* session_description, belle_sdp_key_t* key);*/
void belle_sdp_session_description_set_media_descriptions(belle_sdp_session_description_t* session_description, belle_sip_list_t* mediaDescriptions);
void belle_sdp_session_description_set_origin(belle_sdp_session_description_t* session_description, belle_sdp_origin_t* origin);
void belle_sdp_session_description_set_phones(belle_sdp_session_description_t* session_description, belle_sip_list_t* phones);
......
......@@ -31,14 +31,16 @@ options {
session_description: proto_version
origin_field
session_name_field
information_field?
(info CR LF)?
uri_field?
email_field*
(email CR LF)*
phone_field*
(connection CR LF)?
bandwidth_field*
time_fields
key_field
(bandwidth CR LF)*
time_field
(repeat_time CR LF)?
(zone_adjustments CR LF)?
(key_field CR LF)?
(attribute CR LF)*
media_descriptions;
......@@ -52,11 +54,19 @@ origin_field: {IS_TOKEN(o)}?alpha_num EQUAL username SPACE
session_name_field: {IS_TOKEN(s)}? alpha_num EQUAL text CR LF;
information_field: {IS_TOKEN(i)}? alpha_num EQUAL text CR LF;
info returns [belle_sdp_info_t* ret]
scope { belle_sdp_info_t* current; }
@init {$info::current = belle_sdp_info_new(); $ret=$info::current; }
: {IS_TOKEN(i)}? alpha_num EQUAL info_value {belle_sdp_info_set_value($info::current,(const char*) $info_value.text->chars);} ;
info_value options { greedy = false; }: ~(CR|LF)*;
uri_field: {IS_TOKEN(u)}?alpha_num EQUAL uri CR LF;
email_field: {IS_TOKEN(e)}?alpha_num EQUAL email_address CR LF;
email returns [belle_sdp_email_t* ret]
scope { belle_sdp_email_t* current; }
@init {$email::current = belle_sdp_email_new(); $ret=$email::current; }
: {IS_TOKEN(e)}?alpha_num EQUAL email_address {belle_sdp_email_set_value($email::current,(const char*)$email_address.text->chars);};
phone_field: {IS_TOKEN(p)}?alpha_num EQUAL phone_number CR LF;
......@@ -71,54 +81,64 @@ scope { belle_sdp_connection_t* current; }
//;in every media description or at the
//;session-level
bandwidth_field: {IS_TOKEN(b)}?alpha_num EQUAL bwtype COLON bandwidth CR LF;
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));};
time_fields: ( {IS_TOKEN(t)}?alpha_num EQUAL start_time SPACE stop_time
(CR LF repeat_fields)* CR LF)+
(zone_adjustments CR LF)?;
time_field: {IS_TOKEN(t)}?alpha_num EQUAL start_time SPACE stop_time;
repeat_fields: {IS_TOKEN(r)}?alpha_num EQUAL repeat_interval (SPACE typed_time)+;
repeat_time: {IS_TOKEN(r)}?alpha_num EQUAL repeat_interval (SPACE typed_time)+;
zone_adjustments: sdp_time SPACE '-'? typed_time
(SPACE sdp_time SPACE '-'? typed_time)*;
key_field: {IS_TOKEN(k)}?alpha_num EQUAL key_type 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 |
{IS_TOKEN(base64)}? alpha_num* /*'uri*/ COLON uri;
key_data: email_safe;
key_field: {IS_TOKEN(k)}?alpha_num EQUAL key_value ;
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 |
// {IS_TOKEN(base64)}? alpha_num* /*'uri*/ COLON uri;
//
//key_data: email_safe;
attribute returns [belle_sdp_attribute_t* ret]
scope { belle_sdp_attribute_t* current; }
@init {$attribute::current = belle_sdp_attribute_new(); $ret=$attribute::current; }: 'a=' attribute_value;
@init {$attribute::current = belle_sdp_attribute_new(); $ret=$attribute::current; }: {IS_TOKEN(a)}?alpha_num EQUAL attribute_value;
media_descriptions: media_description*;
media_description: media_field
information_field
connection*
bandwidth_field*
key_field
media_description: media CR LF
(info CR LF)?
(connection CR LF)?
(bandwidth CR LF)*
key_field ?
(attribute CR LF)*;
media_field: {IS_TOKEN(m)}?alpha_num EQUAL media SPACE port ('/' integer)? SPACE proto (SPACE fmt)?CR LF;
media: alpha_num*;
media returns [belle_sdp_media_t* ret]
scope { belle_sdp_media_t* current; }
@init {$media::current = belle_sdp_media_new(); $ret=$media::current; }
: {IS_TOKEN(m)}?alpha_num EQUAL
media_value {belle_sdp_media_set_value($media::current,(const char*)$media_value.text->chars);}
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_media_protocol($media::current,(const char*)$proto.text->chars);}
(SPACE fmt)?;
media_value: alpha_num+;
// ;typically "audio", "video", "application"
// ;or "data"
fmt: alpha_num*;
fmt: DIGIT+;
//;typically an RTP payload type for audio
//;and video media
proto: alpha_num*;
proto options { greedy = false; }: ~(SPACE|CR|LF)*;
//;typically "RTP/AVP" or "udp" for IP4
port: DIGIT*;
port: DIGIT+;
// ;should in the range "1024" to "65535" inclusive
// ;for UDP based media
......@@ -126,14 +146,14 @@ 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: alpha_num+;
att_value: byte_string;
att_value options { greedy = false; }: ~(CR|LF)*;
sess_id: DIGIT*;
// ;should be unique for this originating username/host
sess_version: DIGIT*;
sess_version: DIGIT+;
//;0 is a new session
connection_address: multicast_address
......@@ -145,11 +165,11 @@ multicast_address: (decimal_uchar decimal_uchar decimal_uchar DOT) decimal_uch
ttl: decimal_uchar;
start_time: sdp_time | ZERO ;
start_time: DIGIT+ ;
stop_time: sdp_time | ZERO ;
stop_time: DIGIT+ ;
sdp_time: POS_DIGIT DIGIT*;
sdp_time: DIGIT+;
// ;sufficient for 2 more centuries
repeat_interval: typed_time;
......@@ -163,15 +183,14 @@ fixed_len_time_unit: {IS_TOKEN(d)}? alpha_num
bwtype: alpha_num+;
bandwidth: DIGIT+;
bandwidth_value: DIGIT+;
username: email_safe;
//;pretty wide definition, but doesn't include SPACE
email_address: email ; //| email '(' email_safe ')' |
email_address options { greedy = false; }: ~(CR|LF)* ; //| email '(' email_safe ')' |
//email_safe '<' email '>';
email: text ;//defined in RFC822
uri: text ;//defined in RFC1630
......@@ -209,15 +228,15 @@ text : byte_string;
//ISO 8859-1 requires a "a=charset:ISO-8859-1"
//session-level attribute to be used
byte_string: ~(CR|LF)* ;
byte_string options { greedy = false; }: (.)* ;
//any byte except NUL, CR or LF
decimal_uchar: d+=DIGIT+ {$d->count<=3}? ;
integer: POS_DIGIT DIGIT*;
email_safe
options { greedy = false; }: ~(LQUOTE|RQUOTE|CR|LF)* ;
email_safe : byte_string;
alpha_num: ALPHA | DIGIT;
......@@ -236,3 +255,5 @@ LF:'\n';
DOT: '.';
EQUAL: '=';
COLON: ':';
SLASH: '/';
ANY_EXCEPT_CR_LF: ~(CR|LF);
\ No newline at end of file
......@@ -55,6 +55,33 @@ GET_SET_STRING(belle_sdp_attribute,value);
unsigned int belle_sdp_attribute_as_value(const belle_sdp_attribute_t* attribute) {
return attribute->value!=NULL;
}
/***************************************************************************************
* Bandwidth
*
**************************************************************************************/
struct _belle_sdp_bandwidth {
belle_sip_object_t base;
const char* type;
int value;
};
void belle_sdp_bandwidth_destroy(belle_sdp_bandwidth_t* bandwidth) {
}
void belle_sdp_bandwidth_clone(belle_sdp_bandwidth_t *bandwidth, const belle_sdp_bandwidth_t *orig){
}
int belle_sdp_bandwidth_marshal(belle_sdp_bandwidth_t* bandwidth, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=snprintf( buff+current_offset
,buff_size-current_offset
,"b=%s:%i"
,bandwidth->type,bandwidth->value);
return current_offset-offset;
}
BELLE_SDP_NEW(bandwidth,belle_sip_object)
BELLE_SDP_PARSE(bandwidth)
GET_SET_STRING(belle_sdp_bandwidth,type);
GET_SET_INT(belle_sdp_bandwidth,value,int)
/************************
* connection
......@@ -86,3 +113,84 @@ BELLE_SDP_PARSE(connection)
GET_SET_STRING(belle_sdp_connection,network_type);
GET_SET_STRING(belle_sdp_connection,address_type);
GET_SET_STRING(belle_sdp_connection,address);
/************************
* email
***********************/
struct _belle_sdp_email {
belle_sip_object_t base;
const char* value;
};
void belle_sdp_email_destroy(belle_sdp_email_t* email) {
}
void belle_sdp_email_clone(belle_sdp_email_t *email, const belle_sdp_email_t *orig){
}
int belle_sdp_email_marshal(belle_sdp_email_t* email, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=snprintf( buff+current_offset
,buff_size-current_offset
,"e=%s"
,email->value);
return current_offset-offset;
}
BELLE_SDP_NEW(email,belle_sip_object)
BELLE_SDP_PARSE(email)
GET_SET_STRING(belle_sdp_email,value);
/************************
* info
***********************/
struct _belle_sdp_info {
belle_sip_object_t base;
const char* value;
};
void belle_sdp_info_destroy(belle_sdp_info_t* info) {
}
void belle_sdp_info_clone(belle_sdp_info_t *info, const belle_sdp_info_t *orig){
}
int belle_sdp_info_marshal(belle_sdp_info_t* info, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=snprintf( buff+current_offset
,buff_size-current_offset
,"i=%s"
,info->value);
return current_offset-offset;
}
BELLE_SDP_NEW(info,belle_sip_object)
BELLE_SDP_PARSE(info)
GET_SET_STRING(belle_sdp_info,value);
/************************
* media
***********************/
struct _belle_sdp_media {
belle_sip_object_t base;
const char* value;
int media_port;
belle_sip_list_t* media_formats;
const char* media_type;
int port_count;
const char* media_protocol;
};
void belle_sdp_media_destroy(belle_sdp_media_t* media) {
}
void belle_sdp_media_clone(belle_sdp_media_t *media, const belle_sdp_media_t *orig){
}
int belle_sdp_media_marshal(belle_sdp_media_t* media, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=snprintf( buff+current_offset
,buff_size-current_offset
,"m=%s"
,media->value);
return current_offset-offset;
}
BELLE_SDP_NEW(media,belle_sip_object)
BELLE_SDP_PARSE(media)
GET_SET_STRING(belle_sdp_media,value);
GET_SET_STRING(belle_sdp_media,media_type);
GET_SET_STRING(belle_sdp_media,media_protocol);
GET_SET_INT(belle_sdp_media,media_port,int)
GET_SET_INT(belle_sdp_media,port_count,int)
......@@ -56,6 +56,16 @@ 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_bandwidth(void) {
belle_sdp_bandwidth_t* l_bandwidth = belle_sdp_bandwidth_parse("b=AS:380");
char* l_raw_bandwidth = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_bandwidth));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_bandwidth));
l_bandwidth = belle_sdp_bandwidth_parse(l_raw_bandwidth);
CU_ASSERT_STRING_EQUAL(belle_sdp_bandwidth_get_type(l_bandwidth), "AS");
CU_ASSERT_EQUAL(belle_sdp_bandwidth_get_value(l_bandwidth),380);
belle_sip_object_unref(BELLE_SIP_OBJECT(l_bandwidth));
}
static void test_connection(void) {
belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP4 192.168.0.18");
......@@ -67,7 +77,22 @@ static void test_connection(void) {
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_network_type(lConnection), "IN");
belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection));
}
static void test_email(void) {
belle_sdp_email_t* l_email = belle_sdp_email_parse("e= jehan <jehan@linphone.org>");
char* l_raw_email = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_email));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_email));
l_email = belle_sdp_email_parse(l_raw_email);
CU_ASSERT_STRING_EQUAL(belle_sdp_email_get_value(l_email), " jehan <jehan@linphone.org>");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_email));
}
static void test_info(void) {
belle_sdp_info_t* l_info = belle_sdp_info_parse("i=A Seminar on the session description protocol");
char* l_raw_info = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_info));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_info));
l_info = belle_sdp_info_parse(l_raw_info);
CU_ASSERT_STRING_EQUAL(belle_sdp_info_get_value(l_info), "A Seminar on the session description protocol");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_info));
}
int belle_sdp_test_suite () {
......@@ -82,7 +107,15 @@ int belle_sdp_test_suite () {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "attribute", test_attribute)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "bandwidth", test_bandwidth)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "email", test_email)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "info", test_info)) {
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