bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen /* we'll use the current time in nanoseconds as the initial 64bit
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen } else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
5b02d2191f2dd9da567c70b383243395ec0ce13dMartti Rannanjärvi return t_strdup_printf("%08x%08lx.%x.%s",
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char hash_r[STATIC_ARRAY GUID_128_HOST_HASH_SIZE])
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen sha1_get_digest(host, strlen(host), full_hash);
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen memcpy(hash_r, full_hash + sizeof(full_hash)-GUID_128_HOST_HASH_SIZE,
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen /* we'll use the current time in nanoseconds as the initial 64bit
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen guid_128_host_hash_get(my_hostdomain(), guid_static+4);
c1684fd2affe6159e99bc6de0fd387ce802f0ca6Timo Sirainen } else if (ioloop_timeval.tv_sec > ts.tv_sec ||
c104ea8f180db4be2b491ef5b1f2626958dce80dJosef 'Jeff' Sipek ioloop_timeval.tv_usec * 1000 > ts.tv_nsec)) {
c1684fd2affe6159e99bc6de0fd387ce802f0ca6Timo Sirainen /* use ioloop's time since we have it. it doesn't provide any
c1684fd2affe6159e99bc6de0fd387ce802f0ca6Timo Sirainen more uniqueness, but it allows finding out more reliably
c1684fd2affe6159e99bc6de0fd387ce802f0ca6Timo Sirainen when a GUID was created. */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen unsigned int i;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen for (i = 0; i < GUID_128_SIZE; i++) {
40ac30b9267c710f5fcdd4b2f6bcd7718a631843Timo Sirainenbool guid_128_equals(const guid_128_t guid1, const guid_128_t guid2)
40ac30b9267c710f5fcdd4b2f6bcd7718a631843Timo Sirainen return memcmp(guid1, guid2, GUID_128_SIZE) == 0;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint guid_128_from_string(const char *str, guid_128_t guid_r)
3281669db44d09a087a203201248abbc81b3cc1aTimo Sirainen buffer_create_from_data(&buf, guid_r, GUID_128_SIZE);
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenconst char *guid_128_to_string(const guid_128_t guid)
efaa1272c1b682bc2e105b2f374152a6a1f45825Phil Carmodyunsigned int guid_128_hash(const guid_128_t guid)
efaa1272c1b682bc2e105b2f374152a6a1f45825Phil Carmodyint guid_128_cmp(const guid_128_t guid1, const guid_128_t guid2)
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomiconst char *guid_128_to_uuid_string(const guid_128_t guid, enum uuid_format format)
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi return t_strdup_printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi return t_strdup_printf("{%s}", guid_128_to_uuid_string(guid, FORMAT_RECORD));
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomiint guid_128_from_uuid_string(const char *str, guid_128_t guid_r)
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi for(i=0; i < len; i++) {
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi /* Microsoft format */
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi /* 8-4-4-4-12 */
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi if (((i==8+m) || (i==13+m) || (i==18+m) || (i==23+m)) &&