Mercurial > hg > orthanc
changeset 911:306afd58a0b3 plugins
fix build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 20 Jun 2014 13:45:22 +0200 |
parents | 28a52982196e |
children | dcb2469f00f4 |
files | Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpOutput.h Core/HttpServer/MongooseServer.cpp |
diffstat | 3 files changed, 27 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp Fri Jun 20 13:38:19 2014 +0200 +++ b/Core/HttpServer/HttpOutput.cpp Fri Jun 20 13:45:22 2014 +0200 @@ -42,38 +42,6 @@ namespace Orthanc { - class HttpOutput::StateMachine : public boost::noncopyable - { - protected: - enum State - { - State_WaitingHttpStatus, - State_WritingHeader, - State_WritingBody - }; - - private: - IHttpOutputStream& stream_; - State state_; - - public: - HttpStateMachine() : - state_(State_WaitingHttpStatus) - { - } - - void SendHttpStatus(HttpStatus status); - - void SendHeaderData(const void* buffer, size_t length); - - void SendHeaderString(const std::string& str); - - void SendBodyData(const void* buffer, size_t length); - - void SendBodyString(const std::string& str); - }; - - void HttpOutput::StateMachine::SendHttpStatus(HttpStatus status) { if (state_ != State_WaitingHttpStatus) @@ -81,7 +49,7 @@ throw OrthancException(ErrorCode_BadSequenceOfCalls); } - OnHttpStatusReceived(status); + stream_.OnHttpStatusReceived(status); state_ = State_WritingHeader; std::string s = "HTTP/1.1 " + @@ -89,7 +57,7 @@ " " + std::string(EnumerationToString(status)) + "\r\n"; - Send(true, &s[0], s.size()); + stream_.Send(true, &s[0], s.size()); } void HttpOutput::StateMachine::SendHeaderData(const void* buffer, size_t length) @@ -99,7 +67,7 @@ throw OrthancException(ErrorCode_BadSequenceOfCalls); } - Send(true, buffer, length); + stream_.Send(true, buffer, length); } void HttpOutput::StateMachine::SendHeaderString(const std::string& str) @@ -120,13 +88,13 @@ if (state_ == State_WritingHeader) { // Close the HTTP header before writing the body - Send(true, "\r\n", 2); + stream_.Send(true, "\r\n", 2); state_ = State_WritingBody; } if (length > 0) { - Send(false, buffer, length); + stream_.Send(false, buffer, length); } } @@ -176,7 +144,7 @@ void HttpOutput::SendOkHeader(const Header& header) { - stream_.SendHttpStatus(HttpStatus_200_Ok); + stateMachine_.SendHttpStatus(HttpStatus_200_Ok); std::string s; for (Header::const_iterator @@ -185,14 +153,14 @@ s += it->first + ": " + it->second + "\r\n"; } - stream_.SendHeaderString(s); + stateMachine_.SendHeaderString(s); } void HttpOutput::SendMethodNotAllowedError(const std::string& allowed) { - stream_.SendHttpStatus(HttpStatus_405_MethodNotAllowed); - stream_.SendHeaderString("Allow: " + allowed + "\r\n"); + stateMachine_.SendHttpStatus(HttpStatus_405_MethodNotAllowed); + stateMachine_.SendHeaderString("Allow: " + allowed + "\r\n"); } @@ -206,7 +174,7 @@ throw OrthancException("Please use the dedicated methods to this HTTP status code in HttpOutput"); } - stream_.SendHttpStatus(status); + stateMachine_.SendHttpStatus(status); } @@ -265,15 +233,15 @@ void HttpOutput::Redirect(const std::string& path) { - stream_.SendHttpStatus(HttpStatus_301_MovedPermanently); - stream_.SendHeaderString("Location: " + path + "\r\n"); + stateMachine_.SendHttpStatus(HttpStatus_301_MovedPermanently); + stateMachine_.SendHeaderString("Location: " + path + "\r\n"); } void HttpOutput::SendUnauthorized(const std::string& realm) { - stream_.SendHttpStatus(HttpStatus_401_Unauthorized); - stream_.SendHeaderString("WWW-Authenticate: Basic realm=\"" + realm + "\"\r\n"); + stateMachine_.SendHttpStatus(HttpStatus_401_Unauthorized); + stateMachine_.SendHeaderString("WWW-Authenticate: Basic realm=\"" + realm + "\"\r\n"); } }
--- a/Core/HttpServer/HttpOutput.h Fri Jun 20 13:38:19 2014 +0200 +++ b/Core/HttpServer/HttpOutput.h Fri Jun 20 13:45:22 2014 +0200 @@ -48,7 +48,7 @@ class StateMachine : public boost::noncopyable { - protected: + private: enum State { State_WaitingHttpStatus, @@ -56,13 +56,12 @@ State_WritingBody }; - private: IHttpOutputStream& stream_; State state_; public: - HttpStateMachine(IHttpOutputStream& stream) : - stream_(stream) + StateMachine(IHttpOutputStream& stream) : + stream_(stream), state_(State_WaitingHttpStatus) { } @@ -103,12 +102,12 @@ void SendBodyData(const void* buffer, size_t length) { - stream_.SendBodyData(buffer, length); + stateMachine_.SendBodyData(buffer, length); } void SendBodyString(const std::string& str) { - stream_.SendBodyString(str); + stateMachine_.SendBodyString(str); } void SendMethodNotAllowedError(const std::string& allowed);
--- a/Core/HttpServer/MongooseServer.cpp Fri Jun 20 13:38:19 2014 +0200 +++ b/Core/HttpServer/MongooseServer.cpp Fri Jun 20 13:45:22 2014 +0200 @@ -68,12 +68,16 @@ namespace { // Anonymous namespace to avoid clashes between compilation modules - class MongooseOutputStream : public HttpOutputStream + class MongooseOutputStream : public IHttpOutputStream { private: struct mg_connection* connection_; - protected: + public: + MongooseOutputStream(struct mg_connection* connection) : connection_(connection) + { + } + virtual void Send(bool isHeader, const void* buffer, size_t length) { if (length > 0) @@ -82,9 +86,9 @@ } } - public: - MongooseOutputStream(struct mg_connection* connection) : connection_(connection) + virtual void OnHttpStatusReceived(HttpStatus status) { + // Ignore this } };