de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#ifndef GUID_H
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#define GUID_H
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#define GUID_128_SIZE 16
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainentypedef uint8_t guid_128_t[GUID_128_SIZE];
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen#define GUID_128_HOST_HASH_SIZE 4
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen
fea53234804e75bb8f0b87ab0a0b1cc1c9770031Timo SirainenARRAY_DEFINE_TYPE(guid_128_t, guid_128_t);
fea53234804e75bb8f0b87ab0a0b1cc1c9770031Timo Sirainen
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomienum uuid_format {
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi FORMAT_RECORD,
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi FORMAT_COMPACT,
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi FORMAT_MICROSOFT,
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi};
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* Generate a GUID (contains host name) */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenconst char *guid_generate(void);
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* Generate 128 bit GUID */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenvoid guid_128_generate(guid_128_t guid_r);
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* Returns TRUE if GUID is empty (not set / unknown). */
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodybool guid_128_is_empty(const guid_128_t guid) ATTR_PURE;
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmodystatic inline void guid_128_empty(guid_128_t guid)
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmody{
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmody memset(guid, 0, GUID_128_SIZE);
33750ba29b605a925af5aed58d3f3735422b1e25Phil Carmody}
40ac30b9267c710f5fcdd4b2f6bcd7718a631843Timo Sirainen/* Returns TRUE if two GUIDs are equal. */
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodybool guid_128_equals(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainen/* Copy GUID */
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainenstatic inline void guid_128_copy(guid_128_t dest, const guid_128_t src)
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainen{
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainen memcpy(dest, src, GUID_128_SIZE);
8562f8de469e87ad4104747cebec6b133fa3a0f5Timo Sirainen}
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* Returns GUID as a hex string. */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenconst char *guid_128_to_string(const guid_128_t guid);
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* Parse GUID from a string. Returns 0 if ok, -1 if GUID isn't valid. */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainenint guid_128_from_string(const char *str, guid_128_t guid_r);
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi/* Returns GUID as a UUID hex string. */
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomiconst char *guid_128_to_uuid_string(const guid_128_t guid, enum uuid_format format);
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi/* Parse GUID from a UUID string. Returns 0 if ok, -1 if UIID isn't valid. */
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomiint guid_128_from_uuid_string(const char *str, guid_128_t guid_r);
7c681809344b880aae61e99b6ab74ae19945ff9eAki Tuomi
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen/* guid_128 hash/cmp functions for hash.h */
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodyunsigned int guid_128_hash(const guid_128_t guid) ATTR_PURE;
518781a0a4ba2403f23dbadda445b107fbb87daaPhil Carmodyint guid_128_cmp(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen/* Return the hash of host used by guid_128_generate(). */
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainenvoid guid_128_host_hash_get(const char *host,
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char hash_r[STATIC_ARRAY GUID_128_HOST_HASH_SIZE]);
af49da69a12b5383b89c7b2fa574c2a85b9ca310Timo Sirainen
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#endif