diff --git a/ChangeLog b/ChangeLog index 8da05d42df962b5a8f31748da1387a5b47bb83ed..23941691a2e0de52ef257dcd3faef8ec31817385 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Aug 16 11:36:21 EDT 2006 Daniel Berrange + + * 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 * src/libvirt.c: Remove some duplicated changes for VIR_DOMAIN_RO diff --git a/src/xend_internal.c b/src/xend_internal.c index f0fbc568b0129bf67994dc6c5235db08f39c59f9..b847d5269096e6f470997b0080c358c2cad31166 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -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); } diff --git a/src/xml.c b/src/xml.c index 8bae273009b937f913d2c32a30b353561f936222..145975227eb87fa9f06eaf8997e3c4e074b3f5ee 100644 --- a/src/xml.c +++ b/src/xml.c @@ -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; +} diff --git a/src/xml.h b/src/xml.h index bda52411c9aa4bca19605978d97ccd8e8efe215d..78e086c014f4ad879599e19ded544298af6a6f9b 100644 --- a/src/xml.h +++ b/src/xml.h @@ -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 }