[Tarantool-patches] [PATCH v2 2/4] uuid: expose tt_uuid_validate method

Serge Petrenko sergepetrenko at tarantool.org
Fri Apr 10 02:50:40 MSK 2020


Expose the code used to check UUID variant to a separate function:
tt_uuid_validate(). The function will be used for msgpack uuid decoding
when checking whether the buffer contains a valid uuid value.

Prerequisite #4268
---
 src/lib/uuid/tt_uuid.c |  3 +++
 src/lib/uuid/tt_uuid.h | 16 +++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/lib/uuid/tt_uuid.c b/src/lib/uuid/tt_uuid.c
index 1bd2e2cfe..8bc9bc7af 100644
--- a/src/lib/uuid/tt_uuid.c
+++ b/src/lib/uuid/tt_uuid.c
@@ -65,6 +65,9 @@ tt_uuid_create(struct tt_uuid *uu)
 }
 #endif
 
+extern inline int
+tt_uuid_validate(struct tt_uuid *uu);
+
 extern inline int
 tt_uuid_from_string(const char *in, struct tt_uuid *uu);
 
diff --git a/src/lib/uuid/tt_uuid.h b/src/lib/uuid/tt_uuid.h
index 48cd68e69..c2c436ed4 100644
--- a/src/lib/uuid/tt_uuid.h
+++ b/src/lib/uuid/tt_uuid.h
@@ -62,6 +62,16 @@ struct tt_uuid {
 void
 tt_uuid_create(struct tt_uuid *uu);
 
+inline int
+tt_uuid_validate(struct tt_uuid *uu)
+{
+	/* Check variant (NCS, RFC4122, MSFT) */
+	uint8_t n = uu->clock_seq_hi_and_reserved;
+	if ((n & 0x80) != 0x00 && (n & 0xc0) != 0x80 &&	(n & 0xe0) != 0xc0)
+		return 1;
+	return 0;
+}
+
 /**
  * \brief Parse UUID from string.
  * \param in string
@@ -79,11 +89,7 @@ tt_uuid_from_string(const char *in, struct tt_uuid *uu)
 		   &uu->node[4], &uu->node[5]) != 11)
 		return 1;
 
-	/* Check variant (NCS, RFC4122, MSFT) */
-	uint8_t n = uu->clock_seq_hi_and_reserved;
-	if ((n & 0x80) != 0x00 && (n & 0xc0) != 0x80 &&	(n & 0xe0) != 0xc0)
-		return 1;
-	return 0;
+	return tt_uuid_validate(uu);
 }
 
 /**
-- 
2.21.1 (Apple Git-122.3)



More information about the Tarantool-patches mailing list