2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla 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://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// 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):
|
|
|
|
//
|
|
|
|
|
2002-06-06 18:50:12 +00:00
|
|
|
#include "windows_cpp.h"
|
|
|
|
|
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>
|
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"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "file_names.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "prefs.h"
|
|
|
|
|
2002-09-27 06:12:50 +00:00
|
|
|
// the following values determine how the client behaves
|
2002-09-29 00:32:11 +00:00
|
|
|
// if there are no global prefs yet
|
2002-09-27 06:12:50 +00:00
|
|
|
//
|
2003-03-06 00:42:18 +00:00
|
|
|
void GLOBAL_PREFS::init() {
|
2003-05-16 22:45:30 +00:00
|
|
|
run_on_batteries = false;
|
|
|
|
run_if_user_active = false;
|
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;
|
2003-03-10 23:21:39 +00:00
|
|
|
hangup_if_dialed = true;
|
2003-02-26 00:47:57 +00:00
|
|
|
work_buf_max_days = 3;
|
|
|
|
work_buf_min_days = 1;
|
2003-03-20 02:05:25 +00:00
|
|
|
max_cpus = 2;
|
|
|
|
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;
|
2002-11-20 20:14:48 +00:00
|
|
|
idle_time_to_run = 0;
|
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;
|
|
|
|
cpu_affinity = -1;
|
2003-06-16 21:23:58 +00:00
|
|
|
confirm_executable = true;
|
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>
|
|
|
|
// then parse that and ignore the rest.
|
|
|
|
// Otherwise ignore <venue> elements.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2003-03-06 00:42:18 +00:00
|
|
|
int GLOBAL_PREFS::parse(FILE* in, char* host_venue) {
|
|
|
|
char buf[256], buf2[256];
|
|
|
|
bool in_venue = false, in_correct_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) {
|
|
|
|
return 0;
|
|
|
|
} 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;
|
|
|
|
} else {
|
|
|
|
in_correct_venue = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2002-09-29 00:32:11 +00:00
|
|
|
if (match_tag(buf, "</global_preferences>")) {
|
2002-09-26 05:57:10 +00:00
|
|
|
return 0;
|
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-06-16 21:23:58 +00:00
|
|
|
} else if (match_tag(buf, "<confirm_executable/>")) {
|
|
|
|
confirm_executable = true;
|
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Parse global prefs file
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2003-03-06 00:42:18 +00:00
|
|
|
int GLOBAL_PREFS::parse_file(char* host_venue) {
|
2002-06-21 06:52:47 +00:00
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
f = fopen(GLOBAL_PREFS_FILE_NAME, "r");
|
2002-06-21 06:52:47 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2003-03-06 00:42:18 +00:00
|
|
|
retval = parse(f, host_venue);
|
2002-06-21 06:52:47 +00:00
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|