From bd95305d7febcba46a5509304cbbd8bb3bc6cab2 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 27 Aug 2013 21:06:18 +0200 Subject: [PATCH] add reference counting to LinphoneAddress and SalAddress --- coreapi/address.c | 18 +++++++++++++++-- coreapi/bellesip_sal/sal_address_impl.c | 26 ++++++++++++++++++++----- coreapi/linphonecore.h | 6 ++++-- include/sal/sal.h | 2 ++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/coreapi/address.c b/coreapi/address.c index ad07819bc..4151765e4 100644 --- a/coreapi/address.c +++ b/coreapi/address.c @@ -43,6 +43,20 @@ LinphoneAddress * linphone_address_clone(const LinphoneAddress *addr){ return sal_address_clone(addr); } +/** + * Increment reference count of LinphoneAddress object. +**/ +LinphoneAddress * linphone_address_ref(LinphoneAddress *addr){ + return sal_address_ref(addr); +} + +/** + * Decrement reference count of LinphoneAddress object. When dropped to zero, memory is freed. +**/ +void linphone_address_unref(LinphoneAddress *addr){ + sal_address_unref(addr); +} + /** * Returns the address scheme, normally "sip". **/ @@ -153,10 +167,10 @@ bool_t linphone_address_weak_equal(const LinphoneAddress *a1, const LinphoneAddr } /** - * Destroys a LinphoneAddress object. + * Destroys a LinphoneAddress object (actually calls linphone_address_unref()). **/ void linphone_address_destroy(LinphoneAddress *u){ - sal_address_destroy(u); + sal_address_unref(u); } int linphone_address_get_port_int(const LinphoneAddress *u) { diff --git a/coreapi/bellesip_sal/sal_address_impl.c b/coreapi/bellesip_sal/sal_address_impl.c index c7f004bef..63f587173 100644 --- a/coreapi/bellesip_sal/sal_address_impl.c +++ b/coreapi/bellesip_sal/sal_address_impl.c @@ -103,18 +103,23 @@ void sal_address_set_display_name(SalAddress *addr, const char *display_name){ belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); belle_sip_header_address_set_displayname(header_addr,display_name); } + void sal_address_set_username(SalAddress *addr, const char *username){ SAL_ADDRESS_SET(addr,user,username); } + void sal_address_set_domain(SalAddress *addr, const char *host){ SAL_ADDRESS_SET(addr,host,host); } + void sal_address_set_port(SalAddress *addr, const char *port){ SAL_ADDRESS_SET(addr,port,atoi(port)); } + void sal_address_set_port_int(SalAddress *addr, int port){ SAL_ADDRESS_SET(addr,port,port); } + void sal_address_clean(SalAddress *addr){ belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); belle_sip_uri_t* uri=belle_sip_header_address_get_uri(header_addr); @@ -122,19 +127,17 @@ void sal_address_clean(SalAddress *addr){ belle_sip_parameters_clean(BELLE_SIP_PARAMETERS(header_addr)); return ; } + char *sal_address_as_string(const SalAddress *addr){ return belle_sip_object_to_string(BELLE_SIP_OBJECT(addr)); } + char *sal_address_as_string_uri_only(const SalAddress *addr){ belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); belle_sip_uri_t* uri = belle_sip_header_address_get_uri(header_addr); return belle_sip_object_to_string(BELLE_SIP_OBJECT(uri)); } -void sal_address_destroy(SalAddress *addr){ - belle_sip_header_address_t* header_addr = BELLE_SIP_HEADER_ADDRESS(addr); - belle_sip_object_unref(header_addr); - return ; -} + void sal_address_set_param(SalAddress *addr,const char* name,const char* value){ belle_sip_parameters_t* parameters = BELLE_SIP_PARAMETERS(addr); belle_sip_parameters_set_parameter(parameters,name,value); @@ -148,3 +151,16 @@ void sal_address_set_transport(SalAddress* addr,SalTransport transport){ void sal_address_set_transport_name(SalAddress* addr,const char *transport){ SAL_ADDRESS_SET(addr,transport_param,transport); } + +SalAddress *sal_address_ref(SalAddress *addr){ + return (SalAddress*)belle_sip_object_ref(BELLE_SIP_HEADER_ADDRESS(addr)); +} + +void sal_address_unref(SalAddress *addr){ + belle_sip_object_unref(BELLE_SIP_HEADER_ADDRESS(addr)); +} + +void sal_address_destroy(SalAddress *addr){ + sal_address_unref(addr); +} + diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 3399402d3..ac272eb47 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -161,8 +161,10 @@ const char *linphone_reason_to_string(LinphoneReason err); #include "linphone/event.h" #endif -LINPHONE_PUBLIC LinphoneAddress * linphone_address_new(const char *uri); -LinphoneAddress * linphone_address_clone(const LinphoneAddress *uri); +LINPHONE_PUBLIC LinphoneAddress * linphone_address_new(const char *addr); +LinphoneAddress * linphone_address_clone(const LinphoneAddress *addr); +LinphoneAddress * linphone_address_ref(LinphoneAddress *addr); +void linphone_address_unref(LinphoneAddress *addr); const char *linphone_address_get_scheme(const LinphoneAddress *u); LINPHONE_PUBLIC const char *linphone_address_get_display_name(const LinphoneAddress* u); LINPHONE_PUBLIC const char *linphone_address_get_username(const LinphoneAddress *u); diff --git a/include/sal/sal.h b/include/sal/sal.h index 43ecce862..427234f57 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -76,6 +76,8 @@ SalTransport sal_transport_parse(const char*); /* Address manipulation API*/ SalAddress * sal_address_new(const char *uri); SalAddress * sal_address_clone(const SalAddress *addr); +SalAddress * sal_address_ref(SalAddress *addr); +void sal_address_unref(SalAddress *addr); const char *sal_address_get_scheme(const SalAddress *addr); const char *sal_address_get_display_name(const SalAddress* addr); const char *sal_address_get_display_name_unquoted(const SalAddress *addr);