Commit 49e93dd0 authored by Gautier Pelloux-Prayer's avatar Gautier Pelloux-Prayer
Browse files

update presence

parent 1d1c196e
......@@ -102,9 +102,45 @@ static int add_uri_entry(xmlTextWriterPtr writer, int err, const char *uri) {
return err;
}
static bctbx_list_t * uri_list(const LinphoneFriendList *list) {
bctbx_list_t * uri_list = NULL;
bctbx_list_t * elem = NULL;
for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem);
bctbx_list_t *iterator;
bctbx_list_t *addresses = linphone_friend_get_addresses(lf);
bctbx_list_t *numbers = linphone_friend_get_phone_numbers(lf);
iterator = addresses;
while (iterator) {
LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(iterator);
if (addr) {
char *uri = linphone_address_as_string_uri_only(addr);
if (uri) {
if (bctbx_list_find_custom(uri_list, (bctbx_compare_func)strcmp, uri) == NULL) {
uri_list = bctbx_list_insert_sorted(uri_list, uri, (bctbx_compare_func)strcasecmp);
}
}
}
iterator = bctbx_list_next(iterator);
}
iterator = numbers;
while (iterator) {
const char *number = (const char *)bctbx_list_get_data(iterator);
const char *uri = linphone_friend_phone_number_to_sip_uri(lf, number);
if (uri) {
if (bctbx_list_find_custom(uri_list, (bctbx_compare_func)strcmp, uri) == NULL) {
uri_list = bctbx_list_insert_sorted(uri_list, ms_strdup(uri), (bctbx_compare_func)strcasecmp);
}
}
iterator = bctbx_list_next(iterator);
}
if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref);
}
return uri_list;
}
static char * create_resource_list_xml(const LinphoneFriendList *list) {
char *xml_content = NULL;
bctbx_list_t *elem;
xmlBufferPtr buf;
xmlTextWriterPtr writer;
int err;
......@@ -135,31 +171,16 @@ static char * create_resource_list_xml(const LinphoneFriendList *list) {
if (err>= 0) {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"list");
}
for (elem = list->friends; elem != NULL; elem = bctbx_list_next(elem)) {
LinphoneFriend *lf = (LinphoneFriend *)bctbx_list_get_data(elem);
bctbx_list_t *iterator;
bctbx_list_t *addresses = linphone_friend_get_addresses(lf);
bctbx_list_t *numbers = linphone_friend_get_phone_numbers(lf);
iterator = addresses;
while (iterator) {
LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(iterator);
if (addr) {
char *uri = linphone_address_as_string_uri_only(addr);
if (uri) {
err = add_uri_entry(writer, err, uri);
ms_free(uri);
}
}
iterator = bctbx_list_next(iterator);
}
iterator = numbers;
while (iterator) {
const char *number = (const char *)bctbx_list_get_data(iterator);
const char *uri = linphone_friend_phone_number_to_sip_uri(lf, number);
if (uri) err = add_uri_entry(writer, err, uri);
iterator = bctbx_list_next(iterator);
{
bctbx_list_t* entries = uri_list(list);
bctbx_list_t* it = entries;
while (it) {
err = add_uri_entry(writer, err, it->data);
ms_free(it->data);
it = it->next;
}
if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref);
bctbx_free(entries);
}
if (err >= 0) {
/* Close the "list" element. */
......
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