# HG changeset patch # User Sebastien Jodogne # Date 1397488658 -7200 # Node ID 45715eadc2e03a747aec111dcd77dff81b4ecdf1 # Parent 5197fd35333ce5d828c3c0dbe31616354b57e34b port number as a string diff -r 5197fd35333c -r 45715eadc2e0 NEWS --- a/NEWS Mon Apr 14 11:28:35 2014 +0200 +++ b/NEWS Mon Apr 14 17:17:38 2014 +0200 @@ -5,6 +5,7 @@ * Better logging about nonexistent tags * Dcm4Chee manufacturer * Automatic discovering of the path to the DICOM dictionaries +* In the "DicomModalities" config, the port number can be a string Version 0.7.3 (2014/02/14) diff -r 5197fd35333c -r 45715eadc2e0 OrthancServer/OrthancInitialization.cpp --- a/OrthancServer/OrthancInitialization.cpp Mon Apr 14 11:28:35 2014 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Mon Apr 14 17:17:38 2014 +0200 @@ -252,7 +252,7 @@ if (!configuration_->isMember("DicomModalities")) { - throw OrthancException(""); + throw OrthancException(ErrorCode_BadFileFormat); } const Json::Value& modalities = (*configuration_) ["DicomModalities"]; @@ -260,14 +260,30 @@ !modalities.isMember(name) || (modalities[name].size() != 3 && modalities[name].size() != 4)) { - throw OrthancException(""); + throw OrthancException(ErrorCode_BadFileFormat); } try { aet = modalities[name].get(0u, "").asString(); address = modalities[name].get(1u, "").asString(); - port = modalities[name].get(2u, "").asInt(); + + const Json::Value& portValue = modalities[name].get(2u, ""); + try + { + port = portValue.asInt(); + } + catch (std::runtime_error /* error inside JsonCpp */) + { + try + { + port = boost::lexical_cast(portValue.asString()); + } + catch (boost::bad_lexical_cast) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + } if (modalities[name].size() == 4) { @@ -278,9 +294,11 @@ manufacturer = ModalityManufacturer_Generic; } } - catch (...) + catch (OrthancException& e) { - throw OrthancException("Badly formatted DICOM modality"); + LOG(ERROR) << "Syntax error in the definition of modality \"" << name + << "\". Please check your configuration file."; + throw e; } } @@ -295,43 +313,52 @@ if (!configuration_->isMember("OrthancPeers")) { - throw OrthancException(""); - } - - const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; - if (modalities.type() != Json::objectValue || - !modalities.isMember(name)) - { - throw OrthancException(""); + throw OrthancException(ErrorCode_BadFileFormat); } try { - url = modalities[name].get(0u, "").asString(); - - if (modalities[name].size() == 1) - { - username = ""; - password = ""; - } - else if (modalities[name].size() == 3) - { - username = modalities[name].get(1u, "").asString(); - password = modalities[name].get(2u, "").asString(); - } - else + const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; + if (modalities.type() != Json::objectValue || + !modalities.isMember(name)) { throw OrthancException(ErrorCode_BadFileFormat); } - } - catch (...) - { - throw OrthancException(ErrorCode_BadFileFormat); + + try + { + url = modalities[name].get(0u, "").asString(); + + if (modalities[name].size() == 1) + { + username = ""; + password = ""; + } + else if (modalities[name].size() == 3) + { + username = modalities[name].get(1u, "").asString(); + password = modalities[name].get(2u, "").asString(); + } + else + { + throw OrthancException(ErrorCode_BadFileFormat); + } + } + catch (...) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + if (url.size() != 0 && url[url.size() - 1] != '/') + { + url += '/'; + } } - - if (url.size() != 0 && url[url.size() - 1] != '/') + catch (OrthancException& e) { - url += '/'; + LOG(ERROR) << "Syntax error in the definition of peer \"" << name + << "\". Please check your configuration file."; + throw e; } } @@ -436,7 +463,7 @@ However, for some unknown reason, some versions of Boost do not make the proper path resolution when "baseDirectory" is an absolute path. So, a hack is used below. - **/ + **/ if (relative.is_absolute()) {