2005-08-05 22:00:19 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
|
|
|
//
|
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software 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.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
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
|
|
|
|
|
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"
|
2005-10-26 05:43:36 +00:00
|
|
|
#include "client_msgs.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
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
retval = gstate.gui_http.do_rpc(this, url, GET_PROJECT_CONFIG_FILENAME);
|
|
|
|
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 {
|
|
|
|
FILE* f = fopen(GET_PROJECT_CONFIG_FILENAME, "r");
|
|
|
|
if (f) {
|
|
|
|
file_to_str(f, reply);
|
|
|
|
fclose(f);
|
2005-08-07 01:33:15 +00:00
|
|
|
error_num = 0;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_FOPEN;
|
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
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
retval = gstate.gui_http.do_rpc(this, url, LOOKUP_ACCOUNT_FILENAME);
|
|
|
|
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 {
|
|
|
|
FILE* f = fopen(LOOKUP_ACCOUNT_FILENAME, "r");
|
|
|
|
if (f) {
|
|
|
|
file_to_str(f, reply);
|
|
|
|
fclose(f);
|
2005-08-07 01:33:15 +00:00
|
|
|
error_num = 0;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_FOPEN;
|
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
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
retval = gstate.gui_http.do_rpc(this, url, CREATE_ACCOUNT_FILENAME);
|
|
|
|
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 {
|
|
|
|
FILE* f = fopen(CREATE_ACCOUNT_FILENAME, "r");
|
|
|
|
if (f) {
|
|
|
|
file_to_str(f, reply);
|
|
|
|
fclose(f);
|
2005-08-07 01:33:15 +00:00
|
|
|
error_num = 0;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_FOPEN;
|
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;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
sprintf(buf, "http://boinc.berkeley.edu/download.php?xml=1");
|
|
|
|
retval = gstate.gui_http.do_rpc(
|
|
|
|
this, string(buf), GET_CURRENT_VERSION_FILENAME
|
|
|
|
);
|
|
|
|
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))) {
|
|
|
|
same_platform = (strcmp(buf2, gstate.platform_name)==0);
|
|
|
|
}
|
|
|
|
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)) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"A new version of BOINC (%s) is available for your computer",
|
|
|
|
new_version
|
|
|
|
);
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"Visit http://boinc.berkeley.edu/download.php to get it."
|
|
|
|
);
|
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() {
|
|
|
|
if (new_version_check_time) {
|
|
|
|
if (now - new_version_check_time > NEW_VERSION_CHECK_PERIOD) {
|
|
|
|
get_current_version_op.do_rpc();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
new_version_check_time = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
retval = gstate.gui_http.do_rpc(
|
2007-03-13 19:33:27 +00:00
|
|
|
this, string(buf), ALL_PROJECTS_LIST_FILENAME
|
2007-03-04 02:30:48 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
error_num = retval;
|
|
|
|
} else {
|
|
|
|
error_num = ERR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gstate.project_list_check_time = gstate.now;
|
2007-03-04 02:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PROJECT_LIST_CHECK_PERIOD (14*86400)
|
|
|
|
|
|
|
|
void CLIENT_STATE::project_list_check() {
|
|
|
|
if (project_list_check_time) {
|
2007-03-04 02:58:22 +00:00
|
|
|
if (now - project_list_check_time < PROJECT_LIST_CHECK_PERIOD) {
|
|
|
|
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$";
|