1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _RTL_UUID_H_ 28 #define _RTL_UUID_H_ 29 30 31 #include <sal/types.h> 32 #include <rtl/string.h> 33 34 /** 35 @HTML 36 @file 37 Specification (from draft-leach-uuids-guids-01.txt ) 38 39 <p> 40 A UUID is an identifier that is unique across both space and time, 41 with respect to the space of all UUIDs. To be precise, the UUID 42 consists of a finite bit space. Thus, collision cannot be avoided in 43 principle. A UUID can be used for multiple purposes, from tagging objects 44 with an extremely short lifetime, to reliably identifying very persistent 45 objects across a network. 46 47 <p> 48 The generation of UUIDs does not require that a registration 49 authority be contacted for each identifier. Instead, Version 4 UUIDs are 50 generated from (pseudo unique) sequences of (pseudo) random bits. 51 */ 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 /** Generates a new Version 4 (random number based) UUID (Universally Unique 58 IDentifier). 59 60 @param pTargetUUID pointer to at least 16 bytes of memory. After the call it contains 61 the newly generated uuid in network byte order. 62 @param pPredecessorUUID ignored (was used when this function returned 63 Version 1 instead of Version 4 UUIDs). 64 @param bUseEthernetAddress ignored (was used when this function returned 65 Version 1 instead of Version 4 UUIDs). 66 */ 67 void SAL_CALL rtl_createUuid( sal_uInt8 *pTargetUUID , 68 const sal_uInt8 *pPredecessorUUID, 69 sal_Bool bUseEthernetAddress ); 70 71 /** Compare two UUID's lexically 72 73 <p> 74 Note: lexical ordering is not temporal ordering! 75 <p> 76 Note: For equalnesschecking, a memcmp(pUUID1,pUUID2,16) is more efficient 77 78 @return 79 <ul> 80 <li>-1 u1 is lexically before u2 81 <li>0 u1 is equal to u2 82 <li>1 u1 is lexically after u2 83 </ul> 84 85 */ 86 sal_Int32 SAL_CALL rtl_compareUuid( const sal_uInt8 *pUUID1 , const sal_uInt8 *pUUID2 ); 87 88 /** Creates named UUIDs. 89 90 <p> 91 The version 3 UUID is meant for generating UUIDs from <em>names</em> that 92 are drawn from, and unique within, some <em>name space</em>. Some examples 93 of names (and, implicitly, name spaces) might be DNS names, URLs, ISO 94 Object IDs (OIDs), reserved words in a programming language, or X.500 95 Distinguished Names (DNs); thus, the concept of name and name space 96 should be broadly construed, and not limited to textual names. 97 98 <p> 99 The requirements for such UUIDs are as follows: 100 101 <ul> 102 <li> The UUIDs generated at different times from the same name in the 103 same namespace MUST be equal 104 105 <li> The UUIDs generated from two different names in the same namespace 106 should be different (with very high probability) 107 108 <li> The UUIDs generated from the same name in two different namespaces 109 should be different with (very high probability) 110 111 <li> If two UUIDs that were generated from names are equal, then they 112 were generated from the same name in the same namespace (with very 113 high probability). 114 </ul> 115 116 @param pTargetUUID pointer to at least 16 bytes of memory. After the call 117 it contains the newly generated uuid in network byte order. 118 @param pNameSpaceUUID The namespace uuid. Below are some predefined ones, 119 but any arbitray uuid can be used as namespace. 120 121 @param pName the name 122 */ 123 void SAL_CALL rtl_createNamedUuid( 124 sal_uInt8 *pTargetUUID, 125 const sal_uInt8 *pNameSpaceUUID, 126 const rtl_String *pName 127 ); 128 129 130 131 /* 132 Predefined Namespaces 133 (Use them the following way : sal_uInt8 aNsDNS[16]) = RTL_UUID_NAMESPACE_DNS; 134 */ 135 /** namesapce DNS 136 137 <p> 138 (Use them the following way : sal_uInt8 aNsDNS[16]) = RTL_UUID_NAMESPACE_DNS; 139 <p> 140 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */ 141 #define RTL_UUID_NAMESPACE_DNS {\ 142 0x6b,0xa7,0xb8,0x10,\ 143 0x9d,0xad,\ 144 0x11,0xd1,\ 145 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\ 146 } 147 148 /** namespace URL 149 150 <p> 151 6ba7b811-9dad-11d1-80b4-00c04fd430c8 */ 152 #define RTL_UUID_NAMESPACE_URL { \ 153 0x6b, 0xa7, 0xb8, 0x11,\ 154 0x9d, 0xad,\ 155 0x11, 0xd1,\ 156 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\ 157 } 158 159 /** namespace oid 160 161 <p> 162 6ba7b812-9dad-11d1-80b4-00c04fd430c8 */ 163 #define RTL_UUID_NAMESPACE_OID {\ 164 0x6b, 0xa7, 0xb8, 0x12,\ 165 0x9d, 0xad,\ 166 0x11, 0xd1,\ 167 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\ 168 } 169 170 /** namespace X500 171 172 <p> 173 6ba7b814-9dad-11d1-80b4-00c04fd430c8 */ 174 #define RTL_UUID_NAMESPACE_X500 {\ 175 0x6b, 0xa7, 0xb8, 0x14,\ 176 0x9d, 0xad,\ 177 0x11, 0xd1,\ 178 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8\ 179 } 180 181 182 /* 183 This macro must have a value below the system time resolution of the 184 system. The uuid routines use this value as an upper limit for adding ticks to the 185 the predecessor time value if system times are equal. 186 */ 187 #ifdef SAL_W32 188 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 1000 189 #elif defined SAL_OS2 // YD we use posix functions for time 190 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10 191 #elif LINUX 192 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10 193 #elif NETBSD 194 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10 195 #elif FREEBSD 196 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10 197 #elif SOLARIS 198 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 10 199 #elif MACOSX 200 #define UUID_SYSTEM_TIME_RESOLUTION_100NS_TICKS 100000 201 #else 202 #error "System time resolution must be calculated!" 203 #endif 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 #endif 210