guid.h revision 7c681809344b880aae61e99b6ab74ae19945ff9e
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen#ifndef GUID_H
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen#define GUID_H
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen
767431e5084a037c4dbefdf30ebfa03c84b1f449Timo Sirainen#define GUID_128_SIZE 16
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainentypedef uint8_t guid_128_t[GUID_128_SIZE];
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen#define GUID_128_HOST_HASH_SIZE 4
97437f768d1a3e6134fed1971202803fd250eef2Timo Sirainen
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo SirainenARRAY_DEFINE_TYPE(guid_128_t, guid_128_t);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenenum uuid_format {
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen FORMAT_RECORD,
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen FORMAT_COMPACT,
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen FORMAT_MICROSOFT,
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen};
e09c7dc961cb9cab04ec7cc79215c2f6318fbde0Timo Sirainen/* Generate a GUID (contains host name) */
23878bd03d1de531e3261a25598beec621351910Timo Sirainenconst char *guid_generate(void);
23878bd03d1de531e3261a25598beec621351910Timo Sirainen/* Generate 128 bit GUID */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenvoid guid_128_generate(guid_128_t guid_r);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Returns TRUE if GUID is empty (not set / unknown). */
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainenbool guid_128_is_empty(const guid_128_t guid) ATTR_PURE;
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainenstatic inline void guid_128_empty(guid_128_t guid)
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen{
cf63dc8723b971cc80638fccbf494d961cbafc7fTimo Sirainen memset(guid, 0, GUID_128_SIZE);
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen}
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Returns TRUE if two GUIDs are equal. */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenbool guid_128_equals(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Copy GUID */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenstatic inline void guid_128_copy(guid_128_t dest, const guid_128_t src)
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen{
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen memcpy(dest, src, GUID_128_SIZE);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen}
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Returns GUID as a hex string. */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenconst char *guid_128_to_string(const guid_128_t guid);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Parse GUID from a string. Returns 0 if ok, -1 if GUID isn't valid. */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenint guid_128_from_string(const char *str, guid_128_t guid_r);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Returns GUID as a UUID hex string. */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenconst char *guid_128_to_uuid_string(const guid_128_t guid, enum uuid_format format);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* Parse GUID from a UUID string. Returns 0 if ok, -1 if UIID isn't valid. */
7358272563d8ef77366447708ab0e58c0cff4151Timo Sirainenint guid_128_from_uuid_string(const char *str, guid_128_t guid_r);
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen/* guid_128 hash/cmp functions for hash.h */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenunsigned int guid_128_hash(const guid_128_t guid) ATTR_PURE;
7358272563d8ef77366447708ab0e58c0cff4151Timo Sirainenint guid_128_cmp(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
7358272563d8ef77366447708ab0e58c0cff4151Timo Sirainen
97437f768d1a3e6134fed1971202803fd250eef2Timo Sirainen/* Return the hash of host used by guid_128_generate(). */
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainenvoid guid_128_host_hash_get(const char *host,
1db62753d9e3b5d71018889c8ef0a3722a307455Timo Sirainen unsigned char hash_r[STATIC_ARRAY GUID_128_HOST_HASH_SIZE]);
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen
23878bd03d1de531e3261a25598beec621351910Timo Sirainen#endif
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen