From 5f9fe8304f037f91fa765e64580a7119aeb201dd Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 30 Oct 2003 23:43:18 +0000 Subject: [PATCH] Add string to uuid fn. Thanks aliguori. --- source/lib/util_uuid.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/source/lib/util_uuid.c b/source/lib/util_uuid.c index fe8595c8cbe..4c35236c902 100644 --- a/source/lib/util_uuid.c +++ b/source/lib/util_uuid.c @@ -2,7 +2,7 @@ * Unix SMB/CIFS implementation. * UUID server routines * Copyright (C) Theodore Ts'o 1996, 1997, - * Copyright (C) Jim McDonough 2002. + * Copyright (C) Jim McDonough 2002, 2003 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -89,3 +89,86 @@ const char *smb_uuid_string_static(const struct uuid uu) uu.node[3], uu.node[4], uu.node[5]); return out; } + +BOOL smb_string_to_uuid(const char *in, struct uuid* uu) +{ + BOOL ret = False; + const char *ptr = in; + char *end = (char *)in; + int i; + + if (!in || !uu) goto out; + + uu->time_low = strtoul(ptr, &end, 16); + if ((end - ptr) != 8 || *end != '-') goto out; + ptr = (end + 1); + + uu->time_mid = strtoul(ptr, &end, 16); + if ((end - ptr) != 4 || *end != '-') goto out; + ptr = (end + 1); + + uu->time_hi_and_version = strtoul(ptr, &end, 16); + if ((end - ptr) != 4 || *end != '-') goto out; + ptr = (end + 1); + + for (i = 0; i < 2; i++) { + int adj = 0; + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->clock_seq[i] = (*ptr - adj) << 4; + ptr++; + + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->clock_seq[i] |= (*ptr - adj); + ptr++; + } + + if (*ptr != '-') goto out; + ptr++; + + for (i = 0; i < 6; i++) { + int adj = 0; + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->node[i] = (*ptr - adj) << 4; + ptr++; + + if (*ptr >= '0' && *ptr <= '9') { + adj = '0'; + } else if (*ptr >= 'a' && *ptr <= 'f') { + adj = 'a'; + } else if (*ptr >= 'A' && *ptr <= 'F') { + adj = 'A'; + } else { + goto out; + } + uu->node[i] |= (*ptr - adj); + ptr++; + } + + ret = True; +out: + return ret; +} -- 2.11.4.GIT