comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 1446:8dc80ba768aa

refactoring: IHttpHandler does not use std::string to hold the request body
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 13:16:12 +0200
parents 0a355eeeb351
children f967bdf8534e
comparison
equal deleted inserted replaced
1445:d26c8a93d05a 1446:8dc80ba768aa
80 /*************************************************************************** 80 /***************************************************************************
81 * DICOM C-Find SCU => DEPRECATED! 81 * DICOM C-Find SCU => DEPRECATED!
82 ***************************************************************************/ 82 ***************************************************************************/
83 83
84 static bool MergeQueryAndTemplate(DicomMap& result, 84 static bool MergeQueryAndTemplate(DicomMap& result,
85 const std::string& postData) 85 const char* postData,
86 size_t postSize)
86 { 87 {
87 Json::Value query; 88 Json::Value query;
88 Json::Reader reader; 89 Json::Reader reader;
89 90
90 if (!reader.parse(postData, query) || 91 if (!reader.parse(postData, postData + postSize, query) ||
91 query.type() != Json::objectValue) 92 query.type() != Json::objectValue)
92 { 93 {
93 return false; 94 return false;
94 } 95 }
95 96
167 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri(); 168 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri();
168 ServerContext& context = OrthancRestApi::GetContext(call); 169 ServerContext& context = OrthancRestApi::GetContext(call);
169 170
170 DicomMap fields; 171 DicomMap fields;
171 DicomMap::SetupFindPatientTemplate(fields); 172 DicomMap::SetupFindPatientTemplate(fields);
172 if (!MergeQueryAndTemplate(fields, call.GetPostBody())) 173 if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
173 { 174 {
174 return; 175 return;
175 } 176 }
176 177
177 const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle(); 178 const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
191 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri(); 192 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri();
192 ServerContext& context = OrthancRestApi::GetContext(call); 193 ServerContext& context = OrthancRestApi::GetContext(call);
193 194
194 DicomMap fields; 195 DicomMap fields;
195 DicomMap::SetupFindStudyTemplate(fields); 196 DicomMap::SetupFindStudyTemplate(fields);
196 if (!MergeQueryAndTemplate(fields, call.GetPostBody())) 197 if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
197 { 198 {
198 return; 199 return;
199 } 200 }
200 201
201 if (fields.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && 202 if (fields.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
221 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri(); 222 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri();
222 ServerContext& context = OrthancRestApi::GetContext(call); 223 ServerContext& context = OrthancRestApi::GetContext(call);
223 224
224 DicomMap fields; 225 DicomMap fields;
225 DicomMap::SetupFindSeriesTemplate(fields); 226 DicomMap::SetupFindSeriesTemplate(fields);
226 if (!MergeQueryAndTemplate(fields, call.GetPostBody())) 227 if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
227 { 228 {
228 return; 229 return;
229 } 230 }
230 231
231 if ((fields.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && 232 if ((fields.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
252 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri(); 253 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri();
253 ServerContext& context = OrthancRestApi::GetContext(call); 254 ServerContext& context = OrthancRestApi::GetContext(call);
254 255
255 DicomMap fields; 256 DicomMap fields;
256 DicomMap::SetupFindInstanceTemplate(fields); 257 DicomMap::SetupFindInstanceTemplate(fields);
257 if (!MergeQueryAndTemplate(fields, call.GetPostBody())) 258 if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
258 { 259 {
259 return; 260 return;
260 } 261 }
261 262
262 if ((fields.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && 263 if ((fields.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 &&
285 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri(); 286 LOG(WARNING) << "This URI is deprecated: " << call.FlattenUri();
286 ServerContext& context = OrthancRestApi::GetContext(call); 287 ServerContext& context = OrthancRestApi::GetContext(call);
287 288
288 DicomMap m; 289 DicomMap m;
289 DicomMap::SetupFindPatientTemplate(m); 290 DicomMap::SetupFindPatientTemplate(m);
290 if (!MergeQueryAndTemplate(m, call.GetPostBody())) 291 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
291 { 292 {
292 return; 293 return;
293 } 294 }
294 295
295 const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle(); 296 const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
305 { 306 {
306 Json::Value patient(Json::objectValue); 307 Json::Value patient(Json::objectValue);
307 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i), true); 308 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i), true);
308 309
309 DicomMap::SetupFindStudyTemplate(m); 310 DicomMap::SetupFindStudyTemplate(m);
310 if (!MergeQueryAndTemplate(m, call.GetPostBody())) 311 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
311 { 312 {
312 return; 313 return;
313 } 314 }
314 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID); 315 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
315 316
323 { 324 {
324 Json::Value study(Json::objectValue); 325 Json::Value study(Json::objectValue);
325 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j), true); 326 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j), true);
326 327
327 DicomMap::SetupFindSeriesTemplate(m); 328 DicomMap::SetupFindSeriesTemplate(m);
328 if (!MergeQueryAndTemplate(m, call.GetPostBody())) 329 if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
329 { 330 {
330 return; 331 return;
331 } 332 }
332 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID); 333 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
333 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID); 334 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
472 473
473 static void RetrieveOneAnswer(RestApiPostCall& call) 474 static void RetrieveOneAnswer(RestApiPostCall& call)
474 { 475 {
475 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", "")); 476 size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", ""));
476 477
477 LOG(WARNING) << "Driving C-Move SCU on modality: " << call.GetPostBody(); 478 std::string modality;
479 call.BodyToString(modality);
480
481 LOG(WARNING) << "Driving C-Move SCU on modality: " << modality;
478 482
479 QueryAccessor query(call); 483 QueryAccessor query(call);
480 query->Retrieve(call.GetPostBody(), index); 484 query->Retrieve(modality, index);
481 485
482 // Retrieve has succeeded 486 // Retrieve has succeeded
483 call.GetOutput().AnswerBuffer("{}", "application/json"); 487 call.GetOutput().AnswerBuffer("{}", "application/json");
484 } 488 }
485 489
486 490
487 static void RetrieveAllAnswers(RestApiPostCall& call) 491 static void RetrieveAllAnswers(RestApiPostCall& call)
488 { 492 {
489 LOG(WARNING) << "Driving C-Move SCU on modality: " << call.GetPostBody(); 493 std::string modality;
494 call.BodyToString(modality);
495
496 LOG(WARNING) << "Driving C-Move SCU on modality: " << modality;
490 497
491 QueryAccessor query(call); 498 QueryAccessor query(call);
492 query->Retrieve(call.GetPostBody()); 499 query->Retrieve(modality);
493 500
494 // Retrieve has succeeded 501 // Retrieve has succeeded
495 call.GetOutput().AnswerBuffer("{}", "application/json"); 502 call.GetOutput().AnswerBuffer("{}", "application/json");
496 } 503 }
497 504
560 { 567 {
561 otherArguments = Json::objectValue; 568 otherArguments = Json::objectValue;
562 ServerContext& context = OrthancRestApi::GetContext(call); 569 ServerContext& context = OrthancRestApi::GetContext(call);
563 570
564 Json::Value request; 571 Json::Value request;
565 if (Toolbox::IsSHA1(call.GetPostBody())) 572 if (Toolbox::IsSHA1(call.GetBodyData(), call.GetBodySize()))
566 { 573 {
574 std::string s;
575 call.BodyToString(s);
576
567 // This is for compatibility with Orthanc <= 0.5.1. 577 // This is for compatibility with Orthanc <= 0.5.1.
568 request = Json::arrayValue; 578 request = Json::arrayValue;
569 request.append(Toolbox::StripSpaces(call.GetPostBody())); 579 request.append(Toolbox::StripSpaces(s));
570 } 580 }
571 else if (!call.ParseJsonRequest(request)) 581 else if (!call.ParseJsonRequest(request))
572 { 582 {
573 // Bad JSON request 583 // Bad JSON request
574 return false; 584 return false;
795 805
796 static void UpdateModality(RestApiPutCall& call) 806 static void UpdateModality(RestApiPutCall& call)
797 { 807 {
798 Json::Value json; 808 Json::Value json;
799 Json::Reader reader; 809 Json::Reader reader;
800 if (reader.parse(call.GetPutBody(), json)) 810 if (reader.parse(call.GetBodyData(), call.GetBodyData() + call.GetBodySize(), json))
801 { 811 {
802 RemoteModalityParameters modality; 812 RemoteModalityParameters modality;
803 modality.FromJson(json); 813 modality.FromJson(json);
804 Configuration::UpdateModality(call.GetUriComponent("id", ""), modality); 814 Configuration::UpdateModality(call.GetUriComponent("id", ""), modality);
805 call.GetOutput().AnswerBuffer("", "text/plain"); 815 call.GetOutput().AnswerBuffer("", "text/plain");
816 826
817 static void UpdatePeer(RestApiPutCall& call) 827 static void UpdatePeer(RestApiPutCall& call)
818 { 828 {
819 Json::Value json; 829 Json::Value json;
820 Json::Reader reader; 830 Json::Reader reader;
821 if (reader.parse(call.GetPutBody(), json)) 831 if (reader.parse(call.GetBodyData(), call.GetBodyData() + call.GetBodySize(), json))
822 { 832 {
823 OrthancPeerParameters peer; 833 OrthancPeerParameters peer;
824 peer.FromJson(json); 834 peer.FromJson(json);
825 Configuration::UpdatePeer(call.GetUriComponent("id", ""), peer); 835 Configuration::UpdatePeer(call.GetUriComponent("id", ""), peer);
826 call.GetOutput().AnswerBuffer("", "text/plain"); 836 call.GetOutput().AnswerBuffer("", "text/plain");