Mercurial > hg > orthanc
changeset 477:6f8ae46ed90e
moves
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 15 Jul 2013 21:27:49 +0200 |
parents | 4aae0261515e |
children | 888f8a778e70 |
files | CMakeLists.txt Core/Enumerations.cpp Core/Enumerations.h Core/HttpClient.cpp Core/HttpServer/HttpOutput.cpp Core/HttpServer/MongooseServer.cpp Core/RestApi/RestApi.cpp Core/Toolbox.cpp Core/Toolbox.h OrthancCppClient/CMakeLists.txt OrthancCppClient/main.cpp |
diffstat | 11 files changed, 242 insertions(+), 202 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Jul 15 17:37:24 2013 +0200 +++ b/CMakeLists.txt Mon Jul 15 21:27:49 2013 +0200 @@ -122,6 +122,7 @@ Core/DicomFormat/DicomTag.cpp Core/DicomFormat/DicomIntegerPixelAccessor.cpp Core/DicomFormat/DicomInstanceHasher.cpp + Core/Enumerations.cpp Core/FileStorage/FileStorage.cpp Core/FileStorage/StorageAccessor.cpp Core/FileStorage/CompressedFileStorageAccessor.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/Enumerations.cpp Mon Jul 15 21:27:49 2013 +0200 @@ -0,0 +1,225 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "Enumerations.h" + +#include "OrthancException.h" + +namespace Orthanc +{ + const char* EnumerationToString(HttpMethod method) + { + switch (method) + { + case HttpMethod_Get: + return "GET"; + + case HttpMethod_Post: + return "POST"; + + case HttpMethod_Delete: + return "DELETE"; + + case HttpMethod_Put: + return "PUT"; + + default: + return "?"; + } + } + + + const char* EnumerationToString(HttpStatus status) + { + switch (status) + { + case HttpStatus_100_Continue: + return "Continue"; + + case HttpStatus_101_SwitchingProtocols: + return "Switching Protocols"; + + case HttpStatus_102_Processing: + return "Processing"; + + case HttpStatus_200_Ok: + return "OK"; + + case HttpStatus_201_Created: + return "Created"; + + case HttpStatus_202_Accepted: + return "Accepted"; + + case HttpStatus_203_NonAuthoritativeInformation: + return "Non-Authoritative Information"; + + case HttpStatus_204_NoContent: + return "No Content"; + + case HttpStatus_205_ResetContent: + return "Reset Content"; + + case HttpStatus_206_PartialContent: + return "Partial Content"; + + case HttpStatus_207_MultiStatus: + return "Multi-Status"; + + case HttpStatus_208_AlreadyReported: + return "Already Reported"; + + case HttpStatus_226_IMUsed: + return "IM Used"; + + case HttpStatus_300_MultipleChoices: + return "Multiple Choices"; + + case HttpStatus_301_MovedPermanently: + return "Moved Permanently"; + + case HttpStatus_302_Found: + return "Found"; + + case HttpStatus_303_SeeOther: + return "See Other"; + + case HttpStatus_304_NotModified: + return "Not Modified"; + + case HttpStatus_305_UseProxy: + return "Use Proxy"; + + case HttpStatus_307_TemporaryRedirect: + return "Temporary Redirect"; + + case HttpStatus_400_BadRequest: + return "Bad Request"; + + case HttpStatus_401_Unauthorized: + return "Unauthorized"; + + case HttpStatus_402_PaymentRequired: + return "Payment Required"; + + case HttpStatus_403_Forbidden: + return "Forbidden"; + + case HttpStatus_404_NotFound: + return "Not Found"; + + case HttpStatus_405_MethodNotAllowed: + return "Method Not Allowed"; + + case HttpStatus_406_NotAcceptable: + return "Not Acceptable"; + + case HttpStatus_407_ProxyAuthenticationRequired: + return "Proxy Authentication Required"; + + case HttpStatus_408_RequestTimeout: + return "Request Timeout"; + + case HttpStatus_409_Conflict: + return "Conflict"; + + case HttpStatus_410_Gone: + return "Gone"; + + case HttpStatus_411_LengthRequired: + return "Length Required"; + + case HttpStatus_412_PreconditionFailed: + return "Precondition Failed"; + + case HttpStatus_413_RequestEntityTooLarge: + return "Request Entity Too Large"; + + case HttpStatus_414_RequestUriTooLong: + return "Request-URI Too Long"; + + case HttpStatus_415_UnsupportedMediaType: + return "Unsupported Media Type"; + + case HttpStatus_416_RequestedRangeNotSatisfiable: + return "Requested Range Not Satisfiable"; + + case HttpStatus_417_ExpectationFailed: + return "Expectation Failed"; + + case HttpStatus_422_UnprocessableEntity: + return "Unprocessable Entity"; + + case HttpStatus_423_Locked: + return "Locked"; + + case HttpStatus_424_FailedDependency: + return "Failed Dependency"; + + case HttpStatus_426_UpgradeRequired: + return "Upgrade Required"; + + case HttpStatus_500_InternalServerError: + return "Internal Server Error"; + + case HttpStatus_501_NotImplemented: + return "Not Implemented"; + + case HttpStatus_502_BadGateway: + return "Bad Gateway"; + + case HttpStatus_503_ServiceUnavailable: + return "Service Unavailable"; + + case HttpStatus_504_GatewayTimeout: + return "Gateway Timeout"; + + case HttpStatus_505_HttpVersionNotSupported: + return "HTTP Version Not Supported"; + + case HttpStatus_506_VariantAlsoNegotiates: + return "Variant Also Negotiates"; + + case HttpStatus_507_InsufficientStorage: + return "Insufficient Storage"; + + case HttpStatus_509_BandwidthLimitExceeded: + return "Bandwidth Limit Exceeded"; + + case HttpStatus_510_NotExtended: + return "Not Extended"; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } +}
--- a/Core/Enumerations.h Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/Enumerations.h Mon Jul 15 21:27:49 2013 +0200 @@ -182,4 +182,10 @@ FileContentType_Dicom = 1, FileContentType_Json = 2 }; + + + + const char* EnumerationToString(HttpMethod method); + + const char* EnumerationToString(HttpStatus status); }
--- a/Core/HttpClient.cpp Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/HttpClient.cpp Mon Jul 15 21:27:49 2013 +0200 @@ -252,6 +252,6 @@ const char* HttpClient::GetLastStatusText() const { - return Toolbox::ToString(lastStatus_); + return EnumerationToString(lastStatus_); } }
--- a/Core/HttpServer/HttpOutput.cpp Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/HttpServer/HttpOutput.cpp Mon Jul 15 21:27:49 2013 +0200 @@ -103,7 +103,7 @@ void HttpOutput::SendMethodNotAllowedError(const std::string& allowed) { std::string s = - "HTTP/1.1 405 " + std::string(Toolbox::ToString(HttpStatus_405_MethodNotAllowed)) + + "HTTP/1.1 405 " + std::string(EnumerationToString(HttpStatus_405_MethodNotAllowed)) + "\r\nAllow: " + allowed + "\r\n\r\n"; Send(&s[0], s.size()); @@ -126,7 +126,7 @@ { std::string s = "HTTP/1.1 " + boost::lexical_cast<std::string>(status) + - " " + std::string(Toolbox::ToString(status)) + + " " + std::string(EnumerationToString(status)) + "\r\n\r\n"; Send(&s[0], s.size()); } @@ -189,7 +189,7 @@ void HttpOutput::Redirect(const std::string& path) { std::string s = - "HTTP/1.1 301 " + std::string(Toolbox::ToString(HttpStatus_301_MovedPermanently)) + + "HTTP/1.1 301 " + std::string(EnumerationToString(HttpStatus_301_MovedPermanently)) + "\r\nLocation: " + path + "\r\n\r\n"; Send(&s[0], s.size());
--- a/Core/HttpServer/MongooseServer.cpp Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/HttpServer/MongooseServer.cpp Mon Jul 15 21:27:49 2013 +0200 @@ -703,7 +703,7 @@ { try { - LOG(INFO) << Toolbox::ToString(method) << " " << Toolbox::FlattenUri(uri); + LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); handler->Handle(output, method, uri, headers, argumentsGET, body); } catch (OrthancException& e)
--- a/Core/RestApi/RestApi.cpp Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/RestApi/RestApi.cpp Mon Jul 15 21:27:49 2013 +0200 @@ -280,7 +280,7 @@ if (!ok) { - LOG(INFO) << "REST method " << Toolbox::ToString(method) + LOG(INFO) << "REST method " << EnumerationToString(method) << " not allowed on: " << Toolbox::FlattenUri(uri); output.SendMethodNotAllowedError(GetAcceptedMethods(uri)); }
--- a/Core/Toolbox.cpp Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/Toolbox.cpp Mon Jul 15 21:27:49 2013 +0200 @@ -697,192 +697,4 @@ throw OrthancException(ErrorCode_NotImplemented); } } - - - const char* Toolbox::ToString(HttpMethod method) - { - switch (method) - { - case HttpMethod_Get: - return "GET"; - - case HttpMethod_Post: - return "POST"; - - case HttpMethod_Delete: - return "DELETE"; - - case HttpMethod_Put: - return "PUT"; - - default: - return "?"; - } - } - - - const char* Toolbox::ToString(HttpStatus status) - { - switch (status) - { - case HttpStatus_100_Continue: - return "Continue"; - - case HttpStatus_101_SwitchingProtocols: - return "Switching Protocols"; - - case HttpStatus_102_Processing: - return "Processing"; - - case HttpStatus_200_Ok: - return "OK"; - - case HttpStatus_201_Created: - return "Created"; - - case HttpStatus_202_Accepted: - return "Accepted"; - - case HttpStatus_203_NonAuthoritativeInformation: - return "Non-Authoritative Information"; - - case HttpStatus_204_NoContent: - return "No Content"; - - case HttpStatus_205_ResetContent: - return "Reset Content"; - - case HttpStatus_206_PartialContent: - return "Partial Content"; - - case HttpStatus_207_MultiStatus: - return "Multi-Status"; - - case HttpStatus_208_AlreadyReported: - return "Already Reported"; - - case HttpStatus_226_IMUsed: - return "IM Used"; - - case HttpStatus_300_MultipleChoices: - return "Multiple Choices"; - - case HttpStatus_301_MovedPermanently: - return "Moved Permanently"; - - case HttpStatus_302_Found: - return "Found"; - - case HttpStatus_303_SeeOther: - return "See Other"; - - case HttpStatus_304_NotModified: - return "Not Modified"; - - case HttpStatus_305_UseProxy: - return "Use Proxy"; - - case HttpStatus_307_TemporaryRedirect: - return "Temporary Redirect"; - - case HttpStatus_400_BadRequest: - return "Bad Request"; - - case HttpStatus_401_Unauthorized: - return "Unauthorized"; - - case HttpStatus_402_PaymentRequired: - return "Payment Required"; - - case HttpStatus_403_Forbidden: - return "Forbidden"; - - case HttpStatus_404_NotFound: - return "Not Found"; - - case HttpStatus_405_MethodNotAllowed: - return "Method Not Allowed"; - - case HttpStatus_406_NotAcceptable: - return "Not Acceptable"; - - case HttpStatus_407_ProxyAuthenticationRequired: - return "Proxy Authentication Required"; - - case HttpStatus_408_RequestTimeout: - return "Request Timeout"; - - case HttpStatus_409_Conflict: - return "Conflict"; - - case HttpStatus_410_Gone: - return "Gone"; - - case HttpStatus_411_LengthRequired: - return "Length Required"; - - case HttpStatus_412_PreconditionFailed: - return "Precondition Failed"; - - case HttpStatus_413_RequestEntityTooLarge: - return "Request Entity Too Large"; - - case HttpStatus_414_RequestUriTooLong: - return "Request-URI Too Long"; - - case HttpStatus_415_UnsupportedMediaType: - return "Unsupported Media Type"; - - case HttpStatus_416_RequestedRangeNotSatisfiable: - return "Requested Range Not Satisfiable"; - - case HttpStatus_417_ExpectationFailed: - return "Expectation Failed"; - - case HttpStatus_422_UnprocessableEntity: - return "Unprocessable Entity"; - - case HttpStatus_423_Locked: - return "Locked"; - - case HttpStatus_424_FailedDependency: - return "Failed Dependency"; - - case HttpStatus_426_UpgradeRequired: - return "Upgrade Required"; - - case HttpStatus_500_InternalServerError: - return "Internal Server Error"; - - case HttpStatus_501_NotImplemented: - return "Not Implemented"; - - case HttpStatus_502_BadGateway: - return "Bad Gateway"; - - case HttpStatus_503_ServiceUnavailable: - return "Service Unavailable"; - - case HttpStatus_504_GatewayTimeout: - return "Gateway Timeout"; - - case HttpStatus_505_HttpVersionNotSupported: - return "HTTP Version Not Supported"; - - case HttpStatus_506_VariantAlsoNegotiates: - return "Variant Also Negotiates"; - - case HttpStatus_507_InsufficientStorage: - return "Insufficient Storage"; - - case HttpStatus_509_BandwidthLimitExceeded: - return "Bandwidth Limit Exceeded"; - - case HttpStatus_510_NotExtended: - return "Not Extended"; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - } }
--- a/Core/Toolbox.h Mon Jul 15 17:37:24 2013 +0200 +++ b/Core/Toolbox.h Mon Jul 15 21:27:49 2013 +0200 @@ -105,9 +105,5 @@ void UrlDecode(std::string& s); Endianness DetectEndianness(); - - const char* ToString(HttpMethod method); - - const char* ToString(HttpStatus status); } }
--- a/OrthancCppClient/CMakeLists.txt Mon Jul 15 17:37:24 2013 +0200 +++ b/OrthancCppClient/CMakeLists.txt Mon Jul 15 21:27:49 2013 +0200 @@ -22,10 +22,10 @@ add_library(OrthancCppClient SHARED - ${THIRD_PARTY_SOURCES} - HttpException.cpp - HttpClient.cpp + ../Core/OrthancException.cpp + ../Core/Enumerations.cpp + ../Core/HttpClient.cpp ) add_executable(Test