Site map  

Linphone

Written in vi editor

Some stuff to make the use of Linphone a bit easier.

Contacts sortorder patch

A small patch to the file 'gtk/friendlist.c' by Simon IJskes which sets the Linphone (3.6.1) contact list sort order to display_name (name instead of number).
I also build Amd64 Debian Stretch/9 package files. These where never tested though!

Export contacts

The script below extracts a phonebook from ~/.linphonerc. Output is stdout, so you need to redirect to a file. E.G.: phonebook.txt

extr-lin-pb.sh;

#!/bin/bash

export LC_ALL=C.UTF-8

grep -A4 "friend_" ~/.linphonerc | \
	grep url | \
	sed -e 's/url=\"//g' | \
	sed -e 's/" <sip:/\t/g' | \
	sed -E 's/@.+>//g' | \
	sort

The output is: Name<Tab>Number<Lf>.

Import contacts

Newer versions of Linphone use Sqlite to store data, including the contacts list / address book. The script below imports to ~/.local/share/linphone/friends.db

gen-linphonebook.sh;

#!/bin/bash

IFS=$'\t\n'

while read NAME NUMBER
do
	echo "INSERT INTO friends (friend_list_id, sip_uri, subscribe_policy, send_subscribe, ref_key, vCard, vCard_etag, vCard_url, presence_received)
VALUES"
	echo -e "\t(1,\047sip:${NUMBER}@Domain\047,1,0,NULL,replace(replace(\047BEGIN:VCARD\\\r\\\nVERSION:4.0\\\r\\\nFN:${NAME}\\\r\\\nIMPP:sip:${NUMBER}@Domain\\\r\\\nEND:VCARD\\\r\\\n\047,\047\\\r\047,char(13)),\047\\\n\047,char(10)),NULL,NULL,0);"
done < "phonebook.txt"

IFS=$' \t\n'

Replace 'Domain' by the correct domain.

The script

Default, the bash Internal Field Separators are space, tab and newline. "IFS=$'\t\n'" sets this to tab and newline. This way you can use spaces in fields.
'echo -e' makes bash interpret escape sequences; '\t' becomes tab, '\047' single quote (octal 047 is decimal 39).
'\\\r' becomes '\r', '\\\n' becomes '\n'.
There are two sqlite3 replace statements; one turns '\r' into an actual carriage return (ASCII 13), the other turns '\n' into a linefeed (ASCII 10). So the VCARD looks like;

BEGIN:VCARD
VERSION:4.0
FN:${NAME}
IMPP:sip:${NUMBER}@Domain
END:VCARD

E.G.:

BEGIN:VCARD
VERSION:4.0
FN:John Doe
IMPP:sip:1234@example.org
END:VCARD

You could modify the script to contain more fields in the vcard. Below the fields supported by Linphone;

BEGIN:VCARD
VERSION:4.0
FN:
IMPP:
ROLE:
EMAIL:
URL:
END:VCARD

More here.

Use

Make sure you got a properly functioning '~/.linphonerc'.
Start the GUI version of Linphone. Add one contact. This will initialise the contacts database. Stop Linphone.
Make sure it's not in the task bar. Now run the script;

~$ ./gen-linphonebook.sh | sqlite3 friends.db

Potential problems

Don't build a database from scratch. Use the database generated by Linphone.
Don't insert record Id numbers. Sqlite3 does this for you.
If you have already deleted records from the database the script will cause a mismatch. 'sqlite_sequence' will be set to the highest record Id number. This should be the number of records. Use sqlite3 to correct;

DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES('friends',The_Actual_Number_Of_Records);
INSERT INTO sqlite_sequence VALUES('friends_lists',1);