Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 4201:2d5209153b32
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Sep 2020 08:18:28 +0200 |
parents | ff24a06b3474 |
children | 7bd5eab3ba25 |
comparison
equal
deleted
inserted
replaced
4200:7112a8af0b63 | 4201:2d5209153b32 |
---|---|
81 { | 81 { |
82 private: | 82 private: |
83 struct mg_connection* connection_; | 83 struct mg_connection* connection_; |
84 | 84 |
85 public: | 85 public: |
86 MongooseOutputStream(struct mg_connection* connection) : connection_(connection) | 86 explicit MongooseOutputStream(struct mg_connection* connection) : |
87 connection_(connection) | |
87 { | 88 { |
88 } | 89 } |
89 | 90 |
90 virtual void Send(bool isHeader, const void* buffer, size_t length) | 91 virtual void Send(bool isHeader, const void* buffer, size_t length) |
91 { | 92 { |
144 { | 145 { |
145 private: | 146 private: |
146 std::string filename_; | 147 std::string filename_; |
147 | 148 |
148 public: | 149 public: |
149 ChunkedFile(const std::string& filename) : | 150 explicit ChunkedFile(const std::string& filename) : |
150 filename_(filename) | 151 filename_(filename) |
151 { | 152 { |
152 } | 153 } |
153 | 154 |
154 const std::string& GetFilename() const | 155 const std::string& GetFilename() const |
282 | 283 |
283 struct HttpServer::PImpl | 284 struct HttpServer::PImpl |
284 { | 285 { |
285 struct mg_context *context_; | 286 struct mg_context *context_; |
286 ChunkStore chunkStore_; | 287 ChunkStore chunkStore_; |
288 | |
289 PImpl() : | |
290 context_(NULL) | |
291 { | |
292 } | |
287 }; | 293 }; |
288 | 294 |
289 | 295 |
290 ChunkStore& HttpServer::GetChunkStore() | 296 ChunkStore& HttpServer::GetChunkStore() |
291 { | 297 { |
298 const std::string& contentLength) | 304 const std::string& contentLength) |
299 { | 305 { |
300 size_t length; | 306 size_t length; |
301 try | 307 try |
302 { | 308 { |
303 length = boost::lexical_cast<size_t>(contentLength); | 309 int64_t tmp = boost::lexical_cast<int64_t>(contentLength); |
310 if (tmp < 0) | |
311 { | |
312 return PostDataStatus_NoLength; | |
313 } | |
314 | |
315 length = static_cast<size_t>(tmp); | |
304 } | 316 } |
305 catch (boost::bad_lexical_cast&) | 317 catch (boost::bad_lexical_cast&) |
306 { | 318 { |
307 return PostDataStatus_NoLength; | 319 return PostDataStatus_NoLength; |
308 } | |
309 | |
310 if (length < 0) | |
311 { | |
312 length = 0; | |
313 } | 320 } |
314 | 321 |
315 body.resize(length); | 322 body.resize(length); |
316 | 323 |
317 size_t pos = 0; | 324 size_t pos = 0; |
498 | 505 |
499 if (fileName == headers.end()) | 506 if (fileName == headers.end()) |
500 { | 507 { |
501 // This file is stored in a single chunk | 508 // This file is stored in a single chunk |
502 completedFile.resize(chunkSize); | 509 completedFile.resize(chunkSize); |
503 if (chunkSize > 0) | 510 memcpy(&completedFile[0], chunkData, chunkSize); |
504 { | |
505 memcpy(&completedFile[0], chunkData, chunkSize); | |
506 } | |
507 return PostDataStatus_Success; | 511 return PostDataStatus_Success; |
508 } | 512 } |
509 else | 513 else |
510 { | 514 { |
511 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize); | 515 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize); |
1051 { | 1055 { |
1052 return (pimpl_->context_ != NULL); | 1056 return (pimpl_->context_ != NULL); |
1053 } | 1057 } |
1054 | 1058 |
1055 | 1059 |
1056 HttpServer::HttpServer() : pimpl_(new PImpl) | 1060 HttpServer::HttpServer() : |
1057 { | 1061 pimpl_(new PImpl), |
1058 pimpl_->context_ = NULL; | 1062 handler_(NULL), |
1059 handler_ = NULL; | 1063 remoteAllowed_(false), |
1060 remoteAllowed_ = false; | 1064 authentication_(false), |
1061 authentication_ = false; | 1065 sslVerifyPeers_(false), |
1062 ssl_ = false; | 1066 ssl_(false), |
1063 sslVerifyPeers_ = false; | 1067 port_(8000), |
1064 port_ = 8000; | 1068 filter_(NULL), |
1065 filter_ = NULL; | 1069 keepAlive_(false), |
1066 keepAlive_ = false; | 1070 httpCompression_(true), |
1067 httpCompression_ = true; | 1071 exceptionFormatter_(NULL), |
1068 exceptionFormatter_ = NULL; | 1072 realm_(ORTHANC_REALM), |
1069 realm_ = ORTHANC_REALM; | 1073 threadsCount_(50), // Default value in mongoose |
1070 threadsCount_ = 50; // Default value in mongoose | 1074 tcpNoDelay_(true), |
1071 tcpNoDelay_ = true; | 1075 requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds) |
1072 requestTimeout_ = 30; // Default value in mongoose/civetweb (30 seconds) | 1076 { |
1073 | |
1074 #if ORTHANC_ENABLE_MONGOOSE == 1 | 1077 #if ORTHANC_ENABLE_MONGOOSE == 1 |
1075 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server"; | 1078 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server"; |
1076 #endif | 1079 #endif |
1077 | 1080 |
1078 #if ORTHANC_ENABLE_CIVETWEB == 1 | 1081 #if ORTHANC_ENABLE_CIVETWEB == 1 |
1382 } | 1385 } |
1383 | 1386 |
1384 | 1387 |
1385 void HttpServer::SetThreadsCount(unsigned int threads) | 1388 void HttpServer::SetThreadsCount(unsigned int threads) |
1386 { | 1389 { |
1387 if (threads <= 0) | 1390 if (threads == 0) |
1388 { | 1391 { |
1389 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1392 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1390 } | 1393 } |
1391 | 1394 |
1392 Stop(); | 1395 Stop(); |
1405 } | 1408 } |
1406 | 1409 |
1407 | 1410 |
1408 void HttpServer::SetRequestTimeout(unsigned int seconds) | 1411 void HttpServer::SetRequestTimeout(unsigned int seconds) |
1409 { | 1412 { |
1410 if (seconds <= 0) | 1413 if (seconds == 0) |
1411 { | 1414 { |
1412 throw OrthancException(ErrorCode_ParameterOutOfRange, | 1415 throw OrthancException(ErrorCode_ParameterOutOfRange, |
1413 "Request timeout must be a stricly positive integer"); | 1416 "Request timeout must be a stricly positive integer"); |
1414 } | 1417 } |
1415 | 1418 |