uuid.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012, Digium, Inc.
  5. *
  6. * Mark Michelson <mmmichelson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Universally unique identifier support
  20. */
  21. #ifndef _ASTERISK_UUID_H
  22. #define _ASTERISK_UUID_H
  23. /* Size of an RFC 4122 UUID string plus terminating null byte */
  24. #define AST_UUID_STR_LEN (36 + 1)
  25. struct ast_uuid;
  26. /*!
  27. * \brief Initialize the UUID system
  28. */
  29. void ast_uuid_init(void);
  30. /*!
  31. * \brief Generate a UUID
  32. *
  33. * This function allocates memory on the heap. The returned
  34. * pointer must be freed using ast_free()
  35. *
  36. * \retval NULL Generation failed
  37. * \retval non-NULL heap-allocated UUID
  38. */
  39. struct ast_uuid *ast_uuid_generate(void);
  40. /*!
  41. * \brief Convert a UUID to a string
  42. *
  43. * \param uuid The UUID to convert to a string
  44. * \param[out] buf The buffer where the UUID string will be stored
  45. * \param size The size of the buffer. Must be at least AST_UUID_STR_LEN.
  46. * \return The UUID string (a pointer to buf)
  47. */
  48. char *ast_uuid_to_str(struct ast_uuid *uuid, char *buf, size_t size);
  49. /*!
  50. * \brief Generate a UUID string.
  51. * \since 12.0.0
  52. *
  53. * \param buf The buffer where the UUID string will be stored
  54. * \param size The size of the buffer. Must be at least AST_UUID_STR_LEN.
  55. *
  56. * \return The UUID string (a pointer to buf)
  57. */
  58. char *ast_uuid_generate_str(char *buf, size_t size);
  59. /*!
  60. * \brief Convert a string to a UUID
  61. *
  62. * This function allocates memory on the heap. The returned
  63. * pointer must be freed using ast_free()
  64. *
  65. * \param str The string to convert to a UUID
  66. * \retval NULL Failed to convert
  67. * \retval non-NULL The heap-allocated converted UUID
  68. */
  69. struct ast_uuid *ast_str_to_uuid(char *str);
  70. /*!
  71. * \brief Make a copy of a UUID
  72. *
  73. * This function allocates memory on the heap. The returned
  74. * pointer must be freed using ast_free()
  75. *
  76. * \param src The source UUID to copy
  77. * \retval NULL Failed to copy
  78. * \retval non-NULL The heap-allocated duplicate UUID
  79. */
  80. struct ast_uuid *ast_uuid_copy(struct ast_uuid *src);
  81. /*!
  82. * \brief Compare two UUIDs
  83. *
  84. * \param left First UUID to compare
  85. * \param right Second UUID to compare
  86. * \retval <0 left is lexicographically less than right
  87. * \retval 0 left and right are the same
  88. * \retval >0 left is lexicographically greater than right
  89. */
  90. int ast_uuid_compare(struct ast_uuid *left, struct ast_uuid *right);
  91. /*!
  92. * \brief Clear a UUID by setting it to be a nil UUID (all 0s)
  93. *
  94. * \param uuid UUID to clear
  95. */
  96. void ast_uuid_clear(struct ast_uuid *uuid);
  97. /*!
  98. * \brief Check if a UUID is a nil UUID (all 0s)
  99. *
  100. * \param uuid UUID to check
  101. * \retval 0 The UUID is not nil
  102. * \retval non-zero The UUID is nil
  103. */
  104. int ast_uuid_is_nil(struct ast_uuid *uuid);
  105. #endif