tSIP softphone: XML phonebook import
Desk phones from multiple manufacturers (Cisco, Yealink, ATCOM) are using remote XML phonebooks with identical format, example:
<CiscoIPPhoneDirectory> <Title>Name Of Directory</Title> <Prompt>Prompt text.</Prompt> <DirectoryEntry> <Name>Name of Person or Company</Name> <Telephone>TelephoneNumber</Telephone> </DirectoryEntry> <DirectoryEntry> <Name>Name of Person or Company</Name> <Telephone>TelephoneNumber</Telephone> </DirectoryEntry> </CiscoIPPhoneDirectory>
Import function for this XML was added in tSIP 0.1.74.4 as function in main menu and Lua ReadXmlContacts(xml_file) function.
Lua example fetching XML from server using curl was added to Script window:
-- BASIC SETTINGS BLOCK -- where is XML phonebook placed on the server? local server_path = "http://tomeko.net/software/SIPclient/howto/phonebook.xml?token=ABCDEFGH" -- how to authorize to server (optional, may be empty) local server_auth = "--insecure --anyauth --user admin:password" -- END OF BASIC SETTINGS BLOCK function file_exists(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end -- let's use paths relative to exe location local filename = GetExeName() local index = string.find(filename:reverse(), "\") local dir = string.sub(filename, 1, -index) local curl_exe = dir .. "curl.exe" local xml_file = dir .. "phonebook.xml" if file_exists(curl_exe) == false then ShowMessage("This script requires curl.exe placed next to application executable") return end -- remove file from previous run before trying to download new one os.remove(xml_file) local args = " -o " .. xml_file .. " " .. server_path .. " " .. server_auth print(string.format("curl args: [%s]\n", args)) local ret = ShellExecute("open", curl_exe, args, nil, 0) print(string.format("curl ShellExecute return code: %d\n", ret)) -- wait up to 5 seconds for download for i = 1, 10 do -- Range includes both ends. if file_exists(xml_file) then break end if i == 10 then ShowMessage("Failed to download XML phonebook\n") print("Failed to download XML phonebook\n") return end Sleep(500) end -- MessageBox with MB_YESNO and question icon local res = MessageBox("Are you sure to overwrite current phonebook?\r\nCurrent contact entries would be lost.", "Overwrite phonebook?", 4+32) if res ~= 6 then return end local status = ReadXmlContacts(xml_file) if status == 0 then print(string.format("Error %d reading XML contacts\n", status)) else print("XML contacts imported\n") end
Note: XML import function overwrittes content of local phonebook completely.
tSIP uses ANSI code page - import function converts strings from UTF-8 to ANSI, but characters outside of ANSI set would not be converted - they would be visible as quotation marks.
Possible uses of script fetching phonebook include manual run (programmable button), "on startup" script and "on timer" script (e.g. using second timer with period set to 1 hour).
Back to howto list