2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-08-05 22:00:19 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-08-05 22:00:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +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.
|
2005-08-05 22:00:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-08-05 22:00:19 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2005-11-22 02:11:35 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2005-11-22 02:11:35 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2005-08-05 22:00:19 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "parse.h"
|
2005-09-22 08:46:51 +00:00
|
|
|
#include "filesys.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2007-06-22 20:17:08 +00:00
|
|
|
#include "util.h"
|
2005-10-26 05:43:36 +00:00
|
|
|
#include "client_msgs.h"
|
2008-10-14 23:07:40 +00:00
|
|
|
#include "log_flags.h"
|
2005-08-05 22:00:19 +00:00
|
|
|
|
|
|
|
#include "acct_setup.h"
|
|
|
|
|
2005-09-22 08:46:51 +00:00
|
|
|
void PROJECT_INIT::clear() {
|
|
|
|
strcpy(url, "");
|
|
|
|
strcpy(name, "");
|
|
|
|
strcpy(account_key, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
PROJECT_INIT::PROJECT_INIT() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PROJECT_INIT::init() {
|
|
|
|
char buf[256];
|
|
|
|
MIOFILE mf;
|
|
|
|
FILE* p;
|
|
|
|
|
|
|
|
clear();
|
|
|
|
p = fopen(PROJECT_INIT_FILENAME, "r");
|
|
|
|
if (p) {
|
|
|
|
mf.init_file(p);
|
|
|
|
while(mf.fgets(buf, sizeof(buf))) {
|
|
|
|
if (match_tag(buf, "</project_init>")) break;
|
|
|
|
else if (parse_str(buf, "<name>", name, 256)) continue;
|
|
|
|
else if (parse_str(buf, "<url>", url, 256)) {
|
2005-09-27 23:55:20 +00:00
|
|
|
canonicalize_master_url(url);
|
2005-09-22 08:46:51 +00:00
|
|
|
continue;
|
|
|
|
} else if (parse_str(buf, "<account_key>", account_key, 256)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(p);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PROJECT_INIT::remove() {
|
2005-09-27 23:55:20 +00:00
|
|
|
clear();
|
2005-09-22 08:46:51 +00:00
|
|
|
return boinc_delete_file(PROJECT_INIT_FILENAME);
|
|
|
|
}
|
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
void ACCOUNT_IN::parse(char* buf) {
|
|
|
|
url = "";
|
|
|
|
email_addr = "";
|
|
|
|
passwd_hash = "";
|
|
|
|
user_name = "";
|
|
|
|
|
|
|
|
parse_str(buf, "<url>", url);
|
|
|
|
parse_str(buf, "<email_addr>", email_addr);
|
|
|
|
parse_str(buf, "<passwd_hash>", passwd_hash);
|
|
|
|
parse_str(buf, "<user_name>", user_name);
|
2005-08-11 06:52:19 +00:00
|
|
|
canonicalize_master_url(url);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GET_PROJECT_CONFIG_OP::do_rpc(string master_url) {
|
|
|
|
int retval;
|
2006-03-01 10:10:22 +00:00
|
|
|
string url;
|
|
|
|
|
|
|
|
url = master_url;
|
|
|
|
canonicalize_master_url(url);
|
|
|
|
|
|
|
|
url += "get_project_config.php";
|
|
|
|
|
2005-10-26 05:43:36 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Fetching configuration file from %s", url.c_str()
|
2005-10-26 05:43:36 +00:00
|
|
|
);
|
2006-03-01 10:10:22 +00:00
|
|
|
|
2007-09-27 21:03:15 +00:00
|
|
|
retval = gui_http->do_rpc(this, url, GET_PROJECT_CONFIG_FILENAME);
|
2005-08-05 22:00:19 +00:00
|
|
|
if (retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = ERR_IN_PROGRESS;
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void GET_PROJECT_CONFIG_OP::handle_reply(int http_op_retval) {
|
2005-08-05 22:00:19 +00:00
|
|
|
if (http_op_retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = http_op_retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2007-06-22 18:53:55 +00:00
|
|
|
error_num = read_file_string(GET_PROJECT_CONFIG_FILENAME, reply);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int LOOKUP_ACCOUNT_OP::do_rpc(ACCOUNT_IN& ai) {
|
|
|
|
int retval;
|
|
|
|
string url;
|
2006-03-01 10:49:11 +00:00
|
|
|
string parameter;
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2006-03-01 10:10:22 +00:00
|
|
|
url = ai.url;
|
|
|
|
canonicalize_master_url(url);
|
|
|
|
|
2006-03-01 10:49:11 +00:00
|
|
|
url += "lookup_account.php?email_addr=";
|
|
|
|
parameter = ai.email_addr;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
|
|
|
url += "&passwd_hash=";
|
|
|
|
parameter = ai.passwd_hash;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
2006-03-01 10:10:22 +00:00
|
|
|
|
2007-09-27 21:28:32 +00:00
|
|
|
retval = gui_http->do_rpc(this, url, LOOKUP_ACCOUNT_FILENAME);
|
2005-08-05 22:00:19 +00:00
|
|
|
if (retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = ERR_IN_PROGRESS;
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void LOOKUP_ACCOUNT_OP::handle_reply(int http_op_retval) {
|
2005-08-05 22:00:19 +00:00
|
|
|
if (http_op_retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = http_op_retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2007-06-22 18:53:55 +00:00
|
|
|
error_num = read_file_string(LOOKUP_ACCOUNT_FILENAME, reply);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CREATE_ACCOUNT_OP::do_rpc(ACCOUNT_IN& ai) {
|
|
|
|
int retval;
|
|
|
|
string url;
|
2006-03-01 10:49:11 +00:00
|
|
|
string parameter;
|
2005-08-05 22:00:19 +00:00
|
|
|
|
2006-03-01 10:10:22 +00:00
|
|
|
url = ai.url;
|
|
|
|
canonicalize_master_url(url);
|
|
|
|
|
2006-03-01 10:49:11 +00:00
|
|
|
url += "create_account.php?email_addr=";
|
|
|
|
parameter = ai.email_addr;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
|
|
|
url += "&passwd_hash=";
|
|
|
|
parameter = ai.passwd_hash;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
|
|
|
|
|
|
|
url += "&user_name=";
|
|
|
|
parameter = ai.user_name;
|
|
|
|
escape_url(parameter);
|
|
|
|
url += parameter;
|
2006-03-01 10:10:22 +00:00
|
|
|
|
2007-09-27 21:28:32 +00:00
|
|
|
retval = gui_http->do_rpc(this, url, CREATE_ACCOUNT_FILENAME);
|
2005-08-05 22:00:19 +00:00
|
|
|
if (retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = ERR_IN_PROGRESS;
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void CREATE_ACCOUNT_OP::handle_reply(int http_op_retval) {
|
2005-08-05 22:00:19 +00:00
|
|
|
if (http_op_retval) {
|
2005-08-06 19:20:26 +00:00
|
|
|
error_num = http_op_retval;
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2007-06-22 18:53:55 +00:00
|
|
|
error_num = read_file_string(CREATE_ACCOUNT_FILENAME, reply);
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
2005-08-06 19:20:26 +00:00
|
|
|
}
|
|
|
|
|
2005-11-10 06:03:39 +00:00
|
|
|
int GET_CURRENT_VERSION_OP::do_rpc() {
|
|
|
|
int retval;
|
|
|
|
|
2007-09-27 21:28:32 +00:00
|
|
|
retval = gui_http->do_rpc(
|
2008-10-14 23:07:40 +00:00
|
|
|
this, config.client_version_check_url, GET_CURRENT_VERSION_FILENAME
|
2005-11-10 06:03:39 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
error_num = retval;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_version_newer(char* p) {
|
|
|
|
int maj=0, min=0, rel=0;
|
|
|
|
|
|
|
|
sscanf(p, "%d.%d.%d", &maj, &min, &rel);
|
2006-12-14 00:42:43 +00:00
|
|
|
if (maj > gstate.core_client_version.major) return true;
|
|
|
|
if (maj < gstate.core_client_version.major) return false;
|
|
|
|
if (min > gstate.core_client_version.minor) return true;
|
|
|
|
if (min < gstate.core_client_version.minor) return false;
|
|
|
|
if (rel > gstate.core_client_version.release) return true;
|
2005-11-10 06:03:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool parse_version(FILE* f, char* new_version) {
|
|
|
|
char buf[256], buf2[256];
|
2005-11-19 06:29:51 +00:00
|
|
|
bool same_platform = false, newer_version = false;
|
2005-11-10 06:03:39 +00:00
|
|
|
while (fgets(buf, 256, f)) {
|
|
|
|
if (match_tag(buf, "</version>")) {
|
|
|
|
return (same_platform && newer_version);
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<dbplatform>", buf2, sizeof(buf2))) {
|
2007-05-02 17:53:35 +00:00
|
|
|
same_platform = (strcmp(buf2, gstate.get_primary_platform())==0);
|
2005-11-10 06:03:39 +00:00
|
|
|
}
|
|
|
|
if (parse_str(buf, "<version_num>", buf2, sizeof(buf2))) {
|
|
|
|
newer_version = is_version_newer(buf2);
|
|
|
|
strcpy(new_version, buf2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-02-14 21:20:43 +00:00
|
|
|
void GET_CURRENT_VERSION_OP::handle_reply(int http_op_retval) {
|
2005-11-10 06:03:39 +00:00
|
|
|
char buf[256], new_version[256];
|
|
|
|
if (http_op_retval) {
|
|
|
|
error_num = http_op_retval;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gstate.new_version_check_time = gstate.now;
|
|
|
|
FILE* f = boinc_fopen(GET_CURRENT_VERSION_FILENAME, "r");
|
|
|
|
if (f) {
|
|
|
|
while (fgets(buf, 256, f)) {
|
|
|
|
if (match_tag(buf, "<version>")) {
|
|
|
|
if (parse_version(f, new_version)) {
|
2007-09-04 11:40:46 +00:00
|
|
|
msg_printf(0, MSG_USER_ERROR,
|
2005-11-10 06:03:39 +00:00
|
|
|
"A new version of BOINC (%s) is available for your computer",
|
|
|
|
new_version
|
|
|
|
);
|
2008-10-14 23:07:40 +00:00
|
|
|
|
2007-09-04 11:40:46 +00:00
|
|
|
msg_printf(0, MSG_USER_ERROR,
|
2008-10-14 23:07:40 +00:00
|
|
|
"Visit %s to get it.",
|
|
|
|
config.client_download_url.c_str()
|
2005-11-10 06:03:39 +00:00
|
|
|
);
|
2005-11-12 06:14:10 +00:00
|
|
|
gstate.newer_version = string(new_version);
|
2005-11-10 06:03:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NEW_VERSION_CHECK_PERIOD (14*86400)
|
|
|
|
|
|
|
|
void CLIENT_STATE::new_version_check() {
|
2007-09-04 10:48:18 +00:00
|
|
|
if (( new_version_check_time == 0) ||
|
|
|
|
(now - new_version_check_time > NEW_VERSION_CHECK_PERIOD)) {
|
|
|
|
// get_current_version_op.handle_reply() will update new_version_check_time
|
2005-11-10 06:03:39 +00:00
|
|
|
get_current_version_op.do_rpc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-04 02:30:48 +00:00
|
|
|
int GET_PROJECT_LIST_OP::do_rpc() {
|
|
|
|
int retval;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
sprintf(buf, "http://boinc.berkeley.edu/project_list.php");
|
2007-09-27 21:28:32 +00:00
|
|
|
retval = gui_http->do_rpc(
|
2007-10-02 18:43:12 +00:00
|
|
|
this, string(buf), ALL_PROJECTS_LIST_FILENAME_TEMP
|
2007-03-04 02:30:48 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
error_num = retval;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-10-02 18:43:12 +00:00
|
|
|
#define ALL_PROJECTS_LIST_CHECK_PERIOD (14*86400)
|
|
|
|
|
2007-03-04 02:58:22 +00:00
|
|
|
void GET_PROJECT_LIST_OP::handle_reply(int http_op_retval) {
|
|
|
|
if (http_op_retval) {
|
|
|
|
error_num = http_op_retval;
|
2007-10-02 18:43:12 +00:00
|
|
|
// if error, try again in a day
|
|
|
|
//
|
|
|
|
gstate.all_projects_list_check_time =
|
|
|
|
gstate.now - ALL_PROJECTS_LIST_CHECK_PERIOD + SECONDS_PER_DAY;
|
|
|
|
} else {
|
|
|
|
boinc_rename(ALL_PROJECTS_LIST_FILENAME_TEMP, ALL_PROJECTS_LIST_FILENAME);
|
|
|
|
gstate.all_projects_list_check_time = gstate.now;
|
2007-03-04 02:58:22 +00:00
|
|
|
}
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 19:13:40 +00:00
|
|
|
void CLIENT_STATE::all_projects_list_check() {
|
2007-12-01 22:57:24 +00:00
|
|
|
if (config.dont_contact_ref_site) return;
|
2007-03-19 19:13:40 +00:00
|
|
|
if (all_projects_list_check_time) {
|
|
|
|
if (now - all_projects_list_check_time < ALL_PROJECTS_LIST_CHECK_PERIOD) {
|
2007-03-04 02:58:22 +00:00
|
|
|
return;
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-04 02:58:22 +00:00
|
|
|
get_project_list_op.do_rpc();
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
|
2005-09-13 09:01:56 +00:00
|
|
|
const char *BOINC_RCSID_84df3fc17e="$Id$";
|