guid.c revision af49da69a12b5383b89c7b2fa574c2a85b9ca310
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (c) 2011-2013 Dovecot authors, see the included COPYING file */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenconst char *guid_generate(void)
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen static unsigned int pid = 0;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* we'll use the current time in nanoseconds as the initial 64bit
ab530005cbeae9ea2301ef884c913e51870ea912Timo Sirainen } else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
72bc08129fb0aaec8144cc183a998ccc426fef9eTimo Sirainen unsigned char hash_r[GUID_128_HOST_HASH_SIZE])
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen sha1_get_digest(host, strlen(host), full_hash);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen memcpy(hash_r, full_hash + sizeof(full_hash)-GUID_128_HOST_HASH_SIZE,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen /* we'll use the current time in nanoseconds as the initial 64bit
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen guid_128_host_hash_get(my_hostdomain(), guid_static+4);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen } else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
ab530005cbeae9ea2301ef884c913e51870ea912Timo Sirainen unsigned int i;
ab530005cbeae9ea2301ef884c913e51870ea912Timo Sirainen for (i = 0; i < GUID_128_SIZE; i++) {
8ad7aa4ddf9e37fc1aefdf84f90071f49fc2619cTimo Sirainenint guid_128_from_string(const char *str, guid_128_t guid_r)
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen buffer_create_from_data(&buf, guid_r, GUID_128_SIZE);
7d359c1719bf6ff228a96c66d27f5cfa239cb31dTimo Sirainenconst char *guid_128_to_string(const guid_128_t guid)
7d359c1719bf6ff228a96c66d27f5cfa239cb31dTimo Sirainenunsigned int guid_128_hash(const uint8_t *guid)
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenint guid_128_cmp(const uint8_t *guid1, const uint8_t *guid2)