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