The sexpr_uuid method is used to convert from the printable representation of a UUID into the binary format (unsigned char[16]). This patch refactors the main body of the method so that it is usable by other non-XenD driver backends for parsing UUIDs. This new re-factored method will be used by a patch I'll shortly submit for the test driver backend. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Index: src/xml.c =================================================================== RCS file: /data/cvs/libvirt/src/xml.c,v retrieving revision 1.33 diff -c -r1.33 xml.c *** src/xml.c 15 Aug 2006 17:01:42 -0000 1.33 --- src/xml.c 16 Aug 2006 15:19:00 -0000 *************** *** 1249,1251 **** --- 1249,1312 ---- } #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; + } Index: src/xml.h =================================================================== RCS file: /data/cvs/libvirt/src/xml.h,v retrieving revision 1.7 diff -c -r1.7 xml.h *** src/xml.h 26 Jun 2006 15:02:19 -0000 1.7 --- src/xml.h 16 Aug 2006 15:19:00 -0000 *************** *** 30,35 **** --- 30,36 ---- 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 } Index: src/xend_internal.c =================================================================== RCS file: /data/cvs/libvirt/src/xend_internal.c,v retrieving revision 1.54 diff -c -r1.54 xend_internal.c *** src/xend_internal.c 15 Aug 2006 17:01:42 -0000 1.54 --- src/xend_internal.c 16 Aug 2006 15:19:01 -0000 *************** *** 780,841 **** 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; } --- 780,786 ---- sexpr_uuid(char **ptr, struct sexpr *node, const char *path) { const char *r = sexpr_node(node, path); ! return virParseUUID(ptr, r); } Index: src/internal.h =================================================================== RCS file: /data/cvs/libvirt/src/internal.h,v retrieving revision 1.23 diff -c -r1.23 internal.h *** src/internal.h 28 Jun 2006 18:19:13 -0000 1.23 --- src/internal.h 16 Aug 2006 15:19:01 -0000 *************** *** 189,194 **** --- 189,195 ---- virDomainPtr virGetDomainByID(virConnectPtr conn, int id); + #ifdef __cplusplus } #endif /* __cplusplus */