guid.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJ_GUID_H__
  20. #define __PJ_GUID_H__
  21. /**
  22. * @file guid.h
  23. * @brief GUID Globally Unique Identifier.
  24. */
  25. #include <pj/types.h>
  26. PJ_BEGIN_DECL
  27. /**
  28. * @defgroup PJ_DS Data Structure.
  29. */
  30. /**
  31. * @defgroup PJ_GUID Globally Unique Identifier
  32. * @ingroup PJ_DS
  33. * @{
  34. *
  35. * This module provides API to create string that is globally unique.
  36. * If application doesn't require that strong requirement, it can just
  37. * use #pj_create_random_string() instead.
  38. */
  39. /**
  40. * PJ_GUID_STRING_LENGTH specifies length of GUID string. The value is
  41. * dependent on the algorithm used internally to generate the GUID string.
  42. * If real GUID generator is used, then the length will be between 32 and
  43. * 36 bytes. Application should not assume which algorithm will
  44. * be used by GUID generator.
  45. *
  46. * Regardless of the actual length of the GUID, it will not exceed
  47. * PJ_GUID_MAX_LENGTH characters.
  48. *
  49. * @see pj_GUID_STRING_LENGTH()
  50. * @see PJ_GUID_MAX_LENGTH
  51. */
  52. PJ_DECL_DATA(const unsigned) PJ_GUID_STRING_LENGTH;
  53. /**
  54. * Get #PJ_GUID_STRING_LENGTH constant.
  55. */
  56. PJ_DECL(unsigned) pj_GUID_STRING_LENGTH(void);
  57. /**
  58. * PJ_GUID_MAX_LENGTH specifies the maximum length of GUID string,
  59. * regardless of which algorithm to use.
  60. */
  61. #define PJ_GUID_MAX_LENGTH 36
  62. /**
  63. * Create a globally unique string, which length is PJ_GUID_STRING_LENGTH
  64. * characters. Caller is responsible for preallocating the storage used
  65. * in the string.
  66. *
  67. * @param str The string to store the result.
  68. *
  69. * @return The string.
  70. */
  71. PJ_DECL(pj_str_t*) pj_generate_unique_string(pj_str_t *str);
  72. /**
  73. * Create a globally unique string in lowercase, which length is
  74. * PJ_GUID_STRING_LENGTH characters. Caller is responsible for preallocating
  75. * the storage used in the string.
  76. *
  77. * @param str The string to store the result.
  78. *
  79. * @return The string.
  80. */
  81. PJ_DECL(pj_str_t*) pj_generate_unique_string_lower(pj_str_t *str);
  82. /**
  83. * Generate a unique string.
  84. *
  85. * @param pool Pool to allocate memory from.
  86. * @param str The string.
  87. */
  88. PJ_DECL(void) pj_create_unique_string(pj_pool_t *pool, pj_str_t *str);
  89. /**
  90. * Generate a unique string in lowercase.
  91. *
  92. * @param pool Pool to allocate memory from.
  93. * @param str The string.
  94. */
  95. PJ_DECL(void) pj_create_unique_string_lower(pj_pool_t *pool, pj_str_t *str);
  96. /**
  97. * @}
  98. */
  99. PJ_END_DECL
  100. #endif/* __PJ_GUID_H__ */