Mercurial > hg > orthanc-wsi
changeset 39:533cbc4d520c
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 14:17:33 +0100 |
parents | 8f68ad57fd18 |
children | 371243c270cc |
files | Framework/Orthanc/Core/Enumerations.cpp Framework/Orthanc/Core/Enumerations.h Framework/Orthanc/Core/HttpClient.cpp Framework/Orthanc/Core/Logging.cpp Framework/Orthanc/Core/Logging.h Framework/Orthanc/Core/PrecompiledHeaders.h Framework/Orthanc/Core/Toolbox.cpp Framework/Orthanc/Core/Toolbox.h Framework/Orthanc/Plugins/Engine/SharedLibrary.cpp Framework/Orthanc/Plugins/Engine/SharedLibrary.h |
diffstat | 10 files changed, 125 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Orthanc/Core/Enumerations.cpp Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/Enumerations.cpp Wed Nov 09 14:17:33 2016 +0100 @@ -64,7 +64,7 @@ return "Parameter out of range"; case ErrorCode_NotEnoughMemory: - return "Not enough memory"; + return "The server hosting Orthanc is running out of memory"; case ErrorCode_BadParameterType: return "Bad type for a parameter"; @@ -156,6 +156,9 @@ case ErrorCode_NotAcceptable: return "Cannot send a response which is acceptable according to the Accept HTTP header"; + case ErrorCode_NullPointer: + return "Cannot handle a NULL pointer"; + case ErrorCode_SQLiteNotOpened: return "SQLite: The database is not opened";
--- a/Framework/Orthanc/Core/Enumerations.h Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/Enumerations.h Wed Nov 09 14:17:33 2016 +0100 @@ -52,7 +52,7 @@ ErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, ErrorCode_NotImplemented = 2 /*!< Not implemented yet */, ErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */, - ErrorCode_NotEnoughMemory = 4 /*!< Not enough memory */, + ErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */, ErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */, ErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */, ErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */, @@ -83,6 +83,7 @@ ErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, ErrorCode_EmptyRequest = 33 /*!< The request is empty */, ErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */, + ErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */, ErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, ErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, ErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */,
--- a/Framework/Orthanc/Core/HttpClient.cpp Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/HttpClient.cpp Wed Nov 09 14:17:33 2016 +0100 @@ -44,7 +44,7 @@ #include <boost/thread/mutex.hpp> -#if ORTHANC_SSL_ENABLED == 1 +#if ORTHANC_ENABLE_SSL == 1 // For OpenSSL initialization and finalization # include <openssl/conf.h> # include <openssl/engine.h> @@ -54,7 +54,7 @@ #endif -#if ORTHANC_PKCS11_ENABLED == 1 +#if ORTHANC_ENABLE_PKCS11 == 1 # include "Pkcs11.h" #endif @@ -161,7 +161,7 @@ return timeout_; } -#if ORTHANC_PKCS11_ENABLED == 1 +#if ORTHANC_ENABLE_PKCS11 == 1 bool IsPkcs11Initialized() { boost::mutex::scoped_lock lock(mutex_); @@ -435,7 +435,7 @@ CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &headerParameters)); } -#if ORTHANC_SSL_ENABLED == 1 +#if ORTHANC_ENABLE_SSL == 1 // Setup HTTPS-related options if (verifyPeers_) @@ -461,7 +461,7 @@ if (pkcs11Enabled_) { -#if ORTHANC_PKCS11_ENABLED == 1 +#if ORTHANC_ENABLE_PKCS11 == 1 if (GlobalParameters::GetInstance().IsPkcs11Initialized()) { CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLENGINE, Pkcs11::GetEngineIdentifier())); @@ -480,7 +480,7 @@ } else if (!clientCertificateFile_.empty()) { -#if ORTHANC_SSL_ENABLED == 1 +#if ORTHANC_ENABLE_SSL == 1 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERTTYPE, "PEM")); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERT, clientCertificateFile_.c_str())); @@ -671,7 +671,7 @@ void HttpClient::ConfigureSsl(bool httpsVerifyPeers, const std::string& httpsVerifyCertificates) { -#if ORTHANC_SSL_ENABLED == 1 +#if ORTHANC_ENABLE_SSL == 1 if (httpsVerifyPeers) { if (httpsVerifyCertificates.empty()) @@ -696,7 +696,7 @@ void HttpClient::GlobalInitialize() { -#if ORTHANC_SSL_ENABLED == 1 +#if ORTHANC_ENABLE_SSL == 1 CheckCode(curl_global_init(CURL_GLOBAL_ALL)); #else CheckCode(curl_global_init(CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)); @@ -708,7 +708,7 @@ { curl_global_cleanup(); -#if ORTHANC_PKCS11_ENABLED == 1 +#if ORTHANC_ENABLE_PKCS11 == 1 Pkcs11::Finalize(); #endif } @@ -796,7 +796,7 @@ const std::string& pin, bool verbose) { -#if ORTHANC_PKCS11_ENABLED == 1 +#if ORTHANC_ENABLE_PKCS11 == 1 LOG(INFO) << "Initializing PKCS#11 using " << module << (pin.empty() ? " (no PIN provided)" : " (PIN is provided)"); GlobalParameters::GetInstance().InitializePkcs11(module, pin, verbose); @@ -809,7 +809,7 @@ void HttpClient::InitializeOpenSsl() { -#if ORTHANC_SSL_ENABLED == 1 +#if ORTHANC_ENABLE_SSL == 1 // https://wiki.openssl.org/index.php/Library_Initialization SSL_library_init(); SSL_load_error_strings(); @@ -821,7 +821,7 @@ void HttpClient::FinalizeOpenSsl() { - #if ORTHANC_SSL_ENABLED == 1 + #if ORTHANC_ENABLE_SSL == 1 // Finalize OpenSSL // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup FIPS_mode_set(0);
--- a/Framework/Orthanc/Core/Logging.cpp Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/Logging.cpp Wed Nov 09 14:17:33 2016 +0100 @@ -318,113 +318,123 @@ return; } - LogLevel l = StringToLogLevel(level); - - if ((l == LogLevel_Info && !loggingContext_->infoEnabled_) || - (l == LogLevel_Trace && !loggingContext_->traceEnabled_)) + try { - // This logging level is disabled, directly exit and unlock - // the mutex to speed-up things. The stream is set to "/dev/null" - lock_.unlock(); - return; - } + LogLevel l = StringToLogLevel(level); + + if ((l == LogLevel_Info && !loggingContext_->infoEnabled_) || + (l == LogLevel_Trace && !loggingContext_->traceEnabled_)) + { + // This logging level is disabled, directly exit and unlock + // the mutex to speed-up things. The stream is set to "/dev/null" + lock_.unlock(); + return; + } - // Compute the header of the line, temporary release the lock as - // this is a time-consuming operation - lock_.unlock(); - std::string header; + // Compute the header of the line, temporary release the lock as + // this is a time-consuming operation + lock_.unlock(); + std::string header; - { - boost::filesystem::path path(file); - boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); - boost::posix_time::time_duration duration = now.time_of_day(); + { + boost::filesystem::path path(file); + boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); + boost::posix_time::time_duration duration = now.time_of_day(); - /** - From Google Log documentation: + /** + From Google Log documentation: - "Log lines have this form: + "Log lines have this form: - Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... + Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... - where the fields are defined as follows: + where the fields are defined as follows: - L A single character, representing the log level (eg 'I' for INFO) - mm The month (zero padded; ie May is '05') - dd The day (zero padded) - hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds - threadid The space-padded thread ID as returned by GetTID() (this matches the PID on Linux) - file The file name - line The line number - msg The user-supplied message" + L A single character, representing the log level (eg 'I' for INFO) + mm The month (zero padded; ie May is '05') + dd The day (zero padded) + hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds + threadid The space-padded thread ID as returned by GetTID() (this matches the PID on Linux) + file The file name + line The line number + msg The user-supplied message" - In this implementation, "threadid" is not printed. - **/ + In this implementation, "threadid" is not printed. + **/ - char date[32]; - sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ", - level[0], - now.date().month().as_number(), - now.date().day().as_number(), - duration.hours(), - duration.minutes(), - duration.seconds(), - static_cast<int>(duration.fractional_seconds())); + char date[32]; + sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ", + level[0], + now.date().month().as_number(), + now.date().day().as_number(), + duration.hours(), + duration.minutes(), + duration.seconds(), + static_cast<int>(duration.fractional_seconds())); - header = std::string(date) + path.filename().string() + ":" + boost::lexical_cast<std::string>(line) + "] "; - } + header = std::string(date) + path.filename().string() + ":" + boost::lexical_cast<std::string>(line) + "] "; + } - // The header is computed, we now re-lock the mutex to access - // the stream objects. Pay attention that "loggingContext_", - // "infoEnabled_" or "traceEnabled_" might have changed while - // the mutex was unlocked. - lock_.lock(); + // The header is computed, we now re-lock the mutex to access + // the stream objects. Pay attention that "loggingContext_", + // "infoEnabled_" or "traceEnabled_" might have changed while + // the mutex was unlocked. + lock_.lock(); + + if (loggingContext_.get() == NULL) + { + fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine\n"); + return; + } - if (loggingContext_.get() == NULL) - { - fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine\n"); - return; - } + switch (l) + { + case LogLevel_Error: + stream_ = loggingContext_->error_; + break; - switch (l) - { - case LogLevel_Error: - stream_ = loggingContext_->error_; - break; + case LogLevel_Warning: + stream_ = loggingContext_->warning_; + break; - case LogLevel_Warning: - stream_ = loggingContext_->warning_; - break; + case LogLevel_Info: + if (loggingContext_->infoEnabled_) + { + stream_ = loggingContext_->info_; + } + + break; - case LogLevel_Info: - if (loggingContext_->infoEnabled_) - { - stream_ = loggingContext_->info_; - } + case LogLevel_Trace: + if (loggingContext_->traceEnabled_) + { + stream_ = loggingContext_->info_; + } - break; + break; - case LogLevel_Trace: - if (loggingContext_->traceEnabled_) - { - stream_ = loggingContext_->info_; - } + default: + throw OrthancException(ErrorCode_InternalError); + } - break; - - default: - throw OrthancException(ErrorCode_InternalError); - } + if (stream_ == &null_) + { + // The logging is disabled for this level. The stream is the + // "null_" member of this object, so we can release the global + // mutex. + lock_.unlock(); + } - if (stream_ == &null_) - { - // The logging is disabled for this level. The stream is the - // "null_" member of this object, so we can release the global - // mutex. - lock_.unlock(); + (*stream_) << header; } - - (*stream_) << header; + catch (...) + { + // Something is going really wrong, probably running out of + // memory. Fallback to a degraded mode. + stream_ = loggingContext_->error_; + (*stream_) << "E???? ??:??:??.?????? ] "; + } }
--- a/Framework/Orthanc/Core/Logging.h Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/Logging.h Wed Nov 09 14:17:33 2016 +0100 @@ -110,6 +110,12 @@ { return (*stream_) << message; } + + // This overload fixes build problems with Visual Studio 2015 + std::ostream& operator<< (const char* message) + { + return (*stream_) << message; + } }; } }
--- a/Framework/Orthanc/Core/PrecompiledHeaders.h Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/PrecompiledHeaders.h Wed Nov 09 14:17:33 2016 +0100 @@ -48,7 +48,7 @@ #include <json/value.h> -#if ORTHANC_PUGIXML_ENABLED == 1 +#if ORTHANC_ENABLE_PUGIXML == 1 #include <pugixml.hpp> #endif
--- a/Framework/Orthanc/Core/Toolbox.cpp Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/Toolbox.cpp Wed Nov 09 14:17:33 2016 +0100 @@ -103,7 +103,7 @@ #endif -#if ORTHANC_PUGIXML_ENABLED == 1 +#if ORTHANC_ENABLE_PUGIXML == 1 #include "ChunkedBuffer.h" #include <pugixml.hpp> #endif @@ -1207,7 +1207,7 @@ #endif -#if ORTHANC_PUGIXML_ENABLED == 1 +#if ORTHANC_ENABLE_PUGIXML == 1 class ChunkedBufferWriter : public pugi::xml_writer { private:
--- a/Framework/Orthanc/Core/Toolbox.h Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Core/Toolbox.h Wed Nov 09 14:17:33 2016 +0100 @@ -198,7 +198,7 @@ bool IsExistingFile(const std::string& path); #endif -#if ORTHANC_PUGIXML_ENABLED == 1 +#if ORTHANC_ENABLE_PUGIXML == 1 void JsonToXml(std::string& target, const Json::Value& source, const std::string& rootElement = "root",
--- a/Framework/Orthanc/Plugins/Engine/SharedLibrary.cpp Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Plugins/Engine/SharedLibrary.cpp Wed Nov 09 14:17:33 2016 +0100 @@ -33,7 +33,7 @@ #include "../../OrthancServer/PrecompiledHeadersServer.h" #include "SharedLibrary.h" -#if ORTHANC_PLUGINS_ENABLED != 1 +#if ORTHANC_ENABLE_PLUGINS != 1 #error The plugin support is disabled #endif
--- a/Framework/Orthanc/Plugins/Engine/SharedLibrary.h Tue Nov 08 10:51:48 2016 +0100 +++ b/Framework/Orthanc/Plugins/Engine/SharedLibrary.h Wed Nov 09 14:17:33 2016 +0100 @@ -32,7 +32,7 @@ #pragma once -#if ORTHANC_PLUGINS_ENABLED == 1 +#if ORTHANC_ENABLE_PLUGINS == 1 #include "../../Core/OrthancException.h"