2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-02-10 22:26:31 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-02-10 22:26:31 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2005-02-10 22:26:31 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-02-10 22:26:31 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2008-04-30 21:59:46 +00:00
|
|
|
// boinccmd: command-line interface to a BOINC core client,
|
2005-02-10 22:26:31 +00:00
|
|
|
// using GUI RPCs.
|
|
|
|
//
|
2008-04-30 21:59:46 +00:00
|
|
|
// usage: boinccmd [--host hostname] [--passwd passwd] command
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
2005-02-10 22:26:31 +00:00
|
|
|
#include "boinc_win.h"
|
2005-07-14 16:46:38 +00:00
|
|
|
#endif
|
|
|
|
|
2008-05-22 03:57:55 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "win_util.h"
|
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2005-04-09 00:39:31 +00:00
|
|
|
#include <cstdio>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2005-04-09 00:39:31 +00:00
|
|
|
#include <unistd.h>
|
2005-02-10 22:26:31 +00:00
|
|
|
#endif
|
2005-04-09 00:39:31 +00:00
|
|
|
|
2005-02-10 22:26:31 +00:00
|
|
|
#include <vector>
|
2007-03-10 18:47:39 +00:00
|
|
|
#include <string>
|
2005-02-10 22:26:31 +00:00
|
|
|
using std::vector;
|
2005-08-07 01:33:15 +00:00
|
|
|
using std::string;
|
2005-02-10 22:26:31 +00:00
|
|
|
|
|
|
|
#include "gui_rpc_client.h"
|
|
|
|
#include "error_numbers.h"
|
2005-05-31 21:59:29 +00:00
|
|
|
#include "util.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2009-06-16 20:54:44 +00:00
|
|
|
#include "str_replace.h"
|
2009-11-05 18:02:51 +00:00
|
|
|
#include "url.h"
|
2005-05-27 22:01:49 +00:00
|
|
|
#include "version.h"
|
2006-09-01 21:06:30 +00:00
|
|
|
#include "common_defs.h"
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2005-05-27 22:01:49 +00:00
|
|
|
void version(){
|
2008-04-30 21:59:46 +00:00
|
|
|
printf("boinccmd, built from %s \n", PACKAGE_STRING );
|
2005-10-26 05:43:36 +00:00
|
|
|
exit(0);
|
2005-05-27 22:01:49 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 20:16:10 +00:00
|
|
|
void usage() {
|
2007-04-23 16:14:47 +00:00
|
|
|
fprintf(stderr, "\n\
|
2008-04-30 21:59:46 +00:00
|
|
|
usage: boinccmd [--host hostname] [--passwd passwd] command\n\n\
|
2005-05-27 22:01:49 +00:00
|
|
|
Commands:\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
--create_account URL email passwd name\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--file_transfer URL filename op file transfer operation\n\
|
|
|
|
op = retry | abort\n\
|
|
|
|
--get_cc_status\n\
|
2011-10-06 17:23:16 +00:00
|
|
|
--get_daily_xfer_history show network traffic history\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
--get_disk_usage show disk usage\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--get_file_transfers show file transfers\n\
|
|
|
|
--get_host_info\n\
|
2009-07-07 22:58:58 +00:00
|
|
|
--get_message_count show largest message seqno\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--get_messages [ seqno ] show messages > seqno\n\
|
2010-01-07 04:55:11 +00:00
|
|
|
--get_notices [ seqno ] show notices > seqno\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--get_project_config URL\n\
|
|
|
|
--get_project_status show status of all attached projects\n\
|
|
|
|
--get_proxy_settings\n\
|
|
|
|
--get_simple_gui_info show status of projects and active tasks\n\
|
|
|
|
--get_state show entire state\n\
|
|
|
|
--get_tasks show tasks\n\
|
|
|
|
--join_acct_mgr URL name passwd attach account manager\n\
|
|
|
|
--lookup_account URL email passwd\n\
|
2011-07-19 20:52:41 +00:00
|
|
|
--network_available retry deferred network communication\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
--project URL op project operation\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
op = reset | detach | update | suspend | resume | nomorework | allowmorework\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--project_attach URL auth attach to project\n\
|
|
|
|
--quit tell client to exit\n\
|
|
|
|
--quit_acct_mgr quit current account manager\n\
|
|
|
|
--read_cc_config\n\
|
|
|
|
--read_global_prefs_override\n\
|
|
|
|
--run_benchmarks\n\
|
|
|
|
--set_debts URL1 std1 ltd1 [URL2 std2 ltd2 ...]\n\
|
2010-03-25 23:48:58 +00:00
|
|
|
--set_gpu_mode mode duration set GPU run mode for given duration\n\
|
|
|
|
mode = always | auto | never\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
--set_network_mode mode duration\n\
|
2005-05-27 22:01:49 +00:00
|
|
|
--set_proxy_settings\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--set_run_mode mode duration set run mode for given duration\n\
|
|
|
|
mode = always | auto | never\n\
|
|
|
|
--task url task_name op task operation\n\
|
2011-10-14 19:02:43 +00:00
|
|
|
op = suspend | resume | abort\n\
|
2010-11-10 18:17:20 +00:00
|
|
|
--version, -V show core client version\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
"
|
2007-04-23 16:14:47 +00:00
|
|
|
);
|
2005-02-10 22:26:31 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-03-07 21:47:28 +00:00
|
|
|
void show_error(int retval) {
|
2005-05-31 21:59:29 +00:00
|
|
|
fprintf(stderr, "Error %d: %s\n", retval, boincerror(retval));
|
2005-03-07 21:47:28 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
char* next_arg(int argc, char** argv, int& i) {
|
|
|
|
if (i >= argc) {
|
|
|
|
fprintf(stderr, "Missing command-line argument\n");
|
2008-03-05 20:16:10 +00:00
|
|
|
usage();
|
2005-04-03 22:01:18 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return argv[i++];
|
|
|
|
}
|
|
|
|
|
2009-04-03 21:55:26 +00:00
|
|
|
const char* prio_name(int prio) {
|
2009-02-27 00:53:15 +00:00
|
|
|
switch (prio) {
|
2009-11-24 05:26:45 +00:00
|
|
|
case MSG_INFO: return "low";
|
2010-06-29 03:23:13 +00:00
|
|
|
case MSG_USER_ALERT: return "user notification";
|
|
|
|
case MSG_INTERNAL_ERROR: return "internal error";
|
2009-02-27 00:53:15 +00:00
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2005-02-10 22:26:31 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
RPC_CLIENT rpc;
|
2005-12-13 08:04:57 +00:00
|
|
|
int i, retval, port=0;
|
2005-02-10 22:26:31 +00:00
|
|
|
MESSAGES messages;
|
2010-01-07 04:55:11 +00:00
|
|
|
NOTICES notices;
|
2011-01-06 23:09:13 +00:00
|
|
|
char passwd_buf[256], hostname_buf[256], *hostname=0;
|
2005-12-13 08:04:57 +00:00
|
|
|
char* passwd = passwd_buf, *p;
|
2005-10-26 05:43:36 +00:00
|
|
|
|
2008-05-22 03:09:11 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
chdir_to_data_dir();
|
|
|
|
#endif
|
2011-01-06 23:09:13 +00:00
|
|
|
strcpy(passwd_buf, "");
|
|
|
|
read_gui_rpc_password(passwd_buf);
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && defined(USE_WINSOCK)
|
2005-02-10 22:26:31 +00:00
|
|
|
WSADATA wsdata;
|
|
|
|
retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "WinsockInitialize: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (argc < 2) usage();
|
|
|
|
i = 1;
|
2008-03-05 20:16:10 +00:00
|
|
|
if (!strcmp(argv[i], "--help")) usage();
|
|
|
|
if (!strcmp(argv[i], "-h")) usage();
|
2005-05-27 22:01:49 +00:00
|
|
|
if (!strcmp(argv[i], "--version")) version();
|
|
|
|
if (!strcmp(argv[i], "-V")) version();
|
|
|
|
|
2005-03-07 06:09:04 +00:00
|
|
|
if (!strcmp(argv[i], "--host")) {
|
2005-04-19 20:53:04 +00:00
|
|
|
if (++i == argc) usage();
|
2007-03-13 19:33:27 +00:00
|
|
|
strlcpy(hostname_buf, argv[i], sizeof(hostname_buf));
|
2005-12-13 08:04:57 +00:00
|
|
|
hostname = hostname_buf;
|
|
|
|
p = strchr(hostname, ':');
|
|
|
|
if (p) {
|
|
|
|
port = atoi(p+1);
|
|
|
|
*p=0;
|
|
|
|
}
|
2005-04-19 20:53:04 +00:00
|
|
|
i++;
|
2005-03-07 06:09:04 +00:00
|
|
|
}
|
2005-04-19 20:53:04 +00:00
|
|
|
if ((i<argc)&& !strcmp(argv[i], "--passwd")) {
|
|
|
|
if (++i == argc) usage();
|
|
|
|
passwd = argv[i];
|
|
|
|
i++;
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-15 18:50:11 +00:00
|
|
|
|
|
|
|
// change the following to debug GUI RPC's asynchronous connection mechanism
|
|
|
|
//
|
2005-04-09 00:39:31 +00:00
|
|
|
#if 1
|
2005-12-13 08:04:57 +00:00
|
|
|
retval = rpc.init(hostname, port);
|
2005-02-10 22:26:31 +00:00
|
|
|
if (retval) {
|
2010-09-12 01:10:39 +00:00
|
|
|
fprintf(stderr, "can't connect to %s\n", hostname?hostname:"local host");
|
2005-02-10 22:26:31 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2005-04-09 00:39:31 +00:00
|
|
|
#else
|
2005-05-25 19:26:37 +00:00
|
|
|
retval = rpc.init_asynch(hostname, 60., false);
|
2005-04-09 00:39:31 +00:00
|
|
|
while (1) {
|
|
|
|
retval = rpc.init_poll();
|
|
|
|
if (!retval) break;
|
|
|
|
if (retval == ERR_RETRY) {
|
|
|
|
printf("sleeping\n");
|
|
|
|
sleep(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "can't connect: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
printf("connected\n");
|
|
|
|
#endif
|
|
|
|
|
2010-05-19 16:55:57 +00:00
|
|
|
if (strlen(passwd)) {
|
2005-03-07 06:09:04 +00:00
|
|
|
retval = rpc.authorize(passwd);
|
|
|
|
if (retval) {
|
2005-03-07 21:47:28 +00:00
|
|
|
fprintf(stderr, "Authorization failure: %d\n", retval);
|
2005-03-07 06:09:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-02-10 22:26:31 +00:00
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
char* cmd = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(cmd, "--get_state")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
CC_STATE state;
|
|
|
|
retval = rpc.get_state(state);
|
|
|
|
if (!retval) state.print();
|
2010-03-03 22:36:36 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_tasks")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
RESULTS results;
|
|
|
|
retval = rpc.get_results(results);
|
|
|
|
if (!retval) results.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_file_transfers")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
FILE_TRANSFERS ft;
|
|
|
|
retval = rpc.get_file_transfers(ft);
|
|
|
|
if (!retval) ft.print();
|
2011-10-06 17:23:16 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_daily_xfer_history")) {
|
|
|
|
DAILY_XFER_HISTORY dxh;
|
|
|
|
retval = rpc.get_daily_xfer_history(dxh);
|
|
|
|
if (!retval) dxh.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_project_status")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROJECTS ps;
|
|
|
|
retval = rpc.get_project_status(ps);
|
|
|
|
if (!retval) ps.print();
|
2006-06-27 21:46:50 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_simple_gui_info")) {
|
2009-04-30 21:48:20 +00:00
|
|
|
SIMPLE_GUI_INFO info;
|
|
|
|
retval = rpc.get_simple_gui_info(info);
|
|
|
|
if (!retval) info.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_disk_usage")) {
|
2006-11-03 17:08:49 +00:00
|
|
|
DISK_USAGE du;
|
|
|
|
retval = rpc.get_disk_usage(du);
|
|
|
|
if (!retval) du.print();
|
2010-03-03 22:36:36 +00:00
|
|
|
} else if (!strcmp(cmd, "--task")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
RESULT result;
|
2005-04-03 22:01:18 +00:00
|
|
|
char* project_url = next_arg(argc, argv, i);
|
2010-03-12 17:47:17 +00:00
|
|
|
strcpy(result.project_url, project_url);
|
2005-05-27 22:01:49 +00:00
|
|
|
char* name = next_arg(argc, argv, i);
|
2010-03-12 17:47:17 +00:00
|
|
|
strcpy(result.name, name);
|
2005-04-03 22:01:18 +00:00
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "suspend")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.result_op(result, "suspend");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "resume")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.result_op(result, "resume");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "abort")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.result_op(result, "abort");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--project")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
PROJECT project;
|
2010-03-12 17:47:17 +00:00
|
|
|
strcpy(project.master_url, next_arg(argc, argv, i));
|
2007-05-18 22:02:51 +00:00
|
|
|
canonicalize_master_url(project.master_url);
|
2005-04-03 22:01:18 +00:00
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "reset")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "reset");
|
2006-03-30 00:45:24 +00:00
|
|
|
} else if (!strcmp(op, "suspend")) {
|
|
|
|
retval = rpc.project_op(project, "suspend");
|
|
|
|
} else if (!strcmp(op, "resume")) {
|
|
|
|
retval = rpc.project_op(project, "resume");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "detach")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "detach");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "update")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "update");
|
2006-03-26 01:06:19 +00:00
|
|
|
} else if (!strcmp(op, "suspend")) {
|
|
|
|
retval = rpc.project_op(project, "suspend");
|
|
|
|
} else if (!strcmp(op, "resume")) {
|
|
|
|
retval = rpc.project_op(project, "resume");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "nomorework")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "nomorework");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "allowmorework")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.project_op(project, "allowmorework");
|
2007-07-13 21:11:40 +00:00
|
|
|
} else if (!strcmp(op, "detach_when_done")) {
|
|
|
|
retval = rpc.project_op(project, "detach_when_done");
|
|
|
|
} else if (!strcmp(op, "dont_detach_when_done")) {
|
|
|
|
retval = rpc.project_op(project, "dont_detach_when_done");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--project_attach")) {
|
2007-05-18 22:02:51 +00:00
|
|
|
char url[256];
|
|
|
|
strcpy(url, next_arg(argc, argv, i));
|
|
|
|
canonicalize_master_url(url);
|
2005-04-03 22:01:18 +00:00
|
|
|
char* auth = next_arg(argc, argv, i);
|
2006-12-26 00:37:25 +00:00
|
|
|
retval = rpc.project_attach(url, auth, "");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--file_transfer")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
FILE_TRANSFER ft;
|
|
|
|
|
2005-04-03 22:01:18 +00:00
|
|
|
ft.project_url = next_arg(argc, argv, i);
|
|
|
|
ft.name = next_arg(argc, argv, i);
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
if (!strcmp(op, "retry")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.file_transfer_op(ft, "retry");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "abort")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.file_transfer_op(ft, "abort");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_run_mode")) {
|
|
|
|
char* op = next_arg(argc, argv, i);
|
2006-12-19 22:11:53 +00:00
|
|
|
double duration;
|
|
|
|
if (i >= argc || (argv[i][0] == '-')) {
|
|
|
|
duration = 0;
|
|
|
|
} else {
|
|
|
|
duration = atof(next_arg(argc, argv, i));
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
if (!strcmp(op, "always")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_ALWAYS, duration);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "auto")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_AUTO, duration);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "never")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
retval = rpc.set_run_mode(RUN_MODE_NEVER, duration);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2010-03-25 23:48:58 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_gpu_mode")) {
|
|
|
|
char* op = next_arg(argc, argv, i);
|
|
|
|
double duration;
|
|
|
|
if (i >= argc || (argv[i][0] == '-')) {
|
|
|
|
duration = 0;
|
|
|
|
} else {
|
|
|
|
duration = atof(next_arg(argc, argv, i));
|
|
|
|
}
|
|
|
|
if (!strcmp(op, "always")) {
|
|
|
|
retval = rpc.set_gpu_mode(RUN_MODE_ALWAYS, duration);
|
|
|
|
} else if (!strcmp(op, "auto")) {
|
|
|
|
retval = rpc.set_gpu_mode(RUN_MODE_AUTO, duration);
|
|
|
|
} else if (!strcmp(op, "never")) {
|
|
|
|
retval = rpc.set_gpu_mode(RUN_MODE_NEVER, duration);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_network_mode")) {
|
|
|
|
char* op = next_arg(argc, argv, i);
|
2006-12-19 22:11:53 +00:00
|
|
|
double duration;
|
|
|
|
if (i >= argc || (argv[i][0] == '-')) {
|
|
|
|
duration = 0;
|
|
|
|
} else {
|
|
|
|
duration = atof(next_arg(argc, argv, i));
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
if (!strcmp(op, "always")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
retval = rpc.set_network_mode(RUN_MODE_ALWAYS, duration);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "auto")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
retval = rpc.set_network_mode(RUN_MODE_AUTO, duration);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "never")) {
|
2006-11-10 17:55:22 +00:00
|
|
|
retval = rpc.set_network_mode(RUN_MODE_NEVER, duration);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown op %s\n", op);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_proxy_settings")) {
|
2005-08-01 22:44:40 +00:00
|
|
|
GR_PROXY_INFO pi;
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.get_proxy_settings(pi);
|
|
|
|
if (!retval) pi.print();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_proxy_settings")) {
|
2005-08-01 22:44:40 +00:00
|
|
|
GR_PROXY_INFO pi;
|
2005-04-03 22:01:18 +00:00
|
|
|
pi.http_server_name = next_arg(argc, argv, i);
|
|
|
|
pi.http_server_port = atoi(next_arg(argc, argv, i));
|
|
|
|
pi.http_user_name = next_arg(argc, argv, i);
|
|
|
|
pi.http_user_passwd = next_arg(argc, argv, i);
|
|
|
|
pi.socks_server_name = next_arg(argc, argv, i);
|
|
|
|
pi.socks_server_port = atoi(next_arg(argc, argv, i));
|
|
|
|
pi.socks_version = atoi(next_arg(argc, argv, i));
|
|
|
|
pi.socks5_user_name = next_arg(argc, argv, i);
|
|
|
|
pi.socks5_user_passwd = next_arg(argc, argv, i);
|
2008-09-26 17:37:32 +00:00
|
|
|
pi.noproxy_hosts = next_arg(argc, argv, i);
|
2009-02-25 19:18:41 +00:00
|
|
|
if (pi.http_server_name.size()) pi.use_http_proxy = true;
|
|
|
|
if (pi.http_user_name.size()) pi.use_http_authentication = true;
|
|
|
|
if (pi.socks_server_name.size()) pi.use_socks_proxy = true;
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_proxy_settings(pi);
|
2009-07-07 22:58:58 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_message_count")) {
|
|
|
|
int seqno;
|
|
|
|
retval = rpc.get_message_count(seqno);
|
|
|
|
if (!retval) {
|
|
|
|
printf("Greatest message sequence number: %d\n", seqno);
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_messages")) {
|
2009-02-27 00:53:15 +00:00
|
|
|
int seqno;
|
|
|
|
if (i == argc) {
|
|
|
|
seqno = 0;
|
|
|
|
} else {
|
|
|
|
seqno = atoi(next_arg(argc, argv, i));
|
|
|
|
}
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.get_messages(seqno, messages);
|
|
|
|
if (!retval) {
|
2005-03-15 20:23:24 +00:00
|
|
|
unsigned int j;
|
|
|
|
for (j=0; j<messages.messages.size(); j++) {
|
|
|
|
MESSAGE& md = *messages.messages[j];
|
2009-02-27 00:53:15 +00:00
|
|
|
strip_whitespace(md.body);
|
|
|
|
printf("%d: %s (%s) [%s] %s\n",
|
|
|
|
md.seqno,
|
|
|
|
time_to_string(md.timestamp),
|
|
|
|
prio_name(md.priority),
|
|
|
|
md.project.c_str(),
|
|
|
|
md.body.c_str()
|
2005-02-10 22:26:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2010-01-07 04:55:11 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_notices")) {
|
|
|
|
int seqno;
|
|
|
|
if (i == argc) {
|
|
|
|
seqno = 0;
|
|
|
|
} else {
|
|
|
|
seqno = atoi(next_arg(argc, argv, i));
|
|
|
|
}
|
|
|
|
retval = rpc.get_notices(seqno, notices);
|
|
|
|
if (!retval) {
|
|
|
|
unsigned int j;
|
|
|
|
for (j=0; j<notices.notices.size(); j++) {
|
|
|
|
NOTICE& n = *notices.notices[j];
|
|
|
|
strip_whitespace(n.description);
|
|
|
|
printf("%d: (%s) %s\n",
|
|
|
|
n.seqno,
|
|
|
|
time_to_string(n.create_time),
|
|
|
|
n.description.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_host_info")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
HOST_INFO hi;
|
|
|
|
retval = rpc.get_host_info(hi);
|
|
|
|
if (!retval) hi.print();
|
2007-04-06 00:37:07 +00:00
|
|
|
} else if (!strcmp(cmd, "--join_acct_mgr")) {
|
2005-04-04 21:14:49 +00:00
|
|
|
char* am_url = next_arg(argc, argv, i);
|
|
|
|
char* am_name = next_arg(argc, argv, i);
|
|
|
|
char* am_passwd = next_arg(argc, argv, i);
|
|
|
|
retval = rpc.acct_mgr_rpc(am_url, am_name, am_passwd);
|
2007-04-06 00:37:07 +00:00
|
|
|
if (!retval) {
|
|
|
|
while (1) {
|
|
|
|
ACCT_MGR_RPC_REPLY amrr;
|
|
|
|
retval = rpc.acct_mgr_rpc_poll(amrr);
|
|
|
|
if (retval) {
|
|
|
|
printf("poll status: %s\n", boincerror(retval));
|
|
|
|
} else {
|
|
|
|
if (amrr.error_num) {
|
|
|
|
printf("poll status: %s\n", boincerror(amrr.error_num));
|
|
|
|
if (amrr.error_num != ERR_IN_PROGRESS) break;
|
|
|
|
boinc_sleep(1);
|
|
|
|
} else {
|
2008-08-20 18:24:08 +00:00
|
|
|
int j, n = (int)amrr.messages.size();
|
2007-04-06 00:37:07 +00:00
|
|
|
if (n) {
|
|
|
|
printf("Messages from account manager:\n");
|
2007-06-20 22:34:06 +00:00
|
|
|
for (j=0; j<n; j++) {
|
|
|
|
printf("%s\n", amrr.messages[j].c_str());
|
2007-04-06 00:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!strcmp(cmd, "--quit_acct_mgr")) {
|
|
|
|
retval = rpc.acct_mgr_rpc("", "", "");
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--run_benchmarks")) {
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.run_benchmarks();
|
2005-08-07 01:33:15 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_project_config")) {
|
|
|
|
char* gpc_url = next_arg(argc, argv,i);
|
|
|
|
retval = rpc.get_project_config(string(gpc_url));
|
2011-03-01 06:17:54 +00:00
|
|
|
if (!retval) {
|
|
|
|
while (1) {
|
|
|
|
PROJECT_CONFIG pc;
|
|
|
|
retval = rpc.get_project_config_poll(pc);
|
|
|
|
if (retval) {
|
|
|
|
printf("poll status: %s\n", boincerror(retval));
|
|
|
|
} else {
|
|
|
|
if (pc.error_num) {
|
|
|
|
printf("poll status: %s\n", boincerror(pc.error_num));
|
|
|
|
if (pc.error_num != ERR_IN_PROGRESS) break;
|
|
|
|
boinc_sleep(1);
|
|
|
|
} else {
|
|
|
|
pc.print();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-07 01:33:15 +00:00
|
|
|
}
|
|
|
|
} else if (!strcmp(cmd, "--lookup_account")) {
|
|
|
|
ACCOUNT_IN lai;
|
|
|
|
lai.url = next_arg(argc, argv, i);
|
|
|
|
lai.email_addr = next_arg(argc, argv, i);
|
|
|
|
lai.passwd = next_arg(argc, argv, i);
|
|
|
|
retval = rpc.lookup_account(lai);
|
2007-02-24 20:10:06 +00:00
|
|
|
printf("status: %s\n", boincerror(retval));
|
|
|
|
if (!retval) {
|
|
|
|
ACCOUNT_OUT lao;
|
|
|
|
while (1) {
|
|
|
|
retval = rpc.lookup_account_poll(lao);
|
|
|
|
if (retval) {
|
|
|
|
printf("poll status: %s\n", boincerror(retval));
|
|
|
|
} else {
|
|
|
|
if (lao.error_num) {
|
|
|
|
printf("poll status: %s\n", boincerror(lao.error_num));
|
|
|
|
if (lao.error_num != ERR_IN_PROGRESS) break;
|
|
|
|
boinc_sleep(1);
|
|
|
|
} else {
|
|
|
|
lao.print();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-07 01:33:15 +00:00
|
|
|
}
|
|
|
|
} else if (!strcmp(cmd, "--create_account")) {
|
|
|
|
ACCOUNT_IN cai;
|
|
|
|
cai.url = next_arg(argc, argv, i);
|
|
|
|
cai.email_addr = next_arg(argc, argv, i);
|
|
|
|
cai.passwd = next_arg(argc, argv, i);
|
|
|
|
cai.user_name = next_arg(argc, argv, i);
|
|
|
|
retval = rpc.create_account(cai);
|
2007-02-24 20:10:06 +00:00
|
|
|
printf("status: %s\n", boincerror(retval));
|
|
|
|
if (!retval) {
|
|
|
|
ACCOUNT_OUT lao;
|
|
|
|
while (1) {
|
|
|
|
retval = rpc.create_account_poll(lao);
|
|
|
|
if (retval) {
|
|
|
|
printf("poll status: %s\n", boincerror(retval));
|
|
|
|
} else {
|
|
|
|
if (lao.error_num) {
|
|
|
|
printf("poll status: %s\n", boincerror(lao.error_num));
|
|
|
|
if (lao.error_num != ERR_IN_PROGRESS) break;
|
|
|
|
boinc_sleep(1);
|
|
|
|
} else {
|
|
|
|
lao.print();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-07 01:33:15 +00:00
|
|
|
}
|
2006-03-06 23:23:41 +00:00
|
|
|
} else if (!strcmp(cmd, "--read_global_prefs_override")) {
|
|
|
|
retval = rpc.read_global_prefs_override();
|
2006-12-17 02:48:19 +00:00
|
|
|
} else if (!strcmp(cmd, "--read_cc_config")) {
|
|
|
|
retval = rpc.read_cc_config();
|
2006-08-16 03:44:47 +00:00
|
|
|
printf("retval %d\n", retval);
|
2007-05-26 21:15:58 +00:00
|
|
|
} else if (!strcmp(cmd, "--network_available")) {
|
2007-05-11 00:42:13 +00:00
|
|
|
retval = rpc.network_available();
|
2007-05-26 21:15:58 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_cc_status")) {
|
2007-05-11 00:42:13 +00:00
|
|
|
CC_STATUS cs;
|
|
|
|
retval = rpc.get_cc_status(cs);
|
|
|
|
if (!retval) {
|
|
|
|
retval = cs.network_status;
|
|
|
|
}
|
2010-11-10 18:17:20 +00:00
|
|
|
cs.print();
|
2007-05-26 21:15:58 +00:00
|
|
|
} else if (!strcmp(cmd, "--quit")) {
|
|
|
|
retval = rpc.quit();
|
2005-02-10 22:26:31 +00:00
|
|
|
} else {
|
2010-10-07 18:08:20 +00:00
|
|
|
usage();
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
2007-05-11 00:42:13 +00:00
|
|
|
if (retval < 0) {
|
2005-03-07 21:47:28 +00:00
|
|
|
show_error(retval);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && defined(USE_WINSOCK)
|
2005-02-10 22:26:31 +00:00
|
|
|
WSACleanup();
|
|
|
|
#endif
|
2007-05-11 00:42:13 +00:00
|
|
|
exit(retval);
|
2005-02-10 22:26:31 +00:00
|
|
|
}
|
|
|
|
|