Commit d68cfb8c authored by jehan's avatar jehan
Browse files

adapt code to new object ref management

parent 3e3d151c
...@@ -195,6 +195,13 @@ void _belle_sip_object_copy(belle_sip_object_t *newobj, const belle_sip_object_t ...@@ -195,6 +195,13 @@ void _belle_sip_object_copy(belle_sip_object_t *newobj, const belle_sip_object_t
**/ **/
belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj); belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj);
/**
* Same as #belle_sip_object_clone but with ref count set to 1
*
**/
belle_sip_object_t *belle_sip_object_clone_and_ref(const belle_sip_object_t *obj);
/** /**
* Returns a string describing the inheritance diagram and implemented interfaces of object obj. * Returns a string describing the inheritance diagram and implemented interfaces of object obj.
**/ **/
......
...@@ -279,7 +279,7 @@ static void belle_sip_object_freefunc(void* obj) { ...@@ -279,7 +279,7 @@ static void belle_sip_object_freefunc(void* obj) {
belle_sip_object_unref(BELLE_SIP_OBJECT(obj)); belle_sip_object_unref(BELLE_SIP_OBJECT(obj));
} }
static void* belle_sip_object_copyfunc(void* obj) { static void* belle_sip_object_copyfunc(void* obj) {
return belle_sip_object_clone(BELLE_SIP_OBJECT(obj)); return belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(obj));
} }
typedef struct _belle_sdp_base_description { typedef struct _belle_sdp_base_description {
...@@ -299,8 +299,8 @@ static void belle_sdp_base_description_destroy(belle_sdp_base_description_t* bas ...@@ -299,8 +299,8 @@ static void belle_sdp_base_description_destroy(belle_sdp_base_description_t* bas
static 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) {
} }
static 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->info) base_description->info = BELLE_SDP_INFO(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(orig->info)));
if (orig->connection) base_description->connection = BELLE_SDP_CONNECTION(belle_sip_object_clone(BELLE_SIP_OBJECT(orig->connection))); if (orig->connection) base_description->connection = BELLE_SDP_CONNECTION(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(orig->connection)));
base_description->bandwidths = belle_sip_list_copy_with_data(orig->bandwidths,belle_sip_object_copyfunc); 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); base_description->attributes = belle_sip_list_copy_with_data(orig->attributes,belle_sip_object_copyfunc);
...@@ -393,10 +393,10 @@ void belle_sdp_base_description_set_attribute_value(belle_sdp_base_description_t ...@@ -393,10 +393,10 @@ void belle_sdp_base_description_set_attribute_value(belle_sdp_base_description_t
belle_sdp_attribute_t* attribute = belle_sdp_attribute_new(); belle_sdp_attribute_t* attribute = belle_sdp_attribute_new();
belle_sdp_attribute_set_name(attribute,name); belle_sdp_attribute_set_name(attribute,name);
belle_sdp_attribute_set_value(attribute,value); belle_sdp_attribute_set_value(attribute,value);
base_description->attributes = belle_sip_list_append(base_description->attributes,attribute); 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) { void belle_sdp_base_description_add_attribute(belle_sdp_base_description_t* base_description, const belle_sdp_attribute_t* attribute) {
base_description->attributes = belle_sip_list_append(base_description->attributes,(void*)attribute); base_description->attributes = belle_sip_list_append(base_description->attributes,(void*)belle_sip_object_ref(BELLE_SIP_OBJECT(attribute)));
} }
#define SET_LIST(list_name,value) \ #define SET_LIST(list_name,value) \
...@@ -407,6 +407,9 @@ void belle_sdp_base_description_add_attribute(belle_sdp_base_description_t* base ...@@ -407,6 +407,9 @@ void belle_sdp_base_description_add_attribute(belle_sdp_base_description_t* base
}\ }\
belle_sip_list_free(list_name); \ belle_sip_list_free(list_name); \
} \ } \
for (list=value;list !=NULL; list=list->next) {\
belle_sip_object_ref(BELLE_SIP_OBJECT(list->data));\
}\
list_name=value; list_name=value;
...@@ -417,10 +420,10 @@ void belle_sdp_base_description_set_bandwidth(belle_sdp_base_description_t* base ...@@ -417,10 +420,10 @@ void belle_sdp_base_description_set_bandwidth(belle_sdp_base_description_t* base
belle_sdp_bandwidth_t* bandwidth = belle_sdp_bandwidth_new(); belle_sdp_bandwidth_t* bandwidth = belle_sdp_bandwidth_new();
belle_sdp_bandwidth_set_type(bandwidth,type); belle_sdp_bandwidth_set_type(bandwidth,type);
belle_sdp_bandwidth_set_value(bandwidth,value); belle_sdp_bandwidth_set_value(bandwidth,value);
base_description->bandwidths = belle_sip_list_append(base_description->bandwidths,bandwidth); base_description->bandwidths = belle_sip_list_append(base_description->bandwidths,belle_sip_object_ref(bandwidth));
} }
void belle_sdp_base_description_add_bandwidth(belle_sdp_base_description_t* base_description, const belle_sdp_bandwidth_t* bandwidth) { void belle_sdp_base_description_add_bandwidth(belle_sdp_base_description_t* base_description, const belle_sdp_bandwidth_t* bandwidth) {
base_description->bandwidths = belle_sip_list_append(base_description->bandwidths,(void *)bandwidth); base_description->bandwidths = belle_sip_list_append(base_description->bandwidths,(void *)belle_sip_object_ref((void *)bandwidth));
} }
void belle_sdp_base_description_set_bandwidths(belle_sdp_base_description_t* base_description, belle_sip_list_t* bandwidths) { void belle_sdp_base_description_set_bandwidths(belle_sdp_base_description_t* base_description, belle_sip_list_t* bandwidths) {
SET_LIST(base_description->bandwidths,bandwidths) SET_LIST(base_description->bandwidths,bandwidths)
...@@ -438,7 +441,7 @@ void belle_sdp_media_description_destroy(belle_sdp_media_description_t* media_de ...@@ -438,7 +441,7 @@ void belle_sdp_media_description_destroy(belle_sdp_media_description_t* media_de
} }
void belle_sdp_media_description_clone(belle_sdp_media_description_t *media_description, const belle_sdp_media_description_t *orig){ 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)))); if (orig->media) media_description->media = BELLE_SDP_MEDIA(belle_sip_object_clone_and_ref(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) { 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; unsigned int current_offset=offset;
...@@ -674,28 +677,24 @@ void belle_sdp_media_description_add_bandwidth(belle_sdp_media_description_t* me ...@@ -674,28 +677,24 @@ void belle_sdp_media_description_add_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_bandwidths(belle_sdp_media_description_t* media_description, belle_sip_list_t* bandwidths) {
belle_sdp_base_description_set_bandwidths(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),bandwidths); belle_sdp_base_description_set_bandwidths(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),bandwidths);
} }
#define SET_OBJECT(object,param,param_type) \
param_type** current = &object->param; \
if (param) belle_sip_object_ref(param); \
if (*current) { \
belle_sip_object_unref(BELLE_SIP_OBJECT(*current)); \
} \
*current=param; \
void belle_sdp_media_description_set_connection(belle_sdp_media_description_t* media_description, belle_sdp_connection_t* conn) {
belle_sdp_connection_t** current = &BELLE_SIP_CAST(media_description,belle_sdp_base_description_t)->connection; void belle_sdp_media_description_set_connection(belle_sdp_media_description_t* media_description, belle_sdp_connection_t* connection) {
if (*current) { SET_OBJECT(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),connection,belle_sdp_connection_t)
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=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_info(belle_sdp_media_description_t* media_description,belle_sdp_info_t* info) {
belle_sdp_info_t** current = &BELLE_SIP_CAST(media_description,belle_sdp_base_description_t)->info; SET_OBJECT(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),info,belle_sdp_info_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=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) { void belle_sdp_media_description_set_media(belle_sdp_media_description_t* media_description, belle_sdp_media_t* media) {
belle_sdp_media_t** current = &media_description->media; SET_OBJECT(media_description,media,belle_sdp_media_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=media;
} }
/************************ /************************
...@@ -825,14 +824,14 @@ void belle_sdp_session_description_destroy(belle_sdp_session_description_t* sess ...@@ -825,14 +824,14 @@ void belle_sdp_session_description_destroy(belle_sdp_session_description_t* sess
} }
void belle_sdp_session_description_clone(belle_sdp_session_description_t *session_description, const belle_sdp_session_description_t *orig){ 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))); if (orig->version) session_description->version = BELLE_SDP_VERSION(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(orig->version)));
session_description->emails = belle_sip_list_copy_with_data(orig->emails,belle_sip_object_copyfunc); 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->origin) session_description->origin = BELLE_SDP_ORIGIN(belle_sip_object_clone_and_ref(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))); if (orig->session_name) session_description->session_name = BELLE_SDP_SESSION_NAME(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(orig->session_name)));
session_description->phones = belle_sip_list_copy_with_data(orig->phones,belle_sip_object_copyfunc); 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); 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->uri) session_description->uri = BELLE_SDP_URI(belle_sip_object_clone_and_ref(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))); if (orig->zone_adjustments) session_description->zone_adjustments = BELLE_SDP_URI(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(orig->zone_adjustments)));
session_description->media_descriptions = belle_sip_list_copy_with_data(orig->media_descriptions,belle_sip_object_copyfunc); 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) { int belle_sdp_session_description_marshal(belle_sdp_session_description_t* session_description, char* buff,unsigned int offset,unsigned int buff_size) {
...@@ -959,47 +958,31 @@ void belle_sdp_session_description_set_bandwidths(belle_sdp_session_description_ ...@@ -959,47 +958,31 @@ void belle_sdp_session_description_set_bandwidths(belle_sdp_session_description_
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_add_bandwidth(belle_sdp_session_description_t* session_description, const belle_sdp_bandwidth_t* bandwidth) {
belle_sdp_base_description_add_bandwidth(BELLE_SIP_CAST(session_description,belle_sdp_base_description_t),bandwidth); belle_sdp_base_description_add_bandwidth(BELLE_SIP_CAST(session_description,belle_sdp_base_description_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_connection(belle_sdp_session_description_t* session_description, belle_sdp_connection_t* connection) {
belle_sdp_connection_t** current = &BELLE_SIP_CAST(session_description,belle_sdp_base_description_t)->connection; SET_OBJECT(BELLE_SIP_CAST(session_description,belle_sdp_base_description_t),connection,belle_sdp_connection_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=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_emails(belle_sdp_session_description_t* session_description, belle_sip_list_t* emails) {
SET_LIST(session_description->emails,emails) SET_LIST(session_description->emails,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_info(belle_sdp_session_description_t* session_description, belle_sdp_info_t* info) {
belle_sdp_info_t** current = &BELLE_SIP_CAST(session_description,belle_sdp_base_description_t)->info; SET_OBJECT(BELLE_SIP_CAST(session_description,belle_sdp_base_description_t),info,belle_sdp_info_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=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* media_descriptions) { void belle_sdp_session_description_set_media_descriptions(belle_sdp_session_description_t* session_description, belle_sip_list_t* media_descriptions) {
SET_LIST(session_description->media_descriptions,media_descriptions) SET_LIST(session_description->media_descriptions,media_descriptions)
} }
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_add_media_description(belle_sdp_session_description_t* session_description, belle_sdp_media_description_t* media_description) {
session_description->media_descriptions = belle_sip_list_append(session_description->media_descriptions,media_description); session_description->media_descriptions = belle_sip_list_append(session_description->media_descriptions,belle_sip_object_ref(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_origin(belle_sdp_session_description_t* session_description, belle_sdp_origin_t* origin) {
belle_sdp_origin_t** current = &session_description->origin; SET_OBJECT(session_description,origin,belle_sdp_origin_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=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_phones(belle_sdp_session_description_t* session_description, belle_sip_list_t* phones) {
SET_LIST(session_description->phones,phones) SET_LIST(session_description->phones,phones)
} }
void belle_sdp_session_description_set_session_name(belle_sdp_session_description_t* session_description, belle_sdp_session_name_t* session_name) { void belle_sdp_session_description_set_session_name(belle_sdp_session_description_t* session_description, belle_sdp_session_name_t* session_name) {
belle_sdp_session_name_t** current = &session_description->session_name; SET_OBJECT(session_description,session_name,belle_sdp_session_name_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=session_name;
} }
void belle_sdp_session_description_set_time_descriptions(belle_sdp_session_description_t* session_description, belle_sip_list_t* times) { void belle_sdp_session_description_set_time_descriptions(belle_sdp_session_description_t* session_description, belle_sip_list_t* times) {
SET_LIST(session_description->times,times) SET_LIST(session_description->times,times)
...@@ -1008,25 +991,13 @@ void belle_sdp_session_description_set_time_description(belle_sdp_session_descri ...@@ -1008,25 +991,13 @@ void belle_sdp_session_description_set_time_description(belle_sdp_session_descri
belle_sdp_session_description_set_time_descriptions(session_description,belle_sip_list_new(time_desc)); belle_sdp_session_description_set_time_descriptions(session_description,belle_sip_list_new(time_desc));
} }
void belle_sdp_session_description_set_uri(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* uri) { void belle_sdp_session_description_set_uri(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* uri) {
belle_sdp_uri_t** current = &session_description->uri; SET_OBJECT(session_description,uri,belle_sdp_uri_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=uri;
} }
void belle_sdp_session_description_set_version(belle_sdp_session_description_t* session_description, belle_sdp_version_t* version) { void belle_sdp_session_description_set_version(belle_sdp_session_description_t* session_description, belle_sdp_version_t* version) {
belle_sdp_version_t** current = &session_description->version; SET_OBJECT(session_description,version,belle_sdp_version_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=version;
} }
void belle_sdp_session_description_set_zone_adjustments(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* zone_adjustments) { void belle_sdp_session_description_set_zone_adjustments(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* zone_adjustments) {
belle_sdp_uri_t** current = &session_description->zone_adjustments; SET_OBJECT(session_description,zone_adjustments,belle_sdp_uri_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=zone_adjustments;
} }
/************************ /************************
* time * time
...@@ -1073,7 +1044,7 @@ void belle_sdp_time_description_destroy(belle_sdp_time_description_t* time_descr ...@@ -1073,7 +1044,7 @@ void belle_sdp_time_description_destroy(belle_sdp_time_description_t* time_descr
} }
void belle_sdp_time_description_clone(belle_sdp_time_description_t *time_description, const belle_sdp_time_description_t *orig){ 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))); if (orig->time) time_description->time = BELLE_SDP_TIME(belle_sip_object_clone_and_ref(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) { 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; unsigned int current_offset=offset;
...@@ -1099,12 +1070,8 @@ belle_sdp_time_t* belle_sdp_time_description_get_time(const belle_sdp_time_descr ...@@ -1099,12 +1070,8 @@ belle_sdp_time_t* belle_sdp_time_description_get_time(const belle_sdp_time_descr
void belle_sdp_time_description_set_repeate_times(belle_sdp_time_description_t* time_description, belle_sip_list_t* times) { void belle_sdp_time_description_set_repeate_times(belle_sdp_time_description_t* time_description, belle_sip_list_t* times) {
belle_sip_error("time description repeat time not implemented"); belle_sip_error("time description repeat time not implemented");
} }
void belle_sdp_time_description_set_time(belle_sdp_time_description_t* time_description, belle_sdp_time_t* value) { void belle_sdp_time_description_set_time(belle_sdp_time_description_t* time_description, belle_sdp_time_t* time) {
belle_sdp_time_t** current = &time_description->time; SET_OBJECT(time_description,time,belle_sdp_time_t)
if (*current) {
belle_sip_object_unref(BELLE_SIP_OBJECT(*current));
}
*current=value;
} }
#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);
......
...@@ -43,7 +43,7 @@ void belle_sip_header_init(belle_sip_header_t *header) { ...@@ -43,7 +43,7 @@ void belle_sip_header_init(belle_sip_header_t *header) {
static void belle_sip_header_clone(belle_sip_header_t *header, const belle_sip_header_t *orig){ static void belle_sip_header_clone(belle_sip_header_t *header, const belle_sip_header_t *orig){
CLONE_STRING(belle_sip_header,name,header,orig) CLONE_STRING(belle_sip_header,name,header,orig)
if (belle_sip_header_get_next(orig)) { if (belle_sip_header_get_next(orig)) {
belle_sip_header_set_next(header,BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_get_next(orig))))) ; belle_sip_header_set_next(header,BELLE_SIP_HEADER(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(belle_sip_header_get_next(orig))))) ;
} }
} }
static void belle_sip_header_destroy(belle_sip_header_t *header){ static void belle_sip_header_destroy(belle_sip_header_t *header){
......
...@@ -262,7 +262,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){ ...@@ -262,7 +262,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){ if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){
char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s); char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s);
s->expired=TRUE; s->expired=TRUE;
belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout); if (s->timeout>0)/*to avoid too many traces*/ belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
belle_sip_free(objdesc); belle_sip_free(objdesc);
ret=s->notify(s->data,revents); ret=s->notify(s->data,revents);
if (ret==0){ if (ret==0){
......
...@@ -214,7 +214,9 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){ ...@@ -214,7 +214,9 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
return newobj; return newobj;
} }
belle_sip_object_t *belle_sip_object_clone_and_ref(const belle_sip_object_t *obj) {
return belle_sip_object_ref(belle_sip_object_clone(obj));
}
void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno){ void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno){
if (obj!=NULL){ if (obj!=NULL){
......
...@@ -54,6 +54,7 @@ static void belle_sip_channel_destroy(belle_sip_channel_t *obj){ ...@@ -54,6 +54,7 @@ static void belle_sip_channel_destroy(belle_sip_channel_t *obj){
belle_sip_free(obj->peer_name); belle_sip_free(obj->peer_name);
if (obj->local_ip) belle_sip_free(obj->local_ip); if (obj->local_ip) belle_sip_free(obj->local_ip);
obj->listeners=for_each_weak_unref_free(obj->listeners,(belle_sip_object_destroy_notify_t)belle_sip_channel_remove_listener,obj); obj->listeners=for_each_weak_unref_free(obj->listeners,(belle_sip_object_destroy_notify_t)belle_sip_channel_remove_listener,obj);
belle_sip_message("channel [%p] destroyed",obj);
} }
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_channel_t); BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_channel_t);
......
...@@ -30,8 +30,13 @@ void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_s ...@@ -30,8 +30,13 @@ void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_s
static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){ static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
belle_sip_listening_point_clean_channels(lp); belle_sip_listening_point_clean_channels(lp);
belle_sip_message("Listening [%p] on [%s://%s:%i] destroyed" ,lp
,belle_sip_uri_get_transport_param(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_host(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_port(BELLE_SIP_LISTENING_POINT(lp)->listening_uri));
belle_sip_object_unref(lp->listening_uri); belle_sip_object_unref(lp->listening_uri);
lp->channel_listener=NULL; /*does not unref provider*/ lp->channel_listener=NULL; /*does not unref provider*/
} }
...@@ -55,12 +60,17 @@ void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, b ...@@ -55,12 +60,17 @@ void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, b
belle_sip_object_unref(chan); belle_sip_object_unref(chan);
} }
void belle_sip_listening_point_clean_channels(belle_sip_listening_point_t *lp){ void belle_sip_listening_point_clean_channels(belle_sip_listening_point_t *lp){
int existing_channels; int existing_channels;
belle_sip_list_t* iterator;
if ((existing_channels=belle_sip_list_size(lp->channels)) > 0) { if ((existing_channels=belle_sip_list_size(lp->channels)) > 0) {
belle_sip_warning("Listening point destroying [%i] channels",existing_channels); belle_sip_warning("Listening point destroying [%i] channels",existing_channels);
} }
belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref); for (iterator=lp->channels;iterator!=NULL;iterator=iterator->next) {
belle_sip_main_loop_remove_source(lp->stack->ml,(belle_sip_source_t*)(iterator->data));
}
lp->channels=belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
} }
......
...@@ -59,11 +59,11 @@ static void belle_sip_authorization_destroy(authorization_context_t* object) { ...@@ -59,11 +59,11 @@ static void belle_sip_authorization_destroy(authorization_context_t* object) {
static void belle_sip_provider_uninit(belle_sip_provider_t *p){ static void belle_sip_provider_uninit(belle_sip_provider_t *p){
belle_sip_list_free(p->listeners); belle_sip_list_free(p->listeners);
belle_sip_list_free(p->internal_listeners); belle_sip_list_free(p->internal_listeners);
belle_sip_list_free_with_data(p->lps,belle_sip_object_unref);
belle_sip_list_free_with_data(p->client_transactions,belle_sip_object_unref); belle_sip_list_free_with_data(p->client_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->server_transactions,belle_sip_object_unref); belle_sip_list_free_with_data(p->server_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->auth_contexts,(void(*)(void*))belle_sip_authorization_destroy); belle_sip_list_free_with_data(p->auth_contexts,(void(*)(void*))belle_sip_authorization_destroy);
belle_sip_list_free_with_data(p->dialogs,belle_sip_object_unref); belle_sip_list_free_with_data(p->dialogs,belle_sip_object_unref);
belle_sip_list_free_with_data(p->lps,belle_sip_object_unref);
} }
static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_channel_state_t state){ static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_channel_state_t state){
......
...@@ -107,6 +107,7 @@ belle_sip_dialog_t* belle_sip_transaction_get_dialog(const belle_sip_transactio ...@@ -107,6 +107,7 @@ belle_sip_dialog_t* belle_sip_transaction_get_dialog(const belle_sip_transactio
void belle_sip_transaction_set_dialog(belle_sip_transaction_t *t, belle_sip_dialog_t *dialog){ void belle_sip_transaction_set_dialog(belle_sip_transaction_t *t, belle_sip_dialog_t *dialog){
if (dialog) belle_sip_object_ref(dialog); if (dialog) belle_sip_object_ref(dialog);
if (t->dialog) belle_sip_object_unref(t->dialog); /*to avoid keeping unexpected ref*/
t->dialog=dialog; t->dialog=dialog;
} }
......
...@@ -64,7 +64,6 @@ void stream_channel_close(belle_sip_channel_t *obj){ ...@@ -64,7 +64,6 @@ void stream_channel_close(belle_sip_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj); belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (sock!=-1){ if (sock!=-1){
close_socket(sock); close_socket(sock);
belle_sip_main_loop_remove_source(obj->stack->ml,(belle_sip_source_t*)obj);
obj->base.fd=-1; obj->base.fd=-1;
} }
} }
......
...@@ -71,6 +71,7 @@ static void check_tls_deinit(void){ ...@@ -71,6 +71,7 @@ static void check_tls_deinit(void){
} }
static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t *lp){ static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t *lp){
belle_sip_listening_point_clean_channels(BELLE_SIP_LISTENING_POINT(lp)); /*make sure all channels are cleaned before deiniting gnu tls*/
check_tls_deinit(); check_tls_deinit();
} }
......
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