VirtualBox

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

Last change on this file since 35263 was 28800, checked in by vboxsync, 14 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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 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 <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 u32ClientId 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(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
62{
63 Assert(u32ClientId > 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(u32ClientId, "/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(u32ClientId, "/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(u32ClientId, &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 /* Revision not needed here */);
132 if (RT_FAILURE(rc))
133 LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
134 }
135 }
136
137 /* Do the actual version comparison (if needed, see block(s) above) */
138 if (RT_SUCCESS(rc) && *pfUpdate)
139 {
140 if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */
141 {
142 /* Yay, we have an update! */
143 LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
144 }
145 else
146 {
147 /* How sad ... */
148 *pfUpdate = false;
149 }
150 }
151
152 /* Cleanup on failure */
153 if (RT_FAILURE(rc))
154 {
155 if (*ppszHostVersion)
156 {
157 VbglR3GuestPropReadValueFree(*ppszHostVersion);
158 *ppszHostVersion = NULL;
159 }
160 if (*ppszGuestVersion)
161 {
162 VbglR3GuestPropReadValueFree(*ppszGuestVersion);
163 *ppszGuestVersion = NULL;
164 }
165 }
166 return rc;
167}
168
169
170/** Retrieves the last checked host version.
171 *
172 * @returns VBox status code.
173 *
174 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
175 * @param ppszVer Receives pointer of allocated version string.
176 * The returned pointer must be freed using RTStrFree() on VINF_SUCCESS.
177 */
178VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(uint32_t u32ClientId, char **ppszVer)
179{
180 Assert(u32ClientId > 0);
181 AssertPtr(ppszVer);
182 return VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
183}
184
185
186/** Stores the last checked host version for later lookup.
187 * Requires strings in form of "majorVer.minorVer.build".
188 *
189 * @returns VBox status code.
190 *
191 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
192 * @param pszVer Pointer to version string to store.
193 */
194VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(uint32_t u32ClientId, const char *pszVer)
195{
196 Assert(u32ClientId > 0);
197 AssertPtr(pszVer);
198 return VbglR3GuestPropWriteValue(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer);
199}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use