Commit 0e0b7b03 authored by jehan's avatar jehan

firt full belle sdp implementation

parent 51810110
......@@ -171,8 +171,9 @@ int belle_sdp_origin_get_session_version(const belle_sdp_origin_t* origin);
const char* belle_sdp_origin_get_username(const belle_sdp_origin_t* origin);
void belle_sdp_origin_set_address(belle_sdp_origin_t* origin, const char* address);
void belle_sdp_origin_set_address_type(belle_sdp_origin_t* origin, const char* address);
void belle_sdp_origin_set_session_id(belle_sdp_origin_t* origin, long address);
void belle_sdp_origin_set_session_version(belle_sdp_origin_t* origin, long version);
void belle_sdp_origin_set_network_type(belle_sdp_origin_t* origin, const char* network_type);
void belle_sdp_origin_set_session_id(belle_sdp_origin_t* origin, int session_id);
void belle_sdp_origin_set_session_version(belle_sdp_origin_t* origin, int version);
void belle_sdp_origin_set_username(belle_sdp_origin_t* origin, const char* username);
#define BELLE_SDP_ORIGIN(t) BELLE_SDP_CAST(t,belle_sdp_origin_t);
/***************************************************************************************
......@@ -201,7 +202,7 @@ void belle_sdp_repeate_time_set_value(belle_sdp_repeate_time_t* repeate_time, co
**************************************************************************************/
typedef struct _belle_sdp_session_name belle_sdp_session_name_t;
belle_sdp_session_name_t* belle_sdp_session_name_new();
belle_sdp_session_name_t* belle_sdp_session_name_parse (const char* session_name);
/*belle_sdp_session_name_t* belle_sdp_session_name_parse (const char* session_name);*/
const char* belle_sdp_session_name_get_value(const belle_sdp_session_name_t* session_name);
void belle_sdp_session_name_set_value(belle_sdp_session_name_t* session_name, const char* value);
#define BELLE_SDP_SESSION_NAME(t) BELLE_SDP_CAST(t,belle_sdp_session_name_t);
......@@ -212,8 +213,10 @@ void belle_sdp_session_name_set_value(belle_sdp_session_name_t* session_name, co
typedef struct _belle_sdp_time belle_sdp_time_t;
belle_sdp_time_t* belle_sdp_time_new();
belle_sdp_time_t* belle_sdp_time_parse (const char* time);
const char* belle_sdp_time_get_value(const belle_sdp_time_t* time);
void belle_sdp_time_set_value(belle_sdp_time_t* time, const char* value);
int belle_sdp_time_get_start(const belle_sdp_time_t* time);
int belle_sdp_time_get_stop(const belle_sdp_time_t* time);
void belle_sdp_time_set_start(belle_sdp_time_t* time, int value);
void belle_sdp_time_set_stop(belle_sdp_time_t* time, int value);
#define BELLE_SDP_TIME(t) BELLE_SDP_CAST(t,belle_sdp_time_t);
/***************************************************************************************
* Time description
......@@ -243,7 +246,7 @@ void belle_sdp_uri_set_value(belle_sdp_uri_t* uri, const char* value);
**************************************************************************************/
typedef struct _belle_sdp_version belle_sdp_version_t;
belle_sdp_version_t* belle_sdp_version_new();
belle_sdp_version_t* belle_sdp_version_parse (const char* version);
/*belle_sdp_version_t* belle_sdp_version_parse (const char* version);*/
int belle_sdp_version_get_version(const belle_sdp_version_t* version);
void belle_sdp_version_set_version(belle_sdp_version_t* version, int value);
#define BELLE_SDP_VERSION(t) BELLE_SDP_CAST(t,belle_sdp_version_t);
......@@ -273,14 +276,17 @@ belle_sdp_uri_t* belle_sdp_session_description_get_zone_adjustments(const belle_
void belle_sdp_session_description_remove_attribute(belle_sdp_session_description_t* session_description, const char* name);
void belle_sdp_session_description_remove_bandwidth(belle_sdp_session_description_t* session_description, const char* name);
void belle_sdp_session_description_set_attribute(belle_sdp_session_description_t* session_description, const char* name, const char* value);
void belle_sdp_session_description_add_attribute(belle_sdp_session_description_t* session_description, const belle_sdp_attribute_t* attribute);
void belle_sdp_session_description_set_attributes(belle_sdp_session_description_t* session_description, belle_sip_list_t* Attributes);
void belle_sdp_session_description_set_bandwidth(belle_sdp_session_description_t* session_description, const char* name, int value);
void belle_sdp_session_description_set_bandwidths(belle_sdp_session_description_t* session_description, belle_sip_list_t* bandwidths);
void belle_sdp_session_description_add_bandwidth(belle_sdp_session_description_t* session_description, const belle_sdp_bandwidth_t* bandwidth);
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_media_descriptions(belle_sdp_session_description_t* session_description, belle_sip_list_t* mediaDescriptions);
void belle_sdp_session_description_add_media_description(belle_sdp_session_description_t* session_description, belle_sdp_media_description_t* media_description);
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);
void belle_sdp_session_description_set_session_name(belle_sdp_session_description_t* session_description, belle_sdp_session_name_t* sessionName);
......
......@@ -66,6 +66,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_sender_task_t),
BELLE_SIP_TYPE_ID(belle_sip_header_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_record_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_user_agent_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_length_t),
BELLE_SIP_TYPE_ID(belle_sip_header_t),
BELLE_SIP_TYPE_ID(belle_sip_header_extension_t),
......@@ -73,6 +74,8 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_header_www_authenticate_t),
BELLE_SIP_TYPE_ID(belle_sip_header_proxy_authorization_t),
BELLE_SIP_TYPE_ID(belle_sip_header_max_forwards_t),
BELLE_SIP_TYPE_ID(belle_sip_header_expires_t),
BELLE_SIP_TYPE_ID(belle_sip_header_allow_t),
BELLE_SIP_TYPE_ID(belle_sdp_attribute_t),
BELLE_SIP_TYPE_ID(belle_sdp_bandwidth_t),
BELLE_SIP_TYPE_ID(belle_sdp_connection_t),
......
......@@ -67,6 +67,21 @@ void belle_sip_header_set_name (belle_sip_header_t* obj,const char* value);
int belle_sip_header_marshal(belle_sip_header_t* header, char* buff, unsigned int offset,unsigned int buff_size);
#define BELLE_SIP_HEADER(t) BELLE_SIP_CAST(t,belle_sip_header_t)
/******************************
*
* Allow header inherit from header
*
******************************/
typedef struct _belle_sip_header_allow belle_sip_header_allow_t;
belle_sip_header_allow_t* belle_sip_header_allow_new();
belle_sip_header_allow_t* belle_sip_header_allow_parse (const char* allow) ;
const char* belle_sip_header_allow_get_method(const belle_sip_header_allow_t* allow);
void belle_sip_header_allow_set_method(belle_sip_header_allow_t* allow,const char* method);
#define BELLE_SIP_HEADER_ALLOW(t) BELLE_SIP_CAST(t,belle_sip_header_allow_t)
/***********************
* Contact header object
************************/
......@@ -218,6 +233,21 @@ void belle_sip_header_content_type_set_type(belle_sip_header_content_type_t* con
const char* belle_sip_header_content_type_get_subtype(const belle_sip_header_content_type_t* content_type);
void belle_sip_header_content_type_set_subtype(belle_sip_header_content_type_t* content_type,const char* sub_type);
#define BELLE_SIP_HEADER_CONTENT_TYPE(t) BELLE_SIP_CAST(t,belle_sip_header_content_type_t)
/******************************
*
* Expires inherit from header
*
******************************/
typedef struct _belle_sip_header_expires belle_sip_header_expires_t;
belle_sip_header_expires_t* belle_sip_header_expires_new();
belle_sip_header_expires_t* belle_sip_header_expires_parse (const char* expires) ;
int belle_sip_header_expires_get_expires(const belle_sip_header_expires_t* expires);
void belle_sip_header_expires_set_expires(belle_sip_header_expires_t* expires,int value);
int belle_sip_header_expires_decrement_expires(belle_sip_header_expires_t* expires);
#define BELLE_SIP_HEADER_EXPIRES(t) BELLE_SIP_CAST(t,belle_sip_header_expires_t)
/******************************
* Route header object inherent from header_address
*
......@@ -238,7 +268,22 @@ void belle_sip_header_content_type_set_subtype(belle_sip_header_content_type_t*
belle_sip_header_record_route_t* belle_sip_header_record_route_parse (const char* route) ;
#define BELLE_SIP_HEADER_RECORD_ROUTE(t) BELLE_SIP_CAST(t,belle_sip_header_record_route_t)
/******************************
/******************************
*
* user-Agent header inherit from header
*
******************************/
typedef struct _belle_sip_header_user_agent belle_sip_header_user_agent_t;
belle_sip_header_user_agent_t* belle_sip_header_user_agent_new();
belle_sip_header_user_agent_t* belle_sip_header_user_agent_parse (const char* user_agent) ;
belle_sip_list_t* belle_sip_header_user_agent_get_products(const belle_sip_header_user_agent_t* user_agent);
void belle_sip_header_user_agent_set_products(belle_sip_header_user_agent_t* user_agent,belle_sip_list_t* value);
void belle_sip_header_user_agent_add_product(belle_sip_header_user_agent_t* user_agent,const char* product);
#define BELLE_SIP_HEADER_USER_AGENT(t) BELLE_SIP_CAST(t,belle_sip_header_user_agent_t)
/******************************
* Content length inherent from object
*
******************************/
......
......@@ -17,7 +17,7 @@
*/
grammar belle_sdp;
options {
language = C;
output=AST;
......@@ -32,20 +32,20 @@ session_description returns [belle_sdp_session_description_t* ret]
scope { belle_sdp_session_description_t* current; }
@init {$session_description::current = belle_sdp_session_description_new(); $ret=$session_description::current; }
: version CR LF
origin CR LF
session_name_field
origin {belle_sdp_session_description_set_origin($session_description::current,$origin.ret);}CR LF
session_name CR LF
(info CR LF)?
uri_field?
(uri_field CR LF)?
(email CR LF)*
phone_field*
(connection CR LF)?
(bandwidth CR LF)*
time_field
(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)?
(zone_adjustments CR LF)?
(key_field CR LF)?
(attribute CR LF)*
media_descriptions;
(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);}) *;
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));
......@@ -55,12 +55,16 @@ version: {IS_TOKEN(v)}?alpha_num EQUAL v=DIGIT+ {belle_sdp_version_t* ver
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 SPACE
sess_id SPACE sess_version SPACE
nettype SPACE addrtype SPACE
addr ;
: {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 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);} ;
session_name_field: {IS_TOKEN(s)}? alpha_num EQUAL text CR LF;
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);};
info returns [belle_sdp_info_t* ret]
scope { belle_sdp_info_t* current; }
......@@ -69,7 +73,7 @@ scope { belle_sdp_info_t* current; }
info_value options { greedy = false; }: ~(CR|LF)*;
uri_field: {IS_TOKEN(u)}?alpha_num EQUAL uri CR LF;
uri_field: {IS_TOKEN(u)}?alpha_num EQUAL uri ;
email returns [belle_sdp_email_t* ret]
scope { belle_sdp_email_t* current; }
......@@ -95,7 +99,16 @@ scope { belle_sdp_bandwidth_t* 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_field: {IS_TOKEN(t)}?alpha_num EQUAL start_time SPACE stop_time;
time_field: {IS_TOKEN(t)}?alpha_num EQUAL
start_time
SPACE
stop_time {belle_sdp_time_description_t* time_description =belle_sdp_time_description_new();
belle_sdp_time_t* time_value =belle_sdp_time_new();
belle_sdp_time_set_start(time_value,atoi((const char*)$start_time.text->chars));
belle_sdp_time_set_stop(time_value,atoi((const char*)$stop_time.text->chars));
belle_sdp_time_description_set_time(time_description,time_value);
belle_sip_list_t* time_description_list = belle_sip_list_append(NULL,time_description);
belle_sdp_session_description_set_time_descriptions($session_description::current,time_description_list);};
repeat_time: {IS_TOKEN(r)}?alpha_num EQUAL repeat_interval (SPACE typed_time)+;
......@@ -115,8 +128,7 @@ key_value options { greedy = false; }: ~(CR|LF)*;
attribute returns [belle_sdp_attribute_t* ret]
scope { belle_sdp_attribute_t* current; }
@init {$attribute::current = belle_sdp_attribute_new(); $ret=$attribute::current; }: {IS_TOKEN(a)}?alpha_num EQUAL attribute_value;
media_descriptions: media_description*;
media_description returns [belle_sdp_media_description_t* ret]
scope { belle_sdp_media_description_t* current; }
@init {$media_description::current = belle_sdp_media_description_new(); $ret=$media_description::current; }
......@@ -127,7 +139,7 @@ scope { belle_sdp_media_description_t* current; }
key_field ?
(attribute {belle_sdp_media_description_add_attribute($media_description::current,$attribute.ret);} CR LF)*;
media returns [belle_sdp_media_t* ret]
scope { belle_sdp_media_t* current; }
@init {$media::current = belle_sdp_media_new(); $ret=$media::current; }
......
This diff is collapsed.
......@@ -117,6 +117,33 @@ void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle
}
/******************************
* Extension header hinerite from header
*
******************************/
struct _belle_sip_header_allow {
belle_sip_header_t header;
const char* method;
};
static void belle_sip_header_allow_destroy(belle_sip_header_allow_t* allow) {
if (allow->method) belle_sip_free((void*)allow->method);
}
static void belle_sip_header_allow_clone(belle_sip_header_allow_t* allow, const belle_sip_header_allow_t* orig){
}
int belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(allow), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",allow->method);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_allow,header,"Allow")
BELLE_SIP_PARSE(header_allow)
GET_SET_STRING(belle_sip_header_allow,method);
/************************
* header_contact
......@@ -232,6 +259,54 @@ belle_sip_header_to_t* belle_sip_header_to_create(const char *address, const cha
return to;
}
/******************************
* User-Agent header hinerite from header
*
******************************/
struct _belle_sip_header_user_agent {
belle_sip_header_t header;
belle_sip_list_t* products;
};
static void belle_sip_header_user_agent_destroy(belle_sip_header_user_agent_t* user_agent) {
belle_sip_header_user_agent_set_products(user_agent,NULL);
}
static void belle_sip_header_user_agent_clone(belle_sip_header_user_agent_t* user_agent, const belle_sip_header_user_agent_t* orig){
}
int belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agent, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
belle_sip_list_t* list = user_agent->products;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(user_agent), buff,current_offset, buff_size);
for(;list!=NULL;list=list->next){
current_offset+=snprintf( buff+current_offset
,buff_size-current_offset
," %s"
,(const char *)list->data);
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_user_agent,header_address,"User-Agent")
BELLE_SIP_PARSE(header_user_agent)
belle_sip_list_t* belle_sip_header_user_agent_get_products(const belle_sip_header_user_agent_t* user_agent) {
return user_agent->products;
}
void belle_sip_header_user_agent_set_products(belle_sip_header_user_agent_t* user_agent,belle_sip_list_t* products) {
belle_sip_list_t* list;
if (user_agent->products) {
for (list=user_agent->products;list !=NULL; list=list->next) {
belle_sip_free((void*)list->data);
}
belle_sip_list_free(user_agent->products);
}
user_agent->products=products;
}
void belle_sip_header_user_agent_add_product(belle_sip_header_user_agent_t* user_agent,const char* product) {
user_agent->products = belle_sip_list_append(user_agent->products ,belle_sip_strdup(product));
}
/**************************
* Via header object inherits from parameters
****************************
......@@ -472,6 +547,32 @@ int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* c
BELLE_SIP_NEW_HEADER(header_content_length,header,"Content-Length")
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
/**************************
* Expires header object inherent from header
****************************
*/
struct _belle_sip_header_expires {
belle_sip_header_t header;
int expires;
};
static void belle_sip_header_expires_destroy(belle_sip_header_expires_t* expires) {
}
static void belle_sip_header_expires_clone(belle_sip_header_expires_t* expires,
const belle_sip_header_expires_t *orig ) {
}
int belle_sip_header_expires_marshal(belle_sip_header_expires_t* expires, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(expires), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",expires->expires);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_expires,header,"Expires")
BELLE_SIP_PARSE(header_expires)
GET_SET_INT(belle_sip_header_expires,expires,int)
/******************************
* Extension header hinerite from header
*
......
......@@ -218,9 +218,13 @@ alert_param
absoluteURI
: token ':' token;
allow : 'Allow' HCOLON (method (COMMA method))? ;
*/
header_allow returns [belle_sip_header_allow_t* ret]
scope { belle_sip_header_allow_t* current; }
@init {$header_allow::current = belle_sip_header_allow_new(); $ret=$header_allow::current; }
: {IS_TOKEN(Allow)}? token /*'Allow'*/ hcolon methods {belle_sip_header_allow_set_method($header_allow::current,(const char*)($methods.text->chars));} ;
methods : LWS? method (comma method)*;
authorization_token: {IS_TOKEN(Authorization)}? token;
digest_token: {IS_TOKEN(Digest)}? token;
......@@ -406,10 +410,11 @@ c_p_expires
: 'expires' EQUAL delta_seconds;*/
contact_extension
: generic_param [BELLE_SIP_PARAMETERS($header_contact::current)];
/*
delta_seconds
: DIGIT+;*/
: DIGIT+;
/*
content_disposition
: 'Content-Disposition' HCOLON
disp_type ( SEMI disp_param )*;
......@@ -520,10 +525,12 @@ error_info
error_uri
: LAQUOT absoluteURI RAQUOT ( SEMI generic_param )*;
expires
: 'Expires' HCOLON delta_seconds;
*/
header_expires returns [belle_sip_header_expires_t* ret]
scope { belle_sip_header_expires_t* current; }
@init { $header_expires::current = belle_sip_header_expires_new();$ret = $header_expires::current; }
: {IS_TOKEN(Expires)}? token /*'Expires'*/ hcolon delta_seconds {belle_sip_header_expires_set_expires($header_expires::current,atoi((const char *)$delta_seconds.text->chars));};
from_token: {IS_TOKEN(From)}? token;
header_from returns [belle_sip_header_from_t* ret]
scope { belle_sip_header_from_t* current; }
......@@ -686,10 +693,10 @@ require
retry_after
: 'Retry-After' HCOLON delta_seconds
comment? ( SEMI retry_param )*;
*/
comment : '(' . ')';
;
/*
retry_param
: ('duration' EQUAL delta_seconds)
| generic_param;
......@@ -713,13 +720,9 @@ r_param
/*
server
: 'Server' HCOLON server_val (LWS server_val)*;
server_val
: product | comment;
product
: token (SLASH product_version)?;
product_version
: token;
*/
/*
subject
: ( 'Subject' | 's' ) HCOLON (text_utf_huit)?;
......@@ -751,9 +754,20 @@ to_param
/*
unsupported
: 'Unsupported' HCOLON option_tag (COMMA option_tag)*;
user_agent
: 'User-Agent' HCOLON server_val (LWS server_val)*;
*/
header_user_agent returns [belle_sip_header_user_agent_t* ret]
scope { belle_sip_header_user_agent_t* current; }
@init { $header_user_agent::current = belle_sip_header_user_agent_new();$ret = $header_user_agent::current;}
: {IS_TOKEN(User-Agent)}? token /*'User-Agent'*/ hcolon server_val (LWS server_val)*;
server_val : word {belle_sip_header_user_agent_add_product($header_user_agent::current,(const char*)$word.text->chars); };
serval_item
: product | comment ;
product
: token (SLASH product_version)?;
product_version
: token;
via_token: {IS_TOKEN(Via)}? token;
header_via returns [belle_sip_header_via_t* ret]
scope { belle_sip_header_via_t* current; belle_sip_header_via_t* first; }
......@@ -852,6 +866,12 @@ header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_head
$ret = BELLE_SIP_HEADER(belle_sip_header_www_authenticate_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Max-Forwards",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_max_forwards_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("User-Agent",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_user_agent_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Expires",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_expires_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Allow",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_allow_parse((const char*)$header_extension.text->chars));
}else {
$ret = BELLE_SIP_HEADER(belle_sip_header_extension_new());
belle_sip_header_extension_set_value((belle_sip_header_extension_t*)$ret,(const char*)$header_value.text->chars);
......
......@@ -106,27 +106,16 @@ static void test_media(void) {
int fmt[] ={111,110,3,0,8,101};
int i=0;
for(;list!=NULL;list=list->next){
CU_ASSERT_EQUAL((int)(list->data),fmt[i++]);
CU_ASSERT_EQUAL((int)(long)list->data),fmt[i++]);
}
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media));
}
static void test_media_description(void) {
const char* l_src = "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_media_description_t* l_media_description = belle_sdp_media_description_parse(l_src);
char* l_raw_media_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_media_description));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
l_media_description = belle_sdp_media_description_parse(l_raw_media_description);
/*media*/
static void test_media_description_base(belle_sdp_media_description_t* media_description) {
belle_sdp_media_description_t* l_media_description=media_description;
belle_sdp_media_t* l_media = belle_sdp_media_description_get_media(l_media_description);
CU_ASSERT_PTR_NOT_NULL(l_media);
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_media_type(l_media), "video");
CU_ASSERT_EQUAL(belle_sdp_media_get_media_port(l_media), 8078);
......@@ -136,7 +125,7 @@ static void test_media_description(void) {
int fmt[] ={99,97,98};
int i=0;
for(;list!=NULL;list=list->next){
CU_ASSERT_EQUAL((int)(list->data),fmt[i++]);
CU_ASSERT_EQUAL((int)((long)list->data),fmt[i++]);
}
/*connection*/
belle_sdp_connection_t* lConnection = belle_sdp_media_description_get_connection(l_media_description);
......@@ -163,6 +152,78 @@ static void test_media_description(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
}
static void test_media_description(void) {
const char* l_src = "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_media_description_t* l_media_description = belle_sdp_media_description_parse(l_src);
char* l_raw_media_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_media_description));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
l_media_description = belle_sdp_media_description_parse(l_raw_media_description);
test_media_description_base(l_media_description);
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=Talk\r\n"\
"c=IN IP4 192.168.0.18\r\n"\
"t=0 0\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* 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));
l_session_description = belle_sdp_session_description_parse(l_raw_session_description);
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)),"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));
return;
}
int belle_sdp_test_suite () {
CU_pSuite pSuite = NULL;
......@@ -192,5 +253,7 @@ int belle_sdp_test_suite () {
if (NULL == CU_add_test(pSuite, "media_description", test_media_description)) {
return CU_get_error();
}
return 0;
if (NULL == CU_add_test(pSuite, "session_description", test_session_description)) {
return CU_get_error();
} return 0;
}
......@@ -329,6 +329,49 @@ void test_header_max_forwards(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(L_max_forwards));
}
void test_header_user_agent(void) {
const char* l_header = "User-Agent: Linphone/3.4.99.1 (eXosip2/3.3.0)";
belle_sip_header_user_agent_t* L_user_agent = belle_sip_header_user_agent_parse(l_header);
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_user_agent));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
L_user_agent = belle_sip_header_user_agent_parse(l_raw_header);
belle_sip_free(l_raw_header);
const char* values[] ={"Linphone/3.4.99.1"
,"(eXosip2/3.3.0)"};
int i=0;
belle_sip_list_t* products = belle_sip_header_user_agent_get_products(L_user_agent);
for(i=0;i<2;i++){
CU_ASSERT_PTR_NOT_NULL(products);
CU_ASSERT_STRING_EQUAL((const char *)(products->data),values[i]);
products=products->next;
}
belle_sip_object_unref(BELLE_SIP_OBJECT(L_user_agent));
}
void test_header_expires(void) {
belle_sip_header_expires_t* L_expires = belle_sip_header_expires_parse("Expires: 3600");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_expires));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
L_expires = belle_sip_header_expires_parse(l_raw_header);
belle_sip_free(l_raw_header);
CU_ASSERT_EQUAL(belle_sip_header_expires_get_expires(L_expires), 3600);
belle_sip_object_unref(BELLE_SIP_OBJECT(L_expires));
}
void test_header_allow(void) {
belle_sip_header_allow_t* L_allow = belle_sip_header_allow_parse("Allow:INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_allow));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
L_allow = belle_sip_header_allow_parse(l_raw_header);
belle_sip_free(l_raw_header);
CU_ASSERT_STRING_EQUAL(belle_sip_header_allow_get_method(L_allow), "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
}
int belle_sip_headers_test_suite() {
CU_pSuite pSuite = NULL;
......@@ -367,7 +410,7 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test of route header", test_header_route)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of content lenth", test_header_content_length)) {
if (NULL == CU_add_test(pSuite, "test of content length", test_header_content_length)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of extension", test_header_extention)) {
......@@ -383,7 +426,16 @@ int belle_sip_headers_test_suite() {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of max forwards", test_header_max_forwards)) {
return CU_get_error();
}
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of user agent", test_header_user_agent)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of expires", test_header_expires)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of allow", test_header_allow)) {
return CU_get_error();
}
return 0;
}
......@@ -35,6 +35,9 @@ static void check_uri_and_headers(belle_sip_message_t* message) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Max-Forwards"));
CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_MAX_FORWARDS(belle_sip_message_get_header(message,"Max-Forwards")));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"User-Agent"));
CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_USER_AGENT(belle_sip_message_get_header(message,"User-Agent")));
}
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"From"));
CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_FROM(belle_sip_message_get_header(message,"From")));
......@@ -58,6 +61,7 @@ static void check_uri_and_headers(belle_sip_message_t* message) {
}
static void testRegisterMessage(void) {
......@@ -82,6 +86,7 @@ static void testRegisterMessage(void) {
belle_sip_request_t* request = BELLE_SIP_REQUEST(message);
CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER");
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Expires"));
CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_EXPIRES(belle_sip_message_get_header(message,"Expires")));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Proxy-Authorization"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
......
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