From 04b6f1386dba279087f1ea54e979ce728e38f1ec Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Thu, 14 Sep 2017 11:40:30 +0200 Subject: [PATCH] Adding and implementing find_contacts_by_char --- coreapi/linphonecore.c | 29 +++++++++++++++++++ coreapi/linphonecore_jni.cc | 24 +++++++++++++++ include/linphone/core.h | 9 ++++++ .../org/linphone/core/LinphoneCore.java | 8 +++++ .../org/linphone/core/LinphoneCoreImpl.java | 6 +++- 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index ad1331b12..8e8ab2df0 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2587,6 +2587,35 @@ void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list) { linphone_core_notify_friend_list_created(lc, list); } +const bctbx_list_t * linphone_core_find_contacts_by_char(LinphoneCore *core, const char *filter, bool_t sip_only) { + // Get sipuri from filter if possible + bctbx_list_t *list, *_list = NULL; + LinphoneAddress *addr = linphone_core_interpret_url(core, (sip_only) ? filter : ""); + bctbx_list_t* listFriendsList = (bctbx_list_t*)linphone_core_get_friends_lists(core); + bctbx_list_t* listFriend = (listFriendsList != NULL) + ? (bctbx_list_t*)linphone_friend_list_get_friends((LinphoneFriendList*)listFriendsList->data) : NULL; + + if (addr != NULL) + list = bctbx_list_new(addr); + + while (listFriend != NULL && listFriend->data != NULL) { + LinphoneAddress *buff = (LinphoneAddress*)linphone_friend_get_address((LinphoneFriend*)listFriend->data); + if (buff != NULL) { + bctbx_list_t *new_list = bctbx_list_new(buff); + if (list == NULL) { + _list = list = new_list; + } else { + if (_list == NULL) _list = list; + _list->next = new_list; + _list = _list->next; + } + } + listFriend = listFriend->next; + } + + return list; +} + void linphone_core_enable_audio_adaptive_jittcomp(LinphoneCore* lc, bool_t val) { lc->rtp_conf.audio_adaptive_jitt_comp_enabled = val; } diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 8a3687f07..49450e0a8 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2436,6 +2436,30 @@ extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getFriendLists(J return jFriends; } +extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_findContactsByChar(JNIEnv* env + ,jobject thiz + ,jlong lc + ,jstring jfilter + ,jboolean jsiponly) { + const char* filter = GetStringUTFChars(env, jfilter); + const bctbx_list_t* contacts = linphone_core_find_contacts_by_char((LinphoneCore*)lc, filter, jsiponly); + size_t contactsSize = bctbx_list_size(contacts); + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data((LinphoneCore *)lc); + jobjectArray jContacts = env->NewObjectArray(contactsSize, ljb->addressClass, NULL); + + for (size_t i = 0; i < contactsSize; i++) { + LinphoneAddress *addr = (LinphoneAddress*)contacts->data; + jobject jcontact = env->NewObject(ljb->addressClass, ljb->addressCtrId, (jlong)addr); + if(jcontact != NULL){ + env->SetObjectArrayElement(jContacts, i, jcontact); + } + contacts = contacts->next; + } + ReleaseStringUTFChars(env, jfilter, filter); + + return jContacts; +} + extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env ,jobject thiz ,jlong lc diff --git a/include/linphone/core.h b/include/linphone/core.h index 68dee15fc..336d1d7c4 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -5250,6 +5250,15 @@ LINPHONE_PUBLIC const bctbx_list_t * linphone_core_get_friends_lists(const Linph */ LINPHONE_PUBLIC LinphoneFriendList * linphone_core_get_default_friend_list(const LinphoneCore *lc); +/** + * Retrieves a list of LinphoneAddress sort and filter + * @param[in] lc LinphoneCore object + * @param[in] filter Chars used for the filter* + * @param[in] sip_only Only sip address or not + * @return \bctbx_list{LinphoneAddress} a list of filtered LinphoneAddress + the LinphoneAddress created with the filter +**/ +LINPHONE_PUBLIC const bctbx_list_t * linphone_core_find_contacts_by_char(LinphoneCore *core, const char *filter, bool_t sip_only); + /** * Create a LinphonePresenceActivity with the given type and description. * @param[in] lc #LinphoneCore object. diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index db64a5c82..c7abd5303 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -1100,6 +1100,14 @@ public interface LinphoneCore { */ LinphoneFriendList[] getFriendLists(); + /** + * Get filtered list by filter + * @param filter + * @param sipOnly get only sip address + * @return LinphoneAddress list + */ + LinphoneAddress[] findContactsByChar(String filter, boolean sipOnly); + /** * Set my presence status * @param minutes_away how long in away diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index cd076e837..b300a7fc0 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -195,7 +195,6 @@ class LinphoneCoreImpl implements LinphoneCore { private native Object createFriend(long nativePtr); private native Object createFriendWithAddress(long nativePtr, String address); private native int getIncomingTimeout(long nativePtr); - LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig, File factoryConfig, Object userdata, Object context) throws IOException { mListener = listener; String user = userConfig == null ? null : userConfig.getCanonicalPath(); @@ -495,6 +494,11 @@ class LinphoneCoreImpl implements LinphoneCore { return getFriendLists(nativePtr); } + private native LinphoneAddress[] findContactsByChar(long nativePtr, String filter, boolean sipOnly); + public synchronized LinphoneAddress[] findContactsByChar(String filter, boolean sipOnly) { + return findContactsByChar(nativePtr, filter, sipOnly); + } + @SuppressWarnings("deprecation") public synchronized void setPresenceInfo(int minutes_away, String alternative_contact, OnlineStatus status) { setPresenceInfo(nativePtr, minutes_away, alternative_contact, status.mValue);