Mercurial > hg > orthanc
changeset 473:c9a5d72f8481
changing the namespace of HTTP enumerations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 15 Jul 2013 17:22:13 +0200 |
parents | 722b56b99093 |
children | a9693dc7089c |
files | CMakeLists.txt Core/Enumerations.h Core/HttpServer/EmbeddedResourceHttpHandler.cpp Core/HttpServer/EmbeddedResourceHttpHandler.h Core/HttpServer/FilesystemHttpHandler.cpp Core/HttpServer/FilesystemHttpHandler.h Core/HttpServer/HttpFileSender.cpp Core/HttpServer/HttpHandler.h Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpOutput.h Core/HttpServer/MongooseServer.cpp Core/HttpServer/MongooseServer.h Core/RestApi/RestApi.cpp Core/RestApi/RestApi.h Core/RestApi/RestApiOutput.cpp Core/RestApi/RestApiOutput.h Core/Toolbox.cpp Core/Toolbox.h OrthancCppClient/HttpClient.cpp OrthancCppClient/HttpClient.h OrthancCppClient/HttpEnumerations.cpp OrthancCppClient/HttpEnumerations.h OrthancCppClient/HttpException.cpp OrthancCppClient/HttpException.h OrthancServer/main.cpp |
diffstat | 25 files changed, 238 insertions(+), 304 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Jul 15 13:50:36 2013 +0200 +++ b/CMakeLists.txt Mon Jul 15 17:22:13 2013 +0200 @@ -153,7 +153,6 @@ Core/Lua/LuaFunctionCall.cpp OrthancCppClient/HttpClient.cpp - OrthancCppClient/HttpEnumerations.cpp OrthancCppClient/HttpException.cpp )
--- a/Core/Enumerations.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/Enumerations.h Mon Jul 15 17:22:13 2013 +0200 @@ -32,8 +32,6 @@ #pragma once -#include "../OrthancCppClient/HttpEnumerations.h" - namespace Orthanc { enum Endianness @@ -87,6 +85,87 @@ /** + * Most common, non-joke and non-experimental HTTP status codes + * http://en.wikipedia.org/wiki/List_of_HTTP_status_codes + **/ + enum HttpStatus + { + HttpStatus_None = -1, + + // 1xx Informational + HttpStatus_100_Continue = 100, + HttpStatus_101_SwitchingProtocols = 101, + HttpStatus_102_Processing = 102, + + // 2xx Success + HttpStatus_200_Ok = 200, + HttpStatus_201_Created = 201, + HttpStatus_202_Accepted = 202, + HttpStatus_203_NonAuthoritativeInformation = 203, + HttpStatus_204_NoContent = 204, + HttpStatus_205_ResetContent = 205, + HttpStatus_206_PartialContent = 206, + HttpStatus_207_MultiStatus = 207, + HttpStatus_208_AlreadyReported = 208, + HttpStatus_226_IMUsed = 226, + + // 3xx Redirection + HttpStatus_300_MultipleChoices = 300, + HttpStatus_301_MovedPermanently = 301, + HttpStatus_302_Found = 302, + HttpStatus_303_SeeOther = 303, + HttpStatus_304_NotModified = 304, + HttpStatus_305_UseProxy = 305, + HttpStatus_307_TemporaryRedirect = 307, + + // 4xx Client Error + HttpStatus_400_BadRequest = 400, + HttpStatus_401_Unauthorized = 401, + HttpStatus_402_PaymentRequired = 402, + HttpStatus_403_Forbidden = 403, + HttpStatus_404_NotFound = 404, + HttpStatus_405_MethodNotAllowed = 405, + HttpStatus_406_NotAcceptable = 406, + HttpStatus_407_ProxyAuthenticationRequired = 407, + HttpStatus_408_RequestTimeout = 408, + HttpStatus_409_Conflict = 409, + HttpStatus_410_Gone = 410, + HttpStatus_411_LengthRequired = 411, + HttpStatus_412_PreconditionFailed = 412, + HttpStatus_413_RequestEntityTooLarge = 413, + HttpStatus_414_RequestUriTooLong = 414, + HttpStatus_415_UnsupportedMediaType = 415, + HttpStatus_416_RequestedRangeNotSatisfiable = 416, + HttpStatus_417_ExpectationFailed = 417, + HttpStatus_422_UnprocessableEntity = 422, + HttpStatus_423_Locked = 423, + HttpStatus_424_FailedDependency = 424, + HttpStatus_426_UpgradeRequired = 426, + + // 5xx Server Error + HttpStatus_500_InternalServerError = 500, + HttpStatus_501_NotImplemented = 501, + HttpStatus_502_BadGateway = 502, + HttpStatus_503_ServiceUnavailable = 503, + HttpStatus_504_GatewayTimeout = 504, + HttpStatus_505_HttpVersionNotSupported = 505, + HttpStatus_506_VariantAlsoNegotiates = 506, + HttpStatus_507_InsufficientStorage = 507, + HttpStatus_509_BandwidthLimitExceeded = 509, + HttpStatus_510_NotExtended = 510 + }; + + + enum HttpMethod + { + HttpMethod_Get = 0, + HttpMethod_Post = 1, + HttpMethod_Delete = 2, + HttpMethod_Put = 3 + }; + + + /** * WARNING: Do not change the explicit values in the enumerations * below this point. This would result in incompatible databases * between versions of Orthanc!
--- a/Core/HttpServer/EmbeddedResourceHttpHandler.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/EmbeddedResourceHttpHandler.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -58,13 +58,13 @@ void EmbeddedResourceHttpHandler::Handle( HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments, const std::string&) { - if (method != Orthanc_HttpMethod_Get) + if (method != HttpMethod_Get) { output.SendMethodNotAllowedError("GET"); return; @@ -82,7 +82,7 @@ catch (OrthancException& e) { LOG(WARNING) << "Unable to find HTTP resource: " << resourcePath; - output.SendHeader(Orthanc_HttpStatus_404_NotFound); + output.SendHeader(HttpStatus_404_NotFound); } } }
--- a/Core/HttpServer/EmbeddedResourceHttpHandler.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/EmbeddedResourceHttpHandler.h Mon Jul 15 17:22:13 2013 +0200 @@ -54,7 +54,7 @@ virtual void Handle( HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments,
--- a/Core/HttpServer/FilesystemHttpHandler.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/FilesystemHttpHandler.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -127,13 +127,13 @@ void FilesystemHttpHandler::Handle( HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments, const std::string&) { - if (method != Orthanc_HttpMethod_Get) + if (method != HttpMethod_Get) { output.SendMethodNotAllowedError("GET"); return; @@ -161,7 +161,7 @@ } else { - output.SendHeader(Orthanc_HttpStatus_404_NotFound); + output.SendHeader(HttpStatus_404_NotFound); } } }
--- a/Core/HttpServer/FilesystemHttpHandler.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/FilesystemHttpHandler.h Mon Jul 15 17:22:13 2013 +0200 @@ -56,7 +56,7 @@ virtual void Handle( HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments,
--- a/Core/HttpServer/HttpFileSender.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/HttpFileSender.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -47,7 +47,7 @@ if (!SendData(output)) { - output.SendHeader(Orthanc_HttpStatus_500_InternalServerError); + output.SendHeader(HttpStatus_500_InternalServerError); } } }
--- a/Core/HttpServer/HttpHandler.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/HttpHandler.h Mon Jul 15 17:22:13 2013 +0200 @@ -36,7 +36,6 @@ #include <vector> #include <stdint.h> #include "../Toolbox.h" -#include "../../OrthancCppClient/HttpEnumerations.h" namespace Orthanc { @@ -54,7 +53,7 @@ virtual bool IsServedUri(const UriComponents& uri) = 0; virtual void Handle(HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& getArguments,
--- a/Core/HttpServer/HttpOutput.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/HttpOutput.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -104,17 +104,17 @@ void HttpOutput::SendMethodNotAllowedError(const std::string& allowed) { std::string s = - "HTTP/1.1 405 " + std::string(HttpException::GetDescription(Orthanc_HttpStatus_405_MethodNotAllowed)) + + "HTTP/1.1 405 " + std::string(HttpException::GetDescription(HttpStatus_405_MethodNotAllowed)) + "\r\nAllow: " + allowed + "\r\n\r\n"; Send(&s[0], s.size()); } - void HttpOutput::SendHeader(Orthanc_HttpStatus status) + void HttpOutput::SendHeader(HttpStatus status) { - if (status == Orthanc_HttpStatus_200_Ok || - status == Orthanc_HttpStatus_405_MethodNotAllowed) + if (status == HttpStatus_200_Ok || + status == HttpStatus_405_MethodNotAllowed) { throw OrthancException("Please use the dedicated methods to this HTTP status code in HttpOutput"); } @@ -123,7 +123,7 @@ } - void HttpOutput::SendHeaderInternal(Orthanc_HttpStatus status) + void HttpOutput::SendHeaderInternal(HttpStatus status) { std::string s = "HTTP/1.1 " + boost::lexical_cast<std::string>(status) + @@ -190,7 +190,7 @@ void HttpOutput::Redirect(const std::string& path) { std::string s = - "HTTP/1.1 301 " + std::string(HttpException::GetDescription(Orthanc_HttpStatus_301_MovedPermanently)) + + "HTTP/1.1 301 " + std::string(HttpException::GetDescription(HttpStatus_301_MovedPermanently)) + "\r\nLocation: " + path + "\r\n\r\n"; Send(&s[0], s.size());
--- a/Core/HttpServer/HttpOutput.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/HttpOutput.h Mon Jul 15 17:22:13 2013 +0200 @@ -45,7 +45,7 @@ private: typedef std::list< std::pair<std::string, std::string> > Header; - void SendHeaderInternal(Orthanc_HttpStatus status); + void SendHeaderInternal(HttpStatus status); void PrepareOkHeader(Header& header, const char* contentType, @@ -74,7 +74,7 @@ void SendMethodNotAllowedError(const std::string& allowed); - void SendHeader(Orthanc_HttpStatus status); + void SendHeader(HttpStatus status); void Redirect(const std::string& path);
--- a/Core/HttpServer/MongooseServer.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/MongooseServer.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -486,7 +486,7 @@ } - static bool ExtractMethod(Orthanc_HttpMethod& method, + static bool ExtractMethod(HttpMethod& method, const struct mg_request_info *request, const HttpHandler::Arguments& headers, const HttpHandler::Arguments& argumentsGET) @@ -523,12 +523,12 @@ if (overriden == "PUT") { - method = Orthanc_HttpMethod_Put; + method = HttpMethod_Put; return true; } else if (overriden == "DELETE") { - method = Orthanc_HttpMethod_Delete; + method = HttpMethod_Delete; return true; } else @@ -540,19 +540,19 @@ // No PUT/DELETE faking was present if (!strcmp(request->request_method, "GET")) { - method = Orthanc_HttpMethod_Get; + method = HttpMethod_Get; } else if (!strcmp(request->request_method, "POST")) { - method = Orthanc_HttpMethod_Post; + method = HttpMethod_Post; } else if (!strcmp(request->request_method, "DELETE")) { - method = Orthanc_HttpMethod_Delete; + method = HttpMethod_Delete; } else if (!strcmp(request->request_method, "PUT")) { - method = Orthanc_HttpMethod_Put; + method = HttpMethod_Put; } else { @@ -601,10 +601,10 @@ // Compute the HTTP method, taking method faking into consideration - Orthanc_HttpMethod method; + HttpMethod method; if (!ExtractMethod(method, request, headers, argumentsGET)) { - output.SendHeader(Orthanc_HttpStatus_400_BadRequest); + output.SendHeader(HttpStatus_400_BadRequest); return (void*) ""; } @@ -640,8 +640,8 @@ // Extract the body of the request for PUT and POST std::string body; - if (method == Orthanc_HttpMethod_Post || - method == Orthanc_HttpMethod_Put) + if (method == HttpMethod_Post || + method == HttpMethod_Put) { PostDataStatus status; @@ -668,11 +668,11 @@ switch (status) { case PostDataStatus_NoLength: - output.SendHeader(Orthanc_HttpStatus_411_LengthRequired); + output.SendHeader(HttpStatus_411_LengthRequired); return (void*) ""; case PostDataStatus_Failure: - output.SendHeader(Orthanc_HttpStatus_400_BadRequest); + output.SendHeader(HttpStatus_400_BadRequest); return (void*) ""; case PostDataStatus_Pending: @@ -693,7 +693,7 @@ } catch (OrthancException) { - output.SendHeader(Orthanc_HttpStatus_400_BadRequest); + output.SendHeader(HttpStatus_400_BadRequest); return (void*) ""; } @@ -703,28 +703,28 @@ { try { - LOG(INFO) << Orthanc_HttpMethod_ToString(method) << " " << Toolbox::FlattenUri(uri); + LOG(INFO) << Toolbox::ToString(method) << " " << Toolbox::FlattenUri(uri); handler->Handle(output, method, uri, headers, argumentsGET, body); } catch (OrthancException& e) { LOG(ERROR) << "MongooseServer Exception [" << e.What() << "]"; - output.SendHeader(Orthanc_HttpStatus_500_InternalServerError); + output.SendHeader(HttpStatus_500_InternalServerError); } catch (boost::bad_lexical_cast&) { LOG(ERROR) << "MongooseServer Exception: Bad lexical cast"; - output.SendHeader(Orthanc_HttpStatus_400_BadRequest); + output.SendHeader(HttpStatus_400_BadRequest); } catch (std::runtime_error&) { LOG(ERROR) << "MongooseServer Exception: Presumably a bad JSON request"; - output.SendHeader(Orthanc_HttpStatus_400_BadRequest); + output.SendHeader(HttpStatus_400_BadRequest); } } else { - output.SendHeader(Orthanc_HttpStatus_404_NotFound); + output.SendHeader(HttpStatus_404_NotFound); } // Mark as processed
--- a/Core/HttpServer/MongooseServer.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/HttpServer/MongooseServer.h Mon Jul 15 17:22:13 2013 +0200 @@ -51,7 +51,7 @@ { } - virtual bool IsAllowed(Orthanc_HttpMethod method, + virtual bool IsAllowed(HttpMethod method, const char* uri, const char* ip, const char* username) const = 0;
--- a/Core/RestApi/RestApi.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/RestApi/RestApi.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -180,7 +180,7 @@ } void RestApi::Handle(HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& getArguments, @@ -191,7 +191,7 @@ RestApiPath::Components components; UriComponents trailing; - if (method == Orthanc_HttpMethod_Get) + if (method == HttpMethod_Get) { for (GetHandlers::const_iterator it = getHandlers_.begin(); it != getHandlers_.end(); it++) @@ -213,7 +213,7 @@ } } } - else if (method == Orthanc_HttpMethod_Put) + else if (method == HttpMethod_Put) { for (PutHandlers::const_iterator it = putHandlers_.begin(); it != putHandlers_.end(); it++) @@ -235,7 +235,7 @@ } } } - else if (method == Orthanc_HttpMethod_Post) + else if (method == HttpMethod_Post) { for (PostHandlers::const_iterator it = postHandlers_.begin(); it != postHandlers_.end(); it++) @@ -257,7 +257,7 @@ } } } - else if (method == Orthanc_HttpMethod_Delete) + else if (method == HttpMethod_Delete) { for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); it != deleteHandlers_.end(); it++) @@ -280,7 +280,7 @@ if (!ok) { - LOG(INFO) << "REST method " << Orthanc_HttpMethod_ToString(method) + LOG(INFO) << "REST method " << Toolbox::ToString(method) << " not allowed on: " << Toolbox::FlattenUri(uri); output.SendMethodNotAllowedError(GetAcceptedMethods(uri)); }
--- a/Core/RestApi/RestApi.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/RestApi/RestApi.h Mon Jul 15 17:22:13 2013 +0200 @@ -212,7 +212,7 @@ virtual bool IsServedUri(const UriComponents& uri); virtual void Handle(HttpOutput& output, - Orthanc_HttpMethod method, + HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& getArguments,
--- a/Core/RestApi/RestApiOutput.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/RestApi/RestApiOutput.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -48,7 +48,7 @@ { if (!alreadySent_) { - output_.SendHeader(Orthanc_HttpStatus_400_BadRequest); + output_.SendHeader(HttpStatus_400_BadRequest); } } @@ -100,10 +100,10 @@ alreadySent_ = true; } - void RestApiOutput::SignalError(Orthanc_HttpStatus status) + void RestApiOutput::SignalError(HttpStatus status) { - if (status != Orthanc_HttpStatus_403_Forbidden && - status != Orthanc_HttpStatus_415_UnsupportedMediaType) + if (status != HttpStatus_403_Forbidden && + status != HttpStatus_415_UnsupportedMediaType) { throw OrthancException("This HTTP status is not allowed in a REST API"); }
--- a/Core/RestApi/RestApiOutput.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/RestApi/RestApiOutput.h Mon Jul 15 17:22:13 2013 +0200 @@ -74,7 +74,7 @@ size_t length, const std::string& contentType); - void SignalError(Orthanc_HttpStatus status); + void SignalError(HttpStatus status); void Redirect(const std::string& path);
--- a/Core/Toolbox.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/Toolbox.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -132,9 +132,9 @@ #if defined(_WIN32) static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) { - // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx - finish = true; - return true; + // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx + finish = true; + return true; } #else static void SignalHandler(int) @@ -169,7 +169,7 @@ void Toolbox::ServerBarrier() { #if defined(_WIN32) - SetConsoleCtrlHandler(ConsoleControlHandler, true); + SetConsoleCtrlHandler(ConsoleControlHandler, true); #else signal(SIGINT, SignalHandler); signal(SIGQUIT, SignalHandler); @@ -182,7 +182,7 @@ } #if defined(_WIN32) - SetConsoleCtrlHandler(ConsoleControlHandler, false); + SetConsoleCtrlHandler(ConsoleControlHandler, false); #else signal(SIGINT, NULL); signal(SIGQUIT, NULL); @@ -697,4 +697,26 @@ 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 "?"; + } + } }
--- a/Core/Toolbox.h Mon Jul 15 13:50:36 2013 +0200 +++ b/Core/Toolbox.h Mon Jul 15 17:22:13 2013 +0200 @@ -105,5 +105,7 @@ void UrlDecode(std::string& s); Endianness DetectEndianness(); + + const char* ToString(HttpMethod method); } }
--- a/OrthancCppClient/HttpClient.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/OrthancCppClient/HttpClient.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -98,8 +98,8 @@ CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); url_ = ""; - method_ = Orthanc_HttpMethod_Get; - lastStatus_ = Orthanc_HttpStatus_200_Ok; + method_ = HttpMethod_Get; + lastStatus_ = HttpStatus_200_Ok; isVerbose_ = false; } @@ -162,11 +162,11 @@ switch (method_) { - case Orthanc_HttpMethod_Get: + case HttpMethod_Get: CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); break; - case Orthanc_HttpMethod_Post: + case HttpMethod_Post: CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_)); @@ -183,12 +183,12 @@ break; - case Orthanc_HttpMethod_Delete: + case HttpMethod_Delete: CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); break; - case Orthanc_HttpMethod_Put: + case HttpMethod_Put: CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); break; @@ -205,11 +205,11 @@ if (status == 0) { // This corresponds to a call to an inexistent host - lastStatus_ = Orthanc_HttpStatus_500_InternalServerError; + lastStatus_ = HttpStatus_500_InternalServerError; } else { - lastStatus_ = static_cast<Orthanc_HttpStatus>(status); + lastStatus_ = static_cast<HttpStatus>(status); } return (status >= 200 && status < 300);
--- a/OrthancCppClient/HttpClient.h Mon Jul 15 13:50:36 2013 +0200 +++ b/OrthancCppClient/HttpClient.h Mon Jul 15 17:22:13 2013 +0200 @@ -27,7 +27,6 @@ #pragma once -#include "HttpEnumerations.h" #include "HttpException.h" #include <string> @@ -44,8 +43,8 @@ std::string url_; std::string credentials_; - Orthanc_HttpMethod method_; - Orthanc_HttpStatus lastStatus_; + HttpMethod method_; + HttpStatus lastStatus_; std::string postData_; bool isVerbose_; @@ -75,12 +74,12 @@ return url_; } - void SetMethod(Orthanc_HttpMethod method) + void SetMethod(HttpMethod method) { method_ = method; } - Orthanc_HttpMethod GetMethod() const + HttpMethod GetMethod() const { return method_; } @@ -106,7 +105,7 @@ bool Apply(Json::Value& answer); - Orthanc_HttpStatus GetLastStatus() const + HttpStatus GetLastStatus() const { return lastStatus_; }
--- a/OrthancCppClient/HttpEnumerations.cpp Mon Jul 15 13:50:36 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, - * Belgium - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - **/ - - -#include "HttpEnumerations.h" - -const char* Orthanc_HttpMethod_ToString(Orthanc_HttpMethod method) -{ - switch (method) - { - case Orthanc_HttpMethod_Get: - return "GET"; - - case Orthanc_HttpMethod_Post: - return "POST"; - - case Orthanc_HttpMethod_Delete: - return "DELETE"; - - case Orthanc_HttpMethod_Put: - return "PUT"; - - default: - return "?"; - } -} -
--- a/OrthancCppClient/HttpEnumerations.h Mon Jul 15 13:50:36 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, - * Belgium - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - **/ - - -#pragma once - - -/** - * This file contains the enumerations for the access to the Orthanc - * REST API in C and C++. Namespaces are not used, in order to enable - * the access in C. - **/ - -// Most common, non-joke and non-experimental HTTP status codes -// http://en.wikipedia.org/wiki/List_of_HTTP_status_codes -enum Orthanc_HttpStatus -{ - Orthanc_HttpStatus_None = -1, - - // 1xx Informational - Orthanc_HttpStatus_100_Continue = 100, - Orthanc_HttpStatus_101_SwitchingProtocols = 101, - Orthanc_HttpStatus_102_Processing = 102, - - // 2xx Success - Orthanc_HttpStatus_200_Ok = 200, - Orthanc_HttpStatus_201_Created = 201, - Orthanc_HttpStatus_202_Accepted = 202, - Orthanc_HttpStatus_203_NonAuthoritativeInformation = 203, - Orthanc_HttpStatus_204_NoContent = 204, - Orthanc_HttpStatus_205_ResetContent = 205, - Orthanc_HttpStatus_206_PartialContent = 206, - Orthanc_HttpStatus_207_MultiStatus = 207, - Orthanc_HttpStatus_208_AlreadyReported = 208, - Orthanc_HttpStatus_226_IMUsed = 226, - - // 3xx Redirection - Orthanc_HttpStatus_300_MultipleChoices = 300, - Orthanc_HttpStatus_301_MovedPermanently = 301, - Orthanc_HttpStatus_302_Found = 302, - Orthanc_HttpStatus_303_SeeOther = 303, - Orthanc_HttpStatus_304_NotModified = 304, - Orthanc_HttpStatus_305_UseProxy = 305, - Orthanc_HttpStatus_307_TemporaryRedirect = 307, - - // 4xx Client Error - Orthanc_HttpStatus_400_BadRequest = 400, - Orthanc_HttpStatus_401_Unauthorized = 401, - Orthanc_HttpStatus_402_PaymentRequired = 402, - Orthanc_HttpStatus_403_Forbidden = 403, - Orthanc_HttpStatus_404_NotFound = 404, - Orthanc_HttpStatus_405_MethodNotAllowed = 405, - Orthanc_HttpStatus_406_NotAcceptable = 406, - Orthanc_HttpStatus_407_ProxyAuthenticationRequired = 407, - Orthanc_HttpStatus_408_RequestTimeout = 408, - Orthanc_HttpStatus_409_Conflict = 409, - Orthanc_HttpStatus_410_Gone = 410, - Orthanc_HttpStatus_411_LengthRequired = 411, - Orthanc_HttpStatus_412_PreconditionFailed = 412, - Orthanc_HttpStatus_413_RequestEntityTooLarge = 413, - Orthanc_HttpStatus_414_RequestUriTooLong = 414, - Orthanc_HttpStatus_415_UnsupportedMediaType = 415, - Orthanc_HttpStatus_416_RequestedRangeNotSatisfiable = 416, - Orthanc_HttpStatus_417_ExpectationFailed = 417, - Orthanc_HttpStatus_422_UnprocessableEntity = 422, - Orthanc_HttpStatus_423_Locked = 423, - Orthanc_HttpStatus_424_FailedDependency = 424, - Orthanc_HttpStatus_426_UpgradeRequired = 426, - - // 5xx Server Error - Orthanc_HttpStatus_500_InternalServerError = 500, - Orthanc_HttpStatus_501_NotImplemented = 501, - Orthanc_HttpStatus_502_BadGateway = 502, - Orthanc_HttpStatus_503_ServiceUnavailable = 503, - Orthanc_HttpStatus_504_GatewayTimeout = 504, - Orthanc_HttpStatus_505_HttpVersionNotSupported = 505, - Orthanc_HttpStatus_506_VariantAlsoNegotiates = 506, - Orthanc_HttpStatus_507_InsufficientStorage = 507, - Orthanc_HttpStatus_509_BandwidthLimitExceeded = 509, - Orthanc_HttpStatus_510_NotExtended = 510 -}; - - -enum Orthanc_HttpMethod -{ - Orthanc_HttpMethod_Get = 0, - Orthanc_HttpMethod_Post = 1, - Orthanc_HttpMethod_Delete = 2, - Orthanc_HttpMethod_Put = 3 -}; - - -const char* Orthanc_HttpMethod_ToString(Orthanc_HttpMethod method);
--- a/OrthancCppClient/HttpException.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/OrthancCppClient/HttpException.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -31,7 +31,7 @@ { const char* HttpException::What() const { - if (status_ == Orthanc_HttpStatus_None) + if (status_ == HttpStatus_None) { return custom_.c_str(); } @@ -41,164 +41,164 @@ } } - const char* HttpException::GetDescription(Orthanc_HttpStatus status) + const char* HttpException::GetDescription(HttpStatus status) { switch (status) { - case Orthanc_HttpStatus_100_Continue: + case HttpStatus_100_Continue: return "Continue"; - case Orthanc_HttpStatus_101_SwitchingProtocols: + case HttpStatus_101_SwitchingProtocols: return "Switching Protocols"; - case Orthanc_HttpStatus_102_Processing: + case HttpStatus_102_Processing: return "Processing"; - case Orthanc_HttpStatus_200_Ok: + case HttpStatus_200_Ok: return "OK"; - case Orthanc_HttpStatus_201_Created: + case HttpStatus_201_Created: return "Created"; - case Orthanc_HttpStatus_202_Accepted: + case HttpStatus_202_Accepted: return "Accepted"; - case Orthanc_HttpStatus_203_NonAuthoritativeInformation: + case HttpStatus_203_NonAuthoritativeInformation: return "Non-Authoritative Information"; - case Orthanc_HttpStatus_204_NoContent: + case HttpStatus_204_NoContent: return "No Content"; - case Orthanc_HttpStatus_205_ResetContent: + case HttpStatus_205_ResetContent: return "Reset Content"; - case Orthanc_HttpStatus_206_PartialContent: + case HttpStatus_206_PartialContent: return "Partial Content"; - case Orthanc_HttpStatus_207_MultiStatus: + case HttpStatus_207_MultiStatus: return "Multi-Status"; - case Orthanc_HttpStatus_208_AlreadyReported: + case HttpStatus_208_AlreadyReported: return "Already Reported"; - case Orthanc_HttpStatus_226_IMUsed: + case HttpStatus_226_IMUsed: return "IM Used"; - case Orthanc_HttpStatus_300_MultipleChoices: + case HttpStatus_300_MultipleChoices: return "Multiple Choices"; - case Orthanc_HttpStatus_301_MovedPermanently: + case HttpStatus_301_MovedPermanently: return "Moved Permanently"; - case Orthanc_HttpStatus_302_Found: + case HttpStatus_302_Found: return "Found"; - case Orthanc_HttpStatus_303_SeeOther: + case HttpStatus_303_SeeOther: return "See Other"; - case Orthanc_HttpStatus_304_NotModified: + case HttpStatus_304_NotModified: return "Not Modified"; - case Orthanc_HttpStatus_305_UseProxy: + case HttpStatus_305_UseProxy: return "Use Proxy"; - case Orthanc_HttpStatus_307_TemporaryRedirect: + case HttpStatus_307_TemporaryRedirect: return "Temporary Redirect"; - case Orthanc_HttpStatus_400_BadRequest: + case HttpStatus_400_BadRequest: return "Bad Request"; - case Orthanc_HttpStatus_401_Unauthorized: + case HttpStatus_401_Unauthorized: return "Unauthorized"; - case Orthanc_HttpStatus_402_PaymentRequired: + case HttpStatus_402_PaymentRequired: return "Payment Required"; - case Orthanc_HttpStatus_403_Forbidden: + case HttpStatus_403_Forbidden: return "Forbidden"; - case Orthanc_HttpStatus_404_NotFound: + case HttpStatus_404_NotFound: return "Not Found"; - case Orthanc_HttpStatus_405_MethodNotAllowed: + case HttpStatus_405_MethodNotAllowed: return "Method Not Allowed"; - case Orthanc_HttpStatus_406_NotAcceptable: + case HttpStatus_406_NotAcceptable: return "Not Acceptable"; - case Orthanc_HttpStatus_407_ProxyAuthenticationRequired: + case HttpStatus_407_ProxyAuthenticationRequired: return "Proxy Authentication Required"; - case Orthanc_HttpStatus_408_RequestTimeout: + case HttpStatus_408_RequestTimeout: return "Request Timeout"; - case Orthanc_HttpStatus_409_Conflict: + case HttpStatus_409_Conflict: return "Conflict"; - case Orthanc_HttpStatus_410_Gone: + case HttpStatus_410_Gone: return "Gone"; - case Orthanc_HttpStatus_411_LengthRequired: + case HttpStatus_411_LengthRequired: return "Length Required"; - case Orthanc_HttpStatus_412_PreconditionFailed: + case HttpStatus_412_PreconditionFailed: return "Precondition Failed"; - case Orthanc_HttpStatus_413_RequestEntityTooLarge: + case HttpStatus_413_RequestEntityTooLarge: return "Request Entity Too Large"; - case Orthanc_HttpStatus_414_RequestUriTooLong: + case HttpStatus_414_RequestUriTooLong: return "Request-URI Too Long"; - case Orthanc_HttpStatus_415_UnsupportedMediaType: + case HttpStatus_415_UnsupportedMediaType: return "Unsupported Media Type"; - case Orthanc_HttpStatus_416_RequestedRangeNotSatisfiable: + case HttpStatus_416_RequestedRangeNotSatisfiable: return "Requested Range Not Satisfiable"; - case Orthanc_HttpStatus_417_ExpectationFailed: + case HttpStatus_417_ExpectationFailed: return "Expectation Failed"; - case Orthanc_HttpStatus_422_UnprocessableEntity: + case HttpStatus_422_UnprocessableEntity: return "Unprocessable Entity"; - case Orthanc_HttpStatus_423_Locked: + case HttpStatus_423_Locked: return "Locked"; - case Orthanc_HttpStatus_424_FailedDependency: + case HttpStatus_424_FailedDependency: return "Failed Dependency"; - case Orthanc_HttpStatus_426_UpgradeRequired: + case HttpStatus_426_UpgradeRequired: return "Upgrade Required"; - case Orthanc_HttpStatus_500_InternalServerError: + case HttpStatus_500_InternalServerError: return "Internal Server Error"; - case Orthanc_HttpStatus_501_NotImplemented: + case HttpStatus_501_NotImplemented: return "Not Implemented"; - case Orthanc_HttpStatus_502_BadGateway: + case HttpStatus_502_BadGateway: return "Bad Gateway"; - case Orthanc_HttpStatus_503_ServiceUnavailable: + case HttpStatus_503_ServiceUnavailable: return "Service Unavailable"; - case Orthanc_HttpStatus_504_GatewayTimeout: + case HttpStatus_504_GatewayTimeout: return "Gateway Timeout"; - case Orthanc_HttpStatus_505_HttpVersionNotSupported: + case HttpStatus_505_HttpVersionNotSupported: return "HTTP Version Not Supported"; - case Orthanc_HttpStatus_506_VariantAlsoNegotiates: + case HttpStatus_506_VariantAlsoNegotiates: return "Variant Also Negotiates"; - case Orthanc_HttpStatus_507_InsufficientStorage: + case HttpStatus_507_InsufficientStorage: return "Insufficient Storage"; - case Orthanc_HttpStatus_509_BandwidthLimitExceeded: + case HttpStatus_509_BandwidthLimitExceeded: return "Bandwidth Limit Exceeded"; - case Orthanc_HttpStatus_510_NotExtended: + case HttpStatus_510_NotExtended: return "Not Extended"; default:
--- a/OrthancCppClient/HttpException.h Mon Jul 15 13:50:36 2013 +0200 +++ b/OrthancCppClient/HttpException.h Mon Jul 15 17:22:13 2013 +0200 @@ -27,7 +27,7 @@ #pragma once -#include "HttpEnumerations.h" +#include "../Core/Enumerations.h" #include <string> @@ -36,24 +36,24 @@ class HttpException { private: - Orthanc_HttpStatus status_; + HttpStatus status_; std::string custom_; public: - static const char* GetDescription(Orthanc_HttpStatus status); + static const char* GetDescription(HttpStatus status); HttpException(const std::string& custom) { - status_ = Orthanc_HttpStatus_None; + status_ = HttpStatus_None; custom_ = custom; } - HttpException(Orthanc_HttpStatus status) + HttpException(HttpStatus status) { status_ = status; } - Orthanc_HttpStatus GetHttpStatus() const + HttpStatus GetHttpStatus() const { return status_; }
--- a/OrthancServer/main.cpp Mon Jul 15 13:50:36 2013 +0200 +++ b/OrthancServer/main.cpp Mon Jul 15 17:22:13 2013 +0200 @@ -158,7 +158,7 @@ { } - virtual bool IsAllowed(Orthanc_HttpMethod method, + virtual bool IsAllowed(HttpMethod method, const char* uri, const char* ip, const char* username) const @@ -172,19 +172,19 @@ switch (method) { - case Orthanc_HttpMethod_Get: + case HttpMethod_Get: call.PushString("GET"); break; - case Orthanc_HttpMethod_Put: + case HttpMethod_Put: call.PushString("PUT"); break; - case Orthanc_HttpMethod_Post: + case HttpMethod_Post: call.PushString("POST"); break; - case Orthanc_HttpMethod_Delete: + case HttpMethod_Delete: call.PushString("DELETE"); break;