# HG changeset patch # User Sebastien Jodogne # Date 1478704586 -3600 # Node ID a260a8ad83f1504da77b1bc6be7e357ae777035b # Parent aa4b8895cd231c0debeff667277180288d42eaa8 reorganization diff -r aa4b8895cd23 -r a260a8ad83f1 Core/Toolbox.cpp --- 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 +#else +#include +#endif +} + + #if ORTHANC_ENABLE_PUGIXML == 1 #include "ChunkedBuffer.h" #include @@ -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_; diff -r aa4b8895cd23 -r a260a8ad83f1 Core/Toolbox.h --- 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 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); } diff -r aa4b8895cd23 -r a260a8ad83f1 Core/Uuid.cpp --- 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 -#else -#include -#endif -} - #include 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 diff -r aa4b8895cd23 -r a260a8ad83f1 Core/Uuid.h --- 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 -/** - * 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 {