Re-factored sexpr_uuid into virParseUUID

This commit is contained in:
Daniel P. Berrange 2006-08-16 16:33:55 +00:00
parent bfd5060347
commit 64d25e8de5
4 changed files with 69 additions and 56 deletions

View File

@ -1,3 +1,9 @@
Wed Aug 16 11:36:21 EDT 2006 Daniel Berrange <berrange@redhat.com>
* src/xend_internal.c, src/xml.c, src/xml.h: Refactored the
sexpr_uuid method into a re-usable virParseUUID method which
can be used by any backend
Wed Aug 16 11:31:59 EDT 2006 Daniel Berrange <berrange@redhat.com>
* src/libvirt.c: Remove some duplicated changes for VIR_DOMAIN_RO

View File

@ -780,62 +780,7 @@ static unsigned char *
sexpr_uuid(char **ptr, struct sexpr *node, const char *path)
{
const char *r = sexpr_node(node, path);
int uuid[16];
unsigned char *dst_uuid = NULL;
int ret;
int i;
memset(uuid, 0xFF, sizeof(uuid));
if (r == NULL)
goto error;
ret = sscanf(r,
"%02x%02x%02x%02x"
"%02x%02x%02x%02x"
"%02x%02x%02x%02x"
"%02x%02x%02x%02x",
uuid + 0, uuid + 1, uuid + 2, uuid + 3,
uuid + 4, uuid + 5, uuid + 6, uuid + 7,
uuid + 8, uuid + 9, uuid + 10, uuid + 11,
uuid + 12, uuid + 13, uuid + 14, uuid + 15);
if (ret == 16)
goto done;
ret = sscanf(r,
"%02x%02x%02x%02x-"
"%02x%02x-"
"%02x%02x-"
"%02x%02x-"
"%02x%02x%02x%02x%02x%02x",
uuid + 0, uuid + 1, uuid + 2, uuid + 3,
uuid + 4, uuid + 5, uuid + 6, uuid + 7,
uuid + 8, uuid + 9, uuid + 10, uuid + 11,
uuid + 12, uuid + 13, uuid + 14, uuid + 15);
if (ret == 16)
goto done;
ret = sscanf(r,
"%02x%02x%02x%02x-"
"%02x%02x%02x%02x-"
"%02x%02x%02x%02x-"
"%02x%02x%02x%02x",
uuid + 0, uuid + 1, uuid + 2, uuid + 3,
uuid + 4, uuid + 5, uuid + 6, uuid + 7,
uuid + 8, uuid + 9, uuid + 10, uuid + 11,
uuid + 12, uuid + 13, uuid + 14, uuid + 15);
if (ret != 16)
goto error;
done:
dst_uuid = (unsigned char *) *ptr;
*ptr += 16;
for (i = 0; i < 16; i++)
dst_uuid[i] = uuid[i] & 0xFF;
error:
return dst_uuid;
return virParseUUID(ptr, r);
}

View File

@ -1249,3 +1249,64 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
}
#endif /* !PROXY */
unsigned char *virParseUUID(char **ptr, const char *uuid) {
int rawuuid[16];
unsigned char *dst_uuid = NULL;
int ret;
int i;
memset(rawuuid, 0xFF, sizeof(rawuuid));
if (uuid == NULL)
goto error;
ret = sscanf(uuid,
"%02x%02x%02x%02x"
"%02x%02x%02x%02x"
"%02x%02x%02x%02x"
"%02x%02x%02x%02x",
rawuuid + 0, rawuuid + 1, rawuuid + 2, rawuuid + 3,
rawuuid + 4, rawuuid + 5, rawuuid + 6, rawuuid + 7,
rawuuid + 8, rawuuid + 9, rawuuid + 10, rawuuid + 11,
rawuuid + 12, rawuuid + 13, rawuuid + 14, rawuuid + 15);
if (ret == 16)
goto done;
ret = sscanf(uuid,
"%02x%02x%02x%02x-"
"%02x%02x-"
"%02x%02x-"
"%02x%02x-"
"%02x%02x%02x%02x%02x%02x",
rawuuid + 0, rawuuid + 1, rawuuid + 2, rawuuid + 3,
rawuuid + 4, rawuuid + 5, rawuuid + 6, rawuuid + 7,
rawuuid + 8, rawuuid + 9, rawuuid + 10, rawuuid + 11,
rawuuid + 12, rawuuid + 13, rawuuid + 14, rawuuid + 15);
if (ret == 16)
goto done;
ret = sscanf(uuid,
"%02x%02x%02x%02x-"
"%02x%02x%02x%02x-"
"%02x%02x%02x%02x-"
"%02x%02x%02x%02x",
rawuuid + 0, rawuuid + 1, rawuuid + 2, rawuuid + 3,
rawuuid + 4, rawuuid + 5, rawuuid + 6, rawuuid + 7,
rawuuid + 8, rawuuid + 9, rawuuid + 10, rawuuid + 11,
rawuuid + 12, rawuuid + 13, rawuuid + 14, rawuuid + 15);
if (ret != 16)
goto error;
done:
dst_uuid = (unsigned char *) *ptr;
*ptr += 16;
for (i = 0; i < 16; i++)
dst_uuid[i] = rawuuid[i] & 0xFF;
error:
return dst_uuid;
}

View File

@ -30,6 +30,7 @@ int virBufferAdd(virBufferPtr buf, const char *str, int len);
int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
int virBufferStrcat(virBufferPtr buf, ...);
char *virDomainParseXMLDesc(const char *xmldesc, char **name);
unsigned char *virParseUUID(char **ptr, const char *uuid);
#ifdef __cplusplus
}