Re: UUID buffer lengths [was Re: Virtual networking]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 23, 2007 at 12:37:50PM +0000, Mark McLoughlin wrote:
> On Tue, 2007-01-23 at 11:20 +0100, Karel Zak wrote:
> 
> > +    char uuid[37];
> > 
> >   Magic number? :-)
> > 
> >   #define UUID_STRLEN	36
> > 
> >    char uuid[UUID_STRLEN+1];
> 
> 	Good point. Here's a proposed API addition to put the buffer lengths as
> macros in libvirt.h.
> 
> 	Anyone got objections to that?

No objections, but I think if we're going to do this, we should take it
one step further and provide APIs for converting between RAW & Printable
versions of UUID in both directions. Currently we're just duping this
conversion code all over the place - with inconsistent use of '-' in
the printable versions.


   /*
    * uuidstr: the printable UUID string
    * uuid: pre-allocated buffer of length VIR_UUID_BUFLEN
    */
   int virUUIDParseString(const char *uuidstr, unsigned char *uuid)

   /*
    * uuid: the raw UUID valu exactly VIR_UUID_BUFLEN bytes long
    * uuidstr: pre-allocated buffer of length VIR_UUID_STRING_BUFLEN 
    *          to be filled in printable UUID
    */
   int virUUIDFormatString(const unsigned char *uuid, char *uuidstr)

Oh and a thing to generate a random UUID too is needed by both the xm_internal
and qemu  & test backends

    int virUUIDGenerate(unsigned char *uuid);

Probably we only need any of this stuff in the internal headers though, rather 
than public facing

> --- libvirt.orig/include/libvirt/libvirt.h.in
> +++ libvirt/include/libvirt/libvirt.h.in
> @@ -187,6 +187,24 @@ struct _virNodeInfo {
>  
>  typedef virNodeInfo *virNodeInfoPtr;
>  
> +/**
> + * VIR_UUID_STRING_BUFLEN:
> + *
> + * This macro provides the length of the buffer required
> + * for virDomainGetUUID()
> + */
> +
> +#define VIR_UUID_BUFLEN (16)
> +
> +/**
> + * VIR_UUID_STRING_BUFLEN:
> + *
> + * This macro provides the length of the buffer required
> + * for virDomainGetUUIDString()
> + */
> +
> +#define VIR_UUID_STRING_BUFLEN (36+1)
> +
>  /* library versionning */


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 of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]