comparison Framework/Orthanc/Core/Toolbox.cpp @ 14:0b9034112fde

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Nov 2016 15:29:53 +0100
parents 9220cf4a63d5
children da2cf3ace87a
comparison
equal deleted inserted replaced
13:b1eb80ca0d2b 14:0b9034112fde
78 #endif 78 #endif
79 79
80 #include <boost/locale.hpp> 80 #include <boost/locale.hpp>
81 81
82 82
83 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1 83 #if ORTHANC_ENABLE_MD5 == 1
84 #include "../Resources/ThirdParty/md5/md5.h" 84 # include "../Resources/ThirdParty/md5/md5.h"
85 #endif 85 #endif
86 86
87 87
88 #if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1 88 #if ORTHANC_ENABLE_BASE64 == 1
89 #include "../Resources/ThirdParty/base64/base64.h" 89 # include "../Resources/ThirdParty/base64/base64.h"
90 #endif 90 #endif
91 91
92 92
93 #if defined(_MSC_VER) && (_MSC_VER < 1800) 93 #if defined(_MSC_VER) && (_MSC_VER < 1800)
94 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013 94 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013
121 #error Support your platform here 121 #error Support your platform here
122 #endif 122 #endif
123 } 123 }
124 124
125 125
126 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 126 #if ORTHANC_SANDBOXED == 0
127 static bool finish_; 127 static bool finish_;
128 static ServerBarrierEvent barrierEvent_; 128 static ServerBarrierEvent barrierEvent_;
129 129
130 #if defined(_WIN32) 130 #if defined(_WIN32)
131 static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) 131 static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType)
228 228
229 return size; 229 return size;
230 } 230 }
231 231
232 232
233 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 233 #if ORTHANC_SANDBOXED == 0
234 void Toolbox::ReadFile(std::string& content, 234 void Toolbox::ReadFile(std::string& content,
235 const std::string& path) 235 const std::string& path)
236 { 236 {
237 if (!IsRegularFile(path)) 237 if (!IsRegularFile(path))
238 { 238 {
257 f.close(); 257 f.close();
258 } 258 }
259 #endif 259 #endif
260 260
261 261
262 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 262 #if ORTHANC_SANDBOXED == 0
263 bool Toolbox::ReadHeader(std::string& header, 263 bool Toolbox::ReadHeader(std::string& header,
264 const std::string& path, 264 const std::string& path,
265 size_t headerSize) 265 size_t headerSize)
266 { 266 {
267 if (!IsRegularFile(path)) 267 if (!IsRegularFile(path))
304 return full; 304 return full;
305 } 305 }
306 #endif 306 #endif
307 307
308 308
309 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 309 #if ORTHANC_SANDBOXED == 0
310 void Toolbox::WriteFile(const void* content, 310 void Toolbox::WriteFile(const void* content,
311 size_t size, 311 size_t size,
312 const std::string& path) 312 const std::string& path)
313 { 313 {
314 boost::filesystem::ofstream f; 314 boost::filesystem::ofstream f;
332 f.close(); 332 f.close();
333 } 333 }
334 #endif 334 #endif
335 335
336 336
337 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 337 #if ORTHANC_SANDBOXED == 0
338 void Toolbox::WriteFile(const std::string& content, 338 void Toolbox::WriteFile(const std::string& content,
339 const std::string& path) 339 const std::string& path)
340 { 340 {
341 WriteFile(content.size() > 0 ? content.c_str() : NULL, 341 WriteFile(content.size() > 0 ? content.c_str() : NULL,
342 content.size(), path); 342 content.size(), path);
343 } 343 }
344 #endif 344 #endif
345 345
346 346
347 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 347 #if ORTHANC_SANDBOXED == 0
348 void Toolbox::RemoveFile(const std::string& path) 348 void Toolbox::RemoveFile(const std::string& path)
349 { 349 {
350 if (boost::filesystem::exists(path)) 350 if (boost::filesystem::exists(path))
351 { 351 {
352 if (IsRegularFile(path)) 352 if (IsRegularFile(path))
528 } 528 }
529 } 529 }
530 530
531 531
532 532
533 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 533 #if ORTHANC_SANDBOXED == 0
534 uint64_t Toolbox::GetFileSize(const std::string& path) 534 uint64_t Toolbox::GetFileSize(const std::string& path)
535 { 535 {
536 try 536 try
537 { 537 {
538 return static_cast<uint64_t>(boost::filesystem::file_size(path)); 538 return static_cast<uint64_t>(boost::filesystem::file_size(path));
543 } 543 }
544 } 544 }
545 #endif 545 #endif
546 546
547 547
548 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1 548 #if ORTHANC_ENABLE_MD5 == 1
549 static char GetHexadecimalCharacter(uint8_t value) 549 static char GetHexadecimalCharacter(uint8_t value)
550 { 550 {
551 assert(value < 16); 551 assert(value < 16);
552 552
553 if (value < 10) 553 if (value < 10)
600 } 600 }
601 } 601 }
602 #endif 602 #endif
603 603
604 604
605 #if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1 605 #if ORTHANC_ENABLE_BASE64 == 1
606 void Toolbox::EncodeBase64(std::string& result, 606 void Toolbox::EncodeBase64(std::string& result,
607 const std::string& data) 607 const std::string& data)
608 { 608 {
609 result = base64_encode(data); 609 result = base64_encode(data);
610 } 610 }
694 _NSGetExecutablePath( pathbuf, &bufsize); 694 _NSGetExecutablePath( pathbuf, &bufsize);
695 695
696 return std::string(pathbuf); 696 return std::string(pathbuf);
697 } 697 }
698 698
699 #elif defined(ORTHANC_SANDBOXED) && ORTHANC_SANDBOXED == 1 699 #elif ORTHANC_SANDBOXED == 1
700 // Sandboxed Orthanc, no access to the executable 700 // Sandboxed Orthanc, no access to the executable
701 701
702 #else 702 #else
703 #error Support your platform here 703 #error Support your platform here
704 #endif 704 #endif
705 705
706 706
707 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 707 #if ORTHANC_SANDBOXED == 0
708 std::string Toolbox::GetPathToExecutable() 708 std::string Toolbox::GetPathToExecutable()
709 { 709 {
710 boost::filesystem::path p(GetPathToExecutableInternal()); 710 boost::filesystem::path p(GetPathToExecutableInternal());
711 return boost::filesystem::absolute(p).string(); 711 return boost::filesystem::absolute(p).string();
712 } 712 }
1176 1176
1177 result.push_back(currentItem); 1177 result.push_back(currentItem);
1178 } 1178 }
1179 1179
1180 1180
1181 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 1181 #if ORTHANC_SANDBOXED == 0
1182 void Toolbox::MakeDirectory(const std::string& path) 1182 void Toolbox::MakeDirectory(const std::string& path)
1183 { 1183 {
1184 if (boost::filesystem::exists(path)) 1184 if (boost::filesystem::exists(path))
1185 { 1185 {
1186 if (!boost::filesystem::is_directory(path)) 1186 if (!boost::filesystem::is_directory(path))
1197 } 1197 }
1198 } 1198 }
1199 #endif 1199 #endif
1200 1200
1201 1201
1202 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 1202 #if ORTHANC_SANDBOXED == 0
1203 bool Toolbox::IsExistingFile(const std::string& path) 1203 bool Toolbox::IsExistingFile(const std::string& path)
1204 { 1204 {
1205 return boost::filesystem::exists(path); 1205 return boost::filesystem::exists(path);
1206 } 1206 }
1207 #endif 1207 #endif
1327 } 1327 }
1328 1328
1329 #endif 1329 #endif
1330 1330
1331 1331
1332 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 1332 #if ORTHANC_SANDBOXED == 0
1333 void Toolbox::ExecuteSystemCommand(const std::string& command, 1333 void Toolbox::ExecuteSystemCommand(const std::string& command,
1334 const std::vector<std::string>& arguments) 1334 const std::vector<std::string>& arguments)
1335 { 1335 {
1336 // Convert the arguments as a C array 1336 // Convert the arguments as a C array
1337 std::vector<char*> args(arguments.size() + 2); 1337 std::vector<char*> args(arguments.size() + 2);
1496 return str.compare(0, prefix.size(), prefix) == 0; 1496 return str.compare(0, prefix.size(), prefix) == 0;
1497 } 1497 }
1498 } 1498 }
1499 1499
1500 1500
1501 #if ORTHANC_SANDBOXED == 0
1501 int Toolbox::GetProcessId() 1502 int Toolbox::GetProcessId()
1502 { 1503 {
1503 #if defined(_WIN32) 1504 #if defined(_WIN32)
1504 return static_cast<int>(_getpid()); 1505 return static_cast<int>(_getpid());
1505 #else 1506 #else
1506 return static_cast<int>(getpid()); 1507 return static_cast<int>(getpid());
1507 #endif 1508 #endif
1508 } 1509 }
1509 1510 #endif
1510 1511
1511 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 1512
1513 #if ORTHANC_SANDBOXED == 0
1512 bool Toolbox::IsRegularFile(const std::string& path) 1514 bool Toolbox::IsRegularFile(const std::string& path)
1513 { 1515 {
1514 namespace fs = boost::filesystem; 1516 namespace fs = boost::filesystem;
1515 1517
1516 try 1518 try