Re: [libvirt] [PATCH] Remove hand-crafted UUID parsers

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

 



2009/9/24 Daniel P. Berrange <berrange@xxxxxxxxxx>:
> * src/libvirt.c: Remove hand-crafted UUID parsers in favour of
>  calling virParseUUID

s/virParseUUID/virUUIDParse/

> ---
>  src/libvirt.c |   56 +++++---------------------------------------------------
>  1 files changed, 5 insertions(+), 51 deletions(-)
>
> diff --git a/src/libvirt.c b/src/libvirt.c
> index 9fb0617..74d62a4 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -1839,26 +1839,11 @@ virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
>         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
>         goto error;
>     }
> -    /* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
> -     *      We needn't it here. Right?
> -     */
> -    ret = sscanf(uuidstr,
> -                 "%02x%02x%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x%02x%02x%02x%02x",
> -                 raw + 0, raw + 1, raw + 2, raw + 3,
> -                 raw + 4, raw + 5, raw + 6, raw + 7,
> -                 raw + 8, raw + 9, raw + 10, raw + 11,
> -                 raw + 12, raw + 13, raw + 14, raw + 15);
> -
> -    if (ret!=VIR_UUID_BUFLEN) {
> +
> +    if (virUUIDParse(uuidstr, uuid) < 0) {
>         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
>         goto error;
>     }
> -    for (i = 0; i < VIR_UUID_BUFLEN; i++)
> -        uuid[i] = raw[i] & 0xFF;
>
>     return virDomainLookupByUUID(conn, &uuid[0]);
>
> @@ -5038,26 +5023,10 @@ virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
>         goto error;
>     }
>
> -    /* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
> -     *      We needn't it here. Right?
> -     */
> -    ret = sscanf(uuidstr,
> -                 "%02x%02x%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x%02x%02x%02x%02x",
> -                 raw + 0, raw + 1, raw + 2, raw + 3,
> -                 raw + 4, raw + 5, raw + 6, raw + 7,
> -                 raw + 8, raw + 9, raw + 10, raw + 11,
> -                 raw + 12, raw + 13, raw + 14, raw + 15);
> -
> -    if (ret!=VIR_UUID_BUFLEN) {
> +    if (virUUIDParse(uuidstr, uuid) < 0) {
>         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
>         goto error;
>     }
> -    for (i = 0; i < VIR_UUID_BUFLEN; i++)
> -        uuid[i] = raw[i] & 0xFF;
>
>     return virNetworkLookupByUUID(conn, &uuid[0]);
>
> @@ -8887,26 +8856,11 @@ virSecretLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
>         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
>         goto error;
>     }
> -    /* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
> -     *      We needn't it here. Right?
> -     */
> -    ret = sscanf(uuidstr,
> -                 "%02x%02x%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x-"
> -                 "%02x%02x%02x%02x%02x%02x",
> -                 raw + 0, raw + 1, raw + 2, raw + 3,
> -                 raw + 4, raw + 5, raw + 6, raw + 7,
> -                 raw + 8, raw + 9, raw + 10, raw + 11,
> -                 raw + 12, raw + 13, raw + 14, raw + 15);
> -
> -    if (ret!=VIR_UUID_BUFLEN) {
> +
> +    if (virUUIDParse(uuidstr, uuid) < 0) {
>         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
>         goto error;
>     }
> -    for (i = 0; i < VIR_UUID_BUFLEN; i++)
> -        uuid[i] = raw[i] & 0xFF;
>
>     return virSecretLookupByUUID(conn, &uuid[0]);
>
> --
> 1.6.2.5
>

You removed the usage of raw, i and ret in this 3 functions, but
forgot to remove the variable definitions as well.

ACK, beside the two comments.

Matthias

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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]