# HG changeset patch # User Sebastien Jodogne # Date 1604596863 -3600 # Node ID db3932f9660dc1f8c29112df936552d32530e2a6 # Parent 785a2713323e10ca53800c8efc751d0ad3a42ca2 abi continued diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/FilesystemHttpSender.cpp --- a/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -43,6 +43,34 @@ file_.seekg(0, file_.beg); } + FilesystemHttpSender::FilesystemHttpSender(const std::string& path) + { + Initialize(path); + } + + FilesystemHttpSender::FilesystemHttpSender(const boost::filesystem::path& path) + { + Initialize(path); + } + + FilesystemHttpSender::FilesystemHttpSender(const std::string& path, + MimeType contentType) + { + SetContentType(contentType); + Initialize(path); + } + + FilesystemHttpSender::FilesystemHttpSender(const FilesystemStorage& storage, + const std::string& uuid) + { + Initialize(storage.GetPath(uuid)); + } + + uint64_t FilesystemHttpSender::GetContentLength() + { + return size_; + } + bool FilesystemHttpSender::ReadNextChunk() { @@ -63,4 +91,14 @@ return chunkSize_ > 0; } + + const char *FilesystemHttpSender::GetChunkContent() + { + return chunk_.c_str(); + } + + size_t FilesystemHttpSender::GetChunkSize() + { + return chunkSize_; + } } diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h --- a/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h Thu Nov 05 18:21:03 2020 +0100 @@ -40,48 +40,26 @@ void Initialize(const boost::filesystem::path& path); public: - explicit FilesystemHttpSender(const std::string& path) - { - Initialize(path); - } + explicit FilesystemHttpSender(const std::string& path); - explicit FilesystemHttpSender(const boost::filesystem::path& path) - { - Initialize(path); - } + explicit FilesystemHttpSender(const boost::filesystem::path& path); FilesystemHttpSender(const std::string& path, - MimeType contentType) - { - SetContentType(contentType); - Initialize(path); - } + MimeType contentType); FilesystemHttpSender(const FilesystemStorage& storage, - const std::string& uuid) - { - Initialize(storage.GetPath(uuid)); - } + const std::string& uuid); /** * Implementation of the IHttpStreamAnswer interface. **/ - virtual uint64_t GetContentLength() ORTHANC_OVERRIDE - { - return size_; - } + virtual uint64_t GetContentLength() ORTHANC_OVERRIDE; virtual bool ReadNextChunk() ORTHANC_OVERRIDE; - virtual const char* GetChunkContent() ORTHANC_OVERRIDE - { - return chunk_.c_str(); - } + virtual const char* GetChunkContent() ORTHANC_OVERRIDE; - virtual size_t GetChunkSize() ORTHANC_OVERRIDE - { - return chunkSize_; - } + virtual size_t GetChunkSize() ORTHANC_OVERRIDE; }; } diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpFileSender.cpp --- a/OrthancFramework/Sources/HttpServer/HttpFileSender.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpFileSender.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -31,6 +31,21 @@ namespace Orthanc { + void HttpFileSender::SetContentType(MimeType contentType) + { + contentType_ = EnumerationToString(contentType); + } + + void HttpFileSender::SetContentType(const std::string &contentType) + { + contentType_ = contentType; + } + + const std::string &HttpFileSender::GetContentType() const + { + return contentType_; + } + void HttpFileSender::SetContentFilename(const std::string& filename) { filename_ = filename; @@ -41,6 +56,16 @@ } } + const std::string &HttpFileSender::GetContentFilename() const + { + return filename_; + } + + HttpCompression HttpFileSender::SetupHttpCompression(bool, bool) + { + return HttpCompression_None; + } + bool HttpFileSender::HasContentFilename(std::string& filename) { diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpFileSender.h --- a/OrthancFramework/Sources/HttpServer/HttpFileSender.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpFileSender.h Thu Nov 05 18:21:03 2020 +0100 @@ -34,38 +34,23 @@ std::string filename_; public: - void SetContentType(MimeType contentType) - { - contentType_ = EnumerationToString(contentType); - } + void SetContentType(MimeType contentType); - void SetContentType(const std::string& contentType) - { - contentType_ = contentType; - } + void SetContentType(const std::string& contentType); - const std::string& GetContentType() const - { - return contentType_; - } + const std::string& GetContentType() const; void SetContentFilename(const std::string& filename); - const std::string& GetContentFilename() const - { - return filename_; - } + const std::string& GetContentFilename() const; /** * Implementation of the IHttpStreamAnswer interface. **/ - virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/, - bool /*deflateAllowed*/) ORTHANC_OVERRIDE - { - return HttpCompression_None; - } + virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/, + bool /*deflateAllowed*/) ORTHANC_OVERRIDE; virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE; diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpOutput.cpp --- a/OrthancFramework/Sources/HttpServer/HttpOutput.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpOutput.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -282,6 +282,35 @@ } + HttpOutput::HttpOutput(IHttpOutputStream &stream, + bool isKeepAlive) : + stateMachine_(stream, isKeepAlive), + isDeflateAllowed_(false), + isGzipAllowed_(false) + { + } + + void HttpOutput::SetDeflateAllowed(bool allowed) + { + isDeflateAllowed_ = allowed; + } + + bool HttpOutput::IsDeflateAllowed() const + { + return isDeflateAllowed_; + } + + void HttpOutput::SetGzipAllowed(bool allowed) + { + isGzipAllowed_ = allowed; + } + + bool HttpOutput::IsGzipAllowed() const + { + return isGzipAllowed_; + } + + void HttpOutput::SendMethodNotAllowed(const std::string& allowed) { stateMachine_.ClearHeaders(); @@ -307,6 +336,41 @@ stateMachine_.SendBody(message, messageSize); } + void HttpOutput::SendStatus(HttpStatus status) + { + SendStatus(status, NULL, 0); + } + + void HttpOutput::SendStatus(HttpStatus status, const std::string &message) + { + SendStatus(status, message.c_str(), message.size()); + } + + void HttpOutput::SetContentType(MimeType contentType) + { + stateMachine_.SetContentType(EnumerationToString(contentType)); + } + + void HttpOutput::SetContentType(const std::string &contentType) + { + stateMachine_.SetContentType(contentType.c_str()); + } + + void HttpOutput::SetContentFilename(const char *filename) + { + stateMachine_.SetContentFilename(filename); + } + + void HttpOutput::SetCookie(const std::string &cookie, const std::string &value) + { + stateMachine_.SetCookie(cookie, value); + } + + void HttpOutput::AddHeader(const std::string &key, const std::string &value) + { + stateMachine_.AddHeader(key, value); + } + void HttpOutput::Redirect(const std::string& path) { @@ -325,8 +389,30 @@ stateMachine_.SendBody(NULL, 0); } + void HttpOutput::StartMultipart(const std::string &subType, const std::string &contentType) + { + stateMachine_.StartMultipart(subType, contentType); + } + + void HttpOutput::SendMultipartItem(const void *item, + size_t size, + const std::map &headers) + { + stateMachine_.SendMultipartItem(item, size, headers); + } + + void HttpOutput::CloseMultipart() + { + stateMachine_.CloseMultipart(); + } + + bool HttpOutput::IsWritingMultipart() const + { + return stateMachine_.GetState() == StateMachine::State_WritingMultipart; + } + - void HttpOutput::Answer(const void* buffer, + void HttpOutput::Answer(const void* buffer, size_t length) { if (length == 0) diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpOutput.h --- a/OrthancFramework/Sources/HttpServer/HttpOutput.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpOutput.h Thu Nov 05 18:21:03 2020 +0100 @@ -115,74 +115,36 @@ public: HttpOutput(IHttpOutputStream& stream, - bool isKeepAlive) : - stateMachine_(stream, isKeepAlive), - isDeflateAllowed_(false), - isGzipAllowed_(false) - { - } + bool isKeepAlive); - void SetDeflateAllowed(bool allowed) - { - isDeflateAllowed_ = allowed; - } + void SetDeflateAllowed(bool allowed); - bool IsDeflateAllowed() const - { - return isDeflateAllowed_; - } + bool IsDeflateAllowed() const; - void SetGzipAllowed(bool allowed) - { - isGzipAllowed_ = allowed; - } + void SetGzipAllowed(bool allowed); - bool IsGzipAllowed() const - { - return isGzipAllowed_; - } + bool IsGzipAllowed() const; void SendStatus(HttpStatus status, const char* message, size_t messageSize); - void SendStatus(HttpStatus status) - { - SendStatus(status, NULL, 0); - } + void SendStatus(HttpStatus status); void SendStatus(HttpStatus status, - const std::string& message) - { - SendStatus(status, message.c_str(), message.size()); - } + const std::string& message); - void SetContentType(MimeType contentType) - { - stateMachine_.SetContentType(EnumerationToString(contentType)); - } + void SetContentType(MimeType contentType); - void SetContentType(const std::string& contentType) - { - stateMachine_.SetContentType(contentType.c_str()); - } + void SetContentType(const std::string& contentType); - void SetContentFilename(const char* filename) - { - stateMachine_.SetContentFilename(filename); - } + void SetContentFilename(const char* filename); void SetCookie(const std::string& cookie, - const std::string& value) - { - stateMachine_.SetCookie(cookie, value); - } + const std::string& value); void AddHeader(const std::string& key, - const std::string& value) - { - stateMachine_.AddHeader(key, value); - } + const std::string& value); void Answer(const void* buffer, size_t length); @@ -198,27 +160,15 @@ void SendUnauthorized(const std::string& realm); void StartMultipart(const std::string& subType, - const std::string& contentType) - { - stateMachine_.StartMultipart(subType, contentType); - } + const std::string& contentType); - void SendMultipartItem(const void* item, + void SendMultipartItem(const void* item, size_t size, - const std::map& headers) - { - stateMachine_.SendMultipartItem(item, size, headers); - } + const std::map& headers); - void CloseMultipart() - { - stateMachine_.CloseMultipart(); - } + void CloseMultipart(); - bool IsWritingMultipart() const - { - return stateMachine_.GetState() == StateMachine::State_WritingMultipart; - } + bool IsWritingMultipart() const; void Answer(IHttpStreamAnswer& stream); diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -1523,6 +1523,11 @@ port_ = port; } + uint16_t HttpServer::GetPortNumber() const + { + return port_; + } + void HttpServer::Start() { #if ORTHANC_ENABLE_MONGOOSE == 1 @@ -1699,6 +1704,11 @@ registeredUsers_.insert(encoded); } + bool HttpServer::IsAuthenticationEnabled() const + { + return authentication_; + } + void HttpServer::SetSslEnabled(bool enabled) { Stop(); @@ -1749,6 +1759,11 @@ #endif } + const std::string &HttpServer::GetSslCertificate() const + { + return certificate_; + } + void HttpServer::SetAuthenticationEnabled(bool enabled) { @@ -1756,30 +1771,55 @@ authentication_ = enabled; } + bool HttpServer::IsSslEnabled() const + { + return ssl_; + } + void HttpServer::SetSslCertificate(const char* path) { Stop(); certificate_ = path; } + bool HttpServer::IsRemoteAccessAllowed() const + { + return remoteAllowed_; + } + void HttpServer::SetSslTrustedClientCertificates(const char* path) { Stop(); trustedClientCertificates_ = path; } + bool HttpServer::IsKeepAliveEnabled() const + { + return keepAlive_; + } + void HttpServer::SetRemoteAccessAllowed(bool allowed) { Stop(); remoteAllowed_ = allowed; } + bool HttpServer::IsHttpCompressionEnabled() const + { + return httpCompression_;; + } + void HttpServer::SetHttpCompressionEnabled(bool enabled) { Stop(); httpCompression_ = enabled; CLOG(WARNING, HTTP) << "HTTP compression is " << (enabled ? "enabled" : "disabled"); } + + IIncomingHttpRequestFilter *HttpServer::GetIncomingHttpRequestFilter() const + { + return filter_; + } void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) { @@ -1794,6 +1834,21 @@ exceptionFormatter_ = &formatter; } + IHttpExceptionFormatter *HttpServer::GetExceptionFormatter() + { + return exceptionFormatter_; + } + + const std::string &HttpServer::GetRealm() const + { + return realm_; + } + + void HttpServer::SetRealm(const std::string &realm) + { + realm_ = realm; + } + bool HttpServer::IsValidBasicHttpAuthentication(const std::string& basic) const { @@ -1807,6 +1862,11 @@ handler_ = &handler; } + bool HttpServer::HasHandler() const + { + return handler_ != NULL; + } + IHttpHandler& HttpServer::GetHandler() const { @@ -1832,6 +1892,11 @@ CLOG(INFO, HTTP) << "The embedded HTTP server will use " << threads << " threads"; } + unsigned int HttpServer::GetThreadsCount() const + { + return threadsCount_; + } + void HttpServer::SetTcpNoDelay(bool tcpNoDelay) { @@ -1841,6 +1906,11 @@ << (tcpNoDelay ? "true" : "false"); } + bool HttpServer::IsTcpNoDelay() const + { + return tcpNoDelay_; + } + void HttpServer::SetRequestTimeout(unsigned int seconds) { @@ -1855,6 +1925,19 @@ CLOG(INFO, HTTP) << "Request timeout in the HTTP server is set to " << seconds << " seconds"; } + unsigned int HttpServer::GetRequestTimeout() const + { + return requestTimeout_; + } + + +#if ORTHANC_ENABLE_PUGIXML == 1 + HttpServer::WebDavBuckets& HttpServer::GetWebDavBuckets() + { + return webDavBuckets_; + } +#endif + #if ORTHANC_ENABLE_PUGIXML == 1 void HttpServer::Register(const std::vector& root, diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpServer.h --- a/OrthancFramework/Sources/HttpServer/HttpServer.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.h Thu Nov 05 18:21:03 2020 +0100 @@ -120,10 +120,7 @@ void SetPortNumber(uint16_t port); - uint16_t GetPortNumber() const - { - return port_; - } + uint16_t GetPortNumber() const; void Start(); @@ -134,17 +131,11 @@ void RegisterUser(const char* username, const char* password); - bool IsAuthenticationEnabled() const - { - return authentication_; - } + bool IsAuthenticationEnabled() const; void SetAuthenticationEnabled(bool enabled); - bool IsSslEnabled() const - { - return ssl_; - } + bool IsSslEnabled() const; void SetSslEnabled(bool enabled); @@ -152,38 +143,23 @@ void SetSslTrustedClientCertificates(const char* path); - bool IsKeepAliveEnabled() const - { - return keepAlive_; - } + bool IsKeepAliveEnabled() const; void SetKeepAliveEnabled(bool enabled); - const std::string& GetSslCertificate() const - { - return certificate_; - } + const std::string& GetSslCertificate() const; void SetSslCertificate(const char* path); - bool IsRemoteAccessAllowed() const - { - return remoteAllowed_; - } + bool IsRemoteAccessAllowed() const; void SetRemoteAccessAllowed(bool allowed); - bool IsHttpCompressionEnabled() const - { - return httpCompression_;; - } + bool IsHttpCompressionEnabled() const; void SetHttpCompressionEnabled(bool enabled); - IIncomingHttpRequestFilter* GetIncomingHttpRequestFilter() const - { - return filter_; - } + IIncomingHttpRequestFilter* GetIncomingHttpRequestFilter() const; void SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter); @@ -193,57 +169,33 @@ void Register(IHttpHandler& handler); - bool HasHandler() const - { - return handler_ != NULL; - } + bool HasHandler() const; IHttpHandler& GetHandler() const; void SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter); - IHttpExceptionFormatter* GetExceptionFormatter() - { - return exceptionFormatter_; - } + IHttpExceptionFormatter* GetExceptionFormatter(); - const std::string& GetRealm() const - { - return realm_; - } + const std::string& GetRealm() const; - void SetRealm(const std::string& realm) - { - realm_ = realm; - } + void SetRealm(const std::string& realm); void SetThreadsCount(unsigned int threads); - unsigned int GetThreadsCount() const - { - return threadsCount_; - } + unsigned int GetThreadsCount() const; // New in Orthanc 1.5.2, not available for Mongoose void SetTcpNoDelay(bool tcpNoDelay); - bool IsTcpNoDelay() const - { - return tcpNoDelay_; - } + bool IsTcpNoDelay() const; void SetRequestTimeout(unsigned int seconds); - unsigned int GetRequestTimeout() const - { - return requestTimeout_; - } + unsigned int GetRequestTimeout() const; #if ORTHANC_ENABLE_PUGIXML == 1 - WebDavBuckets& GetWebDavBuckets() - { - return webDavBuckets_; - } + WebDavBuckets& GetWebDavBuckets(); #endif #if ORTHANC_ENABLE_PUGIXML == 1 diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.cpp --- a/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -98,6 +98,16 @@ } } + HttpStreamTranscoder::HttpStreamTranscoder(IHttpStreamAnswer &source, CompressionType compression) : + source_(source), + sourceCompression_(compression), + bytesToSkip_(0), + skipped_(0), + currentChunkOffset_(0), + ready_(false) + { + } + HttpCompression HttpStreamTranscoder::SetupHttpCompression(bool gzipAllowed, bool deflateAllowed) @@ -122,6 +132,16 @@ } } + bool HttpStreamTranscoder::HasContentFilename(std::string &filename) + { + return source_.HasContentFilename(filename); + } + + std::string HttpStreamTranscoder::GetContentType() + { + return source_.GetContentType(); + } + uint64_t HttpStreamTranscoder::GetContentLength() { diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h --- a/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h Thu Nov 05 18:21:03 2020 +0100 @@ -48,29 +48,15 @@ public: HttpStreamTranscoder(IHttpStreamAnswer& source, - CompressionType compression) : - source_(source), - sourceCompression_(compression), - bytesToSkip_(0), - skipped_(0), - currentChunkOffset_(0), - ready_(false) - { - } + CompressionType compression); // This is the first method to be called virtual HttpCompression SetupHttpCompression(bool gzipAllowed, bool deflateAllowed) ORTHANC_OVERRIDE; - virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE - { - return source_.HasContentFilename(filename); - } + virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE; - virtual std::string GetContentType() ORTHANC_OVERRIDE - { - return source_.GetContentType(); - } + virtual std::string GetContentType() ORTHANC_OVERRIDE; virtual uint64_t GetContentLength() ORTHANC_OVERRIDE; diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp --- a/OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -232,7 +232,17 @@ } } - + size_t MultipartStreamReader::GetBlockSize() const + { + return blockSize_; + } + + void MultipartStreamReader::SetHandler(MultipartStreamReader::IHandler &handler) + { + handler_ = &handler; + } + + void MultipartStreamReader::AddChunk(const void* chunk, size_t size) { diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/HttpServer/MultipartStreamReader.h --- a/OrthancFramework/Sources/HttpServer/MultipartStreamReader.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/MultipartStreamReader.h Thu Nov 05 18:21:03 2020 +0100 @@ -68,15 +68,9 @@ void SetBlockSize(size_t size); - size_t GetBlockSize() const - { - return blockSize_; - } + size_t GetBlockSize() const; - void SetHandler(IHandler& handler) - { - handler_ = &handler; - } + void SetHandler(IHandler& handler); void AddChunk(const void* chunk, size_t size); diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/Images/FontRegistry.cpp --- a/OrthancFramework/Sources/Images/FontRegistry.cpp Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/Images/FontRegistry.cpp Thu Nov 05 18:21:03 2020 +0100 @@ -55,6 +55,10 @@ } #endif + size_t FontRegistry::GetSize() const + { + return fonts_.size(); + } const Font& FontRegistry::GetFont(size_t i) const { @@ -80,5 +84,4 @@ return NULL; } - } diff -r 785a2713323e -r db3932f9660d OrthancFramework/Sources/Images/FontRegistry.h --- a/OrthancFramework/Sources/Images/FontRegistry.h Thu Nov 05 17:20:49 2020 +0100 +++ b/OrthancFramework/Sources/Images/FontRegistry.h Thu Nov 05 18:21:03 2020 +0100 @@ -42,10 +42,7 @@ void AddFromFile(const std::string& path); #endif - size_t GetSize() const - { - return fonts_.size(); - } + size_t GetSize() const; const Font& GetFont(size_t i) const;