diff --git a/coreapi/chat.c b/coreapi/chat.c index 229992156..0dfd6e597 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -304,6 +304,9 @@ void linphone_chat_room_destroy(LinphoneChatRoom *cr) { } void linphone_chat_room_release(LinphoneChatRoom *cr) { + linphone_chat_room_delete_composing_idle_timer(cr); + linphone_chat_room_delete_composing_refresh_timer(cr); + linphone_chat_room_delete_remote_composing_refresh_timer(cr); cr->lc = NULL; linphone_chat_room_unref(cr); } @@ -457,6 +460,10 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage linphone_chat_room_delete_composing_idle_timer(cr); linphone_chat_room_delete_composing_refresh_timer(cr); + if (message_not_encrypted) { + ms_free(message_not_encrypted); + } + if (call && call->op == op) { /*In this case, chat delivery status is not notified, so unrefing chat message right now*/ /*Might be better fixed by delivering status, but too costly for now*/ @@ -465,10 +472,6 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage linphone_chat_message_unref(msg); return; } - - if (message_not_encrypted) { - ms_free(message_not_encrypted); - } } // if operation failed, we should not change message state if (msg->dir == LinphoneChatMessageOutgoing) { @@ -778,6 +781,8 @@ static void process_imdn(LinphoneChatRoom *cr, xmlparsing_context_t *xml_ctx) { xmlXPathObjectPtr display_status_object; const char *message_id_str = NULL; const char *datetime_str = NULL; + LinphoneCore *lc = linphone_chat_room_get_core(cr); + LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); if (linphone_create_xml_xpath_context(xml_ctx) < 0) return; @@ -808,7 +813,9 @@ static void process_imdn(LinphoneChatRoom *cr, xmlparsing_context_t *xml_ctx) { if ((delivery_status_object->nodesetval != NULL) && (delivery_status_object->nodesetval->nodeNr >= 1)) { xmlNodePtr node = delivery_status_object->nodesetval->nodeTab[0]; if ((node->children != NULL) && (node->children->name != NULL) && (strcmp((const char *)node->children->name, "delivered") == 0)) { - linphone_chat_message_update_state(cm, LinphoneChatMessageStateDeliveredToUser); + if (linphone_im_notif_policy_get_recv_imdn_delivered(policy) == TRUE) { + linphone_chat_message_update_state(cm, LinphoneChatMessageStateDeliveredToUser); + } } } xmlXPathFreeObject(delivery_status_object); @@ -817,7 +824,9 @@ static void process_imdn(LinphoneChatRoom *cr, xmlparsing_context_t *xml_ctx) { if ((display_status_object->nodesetval != NULL) && (display_status_object->nodesetval->nodeNr >= 1)) { xmlNodePtr node = display_status_object->nodesetval->nodeTab[0]; if ((node->children != NULL) && (node->children->name != NULL) && (strcmp((const char *)node->children->name, "displayed") == 0)) { - linphone_chat_message_update_state(cm, LinphoneChatMessageStateDisplayed); + if (linphone_im_notif_policy_get_recv_imdn_displayed(policy) == TRUE) { + linphone_chat_message_update_state(cm, LinphoneChatMessageStateDisplayed); + } } } xmlXPathFreeObject(display_status_object); @@ -969,46 +978,50 @@ static void linphone_chat_room_send_is_composing_notification(LinphoneChatRoom * SalOp *op = NULL; const char *identity = NULL; char *content = NULL; - LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(cr->lc, cr->peer_url); - LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(cr->lc); - LinphoneChatMessage *msg = NULL; - - if (proxy) - identity = linphone_proxy_config_get_identity(proxy); - else - identity = linphone_core_get_primary_contact(cr->lc); - /*sending out of calls*/ - op = sal_op_new(cr->lc->sal); - linphone_configure_op(cr->lc, op, cr->peer_url, NULL, - lp_config_get_int(cr->lc->config, "sip", "chat_msg_with_contact", 0)); + LinphoneCore *lc = linphone_chat_room_get_core(cr); + LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); + if (linphone_im_notif_policy_get_send_is_composing(policy) == TRUE) { + LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(lc, cr->peer_url); + LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(lc); + LinphoneChatMessage *msg = NULL; - content = linphone_chat_room_create_is_composing_xml(cr); - if (content != NULL) { - int retval = -1; - LinphoneAddress *from_addr = linphone_address_new(identity); - LinphoneAddress *to_addr = linphone_address_new(cr->peer); - msg = linphone_chat_room_create_message(cr, content); - linphone_chat_message_set_from_address(msg, from_addr); - linphone_chat_message_set_to_address(msg, to_addr); - msg->content_type = ms_strdup("application/im-iscomposing+xml"); - - if (imee) { - LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); - LinphoneImEncryptionEngineCbsOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); - if (cb_process_outgoing_message) { - retval = cb_process_outgoing_message(imee, cr, msg); + if (proxy) + identity = linphone_proxy_config_get_identity(proxy); + else + identity = linphone_core_get_primary_contact(lc); + /*sending out of calls*/ + op = sal_op_new(lc->sal); + linphone_configure_op(lc, op, cr->peer_url, NULL, + lp_config_get_int(lc->config, "sip", "chat_msg_with_contact", 0)); + + content = linphone_chat_room_create_is_composing_xml(cr); + if (content != NULL) { + int retval = -1; + LinphoneAddress *from_addr = linphone_address_new(identity); + LinphoneAddress *to_addr = linphone_address_new(cr->peer); + msg = linphone_chat_room_create_message(cr, content); + linphone_chat_message_set_from_address(msg, from_addr); + linphone_chat_message_set_to_address(msg, to_addr); + msg->content_type = ms_strdup("application/im-iscomposing+xml"); + + if (imee) { + LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); + LinphoneImEncryptionEngineCbsOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); + if (cb_process_outgoing_message) { + retval = cb_process_outgoing_message(imee, cr, msg); + } } - } - if (retval <= 0) { - sal_message_send(op, identity, cr->peer, msg->content_type, msg->message, NULL); + if (retval <= 0) { + sal_message_send(op, identity, cr->peer, msg->content_type, msg->message, NULL); + } + + linphone_chat_message_unref(msg); + linphone_address_destroy(from_addr); + linphone_address_destroy(to_addr); + ms_free(content); + sal_op_unref(op); } - - linphone_chat_message_unref(msg); - linphone_address_destroy(from_addr); - linphone_address_destroy(to_addr); - ms_free(content); - sal_op_unref(op); } } @@ -1123,9 +1136,9 @@ static void linphone_chat_message_send_imdn(LinphoneChatMessage *cm, enum ImdnTy if (imee) { LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); - LinphoneImEncryptionEngineOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); + LinphoneImEncryptionEngineCbsOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); if (cb_process_outgoing_message) { - retval = cb_process_outgoing_message(cr->lc, cr, msg); + retval = cb_process_outgoing_message(imee, cr, msg); } } @@ -1142,11 +1155,21 @@ static void linphone_chat_message_send_imdn(LinphoneChatMessage *cm, enum ImdnTy } void linphone_chat_message_send_delivery_notification(LinphoneChatMessage *cm) { - linphone_chat_message_send_imdn(cm, ImdnTypeDelivery); + LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(cm); + LinphoneCore *lc = linphone_chat_room_get_core(cr); + LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); + if (linphone_im_notif_policy_get_send_imdn_delivered(policy) == TRUE) { + linphone_chat_message_send_imdn(cm, ImdnTypeDelivery); + } } void linphone_chat_message_send_display_notification(LinphoneChatMessage *cm) { - linphone_chat_message_send_imdn(cm, ImdnTypeDisplay); + LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(cm); + LinphoneCore *lc = linphone_chat_room_get_core(cr); + LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); + if (linphone_im_notif_policy_get_send_imdn_displayed(policy) == TRUE) { + linphone_chat_message_send_imdn(cm, ImdnTypeDisplay); + } } static char* utf8_to_char(uint32_t ic) { diff --git a/coreapi/im_notif_policy.c b/coreapi/im_notif_policy.c index 61ec70bf3..4cfea5eb1 100644 --- a/coreapi/im_notif_policy.c +++ b/coreapi/im_notif_policy.c @@ -40,30 +40,30 @@ static void load_im_notif_policy_from_config(LinphoneImNotifPolicy *policy) { const char *value = (const char *)bctbx_list_get_data(elem); if (strcasecmp(value, "all") == 0) { policy->send_is_composing = TRUE; - policy->display_is_composing = TRUE; + policy->recv_is_composing = TRUE; policy->send_imdn_delivered = TRUE; - policy->display_imdn_delivered = TRUE; + policy->recv_imdn_delivered = TRUE; policy->send_imdn_displayed = TRUE; - policy->display_imdn_displayed = TRUE; + policy->recv_imdn_displayed = TRUE; } else if (strcasecmp(value, "none") == 0) { policy->send_is_composing = FALSE; - policy->display_is_composing = FALSE; + policy->recv_is_composing = FALSE; policy->send_imdn_delivered = FALSE; - policy->display_imdn_delivered = FALSE; + policy->recv_imdn_delivered = FALSE; policy->send_imdn_displayed = FALSE; - policy->display_imdn_displayed = FALSE; + policy->recv_imdn_displayed = FALSE; } else if (strcasecmp(value, "send_is_comp") == 0) { policy->send_is_composing = TRUE; - } else if (strcasecmp(value, "disp_is_comp") == 0) { - policy->display_is_composing = TRUE; + } else if (strcasecmp(value, "recv_is_comp") == 0) { + policy->recv_is_composing = TRUE; } else if (strcasecmp(value, "send_imdn_delivered") == 0) { policy->send_imdn_delivered = TRUE; - } else if (strcasecmp(value, "disp_imdn_delivered") == 0) { - policy->display_imdn_delivered = TRUE; + } else if (strcasecmp(value, "recv_imdn_delivered") == 0) { + policy->recv_imdn_delivered = TRUE; } else if (strcasecmp(value, "send_imdn_displayed") == 0) { policy->send_imdn_displayed = TRUE; - } else if (strcasecmp(value, "disp_imdn_displayed") == 0) { - policy->display_imdn_displayed = TRUE; + } else if (strcasecmp(value, "recv_imdn_displayed") == 0) { + policy->recv_imdn_displayed = TRUE; } } if (values != default_list) { @@ -75,32 +75,32 @@ static void load_im_notif_policy_from_config(LinphoneImNotifPolicy *policy) { static void save_im_notif_policy_to_config(LinphoneImNotifPolicy *policy) { bctbx_list_t *values = NULL; if ((policy->send_is_composing == TRUE) - && (policy->display_is_composing == TRUE) + && (policy->recv_is_composing == TRUE) && (policy->send_imdn_delivered == TRUE) - && (policy->display_imdn_delivered == TRUE) + && (policy->recv_imdn_delivered == TRUE) && (policy->send_imdn_displayed == TRUE) - && (policy->display_imdn_displayed == TRUE)) { + && (policy->recv_imdn_displayed == TRUE)) { /* Do not save anything, the default is everything enabled */ } else if ((policy->send_is_composing == FALSE) - && (policy->display_is_composing == FALSE) + && (policy->recv_is_composing == FALSE) && (policy->send_imdn_delivered == FALSE) - && (policy->display_imdn_delivered == FALSE) + && (policy->recv_imdn_delivered == FALSE) && (policy->send_imdn_displayed == FALSE) - && (policy->display_imdn_displayed == FALSE)) { + && (policy->recv_imdn_displayed == FALSE)) { values = bctbx_list_append(values, "none"); } else { if (policy->send_is_composing == TRUE) values = bctbx_list_append(values, "send_is_comp"); - if (policy->display_is_composing == TRUE) - values = bctbx_list_append(values, "disp_is_comp"); + if (policy->recv_is_composing == TRUE) + values = bctbx_list_append(values, "recv_is_comp"); if (policy->send_imdn_delivered == TRUE) values = bctbx_list_append(values, "send_imdn_delivered"); - if (policy->display_imdn_delivered == TRUE) - values = bctbx_list_append(values, "disp_imdn_delivered"); + if (policy->recv_imdn_delivered == TRUE) + values = bctbx_list_append(values, "recv_imdn_delivered"); if (policy->send_imdn_displayed == TRUE) values = bctbx_list_append(values, "send_imdn_displayed"); - if (policy->display_imdn_displayed == TRUE) - values = bctbx_list_append(values, "disp_imdn_displayed"); + if (policy->recv_imdn_displayed == TRUE) + values = bctbx_list_append(values, "recv_imdn_displayed"); } lp_config_set_string_list(policy->lc->config, "sip", "im_notif_policy", values); if (values != NULL) bctbx_list_free(values); @@ -126,11 +126,21 @@ void linphone_im_notif_policy_set_user_data(LinphoneImNotifPolicy *policy, void void linphone_im_notif_policy_clear(LinphoneImNotifPolicy *policy) { policy->send_is_composing = FALSE; - policy->display_is_composing = FALSE; + policy->recv_is_composing = FALSE; policy->send_imdn_delivered = FALSE; - policy->display_imdn_delivered = FALSE; + policy->recv_imdn_delivered = FALSE; policy->send_imdn_displayed = FALSE; - policy->display_imdn_displayed = FALSE; + policy->recv_imdn_displayed = FALSE; + save_im_notif_policy_to_config(policy); +} + +void linphone_im_notif_policy_enable_all(LinphoneImNotifPolicy *policy) { + policy->send_is_composing = TRUE; + policy->recv_is_composing = TRUE; + policy->send_imdn_delivered = TRUE; + policy->recv_imdn_delivered = TRUE; + policy->send_imdn_displayed = TRUE; + policy->recv_imdn_displayed = TRUE; save_im_notif_policy_to_config(policy); } @@ -143,12 +153,12 @@ void linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy *polic save_im_notif_policy_to_config(policy); } -bool_t linphone_im_notif_policy_get_display_is_composing(const LinphoneImNotifPolicy *policy) { - return policy->display_is_composing; +bool_t linphone_im_notif_policy_get_recv_is_composing(const LinphoneImNotifPolicy *policy) { + return policy->recv_is_composing; } -void linphone_im_notif_policy_set_display_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) { - policy->display_is_composing = enable; +void linphone_im_notif_policy_set_recv_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) { + policy->recv_is_composing = enable; save_im_notif_policy_to_config(policy); } @@ -161,12 +171,12 @@ void linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy *pol save_im_notif_policy_to_config(policy); } -bool_t linphone_im_notif_policy_get_display_imdn_delivered(const LinphoneImNotifPolicy *policy) { - return policy->display_imdn_delivered; +bool_t linphone_im_notif_policy_get_recv_imdn_delivered(const LinphoneImNotifPolicy *policy) { + return policy->recv_imdn_delivered; } -void linphone_im_notif_policy_set_display_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) { - policy->display_imdn_delivered = enable; +void linphone_im_notif_policy_set_recv_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) { + policy->recv_imdn_delivered = enable; save_im_notif_policy_to_config(policy); } @@ -179,12 +189,12 @@ void linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy *pol save_im_notif_policy_to_config(policy); } -bool_t linphone_im_notif_policy_get_display_imdn_displayed(const LinphoneImNotifPolicy *policy) { - return policy->display_imdn_displayed; +bool_t linphone_im_notif_policy_get_recv_imdn_displayed(const LinphoneImNotifPolicy *policy) { + return policy->recv_imdn_displayed; } -void linphone_im_notif_policy_set_display_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) { - policy->display_imdn_displayed = enable; +void linphone_im_notif_policy_set_recv_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) { + policy->recv_imdn_displayed = enable; save_im_notif_policy_to_config(policy); } diff --git a/coreapi/private.h b/coreapi/private.h index 148aeb7d0..76eaf0cea 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1297,11 +1297,11 @@ struct _LinphoneImNotifPolicy { void *user_data; LinphoneCore *lc; bool_t send_is_composing; - bool_t display_is_composing; + bool_t recv_is_composing; bool_t send_imdn_delivered; - bool_t display_imdn_delivered; + bool_t recv_imdn_delivered; bool_t send_imdn_displayed; - bool_t display_imdn_displayed; + bool_t recv_imdn_displayed; }; BELLE_SIP_DECLARE_VPTR(LinphoneImNotifPolicy); diff --git a/coreapi/vtables.c b/coreapi/vtables.c index e106fef01..d2e305acf 100644 --- a/coreapi/vtables.c +++ b/coreapi/vtables.c @@ -213,8 +213,11 @@ void linphone_core_notify_file_transfer_progress_indication(LinphoneCore *lc, Li #pragma GCC diagnostic pop #endif void linphone_core_notify_is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) { - NOTIFY_IF_EXIST(is_composing_received, lc,room); - cleanup_dead_vtable_refs(lc); + LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); + if (linphone_im_notif_policy_get_recv_is_composing(policy) == TRUE) { + NOTIFY_IF_EXIST(is_composing_received, lc,room); + cleanup_dead_vtable_refs(lc); + } } void linphone_core_notify_dtmf_received(LinphoneCore* lc, LinphoneCall *call, int dtmf) { diff --git a/include/linphone/im_notif_policy.h b/include/linphone/im_notif_policy.h index 2f74c496b..8d1c74dd4 100644 --- a/include/linphone/im_notif_policy.h +++ b/include/linphone/im_notif_policy.h @@ -32,7 +32,7 @@ extern "C" { */ /** - * Policy to use to send/display instant messaging composing/delivery/display notifications. + * Policy to use to send/receive instant messaging composing/delivery/display notifications. * The sending of this information is done as in the RFCs 3994 (is_composing) and 5438 (imdn delivered/displayed). */ typedef struct _LinphoneImNotifPolicy LinphoneImNotifPolicy; @@ -66,11 +66,17 @@ LINPHONE_PUBLIC void *linphone_im_notif_policy_get_user_data(const LinphoneImNot LINPHONE_PUBLIC void linphone_im_notif_policy_set_user_data(LinphoneImNotifPolicy *policy, void *ud); /** - * Clear an IM notif policy (deactivate all display and sending of notifications). + * Clear an IM notif policy (deactivate all receiving and sending of notifications). * @param[in] policy LinphoneImNotifPolicy object. */ LINPHONE_PUBLIC void linphone_im_notif_policy_clear(LinphoneImNotifPolicy *policy); +/** + * Enable all receiving and sending of notifications. + * @param[in] policy LinphoneImNotifPolicy object. + */ +LINPHONE_PUBLIC void linphone_im_notif_policy_enable_all(LinphoneImNotifPolicy *policy); + /** * Tell whether is_composing notifications are being sent. * @param[in] policy LinphoneImNotifPolicy object @@ -86,18 +92,18 @@ LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_send_is_composing(const Linp LINPHONE_PUBLIC void linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy *policy, bool_t enable); /** - * Tell whether is_composing notifications are being displayed. + * Tell whether is_composing notifications are being notified when received. * @param[in] policy LinphoneImNotifPolicy object - * @return Boolean value telling whether is_composing notifications are being displayed. + * @return Boolean value telling whether is_composing notifications are being notified when received. */ -LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_display_is_composing(const LinphoneImNotifPolicy *policy); +LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_recv_is_composing(const LinphoneImNotifPolicy *policy); /** - * Enable is_composing notifications display. + * Enable is_composing notifications receiving. * @param[in] policy LinphoneImNotifPolicy object - * @param[in] enable Boolean value telling whether to display is_composing notifications. + * @param[in] enable Boolean value telling whether to notify received is_composing notifications. */ -LINPHONE_PUBLIC void linphone_im_notif_policy_set_display_is_composing(LinphoneImNotifPolicy *policy, bool_t enable); +LINPHONE_PUBLIC void linphone_im_notif_policy_set_recv_is_composing(LinphoneImNotifPolicy *policy, bool_t enable); /** * Tell whether imdn delivered notifications are being sent. @@ -114,18 +120,18 @@ LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_send_imdn_delivered(const Li LINPHONE_PUBLIC void linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable); /** - * Tell whether imdn delivered notifications are being displayed. + * Tell whether imdn delivered notifications are being notified when received. * @param[in] policy LinphoneImNotifPolicy object - * @return Boolean value telling whether imdn delivered notifications are being displayed. + * @return Boolean value telling whether imdn delivered notifications are being notified when received. */ -LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_display_imdn_delivered(const LinphoneImNotifPolicy *policy); +LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_recv_imdn_delivered(const LinphoneImNotifPolicy *policy); /** - * Enable imdn delivered notifications display. + * Enable imdn delivered notifications receiving. * @param[in] policy LinphoneImNotifPolicy object - * @param[in] enable Boolean value telling whether to display imdn delivered notifications. + * @param[in] enable Boolean value telling whether to notify received imdn delivered notifications. */ -LINPHONE_PUBLIC void linphone_im_notif_policy_set_display_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable); +LINPHONE_PUBLIC void linphone_im_notif_policy_set_recv_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable); /** * Tell whether imdn displayed notifications are being sent. @@ -142,18 +148,18 @@ LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_send_imdn_displayed(const Li LINPHONE_PUBLIC void linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable); /** - * Tell whether imdn displayed notifications are being displayed. + * Tell whether imdn displayed notifications are being notified when received. * @param[in] policy LinphoneImNotifPolicy object - * @return Boolean value telling whether imdn displayed notifications are being displayed. + * @return Boolean value telling whether imdn displayed notifications are being notified when received. */ -LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_display_imdn_displayed(const LinphoneImNotifPolicy *policy); +LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_recv_imdn_displayed(const LinphoneImNotifPolicy *policy); /** - * Enable imdn displayed notifications display. + * Enable imdn displayed notifications receiving. * @param[in] policy LinphoneImNotifPolicy object - * @param[in] enable Boolean value telling whether to display imdn displayed notifications. + * @param[in] enable Boolean value telling whether to notify received imdn displayed notifications. */ -LINPHONE_PUBLIC void linphone_im_notif_policy_set_display_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable); +LINPHONE_PUBLIC void linphone_im_notif_policy_set_recv_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable); /** * Get the LinphoneImNotifPolicy object controlling the instant messaging notifications. diff --git a/tester/message_tester.c b/tester/message_tester.c index 76cbea0d5..00e109ec6 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -451,6 +451,7 @@ void transfer_message_base2(LinphoneCoreManager* marie, LinphoneCoreManager* pau LinphoneChatRoom* chat_room; LinphoneChatMessage* msg; LinphoneChatMessageCbs *cbs; + bctbx_list_t *msg_list = NULL; /* Remove any previously downloaded file */ remove(receive_filepath); @@ -486,8 +487,18 @@ void transfer_message_base2(LinphoneCoreManager* marie, LinphoneCoreManager* pau BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneRegistrationOk,pauline->stat.number_of_LinphoneRegistrationOk+1)); } else { BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); - if (marie->stat.last_received_chat_message ) { - cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message); + if (marie->stat.last_received_chat_message) { + LinphoneChatMessage *recv_msg; + if (download_from_history) { + LinphoneChatRoom *marie_room = linphone_core_get_chat_room(marie->lc, pauline->identity); + msg_list = linphone_chat_room_get_history(marie_room,1); + BC_ASSERT_PTR_NOT_NULL(msg_list); + if (!msg_list) goto end; + recv_msg = (LinphoneChatMessage *)msg_list->data; + } else { + recv_msg = marie->stat.last_received_chat_message; + } + cbs = linphone_chat_message_get_callbacks(recv_msg); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); @@ -833,7 +844,7 @@ static void _is_composing_notification(bool_t lime_enabled) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); - + if (lime_enabled) { if (!linphone_core_lime_available(marie->lc)) { ms_warning("Lime not available, skiping"); @@ -885,7 +896,7 @@ static void is_composing_notification_with_lime(void) { static void imdn_notifications(void) { LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); - LinphoneCoreManager *pauline = linphone_core_manager_new( "pauline_tcp_rc"); + LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_tcp_rc"); LinphoneChatRoom *pauline_chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); LinphoneChatRoom *marie_chat_room; LinphoneChatMessage *sent_cm; @@ -893,6 +904,8 @@ static void imdn_notifications(void) { LinphoneChatMessageCbs *cbs; bctbx_list_t *history; + linphone_im_notif_policy_enable_all(linphone_core_get_im_notif_policy(marie->lc)); + linphone_im_notif_policy_enable_all(linphone_core_get_im_notif_policy(pauline->lc)); sent_cm = linphone_chat_room_create_message(pauline_chat_room, "Tell me if you get my message"); linphone_chat_message_ref(sent_cm); cbs = linphone_chat_message_get_callbacks(sent_cm); @@ -916,6 +929,90 @@ static void imdn_notifications(void) { linphone_core_manager_destroy(pauline); } +static void im_notification_policy(void) { + LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); + LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_tcp_rc"); + LinphoneImNotifPolicy *marie_policy = linphone_core_get_im_notif_policy(marie->lc); + LinphoneImNotifPolicy *pauline_policy = linphone_core_get_im_notif_policy(pauline->lc); + LinphoneChatRoom *pauline_chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); + LinphoneChatRoom *marie_chat_room; + LinphoneChatMessage *msg1; + LinphoneChatMessage *msg2; + LinphoneChatMessage *msg3; + LinphoneChatMessage *msg4; + LinphoneChatMessageCbs *cbs; + int dummy = 0; + + linphone_im_notif_policy_enable_all(marie_policy); + linphone_im_notif_policy_clear(pauline_policy); + marie_chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity); /* Make marie create the chatroom with pauline, which is necessary for receiving the is-composing */ + + /* Test is_composing sending */ + linphone_chat_room_compose(pauline_chat_room); + wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /* Just to sleep while iterating */ + BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneIsComposingActiveReceived, 0, int, "%d"); + linphone_im_notif_policy_set_send_is_composing(pauline_policy, TRUE); + linphone_chat_room_compose(pauline_chat_room); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, 1)); + + /* Test is_composing receiving */ + linphone_chat_room_compose(marie_chat_room); + wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /* Just to sleep while iterating */ + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneIsComposingActiveReceived, 0, int, "%d"); + linphone_im_notif_policy_set_recv_is_composing(pauline_policy, TRUE); + linphone_chat_room_compose(marie_chat_room); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneIsComposingActiveReceived, 1)); + + /* Test imdn delivered */ + msg1 = linphone_chat_room_create_message(pauline_chat_room, "Happy new year!"); + linphone_chat_message_ref(msg1); + cbs = linphone_chat_message_get_callbacks(msg1); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(pauline_chat_room, msg1); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); + wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /* Just to sleep while iterating */ + BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDeliveredToUser, 0, int, "%d"); + linphone_im_notif_policy_set_recv_imdn_delivered(pauline_policy, TRUE); + msg2 = linphone_chat_room_create_message(pauline_chat_room, "I said: Happy new year!"); + linphone_chat_message_ref(msg2); + cbs = linphone_chat_message_get_callbacks(msg2); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(pauline_chat_room, msg2); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 2)); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDeliveredToUser, 1)); + msg3 = linphone_chat_room_create_message(marie_chat_room, "Thank you! Happy easter to you!"); + linphone_chat_message_ref(msg3); + cbs = linphone_chat_message_get_callbacks(msg3); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(marie_chat_room, msg3); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceived, 1)); + wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /* Just to sleep while iterating */ + BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageDeliveredToUser, 0, int, "%d"); + linphone_im_notif_policy_set_send_imdn_delivered(pauline_policy, TRUE); + msg4 = linphone_chat_room_create_message(marie_chat_room, "Yeah, yeah, I heard that..."); + linphone_chat_message_ref(msg4); + cbs = linphone_chat_message_get_callbacks(msg4); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(marie_chat_room, msg4); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceived, 2)); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageDeliveredToUser, 1)); + + /* Test imdn displayed */ + linphone_im_notif_policy_set_send_imdn_displayed(pauline_policy, TRUE); + linphone_chat_room_mark_as_read(pauline_chat_room); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageDisplayed, 2)); + linphone_im_notif_policy_set_recv_imdn_displayed(pauline_policy, TRUE); + linphone_chat_room_mark_as_read(marie_chat_room); + BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDisplayed, 2)); + + linphone_chat_message_unref(msg1); + linphone_chat_message_unref(msg2); + linphone_chat_message_unref(msg3); + linphone_chat_message_unref(msg4); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + static void lime_text_message(void) { FILE *ZIDCacheMarieFD, *ZIDCachePaulineFD; LinphoneChatRoom* chat_room; @@ -927,7 +1024,7 @@ static void lime_text_message(void) { ms_warning("Lime not available, skiping"); goto end; } - /* make sure lime is enabled */ + /* make sure lime is enabled and im notify policy is empty */ linphone_core_enable_lime(marie->lc, 1); linphone_core_enable_lime(pauline->lc, 1); @@ -2083,6 +2180,7 @@ test_t message_tests[] = { TEST_NO_TAG("IsComposing notification", is_composing_notification), TEST_ONE_TAG("IsComposing notification lime", is_composing_notification_with_lime, "LIME"), TEST_NO_TAG("IMDN notifications", imdn_notifications), + TEST_NO_TAG("IM notification policy", im_notification_policy), TEST_ONE_TAG("Lime text message", lime_text_message, "LIME"), TEST_ONE_TAG("Lime text message to non lime", lime_text_message_to_non_lime, "LIME"), TEST_ONE_TAG("Lime transfer message", lime_transfer_message, "LIME"), diff --git a/tester/tester.c b/tester/tester.c index 2c719bbbd..f5d676031 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -290,8 +290,10 @@ bool_t transport_supported(LinphoneTransportType transport) { #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, const char* phone_alias) { + LinphoneImNotifPolicy *im_notif_policy; char *rc_path = NULL; char *hellopath = bc_tester_res("sounds/hello8000.wav"); + mgr->number_of_bcunit_error_at_creation = bc_get_number_of_failures(); mgr->v_table.registration_state_changed=registration_state_changed; mgr->v_table.auth_info_requested=auth_info_requested; @@ -319,6 +321,10 @@ void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, c if (rc_file) rc_path = ms_strdup_printf("rcfiles/%s", rc_file); mgr->lc=configure_lc_from(&mgr->v_table, bc_tester_get_resource_dir_prefix(), rc_path, mgr); linphone_core_manager_check_accounts(mgr); + im_notif_policy = linphone_core_get_im_notif_policy(mgr->lc); + linphone_im_notif_policy_clear(im_notif_policy); + linphone_im_notif_policy_set_send_is_composing(im_notif_policy, TRUE); + linphone_im_notif_policy_set_recv_is_composing(im_notif_policy, TRUE); manager_count++; @@ -438,9 +444,11 @@ void linphone_core_manager_stop(LinphoneCoreManager *mgr){ } } linphone_core_destroy(mgr->lc); - if (chatdb && ortp_file_exist(chatdb)==0) { - if (unlink(chatdb) != 0){ - ms_error("Could not delete %s: %s", chatdb, strerror(errno)); + if (chatdb) { + if (ortp_file_exist(chatdb)==0) { + if (unlink(chatdb) != 0){ + ms_error("Could not delete %s: %s", chatdb, strerror(errno)); + } } ms_free(chatdb); }