1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <sal/types.h>
35 #include <rtl/string.h>
40 Specification (from draft-leach-uuids-guids-01.txt )
43 A UUID is an identifier that is unique across both space and time,
44 with respect to the space of all UUIDs. To be precise, the UUID
45 consists of a finite bit space. Thus, collision cannot be avoided in
46 principle. A UUID can be used for multiple purposes, from tagging objects
47 with an extremely short lifetime, to reliably identifying very persistent
48 objects across a network.
51 The generation of UUIDs does not require that a registration
52 authority be contacted for each identifier. Instead, Version 4 UUIDs are
53 generated from (pseudo unique) sequences of (pseudo) random bits.
60 /** Generates a new Version 4 (random number based) UUID (Universally Unique
63 @param pTargetUUID pointer to at least 16 bytes of memory. After the call it contains
64 the newly generated uuid in network byte order.
65 @param pPredecessorUUID ignored (was used when this function returned
66 Version 1 instead of Version 4 UUIDs).
67 @param bUseEthernetAddress ignored (was used when this function returned
68 Version 1 instead of Version 4 UUIDs).
70 void SAL_CALL
rtl_createUuid( sal_uInt8
*pTargetUUID
,
71 const sal_uInt8
*pPredecessorUUID
,
72 sal_Bool bUseEthernetAddress
);
74 /** Compare two UUID's lexically
77 Note: lexical ordering is not temporal ordering!
79 Note: For equalnesschecking, a memcmp(pUUID1,pUUID2,16) is more efficient
83 <li>-1 u1 is lexically before u2
84 <li>0 u1 is equal to u2
85 <li>1 u1 is lexically after u2
89 sal_Int32 SAL_CALL
rtl_compareUuid( const sal_uInt8
*pUUID1
, const sal_uInt8
*pUUID2
);
91 /** Creates named UUIDs.
94 The version 3 UUID is meant for generating UUIDs from <em>names</em> that
95 are drawn from, and unique within, some <em>name space</em>. Some examples
96 of names (and, implicitly, name spaces) might be DNS names, URLs, ISO
97 Object IDs (OIDs), reserved words in a programming language, or X.500
98 Distinguished Names (DNs); thus, the concept of name and name space
99 should be broadly construed, and not limited to textual names.
102 The requirements for such UUIDs are as follows:
105 <li> The UUIDs generated at different times from the same name in the
106 same namespace MUST be equal
108 <li> The UUIDs generated from two different names in the same namespace
109 should be different (with very high probability)
111 <li> The UUIDs generated from the same name in two different namespaces
112 should be different with (very high probability)
114 <li> If two UUIDs that were generated from names are equal, then they
115 were generated from the same name in the same namespace (with very
119 @param pTargetUUID pointer to at least 16 bytes of memory. After the call
120 it contains the newly generated uuid in network byte order.
121 @param pNameSpaceUUID The namespace uuid. Below are some predefined ones,
122 but any arbitray uuid can be used as namespace.
124 @param pName the name
126 void SAL_CALL
rtl_createNamedUuid(
127 sal_uInt8
*pTargetUUID
,
128 const sal_uInt8
*pNameSpaceUUID
,
129 const rtl_String
*pName
135 Predefined Namespaces
136 (Use them the following way : sal_uInt8 aNsDNS[16]) = RTL_UUID_NAMESPACE_DNS;
141 (Use them the following way : sal_uInt8 aNsDNS[16]) = RTL_UUID_NAMESPACE_DNS;
143 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */
144 #define RTL_UUID_NAMESPACE_DNS {\
145 0x6b,0xa7,0xb8,0x10,\
148 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\
154 6ba7b811-9dad-11d1-80b4-00c04fd430c8 */
155 #define RTL_UUID_NAMESPACE_URL { \
156 0x6b, 0xa7, 0xb8, 0x11,\
159 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\
165 6ba7b812-9dad-11d1-80b4-00c04fd430c8 */
166 #define RTL_UUID_NAMESPACE_OID {\
167 0x6b, 0xa7, 0xb8, 0x12,\
170 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\
176 6ba7b814-9dad-11d1-80b4-00c04fd430c8 */
177 #define RTL_UUID_NAMESPACE_X500 {\
178 0x6b, 0xa7, 0xb8, 0x14,\
181 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\
186 This macro must have a value below the system time resolution of the
187 system. The uuid routines use this value as an upper limit for adding ticks to the
188 the predecessor time value if system times are equal.
191 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 1000
192 #elif defined SAL_OS2 // YD we use posix functions for time
193 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10
195 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10
197 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10
199 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10
201 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10
203 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 100000
205 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10
207 #error "System time resolution must be calculated!"