Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 2063:ed383e7a6753
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 04 Jul 2016 15:50:11 +0200 |
parents | 54417b0831c4 |
children | 272094362301 |
comparison
equal
deleted
inserted
replaced
2062:40ffd0e8676a | 2063:ed383e7a6753 |
---|---|
228 | 228 |
229 return size; | 229 return size; |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
233 void Toolbox::ReadFile(std::string& content, | 234 void Toolbox::ReadFile(std::string& content, |
234 const std::string& path) | 235 const std::string& path) |
235 { | 236 { |
236 if (!IsRegularFile(path)) | 237 if (!IsRegularFile(path)) |
237 { | 238 { |
253 f.read(reinterpret_cast<char*>(&content[0]), size); | 254 f.read(reinterpret_cast<char*>(&content[0]), size); |
254 } | 255 } |
255 | 256 |
256 f.close(); | 257 f.close(); |
257 } | 258 } |
258 | 259 #endif |
259 | 260 |
261 | |
262 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
260 bool Toolbox::ReadHeader(std::string& header, | 263 bool Toolbox::ReadHeader(std::string& header, |
261 const std::string& path, | 264 const std::string& path, |
262 size_t headerSize) | 265 size_t headerSize) |
263 { | 266 { |
264 if (!IsRegularFile(path)) | 267 if (!IsRegularFile(path)) |
298 | 301 |
299 f.close(); | 302 f.close(); |
300 | 303 |
301 return full; | 304 return full; |
302 } | 305 } |
303 | 306 #endif |
304 | 307 |
308 | |
309 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
305 void Toolbox::WriteFile(const void* content, | 310 void Toolbox::WriteFile(const void* content, |
306 size_t size, | 311 size_t size, |
307 const std::string& path) | 312 const std::string& path) |
308 { | 313 { |
309 boost::filesystem::ofstream f; | 314 boost::filesystem::ofstream f; |
318 f.write(reinterpret_cast<const char*>(content), size); | 323 f.write(reinterpret_cast<const char*>(content), size); |
319 } | 324 } |
320 | 325 |
321 f.close(); | 326 f.close(); |
322 } | 327 } |
323 | 328 #endif |
324 | 329 |
330 | |
331 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
325 void Toolbox::WriteFile(const std::string& content, | 332 void Toolbox::WriteFile(const std::string& content, |
326 const std::string& path) | 333 const std::string& path) |
327 { | 334 { |
328 WriteFile(content.size() > 0 ? content.c_str() : NULL, | 335 WriteFile(content.size() > 0 ? content.c_str() : NULL, |
329 content.size(), path); | 336 content.size(), path); |
330 } | 337 } |
331 | 338 #endif |
332 | 339 |
340 | |
341 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
333 void Toolbox::RemoveFile(const std::string& path) | 342 void Toolbox::RemoveFile(const std::string& path) |
334 { | 343 { |
335 if (boost::filesystem::exists(path)) | 344 if (boost::filesystem::exists(path)) |
336 { | 345 { |
337 if (IsRegularFile(path)) | 346 if (IsRegularFile(path)) |
342 { | 351 { |
343 throw OrthancException(ErrorCode_RegularFileExpected); | 352 throw OrthancException(ErrorCode_RegularFileExpected); |
344 } | 353 } |
345 } | 354 } |
346 } | 355 } |
347 | 356 #endif |
348 | 357 |
349 | 358 |
350 void Toolbox::SplitUriComponents(UriComponents& components, | 359 void Toolbox::SplitUriComponents(UriComponents& components, |
351 const std::string& uri) | 360 const std::string& uri) |
352 { | 361 { |
513 } | 522 } |
514 } | 523 } |
515 | 524 |
516 | 525 |
517 | 526 |
527 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
518 uint64_t Toolbox::GetFileSize(const std::string& path) | 528 uint64_t Toolbox::GetFileSize(const std::string& path) |
519 { | 529 { |
520 try | 530 try |
521 { | 531 { |
522 return static_cast<uint64_t>(boost::filesystem::file_size(path)); | 532 return static_cast<uint64_t>(boost::filesystem::file_size(path)); |
524 catch (boost::filesystem::filesystem_error&) | 534 catch (boost::filesystem::filesystem_error&) |
525 { | 535 { |
526 throw OrthancException(ErrorCode_InexistentFile); | 536 throw OrthancException(ErrorCode_InexistentFile); |
527 } | 537 } |
528 } | 538 } |
539 #endif | |
529 | 540 |
530 | 541 |
531 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1 | 542 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1 |
532 static char GetHexadecimalCharacter(uint8_t value) | 543 static char GetHexadecimalCharacter(uint8_t value) |
533 { | 544 { |
1142 | 1153 |
1143 result.push_back(currentItem); | 1154 result.push_back(currentItem); |
1144 } | 1155 } |
1145 | 1156 |
1146 | 1157 |
1158 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
1147 void Toolbox::MakeDirectory(const std::string& path) | 1159 void Toolbox::MakeDirectory(const std::string& path) |
1148 { | 1160 { |
1149 if (boost::filesystem::exists(path)) | 1161 if (boost::filesystem::exists(path)) |
1150 { | 1162 { |
1151 if (!boost::filesystem::is_directory(path)) | 1163 if (!boost::filesystem::is_directory(path)) |
1159 { | 1171 { |
1160 throw OrthancException(ErrorCode_MakeDirectory); | 1172 throw OrthancException(ErrorCode_MakeDirectory); |
1161 } | 1173 } |
1162 } | 1174 } |
1163 } | 1175 } |
1164 | 1176 #endif |
1165 | 1177 |
1178 | |
1179 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
1166 bool Toolbox::IsExistingFile(const std::string& path) | 1180 bool Toolbox::IsExistingFile(const std::string& path) |
1167 { | 1181 { |
1168 return boost::filesystem::exists(path); | 1182 return boost::filesystem::exists(path); |
1169 } | 1183 } |
1184 #endif | |
1170 | 1185 |
1171 | 1186 |
1172 #if ORTHANC_PUGIXML_ENABLED == 1 | 1187 #if ORTHANC_PUGIXML_ENABLED == 1 |
1173 class ChunkedBufferWriter : public pugi::xml_writer | 1188 class ChunkedBufferWriter : public pugi::xml_writer |
1174 { | 1189 { |
1466 return static_cast<int>(getpid()); | 1481 return static_cast<int>(getpid()); |
1467 #endif | 1482 #endif |
1468 } | 1483 } |
1469 | 1484 |
1470 | 1485 |
1486 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
1471 bool Toolbox::IsRegularFile(const std::string& path) | 1487 bool Toolbox::IsRegularFile(const std::string& path) |
1472 { | 1488 { |
1473 namespace fs = boost::filesystem; | 1489 namespace fs = boost::filesystem; |
1474 | 1490 |
1475 try | 1491 try |
1485 { | 1501 { |
1486 } | 1502 } |
1487 | 1503 |
1488 return false; | 1504 return false; |
1489 } | 1505 } |
1506 #endif | |
1490 | 1507 |
1491 | 1508 |
1492 FILE* Toolbox::OpenFile(const std::string& path, | 1509 FILE* Toolbox::OpenFile(const std::string& path, |
1493 FileMode mode) | 1510 FileMode mode) |
1494 { | 1511 { |