Mercurial > hg > orthanc
comparison OrthancServer/Sources/main.cpp @ 4205:d962a2996637
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Sep 2020 17:58:19 +0200 |
parents | 9ce5c89328f5 |
children | 7bd5eab3ba25 |
comparison
equal
deleted
inserted
replaced
4204:318c16cfccab | 4205:d962a2996637 |
---|---|
64 { | 64 { |
65 private: | 65 private: |
66 ServerContext& context_; | 66 ServerContext& context_; |
67 | 67 |
68 public: | 68 public: |
69 OrthancStoreRequestHandler(ServerContext& context) : | 69 explicit OrthancStoreRequestHandler(ServerContext& context) : |
70 context_(context) | 70 context_(context) |
71 { | 71 { |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 virtual void Handle(const std::string& dicomFile, | 75 virtual void Handle(const std::string& dicomFile, |
76 const DicomMap& dicomSummary, | 76 const DicomMap& dicomSummary, |
77 const Json::Value& dicomJson, | 77 const Json::Value& dicomJson, |
78 const std::string& remoteIp, | 78 const std::string& remoteIp, |
79 const std::string& remoteAet, | 79 const std::string& remoteAet, |
80 const std::string& calledAet) | 80 const std::string& calledAet) ORTHANC_OVERRIDE |
81 { | 81 { |
82 if (dicomFile.size() > 0) | 82 if (dicomFile.size() > 0) |
83 { | 83 { |
84 DicomInstanceToStore toStore; | 84 DicomInstanceToStore toStore; |
85 toStore.SetOrigin(DicomInstanceOrigin::FromDicomProtocol | 85 toStore.SetOrigin(DicomInstanceOrigin::FromDicomProtocol |
100 { | 100 { |
101 private: | 101 private: |
102 ServerContext& context_; | 102 ServerContext& context_; |
103 | 103 |
104 public: | 104 public: |
105 OrthancStorageCommitmentRequestHandler(ServerContext& context) : | 105 explicit OrthancStorageCommitmentRequestHandler(ServerContext& context) : |
106 context_(context) | 106 context_(context) |
107 { | 107 { |
108 } | 108 } |
109 | 109 |
110 virtual void HandleRequest(const std::string& transactionUid, | 110 virtual void HandleRequest(const std::string& transactionUid, |
111 const std::vector<std::string>& referencedSopClassUids, | 111 const std::vector<std::string>& referencedSopClassUids, |
112 const std::vector<std::string>& referencedSopInstanceUids, | 112 const std::vector<std::string>& referencedSopInstanceUids, |
113 const std::string& remoteIp, | 113 const std::string& remoteIp, |
114 const std::string& remoteAet, | 114 const std::string& remoteAet, |
115 const std::string& calledAet) | 115 const std::string& calledAet) ORTHANC_OVERRIDE |
116 { | 116 { |
117 if (referencedSopClassUids.size() != referencedSopInstanceUids.size()) | 117 if (referencedSopClassUids.size() != referencedSopInstanceUids.size()) |
118 { | 118 { |
119 throw OrthancException(ErrorCode_InternalError); | 119 throw OrthancException(ErrorCode_InternalError); |
120 } | 120 } |
138 const std::vector<std::string>& failedSopClassUids, | 138 const std::vector<std::string>& failedSopClassUids, |
139 const std::vector<std::string>& failedSopInstanceUids, | 139 const std::vector<std::string>& failedSopInstanceUids, |
140 const std::vector<StorageCommitmentFailureReason>& failureReasons, | 140 const std::vector<StorageCommitmentFailureReason>& failureReasons, |
141 const std::string& remoteIp, | 141 const std::string& remoteIp, |
142 const std::string& remoteAet, | 142 const std::string& remoteAet, |
143 const std::string& calledAet) | 143 const std::string& calledAet) ORTHANC_OVERRIDE |
144 { | 144 { |
145 if (successSopClassUids.size() != successSopInstanceUids.size() || | 145 if (successSopClassUids.size() != successSopInstanceUids.size() || |
146 failedSopClassUids.size() != failedSopInstanceUids.size() || | 146 failedSopClassUids.size() != failedSopInstanceUids.size() || |
147 failedSopClassUids.size() != failureReasons.size()) | 147 failedSopClassUids.size() != failureReasons.size()) |
148 { | 148 { |
172 | 172 |
173 class ModalitiesFromConfiguration : public DicomServer::IRemoteModalities | 173 class ModalitiesFromConfiguration : public DicomServer::IRemoteModalities |
174 { | 174 { |
175 public: | 175 public: |
176 virtual bool IsSameAETitle(const std::string& aet1, | 176 virtual bool IsSameAETitle(const std::string& aet1, |
177 const std::string& aet2) | 177 const std::string& aet2) ORTHANC_OVERRIDE |
178 { | 178 { |
179 OrthancConfiguration::ReaderLock lock; | 179 OrthancConfiguration::ReaderLock lock; |
180 return lock.GetConfiguration().IsSameAETitle(aet1, aet2); | 180 return lock.GetConfiguration().IsSameAETitle(aet1, aet2); |
181 } | 181 } |
182 | 182 |
183 virtual bool LookupAETitle(RemoteModalityParameters& modality, | 183 virtual bool LookupAETitle(RemoteModalityParameters& modality, |
184 const std::string& aet) | 184 const std::string& aet) ORTHANC_OVERRIDE |
185 { | 185 { |
186 OrthancConfiguration::ReaderLock lock; | 186 OrthancConfiguration::ReaderLock lock; |
187 return lock.GetConfiguration().LookupDicomModalityUsingAETitle(modality, aet); | 187 return lock.GetConfiguration().LookupDicomModalityUsingAETitle(modality, aet); |
188 } | 188 } |
189 }; | 189 }; |
198 { | 198 { |
199 private: | 199 private: |
200 ServerContext& context_; | 200 ServerContext& context_; |
201 | 201 |
202 public: | 202 public: |
203 MyDicomServerFactory(ServerContext& context) : context_(context) | 203 explicit MyDicomServerFactory(ServerContext& context) : context_(context) |
204 { | 204 { |
205 } | 205 } |
206 | 206 |
207 virtual IStoreRequestHandler* ConstructStoreRequestHandler() | 207 virtual IStoreRequestHandler* ConstructStoreRequestHandler() ORTHANC_OVERRIDE |
208 { | 208 { |
209 return new OrthancStoreRequestHandler(context_); | 209 return new OrthancStoreRequestHandler(context_); |
210 } | 210 } |
211 | 211 |
212 virtual IFindRequestHandler* ConstructFindRequestHandler() | 212 virtual IFindRequestHandler* ConstructFindRequestHandler() ORTHANC_OVERRIDE |
213 { | 213 { |
214 std::unique_ptr<OrthancFindRequestHandler> result(new OrthancFindRequestHandler(context_)); | 214 std::unique_ptr<OrthancFindRequestHandler> result(new OrthancFindRequestHandler(context_)); |
215 | 215 |
216 { | 216 { |
217 OrthancConfiguration::ReaderLock lock; | 217 OrthancConfiguration::ReaderLock lock; |
240 } | 240 } |
241 | 241 |
242 return result.release(); | 242 return result.release(); |
243 } | 243 } |
244 | 244 |
245 virtual IMoveRequestHandler* ConstructMoveRequestHandler() | 245 virtual IMoveRequestHandler* ConstructMoveRequestHandler() ORTHANC_OVERRIDE |
246 { | 246 { |
247 return new OrthancMoveRequestHandler(context_); | 247 return new OrthancMoveRequestHandler(context_); |
248 } | 248 } |
249 | 249 |
250 virtual IGetRequestHandler* ConstructGetRequestHandler() | 250 virtual IGetRequestHandler* ConstructGetRequestHandler() ORTHANC_OVERRIDE |
251 { | 251 { |
252 return new OrthancGetRequestHandler(context_); | 252 return new OrthancGetRequestHandler(context_); |
253 } | 253 } |
254 | 254 |
255 virtual IStorageCommitmentRequestHandler* ConstructStorageCommitmentRequestHandler() | 255 virtual IStorageCommitmentRequestHandler* ConstructStorageCommitmentRequestHandler() ORTHANC_OVERRIDE |
256 { | 256 { |
257 return new OrthancStorageCommitmentRequestHandler(context_); | 257 return new OrthancStorageCommitmentRequestHandler(context_); |
258 } | 258 } |
259 | 259 |
260 | 260 |
270 ServerContext& context_; | 270 ServerContext& context_; |
271 bool alwaysAllowEcho_; | 271 bool alwaysAllowEcho_; |
272 bool alwaysAllowStore_; | 272 bool alwaysAllowStore_; |
273 | 273 |
274 public: | 274 public: |
275 OrthancApplicationEntityFilter(ServerContext& context) : | 275 explicit OrthancApplicationEntityFilter(ServerContext& context) : |
276 context_(context) | 276 context_(context) |
277 { | 277 { |
278 OrthancConfiguration::ReaderLock lock; | 278 OrthancConfiguration::ReaderLock lock; |
279 alwaysAllowEcho_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowEcho", true); | 279 alwaysAllowEcho_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowEcho", true); |
280 alwaysAllowStore_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowStore", true); | 280 alwaysAllowStore_ = lock.GetConfiguration().GetBooleanParameter("DicomAlwaysAllowStore", true); |
281 } | 281 } |
282 | 282 |
283 virtual bool IsAllowedConnection(const std::string& remoteIp, | 283 virtual bool IsAllowedConnection(const std::string& remoteIp, |
284 const std::string& remoteAet, | 284 const std::string& remoteAet, |
285 const std::string& calledAet) | 285 const std::string& calledAet) ORTHANC_OVERRIDE |
286 { | 286 { |
287 LOG(INFO) << "Incoming connection from AET " << remoteAet | 287 LOG(INFO) << "Incoming connection from AET " << remoteAet |
288 << " on IP " << remoteIp << ", calling AET " << calledAet; | 288 << " on IP " << remoteIp << ", calling AET " << calledAet; |
289 | 289 |
290 if (alwaysAllowEcho_ || | 290 if (alwaysAllowEcho_ || |
300 } | 300 } |
301 | 301 |
302 virtual bool IsAllowedRequest(const std::string& remoteIp, | 302 virtual bool IsAllowedRequest(const std::string& remoteIp, |
303 const std::string& remoteAet, | 303 const std::string& remoteAet, |
304 const std::string& calledAet, | 304 const std::string& calledAet, |
305 DicomRequestType type) | 305 DicomRequestType type) ORTHANC_OVERRIDE |
306 { | 306 { |
307 LOG(INFO) << "Incoming " << EnumerationToString(type) << " request from AET " | 307 LOG(INFO) << "Incoming " << EnumerationToString(type) << " request from AET " |
308 << remoteAet << " on IP " << remoteIp << ", calling AET " << calledAet; | 308 << remoteAet << " on IP " << remoteIp << ", calling AET " << calledAet; |
309 | 309 |
310 if (type == DicomRequestType_Echo && | 310 if (type == DicomRequestType_Echo && |
354 } | 354 } |
355 | 355 |
356 virtual bool IsAllowedTransferSyntax(const std::string& remoteIp, | 356 virtual bool IsAllowedTransferSyntax(const std::string& remoteIp, |
357 const std::string& remoteAet, | 357 const std::string& remoteAet, |
358 const std::string& calledAet, | 358 const std::string& calledAet, |
359 TransferSyntax syntax) | 359 TransferSyntax syntax) ORTHANC_OVERRIDE |
360 { | 360 { |
361 std::string configuration; | 361 std::string configuration; |
362 | 362 |
363 switch (syntax) | 363 switch (syntax) |
364 { | 364 { |
420 } | 420 } |
421 | 421 |
422 | 422 |
423 virtual bool IsUnknownSopClassAccepted(const std::string& remoteIp, | 423 virtual bool IsUnknownSopClassAccepted(const std::string& remoteIp, |
424 const std::string& remoteAet, | 424 const std::string& remoteAet, |
425 const std::string& calledAet) | 425 const std::string& calledAet) ORTHANC_OVERRIDE |
426 { | 426 { |
427 static const char* configuration = "UnknownSopClassAccepted"; | 427 static const char* configuration = "UnknownSopClassAccepted"; |
428 | 428 |
429 { | 429 { |
430 std::string lua = "Is" + std::string(configuration); | 430 std::string lua = "Is" + std::string(configuration); |
466 virtual bool IsAllowed(HttpMethod method, | 466 virtual bool IsAllowed(HttpMethod method, |
467 const char* uri, | 467 const char* uri, |
468 const char* ip, | 468 const char* ip, |
469 const char* username, | 469 const char* username, |
470 const IHttpHandler::Arguments& httpHeaders, | 470 const IHttpHandler::Arguments& httpHeaders, |
471 const IHttpHandler::GetArguments& getArguments) | 471 const IHttpHandler::GetArguments& getArguments) ORTHANC_OVERRIDE |
472 { | 472 { |
473 #if ORTHANC_ENABLE_PLUGINS == 1 | 473 #if ORTHANC_ENABLE_PLUGINS == 1 |
474 if (plugins_ != NULL && | 474 if (plugins_ != NULL && |
475 !plugins_->IsAllowed(method, uri, ip, username, httpHeaders, getArguments)) | 475 !plugins_->IsAllowed(method, uri, ip, username, httpHeaders, getArguments)) |
476 { | 476 { |
542 } | 542 } |
543 | 543 |
544 virtual void Format(HttpOutput& output, | 544 virtual void Format(HttpOutput& output, |
545 const OrthancException& exception, | 545 const OrthancException& exception, |
546 HttpMethod method, | 546 HttpMethod method, |
547 const char* uri) | 547 const char* uri) ORTHANC_OVERRIDE |
548 { | 548 { |
549 { | 549 { |
550 bool isPlugin = false; | 550 bool isPlugin = false; |
551 | 551 |
552 #if ORTHANC_ENABLE_PLUGINS == 1 | 552 #if ORTHANC_ENABLE_PLUGINS == 1 |
798 | 798 |
799 | 799 |
800 #if ORTHANC_ENABLE_PLUGINS == 1 | 800 #if ORTHANC_ENABLE_PLUGINS == 1 |
801 static void LoadPlugins(OrthancPlugins& plugins) | 801 static void LoadPlugins(OrthancPlugins& plugins) |
802 { | 802 { |
803 std::list<std::string> path; | 803 std::list<std::string> pathList; |
804 | 804 |
805 { | 805 { |
806 OrthancConfiguration::ReaderLock lock; | 806 OrthancConfiguration::ReaderLock lock; |
807 lock.GetConfiguration().GetListOfStringsParameter(path, "Plugins"); | 807 lock.GetConfiguration().GetListOfStringsParameter(pathList, "Plugins"); |
808 } | 808 } |
809 | 809 |
810 for (std::list<std::string>::const_iterator | 810 for (std::list<std::string>::const_iterator |
811 it = path.begin(); it != path.end(); ++it) | 811 it = pathList.begin(); it != pathList.end(); ++it) |
812 { | 812 { |
813 std::string path; | 813 std::string path; |
814 | 814 |
815 { | 815 { |
816 OrthancConfiguration::ReaderLock lock; | 816 OrthancConfiguration::ReaderLock lock; |
825 | 825 |
826 | 826 |
827 | 827 |
828 // Returns "true" if restart is required | 828 // Returns "true" if restart is required |
829 static bool WaitForExit(ServerContext& context, | 829 static bool WaitForExit(ServerContext& context, |
830 OrthancRestApi& restApi) | 830 const OrthancRestApi& restApi) |
831 { | 831 { |
832 LOG(WARNING) << "Orthanc has started"; | 832 LOG(WARNING) << "Orthanc has started"; |
833 | 833 |
834 #if ORTHANC_ENABLE_PLUGINS == 1 | 834 #if ORTHANC_ENABLE_PLUGINS == 1 |
835 if (context.HasPlugins()) | 835 if (context.HasPlugins()) |
897 } | 897 } |
898 | 898 |
899 | 899 |
900 | 900 |
901 static bool StartHttpServer(ServerContext& context, | 901 static bool StartHttpServer(ServerContext& context, |
902 OrthancRestApi& restApi, | 902 const OrthancRestApi& restApi, |
903 OrthancPlugins* plugins) | 903 OrthancPlugins* plugins) |
904 { | 904 { |
905 bool httpServerEnabled; | 905 bool httpServerEnabled; |
906 | 906 |
907 { | 907 { |
1066 } | 1066 } |
1067 } | 1067 } |
1068 | 1068 |
1069 | 1069 |
1070 static bool StartDicomServer(ServerContext& context, | 1070 static bool StartDicomServer(ServerContext& context, |
1071 OrthancRestApi& restApi, | 1071 const OrthancRestApi& restApi, |
1072 OrthancPlugins* plugins) | 1072 OrthancPlugins* plugins) |
1073 { | 1073 { |
1074 bool dicomServerEnabled; | 1074 bool dicomServerEnabled; |
1075 | 1075 |
1076 { | 1076 { |