2010-10-18 20:31:54 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
2022-04-01 10:25:05 +00:00
|
|
|
// Copyright (C) 2022 University of California
|
2010-10-18 20:31:54 +00:00
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// Stuff related to the mechanism where the client fetches
|
|
|
|
// http://boinc.berkeley.edu/download.php?xml=1
|
|
|
|
// every so often to see if there's a newer client version
|
|
|
|
|
|
|
|
#include "filesys.h"
|
2013-06-07 00:31:46 +00:00
|
|
|
#include "str_replace.h"
|
2010-10-18 20:31:54 +00:00
|
|
|
|
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "client_state.h"
|
2018-07-14 11:59:06 +00:00
|
|
|
#include "file_names.h"
|
2010-10-18 20:31:54 +00:00
|
|
|
|
|
|
|
#include "current_version.h"
|
|
|
|
|
2023-05-05 18:05:20 +00:00
|
|
|
// NVC_CONFIG allows branded installers to have the client check for a new
|
2022-04-01 10:25:05 +00:00
|
|
|
// branded client on their serve instead of checking the Berkeley server for
|
|
|
|
// a new standard (unbranded) BOINC client.
|
|
|
|
//
|
2023-05-05 18:05:20 +00:00
|
|
|
// If the nvc_config.xml file is absent from the BOINC Data folder, use
|
2022-04-01 10:25:05 +00:00
|
|
|
// default values (Berkeley server.)
|
2023-05-05 18:05:20 +00:00
|
|
|
// Unbranded BOINC should not have an nvc_config.xml file.
|
2022-04-01 10:25:05 +00:00
|
|
|
// Branded installers can create or replace this file to customize these values.
|
2023-05-05 18:05:20 +00:00
|
|
|
// Standard (unbranded) BOINC installers should either delete the file or
|
2022-04-01 10:25:05 +00:00
|
|
|
// create or replace it with one containing default values.
|
|
|
|
|
2018-07-14 11:59:06 +00:00
|
|
|
NVC_CONFIG nvc_config;
|
|
|
|
|
|
|
|
NVC_CONFIG::NVC_CONFIG() {
|
|
|
|
defaults();
|
|
|
|
}
|
|
|
|
|
2018-07-26 09:09:48 +00:00
|
|
|
// this is called first thing by client right after CC_CONFIG::defaults()
|
2018-07-14 11:59:06 +00:00
|
|
|
//
|
|
|
|
void NVC_CONFIG::defaults() {
|
|
|
|
client_download_url = "https://boinc.berkeley.edu/download.php";
|
2020-05-07 11:43:14 +00:00
|
|
|
client_new_version_name.clear();
|
2018-08-03 03:23:41 +00:00
|
|
|
client_version_check_url = DEFAULT_VERSION_CHECK_URL;
|
2018-07-19 02:10:30 +00:00
|
|
|
network_test_url = "https://www.google.com/";
|
2018-07-14 11:59:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int NVC_CONFIG::parse(FILE* f) {
|
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
|
|
|
|
mf.init_file(f);
|
|
|
|
if (!xp.parse_start("nvc_config")) {
|
|
|
|
msg_printf_notice(NULL, false,
|
|
|
|
"https://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config",
|
|
|
|
"%s",
|
|
|
|
_("Missing start tag in nvc_config.xml")
|
|
|
|
);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (!xp.is_tag) {
|
|
|
|
msg_printf_notice(NULL, false,
|
|
|
|
"https://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config",
|
|
|
|
"%s: %s",
|
|
|
|
_("Unexpected text in nvc_config.xml"),
|
|
|
|
xp.parsed_tag
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("/nvc_config")) {
|
|
|
|
notices.remove_notices(NULL, REMOVE_CONFIG_MSG);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xp.parse_string("client_download_url", client_download_url)) {
|
|
|
|
downcase_string(client_download_url);
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-15 10:24:59 +00:00
|
|
|
if (xp.parse_string("client_new_version_name", client_new_version_name)) {
|
2018-07-14 11:59:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.parse_string("client_version_check_url", client_version_check_url)) {
|
|
|
|
downcase_string(client_version_check_url);
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-19 02:10:30 +00:00
|
|
|
if (xp.parse_string("network_test_url", network_test_url)) {
|
|
|
|
downcase_string(network_test_url);
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-14 11:59:06 +00:00
|
|
|
msg_printf_notice(NULL, false,
|
|
|
|
"https://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config",
|
|
|
|
"%s: <%s>",
|
|
|
|
_("Unrecognized tag in nvc_config.xml"),
|
|
|
|
xp.parsed_tag
|
|
|
|
);
|
|
|
|
xp.skip_unexpected(true, "NVC_CONFIG.parse");
|
|
|
|
}
|
|
|
|
msg_printf_notice(NULL, false,
|
|
|
|
"https://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config",
|
|
|
|
"%s",
|
|
|
|
_("Missing end tag in nvc_config.xml")
|
|
|
|
);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2022-04-01 10:25:05 +00:00
|
|
|
int read_nvc_config_file() {
|
2018-07-26 09:09:48 +00:00
|
|
|
nvc_config.defaults();
|
|
|
|
FILE* f = boinc_fopen(NVC_CONFIG_FILE, "r");
|
2018-07-14 11:59:06 +00:00
|
|
|
if (!f) {
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
2018-07-26 09:09:48 +00:00
|
|
|
nvc_config.parse(f);
|
2018-07-14 11:59:06 +00:00
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-18 20:31:54 +00:00
|
|
|
int GET_CURRENT_VERSION_OP::do_rpc() {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = gui_http->do_rpc(
|
2018-07-14 11:59:06 +00:00
|
|
|
this, nvc_config.client_version_check_url.c_str(),
|
2010-10-18 20:31:54 +00:00
|
|
|
GET_CURRENT_VERSION_FILENAME,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
error_num = retval;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2022-04-01 10:25:05 +00:00
|
|
|
static bool is_version_newer(const char* p, int major, int minor, int release) {
|
2010-10-18 20:31:54 +00:00
|
|
|
int maj=0, min=0, rel=0;
|
|
|
|
|
|
|
|
sscanf(p, "%d.%d.%d", &maj, &min, &rel);
|
2022-04-01 10:25:05 +00:00
|
|
|
if (maj > major) return true;
|
|
|
|
if (maj < major) return false;
|
|
|
|
if (min > minor) return true;
|
|
|
|
if (min < minor) return false;
|
|
|
|
if (rel > release) return true;
|
2010-10-18 20:31:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-01 10:25:05 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// Encode current MacOS version xx.yy.zz as an integer xxyyzz
|
|
|
|
static int get_current_macos_version() {
|
|
|
|
char buf[100];
|
|
|
|
char *p1 = NULL, *p2 = NULL;
|
|
|
|
int vers = 0;
|
|
|
|
FILE *f;
|
|
|
|
buf[0] = '\0';
|
|
|
|
f = popen("sw_vers -productVersion", "r");
|
|
|
|
if (f) {
|
|
|
|
fscanf(f, "%s", buf);
|
|
|
|
pclose(f);
|
|
|
|
}
|
|
|
|
if (buf[0] == '\0') {
|
|
|
|
return 0;
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2022-04-01 10:25:05 +00:00
|
|
|
// Extract the major system version number
|
|
|
|
vers = atoi(buf) * 10000;
|
|
|
|
// Extract the minor system version number
|
|
|
|
p1 = strchr(buf, '.');
|
|
|
|
vers += atoi(p1+1) * 100;
|
|
|
|
p2 = strchr(p1+1, '.');
|
|
|
|
if (p2) {
|
|
|
|
vers += atoi(p2+1);
|
|
|
|
}
|
|
|
|
return vers;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-18 20:31:54 +00:00
|
|
|
// Parse the output of download.php?xml=1.
|
|
|
|
// If there is a newer version for our primary platform,
|
|
|
|
// copy it to new_version and return true.
|
|
|
|
//
|
2013-06-04 03:24:48 +00:00
|
|
|
static bool parse_version(FILE* f, char* new_version, int len) {
|
2011-08-11 06:17:33 +00:00
|
|
|
char buf2[256];
|
2010-10-18 20:31:54 +00:00
|
|
|
bool same_platform = false, newer_version_exists = false;
|
2022-04-01 10:25:05 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
bool min_macos_OK = false, max_macos_OK = false;
|
|
|
|
int val = 0;
|
|
|
|
int macOS_version = get_current_macos_version();
|
|
|
|
#endif
|
2011-08-11 06:17:33 +00:00
|
|
|
|
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(f);
|
|
|
|
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/version")) {
|
2022-04-01 10:25:05 +00:00
|
|
|
#ifdef __APPLE__
|
2023-05-05 18:05:20 +00:00
|
|
|
return (same_platform
|
2024-07-06 09:11:37 +00:00
|
|
|
&& newer_version_exists
|
|
|
|
&& min_macos_OK
|
|
|
|
&& max_macos_OK
|
|
|
|
);
|
2022-04-01 10:25:05 +00:00
|
|
|
#else
|
2010-10-18 20:31:54 +00:00
|
|
|
return (same_platform && newer_version_exists);
|
2022-04-01 10:25:05 +00:00
|
|
|
#endif
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
2011-08-11 06:17:33 +00:00
|
|
|
if (xp.parse_str("dbplatform", buf2, sizeof(buf2))) {
|
2010-10-18 20:31:54 +00:00
|
|
|
same_platform = (strcmp(buf2, gstate.get_primary_platform())==0);
|
|
|
|
}
|
2011-08-11 06:17:33 +00:00
|
|
|
if (xp.parse_str("version_num", buf2, sizeof(buf2))) {
|
2022-04-01 10:25:05 +00:00
|
|
|
newer_version_exists = is_version_newer(
|
2024-07-06 09:11:37 +00:00
|
|
|
buf2,
|
|
|
|
gstate.core_client_version.major,
|
|
|
|
gstate.core_client_version.minor,
|
|
|
|
gstate.core_client_version.release
|
|
|
|
);
|
2013-06-04 03:24:48 +00:00
|
|
|
strlcpy(new_version, buf2, len);
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
2022-04-01 10:25:05 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (xp.parse_int("min_os_version", val)) {
|
|
|
|
min_macos_OK = (val <= macOS_version);
|
|
|
|
}
|
|
|
|
if (xp.parse_int("max_os_version", val)) {
|
|
|
|
max_macos_OK = (val >= macOS_version);
|
|
|
|
}
|
|
|
|
#endif
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-23 22:29:40 +00:00
|
|
|
static void show_newer_version_msg(const char* new_vers) {
|
2018-07-15 10:24:59 +00:00
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if (nvc_config.client_new_version_name.empty()) {
|
2013-06-05 23:55:34 +00:00
|
|
|
msg_printf_notice(0, true,
|
2017-11-15 23:23:53 +00:00
|
|
|
"https://boinc.berkeley.edu/manager_links.php?target=notice&controlid=download",
|
2017-01-24 00:13:06 +00:00
|
|
|
"%s (%s). <a href=%s>%s</a>",
|
|
|
|
_("A new version of BOINC is available"),
|
2013-06-05 23:55:34 +00:00
|
|
|
new_vers,
|
2018-07-14 11:59:06 +00:00
|
|
|
nvc_config.client_download_url.c_str(),
|
2013-06-05 23:55:34 +00:00
|
|
|
_("Download")
|
|
|
|
);
|
|
|
|
} else {
|
2023-05-05 18:05:20 +00:00
|
|
|
snprintf(buf, sizeof(buf), _("A new version of %s is available"),
|
2018-07-15 10:24:59 +00:00
|
|
|
nvc_config.client_new_version_name.c_str()
|
|
|
|
);
|
2013-06-05 23:55:34 +00:00
|
|
|
msg_printf_notice(0, true, NULL,
|
2017-01-24 00:13:06 +00:00
|
|
|
"%s (%s). <a href=%s>%s</a>",
|
2018-07-15 10:24:59 +00:00
|
|
|
buf,
|
2013-06-05 23:55:34 +00:00
|
|
|
new_vers,
|
2018-07-14 11:59:06 +00:00
|
|
|
nvc_config.client_download_url.c_str(),
|
2013-06-05 23:55:34 +00:00
|
|
|
_("Download")
|
|
|
|
);
|
|
|
|
}
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GET_CURRENT_VERSION_OP::handle_reply(int http_op_retval) {
|
2022-04-01 10:25:05 +00:00
|
|
|
char buf[256], new_version[256], newest_version[256];
|
|
|
|
int maj=0, min=0, rel=0;
|
2010-10-18 20:31:54 +00:00
|
|
|
if (http_op_retval) {
|
|
|
|
error_num = http_op_retval;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gstate.new_version_check_time = gstate.now;
|
2022-04-01 10:25:05 +00:00
|
|
|
newest_version[0] = '\0';
|
2010-10-18 20:31:54 +00:00
|
|
|
FILE* f = boinc_fopen(GET_CURRENT_VERSION_FILENAME, "r");
|
|
|
|
if (!f) return;
|
|
|
|
while (fgets(buf, 256, f)) {
|
|
|
|
if (match_tag(buf, "<version>")) {
|
2013-06-04 03:24:48 +00:00
|
|
|
if (parse_version(f, new_version, sizeof(new_version))) {
|
2022-04-01 10:25:05 +00:00
|
|
|
if (is_version_newer(new_version, maj, min, rel)) {
|
|
|
|
strlcpy(newest_version, new_version, sizeof(newest_version));
|
|
|
|
sscanf(newest_version, "%d.%d.%d", &maj, &min, &rel);
|
|
|
|
}
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2022-04-01 10:25:05 +00:00
|
|
|
if (newest_version[0]) {
|
|
|
|
show_newer_version_msg(newest_version);
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2022-04-01 10:25:05 +00:00
|
|
|
// Cache neweer version number. Empty string if no newer version
|
|
|
|
gstate.newer_version = string(newest_version);
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// called at startup to see if the client state file
|
2018-07-15 09:20:50 +00:00
|
|
|
// says there's a new version. This must be called after
|
2018-07-26 09:09:48 +00:00
|
|
|
// read_vc_config_file()
|
2010-10-18 20:31:54 +00:00
|
|
|
//
|
|
|
|
void newer_version_startup_check() {
|
2018-07-15 09:20:50 +00:00
|
|
|
// If version check URL has changed (perhaps due to installing a build of
|
|
|
|
// BOINC with different branding), reset any past new version information
|
|
|
|
//
|
2018-07-26 09:09:48 +00:00
|
|
|
if (gstate.client_version_check_url != nvc_config.client_version_check_url) {
|
|
|
|
gstate.client_version_check_url = nvc_config.client_version_check_url;
|
2018-07-15 09:20:50 +00:00
|
|
|
gstate.newer_version = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-18 20:31:54 +00:00
|
|
|
if (!gstate.newer_version.empty()) {
|
2023-05-05 18:05:20 +00:00
|
|
|
if (is_version_newer(gstate.newer_version.c_str(),
|
2024-07-06 09:11:37 +00:00
|
|
|
gstate.core_client_version.major,
|
|
|
|
gstate.core_client_version.minor,
|
|
|
|
gstate.core_client_version.release)
|
|
|
|
) {
|
2012-07-23 22:29:40 +00:00
|
|
|
show_newer_version_msg(gstate.newer_version.c_str());
|
2010-10-18 20:31:54 +00:00
|
|
|
} else {
|
|
|
|
gstate.newer_version = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NEW_VERSION_CHECK_PERIOD (14*86400)
|
|
|
|
|
2022-03-30 08:54:03 +00:00
|
|
|
// get client version info from the BOINC server if we haven't done so recently.
|
|
|
|
// Called periodically from the main loop.
|
|
|
|
// Also called with force=true for the get_newer_version() GUI RPC
|
|
|
|
//
|
2017-01-24 00:09:53 +00:00
|
|
|
void CLIENT_STATE::new_version_check(bool force) {
|
2022-03-30 08:54:03 +00:00
|
|
|
if (force
|
|
|
|
|| (new_version_check_time == 0)
|
|
|
|
|| (now - new_version_check_time > NEW_VERSION_CHECK_PERIOD)
|
|
|
|
) {
|
|
|
|
// get_current_version_op.handle_reply()
|
|
|
|
// updates new_version_check_time
|
|
|
|
//
|
|
|
|
get_current_version_op.do_rpc();
|
|
|
|
}
|
2010-10-18 20:31:54 +00:00
|
|
|
}
|
|
|
|
|