VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/hostversion.cpp@ 68495

Last change on this file since 68495 was 63403, checked in by vboxsync, 8 years ago

gcc warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: hostversion.cpp 63403 2016-08-12 20:57:23Z vboxsync $ */
2/** @file
3 * X11 guest client - host version check.
4 */
5
6/*
7 * Copyright (C) 2011-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#include <stdio.h>
18#include <iprt/assert.h>
19#include <iprt/err.h>
20#include <iprt/mem.h>
21#include <iprt/ldr.h>
22#include <iprt/string.h>
23#include <iprt/thread.h>
24
25#ifdef VBOX_WITH_DBUS
26# include <VBox/dbus.h>
27#endif
28#include <VBox/log.h>
29#include <VBox/VBoxGuestLib.h>
30#ifdef VBOX_OSE
31# include <VBox/version.h>
32#endif
33
34#include "VBoxClient.h"
35
36static const char *getPidFilePath()
37{
38 return ".vboxclient-hostversion.pid";
39}
40
41static int showNotify(const char *pszHeader, const char *pszBody)
42{
43 int rc;
44# ifdef VBOX_WITH_DBUS
45 DBusConnection *conn;
46 DBusMessage* msg = NULL;
47 conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
48 if (conn == NULL)
49 {
50 LogRelFlowFunc(("Could not retrieve D-BUS session bus!\n"));
51 rc = VERR_INVALID_HANDLE;
52 }
53 else
54 {
55 msg = dbus_message_new_method_call("org.freedesktop.Notifications",
56 "/org/freedesktop/Notifications",
57 "org.freedesktop.Notifications",
58 "Notify");
59 if (msg == NULL)
60 {
61 LogRel(("Could not create D-BUS message!\n"));
62 rc = VERR_INVALID_HANDLE;
63 }
64 else
65 rc = VINF_SUCCESS;
66 }
67 if (RT_SUCCESS(rc))
68 {
69 uint32_t msg_replace_id = 0;
70 const char *msg_app = "VBoxClient";
71 const char *msg_icon = "";
72 const char *msg_summary = pszHeader;
73 const char *msg_body = pszBody;
74 int32_t msg_timeout = -1; /* Let the notification server decide */
75
76 DBusMessageIter iter;
77 DBusMessageIter array;
78 /*DBusMessageIter dict; - unused */
79 /*DBusMessageIter value; - unused */
80 /*DBusMessageIter variant; - unused */
81 /*DBusMessageIter data; - unused */
82
83 /* Format: UINT32 org.freedesktop.Notifications.Notify
84 * (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body,
85 * ARRAY actions, DICT hints, INT32 expire_timeout)
86 */
87 dbus_message_iter_init_append(msg,&iter);
88 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_app);
89 dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msg_replace_id);
90 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_icon);
91 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_summary);
92 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_body);
93 dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
94 dbus_message_iter_close_container(&iter,&array);
95 dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
96 dbus_message_iter_close_container(&iter,&array);
97 dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&msg_timeout);
98
99 DBusError err;
100 dbus_error_init(&err);
101
102 DBusMessage *reply;
103 reply = dbus_connection_send_with_reply_and_block(conn, msg, 30 * 1000 /* 30 seconds timeout */, &err);
104 if (dbus_error_is_set(&err))
105 LogRel(("D-BUS returned an error while sending the notification: %s", err.message));
106 else if (reply)
107 {
108 dbus_connection_flush(conn);
109 dbus_message_unref(reply);
110 }
111 if (dbus_error_is_set(&err))
112 dbus_error_free(&err);
113 }
114 if (msg != NULL)
115 dbus_message_unref(msg);
116# else
117 /** @todo Implement me */
118 RT_NOREF(pszHeader, pszBody);
119 rc = VINF_SUCCESS;
120# endif /* VBOX_WITH_DBUS */
121 return rc;
122}
123
124/** @todo Move this part in VbglR3 and just provide a callback for the platform-specific
125 notification stuff, since this is very similar to the VBoxTray code. */
126static int run(struct VBCLSERVICE **ppInterface, bool fDaemonised)
127{
128 int rc;
129 LogFlowFunc(("\n"));
130
131 NOREF(ppInterface);
132 /* Initialise the guest library. */
133 rc = VbglR3InitUser();
134 if (RT_FAILURE(rc))
135 VBClFatalError(("Failed to connect to the VirtualBox kernel service, rc=%Rrc\n", rc));
136 /* Because we need desktop notifications to be displayed, wait
137 * some time to make the desktop environment load (as a work around). */
138 if (fDaemonised)
139 RTThreadSleep(30 * 1000 /* Wait 30 seconds */);
140
141# ifdef VBOX_WITH_DBUS
142 rc = RTDBusLoadLib();
143 if (RT_FAILURE(rc))
144 LogRel(("VBoxClient: D-Bus seems not to be installed; no host version check/notification done.\n"));
145# else
146 rc = VERR_NOT_IMPLEMENTED;
147# endif /* VBOX_WITH_DBUS */
148
149# ifdef VBOX_WITH_GUEST_PROPS
150 uint32_t uGuestPropSvcClientID;
151 if (RT_SUCCESS(rc))
152 {
153 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
154 if (RT_FAILURE(rc))
155 LogRel(("VBoxClient: Cannot connect to guest property service while chcking for host version! rc = %Rrc\n", rc));
156 }
157
158 if (RT_SUCCESS(rc))
159 {
160 char *pszHostVersion;
161 char *pszGuestVersion;
162 bool bUpdate;
163
164 rc = VbglR3HostVersionCheckForUpdate(uGuestPropSvcClientID, &bUpdate, &pszHostVersion, &pszGuestVersion);
165 if (RT_SUCCESS(rc))
166 {
167 if (bUpdate)
168 {
169 char szMsg[1024];
170 char szTitle[64];
171
172 /** @todo add some translation macros here */
173 RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!");
174#ifndef VBOX_OSE
175 RTStrPrintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. "
176 "We recommend updating to the latest version (%s) by choosing the "
177 "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
178#else
179/* This is the message which appears for non-Oracle builds of the
180* Guest Additions. Distributors are encouraged to customise this. */
181 RTStrPrintf(szMsg, sizeof(szMsg), "Your virtual machine is currently running the Guest Additions version %s. Since you are running a version of the Guest Additions provided by the operating system you installed in the virtual machine we recommend that you update it to at least version %s using that system's update features, or alternatively that you remove this version and then install the " VBOX_VENDOR_SHORT " Guest Additions package using the install option from the Devices menu. Please consult the documentation for the operating system you are running to find out how to update or remove the current Guest Additions package.", pszGuestVersion, pszHostVersion);
182#endif
183 rc = showNotify(szTitle, szMsg);
184 LogRel(("VBoxClient: VirtualBox Guest Additions update available!"));
185 if (RT_FAILURE(rc))
186 LogRel(("VBoxClient: Could not show version notifier tooltip! rc = %d\n", rc));
187 }
188
189 /* Store host version to not notify again */
190 rc = VbglR3HostVersionLastCheckedStore(uGuestPropSvcClientID, pszHostVersion);
191
192 VbglR3GuestPropReadValueFree(pszHostVersion);
193 VbglR3GuestPropReadValueFree(pszGuestVersion);
194 }
195 VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
196 }
197# endif /* VBOX_WITH_GUEST_PROPS */
198 VbglR3Term();
199 LogFlowFunc(("returning %Rrc\n", rc));
200 return rc;
201}
202
203struct VBCLSERVICE vbclHostVersionInterface =
204{
205 getPidFilePath,
206 VBClServiceDefaultHandler, /* init */
207 run,
208 VBClServiceDefaultCleanup
209};
210
211struct HOSTVERSIONSERVICE
212{
213 struct VBCLSERVICE *pInterface;
214};
215
216/* Static factory */
217struct VBCLSERVICE **VBClGetHostVersionService()
218{
219 struct HOSTVERSIONSERVICE *pService =
220 (struct HOSTVERSIONSERVICE *)RTMemAlloc(sizeof(*pService));
221
222 if (!pService)
223 VBClFatalError(("Out of memory\n"));
224 pService->pInterface = &vbclHostVersionInterface;
225 return &pService->pInterface;
226}
227
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