From 528fc0a026beb201ae71787a4e402daf98cb59f5 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 10 Dec 2015 16:08:46 +0100 Subject: [PATCH] Started vcard interface for belcard --- configure.ac | 36 +++++++++++++++++++++++++++++++++++- coreapi/Makefile.am | 5 ++++- coreapi/friend.c | 13 +++++++++++++ coreapi/linphonecore.h | 2 -- coreapi/linphonefriend.h | 11 +++++++++++ coreapi/private.h | 1 + coreapi/vcard.cc | 27 +++++++++++++++++++++++++++ coreapi/vcard.h | 21 +++++++++++++++++++++ 8 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 coreapi/vcard.cc create mode 100644 coreapi/vcard.h diff --git a/configure.ac b/configure.ac index eb9f974cc..7f2b95aad 100644 --- a/configure.ac +++ b/configure.ac @@ -877,6 +877,39 @@ if test x$enable_tunnel = xtrue; then AC_DEFINE(TUNNEL_ENABLED,1,[Tells tunnel extension is built-in]) fi +AC_ARG_ENABLE(vcard, + [AS_HELP_STRING([--enable-vcard=[yes/no]], [Turn on compilation of vcard (default=auto)])], + [case "${enableval}" in + yes) enable_vcard=true ;; + no) enable_vcard=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-vcard) ;; + esac], + [enable_vcard=auto] +) + +if test x$enable_vcard != xfalse; then + PKG_CHECK_MODULES(BELCARD, belcard, [found_vcard=yes],[found_vcard=no]) + if test "$found_vcard" = "no"; then + dnl Check the lib presence in case the PKG-CONFIG version is not found + AC_LANG_CPLUSPLUS + AC_CHECK_LIB(belcard, main, [BELCARD_LIBS+=" -lbelr -lbelcard"; found_vcard=yes], [foo=bar]) + AC_LANG_C + fi + if test "$found_vcard" = "yes"; then + enable_vcard=true + else + if test x$enable_vcard = xtrue; then + AC_MSG_ERROR([belcard, required for vcard support, not found]) + fi + enable_vcard=false + fi + + AC_SUBST(BELCARD_CFLAGS) + AC_SUBST(BELCARD_LIBS) +fi + +AM_CONDITIONAL(BUILD_VCARD, test x$enable_vcard = xtrue) + AC_ARG_ENABLE(msg-storage, [AS_HELP_STRING([--enable-msg-storage=[yes/no]], [Turn on compilation of message storage (default=auto)])], [case "${enableval}" in @@ -1105,7 +1138,8 @@ printf "* %-30s %s\n" "Account assistant" $build_wizard printf "* %-30s %s\n" "Console interface" $console_ui printf "* %-30s %s\n" "Tools" $build_tools printf "* %-30s %s\n" "Message storage" $enable_msg_storage -printf "* %-30s %s\n" "Call logs storage" $enable_call_logs_storage +printf "* %-30s %s\n" "Call logs storage" $enable_call_logs_storage +printf "* %-30s %s\n" "VCard support" $enable_vcard printf "* %-30s %s\n" "IM encryption" $lime printf "* %-30s %s\n" "uPnP support" $build_upnp printf "* %-30s %s\n" "LDAP support" $enable_ldap diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 02c7f442d..6d9a1c179 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -114,7 +114,8 @@ else liblinphone_la_SOURCES+=linphone_tunnel_stubs.c linphone_tunnel.h endif - +liblinphone_la_SOURCES+=vcard.cc vcard.h +liblinphone_la_CXXFLAGS=-std=c++11 liblinphone_la_LDFLAGS= -version-info $(LIBLINPHONE_SO_VERSION) -no-undefined @@ -142,6 +143,7 @@ liblinphone_la_LIBADD= \ $(LIBXML2_LIBS) \ $(LDAP_LIBS) \ $(SASL_LIBS) \ + $(BELCARD_LIBS) \ $(ZLIB_LIBS) @@ -164,6 +166,7 @@ COMMON_CFLAGS=\ $(LIBXML2_CFLAGS) \ $(LDAP_CFLAGS) \ $(SASL_CFLAGS) \ + $(BELCARD_CFLAGS) \ $(ZLIB_CFLAGS) if BUILD_WIZARD diff --git a/coreapi/friend.c b/coreapi/friend.c index 487cfd2a4..a3334b703 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -132,6 +132,7 @@ LinphoneFriend * linphone_friend_new(){ obj->pol=LinphoneSPAccept; obj->presence=NULL; obj->subscribe=TRUE; + obj->vcard = NULL; return obj; } @@ -290,6 +291,7 @@ static void _linphone_friend_destroy(LinphoneFriend *lf){ if (lf->presence != NULL) linphone_presence_model_unref(lf->presence); if (lf->uri!=NULL) linphone_address_destroy(lf->uri); if (lf->info!=NULL) buddy_info_free(lf->info); + if (lf->vcard != NULL) linphone_vcard_free(lf->vcard); } static belle_sip_error_code _linphone_friend_marshall(belle_sip_object_t *obj, char* buff, size_t buff_size, size_t *offset) { @@ -726,6 +728,17 @@ void linphone_friend_destroy(LinphoneFriend *lf) { linphone_friend_unref(lf); } +LinphoneVCard* linphone_friend_get_vcard(LinphoneFriend *fr) { + return fr->vcard; +} + +void linphone_friend_set_vcard(LinphoneFriend *fr, LinphoneVCard *vcard) { + if (fr->vcard) { + linphone_vcard_free(fr->vcard); + } + fr->vcard = vcard; +} + BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneFriend); BELLE_SIP_INSTANCIATE_VPTR(LinphoneFriend, belle_sip_object_t, diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 6d6444f03..d31a23204 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -4232,7 +4232,6 @@ LINPHONE_PUBLIC const char* linphone_transport_to_string(LinphoneTransportType t **/ LINPHONE_PUBLIC LinphoneTransportType linphone_transport_parse(const char* transport); - /** * @ingroup media_parameters * Get default call parameters reflecting current linphone core configuration @@ -4242,7 +4241,6 @@ LINPHONE_PUBLIC LinphoneTransportType linphone_transport_parse(const char* trans */ LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneCallParams *linphone_core_create_default_call_parameters(LinphoneCore *lc); - #ifdef __cplusplus } #endif diff --git a/coreapi/linphonefriend.h b/coreapi/linphonefriend.h index 1a6535fed..2276c98bb 100644 --- a/coreapi/linphonefriend.h +++ b/coreapi/linphonefriend.h @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define LINPHONEFRIEND_H_ #include "linphonepresence.h" +#include "vcard.h" #ifdef __cplusplus extern "C" { @@ -411,6 +412,16 @@ LINPHONE_PUBLIC void linphone_friend_unref(LinphoneFriend *lf); * Returns the LinphoneCore object managing this friend, if any. */ LINPHONE_PUBLIC LinphoneCore *linphone_friend_get_core(const LinphoneFriend *fr); + +/** + * Returns the VCard object associated to this friend, if any + */ +LINPHONE_PUBLIC LinphoneVCard* linphone_friend_get_vcard(LinphoneFriend *fr); + +/** + * Returns the VCard object associated to this friend, if any + */ +LINPHONE_PUBLIC void linphone_friend_set_vcard(LinphoneFriend *fr, LinphoneVCard *vcard); /** * @} */ diff --git a/coreapi/private.h b/coreapi/private.h index 797b19708..2190af8e3 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -653,6 +653,7 @@ struct _LinphoneFriend{ bool_t inc_subscribe_pending; bool_t commit; bool_t initial_subscribes_sent; /*used to know if initial subscribe message was sent or not*/ + LinphoneVCard *vcard; }; BELLE_SIP_DECLARE_VPTR(LinphoneFriend); diff --git a/coreapi/vcard.cc b/coreapi/vcard.cc new file mode 100644 index 000000000..88d77178f --- /dev/null +++ b/coreapi/vcard.cc @@ -0,0 +1,27 @@ +#include "vcard.h" +#include "belcard/belcard.hpp" + +struct _LinphoneVCard { + shared_ptr belcard; +}; + +extern "C" LinphoneVCard* linphone_vcard_new(void) { + LinphoneVCard* vcard = (LinphoneVCard*) malloc(sizeof(LinphoneVCard)); + vcard->belcard = belcard::BelCardGeneric::create(); + return vcard; +} + +extern "C" void linphone_vcard_free(LinphoneVCard *vcard) { + vcard->belcard.reset(); + free(vcard); +} + +extern "C" void linphone_vcard_set_full_name(LinphoneVCard *vcard, const char *name) { + shared_ptr fn = belcard::BelCardGeneric::create(); + fn->setValue(name); + vcard->belcard->setFullName(fn); +} + +extern "C" const char* linphone_vcard_get_full_name(LinphoneVCard *vcard) { + return vcard->belcard->getFullName() ? vcard->belcard->getFullName()->getValue().c_str() : NULL; +} \ No newline at end of file diff --git a/coreapi/vcard.h b/coreapi/vcard.h new file mode 100644 index 000000000..93bb17d30 --- /dev/null +++ b/coreapi/vcard.h @@ -0,0 +1,21 @@ +#ifndef LINPHONE_VCARD_H +#define LINPHONE_VCARD_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct _LinphoneVCard LinphoneVCard; + +LinphoneVCard* linphone_vcard_new(void); +void linphone_vcard_free(LinphoneVCard *vcard); + +void linphone_vcard_set_full_name(LinphoneVCard *vcard, const char *name); +const char* linphone_vcard_get_full_name(LinphoneVCard *vcard); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file