Commit 6e37c97c authored by Ghislain MARY's avatar Ghislain MARY

Add the LinphoneImNotifPolicy object to configure whether to display/send IM...

Add the LinphoneImNotifPolicy object to configure whether to display/send IM notifications (is_composing, message delivered, message displayed).
parent f9ae4317
......@@ -80,6 +80,7 @@ set(LINPHONE_SOURCE_FILES_C
event.c
friend.c
friendlist.c
im_notif_policy.c
info.c
ldapprovider.c
lime.c
......
......@@ -47,6 +47,7 @@ liblinphone_la_SOURCES=\
event.c \
friend.c \
friendlist.c \
im_notify_policy.c \
info.c \
ldapprovider.c \
linphonecall.c \
......
/*
linphone
Copyright (C) 2010-2016 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/core.h"
#include "private.h"
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneImNotifPolicy);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneImNotifPolicy, belle_sip_object_t,
NULL, // destroy
NULL, // clone
NULL, // marshal
FALSE
);
static void load_im_notif_policy_from_config(LinphoneImNotifPolicy *policy) {
bctbx_list_t *default_list = bctbx_list_append(NULL, "all");
bctbx_list_t *values = lp_config_get_string_list(policy->lc->config, "sip", "im_notif_policy", default_list);
bctbx_list_t *elem;
for (elem = values; elem != NULL; elem = bctbx_list_next(elem)) {
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->send_imdn_delivered = TRUE;
policy->display_imdn_delivered = TRUE;
policy->send_imdn_displayed = TRUE;
policy->display_imdn_displayed = TRUE;
} else if (strcasecmp(value, "none") == 0) {
policy->send_is_composing = FALSE;
policy->display_is_composing = FALSE;
policy->send_imdn_delivered = FALSE;
policy->display_imdn_delivered = FALSE;
policy->send_imdn_displayed = FALSE;
policy->display_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, "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, "send_imdn_displayed") == 0) {
policy->send_imdn_displayed = TRUE;
} else if (strcasecmp(value, "disp_imdn_displayed") == 0) {
policy->display_imdn_displayed = TRUE;
}
}
if (values != default_list) {
bctbx_list_free_with_data(values, ms_free);
}
bctbx_list_free(default_list);
}
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->send_imdn_delivered == TRUE)
&& (policy->display_imdn_delivered == TRUE)
&& (policy->send_imdn_displayed == TRUE)
&& (policy->display_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->send_imdn_delivered == FALSE)
&& (policy->display_imdn_delivered == FALSE)
&& (policy->send_imdn_displayed == FALSE)
&& (policy->display_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->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->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");
}
lp_config_set_string_list(policy->lc->config, "sip", "im_notif_policy", values);
if (values != NULL) bctbx_list_free(values);
}
LinphoneImNotifPolicy * linphone_im_notif_policy_ref(LinphoneImNotifPolicy *policy) {
belle_sip_object_ref(policy);
return policy;
}
void linphone_im_notif_policy_unref(LinphoneImNotifPolicy *policy) {
belle_sip_object_unref(policy);
}
void *linphone_im_notif_policy_get_user_data(const LinphoneImNotifPolicy *policy) {
return policy->user_data;
}
void linphone_im_notif_policy_set_user_data(LinphoneImNotifPolicy *policy, void *ud) {
policy->user_data = ud;
}
void linphone_im_notif_policy_clear(LinphoneImNotifPolicy *policy) {
policy->send_is_composing = FALSE;
policy->display_is_composing = FALSE;
policy->send_imdn_delivered = FALSE;
policy->display_imdn_delivered = FALSE;
policy->send_imdn_displayed = FALSE;
policy->display_imdn_displayed = FALSE;
save_im_notif_policy_to_config(policy);
}
bool_t linphone_im_notif_policy_get_send_is_composing(const LinphoneImNotifPolicy *policy) {
return policy->send_is_composing;
}
void linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) {
policy->send_is_composing = enable;
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;
}
void linphone_im_notif_policy_set_display_is_composing(LinphoneImNotifPolicy *policy, bool_t enable) {
policy->display_is_composing = enable;
save_im_notif_policy_to_config(policy);
}
bool_t linphone_im_notif_policy_get_send_imdn_delivered(const LinphoneImNotifPolicy *policy) {
return policy->send_imdn_delivered;
}
void linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) {
policy->send_imdn_delivered = enable;
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;
}
void linphone_im_notif_policy_set_display_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable) {
policy->display_imdn_delivered = enable;
save_im_notif_policy_to_config(policy);
}
bool_t linphone_im_notif_policy_get_send_imdn_displayed(const LinphoneImNotifPolicy *policy) {
return policy->send_imdn_displayed;
}
void linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) {
policy->send_imdn_displayed = enable;
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;
}
void linphone_im_notif_policy_set_display_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable) {
policy->display_imdn_displayed = enable;
save_im_notif_policy_to_config(policy);
}
LinphoneImNotifPolicy * linphone_core_get_im_notif_policy(const LinphoneCore *lc) {
return lc->im_notif_policy;
}
void linphone_core_create_im_notif_policy(LinphoneCore *lc) {
lc->im_notif_policy = belle_sip_object_new(LinphoneImNotifPolicy);
lc->im_notif_policy->lc = lc;
load_im_notif_policy_from_config(lc->im_notif_policy);
save_im_notif_policy_to_config(lc->im_notif_policy);
}
......@@ -1044,6 +1044,8 @@ static void sip_config_read(LinphoneCore *lc) {
lc->sip_conf.save_auth_info = lp_config_get_int(lc->config, "sip", "save_auth_info", 1);
if (lp_config_get_string(lc->config, "sip", "rls_uri", NULL))
lc->default_rls_addr = linphone_address_new(lp_config_get_string(lc->config, "sip", "rls_uri", NULL));
linphone_core_create_im_notif_policy(lc);
}
static void rtp_config_read(LinphoneCore *lc) {
......@@ -5729,6 +5731,8 @@ void sip_config_uninit(LinphoneCore *lc)
ms_free(config->contact);
if (lc->default_rls_addr)
linphone_address_destroy(lc->default_rls_addr);
linphone_im_notif_policy_unref(lc->im_notif_policy);
}
void rtp_config_uninit(LinphoneCore *lc)
......
......@@ -1009,6 +1009,7 @@ struct _LinphoneCore
LinphoneVideoPolicy video_policy;
time_t network_last_check;
LinphoneNatPolicy *nat_policy;
LinphoneImNotifPolicy *im_notif_policy;
bool_t use_files;
bool_t apply_nat_settings;
......@@ -1291,6 +1292,22 @@ BELLE_SIP_DECLARE_VPTR(LinphoneNatPolicy);
void linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy);
struct _LinphoneImNotifPolicy {
belle_sip_object_t base;
void *user_data;
LinphoneCore *lc;
bool_t send_is_composing;
bool_t display_is_composing;
bool_t send_imdn_delivered;
bool_t display_imdn_delivered;
bool_t send_imdn_displayed;
bool_t display_imdn_displayed;
};
BELLE_SIP_DECLARE_VPTR(LinphoneImNotifPolicy);
void linphone_core_create_im_notif_policy(LinphoneCore *lc);
/*****************************************************************************
* XML-RPC interface *
......@@ -1542,6 +1559,7 @@ BELLE_SIP_TYPE_ID(LinphoneChatRoom),
BELLE_SIP_TYPE_ID(LinphoneContent),
BELLE_SIP_TYPE_ID(LinphoneImEncryptionEngine),
BELLE_SIP_TYPE_ID(LinphoneImEncryptionEngineCbs),
BELLE_SIP_TYPE_ID(LinphoneImNotifPolicy),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch),
BELLE_SIP_TYPE_ID(LinphoneProxyConfig),
......
......@@ -40,6 +40,7 @@ set(HEADER_FILES
event.h
friend.h
friendlist.h
im_notif_policy.h
ldapprovider.h
lpconfig.h
nat_policy.h
......
......@@ -20,6 +20,7 @@ linphone_include_HEADERS=\
event.h \
friend.h \
friendlist.h \
im_notif_policy.h \
ldapprovider.h \
lpconfig.h \
nat_policy.h \
......
......@@ -351,6 +351,7 @@ LINPHONE_PUBLIC bool_t linphone_local_player_matroska_supported(void);
#include "linphone/call_params.h"
#include "linphone/content.h"
#include "linphone/event.h"
#include "linphone/im_notif_policy.h"
#include "linphone/linphonefriend.h"
#include "linphone/nat_policy.h"
#include "linphone/xmlrpc.h"
......
/*
im_notif_policy.h
Copyright (C) 2010-2016 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef LINPHONE_IM_NOTIF_POLICY_H_
#define LINPHONE_IM_NOTIF_POLICY_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup chatroom
* @{
*/
/**
* Policy to use to send/display 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;
/**
* Acquire a reference to the LinphoneImNotifPolicy object.
* @param[in] policy LinphoneImNotifPolicy object.
* @return The same LinphoneImNotifPolicy object.
**/
LINPHONE_PUBLIC LinphoneImNotifPolicy * linphone_im_notif_policy_ref(LinphoneImNotifPolicy *policy);
/**
* Release reference to the LinphoneImNotifPolicy object.
* @param[in] policy LinphoneImNotifPolicy object.
**/
LINPHONE_PUBLIC void linphone_im_notif_policy_unref(LinphoneImNotifPolicy *policy);
/**
* Retrieve the user pointer associated with the LinphoneImNotifPolicy object.
* @param[in] policy LinphoneImNotifPolicy object.
* @return The user pointer associated with the LinphoneImNotifPolicy object.
**/
LINPHONE_PUBLIC void *linphone_im_notif_policy_get_user_data(const LinphoneImNotifPolicy *policy);
/**
* Assign a user pointer to the LinphoneImNotifPolicy object.
* @param[in] policy LinphoneImNotifPolicy object.
* @param[in] ud The user pointer to associate with the LinphoneImNotifPolicy object.
**/
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).
* @param[in] policy LinphoneImNotifPolicy object.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_clear(LinphoneImNotifPolicy *policy);
/**
* Tell whether is_composing notifications are being sent.
* @param[in] policy LinphoneImNotifPolicy object
* @return Boolean value telling whether is_composing notifications are being sent.
*/
LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_send_is_composing(const LinphoneImNotifPolicy *policy);
/**
* Enable is_composing notifications sending.
* @param[in] policy LinphoneImNotifPolicy object
* @param[in] enable Boolean value telling whether to send is_composing notifications.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_set_send_is_composing(LinphoneImNotifPolicy *policy, bool_t enable);
/**
* Tell whether is_composing notifications are being displayed.
* @param[in] policy LinphoneImNotifPolicy object
* @return Boolean value telling whether is_composing notifications are being displayed.
*/
LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_display_is_composing(const LinphoneImNotifPolicy *policy);
/**
* Enable is_composing notifications display.
* @param[in] policy LinphoneImNotifPolicy object
* @param[in] enable Boolean value telling whether to display is_composing notifications.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_set_display_is_composing(LinphoneImNotifPolicy *policy, bool_t enable);
/**
* Tell whether imdn delivered notifications are being sent.
* @param[in] policy LinphoneImNotifPolicy object
* @return Boolean value telling whether imdn delivered notifications are being sent.
*/
LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_send_imdn_delivered(const LinphoneImNotifPolicy *policy);
/**
* Enable imdn delivered notifications sending.
* @param[in] policy LinphoneImNotifPolicy object
* @param[in] enable Boolean value telling whether to send imdn delivered notifications.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_set_send_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable);
/**
* Tell whether imdn delivered notifications are being displayed.
* @param[in] policy LinphoneImNotifPolicy object
* @return Boolean value telling whether imdn delivered notifications are being displayed.
*/
LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_display_imdn_delivered(const LinphoneImNotifPolicy *policy);
/**
* Enable imdn delivered notifications display.
* @param[in] policy LinphoneImNotifPolicy object
* @param[in] enable Boolean value telling whether to display imdn delivered notifications.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_set_display_imdn_delivered(LinphoneImNotifPolicy *policy, bool_t enable);
/**
* Tell whether imdn displayed notifications are being sent.
* @param[in] policy LinphoneImNotifPolicy object
* @return Boolean value telling whether imdn displayed notifications are being sent.
*/
LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_send_imdn_displayed(const LinphoneImNotifPolicy *policy);
/**
* Enable imdn displayed notifications sending.
* @param[in] policy LinphoneImNotifPolicy object
* @param[in] enable Boolean value telling whether to send imdn displayed notifications.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_set_send_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable);
/**
* Tell whether imdn displayed notifications are being displayed.
* @param[in] policy LinphoneImNotifPolicy object
* @return Boolean value telling whether imdn displayed notifications are being displayed.
*/
LINPHONE_PUBLIC bool_t linphone_im_notif_policy_get_display_imdn_displayed(const LinphoneImNotifPolicy *policy);
/**
* Enable imdn displayed notifications display.
* @param[in] policy LinphoneImNotifPolicy object
* @param[in] enable Boolean value telling whether to display imdn displayed notifications.
*/
LINPHONE_PUBLIC void linphone_im_notif_policy_set_display_imdn_displayed(LinphoneImNotifPolicy *policy, bool_t enable);
/**
* Get the LinphoneImNotifPolicy object controlling the instant messaging notifications.
* @param[in] lc LinphoneCore object
* @return A LinphoneImNotifPolicy object.
*/
LINPHONE_PUBLIC LinphoneImNotifPolicy * linphone_core_get_im_notif_policy(const LinphoneCore *lc);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* LINPHONE_IM_NOTIF_POLICY_H_ */
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