Mercurial > hg > orthanc
changeset 2141:a260a8ad83f1
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 16:16:26 +0100 |
parents | aa4b8895cd23 |
children | 5a8840920121 |
files | Core/Toolbox.cpp Core/Toolbox.h Core/Uuid.cpp Core/Uuid.h |
diffstat | 4 files changed, 101 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Toolbox.cpp Wed Nov 09 16:12:47 2016 +0100 +++ b/Core/Toolbox.cpp Wed Nov 09 16:16:26 2016 +0100 @@ -103,6 +103,20 @@ #endif + +// Inclusions for UUID +// http://stackoverflow.com/a/1626302 + +extern "C" +{ +#ifdef WIN32 +#include <rpc.h> +#else +#include <uuid/uuid.h> +#endif +} + + #if ORTHANC_ENABLE_PUGIXML == 1 #include "ChunkedBuffer.h" #include <pugixml.hpp> @@ -1238,6 +1252,75 @@ } + std::string Toolbox::GenerateUuid() + { +#ifdef WIN32 + UUID uuid; + UuidCreate ( &uuid ); + + unsigned char * str; + UuidToStringA ( &uuid, &str ); + + std::string s( ( char* ) str ); + + RpcStringFreeA ( &str ); +#else + uuid_t uuid; + uuid_generate_random ( uuid ); + char s[37]; + uuid_unparse ( uuid, s ); +#endif + return s; + } + + + bool Toolbox::IsUuid(const std::string& str) + { + if (str.size() != 36) + { + return false; + } + + for (size_t i = 0; i < str.length(); i++) + { + if (i == 8 || i == 13 || i == 18 || i == 23) + { + if (str[i] != '-') + return false; + } + else + { + if (!isalnum(str[i])) + return false; + } + } + + return true; + } + + + bool Toolbox::StartsWithUuid(const std::string& str) + { + if (str.size() < 36) + { + return false; + } + + if (str.size() == 36) + { + return IsUuid(str); + } + + assert(str.size() > 36); + if (!isspace(str[36])) + { + return false; + } + + return IsUuid(str.substr(0, 36)); + } + + #if ORTHANC_SANDBOXED == 0 static bool finish_;
--- a/Core/Toolbox.h Wed Nov 09 16:12:47 2016 +0100 +++ b/Core/Toolbox.h Wed Nov 09 16:16:26 2016 +0100 @@ -60,6 +60,18 @@ # define ORTHANC_SANDBOXED 0 #endif + +/** + * NOTE: GUID vs. UUID + * The simple answer is: no difference, they are the same thing. Treat + * them as a 16 byte (128 bits) value that is used as a unique + * value. In Microsoft-speak they are called GUIDs, but call them + * UUIDs when not using Microsoft-speak. + * http://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid + **/ + + + namespace Orthanc { typedef std::vector<std::string> UriComponents; @@ -195,6 +207,12 @@ unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, const std::string& key, unsigned int defaultValue); + + std::string GenerateUuid(); + + bool IsUuid(const std::string& str); + + bool StartsWithUuid(const std::string& str); }
--- a/Core/Uuid.cpp Wed Nov 09 16:12:47 2016 +0100 +++ b/Core/Uuid.cpp Wed Nov 09 16:16:26 2016 +0100 @@ -33,93 +33,10 @@ #include "PrecompiledHeaders.h" #include "Uuid.h" -// http://stackoverflow.com/a/1626302 - -extern "C" -{ -#ifdef WIN32 -#include <rpc.h> -#else -#include <uuid/uuid.h> -#endif -} - #include <boost/filesystem.hpp> namespace Orthanc { - namespace Toolbox - { - std::string GenerateUuid() - { -#ifdef WIN32 - UUID uuid; - UuidCreate ( &uuid ); - - unsigned char * str; - UuidToStringA ( &uuid, &str ); - - std::string s( ( char* ) str ); - - RpcStringFreeA ( &str ); -#else - uuid_t uuid; - uuid_generate_random ( uuid ); - char s[37]; - uuid_unparse ( uuid, s ); -#endif - return s; - } - - - bool IsUuid(const std::string& str) - { - if (str.size() != 36) - { - return false; - } - - for (size_t i = 0; i < str.length(); i++) - { - if (i == 8 || i == 13 || i == 18 || i == 23) - { - if (str[i] != '-') - return false; - } - else - { - if (!isalnum(str[i])) - return false; - } - } - - return true; - } - - - bool StartsWithUuid(const std::string& str) - { - if (str.size() < 36) - { - return false; - } - - if (str.size() == 36) - { - return IsUuid(str); - } - - assert(str.size() > 36); - if (!isspace(str[36])) - { - return false; - } - - return IsUuid(str.substr(0, 36)); - } - } - - static std::string CreateTemporaryPath(const char* extension) { #if BOOST_HAS_FILESYSTEM_V3 == 1
--- a/Core/Uuid.h Wed Nov 09 16:12:47 2016 +0100 +++ b/Core/Uuid.h Wed Nov 09 16:16:26 2016 +0100 @@ -34,15 +34,6 @@ #include <string> -/** - * GUID vs. UUID - * The simple answer is: no difference, they are the same thing. Treat - * them as a 16 byte (128 bits) value that is used as a unique - * value. In Microsoft-speak they are called GUIDs, but call them - * UUIDs when not using Microsoft-speak. - * http://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid - **/ - #if !defined(ORTHANC_SANDBOXED) # define ORTHANC_SANDBOXED 0 #endif @@ -51,15 +42,6 @@ namespace Orthanc { - namespace Toolbox - { - std::string GenerateUuid(); - - bool IsUuid(const std::string& str); - - bool StartsWithUuid(const std::string& str); - } - #if ORTHANC_SANDBOXED == 0 class TemporaryFile {