2005-07-31 23:33:12 +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
|
|
|
|
|
|
|
|
// GUI RPC server side (the actual RPCs)
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
2007-05-11 07:05:29 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2005-07-31 23:33:12 +00:00
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2005-07-31 23:33:12 +00:00
|
|
|
#include <stdio.h>
|
2005-12-16 03:45:01 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-07-31 23:33:12 +00:00
|
|
|
#include <unistd.h>
|
2005-12-16 03:45:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2005-07-31 23:33:12 +00:00
|
|
|
#include <sys/socket.h>
|
2005-12-16 03:45:01 +00:00
|
|
|
#endif
|
2005-07-31 23:33:12 +00:00
|
|
|
#include <sys/un.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2007-05-26 21:15:58 +00:00
|
|
|
#include "client_state.h"
|
2005-07-31 23:33:12 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "network.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
static void auth_failure(MIOFILE& fout) {
|
|
|
|
fout.printf("<unauthorized/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUI_RPC_CONN::handle_auth1(MIOFILE& fout) {
|
|
|
|
sprintf(nonce, "%f", dtime());
|
|
|
|
fout.printf("<nonce>%s</nonce>\n", nonce);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUI_RPC_CONN::handle_auth2(char* buf, MIOFILE& fout) {
|
|
|
|
char nonce_hash[256], nonce_hash_correct[256], buf2[256];
|
|
|
|
if (!parse_str(buf, "<nonce_hash>", nonce_hash, 256)) {
|
|
|
|
auth_failure(fout);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sprintf(buf2, "%s%s", nonce, gstate.gui_rpcs.password);
|
2006-09-07 18:19:25 +00:00
|
|
|
md5_block((const unsigned char*)buf2, (int)strlen(buf2), nonce_hash_correct);
|
2005-07-31 23:33:12 +00:00
|
|
|
if (strcmp(nonce_hash, nonce_hash_correct)) {
|
|
|
|
auth_failure(fout);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fout.printf("<authorized/>\n");
|
|
|
|
auth_needed = false;
|
|
|
|
}
|
|
|
|
|
2006-08-31 18:31:28 +00:00
|
|
|
// client passes its version, but ignore it for now
|
|
|
|
//
|
|
|
|
static void handle_exchange_versions(MIOFILE& fout) {
|
|
|
|
fout.printf(
|
|
|
|
"<server_version>\n"
|
|
|
|
" <major>%d</major>\n"
|
|
|
|
" <minor>%d</minor>\n"
|
|
|
|
" <release>%d</release>\n"
|
|
|
|
"</server_version>\n",
|
|
|
|
BOINC_MAJOR_VERSION,
|
|
|
|
BOINC_MINOR_VERSION,
|
|
|
|
BOINC_RELEASE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-06-27 21:46:50 +00:00
|
|
|
static void handle_get_simple_gui_info(MIOFILE& fout) {
|
|
|
|
unsigned int i;
|
|
|
|
fout.printf("<simple_gui_info>\n");
|
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
PROJECT* p = gstate.projects[i];
|
|
|
|
p->write_state(fout, true);
|
|
|
|
}
|
2006-08-23 22:16:19 +00:00
|
|
|
gstate.write_tasks_gui(fout);
|
2006-06-27 21:46:50 +00:00
|
|
|
fout.printf("</simple_gui_info>\n");
|
|
|
|
}
|
|
|
|
|
2005-07-31 23:33:12 +00:00
|
|
|
static void handle_get_project_status(MIOFILE& fout) {
|
|
|
|
unsigned int i;
|
|
|
|
fout.printf("<projects>\n");
|
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
PROJECT* p = gstate.projects[i];
|
|
|
|
p->write_state(fout, true);
|
|
|
|
}
|
|
|
|
fout.printf("</projects>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_disk_usage(MIOFILE& fout) {
|
|
|
|
unsigned int i;
|
2007-05-08 23:12:40 +00:00
|
|
|
double size, d_total, d_free, d_boinc;
|
2005-07-31 23:33:12 +00:00
|
|
|
|
2006-11-03 17:08:49 +00:00
|
|
|
fout.printf("<disk_usage_summary>\n");
|
|
|
|
get_filesystem_info(d_total, d_free);
|
2007-05-08 23:12:40 +00:00
|
|
|
dir_size(".", d_boinc, false);
|
|
|
|
dir_size("locale", size, false);
|
|
|
|
d_boinc += size;
|
2007-05-11 07:05:29 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (gstate.launched_by_manager) {
|
|
|
|
// If launched by Manager, get Manager's size on disk
|
|
|
|
ProcessSerialNumber managerPSN;
|
|
|
|
FSRef ourFSRef;
|
|
|
|
char path[1024];
|
|
|
|
double manager_size = 0.0;
|
|
|
|
OSStatus err;
|
|
|
|
err = GetProcessForPID(getppid(), &managerPSN);
|
|
|
|
if (! err) err = GetProcessBundleLocation(&managerPSN, &ourFSRef);
|
|
|
|
if (! err) err = FSRefMakePath (&ourFSRef, (UInt8*)path, sizeof(path));
|
|
|
|
if (! err) dir_size(path, manager_size, true);
|
|
|
|
if (! err) d_boinc += manager_size;
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-03 17:08:49 +00:00
|
|
|
fout.printf(
|
|
|
|
"<d_total>%f</d_total>\n"
|
2007-05-08 23:12:40 +00:00
|
|
|
"<d_free>%f</d_free>\n"
|
|
|
|
"<d_boinc>%f</d_boinc>\n",
|
|
|
|
d_total, d_free, d_boinc
|
2006-11-03 17:08:49 +00:00
|
|
|
);
|
2005-07-31 23:33:12 +00:00
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
PROJECT* p = gstate.projects[i];
|
|
|
|
gstate.project_disk_usage(p, size);
|
|
|
|
fout.printf(
|
|
|
|
"<project>\n"
|
|
|
|
" <master_url>%s</master_url>\n"
|
|
|
|
" <disk_usage>%f</disk_usage>\n"
|
|
|
|
"</project>\n",
|
|
|
|
p->master_url, size
|
|
|
|
);
|
|
|
|
}
|
2006-11-03 17:08:49 +00:00
|
|
|
fout.printf("</disk_usage_summary>\n");
|
2005-07-31 23:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PROJECT* get_project(char* buf, MIOFILE& fout) {
|
|
|
|
string url;
|
|
|
|
if (!parse_str(buf, "<project_url>", url)) {
|
|
|
|
fout.printf("<error>Missing project URL</error>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
PROJECT* p = gstate.lookup_project(url.c_str());
|
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_result_show_graphics(char* buf, MIOFILE& fout) {
|
|
|
|
string result_name;
|
|
|
|
GRAPHICS_MSG gm;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
2007-05-26 21:15:58 +00:00
|
|
|
if (match_tag(buf, "<full_screen/>")) {
|
2005-07-31 23:33:12 +00:00
|
|
|
gm.mode = MODE_FULLSCREEN;
|
2006-03-27 03:44:13 +00:00
|
|
|
} else if (match_tag(buf, "<hide/>")) {
|
|
|
|
gm.mode = MODE_HIDE_GRAPHICS;
|
2005-07-31 23:33:12 +00:00
|
|
|
} else {
|
|
|
|
gm.mode = MODE_WINDOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_str(buf, "<window_station>", gm.window_station, sizeof(gm.window_station));
|
|
|
|
parse_str(buf, "<desktop>", gm.desktop, sizeof(gm.desktop));
|
|
|
|
parse_str(buf, "<display>", gm.display, sizeof(gm.display));
|
|
|
|
|
|
|
|
if (parse_str(buf, "<result_name>", result_name)) {
|
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RESULT* rp = gstate.lookup_result(p, result_name.c_str());
|
|
|
|
if (!rp) {
|
|
|
|
fout.printf("<error>No such result</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
atp = gstate.lookup_active_task_by_result(rp);
|
|
|
|
if (!atp) {
|
|
|
|
fout.printf("<error>no such result</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
atp->request_graphics_mode(gm);
|
|
|
|
} else {
|
|
|
|
for (unsigned int i=0; i<gstate.active_tasks.active_tasks.size(); i++) {
|
|
|
|
atp = gstate.active_tasks.active_tasks[i];
|
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
|
|
|
atp->request_graphics_mode(gm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_project_op(char* buf, MIOFILE& fout, const char* op) {
|
2005-10-19 21:04:45 +00:00
|
|
|
int retval;
|
2005-12-28 19:59:05 +00:00
|
|
|
|
2005-07-31 23:33:12 +00:00
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>no such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strcmp(op, "reset")) {
|
2005-12-28 19:59:05 +00:00
|
|
|
gstate.request_schedule_cpus("project reset by user");
|
2006-07-10 00:46:07 +00:00
|
|
|
gstate.request_work_fetch("project reset by user");
|
2005-12-28 19:59:05 +00:00
|
|
|
gstate.reset_project(p); // writes state file
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "suspend")) {
|
2007-06-03 19:37:45 +00:00
|
|
|
p->suspended_via_gui = true;
|
|
|
|
gstate.request_schedule_cpus("project suspended by user");
|
|
|
|
gstate.request_work_fetch("project suspended by user");
|
|
|
|
gstate.set_client_state_dirty("Project suspended by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "resume")) {
|
|
|
|
p->suspended_via_gui = false;
|
2005-12-28 19:59:05 +00:00
|
|
|
gstate.request_schedule_cpus("project resumed by user");
|
2006-07-10 00:46:07 +00:00
|
|
|
gstate.request_work_fetch("project resumed by user");
|
2005-12-28 19:59:05 +00:00
|
|
|
gstate.set_client_state_dirty("Project resumed by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "detach")) {
|
2005-12-09 22:29:21 +00:00
|
|
|
if (p->attached_via_acct_mgr) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_USER_ERROR,
|
2005-12-09 22:29:21 +00:00
|
|
|
"This project must be detached using the account manager web site."
|
|
|
|
);
|
|
|
|
fout.printf("<error>must detach using account manager</error>");
|
|
|
|
return;
|
|
|
|
}
|
2005-10-19 21:04:45 +00:00
|
|
|
|
|
|
|
// if project_init.xml refers to this project,
|
|
|
|
// delete the file, otherwise we'll just
|
|
|
|
// reattach the next time the core client starts
|
|
|
|
//
|
|
|
|
if (!strcmp(p->master_url, gstate.project_init.url)) {
|
|
|
|
retval = gstate.project_init.remove();
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Can't delete project init file: %s", boincerror(retval)
|
2005-10-19 21:04:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2006-07-12 22:25:27 +00:00
|
|
|
|
|
|
|
gstate.detach_project(p); // writes state file; deletes p
|
2005-12-28 19:59:05 +00:00
|
|
|
gstate.request_schedule_cpus("project detached by user");
|
2006-08-11 04:16:23 +00:00
|
|
|
gstate.request_work_fetch("project detached by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "update")) {
|
2006-09-01 22:21:20 +00:00
|
|
|
p->sched_rpc_pending = RPC_REASON_USER_REQ;
|
2005-07-31 23:33:12 +00:00
|
|
|
p->min_rpc_time = 0;
|
2006-08-11 04:16:23 +00:00
|
|
|
gstate.request_work_fetch("project updated by user");
|
|
|
|
gstate.set_client_state_dirty("project updated by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "nomorework")) {
|
2005-12-28 19:59:05 +00:00
|
|
|
p->dont_request_more_work = true;
|
2006-08-11 04:16:23 +00:00
|
|
|
gstate.set_client_state_dirty("project modified by user");
|
2005-12-28 19:59:05 +00:00
|
|
|
} else if (!strcmp(op, "allowmorework")) {
|
|
|
|
p->dont_request_more_work = false;
|
2006-08-11 04:16:23 +00:00
|
|
|
gstate.request_work_fetch("project allowed to fetch work by user");
|
2005-12-28 19:59:05 +00:00
|
|
|
gstate.set_client_state_dirty("Project modified by user");
|
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_run_mode(char* buf, MIOFILE& fout) {
|
2006-11-10 17:55:22 +00:00
|
|
|
double duration = 0;
|
|
|
|
int mode;
|
|
|
|
parse_double(buf, "<duration>", duration);
|
2005-07-31 23:33:12 +00:00
|
|
|
if (match_tag(buf, "<always")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
mode = RUN_MODE_ALWAYS;
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(buf, "<never")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
mode = RUN_MODE_NEVER;
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(buf, "<auto")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
mode = RUN_MODE_AUTO;
|
2006-11-22 03:23:38 +00:00
|
|
|
} else if (match_tag(buf, "<restore")) {
|
|
|
|
mode = RUN_MODE_RESTORE;
|
2005-07-31 23:33:12 +00:00
|
|
|
} else {
|
|
|
|
fout.printf("<error>Missing mode</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-11-10 17:55:22 +00:00
|
|
|
gstate.run_mode.set(mode, duration);
|
2005-07-31 23:33:12 +00:00
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_network_mode(char* buf, MIOFILE& fout) {
|
2006-11-10 17:55:22 +00:00
|
|
|
double duration = 0;
|
|
|
|
int mode;
|
|
|
|
parse_double(buf, "<duration>", duration);
|
2005-07-31 23:33:12 +00:00
|
|
|
if (match_tag(buf, "<always")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
mode = RUN_MODE_ALWAYS;
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(buf, "<never")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
mode = RUN_MODE_NEVER;
|
2005-09-22 19:33:19 +00:00
|
|
|
} else if (match_tag(buf, "<auto")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
mode = RUN_MODE_AUTO;
|
2006-11-22 03:23:38 +00:00
|
|
|
} else if (match_tag(buf, "<restore")) {
|
|
|
|
mode = RUN_MODE_RESTORE;
|
2005-07-31 23:33:12 +00:00
|
|
|
} else {
|
|
|
|
fout.printf("<error>Missing mode</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-01-17 18:13:33 +00:00
|
|
|
// user is turning network on/off explicitly,
|
|
|
|
// so disable the "5 minute grace period" mechanism
|
|
|
|
//
|
|
|
|
gstate.gui_rpcs.time_of_last_rpc_needing_network = 0;
|
|
|
|
|
2006-11-10 17:55:22 +00:00
|
|
|
gstate.network_mode.set(mode, duration);
|
2005-07-31 23:33:12 +00:00
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_run_benchmarks(char* , MIOFILE& fout) {
|
|
|
|
gstate.start_cpu_benchmarks();
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_proxy_settings(char* buf, MIOFILE& fout) {
|
|
|
|
MIOFILE in;
|
2006-11-07 00:38:08 +00:00
|
|
|
in.init_buf_read(buf);
|
2005-07-31 23:33:12 +00:00
|
|
|
gstate.proxy_info.parse(in);
|
|
|
|
gstate.set_client_state_dirty("Set proxy settings RPC");
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
|
|
|
|
// tell running apps to reread app_info file (for F@h)
|
|
|
|
//
|
|
|
|
gstate.active_tasks.request_reread_app_info();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_proxy_settings(char* , MIOFILE& fout) {
|
|
|
|
gstate.proxy_info.write(fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
// params:
|
|
|
|
// [ <seqno>n</seqno> ]
|
|
|
|
// return only msgs with seqno > n; if absent or zero, return all
|
|
|
|
//
|
2005-08-05 22:00:19 +00:00
|
|
|
static void handle_get_messages(char* buf, MIOFILE& fout) {
|
2005-07-31 23:33:12 +00:00
|
|
|
int seqno=0, i, j;
|
|
|
|
unsigned int k;
|
|
|
|
MESSAGE_DESC* mdp;
|
|
|
|
|
|
|
|
parse_int(buf, "<seqno>", seqno);
|
|
|
|
|
|
|
|
// messages are stored in descreasing seqno,
|
|
|
|
// i.e. newer ones are at the head of the vector.
|
|
|
|
// compute j = index of first message to return
|
|
|
|
//
|
2006-09-07 18:19:25 +00:00
|
|
|
j = (int)message_descs.size()-1;
|
2005-07-31 23:33:12 +00:00
|
|
|
for (k=0; k<message_descs.size(); k++) {
|
|
|
|
mdp = message_descs[k];
|
|
|
|
if (mdp->seqno <= seqno) {
|
|
|
|
j = k-1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fout.printf("<msgs>\n");
|
|
|
|
for (i=j; i>=0; i--) {
|
|
|
|
mdp = message_descs[i];
|
|
|
|
fout.printf(
|
|
|
|
"<msg>\n"
|
|
|
|
" <project>%s</project>\n"
|
|
|
|
" <pri>%d</pri>\n"
|
|
|
|
" <seqno>%d</seqno>\n"
|
|
|
|
" <body>\n%s\n</body>\n"
|
|
|
|
" <time>%d</time>\n",
|
|
|
|
mdp->project_name,
|
|
|
|
mdp->priority,
|
|
|
|
mdp->seqno,
|
|
|
|
mdp->message.c_str(),
|
|
|
|
mdp->timestamp
|
|
|
|
);
|
|
|
|
fout.printf("</msg>\n");
|
|
|
|
}
|
|
|
|
fout.printf("</msgs>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// <retry_file_transfer>
|
|
|
|
// <project_url>XXX</project_url>
|
|
|
|
// <filename>XXX</filename>
|
|
|
|
// </retry_file_transfer>
|
|
|
|
//
|
|
|
|
static void handle_file_transfer_op(char* buf, MIOFILE& fout, const char* op) {
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_str(buf, "<filename>", filename)) {
|
|
|
|
fout.printf("<error>Missing filename</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE_INFO* f = gstate.lookup_file_info(p, filename.c_str());
|
|
|
|
if (!f) {
|
|
|
|
fout.printf("<error>No such file</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-30 22:16:07 +00:00
|
|
|
PERS_FILE_XFER* pfx = f->pers_file_xfer;
|
|
|
|
if (!pfx) {
|
2005-07-31 23:33:12 +00:00
|
|
|
fout.printf("<error>No such transfer waiting</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(op, "retry")) {
|
2005-09-30 22:16:07 +00:00
|
|
|
pfx->next_request_time = 0;
|
|
|
|
// leave file-level backoff mode
|
|
|
|
f->project->file_xfer_succeeded(pfx->is_upload);
|
|
|
|
// and leave project-level backoff mode
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "abort")) {
|
|
|
|
f->pers_file_xfer->abort();
|
|
|
|
} else {
|
|
|
|
fout.printf("<error>unknown op</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gstate.set_client_state_dirty("File transfer RPC");
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_result_op(char* buf, MIOFILE& fout, const char* op) {
|
|
|
|
RESULT* rp;
|
|
|
|
char result_name[256];
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_str(buf, "<name>", result_name, sizeof(result_name))) {
|
|
|
|
fout.printf("<error>Missing result name</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rp = gstate.lookup_result(p, result_name);
|
|
|
|
if (!rp) {
|
|
|
|
fout.printf("<error>no such result</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(op, "abort")) {
|
|
|
|
atp = gstate.lookup_active_task_by_result(rp);
|
|
|
|
if (atp) {
|
2005-11-10 06:06:11 +00:00
|
|
|
atp->abort_task(ERR_ABORTED_VIA_GUI, "aborted by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else {
|
2006-05-25 20:10:08 +00:00
|
|
|
rp->abort_inactive(ERR_ABORTED_VIA_GUI);
|
2005-07-31 23:33:12 +00:00
|
|
|
}
|
2006-07-10 00:46:07 +00:00
|
|
|
gstate.request_work_fetch("result aborted by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "suspend")) {
|
2007-06-03 19:37:45 +00:00
|
|
|
rp->suspended_via_gui = true;
|
|
|
|
gstate.request_work_fetch("result suspended by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (!strcmp(op, "resume")) {
|
|
|
|
rp->suspended_via_gui = false;
|
|
|
|
}
|
2005-12-09 07:50:35 +00:00
|
|
|
gstate.request_schedule_cpus("result suspended, resumed or aborted by user");
|
2005-07-31 23:33:12 +00:00
|
|
|
gstate.set_client_state_dirty("Result RPC");
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_host_info(char*, MIOFILE& fout) {
|
2007-03-13 19:33:27 +00:00
|
|
|
gstate.host_info.write(fout, false);
|
2005-07-31 23:33:12 +00:00
|
|
|
}
|
|
|
|
|
2006-12-14 20:44:39 +00:00
|
|
|
static void handle_get_screensaver_mode(GUI_RPC_CONN* gr, char*, MIOFILE& fout) {
|
2005-07-31 23:33:12 +00:00
|
|
|
int ss_result = gstate.ss_logic.get_ss_status();
|
2006-12-17 02:48:19 +00:00
|
|
|
if (gr->au_ss_state == AU_SS_QUIT_REQ) {
|
2006-12-14 20:44:39 +00:00
|
|
|
ss_result = SS_STATUS_QUIT;
|
|
|
|
gr->au_ss_state = AU_SS_QUIT_SENT;
|
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
fout.printf(
|
|
|
|
"<screensaver_mode>\n"
|
|
|
|
" <status>%d</status>\n"
|
|
|
|
"</screensaver_mode>\n",
|
|
|
|
ss_result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_screensaver_mode(char* buf, MIOFILE& fout) {
|
|
|
|
double blank_time = 0.0;
|
|
|
|
GRAPHICS_MSG gm;
|
|
|
|
|
|
|
|
parse_double(buf, "<blank_time>", blank_time);
|
|
|
|
parse_str(buf, "<desktop>", gm.desktop, sizeof(gm.desktop));
|
|
|
|
parse_str(buf, "<window_station>", gm.window_station, sizeof(gm.window_station));
|
|
|
|
parse_str(buf, "<display>", gm.display, sizeof(gm.display));
|
|
|
|
if (match_tag(buf, "<enabled")) {
|
2007-05-26 21:15:58 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "Got start msg from screensaver");
|
2006-12-07 17:30:48 +00:00
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
gstate.ss_logic.start_ss(gm, blank_time );
|
|
|
|
} else {
|
2007-05-26 21:15:58 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "Got stop msg from screensaver");
|
2006-12-07 17:30:48 +00:00
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
gstate.ss_logic.stop_ss();
|
|
|
|
}
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
2005-11-26 00:12:44 +00:00
|
|
|
static void handle_quit(char*, MIOFILE& fout) {
|
2005-07-31 23:33:12 +00:00
|
|
|
gstate.requested_exit = true;
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_acct_mgr_info(char*, MIOFILE& fout) {
|
|
|
|
fout.printf(
|
|
|
|
"<acct_mgr_info>\n"
|
|
|
|
" <acct_mgr_url>%s</acct_mgr_url>\n"
|
|
|
|
" <acct_mgr_name>%s</acct_mgr_name>\n"
|
2005-09-27 09:55:54 +00:00
|
|
|
" %s\n"
|
2005-08-06 19:20:26 +00:00
|
|
|
"</acct_mgr_info>\n",
|
2005-07-31 23:33:12 +00:00
|
|
|
gstate.acct_mgr_info.acct_mgr_url,
|
|
|
|
gstate.acct_mgr_info.acct_mgr_name,
|
2005-09-27 23:55:20 +00:00
|
|
|
strlen(gstate.acct_mgr_info.login_name)?"<have_credentials/>":""
|
2005-07-31 23:33:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
static void handle_get_statistics(char*, MIOFILE& fout) {
|
2005-07-31 23:33:12 +00:00
|
|
|
fout.printf("<statistics>\n");
|
|
|
|
for (std::vector<PROJECT*>::iterator i=gstate.projects.begin();
|
|
|
|
i!=gstate.projects.end();++i
|
|
|
|
) {
|
|
|
|
(*i)->write_statistics(fout,true);
|
|
|
|
}
|
|
|
|
fout.printf("</statistics>\n");
|
|
|
|
}
|
|
|
|
|
2006-12-14 20:44:39 +00:00
|
|
|
static void handle_get_cc_status(GUI_RPC_CONN* gr, MIOFILE& fout) {
|
2006-06-01 05:29:37 +00:00
|
|
|
fout.printf(
|
|
|
|
"<cc_status>\n"
|
|
|
|
" <network_status>%d</network_status>\n"
|
|
|
|
" <ams_password_error>%d</ams_password_error>\n"
|
2006-08-11 17:58:48 +00:00
|
|
|
" <task_suspend_reason>%d</task_suspend_reason>\n"
|
|
|
|
" <network_suspend_reason>%d</network_suspend_reason>\n"
|
2006-08-31 19:24:38 +00:00
|
|
|
" <task_mode>%d</task_mode>\n"
|
|
|
|
" <network_mode>%d</network_mode>\n"
|
2006-11-10 17:55:22 +00:00
|
|
|
" <task_mode_perm>%d</task_mode_perm>\n"
|
|
|
|
" <network_mode_perm>%d</network_mode_perm>\n"
|
2006-11-20 16:52:03 +00:00
|
|
|
" <task_mode_delay>%f</task_mode_delay>\n"
|
2006-12-14 20:44:39 +00:00
|
|
|
" <network_mode_delay>%f</network_mode_delay>\n",
|
2006-07-17 22:18:17 +00:00
|
|
|
net_status.network_status(),
|
2006-08-11 17:58:48 +00:00
|
|
|
gstate.acct_mgr_info.password_error?1:0,
|
|
|
|
gstate.suspend_reason,
|
2006-08-31 19:24:38 +00:00
|
|
|
gstate.network_suspend_reason,
|
2006-11-10 17:55:22 +00:00
|
|
|
gstate.run_mode.get_current(),
|
|
|
|
gstate.network_mode.get_current(),
|
|
|
|
gstate.run_mode.get_perm(),
|
2006-11-20 16:52:03 +00:00
|
|
|
gstate.network_mode.get_perm(),
|
2007-05-26 21:15:58 +00:00
|
|
|
gstate.run_mode.delay(),
|
|
|
|
gstate.network_mode.delay()
|
2006-06-01 05:29:37 +00:00
|
|
|
);
|
2006-12-14 20:44:39 +00:00
|
|
|
if (gr->au_mgr_state == AU_MGR_QUIT_REQ) {
|
|
|
|
fout.printf(
|
|
|
|
" <manager_must_quit>1</manager_must_quit>\n"
|
|
|
|
);
|
|
|
|
gr->au_mgr_state = AU_MGR_QUIT_SENT;
|
|
|
|
}
|
|
|
|
fout.printf(
|
|
|
|
"</cc_status>\n"
|
|
|
|
);
|
2006-06-01 05:29:37 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
static void handle_network_available(char*, MIOFILE&) {
|
2006-07-17 22:18:17 +00:00
|
|
|
net_status.network_available();
|
2005-07-31 23:33:12 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 08:46:51 +00:00
|
|
|
static void handle_get_project_init_status(char*, MIOFILE& fout) {
|
|
|
|
fout.printf(
|
|
|
|
"<get_project_init_status>\n"
|
2005-09-27 09:55:54 +00:00
|
|
|
" <url>%s</url>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" %s\n"
|
2005-09-22 08:46:51 +00:00
|
|
|
"</get_project_init_status>\n",
|
2005-09-27 09:55:54 +00:00
|
|
|
gstate.project_init.url,
|
|
|
|
gstate.project_init.name,
|
2005-09-27 23:55:20 +00:00
|
|
|
strlen(gstate.project_init.account_key)?"<has_account_key/>":""
|
2005-09-22 08:46:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-08-26 21:23:00 +00:00
|
|
|
static void handle_get_project_config(char* buf, MIOFILE& fout) {
|
2005-08-05 22:00:19 +00:00
|
|
|
string url;
|
2005-08-26 21:23:00 +00:00
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
parse_str(buf, "<url>", url);
|
2005-08-26 21:23:00 +00:00
|
|
|
|
2005-08-11 06:52:19 +00:00
|
|
|
canonicalize_master_url(url);
|
2005-08-05 22:00:19 +00:00
|
|
|
gstate.get_project_config_op.do_rpc(url);
|
2005-08-26 21:23:00 +00:00
|
|
|
fout.printf("<success/>\n");
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_project_config_poll(char*, MIOFILE& fout) {
|
2005-08-06 19:20:26 +00:00
|
|
|
if (gstate.get_project_config_op.error_num) {
|
2005-08-16 09:07:05 +00:00
|
|
|
fout.printf(
|
|
|
|
"<project_config>\n"
|
|
|
|
" <error_num>%d</error_num>\n"
|
|
|
|
"</project_config>\n",
|
2005-08-07 01:33:15 +00:00
|
|
|
gstate.get_project_config_op.error_num
|
|
|
|
);
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 18:12:35 +00:00
|
|
|
fout.printf("%s", gstate.get_project_config_op.reply.c_str());
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-26 21:23:00 +00:00
|
|
|
static void handle_lookup_account(char* buf, MIOFILE& fout) {
|
2005-08-05 22:00:19 +00:00
|
|
|
ACCOUNT_IN ai;
|
2005-08-26 21:23:00 +00:00
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
ai.parse(buf);
|
2005-08-26 21:23:00 +00:00
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
gstate.lookup_account_op.do_rpc(ai);
|
2005-08-26 21:23:00 +00:00
|
|
|
fout.printf("<success/>\n");
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_lookup_account_poll(char*, MIOFILE& fout) {
|
2005-08-06 19:20:26 +00:00
|
|
|
if (gstate.lookup_account_op.error_num) {
|
2005-08-16 09:07:05 +00:00
|
|
|
fout.printf(
|
|
|
|
"<account_out>\n"
|
|
|
|
" <error_num>%d</error_num>\n"
|
|
|
|
"</account_out>\n",
|
2005-08-07 01:33:15 +00:00
|
|
|
gstate.lookup_account_op.error_num
|
|
|
|
);
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 18:12:35 +00:00
|
|
|
fout.printf("%s", gstate.lookup_account_op.reply.c_str());
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-26 21:23:00 +00:00
|
|
|
static void handle_create_account(char* buf, MIOFILE& fout) {
|
2005-08-05 22:00:19 +00:00
|
|
|
ACCOUNT_IN ai;
|
2005-08-26 21:23:00 +00:00
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
ai.parse(buf);
|
2005-08-26 21:23:00 +00:00
|
|
|
|
2005-08-05 22:00:19 +00:00
|
|
|
gstate.create_account_op.do_rpc(ai);
|
2005-08-26 21:23:00 +00:00
|
|
|
fout.printf("<success/>\n");
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_create_account_poll(char*, MIOFILE& fout) {
|
2005-08-06 19:20:26 +00:00
|
|
|
if (gstate.create_account_op.error_num) {
|
2005-08-16 09:07:05 +00:00
|
|
|
fout.printf(
|
|
|
|
"<account_out>\n"
|
|
|
|
" <error_num>%d</error_num>\n"
|
|
|
|
"</account_out>\n",
|
2005-08-07 01:33:15 +00:00
|
|
|
gstate.create_account_op.error_num
|
|
|
|
);
|
2005-08-05 22:00:19 +00:00
|
|
|
} else {
|
2005-08-06 18:12:35 +00:00
|
|
|
fout.printf("%s", gstate.create_account_op.reply.c_str());
|
2005-08-05 22:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-22 08:46:51 +00:00
|
|
|
static void handle_project_attach(char* buf, MIOFILE& fout) {
|
2006-12-26 00:37:25 +00:00
|
|
|
string url, authenticator, project_name;
|
2005-09-27 23:55:20 +00:00
|
|
|
bool use_config_file = false;
|
2005-09-22 08:46:51 +00:00
|
|
|
bool already_attached = false;
|
|
|
|
unsigned int i;
|
|
|
|
|
2007-05-14 17:36:16 +00:00
|
|
|
// Get URL/auth from project_init.xml?
|
2006-12-26 00:37:25 +00:00
|
|
|
//
|
2007-05-14 17:36:16 +00:00
|
|
|
if (parse_bool(buf, "use_config_file", use_config_file)) {
|
|
|
|
if (!strlen(gstate.project_init.url)) {
|
2005-09-22 08:46:51 +00:00
|
|
|
fout.printf("<error>Missing URL</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-14 17:36:16 +00:00
|
|
|
if (!strlen(gstate.project_init.account_key)) {
|
|
|
|
fout.printf("<error>Missing authenticator</error>\n");
|
|
|
|
return;
|
2005-09-22 08:46:51 +00:00
|
|
|
}
|
|
|
|
|
2007-05-14 17:36:16 +00:00
|
|
|
url = gstate.project_init.url;
|
|
|
|
authenticator = gstate.project_init.account_key;
|
|
|
|
} else {
|
|
|
|
if (!parse_str(buf, "<project_url>", url)) {
|
|
|
|
fout.printf("<error>Missing URL</error>\n");
|
2005-09-22 08:46:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!parse_str(buf, "<authenticator>", authenticator)) {
|
|
|
|
fout.printf("<error>Missing authenticator</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-11-28 21:14:46 +00:00
|
|
|
|
|
|
|
if (authenticator.empty()) {
|
|
|
|
fout.printf("<error>Missing authenticator</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-12-26 00:37:25 +00:00
|
|
|
parse_str(buf, "<project_name>", project_name);
|
2007-05-14 17:36:16 +00:00
|
|
|
}
|
2005-09-22 08:46:51 +00:00
|
|
|
|
2007-05-14 17:36:16 +00:00
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
PROJECT* p = gstate.projects[i];
|
|
|
|
if (url == p->master_url) already_attached = true;
|
|
|
|
}
|
2005-09-22 08:46:51 +00:00
|
|
|
|
2007-05-14 17:36:16 +00:00
|
|
|
if (already_attached) {
|
|
|
|
fout.printf("<error>Already attached to project</error>\n");
|
|
|
|
return;
|
2005-09-22 08:46:51 +00:00
|
|
|
}
|
|
|
|
|
2006-12-26 00:37:25 +00:00
|
|
|
// clear messages from previous attach to project.
|
2005-09-28 11:59:34 +00:00
|
|
|
//
|
|
|
|
gstate.project_attach.messages.clear();
|
2007-05-14 19:18:45 +00:00
|
|
|
gstate.project_attach.error_num = gstate.add_project(
|
2006-12-26 00:37:25 +00:00
|
|
|
url.c_str(), authenticator.c_str(), project_name.c_str(), false
|
|
|
|
);
|
2005-09-22 08:46:51 +00:00
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_project_attach_poll(char*, MIOFILE& fout) {
|
2005-09-28 05:47:14 +00:00
|
|
|
unsigned int i;
|
2005-09-22 08:46:51 +00:00
|
|
|
fout.printf(
|
2005-09-28 11:59:34 +00:00
|
|
|
"<project_attach_reply>\n"
|
2005-09-22 08:46:51 +00:00
|
|
|
);
|
2005-09-28 05:47:14 +00:00
|
|
|
for (i=0; i<gstate.project_attach.messages.size(); i++) {
|
|
|
|
fout.printf(
|
|
|
|
" <message>%s</message>\n",
|
|
|
|
gstate.project_attach.messages[i].c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fout.printf(
|
2005-09-28 11:59:34 +00:00
|
|
|
" <error_num>%d</error_num>\n",
|
|
|
|
gstate.project_attach.error_num
|
|
|
|
);
|
|
|
|
fout.printf(
|
|
|
|
"</project_attach_reply>\n"
|
2005-09-28 05:47:14 +00:00
|
|
|
);
|
2005-09-22 08:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_acct_mgr_rpc(char* buf, MIOFILE& fout) {
|
|
|
|
std::string url, name, password;
|
2005-12-14 01:44:11 +00:00
|
|
|
std::string password_hash, name_lc;
|
2005-09-27 23:55:20 +00:00
|
|
|
bool use_config_file = false;
|
2005-09-22 08:46:51 +00:00
|
|
|
bool bad_arg = false;
|
2005-09-27 23:55:20 +00:00
|
|
|
if (!parse_bool(buf, "use_config_file", use_config_file)) {
|
2005-09-22 08:46:51 +00:00
|
|
|
if (!parse_str(buf, "<url>", url)) bad_arg = true;
|
|
|
|
if (!parse_str(buf, "<name>", name)) bad_arg = true;
|
|
|
|
if (!parse_str(buf, "<password>", password)) bad_arg = true;
|
2005-12-14 01:44:11 +00:00
|
|
|
if (!bad_arg) {
|
|
|
|
name_lc = name;
|
|
|
|
downcase_string(name_lc);
|
|
|
|
password_hash = md5_string(password+name_lc);
|
|
|
|
}
|
2005-09-22 08:46:51 +00:00
|
|
|
} else {
|
|
|
|
if (!strlen(gstate.acct_mgr_info.acct_mgr_url) || !strlen(gstate.acct_mgr_info.acct_mgr_url) || !strlen(gstate.acct_mgr_info.acct_mgr_url)) {
|
|
|
|
bad_arg = true;
|
|
|
|
} else {
|
|
|
|
url = gstate.acct_mgr_info.acct_mgr_url;
|
2005-09-29 00:50:19 +00:00
|
|
|
name = gstate.acct_mgr_info.login_name;
|
2005-12-14 01:44:11 +00:00
|
|
|
password_hash = gstate.acct_mgr_info.password_hash;
|
2005-09-22 08:46:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bad_arg) {
|
|
|
|
fout.printf("<error>bad arg</error>\n");
|
|
|
|
} else {
|
2006-06-01 05:29:37 +00:00
|
|
|
gstate.acct_mgr_op.do_rpc(url, name, password_hash, true);
|
2005-09-22 08:46:51 +00:00
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_acct_mgr_rpc_poll(char*, MIOFILE& fout) {
|
2005-09-28 05:47:14 +00:00
|
|
|
fout.printf(
|
|
|
|
"<acct_mgr_rpc_reply>\n"
|
|
|
|
);
|
|
|
|
if (gstate.acct_mgr_op.error_str.size()) {
|
2005-09-22 08:46:51 +00:00
|
|
|
fout.printf(
|
2005-09-28 05:47:14 +00:00
|
|
|
" <message>%s</message>\n",
|
|
|
|
gstate.acct_mgr_op.error_str.c_str()
|
2005-09-22 08:46:51 +00:00
|
|
|
);
|
|
|
|
}
|
2005-09-28 11:59:34 +00:00
|
|
|
fout.printf(
|
|
|
|
" <error_num>%d</error_num>\n",
|
|
|
|
gstate.acct_mgr_op.error_num
|
|
|
|
);
|
2005-09-28 05:47:14 +00:00
|
|
|
fout.printf(
|
|
|
|
"</acct_mgr_rpc_reply>\n"
|
|
|
|
);
|
2005-09-22 08:46:51 +00:00
|
|
|
}
|
|
|
|
|
2005-11-12 06:14:10 +00:00
|
|
|
static void handle_get_newer_version(MIOFILE& fout) {
|
|
|
|
fout.printf("<newer_version>%s</newer_version>\n",
|
|
|
|
gstate.newer_version.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-08-07 16:55:56 +00:00
|
|
|
static void handle_get_global_prefs_override(MIOFILE& fout) {
|
|
|
|
string s;
|
|
|
|
int retval = read_file_string(GLOBAL_PREFS_OVERRIDE_FILE, s);
|
|
|
|
if (!retval) {
|
|
|
|
strip_whitespace(s);
|
|
|
|
fout.printf("%s\n", s.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_global_prefs_override(char* buf, MIOFILE& fout) {
|
|
|
|
char *p, *q=0;
|
|
|
|
int retval = ERR_XML_PARSE;
|
|
|
|
|
|
|
|
// strip off outer tags
|
|
|
|
//
|
2006-08-16 03:44:47 +00:00
|
|
|
p = strstr(buf, "<set_global_prefs_override>\n");
|
2006-08-07 16:55:56 +00:00
|
|
|
if (p) {
|
2006-08-16 03:44:47 +00:00
|
|
|
p += strlen("<set_global_prefs_override>\n");
|
2006-08-07 16:55:56 +00:00
|
|
|
q = strstr(p, "</set_global_prefs_override");
|
|
|
|
}
|
|
|
|
if (q) {
|
|
|
|
*q = 0;
|
|
|
|
strip_whitespace(p);
|
2006-08-16 19:45:43 +00:00
|
|
|
if (strlen(p)) {
|
|
|
|
FILE* f = boinc_fopen(GLOBAL_PREFS_OVERRIDE_FILE, "w");
|
|
|
|
if (f) {
|
|
|
|
fprintf(f, "%s\n", p);
|
|
|
|
fclose(f);
|
|
|
|
retval = 0;
|
|
|
|
} else {
|
|
|
|
retval = ERR_FOPEN;
|
|
|
|
}
|
2006-08-07 16:55:56 +00:00
|
|
|
} else {
|
2006-08-16 19:45:43 +00:00
|
|
|
retval = boinc_delete_file(GLOBAL_PREFS_OVERRIDE_FILE);
|
2006-08-07 16:55:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fout.printf(
|
|
|
|
"<set_global_prefs_override_reply>\n"
|
|
|
|
" <status>%d</status>\n"
|
|
|
|
"</set_global_prefs_override_reply>\n",
|
|
|
|
retval
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-12-17 02:48:19 +00:00
|
|
|
static void handle_get_cc_config(MIOFILE& fout) {
|
|
|
|
string s;
|
|
|
|
int retval = read_file_string(CONFIG_FILE, s);
|
|
|
|
if (!retval) {
|
|
|
|
strip_whitespace(s);
|
|
|
|
fout.printf("%s\n", s.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
static void read_all_projects_list_file(MIOFILE& fout) {
|
|
|
|
string s;
|
|
|
|
int retval = read_file_string(ALL_PROJECTS_LIST_FILENAME, s);
|
|
|
|
if (!retval) {
|
|
|
|
strip_whitespace(s);
|
|
|
|
fout.printf("%s\n", s.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-26 21:15:58 +00:00
|
|
|
static int set_debt(XML_PARSER& xp) {
|
|
|
|
bool is_tag;
|
|
|
|
char tag[256], url[256];
|
|
|
|
double short_term_debt, long_term_debt;
|
|
|
|
bool got_std=false, got_ltd=false;
|
|
|
|
strcpy(url, "");
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!strcmp(tag, "/project")) {
|
|
|
|
if (!strlen(url)) return ERR_XML_PARSE;
|
|
|
|
PROJECT* p = gstate.lookup_project(url);
|
|
|
|
if (!p) return ERR_NOT_FOUND;
|
|
|
|
if (got_std) p->short_term_debt = short_term_debt;
|
|
|
|
if (got_ltd) p->long_term_debt = long_term_debt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xp.parse_str(tag, "master_url", url, sizeof(url))) continue;
|
|
|
|
if (xp.parse_double(tag, "short_term_debt", short_term_debt)) {
|
|
|
|
got_std = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "long_term_debt", long_term_debt)) {
|
|
|
|
got_ltd = true;
|
|
|
|
continue;
|
|
|
|
}
|
2007-06-08 07:55:27 +00:00
|
|
|
if (log_flags.unparsed_xml) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[unparsed_xml] set_debt: unrecognized %s", tag
|
|
|
|
);
|
|
|
|
}
|
|
|
|
xp.skip_unexpected(tag);
|
2007-05-26 21:15:58 +00:00
|
|
|
}
|
2007-05-30 17:25:51 +00:00
|
|
|
return 0;
|
2007-05-26 21:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_debts(char* buf, MIOFILE& fout) {
|
|
|
|
MIOFILE in;
|
|
|
|
XML_PARSER xp(&in);
|
|
|
|
bool is_tag;
|
|
|
|
char tag[256];
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
in.init_buf_read(buf);
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "/set_debts")) {
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
gstate.set_client_state_dirty("set_debt RPC");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!strcmp(tag, "project")) {
|
|
|
|
retval = set_debt(xp);
|
|
|
|
if (retval) {
|
|
|
|
fout.printf("<error>%d</error>\n", retval);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-06-08 07:55:27 +00:00
|
|
|
if (log_flags.unparsed_xml) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[unparsed_xml] handle_set_debts: unrecognized %s", tag
|
|
|
|
);
|
|
|
|
}
|
|
|
|
xp.skip_unexpected(tag);
|
2007-05-26 21:15:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-17 02:48:19 +00:00
|
|
|
static void handle_set_cc_config(char* buf, MIOFILE& fout) {
|
|
|
|
char *p, *q=0;
|
|
|
|
int retval = ERR_XML_PARSE;
|
|
|
|
|
|
|
|
// strip off outer tags
|
|
|
|
//
|
|
|
|
p = strstr(buf, "<set_cc_config>\n");
|
|
|
|
if (p) {
|
|
|
|
p += strlen("<set_cc_config>\n");
|
|
|
|
q = strstr(p, "</set_cc_config");
|
|
|
|
}
|
|
|
|
if (q) {
|
|
|
|
*q = 0;
|
|
|
|
strip_whitespace(p);
|
|
|
|
if (strlen(p)) {
|
|
|
|
FILE* f = boinc_fopen(CONFIG_FILE, "w");
|
|
|
|
if (f) {
|
|
|
|
fprintf(f, "%s\n", p);
|
|
|
|
fclose(f);
|
|
|
|
retval = 0;
|
|
|
|
} else {
|
|
|
|
retval = ERR_FOPEN;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
retval = boinc_delete_file(CONFIG_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fout.printf(
|
|
|
|
"<set_cc_config_reply>\n"
|
|
|
|
" <status>%d</status>\n"
|
|
|
|
"</set_cc_config_reply>\n",
|
|
|
|
retval
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-07-31 23:33:12 +00:00
|
|
|
int GUI_RPC_CONN::handle_rpc() {
|
|
|
|
char request_msg[4096];
|
|
|
|
int n;
|
|
|
|
MIOFILE mf;
|
|
|
|
MFILE m;
|
|
|
|
char* p;
|
|
|
|
mf.init_mfile(&m);
|
|
|
|
|
|
|
|
// read the request message in one read()
|
|
|
|
// so that the core client won't hang because
|
|
|
|
// of malformed request msgs
|
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
n = recv(sock, request_msg, 4095, 0);
|
|
|
|
#else
|
|
|
|
n = read(sock, request_msg, 4095);
|
|
|
|
#endif
|
|
|
|
if (n <= 0) return ERR_READ;
|
|
|
|
request_msg[n] = 0;
|
|
|
|
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.guirpc_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[guirpc_debug] GUI RPC Command = '%s'\n", request_msg
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
|
2006-08-31 18:31:28 +00:00
|
|
|
mf.printf("<boinc_gui_rpc_reply>\n");
|
2005-07-31 23:33:12 +00:00
|
|
|
if (match_tag(request_msg, "<auth1")) {
|
|
|
|
handle_auth1(mf);
|
|
|
|
} else if (match_tag(request_msg, "<auth2")) {
|
|
|
|
handle_auth2(request_msg, mf);
|
|
|
|
|
|
|
|
} else if (auth_needed && !is_local) {
|
|
|
|
auth_failure(mf);
|
|
|
|
|
|
|
|
// operations that require authentication for non-local clients start here
|
|
|
|
|
2006-08-31 18:31:28 +00:00
|
|
|
} else if (match_tag(request_msg, "<exchange_versions")) {
|
|
|
|
handle_exchange_versions(mf);
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_state")) {
|
|
|
|
gstate.write_state_gui(mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_results")) {
|
2006-06-27 21:46:50 +00:00
|
|
|
mf.printf("<results>\n");
|
2006-08-23 22:16:19 +00:00
|
|
|
gstate.write_tasks_gui(mf);
|
2006-06-27 21:46:50 +00:00
|
|
|
mf.printf("</results>\n");
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_screensaver_mode")) {
|
2006-12-14 20:44:39 +00:00
|
|
|
handle_get_screensaver_mode(this, request_msg, mf);
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(request_msg, "<set_screensaver_mode")) {
|
|
|
|
handle_set_screensaver_mode(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_file_transfers")) {
|
|
|
|
gstate.write_file_transfers_gui(mf);
|
2006-06-27 21:46:50 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_simple_gui_info")) {
|
|
|
|
handle_get_simple_gui_info(mf);
|
2006-08-11 22:56:41 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_project_status")) {
|
|
|
|
handle_get_project_status(mf);
|
2005-07-31 23:33:12 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_disk_usage")) {
|
|
|
|
handle_get_disk_usage(mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_proxy_settings")) {
|
|
|
|
handle_get_proxy_settings(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_messages")) {
|
|
|
|
handle_get_messages(request_msg, mf);
|
2005-12-25 04:53:24 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_host_info")) {
|
|
|
|
handle_get_host_info(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_statistics")) {
|
|
|
|
handle_get_statistics(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_newer_version>")) {
|
|
|
|
handle_get_newer_version(mf);
|
2006-09-08 22:28:10 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_cc_status")) {
|
2006-12-14 20:44:39 +00:00
|
|
|
handle_get_cc_status(this, mf);
|
2006-08-11 22:56:41 +00:00
|
|
|
|
|
|
|
// Operations that require authentication start here
|
|
|
|
|
|
|
|
} else if (auth_needed) {
|
|
|
|
auth_failure(mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_nomorework")) {
|
|
|
|
handle_project_op(request_msg, mf, "nomorework");
|
|
|
|
} else if (match_tag(request_msg, "<project_allowmorework")) {
|
|
|
|
handle_project_op(request_msg, mf, "allowmorework");
|
|
|
|
} else if (match_tag(request_msg, "<set_network_mode")) {
|
|
|
|
handle_set_network_mode(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<run_benchmarks")) {
|
|
|
|
handle_run_benchmarks(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<set_proxy_settings")) {
|
|
|
|
handle_set_proxy_settings(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<network_available")) {
|
|
|
|
handle_network_available(request_msg, mf);
|
2006-02-01 22:41:03 +00:00
|
|
|
} else if (match_tag(request_msg, "<abort_file_transfer")) {
|
|
|
|
handle_file_transfer_op(request_msg, mf, "abort");
|
|
|
|
} else if (match_tag(request_msg, "<project_detach")) {
|
|
|
|
handle_project_op(request_msg, mf, "detach");
|
|
|
|
} else if (match_tag(request_msg, "<abort_result")) {
|
|
|
|
handle_result_op(request_msg, mf, "abort");
|
|
|
|
} else if (match_tag(request_msg, "<suspend_result")) {
|
|
|
|
handle_result_op(request_msg, mf, "suspend");
|
|
|
|
} else if (match_tag(request_msg, "<resume_result")) {
|
|
|
|
handle_result_op(request_msg, mf, "resume");
|
|
|
|
} else if (match_tag(request_msg, "<result_show_graphics")) {
|
|
|
|
handle_result_show_graphics(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_suspend")) {
|
|
|
|
handle_project_op(request_msg, mf, "suspend");
|
|
|
|
} else if (match_tag(request_msg, "<project_resume")) {
|
|
|
|
handle_project_op(request_msg, mf, "resume");
|
|
|
|
} else if (match_tag(request_msg, "<set_run_mode")) {
|
|
|
|
handle_set_run_mode(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<quit")) {
|
|
|
|
handle_quit(request_msg, mf);
|
2006-02-07 22:04:55 +00:00
|
|
|
} else if (match_tag(request_msg, "<acct_mgr_info")) {
|
|
|
|
handle_acct_mgr_info(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<read_global_prefs_override/>")) {
|
2006-06-02 20:32:20 +00:00
|
|
|
gstate.read_global_prefs();
|
2006-03-06 21:40:07 +00:00
|
|
|
gstate.request_schedule_cpus("Preferences override");
|
2006-07-10 00:46:07 +00:00
|
|
|
gstate.request_work_fetch("Preferences override");
|
2006-09-08 22:28:10 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_project_init_status")) {
|
|
|
|
handle_get_project_init_status(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_global_prefs_override")) {
|
|
|
|
handle_get_global_prefs_override(mf);
|
|
|
|
} else if (match_tag(request_msg, "<set_global_prefs_override")) {
|
|
|
|
handle_set_global_prefs_override(request_msg, mf);
|
2006-12-17 02:48:19 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_cc_config")) {
|
|
|
|
handle_get_cc_config(mf);
|
|
|
|
} else if (match_tag(request_msg, "<set_cc_config")) {
|
|
|
|
handle_set_cc_config(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<read_cc_config/>")) {
|
|
|
|
read_config_file();
|
|
|
|
gstate.request_schedule_cpus("Core client configuration");
|
|
|
|
gstate.request_work_fetch("Core client configuration");
|
2007-03-13 19:33:27 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_all_projects_list/>")) {
|
|
|
|
read_all_projects_list_file(mf);
|
2007-05-26 21:15:58 +00:00
|
|
|
} else if (match_tag(request_msg, "<set_debts")) {
|
|
|
|
handle_set_debts(request_msg, mf);
|
2005-12-29 22:34:06 +00:00
|
|
|
} else {
|
2005-12-25 04:53:24 +00:00
|
|
|
|
2006-02-01 22:41:03 +00:00
|
|
|
// RPCs after this point enable network communication
|
|
|
|
// for 5 minutes, overriding other factors.
|
|
|
|
// Things like attaching projects, etc.
|
2005-12-29 22:34:06 +00:00
|
|
|
//
|
2005-12-25 04:53:24 +00:00
|
|
|
|
2006-09-08 22:28:10 +00:00
|
|
|
gstate.gui_rpcs.time_of_last_rpc_needing_network = gstate.now;
|
2005-12-29 22:34:06 +00:00
|
|
|
|
|
|
|
if (match_tag(request_msg, "<retry_file_transfer")) {
|
|
|
|
handle_file_transfer_op(request_msg, mf, "retry");
|
|
|
|
} else if (match_tag(request_msg, "<project_reset")) {
|
|
|
|
handle_project_op(request_msg, mf, "reset");
|
|
|
|
} else if (match_tag(request_msg, "<project_update")) {
|
|
|
|
handle_project_op(request_msg, mf, "update");
|
|
|
|
} else if (match_tag(request_msg, "<get_project_config>")) {
|
|
|
|
handle_get_project_config(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_project_config_poll")) {
|
|
|
|
handle_get_project_config_poll(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<lookup_account>")) {
|
|
|
|
handle_lookup_account(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<lookup_account_poll")) {
|
|
|
|
handle_lookup_account_poll(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<create_account>")) {
|
|
|
|
handle_create_account(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<create_account_poll")) {
|
|
|
|
handle_create_account_poll(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_attach>")) {
|
|
|
|
handle_project_attach(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_attach_poll")) {
|
|
|
|
handle_project_attach_poll(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<acct_mgr_rpc>")) {
|
|
|
|
handle_acct_mgr_rpc(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<acct_mgr_rpc_poll")) {
|
|
|
|
handle_acct_mgr_rpc_poll(request_msg, mf);
|
2006-09-08 22:28:10 +00:00
|
|
|
|
2007-05-26 21:15:58 +00:00
|
|
|
// DON'T JUST ADD NEW RPCS HERE - THINK ABOUT THEIR
|
|
|
|
// AUTHENTICATION AND NETWORK REQUIREMENTS FIRST
|
2006-09-08 22:28:10 +00:00
|
|
|
|
2005-12-29 22:34:06 +00:00
|
|
|
} else {
|
|
|
|
mf.printf("<error>unrecognized op</error>\n");
|
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mf.printf("</boinc_gui_rpc_reply>\n\003");
|
|
|
|
m.get_buf(p, n);
|
|
|
|
if (p) {
|
2006-07-20 22:52:57 +00:00
|
|
|
send(sock, p, n, 0);
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.guirpc_debug) {
|
2006-07-20 22:52:57 +00:00
|
|
|
if (n > 1000) p[1000] = 0;
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[guirpc_debug] GUI RPC reply: '%s'\n", p
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2005-07-31 23:33:12 +00:00
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-08-06 18:12:35 +00:00
|
|
|
}
|
2005-09-13 09:01:56 +00:00
|
|
|
const char *BOINC_RCSID_7bf15dcb49="$Id$";
|