uuid.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. /* uuid.h - interface to uuid layer. UUID is generated in accordance
  39. with UUIDs and GUIDs IETF draft
  40. */
  41. /*
  42. ** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
  43. ** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
  44. ** Digital Equipment Corporation, Maynard, Mass.
  45. ** Copyright (c) 1998 Microsoft.
  46. ** To anyone who acknowledges that this file is provided "AS IS"
  47. ** without any express or implied warranty: permission to use, copy,
  48. ** modify, and distribute this file for any purpose is hereby
  49. ** granted without fee, provided that the above copyright notices and
  50. ** this notice appears in all source code copies, and that none of
  51. ** the names of Open Software Foundation, Inc., Hewlett-Packard
  52. ** Company, or Digital Equipment Corporation be used in advertising
  53. ** or publicity pertaining to distribution of the software without
  54. ** specific, written prior permission. Neither Open Software
  55. ** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital Equipment
  56. ** Corporation makes any representations about the suitability of
  57. ** this software for any purpose.
  58. */
  59. #ifndef UUID_H
  60. #define UUID_H
  61. /* Set this to what your compiler uses for 64 bit data type */
  62. #ifdef _WIN32
  63. #define unsigned64_t unsigned __int64
  64. #define I64(C) C
  65. #else
  66. #define unsigned64_t unsigned long long
  67. #define I64(C) C##LL
  68. #endif
  69. /***** uuid related data types *****/
  70. /*
  71. * DBDB These types were broken on 64-bit architectures
  72. * This file has been modified to fix that problem.
  73. */
  74. #if defined(__LP64__) || defined (_LP64)
  75. typedef unsigned int unsigned32;
  76. #else
  77. typedef unsigned long unsigned32;
  78. #endif
  79. typedef unsigned short unsigned16;
  80. typedef unsigned char unsigned8;
  81. typedef unsigned64_t uuid_time_t;
  82. typedef struct
  83. {
  84. char nodeID[6];
  85. } uuid_node_t;
  86. typedef struct _guid_t
  87. {
  88. unsigned32 time_low;
  89. unsigned16 time_mid;
  90. unsigned16 time_hi_and_version;
  91. unsigned8 clock_seq_hi_and_reserved;
  92. unsigned8 clock_seq_low;
  93. PRUint8 node[6];
  94. } guid_t;
  95. enum
  96. {
  97. UUID_SUCCESS, /* operation succeded */
  98. UUID_IO_ERROR, /* file I/O failed */
  99. UUID_LOCK_ERROR, /* lock creation failed */
  100. UUID_TIME_ERROR, /* ran out of time sequence numbers, need
  101. time update to generate the id */
  102. UUID_BAD_FORMAT, /* data in a string buffer is not in UUID format */
  103. UUID_MEMORY_ERROR, /* memory allocation failed */
  104. UUID_LDAP_ERROR, /* LDAP operation failed */
  105. UUID_NOTFOUND, /* generator state is missing */
  106. UUID_FORMAT_ERROR, /* state entry does not contain right data */
  107. UUID_UNKNOWN_ERROR
  108. };
  109. /***** uuid interface *****/
  110. /* uuid_init -- initialize uuid layer */
  111. int uuid_init (const char *configDir, const Slapi_DN *configDN, PRBool mtGen);
  112. /* uuid_cleanup -- cleanup of uuid layer */
  113. void uuid_cleanup ();
  114. /* uuid_create -- generate a UUID */
  115. int uuid_create(guid_t *uuid);
  116. /* uuid_compare -- Compare two UUID's "lexically" and return
  117. -1 u1 is lexically before u2
  118. 0 u1 is equal to u2
  119. 1 u1 is lexically after u2
  120. Note: lexical ordering is not temporal ordering!
  121. */
  122. int uuid_compare(const guid_t *u1, const guid_t *u2);
  123. /* uuid_format -- converts UUID to its string representation and stores it
  124. in the buff. buff must be at list 40 bytes long
  125. */
  126. void uuid_format(const guid_t *u, char *buff);
  127. /* uuid_create_from_name -- create a UUID using a "name" from a "name space" */
  128. void uuid_create_from_name(guid_t * uuid, /* resulting UUID */
  129. const guid_t nsid, /* UUID to serve as context, so identical
  130. names from different name spaces generate
  131. different UUIDs */
  132. const void * name, /* the name from which to generate a UUID */
  133. int namelen); /* the length of the name */
  134. #endif