Commit fb04d714 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Test association of SIP URI and phone number in presence server tester.

parent 0af98652
......@@ -136,6 +136,11 @@ static void free_friend_presence(LinphoneFriendPresence *lfp) {
if (lfp->presence) linphone_presence_model_unref(lfp->presence);
}
static void free_phone_number_sip_uri(LinphoneFriendPhoneNumberSipUri *lfpnsu) {
ms_free(lfpnsu->number);
ms_free(lfpnsu->uri);
}
bctbx_list_t *linphone_find_friend_by_address(bctbx_list_t *fl, const LinphoneAddress *addr, LinphoneFriend **lf){
......@@ -478,6 +483,7 @@ static void _linphone_friend_release_ops(LinphoneFriend *lf){
static void _linphone_friend_destroy(LinphoneFriend *lf){
_linphone_friend_release_ops(lf);
if (lf->presence_models) bctbx_list_free_with_data(lf->presence_models, (bctbx_list_free_func)free_friend_presence);
if (lf->phone_number_sip_uri_map) bctbx_list_free_with_data(lf->phone_number_sip_uri_map, (bctbx_list_free_func)free_phone_number_sip_uri);
if (lf->uri!=NULL) linphone_address_unref(lf->uri);
if (lf->info!=NULL) buddy_info_free(lf->info);
if (lf->vcard != NULL) linphone_vcard_free(lf->vcard);
......@@ -1683,3 +1689,7 @@ const char * linphone_friend_sip_uri_to_phone_number(LinphoneFriend *lf, const c
}
return NULL;
}
void linphone_friend_clear_presence_models(LinphoneFriend *lf) {
bctbx_list_free_with_data(lf->presence_models, (bctbx_list_free_func)free_friend_presence);
}
\ No newline at end of file
......@@ -160,7 +160,6 @@ static char * create_resource_list_xml(const LinphoneFriendList *list) {
iterator = bctbx_list_next(iterator);
}
if (addresses) bctbx_list_free_with_data(addresses, (bctbx_list_free_func)linphone_address_unref);
if (numbers) bctbx_list_free_with_data(numbers, (bctbx_list_free_func)ms_free);
}
if (err >= 0) {
/* Close the "list" element. */
......@@ -225,7 +224,7 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList
bctbx_list_t *l = list->friends;
for (; l != NULL; l = bctbx_list_next(l)) {
lf = (LinphoneFriend *)bctbx_list_get_data(l);
linphone_friend_set_presence_model(lf, NULL);
linphone_friend_clear_presence_models(lf);
}
full_state = TRUE;
}
......@@ -262,9 +261,12 @@ static void linphone_friend_list_parse_multipart_related_body(LinphoneFriendList
const char *phone_number = linphone_friend_sip_uri_to_phone_number(lf, uri);
lf->presence_received = TRUE;
if (phone_number) linphone_friend_set_presence_model_for_uri_or_tel(lf, phone_number, (LinphonePresenceModel *)presence);
else linphone_friend_set_presence_model_for_uri_or_tel(lf, uri, (LinphonePresenceModel *)presence);
if (full_state == FALSE) {
if (phone_number)
linphone_core_notify_notify_presence_received_for_uri_or_tel(list->lc, lf, phone_number, (LinphonePresenceModel *)presence);
else
linphone_core_notify_notify_presence_received_for_uri_or_tel(list->lc, lf, uri, (LinphonePresenceModel *)presence);
linphone_core_notify_notify_presence_received(list->lc, lf);
}
}
......@@ -627,16 +629,32 @@ LinphoneFriend * linphone_friend_list_find_friend_by_address(const LinphoneFrien
LinphoneFriend *lf = NULL;
LinphoneFriend *result = NULL;
const bctbx_list_t *elem;
const char *param = linphone_address_get_uri_param(address, "user");
bool_t find_phone_number = FALSE;
if (param && (strcmp(param, "phone") == 0)) find_phone_number = TRUE;
for (elem = list->friends; (elem != NULL) && (result == NULL); elem = bctbx_list_next(elem)) {
bctbx_list_t *addresses;
bctbx_list_t *iterator;
lf = (LinphoneFriend *)bctbx_list_get_data(elem);
iterator = addresses = linphone_friend_get_addresses(lf);
while (iterator && (result == NULL)) {
LinphoneAddress *lfaddr = (LinphoneAddress *)bctbx_list_get_data(iterator);
if (linphone_address_weak_equal(lfaddr, address))
result = lf;
iterator = bctbx_list_next(iterator);
if (find_phone_number == TRUE) {
char *uri = linphone_address_as_string_uri_only(address);
const char *phone_number = linphone_friend_sip_uri_to_phone_number(lf, uri);
bctbx_list_t *phone_numbers = linphone_friend_get_phone_numbers(lf);
iterator = phone_numbers;
ms_free(uri);
while (iterator && (result == NULL)) {
const char *number = (const char *)bctbx_list_get_data(iterator);
if (strcmp(number, phone_number) == 0) result = lf;
iterator = bctbx_list_next(iterator);
}
} else {
bctbx_list_t *addresses = linphone_friend_get_addresses(lf);
iterator = addresses;
while (iterator && (result == NULL)) {
LinphoneAddress *lfaddr = (LinphoneAddress *)bctbx_list_get_data(iterator);
if (linphone_address_weak_equal(lfaddr, address)) result = lf;
iterator = bctbx_list_next(iterator);
}
}
}
return result;
......
......@@ -430,6 +430,7 @@ void linphone_friend_add_incoming_subscription(LinphoneFriend *lf, SalOp *op);
void linphone_friend_remove_incoming_subscription(LinphoneFriend *lf, SalOp *op);
const char * linphone_friend_phone_number_to_sip_uri(LinphoneFriend *lf, const char *phone_number);
const char * linphone_friend_sip_uri_to_phone_number(LinphoneFriend *lf, const char *uri);
void linphone_friend_clear_presence_models(LinphoneFriend *lf);
LinphoneFriend *linphone_friend_list_find_friend_by_inc_subscribe(const LinphoneFriendList *list, SalOp *op);
LinphoneFriend *linphone_friend_list_find_friend_by_out_subscribe(const LinphoneFriendList *list, SalOp *op);
LinphoneFriend *linphone_core_find_friend_by_out_subscribe(const LinphoneCore *lc, SalOp *op);
......
......@@ -167,6 +167,7 @@ typedef struct _stats {
int number_of_NewSubscriptionRequest;
int number_of_NotifyReceived;
int number_of_NotifyPresenceReceived;
int number_of_NotifyPresenceReceivedForUriOrTel;
int number_of_LinphonePresenceActivityOffline;
int number_of_LinphonePresenceActivityOnline;
int number_of_LinphonePresenceActivityAppointment;
......@@ -297,6 +298,7 @@ void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *c
void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg);
void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state);
void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf);
void notify_presence_received_for_uri_or_tel(LinphoneCore *lc, LinphoneFriend *lf, const char *uri_or_tel, const LinphonePresenceModel *presence);
void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message);
void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message);
void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const LinphoneBuffer *buffer);
......
......@@ -712,6 +712,8 @@ static void long_term_presence_phone_alias2(void) {
static void long_term_presence_list(void) {
LinphoneFriend *f1, *f2;
LinphoneFriendList* friends;
const LinphonePresenceModel *presence;
const char *phone_number = "+331234567890";
LinphoneCoreManager *pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
enable_publish(pauline, FALSE);
enable_deflate_content_encoding(pauline, FALSE);
......@@ -719,6 +721,7 @@ static void long_term_presence_list(void) {
friends = linphone_core_create_friend_list(pauline->lc);
linphone_friend_list_set_rls_uri(friends, "sip:rls@sip.example.org");
f1 = linphone_core_create_friend_with_address(pauline->lc, "sip:liblinphone_tester@sip.example.org");
linphone_friend_add_phone_number(f1, phone_number);
linphone_friend_list_add_friend(friends, f1);
linphone_friend_unref(f1);
f2 = linphone_core_create_friend_with_address(pauline->lc, "sip:random_unknown@sip.example.org");
......@@ -729,9 +732,15 @@ static void long_term_presence_list(void) {
linphone_friend_list_unref(friends);
BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_NotifyPresenceReceived,1));
BC_ASSERT_TRUE(wait_for(pauline->lc, NULL, &pauline->stat.number_of_NotifyPresenceReceivedForUriOrTel, 2));
f1 = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(pauline->lc), "sip:liblinphone_tester@sip.example.org");
BC_ASSERT_EQUAL(linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(f1)), LinphonePresenceBasicStatusOpen, int, "%d");
presence = linphone_friend_get_presence_model_for_uri_or_tel(f1, phone_number);
BC_ASSERT_PTR_NOT_NULL(presence);
if (presence) {
BC_ASSERT_STRING_EQUAL(linphone_presence_model_get_contact(presence), "sip:liblinphone_tester@sip.example.org");
}
BC_ASSERT_TRUE(f1->presence_received);
f2 = linphone_friend_list_find_friend_by_uri(linphone_core_get_default_friend_list(pauline->lc), "sip:random_unknown@sip.example.org");
......
......@@ -131,6 +131,12 @@ void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) {
}
}
void notify_presence_received_for_uri_or_tel(LinphoneCore *lc, LinphoneFriend *lf, const char *uri_or_tel, const LinphonePresenceModel *presence) {
stats *counters = get_stats(lc);
ms_message("Presence notification for URI or phone number [%s]", uri_or_tel);
counters->number_of_NotifyPresenceReceivedForUriOrTel++;
}
static void simple_publish_with_expire(int expires) {
LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
LinphoneProxyConfig* proxy;
......
......@@ -289,6 +289,7 @@ void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, c
mgr->v_table.is_composing_received=is_composing_received;
mgr->v_table.new_subscription_requested=new_subscription_requested;
mgr->v_table.notify_presence_received=notify_presence_received;
mgr->v_table.notify_presence_received_for_uri_or_tel=notify_presence_received_for_uri_or_tel;
mgr->v_table.transfer_state_changed=linphone_transfer_state_changed;
mgr->v_table.info_received=info_message_received;
mgr->v_table.subscription_state_changed=linphone_subscription_state_change;
......
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