guid.h revision 40ac30b9267c710f5fcdd4b2f6bcd7718a631843
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef GUID_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define GUID_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
18398a5d21c88cbb34c601c6b6c1f9dea502e1caTimo Sirainen#define GUID_128_SIZE 16
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef uint8_t guid_128_t[GUID_128_SIZE];
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
cc833a7a4e2258afdc834ace4bfe6579820a1df3Timo Sirainen#define GUID_128_HOST_HASH_SIZE 4
cc833a7a4e2258afdc834ace4bfe6579820a1df3Timo Sirainen
cc833a7a4e2258afdc834ace4bfe6579820a1df3Timo Sirainen/* Generate a GUID (contains host name) */
cc833a7a4e2258afdc834ace4bfe6579820a1df3Timo Sirainenconst char *guid_generate(void);
cc833a7a4e2258afdc834ace4bfe6579820a1df3Timo Sirainen/* Generate 128 bit GUID */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainenvoid guid_128_generate(guid_128_t guid_r);
366eb7178f2c90d97134e0c2d1958f93fcdaba12Timo Sirainen/* Returns TRUE if GUID is empty (not set / unknown). */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainenbool guid_128_is_empty(const guid_128_t guid);
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen/* Returns TRUE if two GUIDs are equal. */
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenbool guid_128_equals(const guid_128_t guid1, const guid_128_t guid2);
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainen
471e447023ab73a73f0f78da2afc0c55905330ddTimo Sirainen/* Returns GUID as a hex string. */
471e447023ab73a73f0f78da2afc0c55905330ddTimo Sirainenconst char *guid_128_to_string(const guid_128_t guid);
471e447023ab73a73f0f78da2afc0c55905330ddTimo Sirainen/* Parse GUID from a string. Returns 0 if ok, -1 if GUID isn't valid. */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainenint guid_128_from_string(const char *str, guid_128_t guid_r);
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* guid_128 hash/cmp functions for hash.h */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenunsigned int guid_128_hash(const uint8_t *guid);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint guid_128_cmp(const uint8_t *guid1, const uint8_t *guid2);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainen/* Return the hash of host used by guid_128_generate(). */
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainenvoid guid_128_host_hash_get(const char *host,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned char hash_r[GUID_128_HOST_HASH_SIZE]);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#endif
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen