1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
|
/*
Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "twinkle_config.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/soundcard.h>
#include <dirent.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <cstring>
#include "sys_settings.h"
#include "log.h"
#include "translator.h"
#include "user.h"
#include "userintf.h"
#include "util.h"
#include "audits/memman.h"
#include "utils/file_utils.h"
using namespace utils;
// Share directory containing files applicable to all users
#define DIR_SHARE DATADIR
// Lock file to guarantee that a user is running the application only once
#define LOCK_FILENAME "twinkle.lck"
// System config file
#define SYS_CONFIG_FILE "twinkle.sys"
// Default location of the shared mime database
#define DFLT_SHARED_MIME_DB "/usr/share/mime/globs"
// Field names in the config file
// AUDIO fields
#define FLD_DEV_RINGTONE "dev_ringtone"
#define FLD_DEV_SPEAKER "dev_speaker"
#define FLD_DEV_MIC "dev_mic"
#define FLD_VALIDATE_AUDIO_DEV "validate_audio_dev"
#define FLD_ALSA_PLAY_PERIOD_SIZE "alsa_play_period_size"
#define FLD_ALSA_CAPTURE_PERIOD_SIZE "alsa_capture_period_size"
#define FLD_OSS_FRAGMENT_SIZE "oss_fragment_size"
// LOG fields
#define FLD_LOG_MAX_SIZE "log_max_size"
#define FLD_LOG_SHOW_SIP "log_show_sip"
#define FLD_LOG_SHOW_STUN "log_show_stun"
#define FLD_LOG_SHOW_MEMORY "log_show_memory"
#define FLD_LOG_SHOW_DEBUG "log_show_debug"
// GUI settings
#define FLD_GUI_USE_SYSTRAY "gui_use_systray"
#define FLD_GUI_HIDE_ON_CLOSE "gui_hide_on_close"
#define FLD_GUI_AUTO_SHOW_INCOMING "gui_auto_show_incoming"
#define FLD_GUI_AUTO_SHOW_TIMEOUT "gui_auto_show_timeout"
#define FLD_GUI_BROWSER_CMD "gui_browser_cmd"
// Address book settings
#define FLD_AB_SHOW_SIP_ONLY "ab_show_sip_only"
#define FLD_AB_LOOKUP_NAME "ab_lookup_name"
#define FLD_AB_OVERRIDE_DISPLAY "ab_override_display"
#define FLD_AB_LOOKUP_PHOTO "ab_lookup_photo"
// Call history fields
#define FLD_CH_MAX_SIZE "ch_max_size"
// Service settings
#define FLD_CALL_WAITING "call_waiting"
#define FLD_HANGUP_BOTH_3WAY "hangup_both_3way"
// Startup settings
#define FLD_START_USER_PROFILE "start_user_profile"
#define FLD_START_HIDDEN "start_hidden"
// Network settings
#define FLD_sip_udp_port "sip_udp_port"
#define FLD_sip_port "sip_port"
#define FLD_RTP_PORT "rtp_port"
#define FLD_SIP_MAX_UDP_SIZE "sip_max_udp_size"
#define FLD_SIP_MAX_TCP_SIZE "sip_max_tcp_size"
// Ring tone settings
#define FLD_PLAY_RINGTONE "play_ringtone"
#define FLD_RINGTONE_FILE "ringtone_file"
#define FLD_PLAY_RINGBACK "play_ringback"
#define FLD_RINGBACK_FILE "ringback_file"
// Persistent storage for user interface state
#define FLD_LAST_USED_PROFILE "last_used_profile"
#define FLD_REDIAL_URL "redial_url"
#define FLD_REDIAL_DISPLAY "redial_display"
#define FLD_REDIAL_SUBJECT "redial_subject"
#define FLD_REDIAL_PROFILE "redial_profile"
#define FLD_REDIAL_HIDE_USER "redial_hide_user"
#define FLD_DIAL_HISTORY "dial_history"
#define FLD_SHOW_DISPLAY "show_display"
#define FLD_COMPACT_LINE_STATUS "compact_line_status"
#define FLD_SHOW_BUDDY_LIST "show_buddy_list"
#define FLD_WARN_HIDE_USER "warn_hide_user"
// Settings to restore session after shutdown
#define FLD_UI_SESSION_ID "ui_session_id"
#define FLD_UI_SESSION_ACTIVE_PROFILE "ui_session_active_profile"
#define FLD_UI_SESSION_MAIN_GEOMETRY "ui_session_main_geometry"
#define FLD_UI_SESSION_MAIN_HIDDEN "ui_session_main_hidden"
#define FLD_UI_SESSION_MAIN_STATE "ui_session_main_state"
// Mime settings
#define FLD_MIME_SHARED_DATABASE "mime_shared_database"
/////////////////////////
// class t_audio_device
/////////////////////////
string t_audio_device::get_description(void) const {
string s = device;
if (type == OSS) {
s = "OSS: " + s;
if (sym_link.size() > 0) {
s += " -> ";
s += sym_link;
}
if (name.size() > 0) {
s += ": ";
s += name;
}
} else if (type == ALSA) {
s = "ALSA: " + s;
if (!name.empty()) {
s += ": ";
s += name;
}
} else {
s = "Unknown: " + s;
}
return s;
}
string t_audio_device::get_settings_value(void) const {
string s;
switch (type) {
case OSS:
s = PFX_OSS;
break;
case ALSA:
s = PFX_ALSA;
break;
default:
assert(false);
}
s += device;
return s;
}
/////////////////////////
// class t_win_geometry
/////////////////////////
t_win_geometry::t_win_geometry(int x_, int y_, int width_, int height_) :
x(x_), y(y_), width(width_), height(height_)
{}
t_win_geometry::t_win_geometry() :
x(0), y(0), width(0), height(0)
{}
t_win_geometry::t_win_geometry(const string &value) {
vector<string> v = split(value, ',');
if (v.size() == 4) {
x = atoi(v[0].c_str());
y = atoi(v[1].c_str());
width = atoi(v[2].c_str());
height = atoi(v[3].c_str());
}
}
string t_win_geometry::encode(void) const {
string s;
s = int2str(x);
s += ',';
s += int2str(y);
s += ',';
s += int2str(width);
s += ',';
s += int2str(height);
return s;
}
/////////////////////////
// class t_sys_settings
/////////////////////////
t_sys_settings::t_sys_settings() {
fd_lock_file = -1;
dir_share = DIR_SHARE;
filename = string(DIR_HOME);
filename += "/";
filename += USER_DIR;
filename += "/";
filename += SYS_CONFIG_FILE;
// Audio device default settings
#ifdef HAVE_LIBASOUND
dev_ringtone = audio_device(DEV_ALSA_DFLT);
dev_speaker = audio_device(DEV_ALSA_DFLT);
dev_mic = audio_device(DEV_ALSA_DFLT);
#else
dev_ringtone = audio_device();
dev_speaker = audio_device();
dev_mic = audio_device();
#endif
validate_audio_dev = true;
alsa_play_period_size = 128;
alsa_capture_period_size = 32;
oss_fragment_size = 128;
log_max_size = 5;
log_show_sip = true;
log_show_stun = true;
log_show_memory = true;
log_show_debug = false;
gui_use_systray = true;
gui_hide_on_close = true;
gui_auto_show_incoming = false;
gui_auto_show_timeout = 10;
ab_show_sip_only = false;
ab_lookup_name = true;
ab_override_display = true;
ab_lookup_photo = true;
ch_max_size = 50;
call_waiting = true;
hangup_both_3way = true;
start_user_profiles.clear();
start_hidden = false;
config_sip_port = 5060;
active_sip_port = 0;
override_sip_port = 0;
rtp_port = 8000;
override_rtp_port = 0;
sip_max_udp_size = 65535;
sip_max_tcp_size = 1000000;
play_ringtone = true;
ringtone_file.clear();
play_ringback = true;
ringback_file.clear();
last_used_profile.clear();
redial_url.set_url("");
redial_display.clear();
redial_subject.clear();
redial_profile.clear();
redial_hide_user = false;
dial_history.clear();
show_display = true;
compact_line_status = false;
show_buddy_list = true;
warn_hide_user = true;
ui_session_id.clear();
mime_shared_database = DFLT_SHARED_MIME_DB;
}
// Getters
t_audio_device t_sys_settings::get_dev_ringtone(void) const {
t_audio_device result;
mtx_sys.lock();
result = dev_ringtone;
mtx_sys.unlock();
return result;
}
t_audio_device t_sys_settings::get_dev_speaker(void) const {
t_audio_device result;
mtx_sys.lock();
result = dev_speaker;
mtx_sys.unlock();
return result;
}
t_audio_device t_sys_settings::get_dev_mic(void) const {
t_audio_device result;
mtx_sys.lock();
result = dev_mic;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_validate_audio_dev(void) const {
bool result;
mtx_sys.lock();
result = validate_audio_dev;
mtx_sys.unlock();
return result;
}
int t_sys_settings::get_alsa_play_period_size(void) const {
int result;
mtx_sys.lock();
result = alsa_play_period_size;
mtx_sys.unlock();
return result;
}
int t_sys_settings::get_alsa_capture_period_size(void) const {
int result;
mtx_sys.lock();
result = alsa_capture_period_size;
mtx_sys.unlock();
return result;
}
int t_sys_settings::get_oss_fragment_size(void) const {
int result;
mtx_sys.lock();
result = oss_fragment_size;
mtx_sys.unlock();
return result;
}
unsigned short t_sys_settings::get_log_max_size(void) const {
unsigned short result;
mtx_sys.lock();
result = log_max_size;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_log_show_sip(void) const {
bool result;
mtx_sys.lock();
result = log_show_sip;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_log_show_stun(void) const {
bool result;
mtx_sys.lock();
result = log_show_stun;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_log_show_memory(void) const {
bool result;
mtx_sys.lock();
result = log_show_memory;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_log_show_debug(void) const {
bool result;
mtx_sys.lock();
result = log_show_debug;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_gui_use_systray(void) const {
t_mutex_guard guard(mtx_sys);
return gui_use_systray;
}
bool t_sys_settings::get_gui_auto_show_incoming(void) const {
t_mutex_guard guard(mtx_sys);
return gui_auto_show_incoming;
}
int t_sys_settings::get_gui_auto_show_timeout(void) const {
t_mutex_guard guard(mtx_sys);
return gui_auto_show_timeout;
}
bool t_sys_settings::get_gui_hide_on_close(void) const {
t_mutex_guard guard(mtx_sys);
return gui_hide_on_close;
}
string t_sys_settings::get_gui_browser_cmd(void) const {
t_mutex_guard guard(mtx_sys);
return gui_browser_cmd;
}
bool t_sys_settings::get_ab_show_sip_only(void) const {
bool result;
mtx_sys.lock();
result = ab_show_sip_only;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_ab_lookup_name(void) const {
bool result;
mtx_sys.lock();
result = ab_lookup_name;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_ab_override_display(void) const {
bool result;
mtx_sys.lock();
result = ab_override_display;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_ab_lookup_photo(void) const {
bool result;
mtx_sys.lock();
result = ab_lookup_photo;
mtx_sys.unlock();
return result;
}
int t_sys_settings::get_ch_max_size(void) const {
int result;
mtx_sys.lock();
result = ch_max_size;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_call_waiting(void) const {
bool result;
mtx_sys.lock();
result = call_waiting;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_hangup_both_3way(void) const {
bool result;
mtx_sys.lock();
result = hangup_both_3way;
mtx_sys.unlock();
return result;
}
list<string> t_sys_settings::get_start_user_profiles(void) const {
list<string> result;
mtx_sys.lock();
result = start_user_profiles;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_start_hidden(void) const {
bool result;
mtx_sys.lock();
result = start_hidden;
mtx_sys.unlock();
return result;
}
unsigned short t_sys_settings::get_config_sip_port(void) const {
unsigned short result;
mtx_sys.lock();
result = config_sip_port;
mtx_sys.unlock();
return result;
}
unsigned short t_sys_settings::get_rtp_port(void) const {
unsigned short result;
mtx_sys.lock();
if (override_rtp_port > 0) {
result = override_rtp_port;
} else {
result = rtp_port;
}
mtx_sys.unlock();
return result;
}
unsigned short t_sys_settings::get_sip_max_udp_size(void) const {
t_mutex_guard guard(mtx_sys);
return sip_max_udp_size;
}
unsigned long t_sys_settings::get_sip_max_tcp_size(void) const {
t_mutex_guard guard(mtx_sys);
return sip_max_tcp_size;
}
bool t_sys_settings::get_play_ringtone(void) const {
bool result;
mtx_sys.lock();
result = play_ringtone;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_ringtone_file(void) const {
string result;
mtx_sys.lock();
result = ringtone_file;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_play_ringback(void) const {
bool result;
mtx_sys.lock();
result = play_ringback;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_ringback_file(void) const {
string result;
mtx_sys.lock();
result = ringback_file;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_last_used_profile(void) const {
string result;
mtx_sys.lock();
result = last_used_profile;
mtx_sys.unlock();
return result;
}
t_url t_sys_settings::get_redial_url(void) const {
t_url result;
mtx_sys.lock();
result = redial_url;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_redial_display(void) const {
string result;
mtx_sys.lock();
result = redial_display;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_redial_subject(void) const {
string result;
mtx_sys.lock();
result = redial_subject;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_redial_profile(void) const {
string result;
mtx_sys.lock();
result = redial_profile;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_redial_hide_user(void) const {
bool result;
mtx_sys.lock();
result = redial_hide_user;
mtx_sys.unlock();
return result;
}
list<string> t_sys_settings::get_dial_history(void) const {
list<string> result;
mtx_sys.lock();
result = dial_history;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_show_display(void) const {
bool result;
mtx_sys.lock();
result = show_display;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_compact_line_status(void) const {
bool result;
mtx_sys.lock();
result = compact_line_status;
mtx_sys.unlock();
return result;
}
bool t_sys_settings::get_show_buddy_list(void) const {
bool result;
mtx_sys.lock();
result = show_buddy_list;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_ui_session_id(void) const {
t_mutex_guard guard(mtx_sys);
return ui_session_id;
}
list<string> t_sys_settings::get_ui_session_active_profiles(void) const {
t_mutex_guard guard(mtx_sys);
return ui_session_active_profiles;
}
t_win_geometry t_sys_settings::get_ui_session_main_geometry(void) const {
t_mutex_guard guard(mtx_sys);
return ui_session_main_geometry;
}
bool t_sys_settings::get_ui_session_main_hidden(void) const {
t_mutex_guard guard(mtx_sys);
return ui_session_main_hidden;
}
unsigned int t_sys_settings::get_ui_session_main_state(void) const {
t_mutex_guard guard(mtx_sys);
return ui_session_main_state;
}
bool t_sys_settings::get_warn_hide_user(void) const {
t_mutex_guard guard(mtx_sys);
return warn_hide_user;
}
string t_sys_settings::get_mime_shared_database(void) const {
t_mutex_guard guard(mtx_sys);
return mime_shared_database;
}
// Setters
void t_sys_settings::set_dev_ringtone(const t_audio_device &dev) {
mtx_sys.lock();
dev_ringtone = dev;
mtx_sys.unlock();
}
void t_sys_settings::set_dev_speaker(const t_audio_device &dev) {
mtx_sys.lock();
dev_speaker = dev;
mtx_sys.unlock();
}
void t_sys_settings::set_dev_mic(const t_audio_device &dev) {
mtx_sys.lock();
dev_mic = dev;
mtx_sys.unlock();
}
void t_sys_settings::set_validate_audio_dev(bool b) {
mtx_sys.lock();
validate_audio_dev = b;
mtx_sys.unlock();
}
void t_sys_settings::set_alsa_play_period_size(int size) {
mtx_sys.lock();
alsa_play_period_size = size;
mtx_sys.unlock();
}
void t_sys_settings::set_alsa_capture_period_size(int size) {
mtx_sys.lock();
alsa_capture_period_size = size;
mtx_sys.unlock();
}
void t_sys_settings::set_oss_fragment_size(int size) {
mtx_sys.lock();
oss_fragment_size = size;
mtx_sys.unlock();
}
void t_sys_settings::set_log_max_size(unsigned short size) {
mtx_sys.lock();
log_max_size = size;
mtx_sys.unlock();
}
void t_sys_settings::set_log_show_sip(bool b) {
mtx_sys.lock();
log_show_sip = b;
mtx_sys.unlock();
}
void t_sys_settings::set_log_show_stun(bool b) {
mtx_sys.lock();
log_show_stun = b;
mtx_sys.unlock();
}
void t_sys_settings::set_log_show_memory(bool b) {
t_mutex_guard guard(mtx_sys);
log_show_memory = b;
}
void t_sys_settings::set_log_show_debug(bool b) {
t_mutex_guard guard(mtx_sys);
log_show_debug = b;
}
void t_sys_settings::set_gui_use_systray(bool b) {
t_mutex_guard guard(mtx_sys);
gui_use_systray = b;
}
void t_sys_settings::set_gui_hide_on_close(bool b) {
t_mutex_guard guard(mtx_sys);
gui_hide_on_close = b;
}
void t_sys_settings::set_gui_auto_show_incoming(bool b) {
t_mutex_guard guard(mtx_sys);
gui_auto_show_incoming = b;
}
void t_sys_settings::set_gui_auto_show_timeout(int timeout) {
t_mutex_guard guard(mtx_sys);
gui_auto_show_timeout = timeout;
}
void t_sys_settings::set_gui_browser_cmd(const string &s) {
t_mutex_guard guard(mtx_sys);
gui_browser_cmd = s;
}
void t_sys_settings::set_ab_show_sip_only(bool b) {
mtx_sys.lock();
ab_show_sip_only = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ab_lookup_name(bool b) {
mtx_sys.lock();
ab_lookup_name = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ab_override_display(bool b) {
mtx_sys.lock();
ab_override_display = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ab_lookup_photo(bool b) {
mtx_sys.lock();
ab_lookup_photo = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ch_max_size(int size) {
mtx_sys.lock();
ch_max_size = size;
mtx_sys.unlock();
}
void t_sys_settings::set_call_waiting(bool b) {
mtx_sys.lock();
call_waiting = b;
mtx_sys.unlock();
}
void t_sys_settings::set_hangup_both_3way(bool b) {
mtx_sys.lock();
hangup_both_3way = b;
mtx_sys.unlock();
}
void t_sys_settings::set_start_user_profiles(const list<string> &profiles) {
mtx_sys.lock();
start_user_profiles = profiles;
mtx_sys.unlock();
}
void t_sys_settings::set_start_hidden(bool b) {
mtx_sys.lock();
start_hidden = b;
mtx_sys.unlock();
}
void t_sys_settings::set_config_sip_port(unsigned short port) {
mtx_sys.lock();
config_sip_port = port;
mtx_sys.unlock();
}
void t_sys_settings::set_override_sip_port(unsigned short port) {
mtx_sys.lock();
override_sip_port = port;
mtx_sys.unlock();
}
void t_sys_settings::set_rtp_port(unsigned short port) {
mtx_sys.lock();
rtp_port = port;
mtx_sys.unlock();
}
void t_sys_settings::set_override_rtp_port(unsigned short port) {
mtx_sys.lock();
override_rtp_port = port;
mtx_sys.unlock();
}
void t_sys_settings::set_sip_max_udp_size(unsigned short size) {
t_mutex_guard guard(mtx_sys);
sip_max_udp_size = size;
}
void t_sys_settings::set_sip_max_tcp_size(unsigned long size) {
t_mutex_guard guard(mtx_sys);
sip_max_tcp_size = size;
}
void t_sys_settings::set_play_ringtone(bool b) {
mtx_sys.lock();
play_ringtone = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ringtone_file(const string &file) {
mtx_sys.lock();
ringtone_file = file;
mtx_sys.unlock();
}
void t_sys_settings::set_play_ringback(bool b) {
mtx_sys.lock();
play_ringback = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ringback_file(const string &file) {
mtx_sys.lock();
ringback_file = file;
mtx_sys.unlock();
}
void t_sys_settings::set_last_used_profile(const string &profile) {
mtx_sys.lock();
last_used_profile = profile;
mtx_sys.unlock();
}
void t_sys_settings::set_redial_url(const t_url &url) {
mtx_sys.lock();
redial_url = url;
mtx_sys.unlock();
}
void t_sys_settings::set_redial_display(const string &display) {
mtx_sys.lock();
redial_display = display;
mtx_sys.unlock();
}
void t_sys_settings::set_redial_subject(const string &subject) {
mtx_sys.lock();
redial_subject = subject;
mtx_sys.unlock();
}
void t_sys_settings::set_redial_profile(const string &profile) {
mtx_sys.lock();
redial_profile = profile;
mtx_sys.unlock();
}
void t_sys_settings::set_redial_hide_user(const bool b) {
mtx_sys.lock();
redial_hide_user = b;
mtx_sys.unlock();
}
void t_sys_settings::set_dial_history(const list<string> &history) {
mtx_sys.lock();
dial_history = history;
mtx_sys.unlock();
}
void t_sys_settings::set_show_display(bool b) {
mtx_sys.lock();
show_display = b;
mtx_sys.unlock();
}
void t_sys_settings::set_compact_line_status(bool b) {
mtx_sys.lock();
compact_line_status = b;
mtx_sys.unlock();
}
void t_sys_settings::set_show_buddy_list(bool b) {
mtx_sys.lock();
show_buddy_list = b;
mtx_sys.unlock();
}
void t_sys_settings::set_ui_session_id(const string &id) {
t_mutex_guard guard(mtx_sys);
ui_session_id = id;
}
void t_sys_settings::set_ui_session_active_profiles(const list<string> &profiles) {
t_mutex_guard guard(mtx_sys);
ui_session_active_profiles = profiles;
}
void t_sys_settings::set_ui_session_main_geometry(const t_win_geometry &geometry) {
t_mutex_guard guard(mtx_sys);
ui_session_main_geometry = geometry;
}
void t_sys_settings::set_ui_session_main_hidden(bool hidden) {
t_mutex_guard guard(mtx_sys);
ui_session_main_hidden = hidden;
}
void t_sys_settings::set_ui_session_main_state(unsigned int state) {
t_mutex_guard guard(mtx_sys);
ui_session_main_state = state;
}
void t_sys_settings::set_warn_hide_user(bool b) {
t_mutex_guard guard(mtx_sys);
warn_hide_user = b;
}
void t_sys_settings::set_mime_shared_database(const string &filename) {
t_mutex_guard guard(mtx_sys);
mime_shared_database = filename;
}
string t_sys_settings::about(bool html) const {
string s = PRODUCT_NAME;
s += ' ';
s += PRODUCT_VERSION;
s += " - ";
s += get_product_date();
if (html) s += "<BR>";
s += "\n";
s += "Copyright (C) 2005-2009 ";
s += PRODUCT_AUTHOR;
if (html) s += "<BR>";
s += "\n";
s += "http://www.twinklephone.com";
if (html) s += "<BR><BR>";
s += "\n\n";
string options_built = get_options_built();
if (!options_built.empty()) {
s += TRANSLATE("Built with support for:");
s += " ";
s += options_built;
if (html) s += "<BR><BR>";
s += "\n\n";
}
s += TRANSLATE("Contributions:");
if (html) s += "<BR>";
s += "\n";
s += "* Werner Dittmann (ZRTP/SRTP)\n";
if (html) s += "<BR>";
s += "* Bogdan Harjoc (AKAv1-MD5, Service-Route)\n";
if (html) s += "<BR>";
s += "* Roman Imankulov (command line editing)\n";
if (html) s += "<BR>";
if (html) {
s += "* Ondrej Moriš (codec preprocessing)<BR>\n";
} else {
s += "* Ondrej Moris (codec preprocessing)\n";
}
if (html) {
s += "* Rickard Petzäll (ALSA)<BR>\n";
} else {
s += "* Rickard Petzall (ALSA)\n";
}
if (html) s += "<BR>";
s += "\n";
s += TRANSLATE("This software contains the following software from 3rd parties:");
if (html) s += "<BR>";
s += "\n";
s += TRANSLATE("* GSM codec from Jutta Degener and Carsten Bormann, University of Berlin");
if (html) s += "<BR>";
s += "\n";
s += TRANSLATE("* G.711/G.726 codecs from Sun Microsystems (public domain)");
if (html) s += "<BR>";
s += "\n";
#ifdef HAVE_ILBC
s += TRANSLATE("* iLBC implementation from RFC 3951 (www.ilbcfreeware.org)");
if (html) s += "<BR>";
s += "\n";
#endif
s += TRANSLATE("* Parts of the STUN project at http://sourceforge.net/projects/stun");
if (html) s += "<BR>";
s += "\n";
s += TRANSLATE("* Parts of libsrv at http://libsrv.sourceforge.net/");
if (html) s += "<BR>";
s += "\n";
if (html) s += "<BR>";
s += "\n";
s += TRANSLATE("For RTP the following dynamic libraries are linked:");
if (html) s += "<BR>";
s += "\n";
s += "* GNU ccRTP - http://www.gnu.org/software/ccrtp";
if (html) s += "<BR>";
s += "\n";
s += "* GNU CommonC++ - http://www.gnu.org/software/commoncpp";
if (html) s += "<BR><BR>";
s += "\n\n";
// Display information about translator only on non-english version.
string translated_by = TRANSLATE("Translated to english by <your name>");
if (translated_by != "Translated to english by <your name>") {
s += translated_by;
if (html) s += "<BR><BR>";
s += "\n\n";
}
s += PRODUCT_NAME;
s += " comes with ABSOLUTELY NO WARRANTY.";
if (html) s += "<BR>";
s += "\n";
s += "This program is free software; you can redistribute it and/or modify";
if (html) s += "<BR>";
s += "\n";
s += "it under the terms of the GNU General Public License as published by";
if (html) s += "<BR>";
s += "\n";
s += "the Free Software Foundation; either version 2 of the License, or";
if (html) s += "<BR>";
s += "\n";
s += "(at your option) any later version.";
if (html) s += "<BR>";
s += "\n";
return s;
}
string t_sys_settings::get_product_date(void) const {
struct tm t;
t.tm_sec = 0;
t.tm_min = 0;
t.tm_hour = 0;
vector<string> l = split(PRODUCT_DATE, ' ');
assert(l.size() == 3);
t.tm_mon = str2month_full(l[0]);
t.tm_mday = atoi(l[1].c_str());
t.tm_year = atoi(l[2].c_str()) - 1900;
char buf[64];
strftime(buf, 64, "%d %B %Y", &t);
return string(buf);
}
string t_sys_settings::get_options_built(void) const {
string options_built;
#ifdef HAVE_LIBASOUND
if (!options_built.empty()) options_built += ", ";
options_built += "ALSA";
#endif
#ifdef HAVE_KDE
if (!options_built.empty()) options_built += ", ";
options_built += "KDE";
#endif
#ifdef HAVE_SPEEX
if (!options_built.empty()) options_built += ", ";
options_built += "Speex";
#endif
#ifdef HAVE_ILBC
if (!options_built.empty()) options_built += ", ";
options_built += "iLBC";
#endif
#ifdef HAVE_ZRTP
if (!options_built.empty()) options_built += ", ";
options_built += "ZRTP";
#endif
return options_built;
}
bool t_sys_settings::check_environment(string &error_msg) const {
struct stat stat_buf;
string filename, dirname;
mtx_sys.lock();
// Check if share directory exists
if (stat(dir_share.c_str(), &stat_buf) != 0) {
error_msg = TRANSLATE("Directory %1 does not exist.");
error_msg = replace_first(error_msg, "%1", dir_share);
mtx_sys.unlock();
return false;
}
// Check if audio file for ring tone exist
filename = dir_share;
filename += '/';
filename += FILE_RINGTONE;
ifstream f_ringtone(filename.c_str());
if (!f_ringtone) {
error_msg = TRANSLATE("Cannot open file %1 .");
error_msg = replace_first(error_msg, "%1", filename);
mtx_sys.unlock();
return false;
}
// Check if audio file for ring back exist
filename = dir_share;
filename += '/';
filename += FILE_RINGBACK;
ifstream f_ringback(filename.c_str());
if (!f_ringback) {
error_msg = TRANSLATE("Cannot open file %1 .");
error_msg = replace_first(error_msg, "%1", filename);
mtx_sys.unlock();
return false;
}
// Check if $HOME is set correctly
if (string(DIR_HOME) == "") {
error_msg = TRANSLATE("%1 is not set to your home directory.");
error_msg = replace_first(error_msg, "%1", "$HOME");
mtx_sys.unlock();
return false;
}
if (stat(DIR_HOME, &stat_buf) != 0) {
error_msg = TRANSLATE("Directory %1 (%2) does not exist.");
error_msg = replace_first(error_msg, "%1", DIR_HOME);
error_msg = replace_first(error_msg, "%2", "$HOME");
mtx_sys.unlock();
return false;
}
// Check if user directory exists
dirname = get_dir_user();
if (stat(dirname.c_str(), &stat_buf) != 0) {
// User directory does not exist. Create it now.
if (mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
// Failed to create the user directory
error_msg = TRANSLATE("Cannot create directory %1 .");
error_msg = replace_first(error_msg, "%1", dirname);
mtx_sys.unlock();
return false;
}
}
// Check if tmp file directory exists
dirname = get_dir_tmpfile();
if (stat(dirname.c_str(), &stat_buf) != 0) {
// Tmp file directory does not exist. Create it now.
if (mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
// Failed to create the tmp file directory
error_msg = TRANSLATE("Cannot create directory %1 .");
error_msg = replace_first(error_msg, "%1", dirname);
mtx_sys.unlock();
return false;
}
}
mtx_sys.unlock();
return true;
}
void t_sys_settings::set_dir_share(const string &dir) {
mtx_sys.lock();
dir_share = dir;
mtx_sys.unlock();
}
string t_sys_settings::get_dir_share(void) const {
string result;
mtx_sys.lock();
result = dir_share;
mtx_sys.unlock();
return result;
}
string t_sys_settings::get_dir_lang(void) const {
string result = get_dir_share();
result += "/lang";
return result;
}
string t_sys_settings::get_dir_user(void) const {
string dir = DIR_HOME;
dir += "/";
dir += DIR_USER;
return dir;
}
string t_sys_settings::get_history_file(void) const {
string dir = get_dir_user();
dir += "/";
dir += FILE_CLI_HISTORY;
return dir;
}
string t_sys_settings::get_dir_tmpfile(void) const {
string dir = get_dir_user();
dir += "/";
dir += DIR_TMPFILE;
return dir;
}
bool t_sys_settings::is_tmpfile(const string &filename) const {
string tmpdir = get_dir_tmpfile();
return filename.substr(0, tmpdir.size()) == tmpdir;
}
bool t_sys_settings::save_tmp_file(const string &data, const string &file_extension,
string &filename, string &error_msg)
{
string fname = get_dir_tmpfile();
fname += "/XXXXXX";
char *tmpfile = strdup(fname.c_str());
MEMMAN_NEW(tmpfile);
int fd = mkstemp(tmpfile);
if (fd < 0) {
error_msg = get_error_str(errno);
MEMMAN_DELETE(tmpfile);
free(tmpfile);
return false;
}
close(fd);
ofstream f(tmpfile);
if (!f) {
error_msg = TRANSLATE("Failed to create file %1");
error_msg = replace_first(error_msg, "%1", tmpfile);
MEMMAN_DELETE(tmpfile);
free(tmpfile);
return false;
}
f.write(data.c_str(), data.size());
if (!f.good()) {
error_msg = TRANSLATE("Failed to write data to file %1");
error_msg = replace_first(error_msg, "%1", tmpfile);
f.close();
MEMMAN_DELETE(tmpfile);
free(tmpfile);
return false;
}
f.close();
// Rename to name with extension
filename = apply_glob_to_filename(tmpfile, file_extension);
if (rename(tmpfile, filename.c_str()) < 0) {
error_msg = get_error_str(errno);
MEMMAN_DELETE(tmpfile);
free(tmpfile);
return false;
}
MEMMAN_DELETE(tmpfile);
free(tmpfile);
return true;
}
bool t_sys_settings::save_sip_body(const t_sip_message &sip_msg,
const string &suggested_file_extension,
string &tmpname, string &save_as_name, string &error_msg)
{
bool retval = true;
if (!sip_msg.body) {
error_msg = "Missing body";
return false;
}
// Determine file extension and save-as name
// The algorithm to get the file extension (glob expression) is:
// 1) If the a file name is supplied in the Content-Disposition header, then
// take the file extension from that file name.
// 2) If no extension is found, then take the suggested_file_extension
// 3) If still no file extension is found, then retrieve the file extension
// from the t_media object in the Content-Type header.
string file_ext = suggested_file_extension;
save_as_name.clear();
if (sip_msg.hdr_content_disp.is_populated() &&
sip_msg.hdr_content_disp.type == DISPOSITION_ATTACHMENT &&
!sip_msg.hdr_content_disp.filename.empty())
{
string x = get_extension_from_filename(sip_msg.hdr_content_disp.filename);
if (!x.empty()) file_ext = string("*." + x);
save_as_name = strip_path_from_filename(sip_msg.hdr_content_disp.filename);
}
if (file_ext.empty()) {
file_ext = sip_msg.hdr_content_type.media.get_file_glob();
if (file_ext.empty()) {
file_ext = "*";
}
}
// Avoid copy of opaque data
if (sip_msg.body->get_type() == BODY_OPAQUE) {
t_sip_body_opaque *body_opaque = dynamic_cast<t_sip_body_opaque *>(sip_msg.body);
retval = save_tmp_file(body_opaque->opaque, file_ext, tmpname, error_msg);
} else {
retval = save_tmp_file(sip_msg.body->encode(), file_ext, tmpname, error_msg);
}
return retval;
}
void t_sys_settings::remove_all_tmp_files(void) const {
DIR *tmpdir = opendir(get_dir_tmpfile().c_str());
if (!tmpdir) {
log_file->write_report(get_error_str(errno), "t_sys_settings::remove_all_tmp_files");
return;
}
struct dirent *entry = readdir(tmpdir);
while (entry) {
if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
string fname = get_dir_tmpfile();
fname += PATH_SEPARATOR;
fname += entry->d_name;
log_file->write_header("t_sys_settings::remove_all_tmp_files");
log_file->write_raw("Remove tmp file ");
log_file->write_raw(fname);
log_file->write_endl();
log_file->write_footer();
unlink(fname.c_str());
}
entry = readdir(tmpdir);
}
closedir(tmpdir);
}
bool t_sys_settings::create_lock_file(bool shared_lock, string &error_msg,
bool &already_running)
{
string lck_filename;
already_running = false;
lck_filename = DIR_HOME;
lck_filename += "/";
lck_filename += DIR_USER;
lck_filename += "/";
lck_filename += LOCK_FILENAME;
fd_lock_file = open(lck_filename.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd_lock_file < 0) {
error_msg = TRANSLATE("Cannot create %1 .");
error_msg = replace_first(error_msg, "%1", lck_filename);
error_msg += "\n";
error_msg += get_error_str(errno);
return false;
}
struct flock lock_options;
// Try to acquire an exclusive lock
if (!shared_lock)
{
memset(&lock_options, 0, sizeof(struct flock));
lock_options.l_type = F_WRLCK;
lock_options.l_whence = SEEK_SET;
if (fcntl(fd_lock_file, F_SETLK, &lock_options) < 0) {
already_running = true;
error_msg = TRANSLATE("%1 is already running.\nLock file %2 already exists.");
error_msg = replace_first(error_msg, "%1", PRODUCT_NAME);
error_msg = replace_first(error_msg, "%2", lck_filename);
return false;
}
}
// Convert the lock to a shared lock. If the user forces multiple
// instances of Twinkle to run, then each will have a shared lock.
memset(&lock_options, 0, sizeof(struct flock));
lock_options.l_type = F_RDLCK;
lock_options.l_whence = SEEK_SET;
if (fcntl(fd_lock_file, F_SETLK, &lock_options) < 0) {
error_msg = TRANSLATE("Cannot lock %1 .");
error_msg = replace_first(error_msg, "%1", lck_filename);
return false;
}
return true;
}
void t_sys_settings::delete_lock_file(void) {
if (fd_lock_file >= 0)
{
struct flock lock_options;
lock_options.l_type = F_UNLCK;
lock_options.l_whence = SEEK_SET;
fcntl(fd_lock_file, F_SETLK, &lock_options);
close(fd_lock_file);
fd_lock_file = -1;
}
}
bool t_sys_settings::read_config(string &error_msg) {
struct stat stat_buf;
mtx_sys.lock();
// Check if config file exists
if (stat(filename.c_str(), &stat_buf) != 0) {
mtx_sys.unlock();
return true;
}
// Open config file
ifstream config(filename.c_str());
if (!config) {
error_msg = TRANSLATE("Cannot open file for reading: %1");
error_msg = replace_first(error_msg, "%1", filename);
mtx_sys.unlock();
return false;
}
// Read and parse config file.
while (!config.eof()) {
string line;
getline(config, line);
// Check if read operation succeeded
if (!config.good() && !config.eof()) {
error_msg = TRANSLATE("File system error while reading file %1 .");
error_msg = replace_first(error_msg, "%1", filename);
mtx_sys.unlock();
return false;
}
line = trim(line);
// Skip empty lines
if (line.size() == 0) continue;
// Skip comment lines
if (line[0] == '#') continue;
vector<string> l = split_on_first(line, '=');
if (l.size() != 2) {
error_msg = TRANSLATE("Syntax error in file %1 .");
error_msg = replace_first(error_msg, "%1", filename);
error_msg += "\n";
error_msg += line;
mtx_sys.unlock();
return false;
}
string parameter = trim(l[0]);
string value = trim(l[1]);
if (parameter == FLD_DEV_RINGTONE) {
dev_ringtone = audio_device(value);
} else if (parameter == FLD_DEV_SPEAKER) {
dev_speaker = audio_device(value);
} else if (parameter == FLD_DEV_MIC) {
dev_mic = audio_device(value);
} else if (parameter == FLD_VALIDATE_AUDIO_DEV) {
validate_audio_dev = yesno2bool(value);
} else if (parameter == FLD_ALSA_PLAY_PERIOD_SIZE) {
alsa_play_period_size = atoi(value.c_str());
} else if (parameter == FLD_ALSA_CAPTURE_PERIOD_SIZE) {
alsa_capture_period_size = atoi(value.c_str());
} else if (parameter == FLD_OSS_FRAGMENT_SIZE) {
oss_fragment_size = atoi(value.c_str());
} else if (parameter == FLD_LOG_MAX_SIZE) {
log_max_size = atoi(value.c_str());
} else if (parameter == FLD_LOG_SHOW_SIP) {
log_show_sip = yesno2bool(value);
} else if (parameter == FLD_LOG_SHOW_STUN) {
log_show_stun = yesno2bool(value);
} else if (parameter == FLD_LOG_SHOW_MEMORY) {
log_show_memory = yesno2bool(value);
} else if (parameter == FLD_LOG_SHOW_DEBUG) {
log_show_debug = yesno2bool(value);
} else if (parameter == FLD_GUI_USE_SYSTRAY) {
gui_use_systray = yesno2bool(value);
} else if (parameter == FLD_GUI_HIDE_ON_CLOSE) {
gui_hide_on_close = yesno2bool(value);
} else if (parameter == FLD_GUI_AUTO_SHOW_INCOMING) {
gui_auto_show_incoming = yesno2bool(value);
} else if (parameter == FLD_GUI_AUTO_SHOW_TIMEOUT) {
gui_auto_show_timeout = atoi(value.c_str());
} else if (parameter == FLD_GUI_BROWSER_CMD) {
gui_browser_cmd = value;
} else if (parameter == FLD_AB_SHOW_SIP_ONLY) {
ab_show_sip_only = yesno2bool(value);
} else if (parameter == FLD_AB_LOOKUP_NAME) {
ab_lookup_name = yesno2bool(value);
} else if (parameter == FLD_AB_OVERRIDE_DISPLAY) {
ab_override_display = yesno2bool(value);
} else if (parameter == FLD_AB_LOOKUP_PHOTO) {
ab_lookup_photo = yesno2bool(value);
} else if (parameter == FLD_CH_MAX_SIZE) {
ch_max_size = atoi(value.c_str());
} else if (parameter == FLD_CALL_WAITING) {
call_waiting = yesno2bool(value);
} else if (parameter == FLD_HANGUP_BOTH_3WAY) {
hangup_both_3way = yesno2bool(value);
} else if (parameter == FLD_START_USER_PROFILE) {
if (!value.empty()) start_user_profiles.push_back(value);
} else if (parameter == FLD_START_HIDDEN) {
start_hidden = yesno2bool(value);
} else if (parameter == FLD_sip_udp_port) { // Deprecated parameter
config_sip_port = atoi(value.c_str());
} else if (parameter == FLD_sip_port) {
config_sip_port = atoi(value.c_str());
} else if (parameter == FLD_RTP_PORT) {
rtp_port = atoi(value.c_str());
} else if (parameter == FLD_SIP_MAX_UDP_SIZE) {
sip_max_udp_size = atoi(value.c_str());
} else if (parameter == FLD_SIP_MAX_TCP_SIZE) {
sip_max_tcp_size = atoi(value.c_str());
} else if (parameter == FLD_PLAY_RINGTONE) {
play_ringtone = yesno2bool(value);
} else if (parameter == FLD_RINGTONE_FILE) {
ringtone_file = value;
} else if (parameter == FLD_PLAY_RINGBACK) {
play_ringback = yesno2bool(value);
} else if (parameter == FLD_RINGBACK_FILE) {
ringback_file = value;
} else if (parameter == FLD_LAST_USED_PROFILE) {
last_used_profile = value;
} else if (parameter == FLD_REDIAL_URL) {
redial_url.set_url(value);
if (!redial_url.is_valid()) {
redial_url.set_url("");
}
} else if (parameter == FLD_REDIAL_DISPLAY) {
redial_display = value;
} else if (parameter == FLD_REDIAL_SUBJECT) {
redial_subject = value;
} else if (parameter == FLD_REDIAL_PROFILE) {
redial_profile = value;
} else if (parameter == FLD_REDIAL_HIDE_USER) {
redial_hide_user = yesno2bool(value);
} else if (parameter == FLD_DIAL_HISTORY) {
dial_history.push_back(value);
} else if (parameter == FLD_SHOW_DISPLAY) {
show_display = yesno2bool(value);
} else if (parameter == FLD_COMPACT_LINE_STATUS) {
//compact_line_status = yesno2bool(value);
} else if (parameter == FLD_SHOW_BUDDY_LIST) {
show_buddy_list = yesno2bool(value);
} else if (parameter == FLD_UI_SESSION_ID) {
ui_session_id = value;
} else if (parameter == FLD_UI_SESSION_ACTIVE_PROFILE) {
ui_session_active_profiles.push_back(value);
} else if (parameter == FLD_UI_SESSION_MAIN_GEOMETRY) {
ui_session_main_geometry = value;
} else if (parameter == FLD_UI_SESSION_MAIN_HIDDEN) {
ui_session_main_hidden = yesno2bool(value);
} else if (parameter == FLD_UI_SESSION_MAIN_STATE) {
ui_session_main_state = atoi(value.c_str());
} else if (parameter == FLD_WARN_HIDE_USER) {
warn_hide_user = yesno2bool(value);
} else if (parameter == FLD_MIME_SHARED_DATABASE) {
mime_shared_database = value;
}
// Unknown field names are skipped.
}
mtx_sys.unlock();
return true;
}
bool t_sys_settings::write_config(string &error_msg) {
struct stat stat_buf;
mtx_sys.lock();
// Make a backup of the file if we are editing an existing file, so
// that can be restored when writing fails.
string f_backup = filename + '~';
if (stat(filename.c_str(), &stat_buf) == 0) {
if (rename(filename.c_str(), f_backup.c_str()) != 0) {
string err = get_error_str(errno);
error_msg = TRANSLATE("Failed to backup %1 to %2");
error_msg = replace_first(error_msg, "%1", filename);
error_msg = replace_first(error_msg, "%2", f_backup);
error_msg += "\n";
error_msg += err;
mtx_sys.unlock();
return false;
}
}
// Open file
ofstream config(filename.c_str());
if (!config) {
error_msg = TRANSLATE("Cannot open file for writing: %1");
error_msg = replace_first(error_msg, "%1", filename);
mtx_sys.unlock();
return false;
}
// Write AUDIO settings
config << "# AUDIO\n";
config << FLD_DEV_RINGTONE << '=' << dev_ringtone.get_settings_value() << endl;
config << FLD_DEV_SPEAKER << '=' << dev_speaker.get_settings_value() << endl;
config << FLD_DEV_MIC << '=' << dev_mic.get_settings_value() << endl;
config << FLD_VALIDATE_AUDIO_DEV << '=' << bool2yesno(validate_audio_dev) << endl;
config << FLD_ALSA_PLAY_PERIOD_SIZE << '=' << alsa_play_period_size << endl;
config << FLD_ALSA_CAPTURE_PERIOD_SIZE << '=' << alsa_capture_period_size << endl;
config << FLD_OSS_FRAGMENT_SIZE << '=' << oss_fragment_size << endl;
config << endl;
// Write LOG settings
config << "# LOG\n";
config << FLD_LOG_MAX_SIZE << '=' << log_max_size << endl;
config << FLD_LOG_SHOW_SIP << '=' << bool2yesno(log_show_sip) << endl;
config << FLD_LOG_SHOW_STUN << '=' << bool2yesno(log_show_stun) << endl;
config << FLD_LOG_SHOW_MEMORY << '=' << bool2yesno(log_show_memory) << endl;
config << FLD_LOG_SHOW_DEBUG << '=' << bool2yesno(log_show_debug) << endl;
config << endl;
// Write GUI settings
config << "# GUI\n";
config << FLD_GUI_USE_SYSTRAY << '=' << bool2yesno(gui_use_systray) << endl;
config << FLD_GUI_HIDE_ON_CLOSE << '=' << bool2yesno(gui_hide_on_close) << endl;
config << FLD_GUI_AUTO_SHOW_INCOMING << '=' << bool2yesno(gui_auto_show_incoming) << endl;
config << FLD_GUI_AUTO_SHOW_TIMEOUT << '=' << gui_auto_show_timeout << endl;
config << FLD_GUI_BROWSER_CMD << '=' << gui_browser_cmd << endl;
config << endl;
// Write address book settings
config << "# Address book\n";
config << FLD_AB_SHOW_SIP_ONLY << '=' << bool2yesno(ab_show_sip_only) << endl;
config << FLD_AB_LOOKUP_NAME << '=' << bool2yesno(ab_lookup_name) << endl;
config << FLD_AB_OVERRIDE_DISPLAY << '=' << bool2yesno(ab_override_display) << endl;
config << FLD_AB_LOOKUP_PHOTO << '=' << bool2yesno(ab_lookup_photo) << endl;
config << endl;
// Write call history settings
config << "# Call history\n";
config << FLD_CH_MAX_SIZE << '=' << ch_max_size << endl;
config << endl;
// Write service settings
config << "# Services\n";
config << FLD_CALL_WAITING << '=' << bool2yesno(call_waiting) << endl;
config << FLD_HANGUP_BOTH_3WAY << '=' << bool2yesno(hangup_both_3way) << endl;
config << endl;
// Write startup settings
config << "# Startup\n";
for (list<string>::iterator i = start_user_profiles.begin();
i != start_user_profiles.end(); i++)
{
config << FLD_START_USER_PROFILE << '=' << *i << endl;
}
config << FLD_START_HIDDEN << '=' << bool2yesno(start_hidden) << endl;
config << endl;
// Write network settings
config << "# Network\n";
config << FLD_sip_port << '=' << config_sip_port << endl;
config << FLD_RTP_PORT << '=' << rtp_port << endl;
config << FLD_SIP_MAX_UDP_SIZE << '=' << sip_max_udp_size << endl;
config << FLD_SIP_MAX_TCP_SIZE << '=' << sip_max_tcp_size << endl;
config << endl;
// Write ring tone settings
config << "# Ring tones\n";
config << FLD_PLAY_RINGTONE << '=' << bool2yesno(play_ringtone) << endl;
config << FLD_RINGTONE_FILE << '=' << ringtone_file << endl;
config << FLD_PLAY_RINGBACK << '=' << bool2yesno(play_ringback) << endl;
config << FLD_RINGBACK_FILE << '=' << ringback_file << endl;
config << endl;
// Write MIME settings
config << "# MIME settings\n";
config << FLD_MIME_SHARED_DATABASE << '=' << mime_shared_database << endl;
config << endl;
// Write persistent user interface state
config << "# Persistent user interface state\n";
config << FLD_LAST_USED_PROFILE << '=' << last_used_profile << endl;
config << FLD_REDIAL_URL << '=' << redial_url.encode() << endl;
config << FLD_REDIAL_DISPLAY << '=' << redial_display << endl;
config << FLD_REDIAL_SUBJECT << '=' << redial_subject << endl;
config << FLD_REDIAL_PROFILE << '=' << redial_profile << endl;
config << FLD_REDIAL_HIDE_USER << '=' << bool2yesno(redial_hide_user) << endl;
config << FLD_SHOW_DISPLAY << '=' << bool2yesno(show_display) << endl;
//config << FLD_COMPACT_LINE_STATUS << '=' << bool2yesno(compact_line_status) << endl;
config << FLD_SHOW_BUDDY_LIST << '=' << bool2yesno(show_buddy_list) << endl;
config << FLD_WARN_HIDE_USER << '=' << bool2yesno(warn_hide_user) << endl;
for (list<string>::iterator i = dial_history.begin();
i != dial_history.end(); i++)
{
config << FLD_DIAL_HISTORY << '=' << *i << endl;
}
config << endl;
// Write session settins
config << "# UI session settings\n";
config << FLD_UI_SESSION_ID << '=' << ui_session_id << endl;
for (list<string>::iterator i = ui_session_active_profiles.begin();
i != ui_session_active_profiles.end(); i++)
{
config << FLD_UI_SESSION_ACTIVE_PROFILE << '=' << *i << endl;
}
config << FLD_UI_SESSION_MAIN_GEOMETRY << '=' << ui_session_main_geometry.encode() << endl;
config << FLD_UI_SESSION_MAIN_HIDDEN << '=' << bool2yesno(ui_session_main_hidden) << endl;
config << FLD_UI_SESSION_MAIN_STATE << '=' << ui_session_main_state << endl;
config << endl;
// Check if writing succeeded
if (!config.good()) {
// Restore backup
config.close();
rename(f_backup.c_str(), filename.c_str());
error_msg = TRANSLATE("File system error while writing file %1 .");
error_msg = replace_first(error_msg, "%1", filename);
mtx_sys.unlock();
return false;
}
mtx_sys.unlock();
return true;
}
list<t_audio_device> t_sys_settings::get_oss_devices(bool playback) const {
struct stat stat_buf;
list<t_audio_device> l;
for (int i = -1; i <= 15; i ++) {
string dev = "/dev/dsp";
if (i >= 0) dev += int2str(i);
t_audio_device oss_dev;
oss_dev.type = t_audio_device::OSS;
// Check if device exists
if (stat(dev.c_str(), &stat_buf) != 0) continue;
oss_dev.device = dev;
// Get sound card name
int fd;
if (playback) {
fd = open(dev.c_str(), O_WRONLY | O_NONBLOCK);
} else {
fd = open(dev.c_str(), O_RDONLY | O_NONBLOCK);
}
if (fd >= 0) {
struct mixer_info soundcard_info;
if (ioctl(fd, SOUND_MIXER_INFO, &soundcard_info) != -1) {
oss_dev.name = "";
oss_dev.name += soundcard_info.name;
oss_dev.name += " (";
oss_dev.name += soundcard_info.id;
oss_dev.name += ")";
}
close(fd);
} else {
if (errno == EBUSY) {
oss_dev.name = TRANSLATE("unknown name (device is busy)");
} else {
// Device is not available.
continue;
}
}
// Check if the device is a symbolic link
char buf[32];
int len_link;
if ((len_link = readlink(dev.c_str(), buf, 31)) != -1) {
buf[len_link] = 0;
oss_dev.sym_link = buf;
}
oss_dev.type = t_audio_device::OSS;
l.push_back(oss_dev);
}
// If no OSS devices can be found (this should not happen), then
// just add /dev/dsp as the default device.
if (l.empty()) {
t_audio_device oss_dev;
oss_dev.device = "/dev/dsp";
oss_dev.type = t_audio_device::OSS;
l.push_back(oss_dev);
}
// Add other device option
t_audio_device other_dev;
other_dev.device = DEV_OTHER;
other_dev.type = t_audio_device::OSS;
l.push_back(other_dev);
return l;
}
#ifdef HAVE_LIBASOUND
// Defined in audio_device.cpp
void alsa_fill_soundcards(list<t_audio_device>& l, bool playback);
list<t_audio_device> t_sys_settings::get_alsa_devices(bool playback) const {
t_audio_device defaultDevice;
defaultDevice.device = "default";
defaultDevice.name = TRANSLATE("Default device");
defaultDevice.type = t_audio_device::ALSA;
list<t_audio_device> l;
l.push_back(defaultDevice);
alsa_fill_soundcards(l, playback);
// Add other device option
t_audio_device other_dev;
other_dev.device = DEV_OTHER;
other_dev.type = t_audio_device::ALSA;
l.push_back(other_dev);
return l;
}
#endif
list<t_audio_device> t_sys_settings::get_audio_devices(bool playback) const {
list<t_audio_device> d, d0;
#ifdef HAVE_LIBASOUND
d = get_alsa_devices(playback);
#endif
d0 = get_oss_devices(playback);
d.insert(d.end(), d0.begin(), d0.end());
return d;
}
bool t_sys_settings::equal_audio_dev(const t_audio_device &dev1, const t_audio_device &dev2) const {
if (dev1.type == t_audio_device::OSS) {
if (dev2.type != t_audio_device::OSS) return false;
if (dev1.device == dev2.device) return true;
char symlink1[32], symlink2[32];
int len_link1, len_link2;
len_link1 = readlink(dev1.device.c_str(), symlink1, 31);
len_link2 = readlink(dev2.device.c_str(), symlink2, 31);
if (len_link1 > 0) {
symlink1[len_link1] = 0;
string symdev1 = "/dev/";
symdev1 += symlink1;
if (len_link2 > 0) {
symlink2[len_link2] = 0;
string symdev2 = "/dev/";
symdev2 += symlink2;
return symdev1 == symdev2;
} else {
return dev2.device == symdev1;
}
} else {
if (len_link2 > 0) {
symlink2[len_link2] = 0;
string symdev2 = "/dev/";
symdev2 += symlink2;
return dev1.device == symdev2;
}
}
} else if (dev1.type == t_audio_device::ALSA) {
if (dev2.type != t_audio_device::ALSA) return false;
return dev1.device == dev2.device;
}
return false;
}
t_audio_device t_sys_settings::audio_device(string device) {
t_audio_device d;
if (device.empty()) device = DEV_DSP; //This is the default device
if (device.substr(0, strlen(PFX_OSS)) == PFX_OSS) {
// OSS device
d.device = device.substr(strlen(PFX_OSS));
d.type = t_audio_device::OSS;
d.name = "";
char symlink[32];
int len_link = readlink(device.c_str(), symlink, 31);
if(len_link > 0) {
d.sym_link = symlink;
}
} else if (device.substr(0, strlen(PFX_ALSA)) == PFX_ALSA) {
// ALSA device
d.device = device.substr(strlen(PFX_ALSA));
d.type = t_audio_device::ALSA;
d.name = "";
d.sym_link = "";
} else {
// Assume it is an OSS device. Version 0.2.1 and lower
// only supported OSS and the value only consisted of
// the device name without "oss:"
d.device = device;
d.type = t_audio_device::OSS;
d.name = "";
char symlink[32];
int len_link = readlink(device.c_str(), symlink, 31);
if(len_link > 0) {
d.sym_link = symlink;
}
}
return d;
}
bool t_sys_settings::exec_audio_validation(bool ringtone, bool speaker, bool mic,
string &error_msg) const
{
error_msg.clear();
if (!validate_audio_dev) return true;
bool valid = true;
bool full_duplex = speaker && mic && equal_audio_dev(dev_speaker, dev_mic);
if (ringtone && !t_audio_io::validate(dev_ringtone, true, false)) {
string msg = TRANSLATE("Cannot access the ring tone device (%1).");
error_msg += replace_first(msg, "%1", dev_ringtone.get_description());
error_msg += "\n";
valid = false;
}
if (speaker && !t_audio_io::validate(dev_speaker, true, full_duplex)) {
string msg = TRANSLATE("Cannot access the speaker (%1).");
error_msg += replace_first(msg, "%1", dev_speaker.get_description());
error_msg += "\n";
valid = false;
}
if (mic && !t_audio_io::validate(dev_mic, full_duplex, true)) {
string msg = TRANSLATE("Cannot access the microphone (%1).");
error_msg += replace_first(msg, "%1", dev_mic.get_description());
error_msg += "\n";
valid = false;
}
return valid;
}
unsigned short t_sys_settings::get_sip_port(bool force_active) {
mtx_sys.lock();
// The configured port becomes the active port after first
// usage of the port.
if (!active_sip_port || force_active) {
if (override_sip_port > 0) {
// The port provided on the command line overrides
// the configured port.
active_sip_port = override_sip_port;
} else {
active_sip_port = config_sip_port;
}
}
mtx_sys.unlock();
return active_sip_port;
}
|