Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2 2/4] uuid: expose tt_uuid_validate method
Date: Fri, 10 Apr 2020 02:50:40 +0300	[thread overview]
Message-ID: <785c5cf951c78eabe922b545a3ee8e01b9f4fcfc.1586476073.git.sergepetrenko@tarantool.org> (raw)
In-Reply-To: <cover.1586476073.git.sergepetrenko@tarantool.org>

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)

  parent reply	other threads:[~2020-04-09 23:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 23:50 [Tarantool-patches] [PATCH v2 0/4] introduce indices over UUID Serge Petrenko
2020-04-09 23:50 ` [Tarantool-patches] [PATCH v2 1/4] refactoring: extract mpstream into a separate library Serge Petrenko
2020-04-10 16:56   ` Vladislav Shpilevoy
2020-04-11 13:12     ` Serge Petrenko
2020-04-09 23:50 ` Serge Petrenko [this message]
2020-04-09 23:50 ` [Tarantool-patches] [PATCH v2 3/4] box: add MsgPack encoding/decoding for UUID Serge Petrenko
2020-04-10 16:56   ` Vladislav Shpilevoy
2020-04-11 14:14     ` Serge Petrenko
2020-04-09 23:50 ` [Tarantool-patches] [PATCH v2 4/4] box: introduce indices by UUID Serge Petrenko
2020-04-10 16:56   ` Vladislav Shpilevoy
2020-04-11 14:14     ` Serge Petrenko
2020-04-10 12:27 ` [Tarantool-patches] [PATCH v2 0/4] introduce indices over UUID Serge Petrenko
2020-04-11 18:01 ` Vladislav Shpilevoy
2020-04-13 13:52 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=785c5cf951c78eabe922b545a3ee8e01b9f4fcfc.1586476073.git.sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 2/4] uuid: expose tt_uuid_validate method' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox