| 1 | /* |
| 2 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to |
| 6 | * deal in the Software without restriction, including without limitation the |
| 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 | * sell copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 | * IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef LTTNG_UUID_H |
| 24 | #define LTTNG_UUID_H |
| 25 | |
| 26 | #include <common/macros.h> |
| 27 | #include <stdbool.h> |
| 28 | #include <stdint.h> |
| 29 | #include <inttypes.h> |
| 30 | |
| 31 | /* |
| 32 | * Includes final \0. |
| 33 | */ |
| 34 | #define LTTNG_UUID_STR_LEN 37 |
| 35 | #define LTTNG_UUID_LEN 16 |
| 36 | #define LTTNG_UUID_VER 4 |
| 37 | |
| 38 | #define LTTNG_UUID_FMT \ |
| 39 | "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 \ |
| 40 | "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 \ |
| 41 | "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 \ |
| 42 | "%02" SCNx8 |
| 43 | |
| 44 | #define LTTNG_UUID_FMT_VALUES(uuid) \ |
| 45 | (uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], \ |
| 46 | (uuid)[6], (uuid)[7], (uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], \ |
| 47 | (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15] |
| 48 | |
| 49 | #define LTTNG_UUID_SCAN_VALUES(uuid) \ |
| 50 | &(uuid)[0], &(uuid)[1], &(uuid)[2], &(uuid)[3], &(uuid)[4], &(uuid)[5], \ |
| 51 | &(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \ |
| 52 | &(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15] |
| 53 | |
| 54 | typedef uint8_t lttng_uuid[LTTNG_UUID_LEN]; |
| 55 | |
| 56 | LTTNG_HIDDEN |
| 57 | int lttng_uuid_from_str(const char *str_in, lttng_uuid uuid_out); |
| 58 | |
| 59 | /* |
| 60 | * Convert a UUID to a human-readable, NULL-terminated, string of the form |
| 61 | * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. |
| 62 | * |
| 63 | * Assumes uuid_str is at least LTTNG_UUID_STR_LEN byte long. |
| 64 | */ |
| 65 | LTTNG_HIDDEN |
| 66 | void lttng_uuid_to_str(const lttng_uuid uuid, char *uuid_str); |
| 67 | |
| 68 | LTTNG_HIDDEN |
| 69 | bool lttng_uuid_is_equal(const lttng_uuid a, const lttng_uuid b); |
| 70 | |
| 71 | LTTNG_HIDDEN |
| 72 | bool lttng_uuid_is_nil(const lttng_uuid uuid); |
| 73 | |
| 74 | LTTNG_HIDDEN |
| 75 | void lttng_uuid_copy(lttng_uuid dst, const lttng_uuid src); |
| 76 | |
| 77 | /* |
| 78 | * Generate a random UUID according to RFC4122, section 4.4. |
| 79 | */ |
| 80 | LTTNG_HIDDEN |
| 81 | int lttng_uuid_generate(lttng_uuid uuid_out); |
| 82 | |
| 83 | #endif /* LTTNG_UUID_H */ |