2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-09-11 17:36:37 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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.
|
2003-09-11 17:36:37 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
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"
|
|
|
|
#include "prefs.h"
|
|
|
|
|
2004-03-23 19:43:58 +00:00
|
|
|
// The following values determine how the client behaves
|
2004-10-17 02:18:59 +00:00
|
|
|
// if there are no global prefs (e.g. on our very first RPC).
|
2006-02-07 20:53:46 +00:00
|
|
|
// These 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
|
|
|
//
|
2004-10-17 02:18:59 +00:00
|
|
|
void GLOBAL_PREFS::defaults() {
|
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;
|
2005-06-08 23:55:21 +00:00
|
|
|
net_start_hour = 0;
|
|
|
|
net_end_hour = 0;
|
2003-02-04 01:07:19 +00:00
|
|
|
run_minimized = false;
|
|
|
|
run_on_startup = false;
|
2004-08-06 23:17:59 +00:00
|
|
|
leave_apps_in_memory = false;
|
2005-07-01 06:30:06 +00:00
|
|
|
confirm_before_connecting = true;
|
2004-03-23 19:43:58 +00:00
|
|
|
hangup_if_dialed = false;
|
2005-04-06 19:41:31 +00:00
|
|
|
dont_verify_images = false;
|
2004-03-06 11:40:54 +00:00
|
|
|
work_buf_min_days = 0.1;
|
2005-06-28 19:25:52 +00:00
|
|
|
max_cpus = 16;
|
2004-10-13 18:30:18 +00:00
|
|
|
cpu_scheduling_period_minutes = 60;
|
2003-03-20 02:05:25 +00:00
|
|
|
disk_interval = 60;
|
2005-06-28 19:25:52 +00:00
|
|
|
disk_max_used_gb = 10;
|
2004-08-06 23:17:59 +00:00
|
|
|
disk_max_used_pct = 50;
|
2002-08-22 22:28:51 +00:00
|
|
|
disk_min_free_gb = 0.1;
|
2004-08-06 23:17:59 +00:00
|
|
|
vm_max_used_pct = 75;
|
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;
|
2004-10-06 19:09:37 +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;
|
2004-10-08 20:00:42 +00:00
|
|
|
|
|
|
|
// don't initialize source_project, source_scheduler here
|
|
|
|
// since they are outside of <venue> elements
|
2006-03-24 22:30:30 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-10-17 02:18:59 +00:00
|
|
|
// before parsing
|
|
|
|
void GLOBAL_PREFS::clear_bools() {
|
|
|
|
run_on_batteries = false;
|
|
|
|
run_if_user_active = false;
|
|
|
|
leave_apps_in_memory = false;
|
|
|
|
confirm_before_connecting = false;
|
|
|
|
run_minimized = false;
|
|
|
|
run_on_startup = false;
|
|
|
|
hangup_if_dialed = false;
|
2005-04-06 19:41:31 +00:00
|
|
|
dont_verify_images = false;
|
2004-10-17 02:18:59 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
GLOBAL_PREFS::GLOBAL_PREFS() {
|
2004-10-17 02:18:59 +00:00
|
|
|
defaults();
|
2003-03-06 00:42:18 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 20:53:46 +00:00
|
|
|
// Parse XML global prefs, setting defaults first.
|
|
|
|
//
|
|
|
|
int GLOBAL_PREFS::parse(
|
|
|
|
MIOFILE& in, const char* host_venue, bool& found_venue
|
|
|
|
) {
|
|
|
|
defaults();
|
|
|
|
clear_bools();
|
|
|
|
|
|
|
|
strcpy(source_project, "");
|
|
|
|
strcpy(source_scheduler, "");
|
|
|
|
return parse_override(in, host_venue, found_venue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse global prefs, overriding whatever is currently in the structure.
|
|
|
|
//
|
2003-03-06 00:42:18 +00:00
|
|
|
// 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
|
|
|
//
|
2006-02-07 20:53:46 +00:00
|
|
|
int GLOBAL_PREFS::parse_override(
|
|
|
|
MIOFILE& in, const 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-03-30 23:05:34 +00:00
|
|
|
found_venue = false;
|
2005-06-22 10:51:34 +00:00
|
|
|
while (in.fgets(buf, 256)) {
|
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 {
|
2004-08-12 10:13:01 +00:00
|
|
|
if (!in_correct_venue) continue;
|
2003-03-06 00:42:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (match_tag(buf, "<venue")) {
|
|
|
|
in_venue = true;
|
|
|
|
parse_attr(buf, "name", buf2, sizeof(buf2));
|
|
|
|
if (!strcmp(buf2, host_venue)) {
|
2004-10-17 02:18:59 +00:00
|
|
|
defaults();
|
|
|
|
clear_bools();
|
2003-03-06 00:42:18 +00:00
|
|
|
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-10-06 19:09:37 +00:00
|
|
|
} else if (parse_str(buf, "<source_project>", source_project, sizeof(source_project))) {
|
2003-09-02 23:49:53 +00:00
|
|
|
continue;
|
2004-10-06 19:09:37 +00:00
|
|
|
} else if (parse_str(buf, "<source_scheduler>", source_scheduler, sizeof(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;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "run_on_batteries", run_on_batteries)) {
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "run_if_user_active", run_if_user_active)) {
|
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;
|
2005-06-08 23:55:21 +00:00
|
|
|
} else if (parse_int(buf, "<net_start_hour>", net_start_hour)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(buf, "<net_end_hour>", net_end_hour)) {
|
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "leave_apps_in_memory", leave_apps_in_memory)) {
|
2004-08-06 23:17:59 +00:00
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "confirm_before_connecting", confirm_before_connecting)) {
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "hangup_if_dialed", hangup_if_dialed)) {
|
2003-03-10 23:21:39 +00:00
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "run_minimized", run_minimized)) {
|
2003-02-04 01:07:19 +00:00
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "run_on_startup", run_on_startup)) {
|
2003-02-04 01:07:19 +00:00
|
|
|
continue;
|
2006-02-07 20:53:46 +00:00
|
|
|
} else if (parse_bool(buf, "dont_verify_images", dont_verify_images)) {
|
2005-04-06 19:41:31 +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;
|
2004-10-13 18:30:18 +00:00
|
|
|
} else if (parse_double(buf, "<cpu_scheduling_period_minutes>", cpu_scheduling_period_minutes)) {
|
2005-04-05 00:32:24 +00:00
|
|
|
if (cpu_scheduling_period_minutes < 0.0001) cpu_scheduling_period_minutes = 60;
|
2004-10-13 18:30:18 +00:00
|
|
|
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;
|
2004-08-06 23:17:59 +00:00
|
|
|
} else if (parse_double(buf, "<vm_max_used_pct>", vm_max_used_pct)) {
|
|
|
|
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;
|
2004-10-06 19:09:37 +00:00
|
|
|
#if 0
|
2003-06-16 18:47:17 +00:00
|
|
|
} else if (parse_int(buf, "<max_memory_mbytes>", max_memory_mbytes)) {
|
|
|
|
continue;
|
2004-10-06 19:09:37 +00:00
|
|
|
#endif
|
2003-06-16 18:47:17 +00:00
|
|
|
} else if (parse_int(buf, "<cpu_affinity>", cpu_affinity)) {
|
|
|
|
continue;
|
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(
|
2005-02-16 23:17:43 +00:00
|
|
|
const char* filename, const char* host_venue, bool& found_venue
|
2004-03-30 23:05:34 +00:00
|
|
|
) {
|
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;
|
2005-06-22 10:51:34 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(f);
|
|
|
|
retval = parse(mf, host_venue, found_venue);
|
2002-06-21 06:52:47 +00:00
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|
2004-10-06 19:09:37 +00:00
|
|
|
|
|
|
|
// this is used only to write the app init data file
|
|
|
|
//
|
2005-06-22 10:51:34 +00:00
|
|
|
int GLOBAL_PREFS::write(MIOFILE& f) {
|
|
|
|
f.printf(
|
2004-10-06 19:09:37 +00:00
|
|
|
"<global_preferences>\n"
|
|
|
|
" <mod_time>%d</mod_time>\n"
|
|
|
|
"%s%s"
|
|
|
|
" <start_hour>%d</start_hour>\n"
|
|
|
|
" <end_hour>%d</end_hour>\n"
|
2005-06-08 23:55:21 +00:00
|
|
|
" <net_start_hour>%d</net_start_hour>\n"
|
|
|
|
" <net_end_hour>%d</net_end_hour>\n"
|
2005-04-06 19:41:31 +00:00
|
|
|
"%s%s%s%s%s%s"
|
2004-10-06 19:09:37 +00:00
|
|
|
" <work_buf_min_days>%f</work_buf_min_days>\n"
|
|
|
|
" <max_cpus>%d</max_cpus>\n"
|
2004-10-13 18:30:18 +00:00
|
|
|
" <cpu_scheduling_period_minutes>%f</cpu_scheduling_period_minutes>\n"
|
2004-10-06 19:09:37 +00:00
|
|
|
" <disk_interval>%f</disk_interval>\n"
|
|
|
|
" <disk_max_used_gb>%f</disk_max_used_gb>\n"
|
|
|
|
" <disk_max_used_pct>%f</disk_max_used_pct>\n"
|
|
|
|
" <disk_min_free_gb>%f</disk_min_free_gb>\n"
|
|
|
|
" <vm_max_used_pct>%f</vm_max_used_pct>\n"
|
|
|
|
" <idle_time_to_run>%f</idle_time_to_run>\n"
|
|
|
|
" <max_bytes_sec_up>%f</max_bytes_sec_up>\n"
|
|
|
|
" <max_bytes_sec_down>%f</max_bytes_sec_down>\n"
|
|
|
|
"</global_preferences>\n",
|
|
|
|
mod_time,
|
|
|
|
run_on_batteries?" <run_on_batteries/>\n":"",
|
|
|
|
run_if_user_active?" <run_if_user_active/>\n":"",
|
|
|
|
start_hour,
|
|
|
|
end_hour,
|
2005-06-08 23:55:21 +00:00
|
|
|
net_start_hour,
|
|
|
|
net_end_hour,
|
2004-10-06 19:09:37 +00:00
|
|
|
leave_apps_in_memory?" <leave_apps_in_memory/>\n":"",
|
|
|
|
confirm_before_connecting?" <confirm_before_connecting/>\n":"",
|
|
|
|
run_minimized?" <run_minimized/>\n":"",
|
|
|
|
run_on_startup?" <run_on_startup/>\n":"",
|
|
|
|
hangup_if_dialed?" <hangup_if_dialed/>\n":"",
|
2005-04-06 19:41:31 +00:00
|
|
|
dont_verify_images?" <dont_verify_images/>\n":"",
|
2004-10-06 19:09:37 +00:00
|
|
|
work_buf_min_days,
|
|
|
|
max_cpus,
|
2004-10-13 18:30:18 +00:00
|
|
|
cpu_scheduling_period_minutes,
|
2004-10-06 19:09:37 +00:00
|
|
|
disk_interval,
|
|
|
|
disk_max_used_gb,
|
|
|
|
disk_max_used_pct,
|
|
|
|
disk_min_free_gb,
|
|
|
|
vm_max_used_pct,
|
|
|
|
idle_time_to_run,
|
|
|
|
max_bytes_sec_up,
|
|
|
|
max_bytes_sec_down
|
|
|
|
);
|
|
|
|
return 0;
|
2004-10-07 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_3fb442bb02 = "$Id$";
|