Mercurial > hg > orthanc-wsi
comparison Framework/Orthanc/Core/Toolbox.h @ 41:5f4e367f7b0d
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 15:34:27 +0100 |
parents | 533cbc4d520c |
children | 9621fd6f17c9 |
comparison
equal
deleted
inserted
replaced
40:371243c270cc | 41:5f4e367f7b0d |
---|---|
37 #include <stdint.h> | 37 #include <stdint.h> |
38 #include <vector> | 38 #include <vector> |
39 #include <string> | 39 #include <string> |
40 #include <json/json.h> | 40 #include <json/json.h> |
41 | 41 |
42 | |
43 #if !defined(ORTHANC_ENABLE_BASE64) | |
44 # error The macro ORTHANC_ENABLE_BASE64 must be defined | |
45 #endif | |
46 | |
47 #if !defined(ORTHANC_ENABLE_MD5) | |
48 # error The macro ORTHANC_ENABLE_MD5 must be defined | |
49 #endif | |
50 | |
51 #if !defined(ORTHANC_ENABLE_PUGIXML) | |
52 # error The macro ORTHANC_ENABLE_PUGIXML must be defined | |
53 #endif | |
54 | |
55 #if !defined(BOOST_HAS_REGEX) | |
56 # error The macro BOOST_HAS_REGEX must be defined | |
57 #endif | |
58 | |
59 #if !defined(ORTHANC_SANDBOXED) | |
60 # define ORTHANC_SANDBOXED 0 | |
61 #endif | |
62 | |
42 namespace Orthanc | 63 namespace Orthanc |
43 { | 64 { |
44 typedef std::vector<std::string> UriComponents; | 65 typedef std::vector<std::string> UriComponents; |
45 | 66 |
46 class NullType | 67 class NullType |
49 | 70 |
50 namespace Toolbox | 71 namespace Toolbox |
51 { | 72 { |
52 void USleep(uint64_t microSeconds); | 73 void USleep(uint64_t microSeconds); |
53 | 74 |
54 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | 75 #if ORTHANC_SANDBOXED == 0 |
55 ServerBarrierEvent ServerBarrier(const bool& stopFlag); | 76 ServerBarrierEvent ServerBarrier(const bool& stopFlag); |
56 | 77 |
57 ServerBarrierEvent ServerBarrier(); | 78 ServerBarrierEvent ServerBarrier(); |
58 #endif | 79 #endif |
59 | 80 |
65 const std::string& source); | 86 const std::string& source); |
66 | 87 |
67 void ToLowerCase(std::string& result, | 88 void ToLowerCase(std::string& result, |
68 const std::string& source); | 89 const std::string& source); |
69 | 90 |
70 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | 91 #if ORTHANC_SANDBOXED == 0 |
71 void ReadFile(std::string& content, | 92 void ReadFile(std::string& content, |
72 const std::string& path); | 93 const std::string& path); |
73 #endif | 94 |
74 | |
75 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
76 bool ReadHeader(std::string& header, | 95 bool ReadHeader(std::string& header, |
77 const std::string& path, | 96 const std::string& path, |
78 size_t headerSize); | 97 size_t headerSize); |
79 #endif | 98 |
80 | |
81 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
82 void WriteFile(const std::string& content, | 99 void WriteFile(const std::string& content, |
83 const std::string& path); | 100 const std::string& path); |
84 #endif | 101 |
85 | |
86 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
87 void WriteFile(const void* content, | 102 void WriteFile(const void* content, |
88 size_t size, | 103 size_t size, |
89 const std::string& path); | 104 const std::string& path); |
90 #endif | 105 |
91 | |
92 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
93 void RemoveFile(const std::string& path); | 106 void RemoveFile(const std::string& path); |
94 #endif | 107 #endif |
95 | 108 |
96 void SplitUriComponents(UriComponents& components, | 109 void SplitUriComponents(UriComponents& components, |
97 const std::string& uri); | 110 const std::string& uri); |
106 std::string AutodetectMimeType(const std::string& path); | 119 std::string AutodetectMimeType(const std::string& path); |
107 | 120 |
108 std::string FlattenUri(const UriComponents& components, | 121 std::string FlattenUri(const UriComponents& components, |
109 size_t fromLevel = 0); | 122 size_t fromLevel = 0); |
110 | 123 |
111 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | 124 #if ORTHANC_SANDBOXED == 0 |
112 uint64_t GetFileSize(const std::string& path); | 125 uint64_t GetFileSize(const std::string& path); |
113 #endif | 126 #endif |
114 | 127 |
115 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1 | 128 #if ORTHANC_ENABLE_MD5 == 1 |
116 void ComputeMD5(std::string& result, | 129 void ComputeMD5(std::string& result, |
117 const std::string& data); | 130 const std::string& data); |
118 | 131 |
119 void ComputeMD5(std::string& result, | 132 void ComputeMD5(std::string& result, |
120 const void* data, | 133 const void* data, |
131 bool IsSHA1(const char* str, | 144 bool IsSHA1(const char* str, |
132 size_t size); | 145 size_t size); |
133 | 146 |
134 bool IsSHA1(const std::string& s); | 147 bool IsSHA1(const std::string& s); |
135 | 148 |
136 #if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1 | 149 #if ORTHANC_ENABLE_BASE64 == 1 |
137 void DecodeBase64(std::string& result, | 150 void DecodeBase64(std::string& result, |
138 const std::string& data); | 151 const std::string& data); |
139 | 152 |
140 void EncodeBase64(std::string& result, | 153 void EncodeBase64(std::string& result, |
141 const std::string& data); | 154 const std::string& data); |
149 void EncodeDataUriScheme(std::string& result, | 162 void EncodeDataUriScheme(std::string& result, |
150 const std::string& mime, | 163 const std::string& mime, |
151 const std::string& content); | 164 const std::string& content); |
152 #endif | 165 #endif |
153 | 166 |
154 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | 167 #if ORTHANC_SANDBOXED == 0 |
155 std::string GetPathToExecutable(); | 168 std::string GetPathToExecutable(); |
156 | 169 |
157 std::string GetDirectoryOfExecutable(); | 170 std::string GetDirectoryOfExecutable(); |
158 #endif | 171 #endif |
159 | 172 |
188 | 201 |
189 void TokenizeString(std::vector<std::string>& result, | 202 void TokenizeString(std::vector<std::string>& result, |
190 const std::string& source, | 203 const std::string& source, |
191 char separator); | 204 char separator); |
192 | 205 |
193 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | 206 #if ORTHANC_SANDBOXED == 0 |
194 void MakeDirectory(const std::string& path); | 207 void MakeDirectory(const std::string& path); |
195 #endif | 208 |
196 | |
197 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
198 bool IsExistingFile(const std::string& path); | 209 bool IsExistingFile(const std::string& path); |
199 #endif | 210 #endif |
200 | 211 |
201 #if ORTHANC_ENABLE_PUGIXML == 1 | 212 #if ORTHANC_ENABLE_PUGIXML == 1 |
202 void JsonToXml(std::string& target, | 213 void JsonToXml(std::string& target, |
203 const Json::Value& source, | 214 const Json::Value& source, |
204 const std::string& rootElement = "root", | 215 const std::string& rootElement = "root", |
205 const std::string& arrayElement = "item"); | 216 const std::string& arrayElement = "item"); |
206 #endif | 217 #endif |
207 | 218 |
208 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | 219 #if ORTHANC_SANDBOXED == 0 |
209 void ExecuteSystemCommand(const std::string& command, | 220 void ExecuteSystemCommand(const std::string& command, |
210 const std::vector<std::string>& arguments); | 221 const std::vector<std::string>& arguments); |
211 #endif | 222 #endif |
212 | 223 |
213 bool IsInteger(const std::string& str); | 224 bool IsInteger(const std::string& str); |
216 const Json::Value& source); | 227 const Json::Value& source); |
217 | 228 |
218 bool StartsWith(const std::string& str, | 229 bool StartsWith(const std::string& str, |
219 const std::string& prefix); | 230 const std::string& prefix); |
220 | 231 |
232 #if ORTHANC_SANDBOXED == 0 | |
221 int GetProcessId(); | 233 int GetProcessId(); |
222 | 234 |
223 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1 | |
224 bool IsRegularFile(const std::string& path); | 235 bool IsRegularFile(const std::string& path); |
225 #endif | 236 #endif |
226 | 237 |
227 FILE* OpenFile(const std::string& path, | 238 FILE* OpenFile(const std::string& path, |
228 FileMode mode); | 239 FileMode mode); |