comparison Framework/Orthanc/Core/Toolbox.h @ 1:2dbe613f6c93

add orthanc core
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Oct 2016 15:39:01 +0200
parents
children 9220cf4a63d5
comparison
equal deleted inserted replaced
0:351ab0da0150 1:2dbe613f6c93
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * In addition, as a special exception, the copyright holders of this
12 * program give permission to link the code of its release with the
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
14 * that use the same license as the "OpenSSL" library), and distribute
15 * the linked executables. You must obey the GNU General Public License
16 * in all respects for all of the code used other than "OpenSSL". If you
17 * modify file(s) with this exception, you may extend this exception to
18 * your version of the file(s), but you are not obligated to do so. If
19 * you do not wish to do so, delete this exception statement from your
20 * version. If you delete this exception statement from all source files
21 * in the program, then also delete it here.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 **/
31
32
33 #pragma once
34
35 #include "Enumerations.h"
36
37 #include <stdint.h>
38 #include <vector>
39 #include <string>
40 #include <json/json.h>
41
42 namespace Orthanc
43 {
44 typedef std::vector<std::string> UriComponents;
45
46 class NullType
47 {
48 };
49
50 namespace Toolbox
51 {
52 void USleep(uint64_t microSeconds);
53
54 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
55 ServerBarrierEvent ServerBarrier(const bool& stopFlag);
56
57 ServerBarrierEvent ServerBarrier();
58 #endif
59
60 void ToUpperCase(std::string& s); // Inplace version
61
62 void ToLowerCase(std::string& s); // Inplace version
63
64 void ToUpperCase(std::string& result,
65 const std::string& source);
66
67 void ToLowerCase(std::string& result,
68 const std::string& source);
69
70 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
71 void ReadFile(std::string& content,
72 const std::string& path);
73 #endif
74
75 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
76 bool ReadHeader(std::string& header,
77 const std::string& path,
78 size_t headerSize);
79 #endif
80
81 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
82 void WriteFile(const std::string& content,
83 const std::string& path);
84 #endif
85
86 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
87 void WriteFile(const void* content,
88 size_t size,
89 const std::string& path);
90 #endif
91
92 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
93 void RemoveFile(const std::string& path);
94 #endif
95
96 void SplitUriComponents(UriComponents& components,
97 const std::string& uri);
98
99 void TruncateUri(UriComponents& target,
100 const UriComponents& source,
101 size_t fromLevel);
102
103 bool IsChildUri(const UriComponents& baseUri,
104 const UriComponents& testedUri);
105
106 std::string AutodetectMimeType(const std::string& path);
107
108 std::string FlattenUri(const UriComponents& components,
109 size_t fromLevel = 0);
110
111 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
112 uint64_t GetFileSize(const std::string& path);
113 #endif
114
115 #if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1
116 void ComputeMD5(std::string& result,
117 const std::string& data);
118
119 void ComputeMD5(std::string& result,
120 const void* data,
121 size_t size);
122 #endif
123
124 void ComputeSHA1(std::string& result,
125 const std::string& data);
126
127 void ComputeSHA1(std::string& result,
128 const void* data,
129 size_t size);
130
131 bool IsSHA1(const char* str,
132 size_t size);
133
134 bool IsSHA1(const std::string& s);
135
136 #if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1
137 void DecodeBase64(std::string& result,
138 const std::string& data);
139
140 void EncodeBase64(std::string& result,
141 const std::string& data);
142
143 # if BOOST_HAS_REGEX == 1
144 bool DecodeDataUriScheme(std::string& mime,
145 std::string& content,
146 const std::string& source);
147 # endif
148
149 void EncodeDataUriScheme(std::string& result,
150 const std::string& mime,
151 const std::string& content);
152 #endif
153
154 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
155 std::string GetPathToExecutable();
156
157 std::string GetDirectoryOfExecutable();
158 #endif
159
160 std::string ConvertToUtf8(const std::string& source,
161 Encoding sourceEncoding);
162
163 std::string ConvertFromUtf8(const std::string& source,
164 Encoding targetEncoding);
165
166 std::string ConvertToAscii(const std::string& source);
167
168 std::string StripSpaces(const std::string& source);
169
170 #if BOOST_HAS_DATE_TIME == 1
171 std::string GetNowIsoString();
172
173 void GetNowDicom(std::string& date,
174 std::string& time);
175 #endif
176
177 // In-place percent-decoding for URL
178 void UrlDecode(std::string& s);
179
180 Endianness DetectEndianness();
181
182 #if BOOST_HAS_REGEX == 1
183 std::string WildcardToRegularExpression(const std::string& s);
184 #endif
185
186 void TokenizeString(std::vector<std::string>& result,
187 const std::string& source,
188 char separator);
189
190 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
191 void MakeDirectory(const std::string& path);
192 #endif
193
194 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
195 bool IsExistingFile(const std::string& path);
196 #endif
197
198 #if ORTHANC_PUGIXML_ENABLED == 1
199 void JsonToXml(std::string& target,
200 const Json::Value& source,
201 const std::string& rootElement = "root",
202 const std::string& arrayElement = "item");
203 #endif
204
205 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
206 void ExecuteSystemCommand(const std::string& command,
207 const std::vector<std::string>& arguments);
208 #endif
209
210 bool IsInteger(const std::string& str);
211
212 void CopyJsonWithoutComments(Json::Value& target,
213 const Json::Value& source);
214
215 bool StartsWith(const std::string& str,
216 const std::string& prefix);
217
218 int GetProcessId();
219
220 #if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
221 bool IsRegularFile(const std::string& path);
222 #endif
223
224 FILE* OpenFile(const std::string& path,
225 FileMode mode);
226
227 void UriEncode(std::string& target,
228 const std::string& source);
229
230 std::string GetJsonStringField(const ::Json::Value& json,
231 const std::string& key,
232 const std::string& defaultValue);
233
234 bool GetJsonBooleanField(const ::Json::Value& json,
235 const std::string& key,
236 bool defaultValue);
237
238 int GetJsonIntegerField(const ::Json::Value& json,
239 const std::string& key,
240 int defaultValue);
241
242 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json,
243 const std::string& key,
244 unsigned int defaultValue);
245 }
246 }