mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
Re-factored sexpr_uuid into virParseUUID
This commit is contained in:
parent
bfd5060347
commit
64d25e8de5
@ -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>
|
Wed Aug 16 11:31:59 EDT 2006 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/libvirt.c: Remove some duplicated changes for VIR_DOMAIN_RO
|
* src/libvirt.c: Remove some duplicated changes for VIR_DOMAIN_RO
|
||||||
|
@ -780,62 +780,7 @@ static unsigned char *
|
|||||||
sexpr_uuid(char **ptr, struct sexpr *node, const char *path)
|
sexpr_uuid(char **ptr, struct sexpr *node, const char *path)
|
||||||
{
|
{
|
||||||
const char *r = sexpr_node(node, path);
|
const char *r = sexpr_node(node, path);
|
||||||
int uuid[16];
|
return virParseUUID(ptr, r);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
61
src/xml.c
61
src/xml.c
@ -1249,3 +1249,64 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !PROXY */
|
#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;
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ int virBufferAdd(virBufferPtr buf, const char *str, int len);
|
|||||||
int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
|
int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
|
||||||
int virBufferStrcat(virBufferPtr buf, ...);
|
int virBufferStrcat(virBufferPtr buf, ...);
|
||||||
char *virDomainParseXMLDesc(const char *xmldesc, char **name);
|
char *virDomainParseXMLDesc(const char *xmldesc, char **name);
|
||||||
|
unsigned char *virParseUUID(char **ptr, const char *uuid);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user