0
|
1 /**
|
59
|
2 * Orthanc - A Lightweight, RESTful DICOM Store
|
0
|
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
|
|
4 * 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 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 **/
|
|
19
|
|
20
|
|
21 #include "Uuid.h"
|
|
22
|
|
23 // http://stackoverflow.com/a/1626302
|
|
24
|
|
25 extern "C"
|
|
26 {
|
|
27 #ifdef WIN32
|
|
28 #include <rpc.h>
|
|
29 #else
|
|
30 #include <uuid/uuid.h>
|
|
31 #endif
|
|
32 }
|
|
33
|
59
|
34 namespace Orthanc
|
0
|
35 {
|
|
36 namespace Toolbox
|
|
37 {
|
|
38 std::string GenerateUuid()
|
|
39 {
|
|
40 #ifdef WIN32
|
|
41 UUID uuid;
|
|
42 UuidCreate ( &uuid );
|
|
43
|
|
44 unsigned char * str;
|
|
45 UuidToStringA ( &uuid, &str );
|
|
46
|
|
47 std::string s( ( char* ) str );
|
|
48
|
|
49 RpcStringFreeA ( &str );
|
|
50 #else
|
|
51 uuid_t uuid;
|
|
52 uuid_generate_random ( uuid );
|
|
53 char s[37];
|
|
54 uuid_unparse ( uuid, s );
|
|
55 #endif
|
|
56 return s;
|
|
57 }
|
|
58
|
|
59
|
|
60 bool IsUuid(const std::string& str)
|
|
61 {
|
|
62 if (str.size() != 36)
|
|
63 {
|
|
64 return false;
|
|
65 }
|
|
66
|
|
67 for (size_t i = 0; i < str.length(); i++)
|
|
68 {
|
|
69 if (i == 8 || i == 13 || i == 18 || i == 23)
|
|
70 {
|
|
71 if (str[i] != '-')
|
|
72 return false;
|
|
73 }
|
|
74 else
|
|
75 {
|
|
76 if (!isalnum(str[i]))
|
|
77 return false;
|
|
78 }
|
|
79 }
|
|
80
|
|
81 return true;
|
|
82 }
|
|
83 }
|
|
84 }
|