Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 2141:a260a8ad83f1
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 16:16:26 +0100 |
parents | aa4b8895cd23 |
children | fd5875662670 |
comparison
equal
deleted
inserted
replaced
2140:aa4b8895cd23 | 2141:a260a8ad83f1 |
---|---|
101 } | 101 } |
102 } | 102 } |
103 #endif | 103 #endif |
104 | 104 |
105 | 105 |
106 | |
107 // Inclusions for UUID | |
108 // http://stackoverflow.com/a/1626302 | |
109 | |
110 extern "C" | |
111 { | |
112 #ifdef WIN32 | |
113 #include <rpc.h> | |
114 #else | |
115 #include <uuid/uuid.h> | |
116 #endif | |
117 } | |
118 | |
119 | |
106 #if ORTHANC_ENABLE_PUGIXML == 1 | 120 #if ORTHANC_ENABLE_PUGIXML == 1 |
107 #include "ChunkedBuffer.h" | 121 #include "ChunkedBuffer.h" |
108 #include <pugixml.hpp> | 122 #include <pugixml.hpp> |
109 #endif | 123 #endif |
110 | 124 |
1236 return static_cast<unsigned int>(v); | 1250 return static_cast<unsigned int>(v); |
1237 } | 1251 } |
1238 } | 1252 } |
1239 | 1253 |
1240 | 1254 |
1255 std::string Toolbox::GenerateUuid() | |
1256 { | |
1257 #ifdef WIN32 | |
1258 UUID uuid; | |
1259 UuidCreate ( &uuid ); | |
1260 | |
1261 unsigned char * str; | |
1262 UuidToStringA ( &uuid, &str ); | |
1263 | |
1264 std::string s( ( char* ) str ); | |
1265 | |
1266 RpcStringFreeA ( &str ); | |
1267 #else | |
1268 uuid_t uuid; | |
1269 uuid_generate_random ( uuid ); | |
1270 char s[37]; | |
1271 uuid_unparse ( uuid, s ); | |
1272 #endif | |
1273 return s; | |
1274 } | |
1275 | |
1276 | |
1277 bool Toolbox::IsUuid(const std::string& str) | |
1278 { | |
1279 if (str.size() != 36) | |
1280 { | |
1281 return false; | |
1282 } | |
1283 | |
1284 for (size_t i = 0; i < str.length(); i++) | |
1285 { | |
1286 if (i == 8 || i == 13 || i == 18 || i == 23) | |
1287 { | |
1288 if (str[i] != '-') | |
1289 return false; | |
1290 } | |
1291 else | |
1292 { | |
1293 if (!isalnum(str[i])) | |
1294 return false; | |
1295 } | |
1296 } | |
1297 | |
1298 return true; | |
1299 } | |
1300 | |
1301 | |
1302 bool Toolbox::StartsWithUuid(const std::string& str) | |
1303 { | |
1304 if (str.size() < 36) | |
1305 { | |
1306 return false; | |
1307 } | |
1308 | |
1309 if (str.size() == 36) | |
1310 { | |
1311 return IsUuid(str); | |
1312 } | |
1313 | |
1314 assert(str.size() > 36); | |
1315 if (!isspace(str[36])) | |
1316 { | |
1317 return false; | |
1318 } | |
1319 | |
1320 return IsUuid(str.substr(0, 36)); | |
1321 } | |
1322 | |
1323 | |
1241 #if ORTHANC_SANDBOXED == 0 | 1324 #if ORTHANC_SANDBOXED == 0 |
1242 | 1325 |
1243 static bool finish_; | 1326 static bool finish_; |
1244 static ServerBarrierEvent barrierEvent_; | 1327 static ServerBarrierEvent barrierEvent_; |
1245 | 1328 |