2005-02-10 22:26:31 +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.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
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"
|
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
|
|
|
--lookup_account URL email passwd\n\
|
|
|
|
--create_account URL email passwd name\n\
|
|
|
|
--project_attach URL auth attach to project\n\
|
|
|
|
--join_acct_mgr URL name passwd attach account manager\n\
|
|
|
|
--quit_acct_mgr quit current account manager\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
--get_state show entire state\n\
|
|
|
|
--get_results show results\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
--get_simple_gui_info show status of projects and active results\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
--get_file_transfers show file transfers\n\
|
|
|
|
--get_project_status show status of all attached projects\n\
|
|
|
|
--get_disk_usage show disk usage\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
--get_proxy_settings\n\
|
|
|
|
--get_messages seqno show messages > seqno\n\
|
|
|
|
--get_host_info\n\
|
|
|
|
--version, -V show core client version\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
--result url result_name op job operation\n\
|
|
|
|
op = suspend | resume | abort | graphics_window | graphics_fullscreen\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\
|
2007-09-08 21:34:20 +00:00
|
|
|
--file_transfer URL filename op file transfer operation\n\
|
2007-04-23 16:14:47 +00:00
|
|
|
op = retry | abort\n\
|
|
|
|
--set_run_mode mode duration set run mode for given duration\n\
|
|
|
|
mode = always | auto | never\n\
|
|
|
|
--set_network_mode mode duration\n\
|
2005-05-27 22:01:49 +00:00
|
|
|
--set_proxy_settings\n\
|
|
|
|
--run_benchmarks\n\
|
2007-05-31 08:33:17 +00:00
|
|
|
--read_global_prefs_override\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
--quit\n\
|
2007-04-11 18:05:26 +00:00
|
|
|
--read_cc_config\n\
|
2007-09-08 21:34:20 +00:00
|
|
|
--set_debts URL1 std1 ltd1 [URL2 std2 ltd2 ...]\n\
|
|
|
|
--get_project_config URL\n\
|
|
|
|
--get_project_config_poll\n\
|
2007-05-11 00:42:13 +00:00
|
|
|
--network_available\n\
|
|
|
|
--get_cc_status\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-04-04 21:14:49 +00:00
|
|
|
void parse_display_args(char** argv, int& i, DISPLAY_INFO& di) {
|
2005-02-15 06:32:43 +00:00
|
|
|
strcpy(di.window_station, "winsta0");
|
|
|
|
strcpy(di.desktop, "default");
|
|
|
|
strcpy(di.display, "");
|
|
|
|
while (argv[i]) {
|
|
|
|
if (!strcmp(argv[i], "--window_station")) {
|
2007-03-13 19:33:27 +00:00
|
|
|
strlcpy(di.window_station, argv[++i], sizeof(di.window_station));
|
2005-02-15 06:32:43 +00:00
|
|
|
} else if (!strcpy(argv[i], "--desktop")) {
|
2007-03-13 19:33:27 +00:00
|
|
|
strlcpy(di.desktop, argv[++i], sizeof(di.desktop));
|
2005-02-15 06:32:43 +00:00
|
|
|
} else if (!strcpy(argv[i], "--display")) {
|
2007-03-13 19:33:27 +00:00
|
|
|
strlcpy(di.display, argv[++i], sizeof(di.display));
|
2005-02-15 06:32:43 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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++];
|
|
|
|
}
|
|
|
|
|
2005-05-27 22:01:49 +00:00
|
|
|
|
2005-10-26 05:43:36 +00:00
|
|
|
// If there's a password file, read it
|
|
|
|
//
|
|
|
|
void read_password_from_file(char* buf) {
|
|
|
|
FILE* f = fopen("gui_rpc_auth.cfg", "r");
|
|
|
|
if (!f) return;
|
2007-03-20 00:40:40 +00:00
|
|
|
char* p = fgets(buf, 256, f);
|
|
|
|
if (p) { // Fixes compiler warning
|
|
|
|
int n = (int)strlen(buf);
|
|
|
|
|
|
|
|
// trim CR
|
|
|
|
//
|
|
|
|
if (n && buf[n-1]=='\n') {
|
|
|
|
buf[n-1] = 0;
|
|
|
|
}
|
2005-10-26 05:43:36 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
2005-05-27 22:01:49 +00:00
|
|
|
|
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;
|
2005-12-13 08:04:57 +00:00
|
|
|
char passwd_buf[256], hostname_buf[256], *hostname=0;
|
|
|
|
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
|
2005-10-26 05:43:36 +00:00
|
|
|
strcpy(passwd_buf, "");
|
|
|
|
read_password_from_file(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) {
|
2005-12-13 08:04:57 +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
|
|
|
|
|
2005-03-07 06:09:04 +00:00
|
|
|
if (passwd) {
|
|
|
|
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();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_results")) {
|
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();
|
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")) {
|
|
|
|
SIMPLE_GUI_INFO sgi;
|
|
|
|
retval = rpc.get_simple_gui_info(sgi);
|
|
|
|
if (!retval) sgi.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();
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--result")) {
|
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);
|
|
|
|
result.project_url = project_url;
|
2005-05-27 22:01:49 +00:00
|
|
|
char* name = next_arg(argc, argv, i);
|
2005-04-03 22:01:18 +00:00
|
|
|
result.name = name;
|
|
|
|
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 if (!strcmp(op, "graphics_window")) {
|
2005-02-15 06:32:43 +00:00
|
|
|
DISPLAY_INFO di;
|
2005-04-04 21:14:49 +00:00
|
|
|
parse_display_args(argv, i, di);
|
2006-03-27 03:44:13 +00:00
|
|
|
retval = rpc.show_graphics(project_url, name, MODE_WINDOW, di);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(op, "graphics_fullscreen")) {
|
2005-02-15 06:32:43 +00:00
|
|
|
DISPLAY_INFO di;
|
2005-04-04 21:14:49 +00:00
|
|
|
parse_display_args(argv, i, di);
|
2006-03-27 03:44:13 +00:00
|
|
|
retval = rpc.show_graphics(project_url, name, MODE_FULLSCREEN, di);
|
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;
|
2005-04-03 22:01:18 +00:00
|
|
|
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
|
|
|
}
|
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);
|
2005-02-10 22:26:31 +00:00
|
|
|
retval = rpc.set_proxy_settings(pi);
|
2005-04-03 22:01:18 +00:00
|
|
|
} else if (!strcmp(cmd, "--get_messages")) {
|
|
|
|
int 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];
|
2005-02-10 22:26:31 +00:00
|
|
|
printf("%s %d %d %s\n",
|
|
|
|
md.project.c_str(), md.priority,
|
|
|
|
md.timestamp, md.body.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 {
|
2007-06-20 22:34:06 +00:00
|
|
|
unsigned int j, n = 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));
|
|
|
|
} else if (!strcmp(cmd, "--get_project_config_poll")) {
|
|
|
|
PROJECT_CONFIG pc;
|
|
|
|
retval = rpc.get_project_config_poll(pc);
|
|
|
|
if (retval) {
|
|
|
|
printf("retval: %d\n", retval);
|
|
|
|
} else {
|
|
|
|
pc.print();
|
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
}
|
2007-05-26 21:15:58 +00:00
|
|
|
} else if (!strcmp(cmd, "--set_debts")) {
|
|
|
|
vector<PROJECT>projects;
|
|
|
|
while (i < argc) {
|
2007-06-20 22:34:06 +00:00
|
|
|
PROJECT proj;
|
|
|
|
proj.master_url = string(next_arg(argc, argv, i));
|
|
|
|
proj.short_term_debt = atoi(next_arg(argc, argv, i));
|
|
|
|
proj.long_term_debt = atoi(next_arg(argc, argv, i));
|
|
|
|
projects.push_back(proj);
|
2007-05-26 21:15:58 +00:00
|
|
|
}
|
|
|
|
retval = rpc.set_debts(projects);
|
|
|
|
} else if (!strcmp(cmd, "--quit")) {
|
|
|
|
retval = rpc.quit();
|
2005-02-10 22:26:31 +00:00
|
|
|
} else {
|
2005-04-03 22:01:18 +00:00
|
|
|
fprintf(stderr, "unrecognized command %s\n", cmd);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
const char *BOINC_RCSID_77f00010ab = "$Id$";
|