VirtualBox

Changeset 24331 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 4, 2009 1:59:31 PM (15 years ago)
Author:
vboxsync
Message:

VBoxGuestR3LibHostVersion.cpp: r=bird: RTStrAPrintf does not return a IPRT status value (fixed). Added a couple of todos about bugs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp

    r24306 r24331  
    3636#include "VBGLR3Internal.h"
    3737
    38 /** Compares two VirtualBox version strings and returns the result.
    39  *  Requires strings in form of "majorVer.minorVer.build".
     38/**
     39 * Compares two VirtualBox version strings and returns the result.
     40 *
     41 * Requires strings in form of "majorVer.minorVer.build".
    4042 *
    4143 * @returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater.
     
    4446 * @param   pszVer2     First version string to compare.
    4547 *
     48 * @todo Move this to IPRT and add support for more dots, suffixes and whatnot.
    4649 */
    4750VBGLR3DECL(int) VbglR3HostVersionCompare(const char *pszVer1, const char *pszVer2)
    4851{
    49     int rc = 0;
    5052    int iVer1Major, iVer1Minor, iVer1Build;
    5153    sscanf(pszVer1, "%d.%d.%d", &iVer1Major, &iVer1Minor, &iVer1Build);
     
    5658    int iVer2Final = (iVer2Major * 10000) + (iVer2Minor * 100) + iVer2Build;
    5759
     60    int rc = 0;
    5861    if (iVer1Final > iVer2Final)
    5962        rc = 1;
     
    6467
    6568
    66 /** Checks for a Guest Additions update by comparing the installed version on
    67  *  the guest and the reported host version.
     69/**
     70 * Checks for a Guest Additions update by comparing the installed version on the
     71 * guest and the reported host version.
    6872 *
    6973 * @returns VBox status code
    7074 *
    71  * @param   u32ClientId          The client id returned by VbglR3InfoSvcConnect().
    72  * @param   bUpdate              Receives pointer to boolean flag indicating whether
    73                                  an update was found or not.
    74  * @param   ppszHostVersion      Receives pointer of allocated version string.
    75  *                               The returned pointer must be freed using RTStrFree().
    76  * @param   ppszGuestVersion     Receives pointer of allocated revision string.
    77  *                               The returned pointer must be freed using RTStrFree().
    78  */
    79 VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *bUpdate, char **ppszHostVersion, char **ppszGuestVersion)
    80 {
    81     int rc;
    82 
     75 * @param   u32ClientId         The client id returned by
     76 *                              VbglR3InfoSvcConnect().
     77 * @param   pfUpdate            Receives pointer to boolean flag indicating
     78 *                              whether an update was found or not.
     79 * @param   ppszHostVersion     Receives pointer of allocated version string.
     80 *                              The returned pointer must be freed using
     81 *                              RTStrFree().
     82 * @param   ppszGuestVersion    Receives pointer of allocated revision string.
     83 *                              The returned pointer must be freed using
     84 *                              RTStrFree().  Always set to zero.
     85 */
     86VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
     87{
    8388    Assert(u32ClientId > 0);
    8489    Assert(bUpdate);
     
    9196    /* We assume we have an update initially.
    9297       Every block down below is allowed to veto */
    93     *bUpdate = true;
     98    *pfUpdate = true;
    9499
    95100    /* Do we need to do all this stuff? */
    96101    char *pszCheckHostVersion;
    97     rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
     102    int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
    98103    if (RT_FAILURE(rc))
    99104    {
     
    101106            rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
    102107        else
    103             LogFlow(("Could not read check host version flag! rc = %d\n", rc));
     108            LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
    104109    }
    105110    else
    106111    {
    107112        /* Only don't do the check if we have a valid "0" in it */
    108         if (   atoi(pszCheckHostVersion) == 0
    109             && strlen(pszCheckHostVersion))
     113        if (   *pszCheckHostVersion
     114            && atoi(pszCheckHostVersion) == 0) /** @todo r=bird: don't use atoi, use RTStrToXX. avoid std*.h! */
    110115        {
    111116            LogRel(("No host version update check performed (disabled)."));
    112             *bUpdate = false;
     117            *pfUpdate = false;
    113118        }
    114119        VbglR3GuestPropReadValueFree(pszCheckHostVersion);
     
    118123    /* Make sure we only notify the user once by comparing the host version with
    119124     * the last checked host version (if any) */
    120     if (RT_SUCCESS(rc) && *bUpdate)
     125    if (RT_SUCCESS(rc) && *pfUpdate)
    121126    {
    122127        /* Look up host version */
     
    124129        if (RT_FAILURE(rc))
    125130        {
    126             LogFlow(("Could not read VBox host version! rc = %d\n", rc));
     131            LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
    127132        }
    128133        else
     
    137142                LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion));
    138143                if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0)
    139                     *bUpdate = false; /* We already notified this version, skip */
     144                    *pfUpdate = false; /* We already notified this version, skip */
    140145                VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion);
    141146            }
     
    152157            rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */);
    153158            if (RT_FAILURE(rc))
    154                 LogFlow(("Could not read VBox guest version! rc = %d\n", rc));
     159                LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
    155160        }
    156161    }
    157162
    158163    /* Do the actual version comparison (if needed, see block(s) above) */
    159     if (RT_SUCCESS(rc) && *bUpdate)
     164    if (RT_SUCCESS(rc) && *pfUpdate)
    160165    {
    161166        if (VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */
     
    167172        {
    168173            /* How sad ... */
    169             *bUpdate = false;
     174            *pfUpdate = false;
    170175        }
    171176    }
     
    175180    {
    176181        if (*ppszHostVersion)
     182        {
    177183            VbglR3GuestPropReadValueFree(*ppszHostVersion);
     184            *ppszHostVersion = NULL;
     185        }
    178186        if (*ppszGuestVersion)
     187        {
    179188            VbglR3GuestPropReadValueFree(*ppszGuestVersion);
     189            *ppszGuestVersion = NULL;
     190        }
    180191    }
    181192    return rc;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette