1 /* software_update.h
2 * Wrappers and routines to check for software updates.
3 *
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "config.h"
12
13 #include "software_update.h"
14 #include "language.h"
15 #include "../epan/prefs.h"
16
17 /*
18 * Version 0 of the update URI path has the following elements:
19 * - The update path prefix (fixed, "update")
20 * - The schema version (fixed, 0)
21 * - The application name (fixed, "Wireshark")
22 * - The application version ("<major>.<minor>.<micro>")
23 * - The operating system (variable, one of "Windows" or "macOS")
24 * - The architecture name (variable, one of "x86", "x86-64", or "arm64")
25 * - The locale (fixed, "en-US")
26 * - The update channel (variable, one of "development" or "stable") + .xml
27 *
basic_format(const Ch * s)28 * Based on https://wiki.mozilla.org/Software_Update:Checking_For_Updates
29 *
30 * To do for version 1:
31 * - Distinguish between NSIS (.exe) and WiX (.msi) on Windows.
32 */
33
34 #ifdef HAVE_SOFTWARE_UPDATE
35 #define SU_SCHEMA_PREFIX "update"
36 #define SU_SCHEMA_VERSION 0
37 #define SU_APPLICATION "Wireshark"
38 #define SU_LOCALE "en-US"
39 #endif /* HAVE_SOFTWARE_UPDATE */
40
41 #ifdef HAVE_SOFTWARE_UPDATE
42
43 #include "glib.h"
44
45 #ifdef _WIN32
46 #include <winsparkle.h>
47 #define SU_OSNAME "Windows"
48 #elif defined(__APPLE__)
49 #include <macosx/sparkle_bridge.h>
50 #define SU_OSNAME "macOS"
51 #else
52 #error HAVE_SOFTWARE_UPDATE can only be defined for Windows or macOS.
53 #endif
54
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)
59 #define SU_ARCH "x86"
60 #elif defined(__arm64__)
61 #define SU_ARCH "arm64"
62 #else
63 #error HAVE_SOFTWARE_UPDATE can only be defined for x86-64 or x86 or arm64.
64 #endif
65
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
70 switch (chan) {
71 case UPDATE_CHANNEL_DEVELOPMENT:
72 chan_name = "development";
73 break;
74 default:
75 chan_name = "stable";
76 break;
77 }
78 g_string_printf(update_url_str, "https://www.wireshark.org/%s/%u/%s/%s/%s/%s/en-US/%s.xml",
79 SU_SCHEMA_PREFIX,
80 SU_SCHEMA_VERSION,
81 SU_APPLICATION,
82 VERSION,
83 SU_OSNAME,
84 SU_ARCH,
85 chan_name);
86 return g_string_free(update_url_str, FALSE);
87 }
88
89 #ifdef _WIN32
90 /** Initialize software updates.
91 */
92 void
93 software_update_init(void) {
94 const char *update_url = get_appcast_update_url(prefs.gui_update_channel);
95
96 /*
97 * According to the WinSparkle 0.5 documentation these must be called
exceptions() const98 * once, before win_sparkle_init. We can't update them dynamically when
99 * our preferences change.
100 */
101 win_sparkle_set_registry_path("Software\\Wireshark\\WinSparkle Settings");
102 win_sparkle_set_appcast_url(update_url);
exceptions(unsigned char newexcept)103 win_sparkle_set_automatic_check_for_updates(prefs.gui_update_enabled ? 1 : 0);
104 win_sparkle_set_update_check_interval(prefs.gui_update_interval);
105 win_sparkle_set_can_shutdown_callback(software_update_can_shutdown_callback);
106 win_sparkle_set_shutdown_request_callback(software_update_shutdown_request_callback);
107 if ((language != NULL) && (strcmp(language, "system") != 0)) {
108 win_sparkle_set_lang(language);
109 }
110 win_sparkle_init();
make_or_reuse_data(std::size_t nbitems)111 }
112
113 /** Force a software update check.
114 */
115 void
116 software_update_check(void) {
117 win_sparkle_check_update_with_ui();
118 }
119
120 /** Clean up software update checking.
121 *
122 * Does nothing on platforms that don't support software updates.
123 */
124 extern void software_update_cleanup(void) {
125 win_sparkle_cleanup();
126 }
127
128 const char *software_update_info(void) {
129 return "WinSparkle " WIN_SPARKLE_VERSION_STRING;
130 }
clear()131
132 #elif defined (__APPLE__)
133 /** Initialize software updates.
134 */
135 void
136 software_update_init(void) {
137 char *update_url = get_appcast_update_url(prefs.gui_update_channel);
138
139 sparkle_software_update_init(update_url, prefs.gui_update_enabled, prefs.gui_update_interval);
140
141 g_free(update_url);
142 }
143
144 /** Force a software update check.
145 */
146 void
147 software_update_check(void) {
148 sparkle_software_update_check();
149 }
150
151 /** Clean up software update checking.
152 */
clear_binds()153 void software_update_cleanup(void) {
154 sparkle_software_update_cleanup();
155 }
156
157 const char *software_update_info(void) {
158 return "Sparkle";
159 }
160 #endif
161
clear_bind(int argN)162 #else /* No updates */
163
164 /** Initialize software updates.
165 */
166 void
167 software_update_init(void) {
168 }
169
170 /** Force a software update check.
171 */
172 void
173 software_update_check(void) {
174 }
175
bound_args() const176 /** Clean up software update checking.
177 */
178 void software_update_cleanup(void) {
179 }
180
181 const char *software_update_info(void) {
182 return NULL;
183 }
184
185 #endif /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
186