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
|
#include "PrecompiledHeadersServer.h"
#include "OrthancRestApi/OrthancRestApi.h"
#include "../../OrthancFramework/Sources/Compatibility.h"
#include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
#include "../../OrthancFramework/Sources/DicomNetworking/DicomAssociationParameters.h"
#include "../../OrthancFramework/Sources/DicomNetworking/DicomServer.h"
#include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
#include "../../OrthancFramework/Sources/FileStorage/MemoryStorageArea.h"
#include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpHandler.h"
#include "../../OrthancFramework/Sources/HttpServer/HttpServer.h"
#include "../../OrthancFramework/Sources/Logging.h"
#include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h"
#include "../Plugins/Engine/OrthancPlugins.h"
#include "Database/SQLiteDatabaseWrapper.h"
#include "EmbeddedResourceHttpHandler.h"
#include "OrthancConfiguration.h"
#include "OrthancFindRequestHandler.h"
#include "OrthancGetRequestHandler.h"
#include "OrthancInitialization.h"
#include "OrthancMoveRequestHandler.h"
#include "OrthancWebDav.h"
#include "ServerContext.h"
#include "ServerJobs/StorageCommitmentScpJob.h"
#include "ServerToolbox.h"
#include "StorageCommitmentReports.h"
#include <boost/algorithm/string/predicate.hpp>
using namespace Orthanc;
static const char* const KEY_DICOM_TLS_PRIVATE_KEY = "DicomTlsPrivateKey";
static const char* const KEY_DICOM_TLS_ENABLED = "DicomTlsEnabled";
static const char* const KEY_DICOM_TLS_CERTIFICATE = "DicomTlsCertificate";
static const char* const KEY_DICOM_TLS_TRUSTED_CERTIFICATES = "DicomTlsTrustedCertificates";
static const char* const KEY_MAXIMUM_PDU_LENGTH = "MaximumPduLength";
class OrthancStoreRequestHandler : public IStoreRequestHandler
{
private:
ServerContext& context_;
public:
explicit OrthancStoreRequestHandler(ServerContext& context) :
context_(context)
{
}
virtual void Handle(DcmDataset& dicom,
const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet) ORTHANC_OVERRIDE
{
std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromDcmDataset(dicom));
if (toStore->GetBufferSize() > 0)
{
toStore->SetOrigin(DicomInstanceOrigin::FromDicomProtocol
(remoteIp.c_str(), remoteAet.c_str(), calledAet.c_str()));
std::string id;
context_.Store(id, *toStore, StoreInstanceMode_Default);
}
}
};
class OrthancStorageCommitmentRequestHandler : public IStorageCommitmentRequestHandler
{
private:
ServerContext& context_;
public:
explicit OrthancStorageCommitmentRequestHandler(ServerContext& context) :
context_(context)
{
}
virtual void HandleRequest(const std::string& transactionUid,
const std::vector<std::string>& referencedSopClassUids,
const std::vector<std::string>& referencedSopInstanceUids,
const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet) ORTHANC_OVERRIDE
{
if (referencedSopClassUids.size() != referencedSopInstanceUids.size())
{
throw OrthancException(ErrorCode_InternalError);
}
std::unique_ptr<StorageCommitmentScpJob> job(
new StorageCommitmentScpJob(context_, transactionUid, remoteAet, calledAet));
for (size_t i = 0; i < referencedSopClassUids.size(); i++)
{
job->AddInstance(referencedSopClassUids[i], referencedSopInstanceUids[i]);
}
job->MarkAsReady();
context_.GetJobsEngine().GetRegistry().Submit(job.release(), 0 );
}
virtual void HandleReport(const std::string& transactionUid,
const std::vector<std::string>& successSopClassUids,
const std::vector<std::string>& successSopInstanceUids,
const std::vector<std::string>& failedSopClassUids,
const std::vector<std::string>& failedSopInstanceUids,
const std::vector<StorageCommitmentFailureReason>& failureReasons,
const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet) ORTHANC_OVERRIDE
{
if (successSopClassUids.size() != successSopInstanceUids.size() ||
failedSopClassUids.size() != failedSopInstanceUids.size() ||
failedSopClassUids.size() != failureReasons.size())
{
throw OrthancException(ErrorCode_InternalError);
}
std::unique_ptr<StorageCommitmentReports::Report> report(
new StorageCommitmentReports::Report(remoteAet));
for (size_t i = 0; i < successSopClassUids.size(); i++)
{
report->AddSuccess(successSopClassUids[i], successSopInstanceUids[i]);
}
for (size_t i = 0; i < failedSopClassUids.size(); i++)
{
report->AddFailure(failedSopClassUids[i], failedSopInstanceUids[i], failureReasons[i]);
}
report->MarkAsComplete();
context_.GetStorageCommitmentReports().Store(transactionUid, report.release());
}
};
class ModalitiesFromConfiguration : public DicomServer::IRemoteModalities
{
public:
virtual bool IsSameAETitle(const std::string& aet1,
const std::string& aet2) ORTHANC_OVERRIDE
{
OrthancConfiguration::ReaderLock lock;
return lock.GetConfiguration().IsSameAETitle(aet1, aet2);
}
virtual bool LookupAETitle(RemoteModalityParameters& modality,
const std::string& aet) ORTHANC_OVERRIDE
{
OrthancConfiguration::ReaderLock lock;
return lock.GetConfiguration().LookupDicomModalityUsingAETitle(modality, aet);
}
};
class MyDicomServerFactory :
public IStoreRequestHandlerFactory,
public IFindRequestHandlerFactory,
public IMoveRequestHandlerFactory,
public IGetRequestHandlerFactory,
public IStorageCommitmentRequestHandlerFactory
{
private:
ServerContext& context_;
public:
explicit MyDicomServerFactory(ServerContext& context) : context_(context)
{
}
virtual IStoreRequestHandler* ConstructStoreRequestHandler() ORTHANC_OVERRIDE
{
return new OrthancStoreRequestHandler(context_);
}
virtual IFindRequestHandler* ConstructFindRequestHandler() ORTHANC_OVERRIDE
{
std::unique_ptr<OrthancFindRequestHandler> result(new OrthancFindRequestHandler(context_));
{
OrthancConfiguration::ReaderLock lock;
result->SetMaxResults(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0));
result->SetMaxInstances(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0));
}
if (result->GetMaxResults() == 0)
{
LOG(INFO) << "No limit on the number of C-FIND results at the Patient, Study and Series levels";
}
else
{
LOG(INFO) << "Maximum " << result->GetMaxResults()
<< " results for C-FIND queries at the Patient, Study and Series levels";
}
if (result->GetMaxInstances() == 0)
{
LOG(INFO) << "No limit on the number of C-FIND results at the Instance level";
}
else
{
LOG(INFO) << "Maximum " << result->GetMaxInstances()
<< " instances will be returned for C-FIND queries at the Instance level";
}
return result.release();
}
virtual IMoveRequestHandler* ConstructMoveRequestHandler() ORTHANC_OVERRIDE
{
return new OrthancMoveRequestHandler(context_);
}
virtual IGetRequestHandler* ConstructGetRequestHandler() ORTHANC_OVERRIDE
{
return new OrthancGetRequestHandler(context_);
}
virtual IStorageCommitmentRequestHandler* ConstructStorageCommitmentRequestHandler() ORTHANC_OVERRIDE
{
return new OrthancStorageCommitmentRequestHandler(context_);
}
void Done()
{
}
};
class OrthancApplicationEntityFilter : public IApplicationEntityFilter
{
private:
ServerContext& context_;
bool alwaysAllowEcho_;
bool alwaysAllowFind_;
bool alwaysAllowGet_;
bool alwaysAllowStore_;
public:
explicit OrthancApplicationEntityFilter(ServerContext& context) :
context_(context)
{
{
OrthancConfiguration::ReaderLock lock;
alwaysAllowEcho_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowEcho", true);
alwaysAllowFind_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowFind", false);
alwaysAllowGet_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowGet", false);
alwaysAllowStore_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowStore", true);
}
if (alwaysAllowFind_)
{
LOG(WARNING) << "Security risk in DICOM SCP: C-FIND requests are always allowed, even from unknown modalities";
}
if (alwaysAllowGet_)
{
LOG(WARNING) << "Security risk in DICOM SCP: C-GET requests are always allowed, even from unknown modalities";
}
}
virtual bool IsAllowedConnection(const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet) ORTHANC_OVERRIDE
{
LOG(INFO) << "Incoming connection from AET " << remoteAet
<< " on IP " << remoteIp << ", calling AET " << calledAet;
if (alwaysAllowEcho_ ||
alwaysAllowFind_ ||
alwaysAllowGet_ ||
alwaysAllowStore_)
{
return true;
}
else
{
OrthancConfiguration::ReaderLock lock;
return lock.GetConfiguration().IsKnownAETitle(remoteAet, remoteIp);
}
}
virtual bool IsAllowedRequest(const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet,
DicomRequestType type) ORTHANC_OVERRIDE
{
LOG(INFO) << "Incoming " << EnumerationToString(type) << " request from AET "
<< remoteAet << " on IP " << remoteIp << ", calling AET " << calledAet;
if (type == DicomRequestType_Echo &&
alwaysAllowEcho_)
{
return true;
}
else if (type == DicomRequestType_Find &&
alwaysAllowFind_)
{
return true;
}
else if (type == DicomRequestType_Store &&
alwaysAllowStore_)
{
return true;
}
else if (type == DicomRequestType_Get &&
alwaysAllowGet_)
{
return true;
}
else
{
OrthancConfiguration::ReaderLock lock;
std::list<RemoteModalityParameters> modalities;
if (lock.GetConfiguration().LookupDicomModalitiesUsingAETitle(modalities, remoteAet))
{
if (modalities.size() == 1)
{
return modalities.front().IsRequestAllowed(type);
}
else
{
for (std::list<RemoteModalityParameters>::const_iterator it = modalities.begin(); it != modalities.end(); ++it)
{
if (it->GetHost() == remoteIp)
{
return it->IsRequestAllowed(type);
}
}
LOG(WARNING) << "Unable to check DICOM authorization for AET " << remoteAet
<< " on IP " << remoteIp << ", " << modalities.size()
<< " modalites found with this AET but none of them matching the IP";
}
return false;
}
else
{
return false;
}
}
}
virtual void GetAcceptedTransferSyntaxes(std::set<DicomTransferSyntax>& target,
const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet) ORTHANC_OVERRIDE
{
context_.GetAcceptedTransferSyntaxes(target);
}
virtual bool IsUnknownSopClassAccepted(const std::string& remoteIp,
const std::string& remoteAet,
const std::string& calledAet) ORTHANC_OVERRIDE
{
return context_.IsUnknownSopClassAccepted();
}
};
class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter
{
private:
ServerContext& context_;
OrthancPlugins* plugins_;
public:
MyIncomingHttpRequestFilter(ServerContext& context,
OrthancPlugins* plugins) :
context_(context),
plugins_(plugins)
{
}
virtual bool IsValidBearerToken(const std::string& token) ORTHANC_OVERRIDE
{
#if ORTHANC_ENABLE_PLUGINS == 1
return (plugins_ != NULL &&
plugins_->IsValidAuthorizationToken(token));
#else
return false;
#endif
}
virtual bool IsAllowed(HttpMethod method,
const char* uri,
const char* ip,
const char* username,
const HttpToolbox::Arguments& httpHeaders,
const HttpToolbox::GetArguments& getArguments) ORTHANC_OVERRIDE
{
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins_ != NULL &&
!plugins_->IsAllowed(method, uri, ip, username, httpHeaders, getArguments))
{
return false;
}
#endif
static const char* HTTP_FILTER = "IncomingHttpRequestFilter";
LuaScripting::Lock lock(context_.GetLuaScripting());
if (lock.GetLua().IsExistingFunction(HTTP_FILTER))
{
LuaFunctionCall call(lock.GetLua(), HTTP_FILTER);
switch (method)
{
case HttpMethod_Get:
call.PushString("GET");
break;
case HttpMethod_Put:
call.PushString("PUT");
break;
case HttpMethod_Post:
call.PushString("POST");
break;
case HttpMethod_Delete:
call.PushString("DELETE");
break;
default:
return true;
}
call.PushString(uri);
call.PushString(ip);
call.PushString(username);
call.PushStringMap(httpHeaders);
if (!call.ExecutePredicate())
{
LOG(INFO) << "An incoming HTTP request has been discarded by the filter";
return false;
}
}
return true;
}
};
class MyHttpExceptionFormatter : public IHttpExceptionFormatter
{
private:
bool describeErrors_;
OrthancPlugins* plugins_;
public:
MyHttpExceptionFormatter(bool describeErrors,
OrthancPlugins* plugins) :
describeErrors_(describeErrors),
plugins_(plugins)
{
}
virtual void Format(HttpOutput& output,
const OrthancException& exception,
HttpMethod method,
const char* uri) ORTHANC_OVERRIDE
{
{
bool isPlugin = false;
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins_ != NULL)
{
plugins_->GetErrorDictionary().LogError(exception.GetErrorCode(), true);
isPlugin = true;
}
#endif
if (!isPlugin)
{
LOG(ERROR) << "Exception in the HTTP handler: " << exception.What();
}
}
Json::Value message = Json::objectValue;
ErrorCode errorCode = exception.GetErrorCode();
HttpStatus httpStatus = exception.GetHttpStatus();
{
bool isPlugin = false;
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins_ != NULL &&
plugins_->GetErrorDictionary().Format(message, httpStatus, exception))
{
errorCode = ErrorCode_Plugin;
isPlugin = true;
}
#endif
if (!isPlugin)
{
message["Message"] = exception.What();
}
}
if (!describeErrors_)
{
output.SendStatus(httpStatus);
}
else
{
message["Method"] = EnumerationToString(method);
message["Uri"] = uri;
message["HttpError"] = EnumerationToString(httpStatus);
message["HttpStatus"] = httpStatus;
message["OrthancError"] = EnumerationToString(errorCode);
message["OrthancStatus"] = errorCode;
if (exception.HasDetails())
{
message["Details"] = exception.GetDetails();
}
std::string info = message.toStyledString();
output.SendStatus(httpStatus, info);
}
}
};
static void PrintHelp(const char* path)
{
std::cout
<< "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl
<< "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl
<< std::endl
<< "The \"CONFIGURATION\" argument can be a single file or a directory. In the " << std::endl
<< "case of a directory, all the JSON files it contains will be merged. " << std::endl
<< "If no configuration path is given on the command line, a set of default " << std::endl
<< "parameters is used. Please refer to the Orthanc Book for the full " << std::endl
<< "instructions about how to use Orthanc <http://book.orthanc-server.com/>." << std::endl
<< std::endl
<< "Pay attention to the fact that the order of the options is important." << std::endl
<< "Options are read left to right. In particular, options such as \"--verbose\" can " << std::endl
<< "reset the value of other log-related options that were read before." << std::endl
<< std::endl
<< "The recommended set of options to debug DICOM communications is " << std::endl
<< "\"--verbose --trace-dicom --logfile=dicom.log\"" << std::endl
<< std::endl
<< "Command-line options:" << std::endl
<< " --help\t\tdisplay this help and exit" << std::endl
<< " --logdir=[dir]\tdirectory where to store the log files" << std::endl
<< "\t\t\t(by default, the log is dumped to stderr)" << std::endl
<< " --logfile=[file]\tfile where to store the log of Orthanc" << std::endl
<< "\t\t\t(by default, the log is dumped to stderr)" << std::endl
<< " --config=[file]\tcreate a sample configuration file and exit" << std::endl
<< "\t\t\t(if \"file\" is \"-\", dumps to stdout)" << std::endl
<< " --errors\t\tprint the supported error codes and exit" << std::endl
<< " --verbose\t\tbe verbose in logs" << std::endl
<< " --trace\t\thighest verbosity in logs (for debug)" << std::endl
<< " --upgrade\t\tallow Orthanc to upgrade the version of the" << std::endl
<< "\t\t\tdatabase (beware that the database will become" << std::endl
<< "\t\t\tincompatible with former versions of Orthanc)" << std::endl
<< " --no-jobs\t\tdon't restart the jobs that were stored during" << std::endl
<< "\t\t\tthe last execution of Orthanc" << std::endl
<< " --openapi=[file]\twrite the OpenAPI documentation and exit" << std::endl
<< "\t\t\t(if \"file\" is \"-\", dumps to stdout)" << std::endl
<< " --cheatsheet=[file]\twrite the cheat sheet of REST API as CSV" << std::endl
<< "\t\t\tand exit (if \"file\" is \"-\", dumps to stdout)" << std::endl
<< " --version\t\toutput version information and exit" << std::endl
<< std::endl
<< "Fine-tuning of log categories:" << std::endl;
for (size_t i = 0; i < Logging::GetCategoriesCount(); i++)
{
const std::string name = Logging::GetCategoryName(i);
std::cout << " --verbose-" << name
<< "\tbe verbose in logs of category \"" << name << "\"" << std::endl;
std::cout << " --trace-" << name
<< "\tuse highest verbosity for logs of category \"" << name << "\"" << std::endl;
}
std::cout
<< std::endl
<< "Exit status:" << std::endl
<< " 0\tif success," << std::endl
#if defined(_WIN32)
<< " != 0\tif error (use the --errors option to get the list of possible errors)." << std::endl
#else
<< " -1\tif error (have a look at the logs)." << std::endl
#endif
<< std::endl;
}
static void PrintVersion(const char* path)
{
std::cout
<< path << " " << ORTHANC_VERSION << std::endl
<< "Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics Department, University Hospital of Liege (Belgium)" << std::endl
<< "Copyright (C) 2017-2021 Osimis S.A. (Belgium)" << std::endl
<< "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl
<< "This is free software: you are free to change and redistribute it." << std::endl
<< "There is NO WARRANTY, to the extent permitted by law." << std::endl
<< std::endl
<< "Written by Sebastien Jodogne <s.jodogne@orthanc-labs.com>" << std::endl;
}
static void PrintErrorCode(ErrorCode code, const char* description)
{
std::cout
<< std::right << std::setw(16)
<< static_cast<int>(code)
<< " " << description << std::endl;
}
static void PrintErrors(const char* path)
{
std::cout
<< path << " " << ORTHANC_VERSION << std::endl
<< "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research."
<< std::endl << std::endl
<< "List of error codes that could be returned by Orthanc:"
<< std::endl << std::endl;
{
PrintErrorCode(ErrorCode_InternalError, "Internal error");
PrintErrorCode(ErrorCode_Success, "Success");
PrintErrorCode(ErrorCode_Plugin, "Error encountered within the plugin engine");
PrintErrorCode(ErrorCode_NotImplemented, "Not implemented yet");
PrintErrorCode(ErrorCode_ParameterOutOfRange, "Parameter out of range");
PrintErrorCode(ErrorCode_NotEnoughMemory, "The server hosting Orthanc is running out of memory");
PrintErrorCode(ErrorCode_BadParameterType, "Bad type for a parameter");
PrintErrorCode(ErrorCode_BadSequenceOfCalls, "Bad sequence of calls");
PrintErrorCode(ErrorCode_InexistentItem, "Accessing an inexistent item");
PrintErrorCode(ErrorCode_BadRequest, "Bad request");
PrintErrorCode(ErrorCode_NetworkProtocol, "Error in the network protocol");
PrintErrorCode(ErrorCode_SystemCommand, "Error while calling a system command");
PrintErrorCode(ErrorCode_Database, "Error with the database engine");
PrintErrorCode(ErrorCode_UriSyntax, "Badly formatted URI");
PrintErrorCode(ErrorCode_InexistentFile, "Inexistent file");
PrintErrorCode(ErrorCode_CannotWriteFile, "Cannot write to file");
PrintErrorCode(ErrorCode_BadFileFormat, "Bad file format");
PrintErrorCode(ErrorCode_Timeout, "Timeout");
PrintErrorCode(ErrorCode_UnknownResource, "Unknown resource");
PrintErrorCode(ErrorCode_IncompatibleDatabaseVersion, "Incompatible version of the database");
PrintErrorCode(ErrorCode_FullStorage, "The file storage is full");
PrintErrorCode(ErrorCode_CorruptedFile, "Corrupted file (e.g. inconsistent MD5 hash)");
PrintErrorCode(ErrorCode_InexistentTag, "Inexistent tag");
PrintErrorCode(ErrorCode_ReadOnly, "Cannot modify a read-only data structure");
PrintErrorCode(ErrorCode_IncompatibleImageFormat, "Incompatible format of the images");
PrintErrorCode(ErrorCode_IncompatibleImageSize, "Incompatible size of the images");
PrintErrorCode(ErrorCode_SharedLibrary, "Error while using a shared library (plugin)");
PrintErrorCode(ErrorCode_UnknownPluginService, "Plugin invoking an unknown service");
PrintErrorCode(ErrorCode_UnknownDicomTag, "Unknown DICOM tag");
PrintErrorCode(ErrorCode_BadJson, "Cannot parse a JSON document");
PrintErrorCode(ErrorCode_Unauthorized, "Bad credentials were provided to an HTTP request");
PrintErrorCode(ErrorCode_BadFont, "Badly formatted font file");
PrintErrorCode(ErrorCode_DatabasePlugin, "The plugin implementing a custom database back-end does not fulfill the proper interface");
PrintErrorCode(ErrorCode_StorageAreaPlugin, "Error in the plugin implementing a custom storage area");
PrintErrorCode(ErrorCode_EmptyRequest, "The request is empty");
PrintErrorCode(ErrorCode_NotAcceptable, "Cannot send a response which is acceptable according to the Accept HTTP header");
PrintErrorCode(ErrorCode_NullPointer, "Cannot handle a NULL pointer");
PrintErrorCode(ErrorCode_DatabaseUnavailable, "The database is currently not available (probably a transient situation)");
PrintErrorCode(ErrorCode_CanceledJob, "This job was canceled");
PrintErrorCode(ErrorCode_BadGeometry, "Geometry error encountered in Stone");
PrintErrorCode(ErrorCode_SslInitialization, "Cannot initialize SSL encryption, check out your certificates");
PrintErrorCode(ErrorCode_DiscontinuedAbi, "Calling a function that has been removed from the Orthanc Framework");
PrintErrorCode(ErrorCode_BadRange, "Incorrect range request");
PrintErrorCode(ErrorCode_SQLiteNotOpened, "SQLite: The database is not opened");
PrintErrorCode(ErrorCode_SQLiteAlreadyOpened, "SQLite: Connection is already open");
PrintErrorCode(ErrorCode_SQLiteCannotOpen, "SQLite: Unable to open the database");
PrintErrorCode(ErrorCode_SQLiteStatementAlreadyUsed, "SQLite: This cached statement is already being referred to");
PrintErrorCode(ErrorCode_SQLiteExecute, "SQLite: Cannot execute a command");
PrintErrorCode(ErrorCode_SQLiteRollbackWithoutTransaction, "SQLite: Rolling back a nonexistent transaction (have you called Begin()?)");
PrintErrorCode(ErrorCode_SQLiteCommitWithoutTransaction, "SQLite: Committing a nonexistent transaction");
PrintErrorCode(ErrorCode_SQLiteRegisterFunction, "SQLite: Unable to register a function");
PrintErrorCode(ErrorCode_SQLiteFlush, "SQLite: Unable to flush the database");
PrintErrorCode(ErrorCode_SQLiteCannotRun, "SQLite: Cannot run a cached statement");
PrintErrorCode(ErrorCode_SQLiteCannotStep, "SQLite: Cannot step over a cached statement");
PrintErrorCode(ErrorCode_SQLiteBindOutOfRange, "SQLite: Bing a value while out of range (serious error)");
PrintErrorCode(ErrorCode_SQLitePrepareStatement, "SQLite: Cannot prepare a cached statement");
PrintErrorCode(ErrorCode_SQLiteTransactionAlreadyStarted, "SQLite: Beginning the same transaction twice");
PrintErrorCode(ErrorCode_SQLiteTransactionCommit, "SQLite: Failure when committing the transaction");
PrintErrorCode(ErrorCode_SQLiteTransactionBegin, "SQLite: Cannot start a transaction");
PrintErrorCode(ErrorCode_DirectoryOverFile, "The directory to be created is already occupied by a regular file");
PrintErrorCode(ErrorCode_FileStorageCannotWrite, "Unable to create a subdirectory or a file in the file storage");
PrintErrorCode(ErrorCode_DirectoryExpected, "The specified path does not point to a directory");
PrintErrorCode(ErrorCode_HttpPortInUse, "The TCP port of the HTTP server is privileged or already in use");
PrintErrorCode(ErrorCode_DicomPortInUse, "The TCP port of the DICOM server is privileged or already in use");
PrintErrorCode(ErrorCode_BadHttpStatusInRest, "This HTTP status is not allowed in a REST API");
PrintErrorCode(ErrorCode_RegularFileExpected, "The specified path does not point to a regular file");
PrintErrorCode(ErrorCode_PathToExecutable, "Unable to get the path to the executable");
PrintErrorCode(ErrorCode_MakeDirectory, "Cannot create a directory");
PrintErrorCode(ErrorCode_BadApplicationEntityTitle, "An application entity title (AET) cannot be empty or be longer than 16 characters");
PrintErrorCode(ErrorCode_NoCFindHandler, "No request handler factory for DICOM C-FIND SCP");
PrintErrorCode(ErrorCode_NoCMoveHandler, "No request handler factory for DICOM C-MOVE SCP");
PrintErrorCode(ErrorCode_NoCStoreHandler, "No request handler factory for DICOM C-STORE SCP");
PrintErrorCode(ErrorCode_NoApplicationEntityFilter, "No application entity filter");
PrintErrorCode(ErrorCode_NoSopClassOrInstance, "DicomUserConnection: Unable to find the SOP class and instance");
PrintErrorCode(ErrorCode_NoPresentationContext, "DicomUserConnection: No acceptable presentation context for modality");
PrintErrorCode(ErrorCode_DicomFindUnavailable, "DicomUserConnection: The C-FIND command is not supported by the remote SCP");
PrintErrorCode(ErrorCode_DicomMoveUnavailable, "DicomUserConnection: The C-MOVE command is not supported by the remote SCP");
PrintErrorCode(ErrorCode_CannotStoreInstance, "Cannot store an instance");
PrintErrorCode(ErrorCode_CreateDicomNotString, "Only string values are supported when creating DICOM instances");
PrintErrorCode(ErrorCode_CreateDicomOverrideTag, "Trying to override a value inherited from a parent module");
PrintErrorCode(ErrorCode_CreateDicomUseContent, "Use \"Content\" to inject an image into a new DICOM instance");
PrintErrorCode(ErrorCode_CreateDicomNoPayload, "No payload is present for one instance in the series");
PrintErrorCode(ErrorCode_CreateDicomUseDataUriScheme, "The payload of the DICOM instance must be specified according to Data URI scheme");
PrintErrorCode(ErrorCode_CreateDicomBadParent, "Trying to attach a new DICOM instance to an inexistent resource");
PrintErrorCode(ErrorCode_CreateDicomParentIsInstance, "Trying to attach a new DICOM instance to an instance (must be a series, study or patient)");
PrintErrorCode(ErrorCode_CreateDicomParentEncoding, "Unable to get the encoding of the parent resource");
PrintErrorCode(ErrorCode_UnknownModality, "Unknown modality");
PrintErrorCode(ErrorCode_BadJobOrdering, "Bad ordering of filters in a job");
PrintErrorCode(ErrorCode_JsonToLuaTable, "Cannot convert the given JSON object to a Lua table");
PrintErrorCode(ErrorCode_CannotCreateLua, "Cannot create the Lua context");
PrintErrorCode(ErrorCode_CannotExecuteLua, "Cannot execute a Lua command");
PrintErrorCode(ErrorCode_LuaAlreadyExecuted, "Arguments cannot be pushed after the Lua function is executed");
PrintErrorCode(ErrorCode_LuaBadOutput, "The Lua function does not give the expected number of outputs");
PrintErrorCode(ErrorCode_NotLuaPredicate, "The Lua function is not a predicate (only true/false outputs allowed)");
PrintErrorCode(ErrorCode_LuaReturnsNoString, "The Lua function does not return a string");
PrintErrorCode(ErrorCode_StorageAreaAlreadyRegistered, "Another plugin has already registered a custom storage area");
PrintErrorCode(ErrorCode_DatabaseBackendAlreadyRegistered, "Another plugin has already registered a custom database back-end");
PrintErrorCode(ErrorCode_DatabaseNotInitialized, "Plugin trying to call the database during its initialization");
PrintErrorCode(ErrorCode_SslDisabled, "Orthanc has been built without SSL support");
PrintErrorCode(ErrorCode_CannotOrderSlices, "Unable to order the slices of the series");
PrintErrorCode(ErrorCode_NoWorklistHandler, "No request handler factory for DICOM C-Find Modality SCP");
PrintErrorCode(ErrorCode_AlreadyExistingTag, "Cannot override the value of a tag that already exists");
PrintErrorCode(ErrorCode_NoStorageCommitmentHandler, "No request handler factory for DICOM N-ACTION SCP (storage commitment)");
PrintErrorCode(ErrorCode_NoCGetHandler, "No request handler factory for DICOM C-GET SCP");
PrintErrorCode(ErrorCode_UnsupportedMediaType, "Unsupported media type");
}
std::cout << std::endl;
}
#if ORTHANC_ENABLE_PLUGINS == 1
static void LoadPlugins(OrthancPlugins& plugins)
{
std::list<std::string> pathList;
{
OrthancConfiguration::ReaderLock lock;
lock.GetConfiguration().GetListOfStringsParameter(pathList, "Plugins");
}
for (std::list<std::string>::const_iterator
it = pathList.begin(); it != pathList.end(); ++it)
{
std::string path;
{
OrthancConfiguration::ReaderLock lock;
path = lock.GetConfiguration().InterpretStringParameterAsPath(*it);
}
LOG(WARNING) << "Loading plugin(s) from: " << path;
plugins.GetManager().RegisterPlugin(path);
}
}
#endif
static bool WaitForExit(ServerContext& context,
const OrthancRestApi& restApi)
{
LOG(WARNING) << "Orthanc has started";
#if ORTHANC_ENABLE_PLUGINS == 1
if (context.HasPlugins())
{
context.GetPlugins().SignalOrthancStarted();
}
#endif
context.GetLuaScripting().Start();
context.GetLuaScripting().Execute("Initialize");
bool restart;
for (;;)
{
ServerBarrierEvent event = SystemToolbox::ServerBarrier(restApi.LeaveBarrierFlag());
restart = restApi.IsResetRequestReceived();
if (!restart &&
event == ServerBarrierEvent_Reload)
{
OrthancConfiguration::ReaderLock lock;
if (lock.GetConfiguration().HasConfigurationChanged())
{
LOG(WARNING) << "A SIGHUP signal has been received, resetting Orthanc";
Logging::Flush();
restart = true;
break;
}
else
{
LOG(WARNING) << "A SIGHUP signal has been received, but is ignored "
<< "as the configuration has not changed on the disk";
Logging::Flush();
continue;
}
}
else
{
break;
}
}
context.GetLuaScripting().Execute("Finalize");
context.GetLuaScripting().Stop();
#if ORTHANC_ENABLE_PLUGINS == 1
if (context.HasPlugins())
{
context.GetPlugins().SignalOrthancStopped();
}
#endif
if (restart)
{
LOG(WARNING) << "Reset request received, restarting Orthanc";
}
LOG(WARNING) << "Orthanc is stopping";
return restart;
}
static bool StartHttpServer(ServerContext& context,
const OrthancRestApi& restApi,
OrthancPlugins* plugins)
{
bool httpServerEnabled;
{
OrthancConfiguration::ReaderLock lock;
httpServerEnabled = lock.GetConfiguration().GetBooleanParameter("HttpServerEnabled", true);
}
if (!httpServerEnabled)
{
LOG(WARNING) << "The HTTP server is disabled";
return WaitForExit(context, restApi);
}
else
{
MyIncomingHttpRequestFilter httpFilter(context, plugins);
HttpServer httpServer;
bool httpDescribeErrors;
#if ORTHANC_ENABLE_MONGOOSE == 1
const bool defaultKeepAlive = false;
#elif ORTHANC_ENABLE_CIVETWEB == 1
const bool defaultKeepAlive = true;
#else
# error "Either Mongoose or Civetweb must be enabled to compile this file"
#endif
{
OrthancConfiguration::ReaderLock lock;
httpDescribeErrors = lock.GetConfiguration().GetBooleanParameter("HttpDescribeErrors", true);
httpServer.SetThreadsCount(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpThreadsCount", 50));
httpServer.SetPortNumber(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpPort", 8042));
httpServer.SetRemoteAccessAllowed(lock.GetConfiguration().GetBooleanParameter("RemoteAccessAllowed", false));
httpServer.SetKeepAliveEnabled(lock.GetConfiguration().GetBooleanParameter("KeepAlive", defaultKeepAlive));
httpServer.SetHttpCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("HttpCompressionEnabled", true));
httpServer.SetTcpNoDelay(lock.GetConfiguration().GetBooleanParameter("TcpNoDelay", true));
httpServer.SetRequestTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpRequestTimeout", 30));
context.SetHttpServerSecure(true);
bool authenticationEnabled;
if (lock.GetConfiguration().LookupBooleanParameter(authenticationEnabled, "AuthenticationEnabled"))
{
httpServer.SetAuthenticationEnabled(authenticationEnabled);
if (httpServer.IsRemoteAccessAllowed() &&
!authenticationEnabled)
{
LOG(WARNING) << "====> Remote access is enabled while user authentication is explicitly disabled, "
<< "your setup is POSSIBLY INSECURE <====";
context.SetHttpServerSecure(false);
}
}
else if (httpServer.IsRemoteAccessAllowed())
{
LOG(WARNING) << "Remote access is allowed but \"AuthenticationEnabled\" is not in the configuration, "
<< "automatically enabling HTTP authentication for security";
httpServer.SetAuthenticationEnabled(true);
}
else
{
httpServer.SetAuthenticationEnabled(false);
}
bool hasUsers = lock.GetConfiguration().SetupRegisteredUsers(httpServer);
if (httpServer.IsAuthenticationEnabled() &&
!hasUsers)
{
if (httpServer.IsRemoteAccessAllowed())
{
LOG(WARNING) << "====> HTTP authentication is enabled, but no user is declared. "
<< "Creating a default user: Review your configuration option \"RegisteredUsers\". "
<< "Your setup is INSECURE <====";
context.SetHttpServerSecure(false);
httpServer.RegisterUser("orthanc", "orthanc");
}
else
{
LOG(WARNING) << "HTTP authentication is enabled, but no user is declared, "
<< "check the value of configuration option \"RegisteredUsers\"";
}
}
if (lock.GetConfiguration().GetBooleanParameter("SslEnabled", false))
{
std::string certificate = lock.GetConfiguration().InterpretStringParameterAsPath(
lock.GetConfiguration().GetStringParameter("SslCertificate", "certificate.pem"));
httpServer.SetSslEnabled(true);
httpServer.SetSslCertificate(certificate.c_str());
static const unsigned int TLS_1_2 = 4;
unsigned int minimumVersion = lock.GetConfiguration().GetUnsignedIntegerParameter("SslMinimumProtocolVersion", TLS_1_2);
httpServer.SetSslMinimumVersion(minimumVersion);
static const char* SSL_CIPHERS_ACCEPTED = "SslCiphersAccepted";
std::list<std::string> ciphers;
if (lock.GetJson().type() == Json::objectValue &&
lock.GetJson().isMember(SSL_CIPHERS_ACCEPTED))
{
lock.GetConfiguration().GetListOfStringsParameter(ciphers, SSL_CIPHERS_ACCEPTED);
}
else
{
CLOG(INFO, HTTP) << "No configuration option \"" << SSL_CIPHERS_ACCEPTED
<< "\", will accept the FIPS 140-2 ciphers";
ciphers.push_back("ECDHE-ECDSA-AES256-GCM-SHA384");
ciphers.push_back("ECDHE-ECDSA-AES256-SHA384");
ciphers.push_back("ECDHE-RSA-AES256-GCM-SHA384");
ciphers.push_back("ECDHE-RSA-AES128-GCM-SHA256");
ciphers.push_back("ECDHE-RSA-AES256-SHA384");
ciphers.push_back("ECDHE-RSA-AES128-SHA256");
ciphers.push_back("ECDHE-RSA-AES128-SHA");
ciphers.push_back("ECDHE-RSA-AES256-SHA");
ciphers.push_back("DHE-RSA-AES256-SHA");
ciphers.push_back("DHE-RSA-AES128-SHA");
ciphers.push_back("AES256-SHA");
ciphers.push_back("AES128-SHA");
}
httpServer.SetSslCiphers(ciphers);
}
else
{
httpServer.SetSslEnabled(false);
}
if (lock.GetConfiguration().GetBooleanParameter("SslVerifyPeers", false))
{
std::string trustedClientCertificates = lock.GetConfiguration().InterpretStringParameterAsPath(
lock.GetConfiguration().GetStringParameter("SslTrustedClientCertificates", "trustedCertificates.pem"));
httpServer.SetSslVerifyPeers(true);
httpServer.SetSslTrustedClientCertificates(trustedClientCertificates.c_str());
}
else
{
httpServer.SetSslVerifyPeers(false);
}
if (lock.GetConfiguration().GetBooleanParameter("ExecuteLuaEnabled", false))
{
context.SetExecuteLuaEnabled(true);
LOG(WARNING) << "====> Remote LUA script execution is enabled. Review your configuration option \"ExecuteLuaEnabled\". "
<< "Your setup is POSSIBLY INSECURE <====";
}
else
{
context.SetExecuteLuaEnabled(false);
LOG(WARNING) << "Remote LUA script execution is disabled";
}
if (lock.GetConfiguration().GetBooleanParameter("RestApiWriteToFileSystemEnabled", false))
{
context.SetRestApiWriteToFileSystemEnabled(true);
LOG(WARNING) << "====> Your Rest API can write to the FileSystem. Review your configuration option \"RestApiWriteToFileSystemEnabled\". "
<< "Your setup is POSSIBLY INSECURE <====";
}
else
{
context.SetRestApiWriteToFileSystemEnabled(false);
LOG(WARNING) << "Rest API can not write to the file system.";
}
if (lock.GetConfiguration().GetBooleanParameter("WebDavEnabled", true))
{
const bool allowDelete = lock.GetConfiguration().GetBooleanParameter("WebDavDeleteAllowed", false);
const bool allowUpload = lock.GetConfiguration().GetBooleanParameter("WebDavUploadAllowed", true);
UriComponents root;
root.push_back("webdav");
httpServer.Register(root, new OrthancWebDav(context, allowDelete, allowUpload));
}
}
MyHttpExceptionFormatter exceptionFormatter(httpDescribeErrors, plugins);
httpServer.SetIncomingHttpRequestFilter(httpFilter);
httpServer.SetHttpExceptionFormatter(exceptionFormatter);
httpServer.Register(context.GetHttpHandler());
if (httpServer.GetPortNumber() < 1024)
{
LOG(WARNING) << "The HTTP port is privileged ("
<< httpServer.GetPortNumber() << " is below 1024), "
<< "make sure you run Orthanc as root/administrator";
}
httpServer.Start();
bool restart = WaitForExit(context, restApi);
httpServer.Stop();
LOG(WARNING) << " HTTP server has stopped";
return restart;
}
}
static bool StartDicomServer(ServerContext& context,
const OrthancRestApi& restApi,
OrthancPlugins* plugins)
{
bool dicomServerEnabled;
{
OrthancConfiguration::ReaderLock lock;
dicomServerEnabled = lock.GetConfiguration().GetBooleanParameter("DicomServerEnabled", true);
}
if (!dicomServerEnabled)
{
LOG(WARNING) << "The DICOM server is disabled";
return StartHttpServer(context, restApi, plugins);
}
else
{
MyDicomServerFactory serverFactory(context);
OrthancApplicationEntityFilter dicomFilter(context);
ModalitiesFromConfiguration modalities;
DicomServer dicomServer;
dicomServer.SetRemoteModalities(modalities);
dicomServer.SetStoreRequestHandlerFactory(serverFactory);
dicomServer.SetMoveRequestHandlerFactory(serverFactory);
dicomServer.SetGetRequestHandlerFactory(serverFactory);
dicomServer.SetFindRequestHandlerFactory(serverFactory);
dicomServer.SetStorageCommitmentRequestHandlerFactory(serverFactory);
{
OrthancConfiguration::ReaderLock lock;
dicomServer.SetCalledApplicationEntityTitleCheck(lock.GetConfiguration().GetBooleanParameter("DicomCheckCalledAet", false));
dicomServer.SetAssociationTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScpTimeout", 30));
dicomServer.SetPortNumber(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomPort", 4242));
dicomServer.SetApplicationEntityTitle(lock.GetConfiguration().GetOrthancAET());
dicomServer.SetDicomTlsEnabled(lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_ENABLED, false));
if (dicomServer.IsDicomTlsEnabled())
{
dicomServer.SetOwnCertificatePath(
lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""),
lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, ""));
dicomServer.SetTrustedCertificatesPath(
lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_TRUSTED_CERTIFICATES, ""));
}
dicomServer.SetMaximumPduLength(lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH, 16384));
}
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins != NULL)
{
if (plugins->HasWorklistHandler())
{
dicomServer.SetWorklistRequestHandlerFactory(*plugins);
}
if (plugins->HasFindHandler())
{
dicomServer.SetFindRequestHandlerFactory(*plugins);
}
if (plugins->HasMoveHandler())
{
dicomServer.SetMoveRequestHandlerFactory(*plugins);
}
}
#endif
dicomServer.SetApplicationEntityFilter(dicomFilter);
if (dicomServer.GetPortNumber() < 1024)
{
LOG(WARNING) << "The DICOM port is privileged ("
<< dicomServer.GetPortNumber() << " is below 1024), "
<< "make sure you run Orthanc as root/administrator";
}
dicomServer.Start();
LOG(WARNING) << "DICOM server listening with AET " << dicomServer.GetApplicationEntityTitle()
<< " on port: " << dicomServer.GetPortNumber();
bool restart = false;
ErrorCode error = ErrorCode_Success;
try
{
restart = StartHttpServer(context, restApi, plugins);
}
catch (OrthancException& e)
{
error = e.GetErrorCode();
}
dicomServer.Stop();
LOG(WARNING) << " DICOM server has stopped";
serverFactory.Done();
if (error != ErrorCode_Success)
{
throw OrthancException(error);
}
return restart;
}
}
static bool ConfigureHttpHandler(ServerContext& context,
OrthancPlugins *plugins,
bool loadJobsFromDatabase)
{
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins)
{
assert(context.HasPlugins());
context.GetHttpHandler().Register(*plugins, false);
}
#endif
#if ORTHANC_STANDALONE == 1
EmbeddedResourceHttpHandler staticResources("/app", ServerResources::ORTHANC_EXPLORER);
#else
FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer");
#endif
bool orthancExplorerEnabled = false;
{
OrthancConfiguration::ReaderLock lock;
orthancExplorerEnabled = lock.GetConfiguration().GetBooleanParameter(
"OrthancExplorerEnabled", true);
}
if (orthancExplorerEnabled)
{
context.GetHttpHandler().Register(staticResources, false);
}
else
{
LOG(WARNING) << "Orthanc Explorer UI is disabled";
}
OrthancRestApi restApi(context, orthancExplorerEnabled);
context.GetHttpHandler().Register(restApi, true);
context.SetupJobsEngine(false , loadJobsFromDatabase);
bool restart = StartDicomServer(context, restApi, plugins);
context.Stop();
return restart;
}
static void UpgradeDatabase(IDatabaseWrapper& database,
IStorageArea& storageArea)
{
unsigned int currentVersion = database.GetDatabaseVersion();
LOG(WARNING) << "Starting the upgrade of the database schema";
LOG(WARNING) << "Current database version: " << currentVersion;
LOG(WARNING) << "Database version expected by Orthanc: " << ORTHANC_DATABASE_VERSION;
if (currentVersion == ORTHANC_DATABASE_VERSION)
{
LOG(WARNING) << "No upgrade is needed, start Orthanc without the \"--upgrade\" argument";
return;
}
if (currentVersion > ORTHANC_DATABASE_VERSION)
{
throw OrthancException(ErrorCode_IncompatibleDatabaseVersion,
"The version of the database schema (" +
boost::lexical_cast<std::string>(currentVersion) +
") is too recent for this version of Orthanc. Please upgrade Orthanc.");
}
LOG(WARNING) << "Upgrading the database from schema version "
<< currentVersion << " to " << ORTHANC_DATABASE_VERSION;
try
{
database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea);
}
catch (OrthancException&)
{
LOG(ERROR) << "Unable to run the automated upgrade, please use the replication instructions: "
<< "http://book.orthanc-server.com/users/replication.html";
throw;
}
currentVersion = database.GetDatabaseVersion();
if (ORTHANC_DATABASE_VERSION != currentVersion)
{
throw OrthancException(ErrorCode_IncompatibleDatabaseVersion,
"The database schema was not properly upgraded, it is still at version " +
boost::lexical_cast<std::string>(currentVersion));
}
else
{
LOG(WARNING) << "The database schema was successfully upgraded, "
<< "you can now start Orthanc without the \"--upgrade\" argument";
}
}
namespace
{
class ServerContextConfigurator : public boost::noncopyable
{
private:
ServerContext& context_;
OrthancPlugins* plugins_;
public:
ServerContextConfigurator(ServerContext& context,
OrthancPlugins* plugins) :
context_(context),
plugins_(plugins)
{
{
OrthancConfiguration::WriterLock lock;
lock.GetConfiguration().SetServerIndex(context.GetIndex());
}
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins_ != NULL)
{
plugins_->SetServerContext(context_);
context_.SetPlugins(*plugins_);
}
#endif
}
~ServerContextConfigurator()
{
{
OrthancConfiguration::WriterLock lock;
lock.GetConfiguration().ResetServerIndex();
}
#if ORTHANC_ENABLE_PLUGINS == 1
if (plugins_ != NULL)
{
plugins_->ResetServerContext();
context_.ResetPlugins();
}
#endif
}
};
}
static bool ConfigureServerContext(IDatabaseWrapper& database,
IStorageArea& storageArea,
OrthancPlugins *plugins,
bool loadJobsFromDatabase)
{
size_t maxCompletedJobs;
{
OrthancConfiguration::ReaderLock lock;
HttpClient::ConfigureSsl(lock.GetConfiguration().GetBooleanParameter("HttpsVerifyPeers", true),
lock.GetConfiguration().InterpretStringParameterAsPath
(lock.GetConfiguration().GetStringParameter("HttpsCACertificates", "")));
HttpClient::SetDefaultVerbose(lock.GetConfiguration().GetBooleanParameter("HttpVerbose", false));
HttpClient::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpTimeout", 0));
HttpClient::SetDefaultProxy(lock.GetConfiguration().GetStringParameter("HttpProxy", ""));
DicomAssociationParameters::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScuTimeout", 10));
maxCompletedJobs = lock.GetConfiguration().GetUnsignedIntegerParameter("JobsHistorySize", 10);
if (maxCompletedJobs == 0)
{
LOG(WARNING) << "Setting option \"JobsHistorySize\" to zero is not recommended";
}
DicomAssociationParameters::SetDefaultOwnCertificatePath(
lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""),
lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, ""));
DicomAssociationParameters::SetDefaultTrustedCertificatesPath(
lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_TRUSTED_CERTIFICATES, ""));
DicomAssociationParameters::SetDefaultMaximumPduLength(
lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH, 16384));
}
ServerContext context(database, storageArea, false , maxCompletedJobs);
{
OrthancConfiguration::ReaderLock lock;
context.SetCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("StorageCompression", false));
context.SetStoreMD5ForAttachments(lock.GetConfiguration().GetBooleanParameter("StoreMD5ForAttachments", true));
context.SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false));
try
{
context.GetIndex().SetMaximumPatientCount(lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumPatientCount", 0));
}
catch (...)
{
context.GetIndex().SetMaximumPatientCount(0);
}
try
{
uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageSize", 0);
context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024);
}
catch (...)
{
context.GetIndex().SetMaximumStorageSize(0);
}
}
{
ServerContextConfigurator configurator(context, plugins);
{
OrthancConfiguration::WriterLock lock;
lock.GetConfiguration().LoadModalitiesAndPeers();
}
return ConfigureHttpHandler(context, plugins, loadJobsFromDatabase);
}
}
static bool ConfigureDatabase(IDatabaseWrapper& database,
IStorageArea& storageArea,
OrthancPlugins *plugins,
bool upgradeDatabase,
bool loadJobsFromDatabase)
{
database.Open();
unsigned int currentVersion = database.GetDatabaseVersion();
if (upgradeDatabase)
{
UpgradeDatabase(database, storageArea);
return false;
}
else if (currentVersion != ORTHANC_DATABASE_VERSION)
{
throw OrthancException(ErrorCode_IncompatibleDatabaseVersion,
"The database schema must be upgraded from version " +
boost::lexical_cast<std::string>(currentVersion) + " to " +
boost::lexical_cast<std::string>(ORTHANC_DATABASE_VERSION) +
": Please run Orthanc with the \"--upgrade\" argument");
}
bool success = ConfigureServerContext
(database, storageArea, plugins, loadJobsFromDatabase);
database.Close();
return success;
}
static bool ConfigurePlugins(int argc,
char* argv[],
bool upgradeDatabase,
bool loadJobsFromDatabase)
{
std::unique_ptr<IDatabaseWrapper> databasePtr;
std::unique_ptr<IStorageArea> storage;
#if ORTHANC_ENABLE_PLUGINS == 1
OrthancPlugins plugins;
plugins.SetCommandLineArguments(argc, argv);
LoadPlugins(plugins);
IDatabaseWrapper* database = NULL;
if (plugins.HasDatabaseBackend())
{
LOG(WARNING) << "Using a custom database from plugins";
database = &plugins.GetDatabaseBackend();
}
else
{
databasePtr.reset(CreateDatabaseWrapper());
database = databasePtr.get();
}
if (plugins.HasStorageArea())
{
LOG(WARNING) << "Using a custom storage area from plugins";
storage.reset(plugins.CreateStorageArea());
}
else
{
storage.reset(CreateStorageArea());
}
assert(database != NULL);
assert(storage.get() != NULL);
return ConfigureDatabase(*database, *storage, &plugins,
upgradeDatabase, loadJobsFromDatabase);
#elif ORTHANC_ENABLE_PLUGINS == 0
databasePtr.reset(CreateDatabaseWrapper());
storage.reset(CreateStorageArea());
assert(databasePtr.get() != NULL);
assert(storage.get() != NULL);
return ConfigureDatabase(*databasePtr, *storage, NULL,
upgradeDatabase, loadJobsFromDatabase);
#else
# error The macro ORTHANC_ENABLE_PLUGINS must be set to 0 or 1
#endif
}
static bool StartOrthanc(int argc,
char* argv[],
bool upgradeDatabase,
bool loadJobsFromDatabase)
{
return ConfigurePlugins(argc, argv, upgradeDatabase, loadJobsFromDatabase);
}
static bool SetCategoryVerbosity(const Verbosity verbosity,
const std::string& category)
{
Logging::LogCategory c;
if (LookupCategory(c, category))
{
SetCategoryVerbosity(c, verbosity);
return true;
}
else
{
return false;
}
}
static bool DisplayPerformanceWarning()
{
(void) DisplayPerformanceWarning;
LOG(WARNING) << "Performance warning: Non-release build, runtime debug assertions are turned on";
return true;
}
int main(int argc, char* argv[])
{
Logging::Initialize();
SetGlobalVerbosity(Verbosity_Default);
bool upgradeDatabase = false;
bool loadJobsFromDatabase = true;
const char* configurationFile = NULL;
for (int i = 1; i < argc; i++)
{
std::string argument(argv[i]);
if (argument.empty())
{
}
else if (argument[0] != '-')
{
if (configurationFile != NULL)
{
LOG(ERROR) << "More than one configuration path were provided on the command line, aborting";
return -1;
}
else
{
configurationFile = argv[i];
}
}
else if (argument == "--errors")
{
PrintErrors(argv[0]);
return 0;
}
else if (argument == "--help")
{
PrintHelp(argv[0]);
return 0;
}
else if (argument == "--version")
{
PrintVersion(argv[0]);
return 0;
}
else if (argument == "--verbose")
{
SetGlobalVerbosity(Verbosity_Verbose);
}
else if (argument == "--trace")
{
SetGlobalVerbosity(Verbosity_Trace);
}
else if (boost::starts_with(argument, "--verbose-") &&
SetCategoryVerbosity(Verbosity_Verbose, argument.substr(10)))
{
}
else if (boost::starts_with(argument, "--trace-") &&
SetCategoryVerbosity(Verbosity_Trace, argument.substr(8)))
{
}
else if (boost::starts_with(argument, "--logdir="))
{
const std::string directory = argument.substr(9);
try
{
Logging::SetTargetFolder(directory);
}
catch (OrthancException&)
{
LOG(ERROR) << "The directory where to store the log files ("
<< directory << ") is inexistent, aborting.";
return -1;
}
}
else if (boost::starts_with(argument, "--logfile="))
{
const std::string file = argument.substr(10);
try
{
Logging::SetTargetFile(file);
}
catch (OrthancException&)
{
LOG(ERROR) << "Cannot write to the specified log file ("
<< file << "), aborting.";
return -1;
}
}
else if (argument == "--upgrade")
{
upgradeDatabase = true;
}
else if (argument == "--no-jobs")
{
loadJobsFromDatabase = false;
}
else if (boost::starts_with(argument, "--config="))
{
std::string configurationSample;
GetFileResource(configurationSample, ServerResources::CONFIGURATION_SAMPLE);
#if defined(_WIN32)
boost::replace_all(configurationSample, "\n", "\r\n");
#endif
std::string target = argument.substr(9);
try
{
if (target == "-")
{
std::cout << configurationSample;
}
else
{
SystemToolbox::WriteFile(configurationSample, target);
}
return 0;
}
catch (OrthancException&)
{
LOG(ERROR) << "Cannot write sample configuration as file \"" << target << "\"";
return -1;
}
}
else if (boost::starts_with(argument, "--openapi="))
{
std::string target = argument.substr(10);
try
{
Json::Value openapi;
{
SQLiteDatabaseWrapper inMemoryDatabase;
inMemoryDatabase.Open();
MemoryStorageArea inMemoryStorage;
ServerContext context(inMemoryDatabase, inMemoryStorage, true , 0 );
OrthancRestApi restApi(context, false );
restApi.GenerateOpenApiDocumentation(openapi);
context.Stop();
}
openapi["info"]["version"] = ORTHANC_VERSION;
openapi["info"]["title"] = "Orthanc API";
openapi["info"]["description"] =
"This is the full documentation of the [REST API](https://book.orthanc-server.com/users/rest.html) "
"of Orthanc.<p>This reference is automatically generated from the source code of Orthanc. A "
"[shorter cheat sheet](https://book.orthanc-server.com/users/rest-cheatsheet.html) is part of "
"the Orthanc Book.<p>An earlier, manually crafted version from August 2019, is [still available]"
"(2019-08-orthanc-openapi.html), but is not up-to-date anymore ([source]"
"(https://groups.google.com/g/orthanc-users/c/NUiJTEICSl8/m/xKeqMrbqAAAJ)).";
Json::Value server = Json::objectValue;
server["url"] = "https://demo.orthanc-server.com/";
openapi["servers"].append(server);
std::string s;
Toolbox::WriteStyledJson(s, openapi);
if (target == "-")
{
std::cout << s;
}
else
{
SystemToolbox::WriteFile(s, target);
}
return 0;
}
catch (OrthancException&)
{
LOG(ERROR) << "Cannot export OpenAPI documentation as file \"" << target << "\"";
return -1;
}
}
else if (boost::starts_with(argument, "--cheatsheet="))
{
std::string target = argument.substr(13);
try
{
std::string cheatsheet;
{
SQLiteDatabaseWrapper inMemoryDatabase;
inMemoryDatabase.Open();
MemoryStorageArea inMemoryStorage;
ServerContext context(inMemoryDatabase, inMemoryStorage, true , 0 );
OrthancRestApi restApi(context, false );
restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://api.orthanc-server.com/index.html");
context.Stop();
}
if (target == "-")
{
std::cout << cheatsheet;
}
else
{
SystemToolbox::WriteFile(cheatsheet, target);
}
return 0;
}
catch (OrthancException&)
{
LOG(ERROR) << "Cannot export REST cheat sheet as file \"" << target << "\"";
return -1;
}
}
else
{
LOG(WARNING) << "Option unsupported by the core of Orthanc: " << argument;
}
}
{
std::string version(ORTHANC_VERSION);
if (std::string(ORTHANC_VERSION) == "mainline")
{
try
{
boost::filesystem::path exe(SystemToolbox::GetPathToExecutable());
std::time_t creation = boost::filesystem::last_write_time(exe);
boost::posix_time::ptime converted(boost::posix_time::from_time_t(creation));
version += " (" + boost::posix_time::to_iso_string(converted) + ")";
}
catch (...)
{
}
}
LOG(WARNING) << "Orthanc version: " << version;
assert(DisplayPerformanceWarning());
std::string s = "Architecture: ";
if (sizeof(void*) == 4)
{
s += "32-bit, ";
}
else if (sizeof(void*) == 8)
{
s += "64-bit, ";
}
else
{
s += "unsupported pointer size, ";
}
switch (Toolbox::DetectEndianness())
{
case Endianness_Little:
s += "little endian";
break;
case Endianness_Big:
s += "big endian";
break;
default:
s += "unsupported endianness";
break;
}
LOG(INFO) << s;
}
int status = 0;
try
{
for (;;)
{
OrthancInitialize(configurationFile);
bool restart = StartOrthanc(argc, argv, upgradeDatabase, loadJobsFromDatabase);
if (restart)
{
OrthancFinalize();
LOG(WARNING) << "Logging system is resetting";
Logging::Reset();
}
else
{
break;
}
}
}
catch (const OrthancException& e)
{
LOG(ERROR) << "Uncaught exception, stopping now: [" << e.What() << "] (code " << e.GetErrorCode() << ")";
#if defined(_WIN32)
if (e.GetErrorCode() >= ErrorCode_START_PLUGINS)
{
status = static_cast<int>(ErrorCode_Plugin);
}
else
{
status = static_cast<int>(e.GetErrorCode());
}
#else
status = -1;
#endif
}
catch (const std::exception& e)
{
LOG(ERROR) << "Uncaught exception, stopping now: [" << e.what() << "]";
status = -1;
}
catch (const std::string& s)
{
LOG(ERROR) << "Uncaught exception, stopping now: [" << s << "]";
status = -1;
}
catch (...)
{
LOG(ERROR) << "Native exception, stopping now. Check your plugins, if any.";
status = -1;
}
LOG(WARNING) << "Orthanc has stopped";
OrthancFinalize();
return status;
}
|