guid.h revision 33750ba29b605a925af5aed58d3f3735422b1e25
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen#ifndef GUID_H
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen#define GUID_H
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen#define GUID_128_SIZE 16
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainentypedef uint8_t guid_128_t[GUID_128_SIZE];
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen#define GUID_128_HOST_HASH_SIZE 4
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Generate a GUID (contains host name) */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenconst char *guid_generate(void);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Generate 128 bit GUID */
e4d34f2fbee451219599d71505594df704093ce3Timo Sirainenvoid guid_128_generate(guid_128_t guid_r);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Returns TRUE if GUID is empty (not set / unknown). */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenbool guid_128_is_empty(const guid_128_t guid) ATTR_PURE;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenstatic inline void guid_128_empty(guid_128_t guid)
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen{
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen memset(guid, 0, GUID_128_SIZE);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen}
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Returns TRUE if two GUIDs are equal. */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenbool guid_128_equals(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Copy GUID */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenstatic inline void guid_128_copy(guid_128_t dest, const guid_128_t src)
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen{
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen memcpy(dest, src, GUID_128_SIZE);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen}
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Returns GUID as a hex string. */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenconst char *guid_128_to_string(const guid_128_t guid);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* Parse GUID from a string. Returns 0 if ok, -1 if GUID isn't valid. */
31e7be5e1d41a77f08d26cef46aba1df24b3f1baTimo Sirainenint guid_128_from_string(const char *str, guid_128_t guid_r);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen/* guid_128 hash/cmp functions for hash.h */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenunsigned int guid_128_hash(const guid_128_t guid) ATTR_PURE;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenint guid_128_cmp(const guid_128_t guid1, const guid_128_t guid2) ATTR_PURE;
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen/* Return the hash of host used by guid_128_generate(). */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenvoid guid_128_host_hash_get(const char *host,
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen unsigned char hash_r[GUID_128_HOST_HASH_SIZE]);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen#endif
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen