2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-07-13 13:54:09 +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.
|
2004-07-13 13:54:09 +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
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
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
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "error_numbers.h"
|
2002-08-12 23:18:47 +00:00
|
|
|
#include "file_names.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
|
|
|
|
2004-03-01 19:11:12 +00:00
|
|
|
#include "filesys.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
LOG_FLAGS log_flags;
|
2006-05-21 21:11:28 +00:00
|
|
|
CONFIG config;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
LOG_FLAGS::LOG_FLAGS() {
|
2003-03-13 21:49:52 +00:00
|
|
|
|
2006-06-22 19:40:30 +00:00
|
|
|
memset(this, 0, sizeof(LOG_FLAGS));
|
|
|
|
|
|
|
|
// on by default
|
|
|
|
// (others are off by default)
|
2003-03-13 21:49:52 +00:00
|
|
|
//
|
2006-06-22 19:40:30 +00:00
|
|
|
task = true;
|
2003-03-13 21:49:52 +00:00
|
|
|
file_xfer = true;
|
|
|
|
sched_ops = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse log flag preferences
|
|
|
|
//
|
2006-06-21 22:08:20 +00:00
|
|
|
int LOG_FLAGS::parse(FILE* f) {
|
|
|
|
char tag[256], contents[1024];
|
|
|
|
|
|
|
|
while (get_tag(f, tag, contents)) {
|
|
|
|
if (!strcmp(tag, "/log_flags")) return 0;
|
|
|
|
else if (!strcmp(tag, "task")) task = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "file_xfer")) file_xfer = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "sched_ops")) sched_ops = get_bool(contents);
|
2006-06-23 03:28:35 +00:00
|
|
|
|
|
|
|
else if (!strcmp(tag, "cpu_sched")) cpu_sched = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "cpu_sched_debug")) cpu_sched_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "rr_simulation")) rr_simulation = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "debt_debug")) debt_debug = get_bool(contents);
|
2006-06-21 22:08:20 +00:00
|
|
|
else if (!strcmp(tag, "task_debug")) task_debug = get_bool(contents);
|
2006-06-23 03:28:35 +00:00
|
|
|
else if (!strcmp(tag, "work_fetch_debug")) work_fetch_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "unparsed_xml")) unparsed_xml = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "state_debug")) state_debug = get_bool(contents);
|
2006-06-21 22:08:20 +00:00
|
|
|
else if (!strcmp(tag, "file_xfer_debug")) file_xfer_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "sched_op_debug")) sched_op_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "http_debug")) http_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "proxy_debug")) proxy_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "time_debug")) time_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "net_xfer_debug")) net_xfer_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "measurement_debug")) measurement_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "poll_debug")) poll_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "guirpc_debug")) guirpc_debug = get_bool(contents);
|
|
|
|
else if (!strcmp(tag, "scrsave_debug")) scrsave_debug = get_bool(contents);
|
|
|
|
else {
|
|
|
|
msg_printf(NULL, MSG_ERROR, "Unrecognized tag in %s: %s\n",
|
|
|
|
CONFIG_FILE, tag
|
|
|
|
);
|
|
|
|
}
|
2006-05-21 21:11:28 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIG::CONFIG() {
|
2006-05-22 09:54:31 +00:00
|
|
|
dont_check_file_sizes = false;
|
2006-05-21 21:11:28 +00:00
|
|
|
save_stats_days = 30;
|
|
|
|
}
|
|
|
|
|
2006-07-11 22:52:17 +00:00
|
|
|
int CONFIG::parse_options(FILE* f) {
|
|
|
|
char tag[256], contents[1024];
|
|
|
|
while (get_tag(f, tag, contents)) {
|
|
|
|
if (!strcmp(tag, "/options")) {
|
|
|
|
return 0;
|
|
|
|
} else if (!strcmp(tag, "save_stats_days")) {
|
|
|
|
save_stats_days = get_int(contents);
|
|
|
|
} else if (!strcmp(tag, "dont_check_file_sizes")) {
|
|
|
|
dont_check_file_sizes = get_bool(contents);
|
|
|
|
} else if (!strcmp(tag, "ncpus")) {
|
|
|
|
ncpus = get_int(contents);
|
|
|
|
} else {
|
|
|
|
msg_printf(NULL, MSG_ERROR, "Unparsed tag in %s: %s\n",
|
|
|
|
CONFIG_FILE, tag
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2006-06-21 22:08:20 +00:00
|
|
|
int CONFIG::parse(FILE* f) {
|
|
|
|
char tag[256], contents[1024];
|
|
|
|
|
|
|
|
memset(this, 0, sizeof(CONFIG));
|
|
|
|
|
|
|
|
get_tag(f, tag);
|
|
|
|
if (strstr(tag, "?xml")) get_tag(f, tag);
|
|
|
|
if (strcmp(tag, "cc_config")) return ERR_XML_PARSE;
|
2006-05-21 21:11:28 +00:00
|
|
|
|
2006-07-11 22:52:17 +00:00
|
|
|
while (get_tag(f, tag)) {
|
2006-06-21 22:08:20 +00:00
|
|
|
if (!strcmp(tag, "/cc_config")) return 0;
|
|
|
|
if (!strcmp(tag, "log_flags")) {
|
|
|
|
log_flags.parse(f);
|
2006-05-21 21:11:28 +00:00
|
|
|
continue;
|
2006-07-11 22:52:17 +00:00
|
|
|
} else if (!strcmp(tag, "options")) {
|
|
|
|
parse_options(f);
|
2006-06-21 22:08:20 +00:00
|
|
|
} else {
|
|
|
|
msg_printf(NULL, MSG_ERROR, "Unparsed tag in %s: %s\n",
|
|
|
|
CONFIG_FILE, tag
|
|
|
|
);
|
2006-05-21 21:11:28 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2002-08-12 23:18:47 +00:00
|
|
|
|
2006-05-21 21:11:28 +00:00
|
|
|
void read_config_file() {
|
2002-08-12 23:18:47 +00:00
|
|
|
FILE* f;
|
|
|
|
|
2006-06-21 22:08:20 +00:00
|
|
|
f = boinc_fopen(CONFIG_FILE, "r");
|
|
|
|
if (!f) return;
|
|
|
|
config.parse(f);
|
|
|
|
fclose(f);
|
2002-08-12 23:18:47 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_5f23de6652 = "$Id$";
|