Commit 7e2b369f authored by jehan's avatar jehan
Browse files

Finilize clone implementation

parent 5a453382
......@@ -120,8 +120,8 @@
</fileInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
<entry excluding="basic_test.c|cast_test.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="tester"/>
<entry excluding="sender_task.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="describe.c|basic_test.c|cast_test.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="tester"/>
</sourceEntries>
</configuration>
</storageModule>
......@@ -1181,8 +1181,8 @@
</fileInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="tester"/>
<entry excluding="sender_task.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="describe.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="tester"/>
</sourceEntries>
</configuration>
</storageModule>
......
......@@ -48,6 +48,8 @@ int belle_sip_list_index(const belle_sip_list_t * list, void *data);
belle_sip_list_t * belle_sip_list_insert_sorted(belle_sip_list_t * list, void *data, belle_sip_compare_func cmp);
belle_sip_list_t * belle_sip_list_insert(belle_sip_list_t * list, belle_sip_list_t * before, void *data);
belle_sip_list_t * belle_sip_list_copy(const belle_sip_list_t * list);
/*copy list elements and associated data, using the supplied function pointer*/
belle_sip_list_t* belle_sip_list_copy_with_data(const belle_sip_list_t* list, void* (*copyfunc)(void*));
#endif /* BELLE_SIP_LIST_H_ */
......@@ -101,9 +101,16 @@ struct _belle_sdp_connection {
};
void belle_sdp_connection_destroy(belle_sdp_connection_t* connection) {
DESTROY_STRING(connection,network_type)
DESTROY_STRING(connection,address_type)
DESTROY_STRING(connection,address)
}
void belle_sdp_connection_clone(belle_sdp_connection_t *connection, const belle_sdp_connection_t *orig){
CLONE_STRING(belle_sdp_connection,network_type,connection,orig)
CLONE_STRING(belle_sdp_connection,address_type,connection,orig)
CLONE_STRING(belle_sdp_connection,address,connection,orig)
}
int belle_sdp_connection_marshal(belle_sdp_connection_t* connection, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -129,9 +136,11 @@ struct _belle_sdp_email {
};
void belle_sdp_email_destroy(belle_sdp_email_t* email) {
DESTROY_STRING(email,value)
}
void belle_sdp_email_clone(belle_sdp_email_t *email, const belle_sdp_email_t *orig){
CLONE_STRING(belle_sdp_email,value,email,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;
......@@ -153,9 +162,11 @@ struct _belle_sdp_info {
};
void belle_sdp_info_destroy(belle_sdp_info_t* info) {
DESTROY_STRING(info,value)
}
void belle_sdp_info_clone(belle_sdp_info_t *info, const belle_sdp_info_t *orig){
CLONE_STRING(belle_sdp_info,value,info,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;
......@@ -186,12 +197,20 @@ void belle_sdp_media_set_media_formats( belle_sdp_media_t* media, belle_sip_list
media->media_formats = formats;
}
void belle_sdp_media_destroy(belle_sdp_media_t* media) {
DESTROY_STRING(media,media_type)
belle_sip_list_free(media->media_formats);
DESTROY_STRING(media,protocol)
}
static void belle_sdp_media_init(belle_sdp_media_t* media) {
media->port_count=1;
}
void belle_sdp_media_clone(belle_sdp_media_t *media, const belle_sdp_media_t *orig){
CLONE_STRING(belle_sdp_media,media_type,media,orig)
media->media_port=orig->media_port;
media->media_formats = belle_sip_list_copy(orig->media_formats);
media->port_count=orig->port_count;
CLONE_STRING(belle_sdp_media,protocol,media,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;
......@@ -230,6 +249,12 @@ GET_SET_INT(belle_sdp_media,port_count,int)
/************************
* base_description
***********************/
static void belle_sip_object_freefunc(void* obj) {
belle_sip_object_unref(BELLE_SIP_OBJECT(obj));
}
static void* belle_sip_object_copyfunc(void* obj) {
return belle_sip_object_clone(BELLE_SIP_OBJECT(obj));
}
typedef struct _belle_sdp_base_description {
belle_sip_object_t base;
......@@ -239,11 +264,20 @@ typedef struct _belle_sdp_base_description {
belle_sip_list_t* attributes;
} belle_sdp_base_description_t;
void belle_sdp_base_description_destroy(belle_sdp_base_description_t* base_description) {
static void belle_sdp_base_description_destroy(belle_sdp_base_description_t* base_description) {
if (base_description->info) belle_sip_object_unref(BELLE_SIP_OBJECT(base_description->info));
if (base_description->connection) belle_sip_object_unref(BELLE_SIP_OBJECT(base_description->connection));
belle_sip_list_free_with_data(base_description->bandwidths,belle_sip_object_freefunc);
belle_sip_list_free_with_data(base_description->attributes,belle_sip_object_freefunc);
}
void belle_sdp_base_description_init(belle_sdp_base_description_t* base_description) {
static void belle_sdp_base_description_init(belle_sdp_base_description_t* base_description) {
}
void belle_sdp_base_description_clone(belle_sdp_base_description_t *base_description, const belle_sdp_base_description_t *orig){
static void belle_sdp_base_description_clone(belle_sdp_base_description_t *base_description, const belle_sdp_base_description_t *orig){
if (orig->info) base_description->info = BELLE_SDP_INFO(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->info)));
if (orig->connection) base_description->connection = BELLE_SDP_CONNECTION(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->connection)));
base_description->bandwidths = belle_sip_list_copy_with_data(orig->bandwidths,belle_sip_object_copyfunc);
base_description->attributes = belle_sip_list_copy_with_data(orig->attributes,belle_sip_object_copyfunc);
}
int belle_sdp_base_description_marshal(belle_sdp_base_description_t* base_description, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -269,7 +303,12 @@ int belle_sdp_base_description_marshal(belle_sdp_base_description_t* base_descri
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sdp_base_description_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sdp_base_description_t,belle_sip_object_t,belle_sdp_base_description_destroy,NULL,belle_sdp_base_description_marshal,FALSE);
BELLE_SIP_INSTANCIATE_VPTR(belle_sdp_base_description_t
,belle_sip_object_t
,belle_sdp_base_description_destroy
,belle_sdp_base_description_clone
,belle_sdp_base_description_marshal
,FALSE);
static int belle_sdp_base_description_attribute_comp_func(const belle_sdp_attribute_t* a, const char*b) {
return strcmp(a->name,b);
......@@ -361,9 +400,11 @@ struct _belle_sdp_media_description {
belle_sdp_media_t* media;
};
void belle_sdp_media_description_destroy(belle_sdp_media_description_t* media_description) {
if (media_description->media) belle_sip_object_unref(BELLE_SIP_OBJECT((media_description->media)));
}
void belle_sdp_media_description_clone(belle_sdp_media_description_t *media_description, const belle_sdp_media_description_t *orig){
if (orig->media) media_description->media = BELLE_SDP_MEDIA(belle_sip_object_clone(BELLE_SIP_OBJECT((orig->media))));
}
int belle_sdp_media_description_marshal(belle_sdp_media_description_t* media_description, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -626,9 +667,19 @@ struct _belle_sdp_origin {
};
void belle_sdp_origin_destroy(belle_sdp_origin_t* origin) {
DESTROY_STRING(origin,address)
DESTROY_STRING(origin,address_type)
DESTROY_STRING(origin,network_type)
DESTROY_STRING(origin,username)
}
void belle_sdp_origin_clone(belle_sdp_origin_t *origin, const belle_sdp_origin_t *orig){
CLONE_STRING(belle_sdp_origin,username,origin,orig);
CLONE_STRING(belle_sdp_origin,address,origin,orig);
CLONE_STRING(belle_sdp_origin,address_type,origin,orig);
CLONE_STRING(belle_sdp_origin,network_type,origin,orig);
origin->session_id = orig->session_id;
origin->session_version = orig->session_version;
}
int belle_sdp_origin_marshal(belle_sdp_origin_t* origin, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -660,9 +711,11 @@ struct _belle_sdp_session_name {
};
void belle_sdp_session_name_destroy(belle_sdp_session_name_t* session_name) {
DESTROY_STRING(session_name,value)
}
void belle_sdp_session_name_clone(belle_sdp_session_name_t *session_name, const belle_sdp_session_name_t *orig){
CLONE_STRING(belle_sdp_session_name,value,session_name,orig);
}
int belle_sdp_session_name_marshal(belle_sdp_session_name_t* session_name, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -694,9 +747,27 @@ struct _belle_sdp_session_description {
};
void belle_sdp_session_description_destroy(belle_sdp_session_description_t* session_description) {
if (session_description->version) belle_sip_object_unref(BELLE_SIP_OBJECT(session_description->version));
belle_sip_list_free_with_data(session_description->emails,belle_sip_object_freefunc);
if (session_description->origin) belle_sip_object_unref(BELLE_SIP_OBJECT(session_description->origin));
if (session_description->session_name) belle_sip_object_unref(BELLE_SIP_OBJECT(session_description->session_name));
belle_sip_list_free_with_data(session_description->phones,belle_sip_object_freefunc);
belle_sip_list_free_with_data(session_description->times,belle_sip_object_freefunc);
if (session_description->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(session_description->uri));
if (session_description->zone_adjustments) belle_sip_object_unref(BELLE_SIP_OBJECT(session_description->zone_adjustments));
belle_sip_list_free_with_data(session_description->media_descriptions,belle_sip_object_freefunc);
}
void belle_sdp_session_description_clone(belle_sdp_session_description_t *session_description, const belle_sdp_session_description_t *orig){
if (orig->version) session_description->version = BELLE_SDP_VERSION(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->version)));
session_description->emails = belle_sip_list_copy_with_data(orig->emails,belle_sip_object_copyfunc);
if (orig->origin) session_description->origin = BELLE_SDP_ORIGIN(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->origin)));
if (orig->session_name) session_description->session_name = BELLE_SDP_SESSION_NAME(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->session_name)));
session_description->phones = belle_sip_list_copy_with_data(orig->phones,belle_sip_object_copyfunc);
session_description->times = belle_sip_list_copy_with_data(orig->times,belle_sip_object_copyfunc);
if (orig->uri) session_description->uri = BELLE_SDP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->uri)));
if (orig->zone_adjustments) session_description->zone_adjustments = BELLE_SDP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->zone_adjustments)));
session_description->media_descriptions = belle_sip_list_copy_with_data(orig->media_descriptions,belle_sip_object_copyfunc);
}
int belle_sdp_session_description_marshal(belle_sdp_session_description_t* session_description, char* buff,unsigned int offset,unsigned int buff_size) {
/*session_description: proto_version CR LF
......@@ -888,9 +959,12 @@ struct _belle_sdp_time {
};
void belle_sdp_time_destroy(belle_sdp_time_t* time) {
}
void belle_sdp_time_clone(belle_sdp_time_t *time, const belle_sdp_time_t *orig){
time->start=orig->start;
time->stop=orig->stop;
}
int belle_sdp_time_marshal(belle_sdp_time_t* time, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -916,9 +990,11 @@ struct _belle_sdp_time_description {
};
void belle_sdp_time_description_destroy(belle_sdp_time_description_t* time_description) {
if (time_description->time) belle_sip_object_unref(BELLE_SIP_OBJECT(time_description->time));
}
void belle_sdp_time_description_clone(belle_sdp_time_description_t *time_description, const belle_sdp_time_description_t *orig){
if (orig->time) time_description->time = BELLE_SDP_TIME(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->time)));
}
int belle_sdp_time_description_marshal(belle_sdp_time_description_t* time_description, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -954,10 +1030,11 @@ struct _belle_sdp_version {
};
void belle_sdp_version_destroy(belle_sdp_version_t* version) {
}
void belle_sdp_version_clone(belle_sdp_version_t *version, const belle_sdp_version_t *orig){
version->version = orig->version;
}
int belle_sdp_version_marshal(belle_sdp_version_t* version, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
......@@ -990,9 +1067,22 @@ static void belle_sdp_mime_parameter_destroy(belle_sdp_mime_parameter_t *mime_pa
if (mime_parameter->type) belle_sip_free((void*)mime_parameter->type);
if (mime_parameter->parameters) belle_sip_free((void*)mime_parameter->parameters);
}
static void belle_sdp_mime_parameter_clone(belle_sdp_mime_parameter_t *mime_parameter,belle_sdp_mime_parameter_t *orig) {
mime_parameter->rate = orig->rate;
mime_parameter->channel_count = orig->channel_count;
mime_parameter->ptime = orig->ptime;
mime_parameter->max_ptime = orig->max_ptime;
mime_parameter->media_format = orig->media_format;
CLONE_STRING(belle_sdp_mime_parameter,type,mime_parameter,orig);
CLONE_STRING(belle_sdp_mime_parameter,parameters,mime_parameter,orig);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sdp_mime_parameter_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sdp_mime_parameter_t,belle_sip_object_t,belle_sdp_mime_parameter_destroy,NULL,NULL,TRUE);
BELLE_SIP_INSTANCIATE_VPTR(belle_sdp_mime_parameter_t
,belle_sip_object_t
,belle_sdp_mime_parameter_destroy
,belle_sdp_mime_parameter_clone
,NULL
,TRUE);
belle_sdp_mime_parameter_t* belle_sdp_mime_parameter_new() {
belle_sdp_mime_parameter_t* l_param = belle_sip_object_new(belle_sdp_mime_parameter_t);
......
......@@ -402,6 +402,8 @@ char *belle_sip_strdup_printf(const char *fmt,...);
belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(obj),#attribute,value);\
}
#define DESTROY_STRING(object,attribute) if (object->attribute) belle_sip_free((void*)object->attribute);
#define CLONE_STRING(object_type,attribute,dest,src) \
if ( object_type##_get_##attribute (src)) {\
object_type##_set_##attribute(dest,object_type##_get_##attribute(src));\
......
......@@ -381,6 +381,16 @@ belle_sip_list_t* belle_sip_list_copy(const belle_sip_list_t* list){
return copy;
}
belle_sip_list_t* belle_sip_list_copy_with_data(const belle_sip_list_t* list, void* (*copyfunc)(void*)){
belle_sip_list_t* copy=NULL;
const belle_sip_list_t* iter;
for(iter=list;iter!=NULL;iter=belle_sip_list_next(iter)){
copy=belle_sip_list_append(copy,copyfunc(iter->data));
}
return copy;
}
char * belle_sip_concat (const char *str, ...) {
va_list ap;
size_t allocated = 100;
......
......@@ -74,36 +74,48 @@ static void test_bandwidth(void) {
static void test_connection(void) {
belle_sdp_connection_t* lTmp;
belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP4 192.168.0.18");
char* l_raw_connection = belle_sip_object_to_string(BELLE_SIP_OBJECT(lConnection));
belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection));
lConnection = belle_sdp_connection_parse(l_raw_connection);
lTmp = belle_sdp_connection_parse(l_raw_connection);
lConnection = BELLE_SDP_CONNECTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address(lConnection), "192.168.0.18");
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address_type(lConnection), "IP4");
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* lTmp;
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);
lTmp = belle_sdp_email_parse(l_raw_email);
l_email = BELLE_SDP_EMAIL(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
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* lTmp;
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);
lTmp = belle_sdp_info_parse(l_raw_info);
l_info = BELLE_SDP_INFO(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
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));
}
static void test_media(void) {
belle_sdp_media_t* lTmp;
belle_sdp_media_t* l_media = belle_sdp_media_parse("m=audio 7078 RTP/AVP 111 110 3 0 8 101");
char* l_raw_media = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_media));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media));
l_media = belle_sdp_media_parse(l_raw_media);
lTmp = belle_sdp_media_parse(l_raw_media);
l_media = BELLE_SDP_MEDIA(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_media_type(l_media), "audio");
CU_ASSERT_EQUAL(belle_sdp_media_get_media_port(l_media), 7078);
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_protocol(l_media), "RTP/AVP");
......@@ -168,10 +180,13 @@ static void test_media_description(void) {
"a=rtpmap:98 H263-1998/90000\r\n"\
"a=fmtp:98 CIF=1;QCIF=1\r\n";
belle_sdp_media_description_t* lTmp;
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);
lTmp = belle_sdp_media_description_parse(l_raw_media_description);
l_media_description = BELLE_SDP_MEDIA_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
test_media_description_base(l_media_description);
return;
}
......@@ -196,10 +211,13 @@ static void test_session_description(void) {
"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));
l_session_description = belle_sdp_session_description_parse(l_raw_session_description);
lTmp = belle_sdp_session_description_parse(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);
......@@ -279,8 +297,11 @@ static void test_mime_parameter(void) {
belle_sdp_media_description_set_attribute(l_media_description,"ptime","40");
mime_parameter_list = belle_sdp_media_description_build_mime_parameters(l_media_description);
belle_sdp_mime_parameter_t* l_param;
belle_sdp_mime_parameter_t* lTmp = find_mime_parameter(mime_parameter_list,111);
l_param = BELLE_SDP_MIME_PARAMETER(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
belle_sdp_mime_parameter_t* l_param = find_mime_parameter(mime_parameter_list,111);
CU_ASSERT_PTR_NOT_NULL(l_param);
check_mime_param(l_param,16000,1,40,-1,111,"speex","vbr=on");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_param));
......
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