diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index 2f2d59712..1acb41227 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -37,6 +37,7 @@ set(LINPHONE_HEADER_FILES call_params.h content.h event.h + friendlist.h linphonecore.h linphonecore_utils.h linphonefriend.h @@ -82,6 +83,7 @@ set(LINPHONE_SOURCE_FILES_C enum.h event.c friend.c + friendlist.c info.c ldap/ldapprovider.c lime.c diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 02c7f442d..6f777c228 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -31,6 +31,7 @@ linphone_include_HEADERS=\ call_params.h \ content.h \ event.h \ + friendlist.h \ linphonecore.h \ linphonecore_utils.h \ linphonefriend.h \ @@ -63,6 +64,7 @@ liblinphone_la_SOURCES=\ enum.c enum.h \ event.c \ friend.c \ + friendlist.c \ info.c \ ldap/ldapprovider.c ldap/ldapprovider.h \ linphonecall.c \ diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c new file mode 100644 index 000000000..b221717fb --- /dev/null +++ b/coreapi/friendlist.c @@ -0,0 +1,111 @@ +/* +linphone +Copyright (C) 2010-2015 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "linphonecore.h" +#include "private.h" + + + +static void linphone_friend_list_destroy(LinphoneFriendList *list) { + if (list->display_name != NULL) ms_free(list->display_name); + if (list->rls_uri != NULL) ms_free(list->rls_uri); +} + +BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneFriendList); + +BELLE_SIP_INSTANCIATE_VPTR(LinphoneFriendList, belle_sip_object_t, + (belle_sip_object_destroy_t)linphone_friend_list_destroy, + NULL, // clone + NULL, // marshal + TRUE +); + + +LinphoneFriendList * linphone_friend_list_new(void) { + LinphoneFriendList *list = belle_sip_object_new(LinphoneFriendList); + belle_sip_object_ref(list); + return list; +} + +LinphoneFriendList * linphone_friend_list_ref(LinphoneFriendList *list) { + belle_sip_object_ref(list); + return list; +} + +void linphone_friend_list_unref(LinphoneFriendList *list) { + belle_sip_object_unref(list); +} + +void * linphone_friend_list_get_user_data(const LinphoneFriendList *list) { + return list->user_data; +} + +void linphone_friend_list_set_user_data(LinphoneFriendList *list, void *ud) { + list->user_data = ud; +} + +const char * linphone_friend_list_get_display_name(const LinphoneFriendList *list) { + return list->display_name; +} + +void linphone_friend_list_set_display_name(LinphoneFriendList *list, const char *display_name) { + if (list->display_name != NULL) { + ms_free(list->display_name); + list->display_name = NULL; + } + if (display_name != NULL) { + list->display_name = ms_strdup(display_name); + } +} + +const char * linphone_friend_list_get_rls_uri(const LinphoneFriendList *list) { + return list->rls_uri; +} + +void linphone_friend_list_set_rls_uri(LinphoneFriendList *list, const char *rls_uri) { + if (list->rls_uri != NULL) { + ms_free(list->rls_uri); + list->rls_uri = NULL; + } + if (rls_uri != NULL) { + list->rls_uri = ms_strdup(rls_uri); + } +} + +LinphoneFriendListStatus linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *friend) { + if ((friend->lc != NULL) || (friend->uri == NULL)) return LinphoneFriendListInvalidFriend; + if (ms_list_find(list->friends, friend) != NULL) { + char *tmp = NULL; + const LinphoneAddress *addr = linphone_friend_get_address(friend); + if (addr) tmp = linphone_address_as_string(addr); + ms_warning("Friend %s already in list [%s], ignored.", tmp ? tmp : "unknown", list->display_name); + if (tmp) ms_free(tmp); + } else { + list->friends = ms_list_append(list->friends, linphone_friend_ref(friend)); + } + return LinphoneFriendListOK; +} + +LinphoneFriendListStatus linphone_friend_list_remove_friend(LinphoneFriendList *list, LinphoneFriend *friend) { + MSList *el = ms_list_find(list->friends, friend); + if (el == NULL) return LinphoneFriendListNonExistentFriend; + linphone_friend_unref((LinphoneFriend *)el->data); + list->friends = ms_list_remove_link(list->friends, el); + return LinphoneFriendListOK; +} diff --git a/coreapi/friendlist.h b/coreapi/friendlist.h new file mode 100644 index 000000000..1d01bce39 --- /dev/null +++ b/coreapi/friendlist.h @@ -0,0 +1,136 @@ +/* +friendlist.h +Copyright (C) 2010-2015 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef LINPHONE_FRIENDLIST_H_ +#define LINPHONE_FRIENDLIST_H_ + + +#include "linphonefriend.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup buddy_list + * @{ + */ + +/** +* Enum describing the status of a LinphoneFriendList operation. +**/ +typedef enum _LinphoneFriendListStatus { + LinphoneFriendListOK, + LinphoneFriendListNonExistentFriend, + LinphoneFriendListInvalidFriend +} LinphoneFriendListStatus; + +/** + * The LinphoneFriendList object representing a list of friends. +**/ +typedef struct _LinphoneFriendList LinphoneFriendList; + +/** + * Create a new empty LinphoneFriendList object. + * @return A new LinphoneFriendList object. + */ +LINPHONE_PUBLIC LinphoneFriendList * linphone_friend_list_new(void); + +/** + * Acquire a reference to the friend list. + * @param[in] list LinphoneFriendList object. + * @return The same LinphoneFriendList object. +**/ +LINPHONE_PUBLIC LinphoneFriendList * linphone_friend_list_ref(LinphoneFriendList *list); + +/** + * Release reference to the friend list. + * @param[in] list LinphoneFriendList object. +**/ +LINPHONE_PUBLIC void linphone_friend_list_unref(LinphoneFriendList *list); + +/** + * Retrieve the user pointer associated with the friend list. + * @param[in] list LinphoneFriendList object. + * @return The user pointer associated with the friend list. +**/ +LINPHONE_PUBLIC void * linphone_friend_list_get_user_data(const LinphoneFriendList *list); + +/** + * Assign a user pointer to the friend list. + * @param[in] list LinphoneFriendList object. + * @param[in] ud The user pointer to associate with the friend list. +**/ +LINPHONE_PUBLIC void linphone_friend_list_set_user_data(LinphoneFriendList *list, void *ud); + +/** + * Get the display name of the friend list. + * @param[in] list LinphoneFriendList object. + * @return The display name of the friend list. +**/ +LINPHONE_PUBLIC const char * linphone_friend_list_get_display_name(const LinphoneFriendList *list); + +/** + * Set the display name of the friend list. + * @param[in] list LinphoneFriendList object. + * @param[in] display_name The new display name of the friend list. +**/ +LINPHONE_PUBLIC void linphone_friend_list_set_display_name(LinphoneFriendList *list, const char *display_name); + +/** + * Get the RLS (Resource List Server) URI associated with the friend list to subscribe to these friends presence. + * @param[in] list LinphoneFriendList object. + * @return The RLS URI associated with the friend list. +**/ +LINPHONE_PUBLIC const char * linphone_friend_list_get_rls_uri(const LinphoneFriendList *list); + +/** + * Set the RLS (Resource List Server) URI associated with the friend list to subscribe to these friends presence. + * @param[in] list LinphoneFriendList object. + * @param[in] rls_uri The RLS URI to associate with the friend list. +**/ +LINPHONE_PUBLIC void linphone_friend_list_set_rls_uri(LinphoneFriendList *list, const char *rls_uri); + +/** + * Add a friend to a friend list. + * @param[in] list LinphoneFriendList object. + * @param[in] friend LinphoneFriend object to add to the friend list. + * @return LinphoneFriendListOK if successfully added, LinphoneFriendListInvalidFriend if the friend is not valid. +**/ +LINPHONE_PUBLIC LinphoneFriendListStatus linphone_friend_list_add_friend(LinphoneFriendList *list, LinphoneFriend *friend); + +/** + * Remove a friend from a friend list. + * @param[in] list LinphoneFriendList object. + * @param[in] friend LinphoneFriend object to remove from the friend list. + * @return LinphoneFriendListOK if removed successfully, LinphoneFriendListNonExistentFriend if the friend is not in the list. +**/ +LINPHONE_PUBLIC LinphoneFriendListStatus linphone_friend_list_remove_friend(LinphoneFriendList *list, LinphoneFriend *friend); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* LINPHONE_FRIENDLIST_H_ */ diff --git a/coreapi/private.h b/coreapi/private.h index 84d26357e..078ed768b 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -30,6 +30,7 @@ extern "C" { #endif #include "linphonecore.h" #include "linphonefriend.h" +#include "friendlist.h" #include "linphone_tunnel.h" #include "linphonecore_utils.h" #include "sal/sal.h" @@ -648,6 +649,17 @@ struct _LinphoneFriend{ BELLE_SIP_DECLARE_VPTR(LinphoneFriend); +struct _LinphoneFriendList { + belle_sip_object_t base; + void *user_data; + char *display_name; + char *rls_uri; + MSList *friends; +}; + +BELLE_SIP_DECLARE_VPTR(LinphoneFriendList); + + typedef struct sip_config { char *contact; @@ -1278,6 +1290,7 @@ BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider), BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch), BELLE_SIP_TYPE_ID(LinphoneProxyConfig), BELLE_SIP_TYPE_ID(LinphoneFriend), +BELLE_SIP_TYPE_ID(LinphoneFriendList), BELLE_SIP_TYPE_ID(LinphoneXmlRpcRequest), BELLE_SIP_TYPE_ID(LinphoneXmlRpcRequestCbs), BELLE_SIP_TYPE_ID(LinphoneXmlRpcSession),