On 08/31/2012 04:10 AM, Osier Yang wrote: > Validates the wwn while parsing, error out if it's malformed. > > * src/util/util.h: Declare virValidateWWN > * src/util/util.c: Implement virValidateWWN > * src/libvirt_private.syms: Export virValidateWWN. > * src/conf/domain_conf.h: New member 'wwn' for disk def. > * src/conf/domain_conf.c: Parse and format disk <wwn> > +#define WWN_REG_PATTERN "[0-9a-zA-Z]{16}" > +bool > +virValidateWWN(const char *wwn) { > + regex_t re; > + int err; > + char error[100]; > + > + if ((err = regcomp(&re, WWN_REG_PATTERN, REG_EXTENDED)) != 0) Do we really need regcomp() for this? I'm thinking it's much faster to just do something like: for (i = 0; wwn[i]; i++) if (!c_isxdigit(wwn[i])) break; if (i != 16 || wwn[i]) // error, return false; return true; -- -- Eric Blake eblake@xxxxxxxxxx +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list