From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4F1614696C7 for ; Fri, 10 Apr 2020 02:50:57 +0300 (MSK) From: Serge Petrenko Date: Fri, 10 Apr 2020 02:50:40 +0300 Message-Id: <785c5cf951c78eabe922b545a3ee8e01b9f4fcfc.1586476073.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 2/4] uuid: expose tt_uuid_validate method List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.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)