VirtualBox

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

Last change on this file since 26425 was 26425, checked in by vboxsync, 15 years ago

alternative license for VBoxGuestLib is CDDL

  • 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 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <stdio.h> /* Required for sscanf */
36#include <iprt/string.h>
37#include <VBox/log.h>
38
39#ifdef RT_OS_WINDOWS
40 #define WIN32_LEAN_AND_MEAN
41 #include <windows.h>
42#endif
43
44#include "VBGLR3Internal.h"
45
46/**
47 * Checks for a Guest Additions update by comparing the installed version on the
48 * guest and the reported host version.
49 *
50 * @returns VBox status code
51 *
52 * @param u32ClientId The client id returned by
53 * VbglR3InfoSvcConnect().
54 * @param pfUpdate Receives pointer to boolean flag indicating
55 * whether an update was found or not.
56 * @param ppszHostVersion Receives pointer of allocated version string.
57 * The returned pointer must be freed using
58 * VbglR3GuestPropReadValueFree(). Always set to
59 * NULL.
60 * @param ppszGuestVersion Receives pointer of allocated revision string.
61 * The returned pointer must be freed using
62 * VbglR3GuestPropReadValueFree(). Always set to
63 * NULL.
64 */
65VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
66{
67 Assert(u32ClientId > 0);
68 AssertPtr(pfUpdate);
69 AssertPtr(ppszHostVersion);
70 AssertPtr(ppszGuestVersion);
71
72 *ppszHostVersion = NULL;
73 *ppszGuestVersion = NULL;
74
75 /* We assume we have an update initially.
76 Every block down below is allowed to veto */
77 *pfUpdate = true;
78
79 /* Do we need to do all this stuff? */
80 char *pszCheckHostVersion;
81 int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
82 if (RT_FAILURE(rc))
83 {
84 if (rc == VERR_NOT_FOUND)
85 rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
86 else
87 LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
88 }
89 else
90 {
91 /* Only don't do the check if we have a valid "0" in it */
92 if (!strcmp(pszCheckHostVersion, "0"))
93 {
94 LogRel(("No host version update check performed (disabled).\n"));
95 *pfUpdate = false;
96 }
97 VbglR3GuestPropReadValueFree(pszCheckHostVersion);
98 }
99
100 /* Collect all needed information */
101 /* Make sure we only notify the user once by comparing the host version with
102 * the last checked host version (if any) */
103 if (RT_SUCCESS(rc) && *pfUpdate)
104 {
105 /* Look up host version */
106 rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
107 if (RT_FAILURE(rc))
108 {
109 LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
110 }
111 else
112 {
113 LogFlow(("Host version: %s\n", *ppszHostVersion));
114
115 /* Get last checked host version */
116 char *pszLastCheckedHostVersion;
117 rc = VbglR3HostVersionLastCheckedLoad(u32ClientId, &pszLastCheckedHostVersion);
118 if (RT_SUCCESS(rc))
119 {
120 LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion));
121 if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0)
122 *pfUpdate = false; /* We already notified this version, skip */
123 VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion);
124 }
125 else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */
126 {
127 LogFlow(("Never checked a host version before.\n"));
128 rc = VINF_SUCCESS;
129 }
130 }
131
132 /* Look up guest version */
133 if (RT_SUCCESS(rc))
134 {
135 rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */);
136 if (RT_FAILURE(rc))
137 LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
138 }
139 }
140
141 /* Do the actual version comparison (if needed, see block(s) above) */
142 if (RT_SUCCESS(rc) && *pfUpdate)
143 {
144 if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */
145 {
146 /* Yay, we have an update! */
147 LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
148 }
149 else
150 {
151 /* How sad ... */
152 *pfUpdate = false;
153 }
154 }
155
156 /* Cleanup on failure */
157 if (RT_FAILURE(rc))
158 {
159 if (*ppszHostVersion)
160 {
161 VbglR3GuestPropReadValueFree(*ppszHostVersion);
162 *ppszHostVersion = NULL;
163 }
164 if (*ppszGuestVersion)
165 {
166 VbglR3GuestPropReadValueFree(*ppszGuestVersion);
167 *ppszGuestVersion = NULL;
168 }
169 }
170 return rc;
171}
172
173
174/** Retrieves the last checked host version.
175 *
176 * @returns VBox status code.
177 *
178 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
179 * @param ppszVer Receives pointer of allocated version string.
180 * The returned pointer must be freed using RTStrFree() on VINF_SUCCESS.
181 */
182VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(uint32_t u32ClientId, char **ppszVer)
183{
184 Assert(u32ClientId > 0);
185 AssertPtr(ppszVer);
186 return VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
187}
188
189
190/** Stores the last checked host version for later lookup.
191 * Requires strings in form of "majorVer.minorVer.build".
192 *
193 * @returns VBox status code.
194 *
195 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
196 * @param pszVer Pointer to version string to store.
197 */
198VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(uint32_t u32ClientId, const char *pszVer)
199{
200 Assert(u32ClientId > 0);
201 AssertPtr(pszVer);
202 return VbglR3GuestPropWriteValue(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer);
203}
Note: See TracBrowser for help on using the repository browser.

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