Commit 2b300970 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Merge branch 'dev_attributes_parsing'

parents 08b7b4c0 144a6a18
......@@ -79,7 +79,6 @@ endif(NOT "${HAVE_RES_NDESTROY}" STREQUAL "" AND NOT "${HAVE_RES_GETSERVERS}" ST
find_package(Threads)
find_package(Java)
find_package(Antlr3)
if(${ENABLE_TLS})
......
......@@ -25,8 +25,9 @@
# ANTLR3C_FOUND - system has antlr3c
# ANTLR3C_INCLUDE_DIR - the antlr3c include directory
# ANTLR3C_LIBRARIES - The libraries needed to use antlr3c
# ANTLR3_JAR_FOUND - sytem has antlr.jar
# ANTLR3_JAR_PATH - the antlr.jar path
# ANTLR3_COMMAND - The command to run the antlr jar
find_package(Java)
include(CMakePushCheckState)
include(CheckIncludeFile)
......@@ -80,14 +81,23 @@ endif(NOT "${ANTLR3C_INCLUDE_DIR}" STREQUAL "")
mark_as_advanced(ANTLR3C_INCLUDE_DIR ANTLR3C_LIBRARIES)
find_file(ANTLR3_JAR_PATH
NAMES antlr.jar antlr3.jar
HINTS _ANTLR3_JAR_ROOT_PATHS
PATH_SUFFIXES share/java
find_file(ANTLR3_COMMAND
NAMES antlr3
HINTS ${_ANTLR3_JAR_ROOT_PATHS}
PATH_SUFFIXES bin
)
if(NOT "${ANTLR3_JAR_PATH}" STREQUAL "")
set(ANTLR3_JAR_FOUND TRUE)
endif(NOT "${ANTLR3_JAR_PATH}" STREQUAL "")
if(NOT ANTLR3_COMMAND)
# antlr3 command not found, search for the jar file
find_file(ANTLR3_JAR_PATH
NAMES antlr3.jar antlr.jar
HINTS _ANTLR3_JAR_ROOT_PATHS
PATH_SUFFIXES share/java
)
if(NOT "${ANTLR3_JAR_PATH}" STREQUAL "")
set(ANTLR3_COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR3_JAR_PATH})
endif(NOT "${ANTLR3_JAR_PATH}" STREQUAL "")
endif(NOT ANTLR3_COMMAND)
mark_as_advanced(ANTLR3_JAR_PATH)
mark_as_advanced(ANTLR3_COMMAND)
......@@ -32,11 +32,41 @@ BELLESIP_EXPORT belle_sdp_attribute_t* belle_sdp_attribute_new();
BELLESIP_EXPORT belle_sdp_attribute_t* belle_sdp_attribute_parse (const char* attribute);
BELLESIP_EXPORT belle_sdp_attribute_t* belle_sdp_attribute_create (const char* name,const char* value);
BELLESIP_EXPORT const char* belle_sdp_attribute_get_name(const belle_sdp_attribute_t* attribute);
BELLESIP_EXPORT const char* belle_sdp_attribute_get_value(const belle_sdp_attribute_t* attribute);
BELLESIP_EXPORT unsigned int belle_sdp_attribute_as_value(const belle_sdp_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_attribute_set_name(belle_sdp_attribute_t* attribute, const char* name);
BELLESIP_EXPORT void belle_sdp_attribute_set_value(belle_sdp_attribute_t* attribute, const char* value);
#define BELLE_SDP_ATTRIBUTE(t) BELLE_SDP_CAST(t,belle_sdp_attribute_t);
#define BELLE_SDP_ATTRIBUTE(t) BELLE_SDP_CAST(t,belle_sdp_attribute_t)
#define belle_sdp_attribute_init(obj) /*nothing*/
/***************************************************************************************
* RAW Attribute
*
**************************************************************************************/
typedef struct _belle_sdp_raw_attribute belle_sdp_raw_attribute_t;
BELLESIP_EXPORT belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_new();
BELLESIP_EXPORT belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_parse(const char* attribute);
BELLESIP_EXPORT belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_create(const char* name, const char* value);
BELLESIP_EXPORT const char* belle_sdp_raw_attribute_get_value(const belle_sdp_raw_attribute_t* attribute);
BELLESIP_EXPORT unsigned int belle_sdp_raw_attribute_has_value(const belle_sdp_raw_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_raw_attribute_set_value(belle_sdp_raw_attribute_t* attribute, const char* value);
#define BELLE_SDP_RAW_ATTRIBUTE(t) BELLE_SDP_CAST(t,belle_sdp_raw_attribute_t)
/***************************************************************************************
* RTCP-XR Attribute
*
**************************************************************************************/
typedef struct _belle_sdp_rtcp_xr_attribute belle_sdp_rtcp_xr_attribute_t;
BELLESIP_EXPORT belle_sdp_rtcp_xr_attribute_t* belle_sdp_rtcp_xr_attribute_new();
BELLESIP_EXPORT belle_sdp_rtcp_xr_attribute_t* belle_sdp_rtcp_xr_attribute_parse(const char* attribute);
BELLESIP_EXPORT belle_sdp_rtcp_xr_attribute_t* belle_sdp_rtcp_xr_attribute_create();
BELLESIP_EXPORT const char* belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(const belle_sdp_rtcp_xr_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_mode(belle_sdp_rtcp_xr_attribute_t* attribute, const char *mode);
BELLESIP_EXPORT int belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_max_size(const belle_sdp_rtcp_xr_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_max_size(belle_sdp_rtcp_xr_attribute_t* attribute, int max_size);
BELLESIP_EXPORT unsigned int belle_sdp_rtcp_xr_attribute_has_stat_summary(const belle_sdp_rtcp_xr_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_rtcp_xr_attribute_set_stat_summary(belle_sdp_rtcp_xr_attribute_t* attribute, unsigned int enable);
BELLESIP_EXPORT belle_sip_list_t* belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(const belle_sdp_rtcp_xr_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_rtcp_xr_attribute_set_stat_summary_flags(belle_sdp_rtcp_xr_attribute_t* attribute, belle_sip_list_t* flags);
BELLESIP_EXPORT void belle_sdp_rtcp_xr_attribute_add_stat_summary_flag(belle_sdp_rtcp_xr_attribute_t* attribute, const char* flag);
BELLESIP_EXPORT unsigned int belle_sdp_rtcp_xr_attribute_has_voip_metrics(const belle_sdp_rtcp_xr_attribute_t* attribute);
BELLESIP_EXPORT void belle_sdp_rtcp_xr_attribute_set_voip_metrics(belle_sdp_rtcp_xr_attribute_t* attribute, unsigned int enable);
#define BELLE_SDP_RTCP_XR_ATTRIBUTE(t) BELLE_SDP_CAST(t,belle_sdp_rtcp_xr_attribute_t)
/***************************************************************************************
* Bandwidth
*
......@@ -48,7 +78,7 @@ BELLESIP_EXPORT int belle_sdp_bandwidth_get_value(const belle_sdp_bandwidth_t* a
BELLESIP_EXPORT const char* belle_sdp_bandwidth_get_type(const belle_sdp_bandwidth_t* attribute);
BELLESIP_EXPORT void belle_sdp_bandwidth_set_value(belle_sdp_bandwidth_t* attribute, int value);
BELLESIP_EXPORT void belle_sdp_bandwidth_set_type(belle_sdp_bandwidth_t* attribute, const char* type);
#define BELLE_SDP_BANDWIDTH(t) BELLE_SDP_CAST(t,belle_sdp_bandwidth_t);
#define BELLE_SDP_BANDWIDTH(t) BELLE_SDP_CAST(t,belle_sdp_bandwidth_t)
/***************************************************************************************
* Connection
*
......@@ -63,7 +93,7 @@ BELLESIP_EXPORT const char* belle_sdp_connection_get_network_type(const belle_sd
BELLESIP_EXPORT void belle_sdp_connection_set_address(belle_sdp_connection_t* connection, const char* addr);
BELLESIP_EXPORT void belle_sdp_connection_set_address_type(belle_sdp_connection_t* connection, const char* type);
BELLESIP_EXPORT void belle_sdp_connection_set_network_type(belle_sdp_connection_t* connection, const char* type);
#define BELLE_SDP_CONNECTION(t) BELLE_SDP_CAST(t,belle_sdp_connection_t);
#define BELLE_SDP_CONNECTION(t) BELLE_SDP_CAST(t,belle_sdp_connection_t)
/***************************************************************************************
* Email
*
......@@ -73,7 +103,7 @@ BELLESIP_EXPORT belle_sdp_email_t* belle_sdp_email_new();
BELLESIP_EXPORT belle_sdp_email_t* belle_sdp_email_parse (const char* email);
BELLESIP_EXPORT const char* belle_sdp_email_get_value(const belle_sdp_email_t* email);
BELLESIP_EXPORT void belle_sdp_email_set_value(belle_sdp_email_t* email, const char* value);
#define BELLE_SDP_EMAIL(t) BELLE_SDP_CAST(t,belle_sdp_email_t);
#define BELLE_SDP_EMAIL(t) BELLE_SDP_CAST(t,belle_sdp_email_t)
/***************************************************************************************
* Info
*
......@@ -83,7 +113,7 @@ BELLESIP_EXPORT belle_sdp_info_t* belle_sdp_info_new();
BELLESIP_EXPORT belle_sdp_info_t* belle_sdp_info_parse (const char* info);
BELLESIP_EXPORT const char* belle_sdp_info_get_value(const belle_sdp_info_t* info);
BELLESIP_EXPORT void belle_sdp_info_set_value(belle_sdp_info_t* info, const char* value);
#define BELLE_SDP_INFO(t) BELLE_SDP_CAST(t,belle_sdp_info_t);
#define BELLE_SDP_INFO(t) BELLE_SDP_CAST(t,belle_sdp_info_t)
/***************************************************************************************
* Key
*
......@@ -121,7 +151,7 @@ BELLESIP_EXPORT void belle_sdp_media_set_media_port(belle_sdp_media_t* media, in
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);
BELLESIP_EXPORT void belle_sdp_media_set_protocol(belle_sdp_media_t* media, const char* protocole);
#define BELLE_SDP_MEDIA(t) BELLE_SDP_CAST(t,belle_sdp_media_t);
#define BELLE_SDP_MEDIA(t) BELLE_SDP_CAST(t,belle_sdp_media_t)
/***************************************************************************************
* mime_parameter
......@@ -144,7 +174,7 @@ BELLESIP_EXPORT int belle_sdp_mime_parameter_get_media_format(const belle_sdp_mi
BELLESIP_EXPORT void belle_sdp_mime_parameter_set_media_format(belle_sdp_mime_parameter_t* mime_parameter,int format);
BELLESIP_EXPORT const char* belle_sdp_mime_parameter_get_parameters(const belle_sdp_mime_parameter_t* mime_parameter);
BELLESIP_EXPORT void belle_sdp_mime_parameter_set_parameters(belle_sdp_mime_parameter_t* mime_parameter,const char* parameters);
#define BELLE_SDP_MIME_PARAMETER(t) BELLE_SDP_CAST(t,belle_sdp_mime_parameter_t);
#define BELLE_SDP_MIME_PARAMETER(t) BELLE_SDP_CAST(t,belle_sdp_mime_parameter_t)
/***************************************************************************************
* Media Description
......@@ -183,7 +213,7 @@ BELLESIP_EXPORT void belle_sdp_media_description_set_info(belle_sdp_media_descri
/*void belle_sdp_media_description_set_key(belle_sdp_media_description_t* media_description,belle_sdp_key_t* key);*/
BELLESIP_EXPORT void belle_sdp_media_description_set_media(belle_sdp_media_description_t* media_description, belle_sdp_media_t* media);
BELLESIP_EXPORT void belle_sdp_media_description_append_values_from_mime_parameter(belle_sdp_media_description_t* media_description, const belle_sdp_mime_parameter_t* mime_parameter);
#define BELLE_SDP_MEDIA_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_media_description_t);
#define BELLE_SDP_MEDIA_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_media_description_t)
/***************************************************************************************
* Origin
......@@ -210,7 +240,7 @@ BELLESIP_EXPORT void belle_sdp_origin_set_network_type(belle_sdp_origin_t* origi
BELLESIP_EXPORT void belle_sdp_origin_set_session_id(belle_sdp_origin_t* origin, unsigned int session_id);
BELLESIP_EXPORT void belle_sdp_origin_set_session_version(belle_sdp_origin_t* origin, unsigned int version);
BELLESIP_EXPORT 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);
#define BELLE_SDP_ORIGIN(t) BELLE_SDP_CAST(t,belle_sdp_origin_t)
/***************************************************************************************
* Phone
*
......@@ -220,7 +250,7 @@ BELLESIP_EXPORT belle_sdp_phone_t* belle_sdp_phone_new();
BELLESIP_EXPORT belle_sdp_phone_t* belle_sdp_phone_parse (const char* phone);
BELLESIP_EXPORT const char* belle_sdp_phone_get_value(const belle_sdp_phone_t* phone);
BELLESIP_EXPORT void belle_sdp_phone_set_value(belle_sdp_phone_t* phone, const char* value);
#define BELLE_SDP_PHONE(t) BELLE_SDP_CAST(t,belle_sdp_phone_t);
#define BELLE_SDP_PHONE(t) BELLE_SDP_CAST(t,belle_sdp_phone_t)
/***************************************************************************************
* Repeat time
*
......@@ -230,7 +260,7 @@ BELLESIP_EXPORT belle_sdp_repeate_time_t* belle_sdp_repeate_time_new();
BELLESIP_EXPORT belle_sdp_repeate_time_t* belle_sdp_repeate_time_parse (const char* repeate_time);
BELLESIP_EXPORT const char* belle_sdp_repeate_time_get_value(const belle_sdp_repeate_time_t* repeate_time);
BELLESIP_EXPORT void belle_sdp_repeate_time_set_value(belle_sdp_repeate_time_t* repeate_time, const char* value);
#define BELLE_SDP_REPEATE_TIME(t) BELLE_SDP_CAST(t,belle_sdp_repeate_time_t);
#define BELLE_SDP_REPEATE_TIME(t) BELLE_SDP_CAST(t,belle_sdp_repeate_time_t)
/***************************************************************************************
* Session Name
*
......@@ -240,7 +270,7 @@ BELLESIP_EXPORT belle_sdp_session_name_t* belle_sdp_session_name_new();
BELLESIP_EXPORT belle_sdp_session_name_t* belle_sdp_session_name_create (const char* name);
BELLESIP_EXPORT const char* belle_sdp_session_name_get_value(const belle_sdp_session_name_t* session_name);
BELLESIP_EXPORT 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);
#define BELLE_SDP_SESSION_NAME(t) BELLE_SDP_CAST(t,belle_sdp_session_name_t)
/***************************************************************************************
* Time
*
......@@ -253,7 +283,7 @@ BELLESIP_EXPORT int belle_sdp_time_get_start(const belle_sdp_time_t* time);
BELLESIP_EXPORT int belle_sdp_time_get_stop(const belle_sdp_time_t* time);
BELLESIP_EXPORT void belle_sdp_time_set_start(belle_sdp_time_t* time, int value);
BELLESIP_EXPORT 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);
#define BELLE_SDP_TIME(t) BELLE_SDP_CAST(t,belle_sdp_time_t)
/***************************************************************************************
* Time description
*
......@@ -267,7 +297,7 @@ BELLESIP_EXPORT belle_sip_list_t* belle_sdp_time_description_get_repeate_times(c
BELLESIP_EXPORT belle_sdp_time_t* belle_sdp_time_description_get_time(const belle_sdp_time_description_t* time_description);
BELLESIP_EXPORT void belle_sdp_time_description_set_repeate_times(belle_sdp_time_description_t* time_description, belle_sip_list_t* times);
BELLESIP_EXPORT void belle_sdp_time_description_set_time(belle_sdp_time_description_t* time_description, belle_sdp_time_t* times);
#define BELLE_SDP_TIME_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_time_description_t);
#define BELLE_SDP_TIME_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_time_description_t)
/***************************************************************************************
* URI
*
......@@ -277,7 +307,7 @@ BELLESIP_EXPORT belle_sdp_uri_t* belle_sdp_uri_new();
BELLESIP_EXPORT belle_sdp_uri_t* belle_sdp_uri_parse (const char* uri);
BELLESIP_EXPORT const char* belle_sdp_uri_get_value(const belle_sdp_uri_t* uri);
BELLESIP_EXPORT void belle_sdp_uri_set_value(belle_sdp_uri_t* uri, const char* value);
#define BELLE_SDP_URI(t) BELLE_SDP_CAST(t,belle_sdp_uri_t);
#define BELLE_SDP_URI(t) BELLE_SDP_CAST(t,belle_sdp_uri_t)
/***************************************************************************************
* Version
*
......@@ -287,7 +317,7 @@ belle_sdp_version_t* belle_sdp_version_new();
BELLESIP_EXPORT belle_sdp_version_t* belle_sdp_version_create(int version);
BELLESIP_EXPORT int belle_sdp_version_get_version(const belle_sdp_version_t* version);
BELLESIP_EXPORT 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);
#define BELLE_SDP_VERSION(t) BELLE_SDP_CAST(t,belle_sdp_version_t)
/***************************************************************************************
* Session Description
......@@ -335,5 +365,5 @@ BELLESIP_EXPORT void belle_sdp_session_description_set_time_description(belle_sd
BELLESIP_EXPORT void belle_sdp_session_description_set_uri(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* uri);
BELLESIP_EXPORT void belle_sdp_session_description_set_version(belle_sdp_session_description_t* session_description, belle_sdp_version_t* v);
BELLESIP_EXPORT void belle_sdp_session_description_set_zone_adjustments(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* zoneAdjustments);
#define BELLE_SDP_SESSION_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_session_description_t);
#define BELLE_SDP_SESSION_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_session_description_t)
#endif /* BELLE_SDP_H_ */
......@@ -89,7 +89,9 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sdp_media_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_origin_t),
BELLE_SIP_TYPE_ID(belle_sdp_phone_t),
BELLE_SIP_TYPE_ID(belle_sdp_raw_attribute_t),
BELLE_SIP_TYPE_ID(belle_sdp_repeate_time_t),
BELLE_SIP_TYPE_ID(belle_sdp_rtcp_xr_attribute_t),
BELLE_SIP_TYPE_ID(belle_sdp_session_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_session_name_t),
BELLE_SIP_TYPE_ID(belle_sdp_time_t),
......
......@@ -46,7 +46,7 @@ set(SDP_GENERATED_SOURCE_FILES
)
add_custom_command(
OUTPUT ${SDP_GENERATED_SOURCE_FILES}
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR3_JAR_PATH} -make -Xmultithreaded -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sdp.g
COMMAND ${ANTLR3_COMMAND} -make -Xmultithreaded -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sdp.g
DEPENDS grammars/belle_sdp.g
)
......@@ -58,7 +58,7 @@ set(SIP_MESSAGE_GENERATED_SOURCE_FILES
)
add_custom_command(
OUTPUT ${SIP_MESSAGE_GENERATED_SOURCE_FILES}
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR3_JAR_PATH} -make -Xmultithreaded -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sip_message.g
COMMAND ${ANTLR3_COMMAND} -make -Xmultithreaded -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sip_message.g
DEPENDS grammars/belle_sip_message.g
)
......
......@@ -37,44 +37,162 @@ struct _belle_sdp_mime_parameter {
* Attribute
*
**************************************************************************************/
typedef belle_sdp_attribute_t* (*attribute_parse_func)(const char*) ;
struct attribute_name_func_pair {
const char* name;
attribute_parse_func func;
};
static struct attribute_name_func_pair attribute_table[] = {
{ "rtcp-xr", (attribute_parse_func)belle_sdp_rtcp_xr_attribute_parse }
};
struct _belle_sdp_attribute {
belle_sip_object_t base;
const char* name;
const char* value;
};
void belle_sdp_attribute_destroy(belle_sdp_attribute_t* attribute) {
if (attribute->name) belle_sip_free((void*)attribute->name);
if (attribute->value) belle_sip_free((void*)attribute->value);
DESTROY_STRING(attribute,name)
}
void belle_sdp_attribute_clone(belle_sdp_attribute_t *attribute, const belle_sdp_attribute_t *orig){
CLONE_STRING(belle_sdp_attribute,name,attribute,orig)
CLONE_STRING(belle_sdp_attribute,value,attribute,orig)
}
belle_sip_error_code belle_sdp_attribute_marshal(belle_sdp_attribute_t* attribute, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_snprintf(buff,buff_size,offset,"a=%s",attribute->name);
if (error!=BELLE_SIP_OK) return error;
return belle_sip_snprintf(buff, buff_size, offset, "a=%s", attribute->name);
}
belle_sdp_attribute_t* belle_sdp_attribute_create(const char* name, const char* value) {
belle_sdp_attribute_t* ret;
int i;
size_t elements = sizeof(attribute_table) / sizeof(attribute_table[0]);
if (!name || name[0] == '\0') {
belle_sip_error("Cannot create SDP attribute without name");
return NULL;
}
for (i = 0; i < elements; i++) {
if (strcasecmp(attribute_table[i].name, name) == 0) {
char* raw;
if (value)
raw = belle_sip_strdup_printf("a=%s:%s", name, value);
else
raw = belle_sip_strdup_printf("a=%s", name);
ret = attribute_table[i].func(raw);
belle_sip_free(raw);
return ret;
}
}
/* Not a specialized SDP attribute */
return BELLE_SDP_ATTRIBUTE(belle_sdp_raw_attribute_create(name, value));
}
BELLE_SDP_NEW(attribute,belle_sip_object)
BELLE_SDP_PARSE(attribute)
GET_SET_STRING(belle_sdp_attribute,name);
/***************************************************************************************
* RAW Attribute
*
**************************************************************************************/
struct _belle_sdp_raw_attribute {
belle_sdp_attribute_t base;
const char* value;
};
void belle_sdp_raw_attribute_destroy(belle_sdp_raw_attribute_t* attribute) {
DESTROY_STRING(attribute,value)
}
void belle_sdp_raw_attribute_clone(belle_sdp_raw_attribute_t* attribute, const belle_sdp_raw_attribute_t* orig) {
CLONE_STRING(belle_sdp_raw_attribute,value,attribute,orig)
}
belle_sip_error_code belle_sdp_raw_attribute_marshal(belle_sdp_raw_attribute_t* attribute, char* buff, size_t buff_size, size_t* offset) {
belle_sip_error_code error = belle_sdp_attribute_marshal(BELLE_SDP_ATTRIBUTE(attribute), buff, buff_size, offset);
if (error != BELLE_SIP_OK) return error;
if (attribute->value) {
error=belle_sip_snprintf(buff,buff_size,offset,":%s",attribute->value);
if (error!=BELLE_SIP_OK) return error;
error = belle_sip_snprintf(buff, buff_size, offset, ":%s", attribute->value);
if (error != BELLE_SIP_OK) return error;
}
return error;
}
BELLE_SDP_NEW(attribute,belle_sip_object)
belle_sdp_attribute_t* belle_sdp_attribute_create (const char* name,const char* value) {
belle_sdp_attribute_t* attribute = belle_sdp_attribute_new();
belle_sdp_attribute_set_name(attribute,name);
belle_sdp_attribute_set_value(attribute,value);
BELLE_SDP_NEW(raw_attribute,belle_sdp_attribute)
belle_sdp_raw_attribute_t* belle_sdp_raw_attribute_create(const char* name, const char* value) {
belle_sdp_raw_attribute_t* attribute = belle_sdp_raw_attribute_new();
belle_sdp_attribute_set_name(BELLE_SDP_ATTRIBUTE(attribute), name);
belle_sdp_raw_attribute_set_value(attribute, value);
return attribute;
}
BELLE_SDP_PARSE(attribute)
GET_SET_STRING(belle_sdp_attribute,name);
GET_SET_STRING(belle_sdp_attribute,value);
unsigned int belle_sdp_attribute_as_value(const belle_sdp_attribute_t* attribute) {
GET_SET_STRING(belle_sdp_raw_attribute,value);
unsigned int belle_sdp_raw_attribute_has_value(const belle_sdp_raw_attribute_t* attribute) {
return attribute->value!=NULL;
}
/***************************************************************************************
* RTCP-XR Attribute
*
**************************************************************************************/
struct _belle_sdp_rtcp_xr_attribute {
belle_sdp_attribute_t base;
const char* rcvr_rtt_mode;
int rcvr_rtt_max_size;
unsigned int stat_summary;
belle_sip_list_t* stat_summary_flags;
unsigned int voip_metrics;
};
belle_sip_list_t* belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(const belle_sdp_rtcp_xr_attribute_t* attribute) {
return attribute->stat_summary_flags;
}
void belle_sdp_rtcp_xr_attribute_set_stat_summary_flags(belle_sdp_rtcp_xr_attribute_t* attribute, belle_sip_list_t* flags) {
attribute->stat_summary_flags = flags;
}
void belle_sdp_rtcp_xr_attribute_add_stat_summary_flag(belle_sdp_rtcp_xr_attribute_t* attribute, const char* flag) {
attribute->stat_summary_flags = belle_sip_list_append(attribute->stat_summary_flags, belle_sip_strdup(flag));
}
void belle_sdp_rtcp_xr_attribute_destroy(belle_sdp_rtcp_xr_attribute_t* attribute) {
DESTROY_STRING(attribute,rcvr_rtt_mode)
belle_sip_list_free(attribute->stat_summary_flags);
}
void belle_sdp_rtcp_xr_attribute_clone(belle_sdp_rtcp_xr_attribute_t* attribute, const belle_sdp_rtcp_xr_attribute_t *orig) {
CLONE_STRING(belle_sdp_rtcp_xr_attribute,rcvr_rtt_mode,attribute,orig)
attribute->rcvr_rtt_max_size = orig->rcvr_rtt_max_size;
attribute->stat_summary = orig->stat_summary;
attribute->stat_summary_flags = belle_sip_list_copy(orig->stat_summary_flags);
attribute->voip_metrics = orig->voip_metrics;
}
belle_sip_error_code belle_sdp_rtcp_xr_attribute_marshal(belle_sdp_rtcp_xr_attribute_t* attribute, char * buff, size_t buff_size, size_t *offset) {
const char *rcvr_rtt_mode = NULL;
int rcvr_rtt_max_size = -1;
int nb_xr_formats = 0;
belle_sip_error_code error = belle_sdp_attribute_marshal(BELLE_SDP_ATTRIBUTE(attribute), buff, buff_size, offset);
if (error != BELLE_SIP_OK) return error;
rcvr_rtt_mode = belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(attribute);
if (rcvr_rtt_mode != NULL) {
error = belle_sip_snprintf(buff, buff_size, offset, "%srcvr-rtt=%s", nb_xr_formats++ == 0 ? ":" : " ", rcvr_rtt_mode);
if (error != BELLE_SIP_OK) return error;
rcvr_rtt_max_size = belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_max_size(attribute);
if (rcvr_rtt_max_size > 0) {
error = belle_sip_snprintf(buff, buff_size, offset, ":%u", rcvr_rtt_max_size);
if (error != BELLE_SIP_OK) return error;
}
}
if (belle_sdp_rtcp_xr_attribute_has_stat_summary(attribute)) {
belle_sip_list_t* list;
int nb_stat_flags = 0;
error = belle_sip_snprintf(buff, buff_size, offset, "%sstat-summary", nb_xr_formats++ == 0 ? ":" : " ");
if (error != BELLE_SIP_OK) return error;
for (list = attribute->stat_summary_flags; list != NULL; list = list->next) {
error = belle_sip_snprintf(buff, buff_size, offset, "%s%s", nb_stat_flags++ == 0 ? "=" : ",", (const char*)list->data);
if (error != BELLE_SIP_OK) return error;
}
}
if (belle_sdp_rtcp_xr_attribute_has_voip_metrics(attribute)) {
error = belle_sip_snprintf(buff, buff_size, offset, "%svoip-metrics", nb_xr_formats++ == 0 ? ":" : " ");
if (error != BELLE_SIP_OK) return error;
}
return error;
}
static void belle_sdp_rtcp_xr_attribute_init(belle_sdp_rtcp_xr_attribute_t* attribute) {
belle_sdp_attribute_set_name(BELLE_SDP_ATTRIBUTE(attribute), "rtcp-xr");
}
BELLE_SDP_NEW_WITH_CTR(rtcp_xr_attribute,belle_sdp_attribute)
BELLE_SDP_PARSE(rtcp_xr_attribute)
GET_SET_STRING(belle_sdp_rtcp_xr_attribute,rcvr_rtt_mode)
GET_SET_INT(belle_sdp_rtcp_xr_attribute,rcvr_rtt_max_size,int)
GET_SET_BOOL(belle_sdp_rtcp_xr_attribute,stat_summary,has)
GET_SET_BOOL(belle_sdp_rtcp_xr_attribute,voip_metrics,has)
/***************************************************************************************
* Bandwidth
*
......@@ -345,10 +463,14 @@ const belle_sdp_attribute_t* belle_sdp_base_description_get_attribute(const bell
}
const char* belle_sdp_base_description_get_attribute_value(const belle_sdp_base_description_t* base_description, const char* name) {
const belle_sdp_attribute_t* attribute = belle_sdp_base_description_get_attribute(base_description,name);
if (attribute)
return belle_sdp_attribute_get_value(attribute);
else
return NULL;
if (attribute) {
if (BELLE_SIP_IS_INSTANCE_OF(attribute, belle_sdp_raw_attribute_t)) {
return belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attribute));
} else {
belle_sip_error("Cannot get value of non-raw SDP attribute '%s'! Use specialized attribute object.", name);
return NULL;
}
} else return NULL;
}
belle_sip_list_t* belle_sdp_base_description_get_attributes(const belle_sdp_base_description_t* base_description) {
......@@ -385,9 +507,9 @@ void belle_sdp_base_description_remove_bandwidth(belle_sdp_base_description_t* b
}
}
void belle_sdp_base_description_set_attribute_value(belle_sdp_base_description_t* base_description, const char* name, const char* value) {
belle_sdp_attribute_t* attribute = belle_sdp_attribute_new();
belle_sdp_attribute_set_name(attribute,name);
belle_sdp_attribute_set_value(attribute,value);
belle_sdp_raw_attribute_t* attribute = belle_sdp_raw_attribute_new();
belle_sdp_attribute_set_name(BELLE_SDP_ATTRIBUTE(attribute),name);
belle_sdp_raw_attribute_set_value(attribute,value);
base_description->attributes = belle_sip_list_append(base_description->attributes,belle_sip_object_ref(attribute));
}
void belle_sdp_base_description_add_attribute(belle_sdp_base_description_t* base_description, const belle_sdp_attribute_t* attribute) {
......@@ -645,16 +767,16 @@ static const char *belle_sdp_media_description_a_attr_value_get_with_pt(const be
;attribute_list=attribute_list->next) {
attr = BELLE_SDP_ATTRIBUTE(attribute_list->data);
if (strcmp(field,belle_sdp_attribute_get_name(attr))==0 && belle_sdp_attribute_get_value(attr)!=NULL){
int nb = sscanf(belle_sdp_attribute_get_value(attr),"%i %n",&tmppt,&scanned);
if (strcmp(field,belle_sdp_attribute_get_name(attr))==0 && belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr))!=NULL){
int nb = sscanf(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr)),"%i %n",&tmppt,&scanned);
/* the return value may depend on how %n is interpreted by the libc: see manpage*/
if (nb == 1 || nb==2 ){
if (pt==tmppt){
tmp=belle_sdp_attribute_get_value(attr)+scanned;
tmp=belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr))+scanned;
if (strlen(tmp)>0)
return tmp;
}
}else belle_sip_warning("sdp has a strange a= line (%s) nb=%i",belle_sdp_attribute_get_value(attr),nb);
}else belle_sip_warning("sdp has a strange a= line (%s) nb=%i",belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr)),nb);
}
}
return NULL;
......
......@@ -169,7 +169,9 @@ BELLE_SIP_DECLARE_VPTR(belle_sdp_media_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_media_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_origin_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_phone_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_raw_attribute_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_repeate_time_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_rtcp_xr_attribute_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_session_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_session_name_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_time_t);
......
......@@ -219,11 +219,75 @@ key_value options { greedy = false; }: (~(CR|LF))*;
//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; }: {IS_TOKEN(a)}?alpha_num EQUAL attribute_value;
media_description returns [belle_sdp_media_description_t* ret]
attribute returns [belle_sdp_attribute_t* ret]
scope {int has_value;}
@init {$ret=NULL;}
: {IS_TOKEN(a)}?alpha_num EQUAL attribute_content{$ret=$attribute_content.ret;};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
if ($ret) belle_sip_object_unref($ret);
$ret=NULL;
}
attribute_content returns [belle_sdp_attribute_t* ret]
@init {$ret=NULL; }
: attribute_name (COLON val=attribute_value {$ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,(const char*)$attribute_value.text->chars);})?
{
if (!val.tree) $ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,NULL);
};
rtcp_xr_attribute returns [belle_sdp_rtcp_xr_attribute_t* ret]
scope { belle_sdp_rtcp_xr_attribute_t* current; }
@init { $rtcp_xr_attribute::current = belle_sdp_rtcp_xr_attribute_new();$ret = $rtcp_xr_attribute::current;}
: {IS_TOKEN(a)}?alpha_num EQUAL {IS_TOKEN(rtcp-xr)}? attribute_name /*'rtcp-xr'*/ (COLON rtcp_xr_attribute_value (SPACE rtcp_xr_attribute_value)*)?;
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;
}
rtcp_xr_attribute_value :
(pkt_loss_rle)=> pkt_loss_rle
| (pkt_dup_rle)=> pkt_dup_rle
| (pkt_rcpt_times)=> pkt_rcpt_times
| (rcvr_rtt)=> rcvr_rtt
| (stat_summary)=> stat_summary
| (voip_metrics)=> voip_metrics;
pkt_loss_rle :
{IS_TOKEN(pkt-loss-rle)}? rtcp_xr_attribute_name /*'pkt-loss-rle'*/ (EQUAL rtcp_xr_max_size)? ;
pkt_dup_rle :
{IS_TOKEN(pkt-dup-rle)}? rtcp_xr_attribute_name /*'pkt-dup-rle'*/ (EQUAL rtcp_xr_max_size)? ;
pkt_rcpt_times :
{IS_TOKEN(pkt-rcpt-times)}? rtcp_xr_attribute_name /*'pkt-rcpt-times'*/ (EQUAL rtcp_xr_max_size)? ;
rcvr_rtt :
{IS_TOKEN(rcvr-rtt)}? rtcp_xr_attribute_name /*'rcvr-rtt'*/ EQUAL {IS_TOKEN(all) || IS_TOKEN(sender)}? rtcp_xr_rcvr_rtt_mode (COLON val=rtcp_xr_max_size)? {
belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_mode($rtcp_xr_attribute::current,(const char*)$rtcp_xr_rcvr_rtt_mode.text->chars);
if (val.tree) belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_max_size($rtcp_xr_attribute::current,atoi((const char*)$rtcp_xr_max_size.text->chars));
};
stat_summary :
{IS_TOKEN(stat-summary)}? rtcp_xr_attribute_name /*'stat-summary'*/ {
belle_sdp_rtcp_xr_attribute_set_stat_summary($rtcp_xr_attribute::current,1);
} (EQUAL rtcp_xr_stat_summary_flag (COMMA rtcp_xr_stat_summary_flag)*)?;
voip_metrics :
{IS_TOKEN(voip-metrics)}? rtcp_xr_attribute_name /*'voip-metrics'*/ {
belle_sdp_rtcp_xr_attribute_set_voip_metrics($rtcp_xr_attribute::current,1);
};
rtcp_xr_stat_summary_flag :
{IS_TOKEN(loss) || IS_TOKEN(dup) || IS_TOKEN(jitt) || IS_TOKEN(TTL) || IS_TOKEN(HL)}?rtcp_xr_stat_summary_flag_value {
belle_sdp_rtcp_xr_attribute_add_stat_summary_flag($rtcp_xr_attribute::current,(const char*)$rtcp_xr_stat_summary_flag_value.text->chars);
};
rtcp_xr_max_size : DIGIT+;
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; }
: media CR LF {belle_sdp_media_description_set_media($media_description::current,$media.ret);}
......@@ -232,13 +296,13 @@ scope { belle_sdp_media_description_t* current; }
(bandwidth {belle_sdp_media_description_add_bandwidth($media_description::current,$bandwidth.ret);} CR LF)*
(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; }
......@@ -260,7 +324,7 @@ media_value: alpha_num+;
fmt
scope { int is_number; }
@init { $fmt::is_number=0;}: ((DIGIT+)=>(DIGIT+){$fmt::is_number=1;} | token+ )
@init { $fmt::is_number=0;}: ((DIGIT+)=>(DIGIT+){$fmt::is_number=1;} | token )
{belle_sdp_media_set_media_formats($media::current
,belle_sip_