uuid.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* uuid.h - interface to uuid layer. UUID is generated in accordance
  13. with UUIDs and GUIDs IETF draft
  14. */
  15. /*
  16. ** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
  17. ** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
  18. ** Digital Equipment Corporation, Maynard, Mass.
  19. ** Copyright (c) 1998 Microsoft.
  20. ** To anyone who acknowledges that this file is provided "AS IS"
  21. ** without any express or implied warranty: permission to use, copy,
  22. ** modify, and distribute this file for any purpose is hereby
  23. ** granted without fee, provided that the above copyright notices and
  24. ** this notice appears in all source code copies, and that none of
  25. ** the names of Open Software Foundation, Inc., Hewlett-Packard
  26. ** Company, or Digital Equipment Corporation be used in advertising
  27. ** or publicity pertaining to distribution of the software without
  28. ** specific, written prior permission. Neither Open Software
  29. ** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital Equipment
  30. ** Corporation makes any representations about the suitability of
  31. ** this software for any purpose.
  32. */
  33. #ifndef UUID_H
  34. #define UUID_H
  35. /* Set this to what your compiler uses for 64 bit data type */
  36. #define unsigned64_t unsigned long long
  37. #define I64(C) C##LL
  38. /***** uuid related data types *****/
  39. /*
  40. * DBDB These types were broken on 64-bit architectures
  41. * This file has been modified to fix that problem.
  42. */
  43. #if defined(__LP64__) || defined (_LP64)
  44. typedef unsigned int unsigned32;
  45. #else
  46. typedef unsigned long unsigned32;
  47. #endif
  48. typedef unsigned short unsigned16;
  49. typedef unsigned char unsigned8;
  50. typedef unsigned64_t uuid_time_t;
  51. typedef struct
  52. {
  53. char nodeID[6];
  54. } uuid_node_t;
  55. typedef struct _guid_t
  56. {
  57. unsigned32 time_low;
  58. unsigned16 time_mid;
  59. unsigned16 time_hi_and_version;
  60. unsigned8 clock_seq_hi_and_reserved;
  61. unsigned8 clock_seq_low;
  62. PRUint8 node[6];
  63. } guid_t;
  64. enum
  65. {
  66. UUID_SUCCESS, /* operation succeded */
  67. UUID_IO_ERROR, /* file I/O failed */
  68. UUID_LOCK_ERROR, /* lock creation failed */
  69. UUID_TIME_ERROR, /* ran out of time sequence numbers, need
  70. time update to generate the id */
  71. UUID_BAD_FORMAT, /* data in a string buffer is not in UUID format */
  72. UUID_MEMORY_ERROR, /* memory allocation failed */
  73. UUID_LDAP_ERROR, /* LDAP operation failed */
  74. UUID_NOTFOUND, /* generator state is missing */
  75. UUID_FORMAT_ERROR, /* state entry does not contain right data */
  76. UUID_UNKNOWN_ERROR
  77. };
  78. /***** uuid interface *****/
  79. /* uuid_init -- initialize uuid layer */
  80. int uuid_init (const char *configDir, const Slapi_DN *configDN, PRBool mtGen);
  81. /* uuid_cleanup -- cleanup of uuid layer */
  82. void uuid_cleanup ();
  83. /* uuid_create -- generate a UUID */
  84. int uuid_create(guid_t *uuid);
  85. /* uuid_compare -- Compare two UUID's "lexically" and return
  86. -1 u1 is lexically before u2
  87. 0 u1 is equal to u2
  88. 1 u1 is lexically after u2
  89. Note: lexical ordering is not temporal ordering!
  90. */
  91. int uuid_compare(const guid_t *u1, const guid_t *u2);
  92. /* uuid_format -- converts UUID to its string representation and stores it
  93. in the buff. buff must be at list 40 bytes long
  94. */
  95. void uuid_format(const guid_t *u, char *buff);
  96. /* uuid_create_from_name -- create a UUID using a "name" from a "name space" */
  97. void uuid_create_from_name(guid_t * uuid, /* resulting UUID */
  98. const guid_t nsid, /* UUID to serve as context, so identical
  99. names from different name spaces generate
  100. different UUIDs */
  101. const void * name, /* the name from which to generate a UUID */
  102. int namelen); /* the length of the name */
  103. #endif