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
|
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <iostream>
#include <fstream>
#include <stdexcept>
#include "rutil/Log.hxx"
#include "rutil/Logger.hxx"
#include "rutil/DnsUtil.hxx"
#include "rutil/dns/DnsStub.hxx"
#include "rutil/GeneralCongestionManager.hxx"
#include "resip/stack/SipStack.hxx"
#include "resip/stack/Compression.hxx"
#include "resip/stack/EventStackThread.hxx"
#include "resip/stack/InteropHelper.hxx"
#include "resip/stack/ConnectionManager.hxx"
#include "resip/dum/InMemorySyncRegDb.hxx"
#include "resip/dum/MasterProfile.hxx"
#include "resip/dum/DialogUsageManager.hxx"
#include "resip/dum/DumThread.hxx"
#include "resip/dum/TlsPeerAuthManager.hxx"
#include "repro/AsyncProcessorWorker.hxx"
#include "repro/ReproRunner.hxx"
#include "repro/Proxy.hxx"
#include "repro/ProxyConfig.hxx"
#include "repro/BerkeleyDb.hxx"
#include "repro/Dispatcher.hxx"
#include "repro/UserAuthGrabber.hxx"
#include "repro/ProcessorChain.hxx"
#include "repro/ReproVersion.hxx"
#include "repro/WebAdmin.hxx"
#include "repro/WebAdminThread.hxx"
#include "repro/Registrar.hxx"
#include "repro/ReproServerAuthManager.hxx"
#include "repro/RegSyncClient.hxx"
#include "repro/RegSyncServer.hxx"
#include "repro/RegSyncServerThread.hxx"
#include "repro/CommandServer.hxx"
#include "repro/CommandServerThread.hxx"
#include "repro/monkeys/IsTrustedNode.hxx"
#include "repro/monkeys/AmIResponsible.hxx"
#include "repro/monkeys/DigestAuthenticator.hxx"
#include "repro/monkeys/LocationServer.hxx"
#include "repro/monkeys/RecursiveRedirect.hxx"
#include "repro/monkeys/SimpleStaticRoute.hxx"
#include "repro/monkeys/StaticRoute.hxx"
#include "repro/monkeys/StrictRouteFixup.hxx"
#include "repro/monkeys/OutboundTargetHandler.hxx"
#include "repro/monkeys/QValueTargetHandler.hxx"
#include "repro/monkeys/SimpleTargetHandler.hxx"
#include "repro/monkeys/GeoProximityTargetSorter.hxx"
#include "repro/monkeys/RequestFilter.hxx"
#include "repro/monkeys/MessageSilo.hxx"
#include "repro/monkeys/CertificateAuthenticator.hxx"
#if defined(USE_SSL)
#include "repro/stateAgents/CertServer.hxx"
#include "resip/stack/ssl/Security.hxx"
#endif
#if defined(USE_MYSQL)
#include "repro/MySqlDb.hxx"
#endif
#include "rutil/WinLeakCheck.hxx"
#define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
using namespace resip;
using namespace repro;
using namespace std;
class ReproLogger : public ExternalLogger
{
public:
virtual ~ReproLogger() {}
/** return true to also do default logging, false to supress default logging. */
virtual bool operator()(Log::Level level,
const Subsystem& subsystem,
const Data& appName,
const char* file,
int line,
const Data& message,
const Data& messageWithHeaders)
{
// Log any errors to the screen
if(level <= Log::Err)
{
resipCout << messageWithHeaders << endl;
}
return true;
}
};
ReproLogger g_ReproLogger;
ReproRunner::ReproRunner()
: mRunning(false)
, mRestarting(false)
, mThreadedStack(false)
, mSipAuthDisabled(false)
, mUseV4(true)
, mUseV6 (false)
, mRegSyncPort(0)
, mProxyConfig(0)
, mFdPollGrp(0)
, mAsyncProcessHandler(0)
, mSipStack(0)
, mStackThread(0)
, mAbstractDb(0)
, mRuntimeAbstractDb(0)
, mRegistrationPersistenceManager(0)
, mAuthRequestDispatcher(0)
, mAsyncProcessorDispatcher(0)
, mMonkeys(0)
, mLemurs(0)
, mBaboons(0)
, mProxy(0)
, mWebAdmin(0)
, mWebAdminThread(0)
, mRegistrar(0)
, mDum(0)
, mDumThread(0)
, mCertServer(0)
, mRegSyncClient(0)
, mRegSyncServerV4(0)
, mRegSyncServerV6(0)
, mRegSyncServerThread(0)
, mCommandServerV4(0)
, mCommandServerV6(0)
, mCommandServerThread(0)
, mCongestionManager(0)
{
}
ReproRunner::~ReproRunner()
{
if(mRunning) shutdown();
}
bool
ReproRunner::run(int argc, char** argv)
{
if(mRunning) return false;
if(!mRestarting)
{
// Store original arc and argv - so we can reuse them on restart request
mArgc = argc;
mArgv = argv;
}
// Parse command line and configuration file
assert(!mProxyConfig);
Data defaultConfigFilename("repro.config");
try
{
mProxyConfig = new ProxyConfig();
mProxyConfig->parseConfig(mArgc, mArgv, defaultConfigFilename);
}
catch(BaseException& ex)
{
std::cerr << "Error parsing configuration: " << ex << std::endl;
return false;
}
// Non-Windows server process stuff
if(!mRestarting)
{
setPidFile(mProxyConfig->getConfigData("PidFile", "", true));
if(mProxyConfig->getConfigBool("Daemonize", false))
{
daemonize();
}
}
// Initialize resip logger
GenericLogImpl::MaxByteCount = mProxyConfig->getConfigUnsignedLong("LogFileMaxBytes", 5242880 /*5 Mb */);
Data loggingType = mProxyConfig->getConfigData("LoggingType", "cout", true);
Log::initialize(loggingType,
mProxyConfig->getConfigData("LogLevel", "INFO", true),
mArgv[0],
mProxyConfig->getConfigData("LogFilename", "repro.log", true).c_str(),
isEqualNoCase(loggingType, "file") ? &g_ReproLogger : 0); // if logging to file then write WARNINGS, and Errors to console still
InfoLog( << "Starting repro version " << VersionUtils::instance().releaseVersion() << "...");
// Create SipStack and associated objects
if(!createSipStack())
{
return false;
}
// Create datastore
if(!createDatastore())
{
return false;
}
// Create DialogUsageManager that handles ServerRegistration,
// and potentially certificate subscription server
createDialogUsageManager();
// Create the Proxy and associate objects
if(!createProxy())
{
return false;
}
// Create HTTP WebAdmin and Thread
if(!createWebAdmin())
{
return false;
}
// Create reg sync components if required
createRegSync();
// Create command server if required
if(!mRestarting)
{
createCommandServer();
}
// Make it all go - startup all threads
mThreadedStack = mProxyConfig->getConfigBool("ThreadedStack", true);
if(mThreadedStack)
{
// If configured, then start the sub-threads within the stack
mSipStack->run();
}
mStackThread->run();
if(mDumThread)
{
mDumThread->run();
}
mProxy->run();
if(mWebAdminThread)
{
mWebAdminThread->run();
}
if(!mRestarting && mCommandServerThread)
{
mCommandServerThread->run();
}
if(mRegSyncServerThread)
{
mRegSyncServerThread->run();
}
if(mRegSyncClient)
{
mRegSyncClient->run();
}
mRunning = true;
return true;
}
void
ReproRunner::shutdown()
{
if(!mRunning) return;
// Tell all threads to shutdown
if(mWebAdminThread)
{
mWebAdminThread->shutdown();
}
if(mDumThread)
{
mDumThread->shutdown();
}
mProxy->shutdown();
mStackThread->shutdown();
if(!mRestarting && mCommandServerThread) // leave command server running if we are restarting
{
mCommandServerThread->shutdown();
}
if(mRegSyncServerThread)
{
mRegSyncServerThread->shutdown();
}
if(mRegSyncClient)
{
mRegSyncClient->shutdown();
}
// Wait for all threads to shutdown, and destroy objects
mProxy->join();
if(mThreadedStack)
{
mSipStack->shutdownAndJoinThreads();
}
mStackThread->join();
if(mWebAdminThread)
{
mWebAdminThread->join();
}
if(mDumThread)
{
mDumThread->join();
}
if(mAuthRequestDispatcher)
{
// Both proxy and dum threads are down at this point, we can
// destroy the authRequest dispatcher and associated threads now
delete mAuthRequestDispatcher;
mAuthRequestDispatcher = 0;
}
if(mAsyncProcessorDispatcher)
{
// Both proxy and dum threads are down at this point, we can
// destroy the async processor dispatcher and associated threads now
delete mAsyncProcessorDispatcher;
mAsyncProcessorDispatcher = 0;
}
if(!mRestarting && mCommandServerThread) // we leave command server running during restart
{
mCommandServerThread->join();
}
if(mRegSyncServerThread)
{
mRegSyncServerThread->join();
}
if(mRegSyncClient)
{
mRegSyncClient->join();
}
mSipStack->setCongestionManager(0);
cleanupObjects();
mRunning = false;
}
void
ReproRunner::restart()
{
if(!mRunning) return;
mRestarting = true;
shutdown();
run(0, 0);
mRestarting = false;
}
void
ReproRunner::cleanupObjects()
{
delete mCongestionManager; mCongestionManager = 0;
if(!mRestarting)
{
// We leave command server running during restart
delete mCommandServerThread; mCommandServerThread = 0;
delete mCommandServerV6; mCommandServerV6 = 0;
delete mCommandServerV4; mCommandServerV4 = 0;
}
delete mRegSyncServerThread; mRegSyncServerThread = 0;
delete mRegSyncServerV6; mRegSyncServerV6 = 0;
delete mRegSyncServerV4; mRegSyncServerV4 = 0;
delete mRegSyncClient; mRegSyncClient = 0;
#if defined(USE_SSL)
delete mCertServer; mCertServer = 0;
#endif
delete mDumThread; mDumThread = 0;
delete mDum; mDum = 0;
delete mRegistrar; mRegistrar = 0;
delete mWebAdminThread; mWebAdminThread = 0;
delete mWebAdmin; mWebAdmin = 0;
delete mProxy; mProxy = 0;
delete mBaboons; mBaboons = 0;
delete mLemurs; mLemurs = 0;
delete mMonkeys; mMonkeys = 0;
delete mAuthRequestDispatcher; mAuthRequestDispatcher = 0;
delete mAsyncProcessorDispatcher; mAsyncProcessorDispatcher = 0;
if(!mRestarting)
{
// If we are restarting then leave the In Memory Registration database intact
delete mRegistrationPersistenceManager; mRegistrationPersistenceManager = 0;
}
delete mAbstractDb; mAbstractDb = 0;
delete mRuntimeAbstractDb; mRuntimeAbstractDb = 0;
delete mStackThread; mStackThread = 0;
delete mSipStack; mSipStack = 0;
delete mAsyncProcessHandler; mAsyncProcessHandler = 0;
delete mFdPollGrp; mFdPollGrp = 0;
delete mProxyConfig; mProxyConfig = 0;
}
bool
ReproRunner::createSipStack()
{
// Override T1 timer if configured to do so
unsigned long overrideT1 = mProxyConfig->getConfigInt("TimerT1", 0);
if(overrideT1)
{
WarningLog(<< "Overriding T1! (new value is " <<
overrideT1 << ")");
resip::Timer::resetT1(overrideT1);
}
// Create Security (TLS / Certificates) and Compression (SigComp) objects if
// pre-precessor defines are enabled
Security* security = 0;
Compression* compression = 0;
#ifdef USE_SSL
#ifdef WIN32
Data certPath("C:\\sipCerts");
#else
Data certPath(getenv("HOME"));
certPath += "/.sipCerts";
#endif
mProxyConfig->getConfigValue("CertificatePath", certPath);
security = new Security(certPath);
Data caDir;
mProxyConfig->getConfigValue("CADirectory", caDir);
if(!caDir.empty())
{
security->addCADirectory(caDir);
}
Data caFile;
mProxyConfig->getConfigValue("CAFile", caFile);
if(!caFile.empty())
{
security->addCAFile(caFile);
}
#endif
#ifdef USE_SIGCOMP
compression = new Compression(Compression::DEFLATE);
#endif
// Create EventThreadInterruptor used to wake up the stack for
// for reasons other than an Fd signalling
assert(!mFdPollGrp);
mFdPollGrp = FdPollGrp::create();
assert(!mAsyncProcessHandler);
mAsyncProcessHandler = new EventThreadInterruptor(*mFdPollGrp);
// Set Flags that will enable/disable IPv4 and/or IPv6, based on
// configuration and pre-processor flags
mUseV4 = !mProxyConfig->getConfigBool("DisableIPv4", false);
#ifdef USE_IPV6
mUseV6 = mProxyConfig->getConfigBool("EnableIPv6", true);
#else
bool useV6 = false;
#endif
if (mUseV4) InfoLog (<< "V4 enabled");
if (mUseV6) InfoLog (<< "V6 enabled");
// Build DNS Server list from config
DnsStub::NameserverList dnsServers;
std::vector<resip::Data> dnsServersConfig;
mProxyConfig->getConfigValue("DNSServers", dnsServersConfig);
for(std::vector<resip::Data>::iterator it = dnsServersConfig.begin(); it != dnsServersConfig.end(); it++)
{
if((mUseV4 && DnsUtil::isIpV4Address(*it)) || (mUseV6 && DnsUtil::isIpV6Address(*it)))
{
InfoLog(<< "Using DNS Server from config: " << *it);
dnsServers.push_back(Tuple(*it, 0, UNKNOWN_TRANSPORT).toGenericIPAddress());
}
}
// Create the SipStack Object
assert(!mSipStack);
mSipStack = new SipStack(security,
dnsServers,
mAsyncProcessHandler,
/*stateless*/false,
/*socketFunc*/0,
compression,
mFdPollGrp);
// Set any enum suffixes from configuration
std::vector<Data> enumSuffixes;
mProxyConfig->getConfigValue("EnumSuffixes", enumSuffixes);
if (enumSuffixes.size() > 0)
{
mSipStack->setEnumSuffixes(enumSuffixes);
}
// Set any enum domains from configuration
std::map<Data,Data> enumDomains;
std::vector<Data> _enumDomains;
mProxyConfig->getConfigValue("EnumDomains", _enumDomains);
if (enumSuffixes.size() > 0)
{
for(std::vector<Data>::iterator it = _enumDomains.begin(); it != _enumDomains.end(); it++)
{
enumDomains[*it] = *it;
}
mSipStack->setEnumDomains(enumDomains);
}
// Add stack transports
bool allTransportsSpecifyRecordRoute=false;
if(!addTransports(allTransportsSpecifyRecordRoute))
{
cleanupObjects();
return false;
}
// Enable and configure RFC5626 Outbound support
InteropHelper::setOutboundVersion(mProxyConfig->getConfigInt("OutboundVersion", 5626));
InteropHelper::setOutboundSupported(mProxyConfig->getConfigBool("DisableOutbound", false) ? false : true);
InteropHelper::setRRTokenHackEnabled(mProxyConfig->getConfigBool("EnableFlowTokens", false));
InteropHelper::setAssumeFirstHopSupportsOutboundEnabled(mProxyConfig->getConfigBool("AssumeFirstHopSupportsOutbound", false));
Data clientNATDetectionMode = mProxyConfig->getConfigData("ClientNatDetectionMode", "DISABLED");
if(isEqualNoCase(clientNATDetectionMode, "ENABLED"))
{
InteropHelper::setClientNATDetectionMode(InteropHelper::ClientNATDetectionEnabled);
}
else if(isEqualNoCase(clientNATDetectionMode, "PRIVATE_TO_PUBLIC"))
{
InteropHelper::setClientNATDetectionMode(InteropHelper::ClientNATDetectionPrivateToPublicOnly);
}
unsigned long outboundFlowTimer = mProxyConfig->getConfigUnsignedLong("FlowTimer", 0);
if(outboundFlowTimer > 0)
{
InteropHelper::setFlowTimerSeconds(outboundFlowTimer);
ConnectionManager::MinimumGcAge = 7200000; // Timeout connections not related to a flow timer after 2 hours - TODO make configurable
ConnectionManager::EnableAgressiveGc = true;
}
// Check Path and RecordRoute settings, print warning if features are enabled that
// require record-routing and record-route uri(s) is not configured
bool assumePath = mProxyConfig->getConfigBool("AssumePath", false);
bool forceRecordRoute = mProxyConfig->getConfigBool("ForceRecordRouting", false);
Uri recordRouteUri;
mProxyConfig->getConfigValue("RecordRouteUri", recordRouteUri);
if((InteropHelper::getOutboundSupported()
|| InteropHelper::getRRTokenHackEnabled()
|| InteropHelper::getClientNATDetectionMode() != InteropHelper::ClientNATDetectionDisabled
|| assumePath
|| forceRecordRoute
)
&& !(allTransportsSpecifyRecordRoute || !recordRouteUri.host().empty()))
{
CritLog(<< "In order for outbound support, the Record-Route flow-token"
" hack, or force-record-route to work, you MUST specify a Record-Route URI. Launching "
"without...");
InteropHelper::setOutboundSupported(false);
InteropHelper::setRRTokenHackEnabled(false);
InteropHelper::setClientNATDetectionMode(InteropHelper::ClientNATDetectionDisabled);
assumePath = false;
forceRecordRoute=false;
}
// Configure misc. stack settings
mSipStack->setFixBadDialogIdentifiers(false);
mSipStack->setFixBadCSeqNumbers(false);
int statsLogInterval = mProxyConfig->getConfigInt("StatisticsLogInterval", 60);
if(statsLogInterval > 0)
{
mSipStack->setStatisticsInterval(statsLogInterval);
mSipStack->statisticsManagerEnabled() = true;
}
else
{
mSipStack->statisticsManagerEnabled() = false;
}
// Create Congestion Manager, if required
assert(!mCongestionManager);
if(mProxyConfig->getConfigBool("CongestionManagement", true))
{
Data metricData = mProxyConfig->getConfigData("CongestionManagementMetric", "WAIT_TIME", true);
GeneralCongestionManager::MetricType metric = GeneralCongestionManager::WAIT_TIME;
if(isEqualNoCase(metricData, "TIME_DEPTH"))
{
metric = GeneralCongestionManager::TIME_DEPTH;
}
else if(isEqualNoCase(metricData, "SIZE"))
{
metric = GeneralCongestionManager::SIZE;
}
else if(!isEqualNoCase(metricData, "WAIT_TIME"))
{
WarningLog( << "CongestionManagementMetric specified as an unknown value (" << metricData << "), defaulting to WAIT_TIME.");
}
mCongestionManager = new GeneralCongestionManager(
metric,
mProxyConfig->getConfigUnsignedLong("CongestionManagementTolerance", 200));
mSipStack->setCongestionManager(mCongestionManager);
}
// Create base thread to run stack in (note: stack may use other sub-threads, depending on configuration)
assert(!mStackThread);
mStackThread = new EventStackThread(*mSipStack,
*dynamic_cast<EventThreadInterruptor*>(mAsyncProcessHandler),
*mFdPollGrp);
return true;
}
bool
ReproRunner::createDatastore()
{
// Create Database access objects
assert(!mAbstractDb);
assert(!mRuntimeAbstractDb);
#ifdef USE_MYSQL
Data mySQLServer;
mProxyConfig->getConfigValue("MySQLServer", mySQLServer);
if(!mySQLServer.empty())
{
mAbstractDb = new MySqlDb(mySQLServer,
mProxyConfig->getConfigData("MySQLUser", ""),
mProxyConfig->getConfigData("MySQLPassword", ""),
mProxyConfig->getConfigData("MySQLDatabaseName", ""),
mProxyConfig->getConfigUnsignedLong("MySQLPort", 0),
mProxyConfig->getConfigData("MySQLCustomUserAuthQuery", ""));
}
Data runtimeMySQLServer;
mProxyConfig->getConfigValue("RuntimeMySQLServer", runtimeMySQLServer);
if(!runtimeMySQLServer.empty())
{
mRuntimeAbstractDb = new MySqlDb(runtimeMySQLServer,
mProxyConfig->getConfigData("RuntimeMySQLUser", ""),
mProxyConfig->getConfigData("RuntimeMySQLPassword", ""),
mProxyConfig->getConfigData("RuntimeMySQLDatabaseName", ""),
mProxyConfig->getConfigUnsignedLong("RuntimeMySQLPort", 0),
mProxyConfig->getConfigData("MySQLCustomUserAuthQuery", ""));
}
#endif
if (!mAbstractDb)
{
mAbstractDb = new BerkeleyDb(mProxyConfig->getConfigData("DatabasePath", "./", true));
}
assert(mAbstractDb);
if(!mAbstractDb->isSane())
{
CritLog(<<"Failed to open configuration database");
cleanupObjects();
return false;
}
if(mRuntimeAbstractDb && !mRuntimeAbstractDb->isSane())
{
CritLog(<<"Failed to open runtime configuration database");
cleanupObjects();
return false;
}
mProxyConfig->createDataStore(mAbstractDb, mRuntimeAbstractDb);
// Create ImMemory Registration Database
mRegSyncPort = mProxyConfig->getConfigInt("RegSyncPort", 0);
// We only need removed records to linger if we have reg sync enabled
if(!mRestarting) // If we are restarting then we left the InMemoryRegistrationDb intact at shutdown - don't recreate
{
assert(!mRegistrationPersistenceManager);
mRegistrationPersistenceManager = new InMemorySyncRegDb(mRegSyncPort ? 86400 /* 24 hours */ : 0 /* removeLingerSecs */); // !slg! could make linger time a setting
}
assert(mRegistrationPersistenceManager);
// Copy contacts from the StaticRegStore to the RegistrationPersistanceManager
populateRegistrations();
return true;
}
void
ReproRunner::createDialogUsageManager()
{
// Create Profile settings for DUM Instance that handles ServerRegistration,
// and potentially certificate subscription server
SharedPtr<MasterProfile> profile(new MasterProfile);
profile->clearSupportedMethods();
profile->addSupportedMethod(resip::REGISTER);
#ifdef USE_SSL
profile->addSupportedScheme(Symbols::Sips);
#endif
if(InteropHelper::getOutboundSupported())
{
profile->addSupportedOptionTag(Token(Symbols::Outbound));
}
profile->addSupportedOptionTag(Token(Symbols::Path));
if(mProxyConfig->getConfigBool("AllowBadReg", false))
{
profile->allowBadRegistrationEnabled() = true;
}
// Create DialogeUsageManager if Registrar or Certificate Server are enabled
assert(!mRegistrar);
assert(!mDum);
assert(!mDumThread);
mRegistrar = new Registrar;
resip::MessageFilterRuleList ruleList;
bool registrarEnabled = !mProxyConfig->getConfigBool("DisableRegistrar", false);
bool certServerEnabled = mProxyConfig->getConfigBool("EnableCertServer", false);
if (registrarEnabled || certServerEnabled)
{
mDum = new DialogUsageManager(*mSipStack);
mDum->setMasterProfile(profile);
addDomains(*mDum, false /* log? already logged when adding to Proxy - no need to log again*/);
}
// If registrar is enabled, configure DUM to handle REGISTER requests
if (registrarEnabled)
{
assert(mDum);
assert(mRegistrationPersistenceManager);
mDum->setServerRegistrationHandler(mRegistrar);
mDum->setRegistrationPersistenceManager(mRegistrationPersistenceManager);
// Install rules so that the registrar only gets REGISTERs
resip::MessageFilterRule::MethodList methodList;
methodList.push_back(resip::REGISTER);
ruleList.push_back(MessageFilterRule(resip::MessageFilterRule::SchemeList(),
resip::MessageFilterRule::DomainIsMe,
methodList) );
}
// If Certificate Server is enabled, configure DUM to handle SUBSCRIBE and
// PUBLISH requests for events: credential and certificate
assert(!mCertServer);
if (certServerEnabled)
{
#if defined(USE_SSL)
mCertServer = new CertServer(*mDum);
// Install rules so that the cert server receives SUBSCRIBEs and PUBLISHs
resip::MessageFilterRule::MethodList methodList;
resip::MessageFilterRule::EventList eventList;
methodList.push_back(resip::SUBSCRIBE);
methodList.push_back(resip::PUBLISH);
eventList.push_back(resip::Symbols::Credential);
eventList.push_back(resip::Symbols::Certificate);
ruleList.push_back(MessageFilterRule(resip::MessageFilterRule::SchemeList(),
resip::MessageFilterRule::DomainIsMe,
methodList,
eventList));
#endif
}
if (mDum)
{
bool enableCertAuth = mProxyConfig->getConfigBool("EnableCertificateAuthenticator", false);
// Maintains existing behavior for non-TLS cert auth users
bool digestChallengeThirdParties = !enableCertAuth;
if(enableCertAuth)
{
// TODO: perhaps this should be initialised from the trusted node
// monkey? Or should the list of trusted TLS peers be independent
// from the trusted node list?
std::set<Data> trustedPeers;
loadCommonNameMappings();
SharedPtr<TlsPeerAuthManager> certAuth(new TlsPeerAuthManager(*mDum, mDum->dumIncomingTarget(), trustedPeers, true, mCommonNameMappings));
mDum->addIncomingFeature(certAuth);
}
mSipAuthDisabled = mProxyConfig->getConfigBool("DisableAuth", false);
// If Authentication is enabled, then configure DUM to authenticate requests
if (!mSipAuthDisabled)
{
// Create UserAuthGrabber Worker Thread Pool if auth is enabled
assert(!mAuthRequestDispatcher);
int numAuthGrabberWorkerThreads = mProxyConfig->getConfigInt("NumAuthGrabberWorkerThreads", 2);
if(numAuthGrabberWorkerThreads < 1) numAuthGrabberWorkerThreads = 1; // must have at least one thread
std::auto_ptr<Worker> grabber(new UserAuthGrabber(mProxyConfig->getDataStore()->mUserStore));
mAuthRequestDispatcher = new Dispatcher(grabber, mSipStack, numAuthGrabberWorkerThreads);
SharedPtr<ServerAuthManager>
uasAuth( new ReproServerAuthManager(*mDum,
mAuthRequestDispatcher,
mProxyConfig->getDataStore()->mAclStore,
!mProxyConfig->getConfigBool("DisableAuthInt", false) /*useAuthInt*/,
mProxyConfig->getConfigBool("RejectBadNonces", false),
digestChallengeThirdParties));
mDum->setServerAuthManager(uasAuth);
}
// Set the MessageFilterRuleList on DUM and create a thread to run DUM in
mDum->setMessageFilterRuleList(ruleList);
mDumThread = new DumThread(*mDum);
}
}
bool
ReproRunner::createProxy()
{
// Create AsyncProcessorDispatcher thread pool that is shared by the processsors for
// any asyncronous tasks (ie: RequestFilter and MessageSilo processors)
int numAsyncProcessorWorkerThreads = mProxyConfig->getConfigInt("NumAsyncProcessorWorkerThreads", 2);
if(numAsyncProcessorWorkerThreads > 0)
{
assert(!mAsyncProcessorDispatcher);
mAsyncProcessorDispatcher = new Dispatcher(std::auto_ptr<Worker>(new AsyncProcessorWorker),
mSipStack,
numAsyncProcessorWorkerThreads);
}
// Create proxy processor chains
/* Explanation: "Monkeys" are processors which operate on incoming requests
"Lemurs" are processors which operate on incoming responses
"Baboons" are processors which operate on a request for each target
as the request is about to be forwarded to that target */
// Make Monkeys
assert(!mMonkeys);
mMonkeys = new ProcessorChain(Processor::REQUEST_CHAIN);
makeRequestProcessorChain(*mMonkeys);
InfoLog(<< *mMonkeys);
// Make Lemurs
assert(!mLemurs);
mLemurs = new ProcessorChain(Processor::RESPONSE_CHAIN);
makeResponseProcessorChain(*mLemurs);
InfoLog(<< *mLemurs);
// Make Baboons
assert(!mBaboons);
mBaboons = new ProcessorChain(Processor::TARGET_CHAIN);
makeTargetProcessorChain(*mBaboons);
InfoLog(<< *mBaboons);
// Create main Proxy class
assert(!mProxy);
mProxy = new Proxy(*mSipStack,
*mProxyConfig,
*mMonkeys,
*mLemurs,
*mBaboons);
mHttpRealm = addDomains(*mProxy, true);
// Register the Proxy class a stack transaction user
// Note: This is done after creating the DialogUsageManager so that it acts
// like a catchall and will handle all requests the DUM does not
mSipStack->registerTransactionUser(*mProxy);
return true;
}
void
ReproRunner::populateRegistrations()
{
assert(mRegistrationPersistenceManager);
assert(mProxyConfig);
assert(mProxyConfig->getDataStore());
// Copy contacts from the StaticRegStore to the RegistrationPersistanceManager
StaticRegStore::StaticRegRecordMap& staticRegList = mProxyConfig->getDataStore()->mStaticRegStore.getStaticRegList();
StaticRegStore::StaticRegRecordMap::iterator it = staticRegList.begin();
for(; it != staticRegList.end(); it++)
{
try
{
Uri aor(it->second.mAor);
ContactInstanceRecord rec;
rec.mContact = NameAddr(it->second.mContact);
rec.mSipPath = NameAddrs(it->second.mPath);
rec.mRegExpires = NeverExpire;
rec.mSyncContact = true; // Tag this permanent contact as being a syncronized contact so that it will
// be syncronized to a paired server (this is actually configuration information)
mRegistrationPersistenceManager->updateContact(aor, rec);
}
catch(resip::ParseBuffer::Exception& e)
{
// This should never happen, since the format should be verified before writing to DB
ErrLog(<<"Failed to apply a static registration due to parse error: " << e);
}
}
}
bool
ReproRunner::createWebAdmin()
{
assert(!mWebAdmin);
assert(!mWebAdminThread);
int httpPort = mProxyConfig->getConfigInt("HttpPort", 5080);
if (httpPort)
{
mWebAdmin = new WebAdmin(*mProxy,
*mRegistrationPersistenceManager,
mHttpRealm,
httpPort);
if (!mWebAdmin->isSane())
{
CritLog(<<"Failed to start the WebAdmin");
cleanupObjects();
return false;
}
mWebAdminThread = new WebAdminThread(*mWebAdmin);
}
return true;
}
void
ReproRunner::createRegSync()
{
assert(!mRegSyncClient);
assert(!mRegSyncServerV4);
assert(!mRegSyncServerV6);
assert(!mRegSyncServerThread);
if(mRegSyncPort != 0)
{
std::list<RegSyncServer*> regSyncServerList;
if(mUseV4)
{
mRegSyncServerV4 = new RegSyncServer(dynamic_cast<InMemorySyncRegDb*>(mRegistrationPersistenceManager), mRegSyncPort, V4);
regSyncServerList.push_back(mRegSyncServerV4);
}
if(mUseV6)
{
mRegSyncServerV6 = new RegSyncServer(dynamic_cast<InMemorySyncRegDb*>(mRegistrationPersistenceManager), mRegSyncPort, V6);
regSyncServerList.push_back(mRegSyncServerV6);
}
if(!regSyncServerList.empty())
{
mRegSyncServerThread = new RegSyncServerThread(regSyncServerList);
}
Data regSyncPeerAddress(mProxyConfig->getConfigData("RegSyncPeer", ""));
if(!regSyncPeerAddress.empty())
{
mRegSyncClient = new RegSyncClient(dynamic_cast<InMemorySyncRegDb*>(mRegistrationPersistenceManager), regSyncPeerAddress, mRegSyncPort);
}
}
}
void
ReproRunner::createCommandServer()
{
assert(!mCommandServerV4);
assert(!mCommandServerV6);
assert(!mCommandServerThread);
int commandPort = mProxyConfig->getConfigInt("CommandPort", 5081);
if(commandPort != 0)
{
std::list<CommandServer*> commandServerList;
if(mUseV4)
{
mCommandServerV4 = new CommandServer(*this, commandPort, V4);
commandServerList.push_back(mCommandServerV4);
}
if(mUseV6)
{
mCommandServerV6 = new CommandServer(*this, commandPort, V6);
commandServerList.push_back(mCommandServerV6);
}
if(!commandServerList.empty())
{
mCommandServerThread = new CommandServerThread(commandServerList);
}
}
}
Data
ReproRunner::addDomains(TransactionUser& tu, bool log)
{
assert(mProxyConfig);
Data realm;
std::vector<Data> configDomains;
if(mProxyConfig->getConfigValue("Domains", configDomains))
{
for (std::vector<Data>::const_iterator i=configDomains.begin();
i != configDomains.end(); ++i)
{
if(log) InfoLog (<< "Adding domain " << *i << " from command line");
tu.addDomain(*i);
if ( realm.empty() )
{
realm = *i;
}
}
}
const ConfigStore::ConfigData& dList = mProxyConfig->getDataStore()->mConfigStore.getConfigs();
for (ConfigStore::ConfigData::const_iterator i=dList.begin();
i != dList.end(); ++i)
{
if(log) InfoLog (<< "Adding domain " << i->second.mDomain << " from config");
tu.addDomain( i->second.mDomain );
if ( realm.empty() )
{
realm = i->second.mDomain;
}
}
/* All of this logic has been commented out - the sysadmin must explicitly
add any of the items below to the Domains config option in repro.config
Data localhostname(DnsUtil::getLocalHostName());
if(log) InfoLog (<< "Adding local hostname domain " << localhostname );
tu.addDomain(localhostname);
if ( realm.empty() )
{
realm = localhostname;
}
if(log) InfoLog (<< "Adding localhost domain.");
tu.addDomain("localhost");
if ( realm.empty() )
{
realm = "localhost";
}
list<pair<Data,Data> > ips = DnsUtil::getInterfaces();
for ( list<pair<Data,Data> >::const_iterator i=ips.begin(); i!=ips.end(); i++)
{
if(log) InfoLog( << "Adding domain for IP " << i->second << " from interface " << i->first );
tu.addDomain(i->second);
}
if(log) InfoLog (<< "Adding 127.0.0.1 domain.");
tu.addDomain("127.0.0.1"); */
if( realm.empty() )
realm = "Unconfigured";
return realm;
}
bool
ReproRunner::addTransports(bool& allTransportsSpecifyRecordRoute)
{
assert(mProxyConfig);
assert(mSipStack);
allTransportsSpecifyRecordRoute=false;
bool useEmailAsSIP = mProxyConfig->getConfigBool("TLSUseEmailAsSIP", false);
try
{
// Check if advanced transport settings are provided
unsigned int transportNum = 1;
Data settingKeyBase("Transport" + Data(transportNum));
Data interfaceSettingKey(settingKeyBase + "Interface");
Data interfaceSettings = mProxyConfig->getConfigData(interfaceSettingKey, "", true);
if(!interfaceSettings.empty())
{
// Sample config file format for advanced transport settings
// Transport1Interface = 192.168.1.106:5061
// Transport1Type = TLS
// Transport1TlsDomain = sipdomain.com
// Transport1TlsClientVerification = None
// Transport1RecordRouteUri = sip:sipdomain.com;transport=TLS
// Transport1RcvBufLen = 2000
allTransportsSpecifyRecordRoute = true;
const char *anchor;
while(!interfaceSettings.empty())
{
Data typeSettingKey(settingKeyBase + "Type");
Data tlsDomainSettingKey(settingKeyBase + "TlsDomain");
Data tlsCVMSettingKey(settingKeyBase + "TlsClientVerification");
Data recordRouteUriSettingKey(settingKeyBase + "RecordRouteUri");
Data rcvBufSettingKey(settingKeyBase + "RcvBufLen");
// Parse out interface settings
ParseBuffer pb(interfaceSettings);
anchor = pb.position();
pb.skipToChar(':');
if(!pb.eof())
{
Data ipAddr;
Data portData;
pb.data(ipAddr, anchor);
pb.skipChar();
anchor = pb.position();
pb.skipToEnd();
pb.data(portData, anchor);
if(!DnsUtil::isIpAddress(ipAddr))
{
CritLog(<< "Malformed IP-address found in " << interfaceSettingKey << " setting: " << ipAddr);
}
int port = portData.convertInt();
if(port == 0)
{
CritLog(<< "Invalid port found in " << interfaceSettingKey << " setting: " << port);
}
TransportType tt = Tuple::toTransport(mProxyConfig->getConfigData(typeSettingKey, "UDP"));
if(tt == UNKNOWN_TRANSPORT)
{
CritLog(<< "Unknown transport type found in " << typeSettingKey << " setting: " << mProxyConfig->getConfigData(typeSettingKey, "UDP"));
}
Data tlsDomain = mProxyConfig->getConfigData(tlsDomainSettingKey, "");
Data tlsCVMValue = mProxyConfig->getConfigData(tlsCVMSettingKey, "NONE");
SecurityTypes::TlsClientVerificationMode cvm = SecurityTypes::None;
if(isEqualNoCase(tlsCVMValue, "Optional"))
{
cvm = SecurityTypes::Optional;
}
else if(isEqualNoCase(tlsCVMValue, "Mandatory"))
{
cvm = SecurityTypes::Mandatory;
}
else if(!isEqualNoCase(tlsCVMValue, "None"))
{
CritLog(<< "Unknown TLS client verification mode found in " << tlsCVMSettingKey << " setting: " << tlsCVMValue);
}
int rcvBufLen = mProxyConfig->getConfigInt(rcvBufSettingKey, 0);
Transport *t = mSipStack->addTransport(tt,
port,
DnsUtil::isIpV6Address(ipAddr) ? V6 : V4,
StunEnabled,
ipAddr, // interface to bind to
tlsDomain,
Data::Empty, // private key passphrase - not currently used
SecurityTypes::TLSv1, // sslType
0, // transport flags
cvm, // tls client verification mode
useEmailAsSIP);
if (t && rcvBufLen>0 )
{
#if defined(RESIP_SIPSTACK_HAVE_FDPOLL)
// this new method is part of the epoll changeset,
// which isn't commited yet.
t->setRcvBufLen(rcvBufLen);
#else
assert(0);
#endif
}
Data recordRouteUri = mProxyConfig->getConfigData(recordRouteUriSettingKey, "");
if(!recordRouteUri.empty())
{
try
{
if(isEqualNoCase(recordRouteUri, "auto")) // auto generated record route uri
{
if(tt == TLS || tt == DTLS)
{
NameAddr rr;
rr.uri().host()=tlsDomain;
rr.uri().port()=port;
rr.uri().param(resip::p_transport)=resip::Tuple::toDataLower(tt);
t->setRecordRoute(rr);
InfoLog (<< "Transport specific record-route enabled (generated): " << rr);
}
else
{
NameAddr rr;
rr.uri().host()=ipAddr;
rr.uri().port()=port;
rr.uri().param(resip::p_transport)=resip::Tuple::toDataLower(tt);
t->setRecordRoute(rr);
InfoLog (<< "Transport specific record-route enabled (generated): " << rr);
}
}
else
{
NameAddr rr(recordRouteUri);
t->setRecordRoute(rr);
InfoLog (<< "Transport specific record-route enabled: " << rr);
}
}
catch(BaseException& e)
{
ErrLog (<< "Invalid uri provided in " << recordRouteUriSettingKey << " setting (ignoring): " << e);
allTransportsSpecifyRecordRoute = false;
}
}
else
{
allTransportsSpecifyRecordRoute = false;
}
}
else
{
CritLog(<< "Port not specified in " << interfaceSettingKey << " setting: expected format is <IPAddress>:<Port>");
return false;
}
// Check if there is another transport
transportNum++;
settingKeyBase = Data("Transport" + Data(transportNum));
interfaceSettingKey = Data(settingKeyBase + "Interface");
interfaceSettings = mProxyConfig->getConfigData(interfaceSettingKey, "", true);
}
}
else
{
int udpPort = mProxyConfig->getConfigInt("UDPPort", 5060);
int tcpPort = mProxyConfig->getConfigInt("TCPPort", 5060);
int tlsPort = mProxyConfig->getConfigInt("TLSPort", 5061);
int dtlsPort = mProxyConfig->getConfigInt("DTLSPort", 0);
Data tlsDomain = mProxyConfig->getConfigData("TLSDomainName", "");
Data tlsCVMValue = mProxyConfig->getConfigData("TLSClientVerification", "NONE");
SecurityTypes::TlsClientVerificationMode cvm = SecurityTypes::None;
if(isEqualNoCase(tlsCVMValue, "Optional"))
{
cvm = SecurityTypes::Optional;
}
else if(isEqualNoCase(tlsCVMValue, "Mandatory"))
{
cvm = SecurityTypes::Mandatory;
}
else if(!isEqualNoCase(tlsCVMValue, "None"))
{
CritLog(<< "Unknown TLS client verification mode found in TLSClientVerification setting: " << tlsCVMValue);
}
if (udpPort)
{
if (mUseV4) mSipStack->addTransport(UDP, udpPort, V4, StunEnabled);
if (mUseV6) mSipStack->addTransport(UDP, udpPort, V6, StunEnabled);
}
if (tcpPort)
{
if (mUseV4) mSipStack->addTransport(TCP, tcpPort, V4, StunEnabled);
if (mUseV6) mSipStack->addTransport(TCP, tcpPort, V6, StunEnabled);
}
if (tlsPort)
{
if (mUseV4) mSipStack->addTransport(TLS, tlsPort, V4, StunEnabled, Data::Empty, tlsDomain, Data::Empty, SecurityTypes::TLSv1, 0, cvm, useEmailAsSIP);
if (mUseV6) mSipStack->addTransport(TLS, tlsPort, V6, StunEnabled, Data::Empty, tlsDomain, Data::Empty, SecurityTypes::TLSv1, 0, cvm, useEmailAsSIP);
}
if (dtlsPort)
{
if (mUseV4) mSipStack->addTransport(DTLS, dtlsPort, V4, StunEnabled, Data::Empty, tlsDomain);
if (mUseV6) mSipStack->addTransport(DTLS, dtlsPort, V6, StunEnabled, Data::Empty, tlsDomain);
}
}
}
catch (BaseException& e)
{
std::cerr << "Likely a port is already in use" << endl;
InfoLog (<< "Caught: " << e);
return false;
}
return true;
}
void
ReproRunner::addProcessor(repro::ProcessorChain& chain, std::auto_ptr<Processor> processor)
{
chain.addProcessor(processor);
}
void
ReproRunner::loadCommonNameMappings()
{
// Already loaded?
if(!mCommonNameMappings.empty())
return;
Data mappingsFileName = mProxyConfig->getConfigData("CommonNameMappings", "");
if(mappingsFileName.empty())
return;
InfoLog(<< "trying to load common name mappings from file: " << mappingsFileName);
ifstream mappingsFile(mappingsFileName.c_str());
if(!mappingsFile)
{
ErrLog(<< "failed to open mappings file: " << mappingsFileName << ", aborting");
throw std::runtime_error("Error opening/reading mappings file");
}
string sline;
while(getline(mappingsFile, sline))
{
Data line(sline);
Data cn;
PermittedFromAddresses permitted;
ParseBuffer pb(line);
pb.skipWhitespace();
const char * anchor = pb.position();
if(pb.eof() || *anchor == '#') continue; // if line is a comment or blank then skip it
// Look for end of name
pb.skipToOneOf("\t");
pb.data(cn, anchor);
pb.skipChar('\t');
while(!pb.eof())
{
pb.skipWhitespace();
if(pb.eof())
continue;
Data value;
anchor = pb.position();
pb.skipToOneOf(",\r\n ");
pb.data(value, anchor);
if(!value.empty())
{
StackLog(<< "Loading CN '" << cn << "', found mapping '" << value << "'");
permitted.insert(value);
}
if(!pb.eof())
pb.skipChar();
}
DebugLog(<< "Loaded mapping for CN '" << cn << "', " << permitted.size() << " mapping(s)");
mCommonNameMappings[cn] = permitted;
}
}
void // Monkeys
ReproRunner::makeRequestProcessorChain(ProcessorChain& chain)
{
assert(mProxyConfig);
assert(mRegistrationPersistenceManager);
// Add strict route fixup monkey
addProcessor(chain, std::auto_ptr<Processor>(new StrictRouteFixup));
// Add is trusted node monkey
addProcessor(chain, std::auto_ptr<Processor>(new IsTrustedNode(*mProxyConfig)));
// Add Certificate Authenticator - if required
if(mProxyConfig->getConfigBool("EnableCertificateAuthenticator", false))
{
// TODO: perhaps this should be initialised from the trusted node
// monkey? Or should the list of trusted TLS peers be independent
// from the trusted node list?
// Should we used the same trustedPeers object that was
// passed to TlsPeerAuthManager perhaps?
std::set<Data> trustedPeers;
loadCommonNameMappings();
addProcessor(chain, std::auto_ptr<Processor>(new CertificateAuthenticator(*mProxyConfig, mSipStack, trustedPeers, true, mCommonNameMappings)));
}
// Add digest authenticator monkey - if required
if (!mSipAuthDisabled)
{
assert(mAuthRequestDispatcher);
DigestAuthenticator* da = new DigestAuthenticator(*mProxyConfig, mAuthRequestDispatcher);
addProcessor(chain, std::auto_ptr<Processor>(da));
}
// Add am I responsible monkey
addProcessor(chain, std::auto_ptr<Processor>(new AmIResponsible));
// Add RequestFilter monkey
if(!mProxyConfig->getConfigBool("DisableRequestFilterProcessor", false))
{
if(mAsyncProcessorDispatcher)
{
addProcessor(chain, std::auto_ptr<Processor>(new RequestFilter(*mProxyConfig, mAsyncProcessorDispatcher)));
}
else
{
WarningLog(<< "Could not start RequestFilter Processor due to no worker thread pool (NumAsyncProcessorWorkerThreads=0)");
}
}
// [TODO] support for GRUU is on roadmap. When it is added the GruuMonkey will go here
// [TODO] support for Manipulating Tel URIs is on the roadmap.
// When added, the telUriMonkey will go here
std::vector<Data> routeSet;
mProxyConfig->getConfigValue("Routes", routeSet);
if (routeSet.empty())
{
// add static route monkey
addProcessor(chain, std::auto_ptr<Processor>(new StaticRoute(*mProxyConfig)));
}
else
{
// add simple static route monkey
addProcessor(chain, std::auto_ptr<Processor>(new SimpleStaticRoute(*mProxyConfig)));
}
// Add location server monkey
addProcessor(chain, std::auto_ptr<Processor>(new LocationServer(*mProxyConfig, *mRegistrationPersistenceManager, mAuthRequestDispatcher)));
// Add message silo monkey
if(mProxyConfig->getConfigBool("MessageSiloEnabled", false))
{
if(mAsyncProcessorDispatcher && mRegistrar)
{
MessageSilo* silo = new MessageSilo(*mProxyConfig, mAsyncProcessorDispatcher);
mRegistrar->addRegistrarHandler(silo);
addProcessor(chain, std::auto_ptr<Processor>(silo));
}
else
{
WarningLog(<< "Could not start MessageSilo Processor due to no worker thread pool (NumAsyncProcessorWorkerThreads=0) or Registrar");
}
}
}
void // Lemurs
ReproRunner::makeResponseProcessorChain(ProcessorChain& chain)
{
assert(mProxyConfig);
assert(mRegistrationPersistenceManager);
// Add outbound target handler lemur
addProcessor(chain, std::auto_ptr<Processor>(new OutboundTargetHandler(*mRegistrationPersistenceManager)));
if (mProxyConfig->getConfigBool("RecursiveRedirect", false))
{
// Add recursive redirect lemur
addProcessor(chain, std::auto_ptr<Processor>(new RecursiveRedirect));
}
}
void // Baboons
ReproRunner::makeTargetProcessorChain(ProcessorChain& chain)
{
assert(mProxyConfig);
#ifndef RESIP_FIXED_POINT
if(mProxyConfig->getConfigBool("GeoProximityTargetSorting", false))
{
addProcessor(chain, std::auto_ptr<Processor>(new GeoProximityTargetSorter(*mProxyConfig)));
}
#endif
if(mProxyConfig->getConfigBool("QValue", true))
{
// Add q value target handler baboon
addProcessor(chain, std::auto_ptr<Processor>(new QValueTargetHandler(*mProxyConfig)));
}
// Add simple target handler baboon
addProcessor(chain, std::auto_ptr<Processor>(new SimpleTargetHandler));
}
/* ====================================================================
* The Vovida Software License, Version 1.0
*
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
* and "Vovida Open Communication Application Library (VOCAL)" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact vocal@vovida.org.
*
* 4. Products derived from this software may not be called "VOCAL", nor
* may "VOCAL" appear in their name, without prior written
* permission of Vovida Networks, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* ====================================================================
*/
|