2 * Wrappers and routines to check for software updates.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "software_update.h"
15 #include "../epan/prefs.h"
16 #include "../wsutil/filesystem.h"
19 * Version 0 of the update URI path has the following elements:
20 * - The update path prefix (fixed, "update")
21 * - The schema version (fixed, 0)
22 * - The application name (variable, "Wireshark" or "Stratoshark")
23 * - The application version ("<major>.<minor>.<micro>")
24 * - The operating system (variable, one of "Windows" or "macOS")
25 * - The architecture name (variable, one of "x86", "x86-64", or "arm64")
26 * - The locale (fixed, "en-US")
27 * - The update channel (variable, one of "development" or "stable") + .xml
29 * Based on https://wiki.mozilla.org/Software_Update:Checking_For_Updates
31 * To do for version 1:
32 * - Distinguish between NSIS (.exe) and WiX (.msi) on Windows.
35 #ifdef HAVE_SOFTWARE_UPDATE
36 #define SU_SCHEMA_PREFIX "update"
37 #define SU_SCHEMA_VERSION 0
38 #define SU_LOCALE "en-US"
39 #endif /* HAVE_SOFTWARE_UPDATE */
41 #ifdef HAVE_SOFTWARE_UPDATE
46 #include <winsparkle.h>
47 #define SU_OSNAME "Windows"
48 #elif defined(__APPLE__)
49 #include <macosx/sparkle_bridge.h>
50 #define SU_OSNAME "macOS"
52 #error HAVE_SOFTWARE_UPDATE can only be defined for Windows or macOS.
55 // https://sourceforge.net/p/predef/wiki/Architectures/
56 #if defined(__x86_64__) || defined(_M_X64)
57 #define SU_ARCH "x86-64"
58 #elif defined(__i386__) || defined(_M_IX86)
60 #elif defined(__arm64__) || defined(_M_ARM64)
61 #define SU_ARCH "arm64"
63 #error HAVE_SOFTWARE_UPDATE can only be defined for x86-64 or x86 or arm64.
66 static char *get_appcast_update_url(software_update_channel_e chan
) {
67 GString
*update_url_str
= g_string_new("");
68 const char *chan_name
;
69 const char *su_application
= get_configuration_namespace();
70 const char *su_version
= VERSION
;
72 if (!is_packet_configuration_namespace()) {
73 su_version
= LOG_VERSION
;
77 case UPDATE_CHANNEL_DEVELOPMENT
:
78 chan_name
= "development";
84 g_string_printf(update_url_str
, "https://www.wireshark.org/%s/%u/%s/%s/%s/%s/en-US/%s.xml",
92 return g_string_free(update_url_str
, FALSE
);
96 /** Initialize software updates.
99 software_update_init(void) {
100 const char *update_url
= get_appcast_update_url(prefs
.gui_update_channel
);
103 * According to the WinSparkle 0.5 documentation these must be called
104 * once, before win_sparkle_init. We can't update them dynamically when
105 * our preferences change.
107 win_sparkle_set_registry_path("Software\\Wireshark\\WinSparkle Settings");
108 win_sparkle_set_appcast_url(update_url
);
109 win_sparkle_set_automatic_check_for_updates(prefs
.gui_update_enabled
? 1 : 0);
110 win_sparkle_set_update_check_interval(prefs
.gui_update_interval
);
111 win_sparkle_set_can_shutdown_callback(software_update_can_shutdown_callback
);
112 win_sparkle_set_shutdown_request_callback(software_update_shutdown_request_callback
);
113 if ((language
!= NULL
) && (strcmp(language
, "system") != 0)) {
114 win_sparkle_set_lang(language
);
119 /** Force a software update check.
122 software_update_check(void) {
123 win_sparkle_check_update_with_ui();
126 /** Clean up software update checking.
128 * Does nothing on platforms that don't support software updates.
130 extern void software_update_cleanup(void) {
131 win_sparkle_cleanup();
134 const char *software_update_info(void) {
135 return "WinSparkle " WIN_SPARKLE_VERSION_STRING
;
138 #elif defined (__APPLE__)
139 /** Initialize software updates.
142 software_update_init(void) {
143 char *update_url
= get_appcast_update_url(prefs
.gui_update_channel
);
145 sparkle_software_update_init(update_url
, prefs
.gui_update_enabled
, prefs
.gui_update_interval
);
150 /** Force a software update check.
153 software_update_check(void) {
154 sparkle_software_update_check();
157 /** Clean up software update checking.
159 void software_update_cleanup(void) {
162 const char *software_update_info(void) {
167 #else /* No updates */
169 /** Initialize software updates.
172 software_update_init(void) {
175 /** Force a software update check.
178 software_update_check(void) {
181 /** Clean up software update checking.
183 void software_update_cleanup(void) {
186 const char *software_update_info(void) {
190 #endif /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */