How to check if vCard/CardDAV support is enabled

  • VCARD_ENABLED is defined
  • the VCard suite of liblinphone tester is OK

vCards

Linphone library will edit the FN and IMPP fields when using int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr) and int linphone_friend_set_name(LinphoneFriend *lf, const char *name) if the LinphoneFriend has a vCard attached.

On Android, the vCard update for SIP address and display name is done using LinphoneFriend.setAddress(LinphoneAddress addr) and LinphoneFriend.setName(String name)

Import / Export of Friends from/to vCards

How to import LinphoneFriends from a vCard 4 file

Call the int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *list, const char *vcard_file) or int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *list, const char *vcard_buffer) methods. If the operation succeeds, it returns the number of LinphoneFriend created.

On Android, use LinphoneFriendList.importFriendsFromVCardFile(String path) or LinphoneFriendList.importFriendsFromVCardBuffer(String buffer) methods.

How to export LinphoneFriends to a vCard 4 file

Call the void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list, const char *vcard_file) method. If the file already exists, it is overidden. If there is no LinphoneFriend (with a vCard attached or none at all), the file will be empty.

On Android, use LinphoneFriendList.exportFriendsToVCardFile(String path) method.

Supported RFCs

Currently the following RFCs regarding vCards and CardDAV are supported:

vCards database storage

First, linphone library has to be compiled with SQLite.

Then you can enable the friend storage using void linphone_core_set_friends_database_path(LinphoneCore *lc, const char *path)

On Android, use void LinphoneCore.setFriendsDatabasePath(String path).

Previous friends (stored in linphonerc) will be moved to the database storage on first call, and LinphoneFriend objects remain available through the same APIs as before.

CardDAV

When vCard support is enabled, CardDAV synchronization is also available. 

A few requirements for the CardDAV server are:

  • Authentication (if any) must be Digest (and not Basic)
  • It must support vCards version 4

So far, the following CardDAV servers have been successfully tested:

  • sabre/dav 3.0.5 and 3.0.6
  • sabre/dav 3.1.0

Configuring a CardDAV addressbook synchronization

CardDAV sync is enabled on a LinphoneFriendList object. This way you can have CardDAV sync with multiple servers/addressbooks easily.

First of all, create a LinphoneFriendList that will contain the local LinphoneFriends:

LinphoneFriendList *lfl = linphone_core_create_friend_list(lc);

It is recommended to listen for LinphoneFriendList events:

LinphoneFriendListCbs *cbs = linphone_friend_list_get_callbacks(lfl);

linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created);

linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted);

linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated);

linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed);

Now add the LinphoneFriendList in the LinphoneCore:

linphone_core_add_friend_list(lc, lfl);

Then, configure the CardDAV remote address:

linphone_friend_list_set_uri(lfl, "http://192.168.0.230/sabredav/addressbookserver.php/addressbooks/sylvain/default");

If authentication is needed, add an auth info:

[auth_info_0]
domain=192.168.0.230
username=sylvain
ha1=<ha1> or password=<password>
realm=SabreDAV

Finally, do a synchronization:

linphone_friend_list_synchronize_friends_from_server(lfl);

Note that when a change is detected on a LinphoneFriend between edit() and done(), the LinphoneFriend will be added to a "dirty" list. Every second (in the iterate), if one or more LinphoneFriend are found in the dirty list, they are pushed to the CardDAV server automatically. Also when a LinphoneFriend is added to a LinphoneFriendList, it is automatically added to the dirty list.

On Android, there is a CardDAV tutorial available in src/org/linphone/tutorials/TutorialCardDavSync.java