VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp@ 63206

Last change on this file since 63206 was 62679, checked in by vboxsync, 8 years ago

Use the iprt/win/windows.h wrapper for Windows.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, host version check.
4 */
5
6/*
7 * Copyright (C) 2009-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <stdio.h> /* Required for sscanf */
32#include <iprt/string.h>
33#include <VBox/log.h>
34
35#ifdef RT_OS_WINDOWS
36 #define WIN32_LEAN_AND_MEAN
37 #include <iprt/win/windows.h>
38#endif
39
40#include "VBGLR3Internal.h"
41
42/**
43 * Checks for a Guest Additions update by comparing the installed version on the
44 * guest and the reported host version.
45 *
46 * @returns VBox status code
47 *
48 * @param idClient The client id returned by
49 * VbglR3InfoSvcConnect().
50 * @param pfUpdate Receives pointer to boolean flag indicating
51 * whether an update was found or not.
52 * @param ppszHostVersion Receives pointer of allocated version string.
53 * The returned pointer must be freed using
54 * VbglR3GuestPropReadValueFree(). Always set to
55 * NULL.
56 * @param ppszGuestVersion Receives pointer of allocated revision string.
57 * The returned pointer must be freed using
58 * VbglR3GuestPropReadValueFree(). Always set to
59 * NULL.
60 */
61VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(HGCMCLIENTID idClient, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
62{
63 Assert(idClient > 0);
64 AssertPtr(pfUpdate);
65 AssertPtr(ppszHostVersion);
66 AssertPtr(ppszGuestVersion);
67
68 *ppszHostVersion = NULL;
69 *ppszGuestVersion = NULL;
70
71 /* We assume we have an update initially.
72 Every block down below is allowed to veto */
73 *pfUpdate = true;
74
75 /* Do we need to do all this stuff? */
76 char *pszCheckHostVersion;
77 int rc = VbglR3GuestPropReadValueAlloc(idClient, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
78 if (RT_FAILURE(rc))
79 {
80 if (rc == VERR_NOT_FOUND)
81 rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
82 else
83 LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
84 }
85 else
86 {
87 /* Only don't do the check if we have a valid "0" in it */
88 if (!strcmp(pszCheckHostVersion, "0"))
89 {
90 LogRel(("No host version update check performed (disabled).\n"));
91 *pfUpdate = false;
92 }
93 VbglR3GuestPropReadValueFree(pszCheckHostVersion);
94 }
95
96 /* Collect all needed information */
97 /* Make sure we only notify the user once by comparing the host version with
98 * the last checked host version (if any) */
99 if (RT_SUCCESS(rc) && *pfUpdate)
100 {
101 /* Look up host version */
102 rc = VbglR3GuestPropReadValueAlloc(idClient, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
103 if (RT_FAILURE(rc))
104 {
105 LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
106 }
107 else
108 {
109 LogFlow(("Host version: %s\n", *ppszHostVersion));
110
111 /* Get last checked host version */
112 char *pszLastCheckedHostVersion;
113 rc = VbglR3HostVersionLastCheckedLoad(idClient, &pszLastCheckedHostVersion);
114 if (RT_SUCCESS(rc))
115 {
116 LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion));
117 if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0)
118 *pfUpdate = false; /* We already notified this version, skip */
119 VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion);
120 }
121 else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */
122 {
123 LogFlow(("Never checked a host version before.\n"));
124 rc = VINF_SUCCESS;
125 }
126 }
127
128 /* Look up guest version */
129 if (RT_SUCCESS(rc))
130 {
131 rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Extended version not needed here */,
132 NULL /* Revision not needed here */);
133 if (RT_FAILURE(rc))
134 LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
135 }
136 }
137
138 /* Do the actual version comparison (if needed, see block(s) above) */
139 if (RT_SUCCESS(rc) && *pfUpdate)
140 {
141 if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */
142 {
143 /* Yay, we have an update! */
144 LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
145 }
146 else
147 {
148 /* How sad ... */
149 *pfUpdate = false;
150 }
151 }
152
153 /* Cleanup on failure */
154 if (RT_FAILURE(rc))
155 {
156 if (*ppszHostVersion)
157 {
158 VbglR3GuestPropReadValueFree(*ppszHostVersion);
159 *ppszHostVersion = NULL;
160 }
161 if (*ppszGuestVersion)
162 {
163 VbglR3GuestPropReadValueFree(*ppszGuestVersion);
164 *ppszGuestVersion = NULL;
165 }
166 }
167 return rc;
168}
169
170
171/** Retrieves the last checked host version.
172 *
173 * @returns VBox status code.
174 *
175 * @param idClient The client id returned by VbglR3InfoSvcConnect().
176 * @param ppszVer Receives pointer of allocated version string.
177 * The returned pointer must be freed using RTStrFree() on VINF_SUCCESS.
178 */
179VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(HGCMCLIENTID idClient, char **ppszVer)
180{
181 Assert(idClient > 0);
182 AssertPtr(ppszVer);
183 return VbglR3GuestPropReadValueAlloc(idClient, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
184}
185
186
187/** Stores the last checked host version for later lookup.
188 * Requires strings in form of "majorVer.minorVer.build".
189 *
190 * @returns VBox status code.
191 *
192 * @param idClient The client id returned by VbglR3InfoSvcConnect().
193 * @param pszVer Pointer to version string to store.
194 */
195VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(HGCMCLIENTID idClient, const char *pszVer)
196{
197 Assert(idClient > 0);
198 AssertPtr(pszVer);
199 return VbglR3GuestPropWriteValue(idClient, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer);
200}
201
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use