Commit 1f66ebe0 authored by jehan's avatar jehan

create a public function belle_sip_header_address_clone to clone only uri + displayname

parent fc657985
......@@ -92,6 +92,15 @@ BELLESIP_EXPORT const char* belle_sip_header_address_get_displayname(const belle
*/
BELLESIP_EXPORT void belle_sip_header_address_set_displayname(belle_sip_header_address_t* address, const char* uri);
/*
* Clone both display name and an uri from an belle_sip_header_address_t to a newly allocated belle_sip_header_address_t
* @param orig, originating header adderss.
* @return belle_sip_header_address_t
* */
BELLESIP_EXPORT belle_sip_header_address_t* belle_sip_header_address_clone(const belle_sip_header_address_t* orig);
#define BELLE_SIP_HEADER_ADDRESS(t) BELLE_SIP_CAST(t,belle_sip_header_address_t)
......
......@@ -199,7 +199,7 @@ static void belle_sip_header_address_destroy(belle_sip_header_address_t* address
if (address->absolute_uri) belle_sip_object_unref(address->absolute_uri);
}
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
static void _belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
CLONE_STRING(belle_sip_header_address,displayname,addr,orig)
if (belle_sip_header_address_get_uri(orig)) {
belle_sip_header_address_set_uri(addr,BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(orig)))));
......@@ -208,7 +208,11 @@ static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, con
belle_sip_header_address_set_absolute_uri(addr,BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_absolute_uri(orig)))));
}
}
belle_sip_header_address_t* belle_sip_header_address_clone(const belle_sip_header_address_t* orig) {
belle_sip_header_address_t* new_address = belle_sip_header_address_new();
_belle_sip_header_address_clone(new_address, orig);
return new_address;
}
static belle_sip_error_code _belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff, size_t buff_size, size_t *offset, int force_angle_quote) {
belle_sip_error_code error=BELLE_SIP_OK;
/*1 display name*/
......@@ -253,7 +257,7 @@ static belle_sip_error_code _belle_sip_header_address_marshal(belle_sip_header_a
belle_sip_error_code belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff, size_t buff_size, size_t *offset){
return _belle_sip_header_address_marshal(header, buff, buff_size, offset, FALSE);
}
#define belle_sip_header_address_clone _belle_sip_header_address_clone /*because public clone function is not the one to be used internally*/
BELLE_SIP_NEW_HEADER(header_address,parameters,"header_address")
BELLE_SIP_PARSE(header_address)
GET_SET_STRING(belle_sip_header_address,displayname);
......
......@@ -741,11 +741,14 @@ static void test_address_with_error_header(void) {
static void test_address_header(void) {
belle_sip_uri_t* L_uri;
char* L_raw;
belle_sip_header_address_t* lclonedaddr;
belle_sip_header_address_t* laddress = belle_sip_header_address_fast_parse("\"toto\" <sip:liblinphone_tester@81.56.11.2:5060>");
BC_ASSERT_PTR_NOT_NULL(laddress);
L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(lclonedaddr=belle_sip_header_address_clone(laddress)));
BC_ASSERT_PTR_NOT_NULL(L_raw);
belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
belle_sip_object_unref(BELLE_SIP_OBJECT(lclonedaddr));
laddress = belle_sip_header_address_parse(L_raw);
belle_sip_free(L_raw);
......
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