X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Fuuid.c;h=a466090d9d37e30de1b3f2ed83372eb278ae4426;hb=198879bd5f1baa09e5dc7a951db980a932cd5db5;hp=f300f425746627717ef3ad28bf24e620d478f10b;hpb=dc0eacd40b625258355eea866d62188e5aa7ce3b;p=openldap
diff --git a/libraries/liblutil/uuid.c b/libraries/liblutil/uuid.c
index f300f42574..a466090d9d 100644
--- a/libraries/liblutil/uuid.c
+++ b/libraries/liblutil/uuid.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2009 The OpenLDAP Foundation.
* Portions Copyright 2000-2003 Kurt D. Zeilenga.
* All rights reserved.
*
@@ -41,6 +41,8 @@
#ifdef HAVE_UUID_TO_STR
# include
+#elif defined( HAVE_UUID_GENERATE )
+# include
#elif defined( _WIN32 )
# include
#else
@@ -56,7 +58,7 @@
#include
/* not needed for Windows */
-#if !defined(HAVE_UUID_TO_STR) && !defined(_WIN32)
+#if !defined(HAVE_UUID_TO_STR) && !defined(HAVE_UUID_GENERATE) && !defined(_WIN32)
static unsigned char *
lutil_eaddr( void )
{
@@ -169,7 +171,7 @@ lutil_eaddr( void )
if (memcmp(eaddr, zero, sizeof(eaddr)) == 0) {
/* XXX - who knows? */
lutil_entropy( eaddr, sizeof(eaddr) );
- eaddr[0] |= 0x80; /* turn it into a multicast address */
+ eaddr[0] |= 0x01; /* turn it into a multicast address */
}
return eaddr;
@@ -251,7 +253,7 @@ mul64ll(unsigned long i1, unsigned long i2)
#endif /* ULONG_MAX >= 64 bits || HAVE_LONG_LONG */
-#endif /* !HAVE_UUID_TO_STR && !_WIN32 */
+#endif /* !HAVE_UUID_TO_STR && !HAVE_UUID_GENERATE && !_WIN32 */
/*
** All we really care about is an ISO UUID string. The format of a UUID is:
@@ -298,6 +300,13 @@ lutil_uuidstr( char *buf, size_t len )
return l;
+#elif defined( HAVE_UUID_GENERATE )
+ uuid_t uu;
+
+ uuid_generate( uu );
+ uuid_unparse_lower( uu, buf );
+ return strlen( buf );
+
#elif defined( _WIN32 )
UUID uuid;
unsigned char *uuidstr;
@@ -371,6 +380,47 @@ lutil_uuidstr( char *buf, size_t len )
#endif
}
+int
+lutil_uuidstr_from_normalized(
+ char *uuid,
+ size_t uuidlen,
+ char *buf,
+ size_t buflen )
+{
+ unsigned char nibble;
+ int i, d = 0;
+
+ assert( uuid != NULL );
+ assert( buf != NULL );
+
+ if ( uuidlen != 16 ) return -1;
+ if ( buflen < 36 ) return -1;
+
+ for ( i = 0; i < 16; i++ ) {
+ if ( i == 4 || i == 6 || i == 8 || i == 10 ) {
+ buf[(i<<1)+d] = '-';
+ d += 1;
+ }
+
+ nibble = (uuid[i] >> 4) & 0xF;
+ if ( nibble < 10 ) {
+ buf[(i<<1)+d] = nibble + '0';
+ } else {
+ buf[(i<<1)+d] = nibble - 10 + 'a';
+ }
+
+ nibble = (uuid[i]) & 0xF;
+ if ( nibble < 10 ) {
+ buf[(i<<1)+d+1] = nibble + '0';
+ } else {
+ buf[(i<<1)+d+1] = nibble - 10 + 'a';
+ }
+ }
+
+ if ( buflen > 36 ) buf[36] = '\0';
+ return 36;
+}
+
#ifdef TEST
int
main(int argc, char **argv)