comparison OrthancServer/OrthancRestApi/OrthancRestResources.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 02f5a3f5c0a0
children f967bdf8534e
comparison
equal deleted inserted replaced
1445:d26c8a93d05a 1446:8dc80ba768aa
119 static void SetPatientProtection(RestApiPutCall& call) 119 static void SetPatientProtection(RestApiPutCall& call)
120 { 120 {
121 ServerContext& context = OrthancRestApi::GetContext(call); 121 ServerContext& context = OrthancRestApi::GetContext(call);
122 122
123 std::string publicId = call.GetUriComponent("id", ""); 123 std::string publicId = call.GetUriComponent("id", "");
124 std::string s = Toolbox::StripSpaces(call.GetPutBody()); 124
125 125 std::string body;
126 if (s == "0") 126 call.BodyToString(body);
127 body = Toolbox::StripSpaces(body);
128
129 if (body == "0")
127 { 130 {
128 context.GetIndex().SetProtectedPatient(publicId, false); 131 context.GetIndex().SetProtectedPatient(publicId, false);
129 call.GetOutput().AnswerBuffer("", "text/plain"); 132 call.GetOutput().AnswerBuffer("", "text/plain");
130 } 133 }
131 else if (s == "1") 134 else if (body == "1")
132 { 135 {
133 context.GetIndex().SetProtectedPatient(publicId, true); 136 context.GetIndex().SetProtectedPatient(publicId, true);
134 call.GetOutput().AnswerBuffer("", "text/plain"); 137 call.GetOutput().AnswerBuffer("", "text/plain");
135 } 138 }
136 else 139 else
158 std::string publicId = call.GetUriComponent("id", ""); 161 std::string publicId = call.GetUriComponent("id", "");
159 162
160 std::string dicom; 163 std::string dicom;
161 context.ReadFile(dicom, publicId, FileContentType_Dicom); 164 context.ReadFile(dicom, publicId, FileContentType_Dicom);
162 165
163 Toolbox::WriteFile(dicom, call.GetPostBody()); 166 std::string target;
167 call.BodyToString(target);
168 Toolbox::WriteFile(dicom, target);
164 169
165 call.GetOutput().AnswerBuffer("{}", "application/json"); 170 call.GetOutput().AnswerBuffer("{}", "application/json");
166 } 171 }
167 172
168 173
392 CheckValidResourceType(call); 397 CheckValidResourceType(call);
393 398
394 std::string publicId = call.GetUriComponent("id", ""); 399 std::string publicId = call.GetUriComponent("id", "");
395 std::string name = call.GetUriComponent("name", ""); 400 std::string name = call.GetUriComponent("name", "");
396 MetadataType metadata = StringToMetadata(name); 401 MetadataType metadata = StringToMetadata(name);
397 std::string value = call.GetPutBody(); 402
403 std::string value;
404 call.BodyToString(value);
398 405
399 if (metadata >= MetadataType_StartUser && 406 if (metadata >= MetadataType_StartUser &&
400 metadata <= MetadataType_EndUser) 407 metadata <= MetadataType_EndUser)
401 { 408 {
402 // It is forbidden to modify internal metadata 409 // It is forbidden to modify internal metadata
602 CheckValidResourceType(call); 609 CheckValidResourceType(call);
603 610
604 std::string publicId = call.GetUriComponent("id", ""); 611 std::string publicId = call.GetUriComponent("id", "");
605 std::string name = call.GetUriComponent("name", ""); 612 std::string name = call.GetUriComponent("name", "");
606 613
607 const void* data = call.GetPutBody().size() ? &call.GetPutBody()[0] : NULL;
608
609 FileContentType contentType = StringToContentType(name); 614 FileContentType contentType = StringToContentType(name);
610 if (contentType >= FileContentType_StartUser && // It is forbidden to modify internal attachments 615 if (contentType >= FileContentType_StartUser && // It is forbidden to modify internal attachments
611 contentType <= FileContentType_EndUser && 616 contentType <= FileContentType_EndUser &&
612 context.AddAttachment(publicId, StringToContentType(name), data, call.GetPutBody().size())) 617 context.AddAttachment(publicId, StringToContentType(name), call.GetBodyData(), call.GetBodySize()))
613 { 618 {
614 call.GetOutput().AnswerBuffer("{}", "application/json"); 619 call.GetOutput().AnswerBuffer("{}", "application/json");
615 } 620 }
616 } 621 }
617 622
823 828
824 static void Lookup(RestApiPostCall& call) 829 static void Lookup(RestApiPostCall& call)
825 { 830 {
826 typedef std::list< std::pair<ResourceType, std::string> > Resources; 831 typedef std::list< std::pair<ResourceType, std::string> > Resources;
827 832
828 std::string tag = call.GetPostBody(); 833 std::string tag;
834 call.BodyToString(tag);
829 Resources resources; 835 Resources resources;
830 836
831 OrthancRestApi::GetIndex(call).LookupIdentifier(resources, tag); 837 OrthancRestApi::GetIndex(call).LookupIdentifier(resources, tag);
832 838
833 Json::Value result = Json::arrayValue; 839 Json::Value result = Json::arrayValue;