2004-01-30 22:19:19 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2004-02-28 19:11:40 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <stdio.h>
|
2004-01-21 07:07:16 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2004-01-21 22:54:35 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
2004-04-15 20:42:15 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2004-07-10 07:27:00 +00:00
|
|
|
#include <arpa/inet.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2004-01-21 07:07:16 +00:00
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2004-05-05 21:15:34 +00:00
|
|
|
#include "error_numbers.h"
|
2004-01-21 07:07:16 +00:00
|
|
|
#include "parse.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
|
2004-07-10 07:27:00 +00:00
|
|
|
#include "file_names.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2004-01-21 07:07:16 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2004-07-15 20:05:04 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
typedef int socklen_t;
|
2004-12-05 23:52:17 +00:00
|
|
|
#elif defined( __APPLE__)
|
2004-07-15 20:05:04 +00:00
|
|
|
typedef int32_t socklen_t;
|
2004-12-05 23:52:17 +00:00
|
|
|
#elif !defined(GETSOCKOPT_SOCKLEN_T) && !defined(_SOCKLEN_T_DECLARED) && !defined(socklen_t)
|
2004-07-15 20:05:04 +00:00
|
|
|
typedef size_t socklen_t;
|
|
|
|
#endif
|
|
|
|
|
2004-08-17 10:46:37 +00:00
|
|
|
static void boinc_close_socket(int sock) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
closesocket(sock);
|
|
|
|
#else
|
|
|
|
close(sock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
GUI_RPC_CONN::GUI_RPC_CONN(int s) {
|
|
|
|
sock = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GUI_RPC_CONN::~GUI_RPC_CONN() {
|
2004-09-05 18:46:19 +00:00
|
|
|
boinc_close_socket(sock);
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
2004-07-21 21:30:25 +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];
|
2004-10-20 23:55:07 +00:00
|
|
|
p->write_state(fout, true);
|
2004-07-21 21:30:25 +00:00
|
|
|
}
|
|
|
|
fout.printf("</projects>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_disk_usage(MIOFILE& fout) {
|
|
|
|
unsigned int i;
|
|
|
|
double size;
|
|
|
|
|
|
|
|
fout.printf("<projects>\n");
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fout.printf("</projects>\n");
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static PROJECT* get_project(char* buf, MIOFILE& fout) {
|
2004-09-05 18:46:19 +00:00
|
|
|
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;
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_result_show_graphics(char* buf, MIOFILE& fout) {
|
2004-08-09 19:06:47 +00:00
|
|
|
string result_name;
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG gm;
|
2004-07-09 20:14:33 +00:00
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
2004-08-07 20:23:22 +00:00
|
|
|
if (match_tag(buf, "<full_screen/>")) {
|
2004-11-17 19:19:26 +00:00
|
|
|
gm.mode = MODE_FULLSCREEN;
|
2004-08-07 20:23:22 +00:00
|
|
|
} else {
|
2004-11-17 19:19:26 +00:00
|
|
|
gm.mode = MODE_WINDOW;
|
2004-08-07 20:23:22 +00:00
|
|
|
}
|
2004-02-28 19:11:40 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
parse_str(buf, "<window_station>", gm.window_station, sizeof(gm.window_station));
|
|
|
|
parse_str(buf, "<desktop>", gm.desktop, sizeof(gm.desktop));
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2004-09-05 18:46:19 +00:00
|
|
|
if (parse_str(buf, "<result_name>", result_name)) {
|
2004-07-19 19:40:06 +00:00
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-07-09 20:14:33 +00:00
|
|
|
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);
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp || atp->scheduler_state != CPU_SCHED_SCHEDULED) {
|
2004-07-09 20:14:33 +00:00
|
|
|
fout.printf("<error>Result not active</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-11-17 19:19:26 +00:00
|
|
|
atp->request_graphics_mode(gm);
|
2004-07-09 20:14:33 +00:00
|
|
|
} else {
|
|
|
|
for (unsigned int i=0; i<gstate.active_tasks.active_tasks.size(); i++) {
|
|
|
|
atp = gstate.active_tasks.active_tasks[i];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
2004-11-17 19:19:26 +00:00
|
|
|
atp->request_graphics_mode(gm);
|
2004-07-09 20:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-05 18:46:19 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-26 04:16:52 +00:00
|
|
|
static void handle_project_op(char* buf, MIOFILE& fout, char* op) {
|
2004-09-05 18:46:19 +00:00
|
|
|
PROJECT* p = get_project(buf, fout);
|
2004-09-26 04:16:52 +00:00
|
|
|
if (!p) {
|
2004-09-30 06:17:49 +00:00
|
|
|
fout.printf("<error>no such project</error>\n");
|
2004-10-15 19:19:03 +00:00
|
|
|
return;
|
2004-09-05 18:46:19 +00:00
|
|
|
}
|
2004-09-26 04:16:52 +00:00
|
|
|
if (!strcmp(op, "reset")) {
|
|
|
|
gstate.reset_project(p);
|
|
|
|
} else if (!strcmp(op, "suspend")) {
|
|
|
|
p->suspended_via_gui = true;
|
|
|
|
} else if (!strcmp(op, "resume")) {
|
|
|
|
p->suspended_via_gui = false;
|
|
|
|
} else if (!strcmp(op, "detach")) {
|
|
|
|
gstate.detach_project(p);
|
|
|
|
} else if (!strcmp(op, "update")) {
|
|
|
|
p->sched_rpc_pending = true;
|
|
|
|
p->min_rpc_time = 0;
|
2004-12-30 03:03:26 +00:00
|
|
|
} else if (!strcmp(op, "nomorework")) {
|
|
|
|
p->dont_request_more_work = true;
|
|
|
|
} else if (!strcmp(op, "allowmorework")) {
|
|
|
|
p->dont_request_more_work = false;
|
|
|
|
}
|
2004-10-19 19:53:53 +00:00
|
|
|
gstate.must_schedule_cpus = true;
|
2004-09-26 04:16:52 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_project_attach(char* buf, MIOFILE& fout) {
|
2004-09-05 18:46:19 +00:00
|
|
|
string url, authenticator;
|
|
|
|
if (!parse_str(buf, "<project_url>", url)) {
|
|
|
|
fout.printf("<error>Missing URL</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!parse_str(buf, "<authenticator>", authenticator)) {
|
|
|
|
fout.printf("<error>Missing authenticator</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gstate.add_project(url.c_str(), authenticator.c_str());
|
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_set_run_mode(char* buf, MIOFILE& fout) {
|
2004-09-05 18:46:19 +00:00
|
|
|
if (match_tag(buf, "<always")) {
|
|
|
|
gstate.user_run_request = USER_RUN_REQUEST_ALWAYS;
|
|
|
|
} else if (match_tag(buf, "<never")) {
|
|
|
|
gstate.user_run_request = USER_RUN_REQUEST_NEVER;
|
|
|
|
} else if (match_tag(buf, "<auto")) {
|
|
|
|
gstate.user_run_request = USER_RUN_REQUEST_AUTO;
|
|
|
|
} else {
|
|
|
|
fout.printf("<error>Missing mode</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
2004-09-22 21:08:26 +00:00
|
|
|
static void handle_get_run_mode(char* , MIOFILE& fout) {
|
2004-09-05 18:46:19 +00:00
|
|
|
fout.printf("<run_mode>\n");
|
|
|
|
switch (gstate.user_run_request) {
|
|
|
|
case USER_RUN_REQUEST_ALWAYS:
|
|
|
|
fout.printf("<always/>\n");
|
|
|
|
break;
|
|
|
|
case USER_RUN_REQUEST_NEVER:
|
|
|
|
fout.printf("<never/>\n");
|
|
|
|
break;
|
|
|
|
case USER_RUN_REQUEST_AUTO:
|
|
|
|
fout.printf("<auto/>\n");
|
|
|
|
break;
|
|
|
|
default:
|
2004-10-20 21:11:29 +00:00
|
|
|
fout.printf("<error>Unknown run mode</error>\n");
|
2004-09-05 18:46:19 +00:00
|
|
|
}
|
|
|
|
fout.printf("</run_mode>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_network_mode(char* buf, MIOFILE& fout) {
|
|
|
|
if (match_tag(buf, "<always")) {
|
|
|
|
gstate.user_network_request = USER_RUN_REQUEST_ALWAYS;
|
|
|
|
} else if (match_tag(buf, "<never")) {
|
|
|
|
gstate.user_network_request = USER_RUN_REQUEST_NEVER;
|
|
|
|
} else {
|
|
|
|
fout.printf("<error>Missing mode</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
2004-09-22 21:08:26 +00:00
|
|
|
static void handle_get_network_mode(char* , MIOFILE& fout) {
|
2004-09-05 18:46:19 +00:00
|
|
|
fout.printf("<network_mode>\n");
|
|
|
|
switch (gstate.user_network_request) {
|
2004-09-25 19:33:30 +00:00
|
|
|
case USER_RUN_REQUEST_ALWAYS:
|
|
|
|
fout.printf("<always/>\n");
|
|
|
|
break;
|
|
|
|
case USER_RUN_REQUEST_NEVER:
|
|
|
|
fout.printf("<never/>\n");
|
|
|
|
break;
|
|
|
|
default:
|
2004-10-20 21:11:29 +00:00
|
|
|
fout.printf("<error>Unknown network mode</error>\n");
|
2004-09-05 18:46:19 +00:00
|
|
|
}
|
|
|
|
fout.printf("</network_mode>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 21:08:26 +00:00
|
|
|
static void handle_run_benchmarks(char* , MIOFILE& fout) {
|
2004-03-21 00:10:15 +00:00
|
|
|
gstate.start_cpu_benchmarks();
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_set_proxy_settings(char* buf, MIOFILE& fout) {
|
2004-09-25 19:33:30 +00:00
|
|
|
MIOFILE in;
|
2004-09-26 04:16:52 +00:00
|
|
|
in.init_buf(buf);
|
|
|
|
gstate.proxy_info.parse(in);
|
2004-09-25 19:33:30 +00:00
|
|
|
gstate.set_client_state_dirty("Set proxy settings RPC");
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-09-26 04:16:52 +00:00
|
|
|
static void handle_get_proxy_settings(char* , MIOFILE& fout) {
|
|
|
|
gstate.proxy_info.write(fout);
|
|
|
|
}
|
|
|
|
|
2004-04-01 23:19:13 +00:00
|
|
|
// params:
|
2004-09-30 21:41:09 +00:00
|
|
|
// [ <seqno>n</seqno> ]
|
2004-09-30 23:35:30 +00:00
|
|
|
// return only msgs with seqno > n; if absent or zero, return all
|
2004-04-01 23:19:13 +00:00
|
|
|
//
|
2004-06-12 04:45:36 +00:00
|
|
|
void handle_get_messages(char* buf, MIOFILE& fout) {
|
2004-09-30 23:35:30 +00:00
|
|
|
int seqno=0, i, j;
|
|
|
|
unsigned int k;
|
2004-09-30 21:41:09 +00:00
|
|
|
MESSAGE_DESC* mdp;
|
|
|
|
bool found=false;
|
2004-04-01 23:19:13 +00:00
|
|
|
|
2004-06-17 04:49:34 +00:00
|
|
|
parse_int(buf, "<seqno>", seqno);
|
2004-09-30 21:41:09 +00:00
|
|
|
|
|
|
|
j = message_descs.size()-1;
|
2004-09-30 23:35:30 +00:00
|
|
|
for (k=0; k<message_descs.size(); k++) {
|
|
|
|
mdp = message_descs[k];
|
2004-09-30 21:41:09 +00:00
|
|
|
if (mdp->seqno <= seqno) {
|
|
|
|
found = true;
|
2004-09-30 23:35:30 +00:00
|
|
|
j = k-1;
|
2004-09-30 21:41:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-04-01 23:19:13 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<msgs>\n");
|
2004-09-30 21:41:09 +00:00
|
|
|
for (i=j; i>=0; i--) {
|
|
|
|
mdp = message_descs[i];
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf(
|
2004-04-01 23:19:13 +00:00
|
|
|
"<msg>\n"
|
|
|
|
" <pri>%d</pri>\n"
|
2004-06-17 04:49:34 +00:00
|
|
|
" <seqno>%d</seqno>\n"
|
2004-06-12 05:44:28 +00:00
|
|
|
" <body>\n%s\n</body>\n"
|
2004-04-01 23:19:13 +00:00
|
|
|
" <time>%d</time>\n",
|
2004-06-17 04:49:34 +00:00
|
|
|
mdp->priority,
|
|
|
|
mdp->seqno,
|
|
|
|
mdp->message.c_str(),
|
|
|
|
mdp->timestamp
|
2004-04-01 23:19:13 +00:00
|
|
|
);
|
2004-06-17 04:49:34 +00:00
|
|
|
if (mdp->project) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf(
|
2004-04-02 00:32:10 +00:00
|
|
|
" <project>%s</project>\n",
|
2004-06-17 04:49:34 +00:00
|
|
|
mdp->project->get_project_name()
|
2004-04-01 23:19:13 +00:00
|
|
|
);
|
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("</msg>\n");
|
2004-04-01 23:19:13 +00:00
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("</msgs>\n");
|
2004-04-01 23:19:13 +00:00
|
|
|
}
|
|
|
|
|
2004-09-05 18:46:19 +00:00
|
|
|
// <retry_file_transfer>
|
|
|
|
// <project_url>XXX</project_url>
|
|
|
|
// <filename>XXX</filename>
|
|
|
|
// </retry_file_transfer>
|
2004-09-26 04:16:52 +00:00
|
|
|
static void handle_file_transfer_op(char* buf, MIOFILE& fout, char* op) {
|
2004-09-05 18:46:19 +00:00
|
|
|
string filename;
|
|
|
|
|
|
|
|
PROJECT* p = get_project(buf, fout);
|
2004-10-15 19:19:03 +00:00
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-09-05 18:46:19 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f->pers_file_xfer) {
|
|
|
|
fout.printf("<error>No such transfer waiting</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-26 04:16:52 +00:00
|
|
|
if (!strcmp(op, "retry")) {
|
|
|
|
f->pers_file_xfer->next_request_time = 0;
|
|
|
|
} else if (!strcmp(op, "abort")) {
|
|
|
|
f->pers_file_xfer->abort();
|
|
|
|
} else {
|
|
|
|
fout.printf("<error>unknown op</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_result_op(char* buf, MIOFILE& fout, char* op) {
|
|
|
|
RESULT* rp;
|
|
|
|
char result_name[256];
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
PROJECT* p = get_project(buf, fout);
|
2004-10-15 19:19:03 +00:00
|
|
|
if (!p) {
|
|
|
|
fout.printf("<error>No such project</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-09-26 04:16:52 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
atp = gstate.lookup_active_task_by_result(rp);
|
|
|
|
if (!atp) {
|
|
|
|
fout.printf("<error>result is not active</error>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(op, "abort")) {
|
|
|
|
atp->abort_task("aborted via GUI RPC");
|
|
|
|
} else if (!strcmp(op, "suspend")) {
|
|
|
|
atp->suspended_via_gui = true;
|
|
|
|
} else if (!strcmp(op, "resume")) {
|
|
|
|
atp->suspended_via_gui = false;
|
|
|
|
}
|
2004-10-19 19:53:53 +00:00
|
|
|
gstate.must_schedule_cpus = true;
|
2004-09-05 18:46:19 +00:00
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
2004-10-12 00:27:48 +00:00
|
|
|
static void handle_get_host_info(char*, MIOFILE& fout) {
|
|
|
|
gstate.host_info.write(fout);
|
|
|
|
}
|
|
|
|
|
2004-11-14 08:29:32 +00:00
|
|
|
static void handle_get_screensaver_mode(char*, MIOFILE& fout) {
|
2004-11-17 09:27:06 +00:00
|
|
|
int ss_result = gstate.ss_logic.get_ss_status();
|
|
|
|
fout.printf(
|
|
|
|
"<screensaver_mode>\n"
|
|
|
|
" <status>%d</status>\n"
|
|
|
|
"</screensaver_mode>\n",
|
|
|
|
ss_result
|
|
|
|
);
|
2004-11-14 08:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_screensaver_mode(char* buf, MIOFILE& fout) {
|
|
|
|
double blank_time = 0.0;
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG gm;
|
2004-11-15 06:44:50 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
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));
|
2004-11-14 08:29:32 +00:00
|
|
|
if (match_tag(buf, "<enabled")) {
|
2004-11-17 19:19:26 +00:00
|
|
|
gstate.ss_logic.start_ss(gm, blank_time );
|
2004-11-17 10:25:39 +00:00
|
|
|
} else {
|
|
|
|
gstate.ss_logic.stop_ss();
|
2004-11-14 08:29:32 +00:00
|
|
|
}
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
2004-11-19 08:11:49 +00:00
|
|
|
static void handle_quit(char* buf, MIOFILE& fout) {
|
|
|
|
gstate.requested_exit = true;
|
|
|
|
fout.printf("<success/>\n");
|
|
|
|
}
|
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
int GUI_RPC_CONN::handle_rpc() {
|
2004-11-24 22:00:10 +00:00
|
|
|
char request_msg[4096];
|
2004-01-21 07:07:16 +00:00
|
|
|
int n;
|
2004-06-12 04:45:36 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
MFILE m;
|
|
|
|
char* p;
|
2004-11-09 17:28:22 +00:00
|
|
|
int client_version;
|
2004-06-12 04:45:36 +00:00
|
|
|
mf.init_mfile(&m);
|
2004-01-21 07:07:16 +00:00
|
|
|
|
2004-06-11 20:52:27 +00:00
|
|
|
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_GUIRPC);
|
|
|
|
|
|
|
|
// read the request message in one read()
|
2004-09-05 18:46:19 +00:00
|
|
|
// so that the core client won't hang because
|
|
|
|
// of malformed request msgs
|
|
|
|
//
|
2004-06-10 21:58:57 +00:00
|
|
|
#ifdef _WIN32
|
2004-11-24 22:00:10 +00:00
|
|
|
n = recv(sock, request_msg, 4095, 0);
|
2004-06-10 21:58:57 +00:00
|
|
|
#else
|
2004-11-24 22:00:10 +00:00
|
|
|
n = read(sock, request_msg, 4095);
|
2004-06-10 21:58:57 +00:00
|
|
|
#endif
|
2004-01-21 07:07:16 +00:00
|
|
|
if (n <= 0) return -1;
|
2004-06-12 04:45:36 +00:00
|
|
|
request_msg[n] = 0;
|
2004-06-14 18:37:46 +00:00
|
|
|
|
2004-06-14 23:03:49 +00:00
|
|
|
scope_messages.printf("GUI RPC Command = '%s'\n", request_msg);
|
2004-06-14 18:37:46 +00:00
|
|
|
|
2004-11-09 17:28:22 +00:00
|
|
|
// get client version. not used for now
|
|
|
|
//
|
|
|
|
parse_int(request_msg, "<version>", client_version);
|
|
|
|
|
|
|
|
mf.printf(
|
|
|
|
"<boinc_gui_rpc_reply>\n"
|
|
|
|
"<version>%d</version>\n",
|
|
|
|
gstate.version()
|
|
|
|
);
|
2004-06-12 04:45:36 +00:00
|
|
|
if (match_tag(request_msg, "<get_state")) {
|
2004-07-13 23:51:09 +00:00
|
|
|
gstate.write_state_gui(mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_results")) {
|
2004-07-13 23:51:09 +00:00
|
|
|
gstate.write_tasks_gui(mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_file_transfers")) {
|
2004-07-13 23:51:09 +00:00
|
|
|
gstate.write_file_transfers_gui(mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_project_status")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_get_project_status(mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_disk_usage")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_get_disk_usage(mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<result_show_graphics")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_result_show_graphics(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<project_reset")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_project_op(request_msg, mf, "reset");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<project_attach")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_project_attach(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<project_detach")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_project_op(request_msg, mf, "detach");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<project_update")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_project_op(request_msg, mf, "update");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<project_suspend")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_project_op(request_msg, mf, "suspend");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<project_resume")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_project_op(request_msg, mf, "resume");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<set_run_mode")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_set_run_mode(request_msg, mf);
|
2004-12-30 03:03:26 +00:00
|
|
|
} 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");
|
2004-09-05 18:46:19 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_run_mode")) {
|
|
|
|
handle_get_run_mode(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<set_network_mode")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_set_network_mode(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_network_mode")) {
|
2004-09-05 18:51:41 +00:00
|
|
|
handle_get_network_mode(request_msg, mf);
|
2004-09-05 18:46:19 +00:00
|
|
|
} else if (match_tag(request_msg, "<run_benchmarks")) {
|
|
|
|
handle_run_benchmarks(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<set_proxy_settings")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_set_proxy_settings(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_proxy_settings")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_get_proxy_settings(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_messages")) {
|
2004-09-05 18:46:19 +00:00
|
|
|
handle_get_messages(request_msg, mf);
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<retry_file_transfer")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_file_transfer_op(request_msg, mf, "retry");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<abort_file_transfer")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_file_transfer_op(request_msg, mf, "abort");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<abort_result")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_result_op(request_msg, mf, "abort");
|
2004-10-19 19:53:53 +00:00
|
|
|
} else if (match_tag(request_msg, "<suspend_result")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_result_op(request_msg, mf, "suspend");
|
2004-10-11 04:36:47 +00:00
|
|
|
} else if (match_tag(request_msg, "<resume_result")) {
|
2004-09-26 04:16:52 +00:00
|
|
|
handle_result_op(request_msg, mf, "resume");
|
2004-10-12 00:27:48 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_host_info")) {
|
|
|
|
handle_get_host_info(request_msg, mf);
|
2004-11-14 08:29:32 +00:00
|
|
|
} else if (match_tag(request_msg, "<get_screensaver_mode")) {
|
|
|
|
handle_get_screensaver_mode(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<set_screensaver_mode")) {
|
|
|
|
handle_set_screensaver_mode(request_msg, mf);
|
2004-11-19 08:11:49 +00:00
|
|
|
} else if (match_tag(request_msg, "<quit")) {
|
|
|
|
handle_quit(request_msg, mf);
|
2004-01-21 07:07:16 +00:00
|
|
|
} else {
|
2004-10-11 04:36:47 +00:00
|
|
|
mf.printf("<error>unrecognized op</error>\n");
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-06-10 21:58:57 +00:00
|
|
|
|
2004-11-09 17:28:22 +00:00
|
|
|
mf.printf("</boinc_gui_rpc_reply>\n\003");
|
2004-06-12 04:45:36 +00:00
|
|
|
m.get_buf(p, n);
|
|
|
|
send(sock, p, n, 0);
|
2004-06-17 21:37:59 +00:00
|
|
|
if (p) free(p);
|
2004-06-10 21:58:57 +00:00
|
|
|
|
2004-04-01 23:19:13 +00:00
|
|
|
return 0;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
2004-07-10 07:27:00 +00:00
|
|
|
int GUI_RPC_CONN_SET::get_allowed_hosts() {
|
|
|
|
|
|
|
|
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_STATE);
|
|
|
|
|
|
|
|
// add localhost
|
|
|
|
allowed_remote_ip_addresses.push_back(0x7f000001);
|
|
|
|
|
|
|
|
NET_XFER temp; // network address resolver is in this class
|
|
|
|
int ipaddr;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
// open file remote_hosts.cfg and read in the
|
|
|
|
// allowed host list and resolve them to an ip address
|
|
|
|
//
|
|
|
|
FILE* f = fopen(REMOTEHOST_FILE_NAME, "r");
|
|
|
|
if (f != NULL) {
|
|
|
|
scope_messages.printf(
|
|
|
|
"GUI_RPC_CONN_SET::get_allowed_hosts(): found allowed hosts list\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
// read in each line, if it is not a comment
|
|
|
|
// then resolve the address and add to our
|
|
|
|
// allowed list
|
|
|
|
memset(buf,0,sizeof(buf));
|
|
|
|
while (fgets(buf, 256, f) != NULL) {
|
|
|
|
strip_whitespace(buf);
|
|
|
|
if (!(buf[0] =='#' || buf[0] == ';') && strlen(buf) > 0 ) {
|
|
|
|
// resolve and add
|
|
|
|
if (temp.get_ip_addr(buf, ipaddr) == 0) {
|
|
|
|
allowed_remote_ip_addresses.push_back((int)ntohl(ipaddr));
|
2004-09-05 18:46:19 +00:00
|
|
|
}
|
2004-07-10 07:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
int GUI_RPC_CONN_SET::insert(GUI_RPC_CONN* p) {
|
|
|
|
gui_rpcs.push_back(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-05 21:15:34 +00:00
|
|
|
int GUI_RPC_CONN_SET::init() {
|
2004-09-05 18:46:19 +00:00
|
|
|
sockaddr_in addr;
|
2004-01-21 07:07:16 +00:00
|
|
|
int retval;
|
|
|
|
|
2004-07-10 07:27:00 +00:00
|
|
|
// get list of hosts allowed to do GUI RPCs
|
|
|
|
//
|
|
|
|
get_allowed_hosts();
|
|
|
|
|
2004-04-15 20:42:15 +00:00
|
|
|
lsock = socket(AF_INET, SOCK_STREAM, 0);
|
2004-06-12 04:45:36 +00:00
|
|
|
if (lsock < 0) {
|
|
|
|
msg_printf(NULL, MSG_ERROR,
|
2004-07-21 21:30:25 +00:00
|
|
|
"GUI RPC failed to create socket: %d\n", lsock
|
2004-06-12 04:45:36 +00:00
|
|
|
);
|
2004-05-05 21:15:34 +00:00
|
|
|
return ERR_SOCKET;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-04-15 20:42:15 +00:00
|
|
|
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(GUI_RPC_PORT);
|
|
|
|
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int one = 1;
|
|
|
|
setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char*)&one, 4);
|
|
|
|
|
2004-11-12 19:55:36 +00:00
|
|
|
retval = bind(lsock, (const sockaddr*)(&addr), (socklen_t)sizeof(addr));
|
2004-01-21 07:07:16 +00:00
|
|
|
if (retval) {
|
2004-07-21 21:30:25 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "GUI RPC bind failed: %d\n", retval);
|
2004-08-16 09:41:02 +00:00
|
|
|
boinc_close_socket(lsock);
|
|
|
|
lsock = -1;
|
2004-05-05 21:15:34 +00:00
|
|
|
return ERR_BIND;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
retval = listen(lsock, 999);
|
|
|
|
if (retval) {
|
2004-07-21 21:30:25 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "GUI RPC listen failed: %d\n", retval);
|
2004-08-16 09:41:02 +00:00
|
|
|
boinc_close_socket(lsock);
|
|
|
|
lsock = -1;
|
2004-05-05 21:15:34 +00:00
|
|
|
return ERR_LISTEN;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-05-12 21:21:09 +00:00
|
|
|
return 0;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-14 22:01:05 +00:00
|
|
|
bool GUI_RPC_CONN_SET::poll(double) {
|
2004-06-09 18:17:25 +00:00
|
|
|
int n = 0;
|
2004-08-16 09:41:02 +00:00
|
|
|
unsigned int i;
|
|
|
|
fd_set read_fds, error_fds;
|
|
|
|
int sock, retval;
|
|
|
|
vector<GUI_RPC_CONN*>::iterator iter;
|
|
|
|
GUI_RPC_CONN* gr;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
if (lsock < 0) return false;
|
|
|
|
FD_ZERO(&read_fds);
|
|
|
|
FD_ZERO(&error_fds);
|
|
|
|
FD_SET(lsock, &read_fds);
|
|
|
|
for (i=0; i<gui_rpcs.size(); i++) {
|
|
|
|
gr = gui_rpcs[i];
|
|
|
|
FD_SET(gr->sock, &read_fds);
|
|
|
|
FD_SET(gr->sock, &error_fds);
|
|
|
|
}
|
2004-06-09 18:17:25 +00:00
|
|
|
|
2004-08-16 09:41:02 +00:00
|
|
|
memset(&tv, 0, sizeof(tv));
|
|
|
|
n = select(FD_SETSIZE, &read_fds, 0, &error_fds, &tv);
|
|
|
|
if (FD_ISSET(lsock, &read_fds)) {
|
|
|
|
struct sockaddr_in addr;
|
2004-01-21 07:07:16 +00:00
|
|
|
|
2004-08-16 09:41:02 +00:00
|
|
|
socklen_t addr_len = sizeof(addr);
|
|
|
|
sock = accept(lsock, (struct sockaddr*)&addr, &addr_len);
|
2004-07-15 20:05:04 +00:00
|
|
|
|
2004-08-16 09:41:02 +00:00
|
|
|
int peer_ip = (int) ntohl(addr.sin_addr.s_addr);
|
2004-07-15 20:05:04 +00:00
|
|
|
|
2004-08-16 09:41:02 +00:00
|
|
|
// check list of allowed remote hosts
|
|
|
|
bool allowed = false;
|
|
|
|
vector<int>::iterator remote_iter;
|
2004-07-10 07:27:00 +00:00
|
|
|
|
2004-08-16 09:41:02 +00:00
|
|
|
remote_iter = allowed_remote_ip_addresses.begin();
|
|
|
|
while (remote_iter != allowed_remote_ip_addresses.end() ) {
|
|
|
|
int remote_host = *remote_iter;
|
|
|
|
if (peer_ip == remote_host) allowed = true;
|
|
|
|
remote_iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accept the connection if:
|
|
|
|
// 1) allow_remote_gui_rpc is set or
|
|
|
|
// 2) client host is included in "remote_hosts" file or
|
|
|
|
// 3) client is on localhost
|
|
|
|
//
|
|
|
|
if ( !(gstate.allow_remote_gui_rpc) && !(allowed)) {
|
|
|
|
in_addr ia;
|
|
|
|
ia.s_addr = htonl(peer_ip);
|
|
|
|
msg_printf(
|
|
|
|
NULL, MSG_ERROR,
|
|
|
|
"GUI RPC request from non-allowed address %s\n",
|
|
|
|
inet_ntoa(ia)
|
|
|
|
);
|
|
|
|
boinc_close_socket(sock);
|
|
|
|
} else {
|
|
|
|
GUI_RPC_CONN* gr = new GUI_RPC_CONN(sock);
|
|
|
|
insert(gr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iter = gui_rpcs.begin();
|
|
|
|
while (iter != gui_rpcs.end()) {
|
|
|
|
gr = *iter;
|
|
|
|
if (FD_ISSET(gr->sock, &error_fds)) {
|
|
|
|
delete gr;
|
|
|
|
gui_rpcs.erase(iter);
|
|
|
|
} else {
|
|
|
|
iter++;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-08-16 09:41:02 +00:00
|
|
|
}
|
|
|
|
iter = gui_rpcs.begin();
|
|
|
|
while (iter != gui_rpcs.end()) {
|
|
|
|
gr = *iter;
|
|
|
|
if (FD_ISSET(gr->sock, &read_fds)) {
|
|
|
|
retval = gr->handle_rpc();
|
|
|
|
if (retval) {
|
2004-01-21 07:07:16 +00:00
|
|
|
delete gr;
|
|
|
|
gui_rpcs.erase(iter);
|
2004-08-16 09:41:02 +00:00
|
|
|
continue;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-16 09:41:02 +00:00
|
|
|
iter++;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-08-16 09:41:02 +00:00
|
|
|
return (n > 0);
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
static volatile const char __attribute__((unused)) *BOINCrcsid="$Id$";
|
|
|
|
#else
|
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
|
|
|
#endif
|