comparison Resources/Orthanc/Core/Toolbox.h @ 200:03afbee0cc7b

integration of Orthanc core into Stone
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Mar 2018 11:04:03 +0100
parents
children 795d71f66f31
comparison
equal deleted inserted replaced
199:dabe9982fca3 200:03afbee0cc7b
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 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #include "Enumerations.h"
37
38 #include <stdint.h>
39 #include <vector>
40 #include <string>
41 #include <json/json.h>
42
43
44 #if !defined(ORTHANC_ENABLE_BASE64)
45 # error The macro ORTHANC_ENABLE_BASE64 must be defined
46 #endif
47
48 #if !defined(ORTHANC_ENABLE_LOCALE)
49 # error The macro ORTHANC_ENABLE_LOCALE must be defined
50 #endif
51
52 #if !defined(ORTHANC_ENABLE_MD5)
53 # error The macro ORTHANC_ENABLE_MD5 must be defined
54 #endif
55
56 #if !defined(ORTHANC_ENABLE_PUGIXML)
57 # error The macro ORTHANC_ENABLE_PUGIXML must be defined
58 #endif
59
60
61 /**
62 * NOTE: GUID vs. UUID
63 * The simple answer is: no difference, they are the same thing. Treat
64 * them as a 16 byte (128 bits) value that is used as a unique
65 * value. In Microsoft-speak they are called GUIDs, but call them
66 * UUIDs when not using Microsoft-speak.
67 * http://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid
68 **/
69
70
71
72 namespace Orthanc
73 {
74 typedef std::vector<std::string> UriComponents;
75
76 class NullType
77 {
78 };
79
80 namespace Toolbox
81 {
82 void ToUpperCase(std::string& s); // Inplace version
83
84 void ToLowerCase(std::string& s); // Inplace version
85
86 void ToUpperCase(std::string& result,
87 const std::string& source);
88
89 void ToLowerCase(std::string& result,
90 const std::string& source);
91
92 void SplitUriComponents(UriComponents& components,
93 const std::string& uri);
94
95 void TruncateUri(UriComponents& target,
96 const UriComponents& source,
97 size_t fromLevel);
98
99 bool IsChildUri(const UriComponents& baseUri,
100 const UriComponents& testedUri);
101
102 std::string AutodetectMimeType(const std::string& path);
103
104 std::string FlattenUri(const UriComponents& components,
105 size_t fromLevel = 0);
106
107 #if ORTHANC_ENABLE_MD5 == 1
108 void ComputeMD5(std::string& result,
109 const std::string& data);
110
111 void ComputeMD5(std::string& result,
112 const void* data,
113 size_t size);
114 #endif
115
116 void ComputeSHA1(std::string& result,
117 const std::string& data);
118
119 void ComputeSHA1(std::string& result,
120 const void* data,
121 size_t size);
122
123 bool IsSHA1(const char* str,
124 size_t size);
125
126 bool IsSHA1(const std::string& s);
127
128 #if ORTHANC_ENABLE_BASE64 == 1
129 void DecodeBase64(std::string& result,
130 const std::string& data);
131
132 void EncodeBase64(std::string& result,
133 const std::string& data);
134
135 bool DecodeDataUriScheme(std::string& mime,
136 std::string& content,
137 const std::string& source);
138
139 void EncodeDataUriScheme(std::string& result,
140 const std::string& mime,
141 const std::string& content);
142 #endif
143
144 #if ORTHANC_ENABLE_LOCALE == 1
145 std::string ConvertToUtf8(const std::string& source,
146 Encoding sourceEncoding);
147
148 std::string ConvertFromUtf8(const std::string& source,
149 Encoding targetEncoding);
150 #endif
151
152 bool IsAsciiString(const void* data,
153 size_t size);
154
155 bool IsAsciiString(const std::string& s);
156
157 std::string ConvertToAscii(const std::string& source);
158
159 std::string StripSpaces(const std::string& source);
160
161 // In-place percent-decoding for URL
162 void UrlDecode(std::string& s);
163
164 Endianness DetectEndianness();
165
166 std::string WildcardToRegularExpression(const std::string& s);
167
168 void TokenizeString(std::vector<std::string>& result,
169 const std::string& source,
170 char separator);
171
172 #if ORTHANC_ENABLE_PUGIXML == 1
173 void JsonToXml(std::string& target,
174 const Json::Value& source,
175 const std::string& rootElement = "root",
176 const std::string& arrayElement = "item");
177 #endif
178
179 bool IsInteger(const std::string& str);
180
181 void CopyJsonWithoutComments(Json::Value& target,
182 const Json::Value& source);
183
184 bool StartsWith(const std::string& str,
185 const std::string& prefix);
186
187 void UriEncode(std::string& target,
188 const std::string& source);
189
190 std::string GetJsonStringField(const ::Json::Value& json,
191 const std::string& key,
192 const std::string& defaultValue);
193
194 bool GetJsonBooleanField(const ::Json::Value& json,
195 const std::string& key,
196 bool defaultValue);
197
198 int GetJsonIntegerField(const ::Json::Value& json,
199 const std::string& key,
200 int defaultValue);
201
202 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json,
203 const std::string& key,
204 unsigned int defaultValue);
205
206 bool IsUuid(const std::string& str);
207
208 bool StartsWithUuid(const std::string& str);
209
210 #if ORTHANC_ENABLE_LOCALE == 1
211 void InitializeGlobalLocale(const char* locale);
212
213 void FinalizeGlobalLocale();
214
215 std::string ToUpperCaseWithAccents(const std::string& source);
216 #endif
217 }
218 }