2005-02-06 21:26:21 +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
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
|
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
#include "acct_mgr.h"
|
|
|
|
|
|
|
|
int ACCT_MGR::do_rpc(std::string url, std::string name, std::string password) {
|
|
|
|
int retval;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (state != ACCT_MGR_STATE_IDLE) return 0;
|
|
|
|
|
2005-03-12 06:51:33 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Doing account manager RPC to %s", url.c_str());
|
2005-02-06 21:26:21 +00:00
|
|
|
sprintf(buf, "%s?name=%s&password=%s", url.c_str(), name.c_str(), password.c_str());
|
|
|
|
http_op.set_proxy(&gstate.proxy_info);
|
|
|
|
boinc_delete_file(ACCT_MGR_REPLY_FILENAME);
|
|
|
|
retval = http_op.init_get(buf, ACCT_MGR_REPLY_FILENAME, true);
|
|
|
|
if (retval) return retval;
|
2005-03-11 00:33:25 +00:00
|
|
|
retval = gstate.http_ops->insert(&http_op);
|
2005-02-06 21:26:21 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
state = ACCT_MGR_STATE_BUSY;
|
2005-03-11 00:33:25 +00:00
|
|
|
|
2005-02-06 21:26:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ACCT_MGR::poll(double now) {
|
|
|
|
if (state == ACCT_MGR_STATE_IDLE) return false;
|
|
|
|
static double last_time=0;
|
2005-03-11 00:33:25 +00:00
|
|
|
if (now-last_time < 1) return false;
|
2005-02-06 21:26:21 +00:00
|
|
|
last_time = now;
|
|
|
|
|
|
|
|
if (http_op.http_op_state == HTTP_STATE_DONE) {
|
|
|
|
if (http_op.http_op_retval == 0) {
|
2005-03-12 06:51:33 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Account manager RPC succeeded");
|
2005-02-06 21:26:21 +00:00
|
|
|
FILE* f = fopen(ACCT_MGR_REPLY_FILENAME, "r");
|
|
|
|
if (f) {
|
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(f);
|
|
|
|
parse(mf);
|
|
|
|
fclose(f);
|
|
|
|
handle_reply();
|
|
|
|
}
|
|
|
|
} else {
|
2005-03-11 00:33:25 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "Account manager RPC failed");
|
2005-02-06 21:26:21 +00:00
|
|
|
}
|
|
|
|
state = ACCT_MGR_STATE_IDLE;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACCOUNT::parse(MIOFILE& in) {
|
2005-03-10 00:43:22 +00:00
|
|
|
char buf[256];
|
|
|
|
while (in.fgets(buf, sizeof(buf))) {
|
|
|
|
if (match_tag(buf, "</account>")) {
|
|
|
|
if (url.length() && authenticator.length()) return 0;
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<url>", url)) continue;
|
|
|
|
if (parse_str(buf, "<authenticator>", authenticator)) continue;
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
2005-02-06 21:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ACCOUNT::ACCOUNT() {}
|
|
|
|
ACCOUNT::~ACCOUNT() {}
|
|
|
|
|
|
|
|
ACCT_MGR::ACCT_MGR() {
|
|
|
|
state = ACCT_MGR_STATE_IDLE;
|
|
|
|
}
|
|
|
|
|
2005-03-11 00:33:25 +00:00
|
|
|
ACCT_MGR::~ACCT_MGR() {
|
|
|
|
}
|
|
|
|
|
2005-02-06 21:26:21 +00:00
|
|
|
int ACCT_MGR::parse(MIOFILE& in) {
|
|
|
|
char buf[256];
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
accounts.clear();
|
2005-03-10 00:43:22 +00:00
|
|
|
while (in.fgets(buf, sizeof(buf))) {
|
2005-03-11 00:33:25 +00:00
|
|
|
if (match_tag(buf, "</accounts>")) return 0;
|
2005-03-10 00:43:22 +00:00
|
|
|
if (match_tag(buf, "<account>")) {
|
|
|
|
ACCOUNT account;
|
|
|
|
retval = account.parse(in);
|
|
|
|
if (!retval) accounts.push_back(account);
|
|
|
|
}
|
|
|
|
}
|
2005-02-06 21:26:21 +00:00
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACCT_MGR::handle_reply() {
|
2005-03-10 00:43:22 +00:00
|
|
|
unsigned int i;
|
2005-02-06 21:26:21 +00:00
|
|
|
|
2005-03-11 00:33:25 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Handling account manager RPC reply");
|
2005-03-10 00:43:22 +00:00
|
|
|
for (i=0; i<accounts.size(); i++) {
|
|
|
|
ACCOUNT& acct = accounts[i];
|
|
|
|
PROJECT* pp = gstate.lookup_project(acct.url.c_str());
|
|
|
|
if (pp) {
|
|
|
|
if (strcmp(pp->authenticator, acct.authenticator.c_str())) {
|
2005-03-11 00:33:25 +00:00
|
|
|
msg_printf(pp, MSG_ERROR,
|
|
|
|
"You're attached to this project with a different account"
|
2005-03-10 00:43:22 +00:00
|
|
|
);
|
2005-03-11 00:33:25 +00:00
|
|
|
} else {
|
|
|
|
msg_printf(pp, MSG_INFO, "Already attached");
|
2005-03-10 00:43:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-03-11 00:33:25 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Attaching to %s", acct.url.c_str());
|
2005-03-10 00:43:22 +00:00
|
|
|
gstate.add_project(acct.url.c_str(), acct.authenticator.c_str());
|
|
|
|
}
|
|
|
|
}
|
2005-03-11 00:33:25 +00:00
|
|
|
if (accounts.size() == 0) {
|
|
|
|
msg_printf(NULL, MSG_ERROR, "No accounts reported by account manager");
|
|
|
|
}
|
2005-02-06 21:26:21 +00:00
|
|
|
}
|
2005-02-11 04:46:01 +00:00
|
|
|
const char *BOINC_RCSID_8fd9e873bf="$Id$";
|