aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/uuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unstable/uuid.cpp')
-rw-r--r--src/unstable/uuid.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp
index 304ea4a..bd6662a 100644
--- a/src/unstable/uuid.cpp
+++ b/src/unstable/uuid.cpp
@@ -9,6 +9,7 @@
9#include "bu/file.h" 9#include "bu/file.h"
10#include "bu/formatter.h" 10#include "bu/formatter.h"
11#include "bu/membuf.h" 11#include "bu/membuf.h"
12#include "bu/random.h"
12#include <string.h> 13#include <string.h>
13 14
14#ifdef WIN32 15#ifdef WIN32
@@ -83,6 +84,7 @@ void Bu::Uuid::clear()
83 84
84Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) 85Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType )
85{ 86{
87 Uuid id;
86 switch( eType ) 88 switch( eType )
87 { 89 {
88 case Version1: 90 case Version1:
@@ -90,19 +92,24 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType )
90 case Version3: 92 case Version3:
91 case Version4: 93 case Version4:
92 case Version5: 94 case Version5:
95 // Yeah... all of these are just random for now, a lot more
96 // platform specific code is required for a lot of these.
97 for( int j = 0; j < 16; j++ )
98 {
99 id.data[j] = Bu::Random::rand(256);
100 }
101 break;
102
93 default: 103 default:
94 case System: 104 case System:
95#if defined(linux) 105#if defined(linux)
96 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read ); 106 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read );
97 char dat[36]; 107 char dat[36];
98 fIn.read( dat, 36 ); 108 fIn.read( dat, 36 );
99 Uuid id;
100 id.set( dat ); 109 id.set( dat );
101 return id;
102#elif defined(WIN32) 110#elif defined(WIN32)
103 UUID uuid; 111 UUID uuid;
104 UuidCreate( &uuid ); 112 UuidCreate( &uuid );
105 Uuid id;
106 id.data[0] = ((unsigned char *)&uuid.Data1)[3]; 113 id.data[0] = ((unsigned char *)&uuid.Data1)[3];
107 id.data[1] = ((unsigned char *)&uuid.Data1)[2]; 114 id.data[1] = ((unsigned char *)&uuid.Data1)[2];
108 id.data[2] = ((unsigned char *)&uuid.Data1)[1]; 115 id.data[2] = ((unsigned char *)&uuid.Data1)[1];
@@ -113,11 +120,12 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType )
113 id.data[7] = ((unsigned char *)&uuid.Data3)[0]; 120 id.data[7] = ((unsigned char *)&uuid.Data3)[0];
114 memcpy( id.data+8, uuid.Data4, 8 ); 121 memcpy( id.data+8, uuid.Data4, 8 );
115 122
116 return id;
117#else 123#else
118# error We should be using one of the other fallbacks, but your platform is not supported yet. Sorry. 124#warning No platform specific UUID, falling back to random for now
125 return generate( Version4 );
119#endif 126#endif
120 } 127 }
128 return id;
121} 129}
122 130
123void Bu::Uuid::set( const Bu::String &sSrc ) 131void Bu::Uuid::set( const Bu::String &sSrc )