forked from mirrors/linphone-iphone
Added method to import friends from buffer instead of file
This commit is contained in:
parent
44ffb32dea
commit
5fe2c68b44
5 changed files with 57 additions and 0 deletions
|
|
@ -942,6 +942,36 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *
|
|||
return count;
|
||||
}
|
||||
|
||||
int linphone_core_import_friends_from_vcard4_buffer(LinphoneCore *lc, const char *vcard_buffer) {
|
||||
MSList *vcards = linphone_vcard_list_from_vcard4_buffer(vcard_buffer);
|
||||
int count = 0;
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
#endif
|
||||
if (!vcards) {
|
||||
ms_error("Failed to parse the buffer");
|
||||
return -1;
|
||||
}
|
||||
while (vcards != NULL && vcards->data != NULL) {
|
||||
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
|
||||
if (lf) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(linphone_core_get_default_friend_list(lc), lf, TRUE)) {
|
||||
count++;
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
} else {
|
||||
linphone_vcard_free(vcard);
|
||||
}
|
||||
vcards = ms_list_next(vcards);
|
||||
}
|
||||
#ifndef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_write_friends_config(lc);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
void linphone_core_export_friends_as_vcard4_file(LinphoneCore *lc, const char *vcard_file) {
|
||||
FILE *file = NULL;
|
||||
const MSList *friends = linphone_core_get_friend_list(lc);
|
||||
|
|
|
|||
|
|
@ -1955,6 +1955,13 @@ extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_importFriendsFromVCardFi
|
|||
return count;
|
||||
}
|
||||
|
||||
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_importFriendsFromVCardBuffer(JNIEnv* env, jobject thiz, jlong lc, jstring jbuffer) {
|
||||
const char* buffer = env->GetStringUTFChars(jbuffer, NULL);
|
||||
int count = linphone_core_import_friends_from_vcard4_buffer((LinphoneCore*)lc, buffer);
|
||||
env->ReleaseStringUTFChars(jbuffer, buffer);
|
||||
return count;
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_exportFriendsToVCardFile(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) {
|
||||
const char* path = env->GetStringUTFChars(jpath, NULL);
|
||||
linphone_core_export_friends_as_vcard4_file((LinphoneCore*)lc, path);
|
||||
|
|
|
|||
|
|
@ -464,6 +464,14 @@ LINPHONE_PUBLIC LinphoneFriend *linphone_friend_new_from_vcard(LinphoneVCard *vc
|
|||
*/
|
||||
LINPHONE_PUBLIC int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *vcard_file);
|
||||
|
||||
/**
|
||||
* Creates and adds LinphoneFriend objects to LinphoneCore from a buffer that contains the vCard(s) to parse
|
||||
* @param[in] lc the LinphoneCore object
|
||||
* @param[in] vcard_buffer the buffer that contains the vCard(s) to parse
|
||||
* @return the amount of linphone friends created
|
||||
*/
|
||||
LINPHONE_PUBLIC int linphone_core_import_friends_from_vcard4_buffer(LinphoneCore *lc, const char *vcard_buffer);
|
||||
|
||||
/**
|
||||
* Creates and export LinphoneFriend objects from LinphoneCore to a file using vCard 4 format
|
||||
* @param[in] lc the LinphoneCore object
|
||||
|
|
|
|||
|
|
@ -2270,6 +2270,12 @@ public interface LinphoneCore {
|
|||
**/
|
||||
public int importFriendsFromVCardFile(String file);
|
||||
|
||||
/**
|
||||
* Imports LinphoneFriends from a vCard 4 buffer
|
||||
* @return the number of friend imported
|
||||
**/
|
||||
public int importFriendsFromVCardBuffer(String buffer);
|
||||
|
||||
/**
|
||||
* Exports LinphoneFriends to a vCard 4 file
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -1627,6 +1627,12 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
return importFriendsFromVCardFile(nativePtr, file);
|
||||
}
|
||||
|
||||
private native int importFriendsFromVCardBuffer(long nativePtr, String buffer);
|
||||
@Override
|
||||
public int importFriendsFromVCardBuffer(String buffer) {
|
||||
return importFriendsFromVCardBuffer(nativePtr, buffer);
|
||||
}
|
||||
|
||||
private native void exportFriendsToVCardFile(long nativePtr, String file);
|
||||
@Override
|
||||
public void exportFriendsToVCardFile(String file) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue