2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-09-11 17:36:37 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-09-11 17:36:37 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-09-11 17:36:37 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2002-06-06 18:50:12 +00:00
|
|
|
|
2004-03-04 11:41:43 +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
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-06-01 20:26:21 +00:00
|
|
|
#include <stdlib.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "file_names.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-23 01:44:47 +00:00
|
|
|
#include "client_state.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
|
2004-03-23 19:43:58 +00:00
|
|
|
// The following values determine how the client behaves
|
2004-03-31 23:39:12 +00:00
|
|
|
// if there are no global prefs yet (e.g. on our very first RPC).
|
|
|
|
// - Should impose minimal restrictions, so that the client can do the RPC
|
|
|
|
// and get the global prefs from the server
|
2002-09-27 06:12:50 +00:00
|
|
|
//
|
2003-03-06 00:42:18 +00:00
|
|
|
void GLOBAL_PREFS::init() {
|
2004-03-23 19:43:58 +00:00
|
|
|
run_on_batteries = true;
|
|
|
|
run_if_user_active = true;
|
2003-03-25 01:30:13 +00:00
|
|
|
start_hour = 0;
|
|
|
|
end_hour = 0;
|
2003-02-04 01:07:19 +00:00
|
|
|
run_minimized = false;
|
|
|
|
run_on_startup = false;
|
2002-06-21 06:52:47 +00:00
|
|
|
confirm_before_connecting = false;
|
2004-03-23 19:43:58 +00:00
|
|
|
hangup_if_dialed = false;
|
2004-03-06 11:40:54 +00:00
|
|
|
work_buf_max_days = 0.2;
|
|
|
|
work_buf_min_days = 0.1;
|
2004-03-31 23:39:12 +00:00
|
|
|
max_cpus = 1;
|
2003-03-20 02:05:25 +00:00
|
|
|
disk_interval = 60;
|
2002-08-22 22:28:51 +00:00
|
|
|
disk_max_used_gb = 1;
|
|
|
|
disk_max_used_pct = 0.5;
|
|
|
|
disk_min_free_gb = 0.1;
|
2003-07-29 04:56:28 +00:00
|
|
|
idle_time_to_run = 3;
|
2003-02-26 00:47:57 +00:00
|
|
|
max_bytes_sec_up = 1e9;
|
|
|
|
max_bytes_sec_down = 1e9;
|
2003-06-16 18:47:17 +00:00
|
|
|
max_memory_mbytes = 128;
|
2003-06-16 23:40:20 +00:00
|
|
|
proc_priority = 1;
|
2003-06-16 18:47:17 +00:00
|
|
|
cpu_affinity = -1;
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
GLOBAL_PREFS::GLOBAL_PREFS() {
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse XML global prefs.
|
|
|
|
// If host_venue is nonempty and we find an element of the form
|
|
|
|
// <venue name="X">
|
|
|
|
// ...
|
|
|
|
// </venue>
|
2003-09-02 23:49:53 +00:00
|
|
|
// where X==host_venue, then parse that and ignore the rest.
|
2003-03-06 00:42:18 +00:00
|
|
|
// Otherwise ignore <venue> elements.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2004-03-30 23:05:34 +00:00
|
|
|
int GLOBAL_PREFS::parse(FILE* in, char* host_venue, bool& found_venue) {
|
2003-03-06 00:42:18 +00:00
|
|
|
char buf[256], buf2[256];
|
|
|
|
bool in_venue = false, in_correct_venue=false;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-05-18 22:47:08 +00:00
|
|
|
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_STATE);
|
|
|
|
|
2003-07-29 04:56:28 +00:00
|
|
|
init();
|
2004-05-03 03:24:34 +00:00
|
|
|
source_project = "";
|
|
|
|
source_scheduler = "";
|
2003-07-29 04:56:28 +00:00
|
|
|
|
2004-03-29 22:57:43 +00:00
|
|
|
// set all booleans to false here
|
|
|
|
run_on_batteries = false;
|
|
|
|
run_if_user_active = false;
|
|
|
|
confirm_before_connecting = false;
|
|
|
|
run_minimized = false;
|
|
|
|
run_on_startup = false;
|
|
|
|
hangup_if_dialed = false;
|
|
|
|
|
2004-03-30 23:05:34 +00:00
|
|
|
found_venue = false;
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
2003-03-06 00:42:18 +00:00
|
|
|
if (in_venue) {
|
|
|
|
if (match_tag(buf, "</venue>")) {
|
|
|
|
if (in_correct_venue) {
|
2003-09-02 23:49:53 +00:00
|
|
|
break;
|
2003-03-06 00:42:18 +00:00
|
|
|
} else {
|
|
|
|
in_venue = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(!in_correct_venue) continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (match_tag(buf, "<venue")) {
|
|
|
|
in_venue = true;
|
|
|
|
parse_attr(buf, "name", buf2, sizeof(buf2));
|
|
|
|
if (!strcmp(buf2, host_venue)) {
|
|
|
|
init();
|
|
|
|
in_correct_venue = true;
|
2003-09-02 23:49:53 +00:00
|
|
|
found_venue = true;
|
2003-03-06 00:42:18 +00:00
|
|
|
} else {
|
|
|
|
in_correct_venue = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-09-02 23:49:53 +00:00
|
|
|
if (match_tag(buf, "<global_preferences>")) {
|
|
|
|
continue;
|
2004-03-23 01:44:47 +00:00
|
|
|
} else if (parse_str(buf, "<source_project>", source_project)) {
|
2003-09-02 23:49:53 +00:00
|
|
|
continue;
|
2004-03-23 01:44:47 +00:00
|
|
|
} else if (parse_str(buf, "<source_scheduler>", source_scheduler)) {
|
2003-09-02 23:49:53 +00:00
|
|
|
continue;
|
|
|
|
} else if (parse_int(buf, "<mod_time>", mod_time)) {
|
|
|
|
continue;
|
|
|
|
} else if (match_tag(buf, "</global_preferences>")) {
|
|
|
|
break;
|
2003-02-21 01:38:16 +00:00
|
|
|
} else if (match_tag(buf, "<run_on_batteries/>")) {
|
|
|
|
run_on_batteries = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
2003-02-21 01:38:16 +00:00
|
|
|
} else if (match_tag(buf, "<run_if_user_active/>")) {
|
|
|
|
run_if_user_active = true;
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2003-06-05 21:38:46 +00:00
|
|
|
} else if (parse_int(buf, "<start_hour>", start_hour)) {
|
2003-03-25 01:30:13 +00:00
|
|
|
continue;
|
2003-06-05 21:38:46 +00:00
|
|
|
} else if (parse_int(buf, "<end_hour>", end_hour)) {
|
2003-03-25 01:30:13 +00:00
|
|
|
continue;
|
2002-06-01 20:26:21 +00:00
|
|
|
} else if (match_tag(buf, "<confirm_before_connecting/>")) {
|
|
|
|
confirm_before_connecting = true;
|
|
|
|
continue;
|
2003-03-10 23:21:39 +00:00
|
|
|
} else if (match_tag(buf, "<hangup_if_dialed/>")) {
|
|
|
|
hangup_if_dialed = true;
|
|
|
|
continue;
|
2003-02-04 01:07:19 +00:00
|
|
|
} else if (match_tag(buf, "<run_minimized/>")) {
|
|
|
|
run_minimized = true;
|
|
|
|
continue;
|
|
|
|
} else if (match_tag(buf, "<run_on_startup/>")) {
|
|
|
|
run_on_startup = true;
|
|
|
|
continue;
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (parse_double(buf, "<work_buf_max_days>", work_buf_max_days)) {
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (parse_double(buf, "<work_buf_min_days>", work_buf_min_days)) {
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2003-03-20 02:05:25 +00:00
|
|
|
} else if (parse_int(buf, "<max_cpus>", max_cpus)) {
|
|
|
|
if (max_cpus < 1) max_cpus = 1;
|
|
|
|
continue;
|
|
|
|
} else if (parse_double(buf, "<disk_interval>", disk_interval)) {
|
|
|
|
if (disk_interval<0) disk_interval = 0;
|
|
|
|
continue;
|
2002-06-01 20:26:21 +00:00
|
|
|
} else if (parse_double(buf, "<disk_max_used_gb>", disk_max_used_gb)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_double(buf, "<disk_max_used_pct>", disk_max_used_pct)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_double(buf, "<disk_min_free_gb>", disk_min_free_gb)) {
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
2002-11-18 21:20:54 +00:00
|
|
|
} else if (parse_double(buf, "<idle_time_to_run>", idle_time_to_run)) {
|
|
|
|
continue;
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (parse_double(buf, "<max_bytes_sec_up>", max_bytes_sec_up)) {
|
2003-03-06 00:42:18 +00:00
|
|
|
if (max_bytes_sec_up <= 0) max_bytes_sec_up = 1e12;
|
2003-02-26 00:47:57 +00:00
|
|
|
continue;
|
|
|
|
} else if (parse_double(buf, "<max_bytes_sec_down>", max_bytes_sec_down)) {
|
2003-03-06 00:42:18 +00:00
|
|
|
if (max_bytes_sec_down <= 0) max_bytes_sec_down = 1e12;
|
2003-02-26 00:47:57 +00:00
|
|
|
continue;
|
2003-06-16 18:47:17 +00:00
|
|
|
} else if (parse_int(buf, "<max_memory_mbytes>", max_memory_mbytes)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(buf, "<cpu_affinity>", cpu_affinity)) {
|
|
|
|
continue;
|
2003-09-02 23:49:53 +00:00
|
|
|
} else {
|
2004-05-18 22:47:08 +00:00
|
|
|
scope_messages.printf("GLOBAL_PREFS::parse: unrecognized: %s\n", buf);
|
2003-09-02 23:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Parse global prefs file
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2004-03-30 23:05:34 +00:00
|
|
|
int GLOBAL_PREFS::parse_file(
|
|
|
|
char* filename, char* host_venue, bool& found_venue
|
|
|
|
) {
|
2002-06-21 06:52:47 +00:00
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
|
2004-03-30 23:05:34 +00:00
|
|
|
f = fopen(filename, "r");
|
2002-06-21 06:52:47 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2004-03-30 23:05:34 +00:00
|
|
|
retval = parse(f, host_venue, found_venue);
|
2002-06-21 06:52:47 +00:00
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|